| 1 |
package assemble; |
| 2 |
|
| 3 |
import java.io.File; |
| 4 |
import java.io.PrintStream; |
| 5 |
import java.util.ArrayList; |
| 6 |
|
| 7 |
import align2.BBMap; |
| 8 |
import dna.Data; |
| 9 |
import fileIO.ByteFile; |
| 10 |
import fileIO.FileFormat; |
| 11 |
import fileIO.ReadWrite; |
| 12 |
import jgi.FilterByCoverage; |
| 13 |
import shared.Parse; |
| 14 |
import shared.PreParser; |
| 15 |
import shared.Shared; |
| 16 |
import shared.Timer; |
| 17 |
import shared.Tools; |
| 18 |
import tracker.ReadStats; |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
public class Postfilter { |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public static void main(String[] args){ |
| 32 |
Timer t=new Timer(); |
| 33 |
|
| 34 |
|
| 35 |
Postfilter x=new Postfilter(args, true); |
| 36 |
|
| 37 |
|
| 38 |
x.process(t); |
| 39 |
|
| 40 |
|
| 41 |
Shared.closeStream(outstream); |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public Postfilter(String[] args, boolean setDefaults){ |
| 49 |
|
| 50 |
{ |
| 51 |
PreParser pp=new PreParser(args, getClass(), false); |
| 52 |
args=pp.args; |
| 53 |
outstream=pp.outstream; |
| 54 |
} |
| 55 |
|
| 56 |
if(setDefaults){ |
| 57 |
|
| 58 |
ReadWrite.ZIPLEVEL=8; |
| 59 |
ReadWrite.USE_UNPIGZ=true; |
| 60 |
ReadWrite.USE_PIGZ=true; |
| 61 |
if(!ByteFile.FORCE_MODE_BF1 && !ByteFile.FORCE_MODE_BF2 && Shared.threads()>2){ |
| 62 |
ByteFile.FORCE_MODE_BF2=true; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
for(int i=0; i<args.length; i++){ |
| 68 |
final String arg=args[i]; |
| 69 |
String[] split=arg.split("="); |
| 70 |
String a=split[0].toLowerCase(); |
| 71 |
String b=split.length>1 ? split[1] : null; |
| 72 |
|
| 73 |
if(a.equals("append") || a.equals("app")){ |
| 74 |
append=ReadStats.append=Parse.parseBoolean(b); |
| 75 |
}else if(a.equals("overwrite") || a.equals("ow")){ |
| 76 |
overwrite=Parse.parseBoolean(b); |
| 77 |
}else if(a.equals("in") || a.equals("in1")){ |
| 78 |
in1=b; |
| 79 |
}else if(a.equals("in2")){ |
| 80 |
in2=b; |
| 81 |
}else if(a.equals("ref") || a.equals("contigs") || a.equals("assembly")){ |
| 82 |
ref=b; |
| 83 |
}else if(a.equals("out") || a.equals("out1")){ |
| 84 |
out=b; |
| 85 |
}else if(a.equals("outdirty") || a.equals("outd") || a.equals("outbad")){ |
| 86 |
outdirty=b; |
| 87 |
}else if(a.equals("showstats")){ |
| 88 |
showStats=Parse.parseBoolean(b); |
| 89 |
}else if(a.equals("covstats") || a.equals("cov")){ |
| 90 |
covstats=b; |
| 91 |
}else if(a.equals("maxindel")){ |
| 92 |
maxIndel=Integer.parseInt(b); |
| 93 |
}else if(a.equals("minhits")){ |
| 94 |
minHits=Integer.parseInt(b); |
| 95 |
}else if(a.equals("minc") || a.equals("mincov") || a.equals("mincoverage")){ |
| 96 |
minCoverage=Double.parseDouble(b); |
| 97 |
}else if(a.equals("minp") || a.equals("minpercent")){ |
| 98 |
minCoveredPercent=Double.parseDouble(b); |
| 99 |
}else if(a.equals("minr") || a.equals("minreads")){ |
| 100 |
minReads=Parse.parseKMG(b); |
| 101 |
}else if(a.equals("minl") || a.equals("minlen") || a.equals("minlength")){ |
| 102 |
minLength=Integer.parseInt(b); |
| 103 |
}else if(a.equals("rescue")){ |
| 104 |
rescue=Parse.parseBoolean(b); |
| 105 |
}else if(a.equals("trim") || a.equals("trimends")){ |
| 106 |
if(b==null || Character.isLetter(b.charAt(0))){ |
| 107 |
trimEnds=Parse.parseBoolean(b) ? 100 : 0; |
| 108 |
}else{ |
| 109 |
trimEnds=Integer.parseInt(b); |
| 110 |
} |
| 111 |
trimEnds=Tools.max(trimEnds, 0); |
| 112 |
}else{ |
| 113 |
mapArgs.add(arg); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
if(in2==null && in1!=null && in1.contains("#") && !new File(in1).exists()){ |
| 118 |
in2=in1.replaceFirst("#", "2"); |
| 119 |
in1=in1.replaceFirst("#", "1"); |
| 120 |
} |
| 121 |
|
| 122 |
if(!Tools.testOutputFiles(overwrite, append, false, covstats, out)){ |
| 123 |
throw new RuntimeException("\n\noverwrite="+overwrite+"; Can't write to output files "+ |
| 124 |
covstats+", "+out+"\n"); |
| 125 |
} |
| 126 |
if(!Tools.testInputFiles(false, true, in1, in2, ref)){ |
| 127 |
throw new RuntimeException("\nCan't read some input files.\n"); |
| 128 |
} |
| 129 |
if(!Tools.testForDuplicateFiles(true, in1, in2, covstats, out, ref)){ |
| 130 |
throw new RuntimeException("\nSome file names were specified multiple times.\n"); |
| 131 |
} |
| 132 |
|
| 133 |
assert(in1!=null); |
| 134 |
assert(out!=null); |
| 135 |
assert(ref!=null); |
| 136 |
assert(covstats!=null); |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
public void process(Timer t){ |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
mapArgs.add("in="+in1); |
| 151 |
if(in2!=null){mapArgs.add("in2="+in2);} |
| 152 |
mapArgs.add("ref="+ref); |
| 153 |
mapArgs.add("covstats="+covstats); |
| 154 |
mapArgs.add("ambig=all"); |
| 155 |
mapArgs.add("minhits="+minHits); |
| 156 |
mapArgs.add("maxindel="+maxIndel); |
| 157 |
mapArgs.add("nodisk"); |
| 158 |
mapArgs.add("append="+append); |
| 159 |
mapArgs.add("ow="+overwrite); |
| 160 |
mapArgs.add("bw="+bw); |
| 161 |
mapArgs.add("tipsearch="+tipsearch); |
| 162 |
mapArgs.add("rescue="+rescue); |
| 163 |
BBMap.main(mapArgs.toArray(new String[0])); |
| 164 |
Data.unloadAll(); |
| 165 |
|
| 166 |
mapArgs.clear(); |
| 167 |
mapArgs.add("in="+ref); |
| 168 |
mapArgs.add("out="+out); |
| 169 |
if(outdirty!=null){mapArgs.add("outdirty="+outdirty);} |
| 170 |
mapArgs.add("covstats="+covstats); |
| 171 |
mapArgs.add("mincov="+minCoverage); |
| 172 |
mapArgs.add("minr="+minReads); |
| 173 |
mapArgs.add("minp="+minCoveredPercent); |
| 174 |
mapArgs.add("minl="+minLength); |
| 175 |
mapArgs.add("trim="+trimEnds); |
| 176 |
mapArgs.add("append="+append); |
| 177 |
mapArgs.add("ow="+overwrite); |
| 178 |
FilterByCoverage.main(mapArgs.toArray(new String[0])); |
| 179 |
|
| 180 |
if(showStats && out!=null && !FileFormat.isStdio(out)){ |
| 181 |
outstream.println(); |
| 182 |
jgi.AssemblyStats2.main(new String[] {"in="+out}); |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
private ArrayList<String> mapArgs=new ArrayList<String>(); |
| 191 |
|
| 192 |
private String in1=null; |
| 193 |
private String in2=null; |
| 194 |
private String ref=null; |
| 195 |
private String out="filtered.fa"; |
| 196 |
private String outdirty=null; |
| 197 |
private String covstats="covstats.txt"; |
| 198 |
|
| 199 |
private int maxIndel=0; |
| 200 |
private int minHits=2; |
| 201 |
private int bw=20; |
| 202 |
private int tipsearch=0; |
| 203 |
private boolean rescue=false; |
| 204 |
|
| 205 |
private int trimEnds=0; |
| 206 |
|
| 207 |
private double minCoverage=2; |
| 208 |
private double minCoveredPercent=95; |
| 209 |
private long minReads=6; |
| 210 |
private int minLength=400; |
| 211 |
|
| 212 |
boolean showStats=true; |
| 213 |
|
| 214 |
boolean append=false; |
| 215 |
boolean overwrite=true; |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
private static PrintStream outstream=System.err; |
| 223 |
|
| 224 |
} |