| 1 |
package jgi; |
| 2 |
|
| 3 |
import java.io.File; |
| 4 |
import java.io.PrintStream; |
| 5 |
import java.text.SimpleDateFormat; |
| 6 |
import java.util.ArrayList; |
| 7 |
import java.util.Date; |
| 8 |
import java.util.TimeZone; |
| 9 |
|
| 10 |
import align2.BBMap; |
| 11 |
import assemble.Tadpole; |
| 12 |
import dna.Data; |
| 13 |
import driver.RenameAndMux; |
| 14 |
import fileIO.ByteFile; |
| 15 |
import fileIO.ByteFile1; |
| 16 |
import fileIO.ByteFile2; |
| 17 |
import fileIO.FileFormat; |
| 18 |
import fileIO.ReadWrite; |
| 19 |
import fileIO.TextFile; |
| 20 |
import shared.Parse; |
| 21 |
import shared.Parser; |
| 22 |
import shared.PreParser; |
| 23 |
import shared.Shared; |
| 24 |
import shared.Timer; |
| 25 |
import shared.Tools; |
| 26 |
import stream.ConcurrentGenericReadInputStream; |
| 27 |
import stream.ConcurrentReadInputStream; |
| 28 |
import stream.ConcurrentReadOutputStream; |
| 29 |
import stream.FastaReadInputStream; |
| 30 |
import stream.Read; |
| 31 |
import structures.ListNum; |
| 32 |
import tracker.ReadStats; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class DecontaminateByNormalization { |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public static void main(String[] args){ |
| 46 |
Timer t=new Timer(); |
| 47 |
DecontaminateByNormalization x=new DecontaminateByNormalization(args); |
| 48 |
x.process(t); |
| 49 |
|
| 50 |
|
| 51 |
Shared.closeStream(x.outstream); |
| 52 |
} |
| 53 |
|
| 54 |
public DecontaminateByNormalization(String[] args){ |
| 55 |
|
| 56 |
{ |
| 57 |
PreParser pp=new PreParser(args, getClass(), false); |
| 58 |
args=pp.args; |
| 59 |
outstream=pp.outstream; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
ReadWrite.USE_PIGZ=ReadWrite.USE_UNPIGZ=true; |
| 64 |
ReadWrite.setZipThreads(Shared.threads()); |
| 65 |
|
| 66 |
CoveragePileup.USE_WINDOW=true; |
| 67 |
|
| 68 |
final ArrayList<String> readNameFiles=new ArrayList<String>(); |
| 69 |
final ArrayList<String> refNameFiles=new ArrayList<String>(); |
| 70 |
int onlyProcessFirstN=-1; |
| 71 |
|
| 72 |
Parser parser=new Parser(); |
| 73 |
parser.overwrite=true; |
| 74 |
for(int i=0; i<args.length; i++){ |
| 75 |
String arg=args[i]; |
| 76 |
String[] split=arg.split("="); |
| 77 |
String a=split[0].toLowerCase(); |
| 78 |
String b=split.length>1 ? split[1] : null; |
| 79 |
|
| 80 |
if(Parser.parseQuality(arg, a, b)){ |
| 81 |
|
| 82 |
}else if(Parser.parseZip(arg, a, b)){ |
| 83 |
|
| 84 |
}else if(Parser.parseFasta(arg, a, b)){ |
| 85 |
|
| 86 |
}else if(Parser.parseCommonStatic(arg, a, b)){ |
| 87 |
|
| 88 |
}else if(parser.parseMapping(arg, a, b)){ |
| 89 |
|
| 90 |
}else if(a.equals("verbose")){ |
| 91 |
verbose=Parse.parseBoolean(b); |
| 92 |
ByteFile1.verbose=verbose; |
| 93 |
ByteFile2.verbose=verbose; |
| 94 |
stream.FastaReadInputStream.verbose=verbose; |
| 95 |
ConcurrentGenericReadInputStream.verbose=verbose; |
| 96 |
stream.FastqReadInputStream.verbose=verbose; |
| 97 |
ReadWrite.verbose=verbose; |
| 98 |
}else if(a.equals("minc")){ |
| 99 |
minc=Float.parseFloat(b); |
| 100 |
}else if(a.equals("minp")){ |
| 101 |
minp=Float.parseFloat(b); |
| 102 |
}else if(a.equals("minr")){ |
| 103 |
minr=Integer.parseInt(b); |
| 104 |
}else if(a.equals("minl")){ |
| 105 |
minl=Integer.parseInt(b); |
| 106 |
}else if(a.equals("mind") || a.equals("mindepth")){ |
| 107 |
minDepth=Integer.parseInt(b); |
| 108 |
}else if(a.equals("dp") || a.equals("depthpercentile")){ |
| 109 |
depthPercentile=Float.parseFloat(b); |
| 110 |
assert(depthPercentile>=0 && depthPercentile<=1) : "depthPercentile must be between 0 and 1."; |
| 111 |
}else if(a.equals("minprob")){ |
| 112 |
minprob=Float.parseFloat(b); |
| 113 |
assert(minprob>=0 && minprob<=1) : "minprob must be between 0 and 1."; |
| 114 |
}else if(a.equals("minratio") || a.equals("ratio")){ |
| 115 |
minRatio=Double.parseDouble(b); |
| 116 |
}else if(a.equals("basesundermin")){ |
| 117 |
basesUnderMin=Integer.parseInt(b); |
| 118 |
}else if(a.equals("onlyprocessfirstn") || a.equals("opfn")){ |
| 119 |
onlyProcessFirstN=Integer.parseInt(b); |
| 120 |
}else if(a.equals("window")){ |
| 121 |
CoveragePileup.LOW_COV_WINDOW=Integer.parseInt(b); |
| 122 |
}else if(a.equals("windowcov")){ |
| 123 |
CoveragePileup.LOW_COV_DEPTH=Double.parseDouble(b); |
| 124 |
}else if(a.equals("mapraw")){ |
| 125 |
mapRawReads=Parse.parseBoolean(b); |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
else if(a.equals("tadpole") || a.equals("ecctadpole") || a.equals("ecct") || a.equals("ecc")){ |
| 130 |
ecct=Parse.parseBoolean(b); |
| 131 |
}else if(a.equals("tadpoleaggressive") || a.equals("aggressive") || a.equals("aecc")){ |
| 132 |
tadpoleAggressive=Parse.parseBoolean(b); |
| 133 |
if(tadpoleAggressive){tadpoleConservative=false;} |
| 134 |
}else if(a.equals("tadpoleconservative") || a.equals("conservative") || a.equals("cecc")){ |
| 135 |
tadpoleConservative=Parse.parseBoolean(b); |
| 136 |
if(tadpoleConservative){tadpoleAggressive=false;} |
| 137 |
}else if(a.equals("kt") || a.equals("ktadpole") || a.equals("tadpolek")){ |
| 138 |
tadpoleK=Integer.parseInt(b); |
| 139 |
}else if(a.equals("tadpoleprefilter") || a.equals("tadpre")){ |
| 140 |
tadpolePrefilter=Integer.parseInt(b); |
| 141 |
} |
| 142 |
|
| 143 |
else if(a.equals("k")){ |
| 144 |
normK=Integer.parseInt(b); |
| 145 |
}else if(a.equals("target")){ |
| 146 |
normTarget=Integer.parseInt(b); |
| 147 |
}else if(a.equals("hashes")){ |
| 148 |
normHashes=Integer.parseInt(b); |
| 149 |
}else if(a.equals("passes")){ |
| 150 |
normPasses=Integer.parseInt(b); |
| 151 |
}else if(a.equals("kfilter")){ |
| 152 |
kfilter=Integer.parseInt(b); |
| 153 |
}else if(a.equals("ambig") || a.equals("ambiguous")){ |
| 154 |
ambigMode=b; |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
else if(a.equals("prefilter")){ |
| 169 |
prefilter=Parse.parseBoolean(b); |
| 170 |
}else if(a.equals("filterbits") || a.equals("fbits")){ |
| 171 |
filterBits=Integer.parseInt(b); |
| 172 |
}else if(a.equals("prefilterbits") || a.equals("prebits") || a.equals("pbits")){ |
| 173 |
prefilterBits=Integer.parseInt(b); |
| 174 |
}else if(a.equals("logname") || a.equals("log")){ |
| 175 |
logName=b; |
| 176 |
}else if(a.equals("resultsname") || a.equals("results") || a.equals("summary")){ |
| 177 |
resultsName=b; |
| 178 |
}else if(a.equals("tempdir") || a.equals("tmpdir")){ |
| 179 |
tempdir=b; |
| 180 |
}else if(a.equals("outdir") || a.equals("out")){ |
| 181 |
outdir=b; |
| 182 |
}else if(a.equals("ref") || a.equals("refs")){ |
| 183 |
assert(b!=null) : "Bad parameter: "+arg; |
| 184 |
String[] split2=b.split(","); |
| 185 |
for(String name : split2){ |
| 186 |
refNames.add(name); |
| 187 |
} |
| 188 |
}else if(a.equals("read") || a.equals("reads") || a.equals("data")){ |
| 189 |
assert(b!=null) : "Bad parameter: "+arg; |
| 190 |
String[] split2=b.split(","); |
| 191 |
for(String name : split2){ |
| 192 |
readNames.add(name); |
| 193 |
} |
| 194 |
}else if(a.equals("refnamefile") || a.equals("refnamelist")){ |
| 195 |
assert(b!=null) : "Bad parameter: "+arg; |
| 196 |
String[] split2=b.split(","); |
| 197 |
for(String name : split2){ |
| 198 |
refNameFiles.add(name); |
| 199 |
} |
| 200 |
}else if(a.equals("readnamefile") || a.equals("readnamelist")){ |
| 201 |
assert(b!=null) : "Bad parameter: "+arg; |
| 202 |
String[] split2=b.split(","); |
| 203 |
for(String name : split2){ |
| 204 |
readNameFiles.add(name); |
| 205 |
} |
| 206 |
}else{ |
| 207 |
outstream.println("Unknown parameter "+args[i]); |
| 208 |
assert(false) : "Unknown parameter "+args[i]; |
| 209 |
|
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
{ |
| 214 |
Parser.processQuality(); |
| 215 |
|
| 216 |
maxReads=parser.maxReads; |
| 217 |
|
| 218 |
overwrite=ReadStats.overwrite=parser.overwrite; |
| 219 |
} |
| 220 |
|
| 221 |
parseStringsFromFiles(readNameFiles); |
| 222 |
parseStringsFromFiles(refNameFiles); |
| 223 |
|
| 224 |
readNames.addAll(readNameFiles); |
| 225 |
refNames.addAll(refNameFiles); |
| 226 |
|
| 227 |
assert(readNames.size()==refNames.size()) : "Must have same number of read and assembly files. "+readNames.size()+"!="+refNames.size(); |
| 228 |
|
| 229 |
while(onlyProcessFirstN>0 && onlyProcessFirstN<readNames.size()){ |
| 230 |
readNames.remove(readNames.size()-1); |
| 231 |
refNames.remove(refNames.size()-1); |
| 232 |
} |
| 233 |
|
| 234 |
|
| 235 |
if(outdir!=null && outdir.length()>0 && !outdir.endsWith("/")){outdir=outdir+"/";} |
| 236 |
if(tempdir!=null && tempdir.length()>0 && !tempdir.endsWith("/")){tempdir=tempdir+"/";} |
| 237 |
|
| 238 |
assert(FastaReadInputStream.settingsOK()); |
| 239 |
|
| 240 |
if(!ByteFile.FORCE_MODE_BF1 && !ByteFile.FORCE_MODE_BF2 && Shared.threads()>2){ |
| 241 |
ByteFile.FORCE_MODE_BF2=true; |
| 242 |
} |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
void process(Timer t){ |
| 250 |
log("Decontaminate start", false); |
| 251 |
String mergePath=tempdir+"_merged.fq.gz"; |
| 252 |
String tadpolePath=tempdir+"_corrected.fq.gz"; |
| 253 |
String normPath=tempdir+"_normalized.fq.gz"; |
| 254 |
|
| 255 |
if(mapRawReads){ |
| 256 |
map(readNames, refNames, 0); |
| 257 |
} |
| 258 |
renameAndMux_MT(readNames, mergePath); |
| 259 |
if(ecct){ |
| 260 |
eccTadpole(mergePath, tadpolePath); |
| 261 |
if(deleteFiles){ReadWrite.delete(mergePath, verbose);} |
| 262 |
mergePath=tadpolePath; |
| 263 |
} |
| 264 |
normalize(mergePath, normPath, normK, minDepth, normTarget, normHashes, normPasses, ecc, prefilter, normalizeByLowerDepth); |
| 265 |
if(deleteFiles){ReadWrite.delete(mergePath, verbose);} |
| 266 |
demux(normPath, readNames); |
| 267 |
if(deleteFiles){ReadWrite.delete(normPath, verbose);} |
| 268 |
map(readNames, refNames, 1); |
| 269 |
filter(readNames, refNames); |
| 270 |
|
| 271 |
t.stop(); |
| 272 |
|
| 273 |
outstream.println("Time: \t"+t); |
| 274 |
log("Decontaminate finish", true); |
| 275 |
} |
| 276 |
|
| 277 |
public static void parseStringsFromFiles(ArrayList<String> list){ |
| 278 |
String[] x=list.toArray(new String[list.size()]); |
| 279 |
list.clear(); |
| 280 |
for(String s : x){ |
| 281 |
File f=new File(s); |
| 282 |
if(f.exists() && f.isFile()){ |
| 283 |
TextFile tf=new TextFile(s); |
| 284 |
String[] lines=tf.toStringLines(); |
| 285 |
for(String s2 : lines){ |
| 286 |
list.add(s2); |
| 287 |
} |
| 288 |
}else{ |
| 289 |
list.add(s); |
| 290 |
} |
| 291 |
} |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
private void renameAndMux_ST(ArrayList<String> readPaths, String fnameOut){ |
| 299 |
log("renameAndMux start", true); |
| 300 |
System.err.println("\nRename/Merge Phase Start"); |
| 301 |
|
| 302 |
FileFormat ffout=FileFormat.testOutput(fnameOut, FileFormat.FASTQ, null, true, true, false, false); |
| 303 |
|
| 304 |
long readsProcessed=0; |
| 305 |
long basesProcessed=0; |
| 306 |
|
| 307 |
for(String in : readPaths){ |
| 308 |
|
| 309 |
final FileFormat ffin=FileFormat.testInput(in, FileFormat.FASTQ, null, true, true); |
| 310 |
final ConcurrentReadInputStream cris; |
| 311 |
final String core=ReadWrite.stripToCore(in); |
| 312 |
{ |
| 313 |
cris=ConcurrentReadInputStream.getReadInputStream(maxReads, true, ffin, null); |
| 314 |
if(verbose){outstream.println("Started cris");} |
| 315 |
cris.start(); |
| 316 |
} |
| 317 |
boolean paired=cris.paired(); |
| 318 |
if(!ffin.samOrBam()){outstream.println("Input is being processed as "+(paired ? "paired" : "unpaired"));} |
| 319 |
final ConcurrentReadOutputStream ros; |
| 320 |
|
| 321 |
final int buff=4; |
| 322 |
|
| 323 |
if(cris.paired()){ |
| 324 |
outstream.println("Writing interleaved."); |
| 325 |
} |
| 326 |
|
| 327 |
assert(!in.equalsIgnoreCase(fnameOut)) : "Input file and output file have same name."; |
| 328 |
|
| 329 |
ros=ConcurrentReadOutputStream.getStream(ffout, null, buff, null, false); |
| 330 |
ros.start(); |
| 331 |
|
| 332 |
{ |
| 333 |
|
| 334 |
ListNum<Read> ln=cris.nextList(); |
| 335 |
ArrayList<Read> reads=(ln!=null ? ln.list : null); |
| 336 |
|
| 337 |
if(reads!=null && !reads.isEmpty()){ |
| 338 |
Read r=reads.get(0); |
| 339 |
assert((r.mate!=null)==cris.paired()); |
| 340 |
} |
| 341 |
|
| 342 |
while(ln!=null && reads!=null && reads.size()>0){ |
| 343 |
|
| 344 |
for(int idx=0; idx<reads.size(); idx++){ |
| 345 |
final Read r1=reads.get(idx); |
| 346 |
final Read r2=r1.mate; |
| 347 |
|
| 348 |
final int initialLength1=r1.length(); |
| 349 |
final int initialLength2=(r1.mateLength()); |
| 350 |
|
| 351 |
{ |
| 352 |
readsProcessed++; |
| 353 |
basesProcessed+=initialLength1; |
| 354 |
r1.id=core+"_"+r1.numericID+" 1:"; |
| 355 |
} |
| 356 |
if(r2!=null){ |
| 357 |
readsProcessed++; |
| 358 |
basesProcessed+=initialLength2; |
| 359 |
r2.id=core+"_"+r1.numericID+" 2:"; |
| 360 |
} |
| 361 |
|
| 362 |
|
| 363 |
} |
| 364 |
|
| 365 |
final ArrayList<Read> listOut=reads; |
| 366 |
|
| 367 |
if(ros!=null){ros.add(listOut, ln.id);} |
| 368 |
|
| 369 |
cris.returnList(ln); |
| 370 |
ln=cris.nextList(); |
| 371 |
reads=(ln!=null ? ln.list : null); |
| 372 |
} |
| 373 |
if(ln!=null){ |
| 374 |
cris.returnList(ln.id, ln.list==null || ln.list.isEmpty()); |
| 375 |
} |
| 376 |
} |
| 377 |
|
| 378 |
errorState|=ReadWrite.closeStreams(cris, ros); |
| 379 |
|
| 380 |
ffout=FileFormat.testOutput(fnameOut, FileFormat.FASTQ, null, true, false, true, false); |
| 381 |
} |
| 382 |
log("renameAndMux finish", true); |
| 383 |
} |
| 384 |
|
| 385 |
private void renameAndMux_MT(ArrayList<String> readPaths, String fnameOut){ |
| 386 |
log("renameAndMux start", true); |
| 387 |
System.err.println("\nRename/Merge Phase Start"); |
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
ArrayList<String> argList=new ArrayList<String>(); |
| 392 |
|
| 393 |
{ |
| 394 |
argList.add("out="+fnameOut); |
| 395 |
|
| 396 |
StringBuilder sb=new StringBuilder("in="); |
| 397 |
String comma=""; |
| 398 |
for(String s : readPaths){ |
| 399 |
sb.append(comma); |
| 400 |
sb.append(s); |
| 401 |
comma=","; |
| 402 |
} |
| 403 |
argList.add(sb.toString()); |
| 404 |
} |
| 405 |
|
| 406 |
String[] args=argList.toArray(new String[0]); |
| 407 |
|
| 408 |
{ |
| 409 |
int oldZT=ReadWrite.MAX_ZIP_THREADS(); |
| 410 |
boolean oldUP=ReadWrite.USE_PIGZ; |
| 411 |
boolean oldUU=ReadWrite.USE_UNPIGZ; |
| 412 |
try { |
| 413 |
RenameAndMux.main(args); |
| 414 |
} catch (Exception e) { |
| 415 |
e.printStackTrace(); |
| 416 |
log("failed", true); |
| 417 |
System.exit(1); |
| 418 |
} |
| 419 |
ReadWrite.setZipThreads(oldZT); |
| 420 |
ReadWrite.USE_PIGZ=oldUP; |
| 421 |
ReadWrite.USE_UNPIGZ=oldUU; |
| 422 |
} |
| 423 |
|
| 424 |
log("renameAndMux finish", true); |
| 425 |
} |
| 426 |
|
| 427 |
private void eccTadpole(String fnameIn, String fnameOut){ |
| 428 |
log("tadpole start", true); |
| 429 |
System.err.println("\nTadpole Phase Start"); |
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
ArrayList<String> argList=new ArrayList<String>(); |
| 434 |
|
| 435 |
{ |
| 436 |
argList.add("in="+fnameIn); |
| 437 |
argList.add("out="+fnameOut); |
| 438 |
argList.add("k="+tadpoleK); |
| 439 |
argList.add("mode=correct"); |
| 440 |
if(tadpoleAggressive){ |
| 441 |
argList.add("aggressive"); |
| 442 |
}else if(tadpoleConservative){ |
| 443 |
argList.add("conservative"); |
| 444 |
} |
| 445 |
if(tadpolePrefilter>=0){ |
| 446 |
argList.add("prefilter="+tadpolePrefilter); |
| 447 |
} |
| 448 |
argList.add("prealloc="+tadpolePrealloc); |
| 449 |
} |
| 450 |
|
| 451 |
String[] args=argList.toArray(new String[0]); |
| 452 |
|
| 453 |
{ |
| 454 |
int oldZT=ReadWrite.MAX_ZIP_THREADS(); |
| 455 |
boolean oldUP=ReadWrite.USE_PIGZ; |
| 456 |
boolean oldUU=ReadWrite.USE_UNPIGZ; |
| 457 |
try { |
| 458 |
Tadpole.main(args); |
| 459 |
} catch (Exception e) { |
| 460 |
e.printStackTrace(); |
| 461 |
log("failed", true); |
| 462 |
System.exit(1); |
| 463 |
} |
| 464 |
ReadWrite.setZipThreads(oldZT); |
| 465 |
ReadWrite.USE_PIGZ=oldUP; |
| 466 |
ReadWrite.USE_UNPIGZ=oldUU; |
| 467 |
} |
| 468 |
|
| 469 |
log("tadpole finish", true); |
| 470 |
} |
| 471 |
|
| 472 |
private void normalize(String fnameIn, String fnameOut, int k, int min, int target, int hashes, int passes, boolean ecc, boolean prefilter, boolean uselowerdepth){ |
| 473 |
log("normalization start", true); |
| 474 |
System.err.println("\nNormalization/Error Correction Phase Start"); |
| 475 |
|
| 476 |
ArrayList<String> argList=new ArrayList<String>(); |
| 477 |
|
| 478 |
{ |
| 479 |
argList.add("ecc="+ecc); |
| 480 |
if(ecc && aecc){argList.add("aecc="+aecc);} |
| 481 |
if(ecc && cecc){argList.add("cecc="+cecc);} |
| 482 |
argList.add("prefilter="+prefilter); |
| 483 |
argList.add("bits="+filterBits); |
| 484 |
argList.add("prebits="+prefilterBits); |
| 485 |
argList.add("hashes="+hashes); |
| 486 |
argList.add("passes="+passes); |
| 487 |
argList.add("target="+target); |
| 488 |
argList.add("k="+k); |
| 489 |
argList.add("mindepth="+min); |
| 490 |
argList.add("maxdepth="+target); |
| 491 |
argList.add("minprob="+minprob); |
| 492 |
argList.add("dp="+depthPercentile); |
| 493 |
argList.add("in="+fnameIn); |
| 494 |
argList.add("out="+fnameOut); |
| 495 |
argList.add("uld="+uselowerdepth); |
| 496 |
} |
| 497 |
|
| 498 |
String[] normargs=argList.toArray(new String[0]); |
| 499 |
|
| 500 |
{ |
| 501 |
try { |
| 502 |
KmerNormalize.main(normargs); |
| 503 |
} catch (Exception e) { |
| 504 |
e.printStackTrace(); |
| 505 |
log("failed", true); |
| 506 |
System.exit(1); |
| 507 |
} |
| 508 |
} |
| 509 |
|
| 510 |
log("normalization finish", true); |
| 511 |
} |
| 512 |
|
| 513 |
private void demux(String fnameIn, ArrayList<String> readPaths){ |
| 514 |
log("demux start", true); |
| 515 |
System.err.println("\nDemux Phase Start"); |
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
ArrayList<String> argList=new ArrayList<String>(); |
| 520 |
|
| 521 |
{ |
| 522 |
|
| 523 |
argList.add("in="+fnameIn); |
| 524 |
argList.add("out="+tempdir+"%_demuxed.fq.gz"); |
| 525 |
|
| 526 |
StringBuilder sb=new StringBuilder("names="); |
| 527 |
String comma=""; |
| 528 |
for(String s : readPaths){ |
| 529 |
sb.append(comma); |
| 530 |
sb.append(ReadWrite.stripToCore(s)); |
| 531 |
comma=","; |
| 532 |
} |
| 533 |
argList.add(sb.toString()); |
| 534 |
} |
| 535 |
|
| 536 |
String[] args=argList.toArray(new String[0]); |
| 537 |
|
| 538 |
{ |
| 539 |
int oldZT=ReadWrite.MAX_ZIP_THREADS(); |
| 540 |
boolean oldUP=ReadWrite.USE_PIGZ; |
| 541 |
boolean oldUU=ReadWrite.USE_UNPIGZ; |
| 542 |
ReadWrite.setZipThreads(Tools.mid(ReadWrite.MAX_ZIP_THREADS(), 2, 4)); |
| 543 |
try { |
| 544 |
DemuxByName.main(args); |
| 545 |
} catch (Exception e) { |
| 546 |
e.printStackTrace(); |
| 547 |
log("failed", true); |
| 548 |
System.exit(1); |
| 549 |
} |
| 550 |
ReadWrite.setZipThreads(oldZT); |
| 551 |
ReadWrite.USE_PIGZ=oldUP; |
| 552 |
ReadWrite.USE_UNPIGZ=oldUU; |
| 553 |
} |
| 554 |
|
| 555 |
log("demux finish", true); |
| 556 |
} |
| 557 |
|
| 558 |
private void map(ArrayList<String> readPaths, ArrayList<String> refnames, int pass){ |
| 559 |
log("map start", true); |
| 560 |
System.err.println("\nMapping Phase Start"); |
| 561 |
|
| 562 |
for(int i=0; i<readPaths.size(); i++){ |
| 563 |
final String path=readPaths.get(i); |
| 564 |
final String ref=refnames.get(i); |
| 565 |
final String core=ReadWrite.stripToCore(path); |
| 566 |
final String demuxed=tempdir+core+"_demuxed.fq.gz"; |
| 567 |
final String dir=(outdir==null ? "" : outdir); |
| 568 |
|
| 569 |
final String infile=(pass==0 ? path : demuxed); |
| 570 |
|
| 571 |
ArrayList<String> argList=new ArrayList<String>(); |
| 572 |
|
| 573 |
{ |
| 574 |
argList.add("in="+infile); |
| 575 |
argList.add("ref="+ref); |
| 576 |
argList.add("covstats="+dir+core+"_covstats"+pass+".txt"); |
| 577 |
argList.add("arrays=t"); |
| 578 |
argList.add("nodisk"); |
| 579 |
argList.add("ambig="+ambigMode); |
| 580 |
if(kfilter>1){argList.add("kfilter="+kfilter);} |
| 581 |
argList.add("fast"); |
| 582 |
argList.add("ow="+overwrite); |
| 583 |
argList.add("minscaf=0"); |
| 584 |
} |
| 585 |
|
| 586 |
String[] args=argList.toArray(new String[0]); |
| 587 |
|
| 588 |
{ |
| 589 |
try { |
| 590 |
BBMap.main(args); |
| 591 |
} catch (Exception e) { |
| 592 |
e.printStackTrace(); |
| 593 |
log("failed", true); |
| 594 |
System.exit(1); |
| 595 |
} |
| 596 |
} |
| 597 |
Data.unloadAll(); |
| 598 |
} |
| 599 |
|
| 600 |
log("map finish", true); |
| 601 |
} |
| 602 |
|
| 603 |
private void filter(ArrayList<String> readPaths, ArrayList<String> refnames){ |
| 604 |
|
| 605 |
log("filter start", true); |
| 606 |
System.err.println("\nFiltering Phase Start"); |
| 607 |
|
| 608 |
for(int i=0; i<readPaths.size(); i++){ |
| 609 |
String path=readPaths.get(i); |
| 610 |
String ref=refnames.get(i); |
| 611 |
String core=ReadWrite.stripToCore(path); |
| 612 |
String dir=(outdir==null ? "" : outdir); |
| 613 |
String stats0=mapRawReads ? (outdir==null ? "" : outdir)+core+"_covstats0.txt" : null; |
| 614 |
String stats1=(outdir==null ? "" : outdir)+core+"_covstats1.txt"; |
| 615 |
String results=(resultsName==null ? "" : (resultsName.contains("/") || resultsName.contains("\\") ? resultsName : (outdir==null ? "" : outdir)+resultsName)); |
| 616 |
|
| 617 |
ArrayList<String> argList=new ArrayList<String>(); |
| 618 |
|
| 619 |
{ |
| 620 |
argList.add("log="+results); |
| 621 |
argList.add("appendlog="+(i>0)); |
| 622 |
argList.add("logheader="+(i==0)); |
| 623 |
if(stats0!=null){argList.add("cov0="+stats0);} |
| 624 |
argList.add("cov1="+stats1); |
| 625 |
argList.add("in="+ref); |
| 626 |
argList.add("out="+dir+core+"_clean.fasta"); |
| 627 |
argList.add("outd="+dir+core+"_dirty.fasta"); |
| 628 |
argList.add("minc="+minc); |
| 629 |
argList.add("minp="+minp); |
| 630 |
argList.add("minr="+minr); |
| 631 |
argList.add("minl="+minl); |
| 632 |
argList.add("basesundermin="+basesUnderMin); |
| 633 |
if(stats0!=null){argList.add("minratio="+minRatio);} |
| 634 |
argList.add("ow="+overwrite); |
| 635 |
} |
| 636 |
|
| 637 |
String[] args=argList.toArray(new String[0]); |
| 638 |
|
| 639 |
{ |
| 640 |
try { |
| 641 |
FilterByCoverage.main(args); |
| 642 |
} catch (Exception e) { |
| 643 |
e.printStackTrace(); |
| 644 |
log("failed", true); |
| 645 |
System.exit(1); |
| 646 |
} |
| 647 |
} |
| 648 |
} |
| 649 |
|
| 650 |
log("filter finish", true); |
| 651 |
} |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
private void log(String message, boolean append){ |
| 659 |
if(logName!=null){ |
| 660 |
ReadWrite.writeString(message+", "+timeString()+"\n", logName, append); |
| 661 |
} |
| 662 |
} |
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
public static String timeString(){ |
| 669 |
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| 670 |
|
| 671 |
sdf.setTimeZone(TimeZone.getDefault()); |
| 672 |
return sdf.format(new Date()); |
| 673 |
} |
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
private final ArrayList<String> readNames=new ArrayList<String>(); |
| 682 |
private final ArrayList<String> refNames=new ArrayList<String>(); |
| 683 |
|
| 684 |
private String logName=null; |
| 685 |
private String resultsName="results.txt"; |
| 686 |
private String tempdir=(Shared.tmpdir() == null ? "" : Shared.tmpdir()); |
| 687 |
private String outdir=null; |
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
private int kfilter=55; |
| 693 |
private String ambigMode="random"; |
| 694 |
|
| 695 |
private long maxReads=-1; |
| 696 |
|
| 697 |
private float minc=3.5f; |
| 698 |
private float minp=20; |
| 699 |
private int minr=20; |
| 700 |
private int minl=500; |
| 701 |
|
| 702 |
|
| 703 |
private boolean deleteFiles=true; |
| 704 |
|
| 705 |
|
| 706 |
private boolean ecct=false; |
| 707 |
private boolean tadpoleAggressive=false; |
| 708 |
private boolean tadpoleConservative=false; |
| 709 |
private boolean tadpolePrealloc=true; |
| 710 |
private int tadpoleK=42; |
| 711 |
private int tadpolePrefilter=1; |
| 712 |
|
| 713 |
|
| 714 |
private int basesUnderMin=-1; |
| 715 |
|
| 716 |
private float depthPercentile=0.75f; |
| 717 |
private float minprob=0.5f; |
| 718 |
private int minDepth=2; |
| 719 |
private int normK=31; |
| 720 |
private int normTarget=20; |
| 721 |
private int normHashes=4; |
| 722 |
private int normPasses=1; |
| 723 |
private int filterBits=32; |
| 724 |
private int prefilterBits=2; |
| 725 |
private boolean ecc=false; |
| 726 |
private boolean cecc=false; |
| 727 |
private boolean aecc=false; |
| 728 |
private boolean prefilter=true; |
| 729 |
private boolean normalizeByLowerDepth=false; |
| 730 |
|
| 731 |
private double minRatio=1.2f; |
| 732 |
private boolean mapRawReads=true; |
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
private PrintStream outstream=System.err; |
| 739 |
public static boolean verbose=false; |
| 740 |
public boolean errorState=false; |
| 741 |
private boolean overwrite=true; |
| 742 |
|
| 743 |
} |