# seg2swc.awk # an awk script by Giorgio A. Ascoli (ascoli@gmu.edu) # to convert ArborVitae "seg" files into Southampton's SWC format # Current version 1.0 # Last modified 4/3/2000 # Usage: awk -f seg2swc.awk inputname > outputname # # 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. Senft S.L., Ascoli G.A. (1999): # Reconstruction of brain networks by algorithmic amplification of morphometry data. # Lecture Notes Computer Science 1606:25-33. # BEGIN { print "# converted from ArborVitae file" print "# by GAA's seg2swc" print "#" print "" stem=1 } $2 == "S" { tag = $3 myid++ lastparid = myid myparid = -1 lastbra = 0 print ("", myid, tag, $4, $5, $6, 0.5*$7, myparid, "") } $2 == "P" { stem++ } $2 == "C" { tag = $3 myid++ myparid = lastparid lastparid = myid print ("", myid, tag, $4, $5, $6, 0.5*$7, myparid, "") } $2 == "B" { tag = $3 myid++ myparid = lastparid lastparid = myid lastbra++ braid[lastbra] = myid print ("", myid, tag, $4, $5, $6, 0.5*$7, myparid, "") } $2 == "T" { tag = $3 myid++ myparid = lastparid if (braid[lastbra]) lastparid = braid[lastbra] else if (stem > 0 ) { lastparid = 1 stem-- } else { print " # error! not enough stems!" break } lastbra-- print ("", myid, tag, $4, $5, $6, 0.5*$7, myparid, "") }