package tax; import java.io.PrintStream; import java.util.ArrayList; import fileIO.FileFormat; import fileIO.ReadWrite; import fileIO.TextFile; import shared.Parse; import shared.Parser; import shared.PreParser; import shared.Shared; import shared.Timer; import shared.Tools; import stream.Read; /** * Creates a taxonomic tree from an identity matrix. * @author Brian Bushnell * @date July 1, 2016 * */ public class IDTree { /*--------------------------------------------------------------*/ /*---------------- Initialization ----------------*/ /*--------------------------------------------------------------*/ /** * Code entrance from the command line. * @param args Command line arguments */ public static void main(String[] args){ Timer t=new Timer(); IDTree x=new IDTree(args); x.process(t); //Close the print stream if it was redirected Shared.closeStream(x.outstream); } /** * Constructor. * @param args Command line arguments */ public IDTree(String[] args){ {//Preparse block for help, config files, and outstream PreParser pp=new PreParser(args, getClass(), false); args=pp.args; outstream=pp.outstream; } //Set shared static variables Shared.capBuffers(4); ReadWrite.USE_PIGZ=ReadWrite.USE_UNPIGZ=true; ReadWrite.setZipThreads(Shared.threads()); //Create a parser object Parser parser=new Parser(); //Parse each argument for(int i=0; i1 ? split[1] : null; if(parser.parse(arg, a, b)){//Parse standard flags in the parser //do nothing }else if(a.equals("verbose")){ verbose=Parse.parseBoolean(b); }else if(a.equals("parse_flag_goes_here")){ //Set a variable here }else{ outstream.println("Unknown parameter "+args[i]); assert(false) : "Unknown parameter "+args[i]; // throw new RuntimeException("Unknown parameter "+args[i]); } } {//Process parser fields overwrite=parser.overwrite; append=parser.append; in1=parser.in1; out1=parser.out1; maxLines=parser.maxReads; } //Ensure there is an input file if(in1==null){throw new RuntimeException("Error - at least one input file is required.");} //Ensure output files can be written if(!Tools.testOutputFiles(overwrite, append, false, out1)){ outstream.println((out1==null)+", "+out1); throw new RuntimeException("\n\noverwrite="+overwrite+"; Can't write to output file "+out1+"\n"); } //Ensure input files can be read if(!Tools.testInputFiles(false, true, in1)){ throw new RuntimeException("\nCan't read some input files.\n"); } //Ensure that no file was specified multiple times if(!Tools.testForDuplicateFiles(true, in1, out1)){ throw new RuntimeException("\nSome file names were specified multiple times.\n"); } //Create output FileFormat objects ffout1=FileFormat.testOutput(out1, FileFormat.TEXT, null, true, overwrite, append, false); //Create input FileFormat objects ffin1=FileFormat.testInput(in1, FileFormat.TEXT, null, true, true); } /*--------------------------------------------------------------*/ /*---------------- Outer Methods ----------------*/ /*--------------------------------------------------------------*/ /** Create read streams and process all data */ void process(Timer t){ ArrayList list=new ArrayList(); TextFile tf=new TextFile(in1); for(String line=tf.nextLine(); line!=null; line=tf.nextLine()){ if(maxLines>=0 && list.size()>=maxLines){break;} if(!line.startsWith("#")){ String[] split=line.split("\t"); double[] array=new double[list.size()]; for(int i=0; i