(*^ ::[ Information = "This is a Mathematica Notebook file. It contains ASCII text, and can be transferred by email, ftp, or other text-file transfer utility. It should be read or edited using a copy of Mathematica or MathReader. If you received this as email, use your mail application or copy/paste to save everything from the line containing (*^ down to the line containing ^*) into a plain text file. On some systems you may have to give the file a name ending with ".ma" to allow Mathematica to recognize it as a Notebook. The line below identifies what version of Mathematica created this file, but it can be opened using any other version as well."; FrontEndVersion = "Macintosh Mathematica Notebook Front End Version 2.2"; MacintoshStandardFontEncoding; fontset = title, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, e8, 24, "Times"; fontset = subtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, e6, 18, "Times"; fontset = subsubtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, italic, e6, 14, "Times"; fontset = section, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, grayBox, M22, bold, a20, 18, "Times"; fontset = subsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, blackBox, M19, bold, a15, 14, "Times"; fontset = subsubsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, whiteBox, M18, bold, a12, 12, "Times"; fontset = text, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = smalltext, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 10, "Times"; fontset = input, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeInput, M42, N23, bold, L-5, 12, "Courier"; fontset = output, output, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L-5, 12, "Courier"; fontset = message, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, R65535, L-5, 12, "Courier"; fontset = print, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L-5, 12, "Courier"; fontset = info, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, B65535, L-5, 12, "Courier"; fontset = postscript, PostScript, formatAsPostScript, output, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeGraphics, M7, l34, w282, h287, 12, "Courier"; fontset = name, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, italic, 10, "Geneva"; fontset = header, inactive, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = leftheader, inactive, L2, 12, "Times"; fontset = footer, inactive, noKeepOnOnePage, preserveAspect, center, M7, 12, "Times"; fontset = leftfooter, inactive, L2, 12, "Times"; fontset = help, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 10, "Times"; fontset = clipboard, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = completions, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = special1, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = special2, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = special3, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = special4, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = special5, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; currentKernel; ] :[font = input; initialization; preserveAspect] *) (* $Id: MET.m,v 1.0 May 12 1995 $ *) (* :Title: MorphoElectrotonicTransform *) (* :Author: Hagai Agmon-Snir hagai@helix.nih.gov *) (* :Summary: This package provides means for reading, transforming and rendering deindrites in various METs. It was used for the figures in: Zador, A., Agmon-Snir, H., and Segev, I. 1995. The morphoelectrotonic transform: a graphical approach to dendritic function. J. Neuroscience 15: 1669-1682. This file comes with a sample Mathematica notebook and with two public domain morphological files adjusted to be used by this package. Any comments are welcome. This package is far from being complete. For any help in customizing the package to specific needs, call: Hagai Agmon-Snir Tel: (301) 496-6136 Surface mail: (301) 496-4325 Mathematical Research Branch, NIDDK Fax: (301) 402-0535 BSA 9190 Rockville Pike - Suite 350 Bethesda, MD 20814-3800 USA E-mail: hagai@helix.nih.gov *) (* :Context: MET` *) (* :Package Version: 1.0 *) (* :Mathematica Version: 2.2.2 *) BeginPackage["MET`"]; readEutecticTree::usage = "readEutecticTree[filename] reads an Eutectic file (with minor changes as explained in the sample notebook) into Mathematica.It assumes that coordinates and diameters are in microns. In the Mathematica program, all the values are saved in cm."; readDouglasTree::usage = "readDouglasTree[filename] reads the R. Douglas files (with minor changes as explained in the sample notebook) into Mathematica.It assumes that coordinates and diameters are in 0.1 microns. In the Mathematica program, all the values are saved in cm."; convert2InternalTree::usage = "convert2InternalTree converts the structure made by the reading routines (e.g. readEutecticTree, readDouglasTree) to the internal tree data structure."; somaIsDendnum::usage = "In reconstructing a neuron, one of the 'dendrites' is the outline of the soma. somaIsDendnum is the number of this 'dendrite'."; dendnum::usage = "dendnum is the number of dendrites reconstructed (including the soma outline"; colorcode::usage = "colorcode gets number between 0 and 1 and output an RGB color according to a predefined colorcode"; makeGraphicsCommandBW2D::usage = " "; makeGraphicsCommandColor2D::usage = " "; makeMETGraphicsCommandBW2D::usage = " "; makeMETGraphicsCommandColor2D::usage = " "; showTheGraph::usage = " "; showTheGraphWithBar::usage = " "; initialBiophysicalCalculations::usage = " "; pointcalc::usage = " "; subtreecalc::usage = " "; vinpointcalc::usage = " "; vinsubtreecalc::usage = " "; makeAttenuationTransform::usage = " "; makeDelayTransform::usage = " "; makeTransform::usage = " "; makeVinAttenuationTransform::usage = " "; makeVinDelayTransform::usage = " "; makeElectroNaiveTransform::usage = " "; listOfTips::usage = " "; traceToRoot::usage = " "; showFewGraphs::usage = " "; Begin["`Private`"]; readEutecticTree[filename_]:= Module[{tmp,name,pointX,pointY,pointZ,pointd},( treefile=OpenRead[filename]; treelist={}; tmp=Read[treefile,Number]; name=Read[treefile,Word]; While[name!="end",( tmp=Read[treefile,Word]; pointX=Read[treefile,Number]/10000 //N; pointY=Read[treefile,Number]/10000 //N; pointZ=Read[treefile,Number]/10000 //N; pointd=Read[treefile,Number]/10000 //N; treelist=Append[treelist, List[ToLowerCase[name], pointX,pointY,pointZ,pointd]]; tmp=Read[treefile,Word]; name=Read[treefile,Word]; )]; Close[treefile]; treelistlength=Length[treelist]; )]; readDouglasTree[filename_]:= Module[{name,pointX,pointY,pointZ,pointd},( treefile=OpenRead[filename]; treelist={}; name=Read[treefile,Word]; While[name!="end",( pointX=Read[treefile,Number]/100000 //N; pointY=Read[treefile,Number]/100000 //N; pointZ=Read[treefile,Number]/100000 //N; pointd=Read[treefile,Number]/100000 //N; treelist=Append[treelist, List[ToLowerCase[name], pointX,pointY,pointZ,pointd]]; name=Read[treefile,Word]; )]; Close[treefile]; treelistlength=Length[treelist]; )]; distance[lx_,ly_]:= Sqrt[(lx[[1]]-ly[[1]])^2+(lx[[2]]-ly[[2]])^2+ (lx[[3]]-ly[[3]])^2]//N convert2InternalTree:= Module[{backpoints={1},pointer=1, backcyls={sroot},treelistlength=Length[treelist], cylindernum,frompointer,prevcyl,cylinder},( dendnum=0; While[pointer<=treelistlength,( If[MemberQ[{"mto","tto","bto","sos"}, treelist[[pointer]][[1]]],( dendnum++;cylindernum=1; frompointer=pointer;pointer++; Print[frompointer,backpoints,backcyls]; backpoints={frompointer}; backcyls={sroot};prevcyl=sroot; )]; If[treelist[[frompointer]][[1]]=="sos" || MemberQ[{"scp","soe"},treelist[[pointer]][[1]]],( somaIsDendnum=dendnum; )]; cylinder=cyl[dendnum,cylindernum]; cylinder[sfrom]=Take[treelist[[frompointer]],{2,4}]; cylinder[sto]= Take[treelist[[ pointer]],{2,4}]; cylinder[sl]=distance[cylinder[sfrom],cylinder[sto]]; If[cylinder[sl] >= (10^(-6)),( cylinder[szerol]=False; cylinder[sxshift]=N[ (cylinder[sto][[1]]-cylinder[sfrom][[1]]) /cylinder[sl]]; cylinder[syshift]=N[ (cylinder[sto][[2]]-cylinder[sfrom][[2]]) /cylinder[sl]]; cylinder[szshift]=N[ (cylinder[sto][[3]]-cylinder[sfrom][[3]]) /cylinder[sl]]; ), (* else *) ( cylinder[szerol]=True; )]; cylinder[sdiam]=N[0.5* treelist[[frompointer]][[5]]+treelist[[pointer]][[5]]]; cylinder[sparent]=prevcyl; prevcyl[schildren]=Append[prevcyl[schildren],cylinder]; cylinder[schildren]={}; If[MemberQ[{"dcp","cp","scp"}, treelist[[pointer]][[1]]],( frompointer=pointer;pointer++; prevcyl=cylinder;cylindernum++; Continue[]; )]; If[MemberQ[{"bp"}, treelist[[pointer]][[1]]],( frompointer=pointer;pointer++; prevcyl=cylinder;cylindernum++; backpoints=Append[backpoints,frompointer]; backcyls=Append[backcyls,prevcyl]; Continue[]; )]; If[MemberQ[{"ne","mae","bae","tae","soe"}, treelist[[pointer]][[1]]],( frompointer=Last[backpoints];pointer++; prevcyl=Last[backcyls];cylindernum++; backpoints=Drop[backpoints,-1]; backcyls=Drop[backcyls,-1]; If[Length[backpoints]*Length[backcyls]==0, Print[frompointer,backpoints,backcyls]; Continue[] ] )] )] )]; passTreeRecursive[lroot_,lfunc_] := ( Apply[lfunc,List[lroot]]; If[Length[lroot[schildren]] >0 , Map[passTreeRecursive[#,lfunc]&,lroot[schildren]]]; ); System`$RecursionLimit=Infinity; colorcode[colorcodearg_]:= Switch[Round[colorcodearg*5-0.5] ,0 ,StringJoin["RGBColor[",ToString[Format[(1-colorcodearg*5)//N,InputForm]],",1,0]"] ,1 ,StringJoin["RGBColor[0,1,",ToString[Format[(colorcodearg*5-1)//N,InputForm]],"]"] ,2 ,StringJoin["RGBColor[0,",ToString[Format[(3-colorcodearg*5)//N,InputForm]],",1]"] ,3 ,StringJoin["RGBColor[",ToString[Format[(colorcodearg*5-3)//N,InputForm]],",0,1]"] ,4 ,StringJoin["RGBColor[1,0,",ToString[Format[(5-colorcodearg*5)//N,InputForm]],"]"] ,_ ,(Print[pointer," ",Length[showoperand]]; StringJoin["RGBColor[1,0,0]"]) ] makeGraphicsCommandBW2D:= Module[{tmpj,thefunc},( graphicsCommand=Array[0,treelistlength];tmpj=0; thefunc[lcyl_]:=Module[{tmp},tmpj++; tmp=StringJoin["Graphics[{" ,"RGBColor[0,0,0]" ,",AbsoluteThickness[" ,ToString[InputForm[((lcyl[sdiam]*10000)/4//N)]] ,"],Line[{{" ,ToString[InputForm[lcyl[sfrom][[1]]]] ,",",ToString[InputForm[lcyl[sfrom][[2]]]] ,"},{" ,ToString[InputForm[lcyl[sto][[1]]]] ,",",ToString[InputForm[lcyl[sto][[2]]]] ,"}}]}]" ]; graphicsCommand[[tmpj]]=tmp; ]; For[i=1,i<=dendnum,i++, passTreeRecursive[cyl[i,1],thefunc]; ]; graphicsCommand=Take[graphicsCommand,tmpj]; )]; makeGraphicsCommandColor2D:= Module[{tmpj,thefunc},( graphicsCommand=Array[0,treelistlength];tmpj=0; thefunc[lcyl_]:=Module[{tmp},tmpj++; tmp=StringJoin["Graphics[{" ,colorcode[tmpj/treelistlength] ,",AbsoluteThickness[" ,ToString[InputForm[((lcyl[sdiam]*10000)/4//N)]] ,"],Line[{{" ,ToString[InputForm[lcyl[sfrom][[1]]]] ,",",ToString[InputForm[lcyl[sfrom][[2]]]] ,"},{" ,ToString[InputForm[lcyl[sto][[1]]]] ,",",ToString[InputForm[lcyl[sto][[2]]]] ,"}}]}]" ]; graphicsCommand[[tmpj]]=tmp; ]; For[i=1,i<=dendnum,i++, passTreeRecursive[cyl[i,1],thefunc]; ]; graphicsCommand=Take[graphicsCommand,tmpj]; )]; makeMETGraphicsCommandBW2D:= Module[{tmpj,thefunc},( graphicsCommand=Array[0,treelistlength];tmpj=0; thefunc[lcyl_]:=Module[{tmp},tmpj++; tmp=StringJoin["Graphics[{" ,"RGBColor[0,0,0]" ,",AbsoluteThickness[" ,ToString[InputForm[((lcyl[sdiam]*10000)/4//N)]] ,"],Line[{{" ,ToString[InputForm[lcyl[strfrom][[1]]]] ,",",ToString[InputForm[lcyl[strfrom][[2]]]] ,"},{" ,ToString[InputForm[lcyl[strto][[1]]]] ,",",ToString[InputForm[lcyl[strto][[2]]]] ,"}}]}]" ]; graphicsCommand[[tmpj]]=tmp; ]; For[i=1,i<=dendnum,i++, If[i!=somaIsDendnum, passTreeRecursive[cyl[i,1],thefunc]; ]; ]; graphicsCommand=Take[graphicsCommand,tmpj]; )]; makeMETGraphicsCommandColor2D:= Module[{tmpj,thefunc},( graphicsCommand=Array[0,treelistlength];tmpj=0; thefunc[lcyl_]:=Module[{tmp},tmpj++; tmp=StringJoin["Graphics[{" ,colorcode[tmpj/treelistlength] ,",AbsoluteThickness[" ,ToString[InputForm[((lcyl[sdiam]*10000)/4//N)]] ,"],Line[{{" ,ToString[InputForm[lcyl[strfrom][[1]]]] ,",",ToString[InputForm[lcyl[strfrom][[2]]]] ,"},{" ,ToString[InputForm[lcyl[strto][[1]]]] ,",",ToString[InputForm[lcyl[strto][[2]]]] ,"}}]}]" ]; graphicsCommand[[tmpj]]=tmp; ]; For[i=1,i<=dendnum,i++, If[i!=somaIsDendnum, passTreeRecursive[cyl[i,1],thefunc]; ]; ]; graphicsCommand=Take[graphicsCommand,tmpj]; )]; showTheGraph:= Module[{fig,optlist,range},( fig=Show[ToExpression[graphicsCommand],AspectRatio->1, DisplayFunction->Identity,PlotRange->All]; optlist=FullOptions[fig,PlotRange]; range=Max[List[optlist[[1,2]]-optlist[[1,1]], optlist[[2,2]]-optlist[[2,1]]]]; Show[fig, AspectRatio->1, DisplayFunction->$DisplayFunction, PlotRange->{{optlist[[1,1]],optlist[[1,1]]+range}, {optlist[[2,1]],optlist[[2,1]]+range}} ] )] showTheGraphWithBar[barlength_]:= Module[{fig,optlist,range,barfig},( fig=Show[ToExpression[graphicsCommand],AspectRatio->1, DisplayFunction->Identity,PlotRange->All]; optlist=FullOptions[fig,PlotRange]; range=Max[List[optlist[[1,2]]-optlist[[1,1]], optlist[[2,2]]-optlist[[2,1]]]]; barfig=Graphics[Line[{ {optlist[[1,1]],optlist[[2,1]]}, {optlist[[1,1]]+barlength,optlist[[2,1]]} }]]; Show[fig, barfig, AspectRatio->1, DisplayFunction->$DisplayFunction, PlotRange->{{optlist[[1,1]],optlist[[1,1]]+range}, {optlist[[2,1]],optlist[[2,1]]+range}} ] )] initialBiophysicalCalculations:= Module[{somaperimeter=0,thefunc},( spinefactor:=Global`spinefactor; rm:=Global`rm; ri:=Global`ri; cm:=Global`cm; epsilon:=Global`epsilon; tau:=Global`tau; thefunc[lcyl_]:=Module[{tmp}, tmp=Sqrt[(lcyl[sto][[1]]-lcyl[sfrom][[1]])^2+ (lcyl[sto][[2]]-lcyl[sfrom][[2]])^2]//N; somaperimeter += tmp; ]; passTreeRecursive[cyl[somaIsDendnum,1],thefunc]; somaarea=(somaperimeter/(2*Pi))^2*Pi*4//N; sroot[spoint]=soma; soma[stau]=tau*epsilon; soma[sgsoma]=somaarea/(rm*epsilon*spinefactor); soma[sbranches]={}; For[i=1,i<=dendnum,i++, If[i!=somaIsDendnum,( soma[sbranches]=Append[soma[sbranches],cyl[i,1]]; )]; ]; For[i=1,i<=dendnum,i++, If[i!=somaIsDendnum,( passTreeRecursive[cyl[i,1],( #[spoint][sbranches]=Append[#[schildren],#]; #[spoint][stau]=tau; #[spoint][sgsoma]=0.0; #[spoints]=List[#[spoint],(#[sparent])[spoint]]; #[selectl]=#[sl]/Sqrt[(rm/ri)*(#[sdiam]/4)] //N; #[srinf]=(2/Pi)*Sqrt[rm*ri]*(#[sdiam]^(-3/2)) //N; #[stau]=tau; )&]; )]; ]; )] pointcalc[p_,callingbranch_] := Module[{gtemp,dgtemp},( p[ssubtrees]=Complement[p[sbranches],callingbranch]; If[ Length[p[ssubtrees]]==0, (*then*)( gtemp=0;dgtemp=0; ),(*else*)( Map[(subtreecalc[#,List[p]])&,p[ssubtrees]]; gtemp=Apply[Plus,Map[#[sgin]&,p[ssubtrees]]]; dgtemp=Apply[Plus,Map[(#[sgin]*#[sdin])&,p[ssubtrees]]]; )]; p[sgin]=gtemp+p[sgsoma] //N; If[p[sgin]<(10^(-20)),p[sdin]="Not defined", p[sdin]=(dgtemp+p[stau]*p[sgsoma])/p[sgin] //N]; )] subtreecalc[t_,callingpoint_] := Module[{totdelayl0},( t[scalcpoint]= First[Complement[t[spoints],callingpoint]]; pointcalc[(t[scalcpoint]),List[t]]; If[t[szerol], ((*then*) t[sgin]=t[scalcpoint][sgin]; t[satten]=1.0; t[sdin]=t[scalcpoint][sdin]; t[spd]=0.0; ),(*else*) If[(t[scalcpoint])[sgin]<(10^(-20)), (*then*)( t[sgin]=Tanh[t[selectl]]/t[srinf] //N; t[satten]=1/Cosh[t[selectl]] //N; t[sdin]=t[stau]* ((1 + t[selectl]*Coth[t[selectl]] - t[selectl]*Tanh[t[selectl]])/2.0) //N; totdelayl0=t[stau]*((1 + t[selectl] - (2*t[selectl])/(1 - E^(2*t[selectl])))/2) //N; t[spd]=totdelayl0-t[sdin] //N; ),(*else*)( t[sgin]=(1/(((E^sl + ksi/E^sl)/(E^sl - ksi/E^sl))*t[srinf] /. sl->t[selectl])) //. { roinf->(1/((t[scalcpoint])[sgin]*t[srinf])), ksi->(roinf-1)/(roinf+1) } //N; t[satten]=1/(Cosh[t[selectl]]+Sinh[t[selectl]]/roinf) /. roinf->(1/((t[scalcpoint])[sgin]*t[srinf])) //N; t[sdin]=t[stau]*( (-E^(4*t[selectl]) + 4*E^(2*t[selectl])*kapa + 4*E^(2*t[selectl])*kapa*ksi + ksi^2 - 4*E^(2*t[selectl])*ksi*t[selectl]) /(2*(-E^(4*t[selectl]) + ksi^2)) ) //. { eps->((t[scalcpoint])[sdin]/t[stau]), roinf->(1/((t[scalcpoint])[sgin]*t[srinf])), ksi->(roinf-1)/(roinf+1), kapa->((1/2-eps)*(1-ksi))/2 } //N; totdelayl0=t[stau]*( (-E^(2*t[selectl]) + 2*kapa + 2*E^(2*t[selectl])*kapa + ksi - E^(2*t[selectl])*t[selectl] - ksi*t[selectl])/ (2*(-E^(2*t[selectl]) + ksi)) ) //. { eps->((t[scalcpoint])[sdin]/t[stau]), roinf->(1/((t[scalcpoint])[sgin]*t[srinf])), ksi->(roinf-1)/(roinf+1), kapa->((1/2-eps)*(1-ksi))/2 } //N; t[spd]=totdelayl0-t[sdin] //N; )]; ]; )] vinpointcalc[p_,callingbranch_] := Module[{gtemp,dgtemp}, p[ssubtrees]=Complement[p[sbranches],callingbranch]; If[ Length[p[ssubtrees]]>0,( Map[(vinsubtreecalc[#,List[p],callingbranch])&, p[ssubtrees]]; )]; ] vinsubtreecalc[t_,callingpoint_,callingbranch_] := Module[{totdelayl0}, t[scalcpoint]= First[Complement[t[spoints],callingpoint]]; If[Length[callingbranch]==0,( (First[callingpoint])[svingin]= (First[callingpoint])[sgin]-t[sgin]; (First[callingpoint])[svindin]= ((First[callingpoint])[sdin]* (First[callingpoint])[sgin]- t[sdin]*t[sgin])/(First[callingpoint])[svingin]; )(*else*), (First[callingpoint])[svingin]= (First[callingpoint])[sgin]- t[sgin]+(First[callingbranch])[svingin]; (First[callingpoint])[svindin]= ((First[callingpoint])[sdin]* (First[callingpoint])[sgin]- t[sdin]*t[sgin]+ (First[callingbranch])[svindin]* (First[callingbranch])[svingin] )/(First[callingpoint])[svingin]; ]; If[t[szerol], ((*then*) t[svingin]=(First[callingpoint])[svingin]; t[svinatten]=1.0; t[svindin]=(First[callingpoint])[svindin]; t[svinpd]=0.0; ),(*else*) If[(First[callingpoint])[svingin]<(10^(-20)), (*then*)( t[svingin]=Tanh[t[selectl]]/t[srinf] //N; t[svinatten]=1/Cosh[t[selectl]] //N; t[svindin]=t[stau]* ((1 + t[selectl]*Coth[t[selectl]] - t[selectl]*Tanh[t[selectl]])/2.0) //N; totdelayl0=t[stau]*((1 + t[selectl] - (2*t[selectl])/(1 - E^(2*t[selectl])))/2) //N; t[svinpd]=totdelayl0-t[svindin] //N; ),(*else*)( t[svingin]= (1/(((E^sl + ksi/E^sl)/(E^sl - ksi/E^sl))*t[srinf] /. sl->t[selectl])) //. { roinf-> (1/((First[callingpoint])[svingin]*t[srinf])), ksi->(roinf-1)/(roinf+1) } //N; t[svinatten]= 1/(Cosh[t[selectl]]+Sinh[t[selectl]]/roinf) /. roinf-> (1/((First[callingpoint])[svingin]*t[srinf])) //N; t[svindin]=t[stau]*( (-E^(4*t[selectl]) + 4*E^(2*t[selectl])*kapa + 4*E^(2*t[selectl])*kapa*ksi + ksi^2 - 4*E^(2*t[selectl])*ksi*t[selectl]) /(2*(-E^(4*t[selectl]) + ksi^2)) ) //. { eps->((First[callingpoint])[svindin]/t[stau]), roinf-> (1/((First[callingpoint])[svingin]*t[srinf])), ksi->(roinf-1)/(roinf+1), kapa->((1/2-eps)*(1-ksi))/2 } //N; totdelayl0=t[stau]*( (-E^(2*t[selectl]) + 2*kapa + 2*E^(2*t[selectl])*kapa + ksi - E^(2*t[selectl])*t[selectl] - ksi*t[selectl])/ (2*(-E^(2*t[selectl]) + ksi)) ) //. { eps->((First[callingpoint])[svindin]/t[stau]), roinf-> (1/((First[callingpoint])[svingin]*t[srinf])), ksi->(roinf-1)/(roinf+1), kapa->((1/2-eps)*(1-ksi))/2 } //N; t[svinpd]=totdelayl0-t[svindin] //N; )]; ]; vinpointcalc[(t[scalcpoint]),List[t]]; ] prepareTransformCoordinates[lroot_]:=( sroot[strto]={0.0,0.0,0.0}; thefunc[lcyl_]:=Module[{}, lcyl[strfrom]=(lcyl[sparent])[strto]; If[lcyl[szerol], lcyl[strto]=lcyl[strfrom];, lcyl[strto]=List[ (lcyl[strfrom])[[1]]+lcyl[strl]*lcyl[sxshift], (lcyl[strfrom])[[2]]+lcyl[strl]*lcyl[syshift], (lcyl[strfrom])[[3]]+lcyl[strl]*lcyl[szshift] ]; ]; (* Print[lcyl," ",lcyl[strfrom]," ",lcyl[strto]];*) ]; passTreeRecursive[lroot,thefunc]; ); attenuationTransform[lroot_]:=( passTreeRecursive[lroot, (#[strl]=N[Log[1.0/#[satten]]];)&]; ); delayTransform[lroot_]:=( passTreeRecursive[lroot, (#[strl]=N[#[spd]];)&]; ); vinAttenuationTransform[lroot_]:=( passTreeRecursive[lroot, (#[strl]=N[Log[1.0/#[svinatten]]];)&]; ); vinDelayTransform[lroot_]:=( passTreeRecursive[lroot, (#[strl]=N[#[svinpd]];)&]; ); electroNaiveTransform[lroot_]:=( passTreeRecursive[lroot, (#[strl]=N[#[selectl]];)&]; ); makeAttenuationTransform:=( For[i=1,i<=dendnum,i++, Print["phase 1, dendrite ",i]; If[i!=somaIsDendnum, attenuationTransform[cyl[i,1]]; ]; ]; For[i=1,i<=dendnum,i++, Print["phase 2, dendrite ",i]; If[i!=somaIsDendnum,( prepareTransformCoordinates[cyl[i,1]]; )]; ]; ) makeDelayTransform:=( For[i=1,i<=dendnum,i++, Print["phase 1, dendrite ",i]; If[i!=somaIsDendnum, delayTransform[cyl[i,1]]; ]; ]; For[i=1,i<=dendnum,i++, Print["phase 2, dendrite ",i]; If[i!=somaIsDendnum,( prepareTransformCoordinates[cyl[i,1]]; )]; ]; ) makeVinAttenuationTransform:=( For[i=1,i<=dendnum,i++, Print["phase 1, dendrite ",i]; If[i!=somaIsDendnum, vinAttenuationTransform[cyl[i,1]]; ]; ]; For[i=1,i<=dendnum,i++, Print["phase 2, dendrite ",i]; If[i!=somaIsDendnum,( prepareTransformCoordinates[cyl[i,1]]; )]; ]; ) makeVinDelayTransform:=( For[i=1,i<=dendnum,i++, Print["phase 1, dendrite ",i]; If[i!=somaIsDendnum, vinDelayTransform[cyl[i,1]]; ]; ]; For[i=1,i<=dendnum,i++, Print["phase 2, dendrite ",i]; If[i!=somaIsDendnum,( prepareTransformCoordinates[cyl[i,1]]; )]; ]; ) makeElectroNaiveTransform:=( For[i=1,i<=dendnum,i++, Print["phase 1, dendrite ",i]; If[i!=somaIsDendnum, electroNaiveTransform[cyl[i,1]]; ]; ]; For[i=1,i<=dendnum,i++, Print["phase 2, dendrite ",i]; If[i!=somaIsDendnum,( prepareTransformCoordinates[cyl[i,1]]; )]; ]; ) branchesFromRoot[lcyl_]:=( If[Length[lcyl]==0,0, 1+branchesFromRoot[lcyl[sparent]] ] ) realdistanceFromRoot[lcyl_]:=( If[Length[lcyl]==0,0, lcyl[sl]+realdistanceFromRoot[lcyl[sparent]] ] ) electricdistanceFromRoot[lcyl_]:=( If[Length[lcyl]==0,0, lcyl[selectl]+electricdistanceFromRoot[lcyl[sparent]] ] ) propdelayFromRoot[lcyl_]:=( If[Length[lcyl]==0,0, lcyl[spd]+propdelayFromRoot[lcyl[sparent]] ] ) listOfTips:= Module[{i,tmplist={}}, For[i=1,i<=dendnum,i++, If[i!=somaIsDendnum,( passTreeRecursive[cyl[i,1],( If[Length[#[schildren]]==0, tmplist=Append[tmplist,#] ] )&]; )]; ]; Print[TableForm[Map[{ StringDrop[ToString[#],{1,15}], realdistanceFromRoot[#], #[sto][[1]],#[sto][[2]],#[sto][[3]] }&,tmplist], TableHeadings -> {None, {"Name", "root dist", "x","y","z"}} ]] ]; traceToRoot[lcyl_]:=( If[Length[lcyl]==0,0, (Print[ StringDrop[ToString[lcyl],{1,15}]," ", lcyl[sto]," ", Map[StringDrop[ToString[#],{1,15}]&,lcyl[schildren]]]; traceToRoot[lcyl[sparent]]) ] ) showFewGraphs[graphlistin_]:= Module[{maxlength,i,tmplist,tmplength,graphs}, maxlength=0; For[i=1,i<=Length[graphlistin],i++,( tmplist= FullOptions[graphlistin[[i]][[1]],PlotRange]; maxlength=Max[maxlength, (tmplist[[1,2]]-tmplist[[1,1]])/ graphlistin[[i]][[2]] ]; )]; graphs={}; For[i=1,i<=Length[graphlistin],i++,( tmplist= FullOptions[graphlistin[[i]][[1]],PlotRange]; tmplength=maxlength*graphlistin[[i]][[2]]//N; graphs=Append[graphs, Show[graphlistin[[i]][[1]], AspectRatio->1, DisplayFunction->$DisplayFunction, PlotRange-> {{tmplist[[1,1]],N[tmplist[[1,1]]+tmplength]}, {tmplist[[2,1]],N[tmplist[[2,1]]+tmplength]}} ]] )]; graphs ] End[]; EndPackage[]; (* ;[s] 9:0,0;1237,1;1248,0;1315,1;1326,0;1516,1;1527,0;1598,1;1609,0;20851,-1; 2:5,12,10,Courier,1,12,0,0,0;4,12,10,Courier,3,12,0,0,0; ^*)