| 1 |
package tax; |
| 2 |
|
| 3 |
import java.io.PrintStream; |
| 4 |
import java.util.ArrayList; |
| 5 |
|
| 6 |
import fileIO.FileFormat; |
| 7 |
import fileIO.ReadWrite; |
| 8 |
import fileIO.TextFile; |
| 9 |
import shared.Parse; |
| 10 |
import shared.Parser; |
| 11 |
import shared.PreParser; |
| 12 |
import shared.Shared; |
| 13 |
import shared.Timer; |
| 14 |
import shared.Tools; |
| 15 |
import stream.Read; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
public class IDTree { |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public static void main(String[] args){ |
| 34 |
Timer t=new Timer(); |
| 35 |
IDTree x=new IDTree(args); |
| 36 |
x.process(t); |
| 37 |
|
| 38 |
|
| 39 |
Shared.closeStream(x.outstream); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public IDTree(String[] args){ |
| 47 |
|
| 48 |
{ |
| 49 |
PreParser pp=new PreParser(args, getClass(), false); |
| 50 |
args=pp.args; |
| 51 |
outstream=pp.outstream; |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
Shared.capBuffers(4); |
| 56 |
ReadWrite.USE_PIGZ=ReadWrite.USE_UNPIGZ=true; |
| 57 |
ReadWrite.setZipThreads(Shared.threads()); |
| 58 |
|
| 59 |
|
| 60 |
Parser parser=new Parser(); |
| 61 |
|
| 62 |
|
| 63 |
for(int i=0; i<args.length; i++){ |
| 64 |
String arg=args[i]; |
| 65 |
|
| 66 |
|
| 67 |
String[] split=arg.split("="); |
| 68 |
String a=split[0].toLowerCase(); |
| 69 |
String b=split.length>1 ? split[1] : null; |
| 70 |
|
| 71 |
if(parser.parse(arg, a, b)){ |
| 72 |
|
| 73 |
}else if(a.equals("verbose")){ |
| 74 |
verbose=Parse.parseBoolean(b); |
| 75 |
}else if(a.equals("parse_flag_goes_here")){ |
| 76 |
|
| 77 |
}else{ |
| 78 |
outstream.println("Unknown parameter "+args[i]); |
| 79 |
assert(false) : "Unknown parameter "+args[i]; |
| 80 |
|
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
{ |
| 85 |
|
| 86 |
overwrite=parser.overwrite; |
| 87 |
append=parser.append; |
| 88 |
|
| 89 |
in1=parser.in1; |
| 90 |
|
| 91 |
out1=parser.out1; |
| 92 |
|
| 93 |
maxLines=parser.maxReads; |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
if(in1==null){throw new RuntimeException("Error - at least one input file is required.");} |
| 98 |
|
| 99 |
|
| 100 |
if(!Tools.testOutputFiles(overwrite, append, false, out1)){ |
| 101 |
outstream.println((out1==null)+", "+out1); |
| 102 |
throw new RuntimeException("\n\noverwrite="+overwrite+"; Can't write to output file "+out1+"\n"); |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
if(!Tools.testInputFiles(false, true, in1)){ |
| 107 |
throw new RuntimeException("\nCan't read some input files.\n"); |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
if(!Tools.testForDuplicateFiles(true, in1, out1)){ |
| 112 |
throw new RuntimeException("\nSome file names were specified multiple times.\n"); |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
ffout1=FileFormat.testOutput(out1, FileFormat.TEXT, null, true, overwrite, append, false); |
| 117 |
|
| 118 |
|
| 119 |
ffin1=FileFormat.testInput(in1, FileFormat.TEXT, null, true, true); |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
void process(Timer t){ |
| 128 |
|
| 129 |
ArrayList<IDNode> list=new ArrayList<IDNode>(); |
| 130 |
TextFile tf=new TextFile(in1); |
| 131 |
for(String line=tf.nextLine(); line!=null; line=tf.nextLine()){ |
| 132 |
if(maxLines>=0 && list.size()>=maxLines){break;} |
| 133 |
if(!line.startsWith("#")){ |
| 134 |
String[] split=line.split("\t"); |
| 135 |
double[] array=new double[list.size()]; |
| 136 |
for(int i=0; i<array.length; i++){ |
| 137 |
array[i]=Double.parseDouble(split[i+1]); |
| 138 |
} |
| 139 |
IDNode n=new IDNode(array, list.size(), split[0]); |
| 140 |
list.add(n); |
| 141 |
} |
| 142 |
} |
| 143 |
tf.close(); |
| 144 |
|
| 145 |
IDNode[] nodes=list.toArray(new IDNode[0]); |
| 146 |
IDNode head=IDNode.makeTree(nodes); |
| 147 |
|
| 148 |
StringBuilder sb=head.toNewick(); |
| 149 |
sb.append(';'); |
| 150 |
|
| 151 |
if(out1!=null){ |
| 152 |
ReadWrite.writeString(sb, out1); |
| 153 |
outstream.println("Wrote tree to "+out1); |
| 154 |
} |
| 155 |
|
| 156 |
t.stop(); |
| 157 |
outstream.println("Time: \t"+t); |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
boolean processReadPair(final Read r1, final Read r2){ |
| 171 |
throw new RuntimeException("TODO"); |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
private String in1=null; |
| 180 |
|
| 181 |
|
| 182 |
private String out1=null; |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
protected long linesProcessed=0; |
| 188 |
|
| 189 |
protected long maxLines=-1; |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
private final FileFormat ffin1; |
| 197 |
|
| 198 |
|
| 199 |
private final FileFormat ffout1; |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
private PrintStream outstream=System.err; |
| 207 |
|
| 208 |
public static boolean verbose=false; |
| 209 |
|
| 210 |
public boolean errorState=false; |
| 211 |
|
| 212 |
private boolean overwrite=true; |
| 213 |
|
| 214 |
private boolean append=false; |
| 215 |
|
| 216 |
} |