# ana2swc.awk # An AWK script by Giorgio A. Ascoli (ascoli@gmu.edu) # to convert Burke's "anat" files into Southampton's SWC format # First version 12/24/99 # Current version 1.0 # Last modified 12/24/99 # Usage: awk -f ana2swc.awk [somadiam=xx(um)] inputname > outputname # e.g. awk -f ana2swc.awk somadiam=60 M36c4.anat > M36c4.swc # # References: 1. Aho A.V., Kernighan B.W., Weinberger P.J. (1988): # The AWK Programming Language (Addison Wesley, New York). # # 2. Cannon R.C., Turner D.A., Pyapali G.K., Wheal H.V. (1998): # An on-line archive of reconstructed hippocampal neurons. # J. Neurosci. Methods 84(1-2):49-54. # # 3. Cullheim S. Fleshman J.W., Glenn L.L., Burke R.E. (1987): # Membrane area and dendritic structure in type-identified Triceps Surae alpha motoneurons. # J. Comp. Neurol. 255:68-81 # # # Note: If somadiam is not given, it is treated as zero... # # ############# # FUNCTIONS # ############# # function abs(value) {return sqrt(value^2)} # function min(val1, val2) {return val1 < val2 ? val1 : val2} # # ######### # BEGIN # ######### # BEGIN {# set the program variables sec_thick = 75 #section thickness } # end BEGIN # # ######## # MAIN # ######## # { # remember all the column-arrays data[NR]=$0 dend_num[NR]=$1 br_order[NR]=$2 seg_num[NR]=$4 x1[NR]=$6 y1[NR]=$7 z1_75[NR]=$8 z1_corr[NR]=$8 # some will be edited... x2[NR]=$9 y2[NR]=$10 z2_75[NR]=$11 seg_len[NR]=$12 seg_diam[NR]=0.01*$13 sum_seg_len=sum_seg_len+$12 }# end main # # ####### # END # ####### # END { for (line=1; line<=NR; line++) { if (br_order[line]==0 && seg_num[line]==1) seg_len[line]=seg_len[line]+0.5*somadiam # accounts for the soma diameter deltaquadro=((seg_len[line])^2-(x1[line]-x2[line])^2-(y1[line]-y2[line])^2) if (deltaquadro < 0) { # it means that reported length is shorter than possible in this section if (z1_corr[line] < (z2_75[line]-0.5*sec_thick)) z2_choice[line]=(z2_75[line]-sec_thick) else z2_choice[line]=z2_75[line] } # end if deltaquadro < 0 else { z_posroot=z1_corr[line]+sqrt(deltaquadro) z_negroot=z1_corr[line]-sqrt(deltaquadro) if ((z2_75[line] >= z_posroot && z_posroot >= (z2_75[line]-sec_thick)) || (z2_75[line] >= z_negroot && z_negroot >= (z2_75[line]-sec_thick))) { # Found a good z2! if ((z2_75[line] >= z_posroot && z_posroot >= (z2_75[line]-sec_thick)) && (z2_75[line] >= z_negroot && z_negroot >= (z2_75[line]-sec_thick))) z2_choice[line]=min(abs(z_posroot-z2_75[line]), abs(z_posroot-(z2_75[line]-sec_thick)))= z_posroot && z_posroot >= (z2_75[line]-sec_thick)) z2_choice[line]=z_posroot else z2_choice[line]=z_negroot } # end else two candidates } # end if found a good z2 else { z2_choice[line]= (min(abs(z_posroot-z2_75[line]), abs(z_negroot-z2_75[line]))) < (min(abs(z_posroot-(z2_75[line]-sec_thick)), abs(z_posroot-(z2_75[line]-sec_thick)))) ? (z2_75[line]) : (z2_75[line]-sec_thick) } # end else found a good z2 } # end else deltaquadro <0 calc_len[line]=sqrt((x1[line]-x2[line])^2+(y1[line]-y2[line])^2+(z1_corr[line]-z2_choice[line])^2) if (br_order[line]==0 && seg_num[line]==1) calc_len[line]=calc_len[line]-0.5*somadiam # accounts for the soma diameter sum_calc_len=sum_calc_len+calc_len[line] if (z2_choice[line] != z2_75[line]) { # need to correct z1 for (scannext=line+1; scannext<=NR; scannext++) { if (dend_num[scannext]==dend_num[line] && x1[scannext]==x2[line] && y1[scannext] == y2 [line]) z1_corr[scannext]=z2_choice[line] } # end for scannext } # end if need to correct z1 for (findpid=1; findpid