# Script for converting a ToL XML file into a Newick file. # Use Steve Coile's xmlparser first: # ftp://ftp.freefriends.org/arnold/Awkstuff/xmlparser.awk # Cam Webb BEGIN{ ORS = ""; last = "begin NODE"; depth = -1; } { gsub(/^\ */,"",$0); if (($0 == "begin NODE") && (last == "begin NODE")) { # down a set of branches if (depth >= 0) {print "("}; depth++; } else if (($0 == "begin NODE") && (last == "end NODE")) { # to the next in a polytomy print ","; last = "begin NODE"; } else if (($0 == "end NODE") && (last == "begin NODE")) { print label[depth]; last = "end NODE"; } else if (($0 == "end NODE") && (last == "end NODE")) { atnode = up[atnode]; depth--; print ")" label[depth]; } else if ($1 == "cdata") { label[depth] = gensub(/[\(\)\ ,.&;\/]+/, "_", "G", substr($0, 7)); } } END{ print ";\n"; }