#!/bin/gawk -f # ^^^^^^^^^ this must point to your gawk executable (get GAWK at www.gnu.org) # Script to join newick files into a single megatree. Written for the # phylomatic project, but can be used as a general solution # Cam Webb # To use: cd to the trees/ directory and type ../tools/makemega # there must be a config file called makemega.config in trees/ # TO DO: modify so that an internal node name will be substituted by # an external tree, if that tree exists, assuming more information in # the external tree. BEGIN{ # Conservative switch if (ARGC > 1) { if (ARGV[1] == "-c") {MODE = "C"} } # read config file while ((getline < "makemega.config") > 0) { if (($0 !~ /^\ *\#/) && ($0 != "")) { # tidy lines gsub(/\ /,"",$0); if (substr($0,1,4)=="ROOT") {usefile["root"] = substr($0,6) ".new"} else { split($0, tmp, "_"); cfgfile[tmp[1]] = $0; } } } # for (i in cfgfile) {print i , cfgfile[i]} RS = "\x04"; # read files: "ls" | getline tmp2; nfiles = split(tmp2, file, "\n"); for (i = 1; i < nfiles; i++) { # for each newick file in the directory if (file[i] ~ /\.new$/) { gsub(/\.new$/,"",file[i]); split(file[i], tmp, "_"); tax = tmp[1]; # tax is the clade name if (gsub(/\.c$/,"",file[i]) == 1) {type[i] = "C"} else {type[i] = ""} # if the mode is conservative if (MODE=="C") { # does taxon occur in config? if