| 1 |
package bloom; |
| 2 |
|
| 3 |
import java.io.File; |
| 4 |
import java.io.PrintStream; |
| 5 |
import java.util.ArrayList; |
| 6 |
|
| 7 |
import dna.AminoAcid; |
| 8 |
import fileIO.ByteFile; |
| 9 |
import fileIO.FileFormat; |
| 10 |
import fileIO.ReadWrite; |
| 11 |
import jgi.BBMerge; |
| 12 |
import shared.Parse; |
| 13 |
import shared.Parser; |
| 14 |
import shared.PreParser; |
| 15 |
import shared.Shared; |
| 16 |
import shared.Timer; |
| 17 |
import shared.Tools; |
| 18 |
import stream.ConcurrentReadInputStream; |
| 19 |
import stream.ConcurrentReadOutputStream; |
| 20 |
import stream.FASTQ; |
| 21 |
import stream.FastaReadInputStream; |
| 22 |
import stream.Read; |
| 23 |
import stream.SamLine; |
| 24 |
import structures.ListNum; |
| 25 |
import structures.LongList; |
| 26 |
import tracker.ReadStats; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class BloomFilterWrapper { |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public static void main(String[] args){ |
| 46 |
|
| 47 |
Timer t=new Timer(); |
| 48 |
|
| 49 |
|
| 50 |
BloomFilterWrapper x=new BloomFilterWrapper(args); |
| 51 |
|
| 52 |
|
| 53 |
x.process(t); |
| 54 |
|
| 55 |
|
| 56 |
Shared.closeStream(x.outstream); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
public BloomFilterWrapper(String[] args){ |
| 64 |
|
| 65 |
{ |
| 66 |
PreParser pp=new PreParser(args, getClass(), false); |
| 67 |
args=pp.args; |
| 68 |
outstream=pp.outstream; |
| 69 |
} |
| 70 |
|
| 71 |
boolean setInterleaved=false; |
| 72 |
|
| 73 |
|
| 74 |
ReadWrite.USE_PIGZ=ReadWrite.USE_UNPIGZ=true; |
| 75 |
ReadWrite.setZipThreads(Tools.max(Shared.threads()>1 ? 2 : 1, Shared.threads()>20 ? Shared.threads()/2 : Shared.threads())); |
| 76 |
SamLine.SET_FROM_OK=true; |
| 77 |
|
| 78 |
|
| 79 |
Parser parser=new Parser(); |
| 80 |
|
| 81 |
boolean setBits=false; |
| 82 |
int k_=31; |
| 83 |
int hashes_=2; |
| 84 |
int minConsecutiveMatches_=3; |
| 85 |
int bits_=1; |
| 86 |
int minCount_=1; |
| 87 |
boolean rcomp_=true; |
| 88 |
boolean requireBothToMatch_=false; |
| 89 |
boolean ecco_=false; |
| 90 |
boolean merge_=false; |
| 91 |
|
| 92 |
|
| 93 |
for(int i=0; i<args.length; i++){ |
| 94 |
String arg=args[i]; |
| 95 |
|
| 96 |
|
| 97 |
String[] split=arg.split("="); |
| 98 |
String a=split[0].toLowerCase(); |
| 99 |
String b=split.length>1 ? split[1] : null; |
| 100 |
|
| 101 |
if(a.equals("verbose")){ |
| 102 |
verbose=Parse.parseBoolean(b); |
| 103 |
}else if(a.equals("ordered")){ |
| 104 |
ordered=Parse.parseBoolean(b); |
| 105 |
} |
| 106 |
|
| 107 |
else if(a.equalsIgnoreCase("k") || a.equalsIgnoreCase("bloomK") || a.equalsIgnoreCase("bloomFilterK")){ |
| 108 |
k_=Integer.parseInt(b); |
| 109 |
}else if(a.equalsIgnoreCase("hashes") || a.equalsIgnoreCase("bloomHashes") || a.equalsIgnoreCase("bloomFilterHashes")){ |
| 110 |
hashes_=Integer.parseInt(b); |
| 111 |
}else if(a.equalsIgnoreCase("minhits") || a.equalsIgnoreCase("bloomMinHits") || a.equalsIgnoreCase("bloomFilterMinHits")){ |
| 112 |
minConsecutiveMatches_=Integer.parseInt(b); |
| 113 |
}else if(a.equals("rcomp")){ |
| 114 |
rcomp_=Parse.parseBoolean(b); |
| 115 |
}else if(a.equals("bits")){ |
| 116 |
setBits=true; |
| 117 |
bits_=Integer.parseInt(b); |
| 118 |
assert(bits_>0); |
| 119 |
}else if(a.equals("mincount")){ |
| 120 |
minCount_=Integer.parseInt(b); |
| 121 |
|
| 122 |
|
| 123 |
}else if(a.equals("minprob")){ |
| 124 |
ReadCounter.minProb=Float.parseFloat(b); |
| 125 |
}else if(a.equals("requireboth")){ |
| 126 |
requireBothToMatch_=Parse.parseBoolean(b); |
| 127 |
}else if(a.equals("ecco")){ |
| 128 |
ecco_=Parse.parseBoolean(b); |
| 129 |
}else if(a.equals("merge")){ |
| 130 |
merge_=Parse.parseBoolean(b); |
| 131 |
}else if(a.equals("memfraction") || a.equals("memmult") || a.equals("memratio")){ |
| 132 |
memFraction=Float.parseFloat(b); |
| 133 |
}else if(a.equals("cells")){ |
| 134 |
BloomFilter.OVERRIDE_CELLS=Parse.parseKMG(b); |
| 135 |
}else if(a.equals("seed")){ |
| 136 |
KCountArray7MTA.setSeed(Parse.parseKMG(b)); |
| 137 |
} |
| 138 |
|
| 139 |
else if(a.equals("serialin")){ |
| 140 |
serialIn=b; |
| 141 |
}else if(a.equals("serialout")){ |
| 142 |
serialOut=b; |
| 143 |
} |
| 144 |
|
| 145 |
else if(a.equals("ref")){ |
| 146 |
boolean result=Tools.addFiles(b, ref); |
| 147 |
assert(result) : "Could not add file(s): "+b; |
| 148 |
}else if(a.equals("outm") || a.equals("outm1") || a.equals("outbad") || a.equals("outbad1") || a.equals("outmatch") || a.equals("outmatch1")){ |
| 149 |
outm1=b; |
| 150 |
}else if(a.equals("outm2") || a.equals("outbad2") || a.equals("outmatch2")){ |
| 151 |
outm2=b; |
| 152 |
}else if(a.equals("outu") || a.equals("outu1") || a.equals("out") || a.equals("out1")){ |
| 153 |
out1=b; |
| 154 |
}else if(a.equals("outu2") || a.equals("out2")){ |
| 155 |
out2=b; |
| 156 |
}else if(a.equals("outc") || a.equals("counts")){ |
| 157 |
outc=b; |
| 158 |
}else if(a.equals("parse_flag_goes_here")){ |
| 159 |
long fake_variable=Parse.parseKMG(b); |
| 160 |
|
| 161 |
}else if(parser.parse(arg, a, b)){ |
| 162 |
|
| 163 |
}else{ |
| 164 |
outstream.println("Unknown parameter "+args[i]); |
| 165 |
assert(false) : "Unknown parameter "+args[i]; |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
while(minCount_>0 && (1L<<bits_)-1<minCount_){bits_*=2;} |
| 170 |
|
| 171 |
k=k_; |
| 172 |
bits=bits_; |
| 173 |
hashes=hashes_; |
| 174 |
minConsecutiveMatches=minConsecutiveMatches_; |
| 175 |
minCount=minCount_; |
| 176 |
rcomp=rcomp_; |
| 177 |
requireBothToMatch=requireBothToMatch_; |
| 178 |
ecco=ecco_; |
| 179 |
merge=merge_; |
| 180 |
KmerCountAbstract.CANONICAL=rcomp; |
| 181 |
|
| 182 |
shift=bitsPerBase*k; |
| 183 |
shift2=shift-bitsPerBase; |
| 184 |
mask=(shift>63 ? -1L : ~((-1L)<<shift)); |
| 185 |
|
| 186 |
{ |
| 187 |
Parser.processQuality(); |
| 188 |
|
| 189 |
maxReads=parser.maxReads; |
| 190 |
|
| 191 |
overwrite=ReadStats.overwrite=parser.overwrite; |
| 192 |
append=ReadStats.append=parser.append; |
| 193 |
setInterleaved=parser.setInterleaved; |
| 194 |
|
| 195 |
in1=parser.in1; |
| 196 |
in2=parser.in2; |
| 197 |
qfin1=parser.qfin1; |
| 198 |
qfin2=parser.qfin2; |
| 199 |
|
| 200 |
qfout1=parser.qfout1; |
| 201 |
qfout2=parser.qfout2; |
| 202 |
|
| 203 |
extin=parser.extin; |
| 204 |
extout=parser.extout; |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
if(in1!=null && in2==null && in1.indexOf('#')>-1 && !new File(in1).exists()){ |
| 209 |
in2=in1.replace("#", "2"); |
| 210 |
in1=in1.replace("#", "1"); |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
if(out1!=null && out2==null && out1.indexOf('#')>-1){ |
| 215 |
out2=out1.replace("#", "2"); |
| 216 |
out1=out1.replace("#", "1"); |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
if(outm1!=null && outm2==null && outm1.indexOf('#')>-1){ |
| 221 |
outm2=outm1.replace("#", "2"); |
| 222 |
outm1=outm1.replace("#", "1"); |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
if(in2!=null){ |
| 227 |
if(FASTQ.FORCE_INTERLEAVED){outstream.println("Reset INTERLEAVED to false because paired input files were specified.");} |
| 228 |
FASTQ.FORCE_INTERLEAVED=FASTQ.TEST_INTERLEAVED=false; |
| 229 |
} |
| 230 |
|
| 231 |
assert(FastaReadInputStream.settingsOK()); |
| 232 |
|
| 233 |
|
| 234 |
if(in1==null){throw new RuntimeException("Error - at least one input file is required.");} |
| 235 |
|
| 236 |
|
| 237 |
if(!ByteFile.FORCE_MODE_BF1 && !ByteFile.FORCE_MODE_BF2 && Shared.threads()>2){ |
| 238 |
ByteFile.FORCE_MODE_BF2=true; |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
if(out1==null && out2!=null){throw new RuntimeException("Error - cannot define out2 without defining out1.");} |
| 243 |
|
| 244 |
|
| 245 |
if(!setInterleaved){ |
| 246 |
assert(in1!=null && (out1!=null || out2==null)) : "\nin1="+in1+"\nin2="+in2+"\nout1="+out1+"\nout2="+out2+"\n"; |
| 247 |
if(in2!=null){ |
| 248 |
FASTQ.FORCE_INTERLEAVED=FASTQ.TEST_INTERLEAVED=false; |
| 249 |
outstream.println("Set INTERLEAVED to "+FASTQ.FORCE_INTERLEAVED); |
| 250 |
}else{ |
| 251 |
if(out2!=null){ |
| 252 |
FASTQ.FORCE_INTERLEAVED=true; |
| 253 |
FASTQ.TEST_INTERLEAVED=false; |
| 254 |
outstream.println("Set INTERLEAVED to "+FASTQ.FORCE_INTERLEAVED); |
| 255 |
} |
| 256 |
} |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
if(!Tools.testOutputFiles(overwrite, append, false, out1, out2, outm1, outm2)){ |
| 261 |
outstream.println((out1==null)+", "+(out2==null)+", "+out1+", "+out2); |
| 262 |
throw new RuntimeException("\n\noverwrite="+overwrite+"; Can't write to output files "+out1+", "+out2+"\n"); |
| 263 |
} |
| 264 |
|
| 265 |
|
| 266 |
if(!Tools.testInputFiles(false, true, in1, in2)){ |
| 267 |
throw new RuntimeException("\nCan't read some input files.\n"); |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
if(!Tools.testForDuplicateFiles(true, in1, in2, out1, out2, outm1, outm2)){ |
| 272 |
throw new RuntimeException("\nSome file names were specified multiple times.\n"); |
| 273 |
} |
| 274 |
|
| 275 |
|
| 276 |
ffout1=FileFormat.testOutput(out1, FileFormat.FASTQ, extout, true, overwrite, append, ordered); |
| 277 |
ffout2=FileFormat.testOutput(out2, FileFormat.FASTQ, extout, true, overwrite, append, ordered); |
| 278 |
|
| 279 |
|
| 280 |
ffoutm1=FileFormat.testOutput(outm1, FileFormat.FASTQ, extout, true, overwrite, append, ordered); |
| 281 |
ffoutm2=FileFormat.testOutput(outm2, FileFormat.FASTQ, extout, true, overwrite, append, ordered); |
| 282 |
|
| 283 |
ffoutc=FileFormat.testOutput(outc, FileFormat.FASTA, extout, true, overwrite, append, ordered); |
| 284 |
|
| 285 |
|
| 286 |
ffin1=FileFormat.testInput(in1, FileFormat.FASTA, extin, true, true); |
| 287 |
ffin2=FileFormat.testInput(in2, FileFormat.FASTA, extin, true, true); |
| 288 |
|
| 289 |
{ |
| 290 |
Timer t=new Timer(outstream, true); |
| 291 |
if(serialIn==null){ |
| 292 |
filter=new BloomFilter(null, null, ref, k, k, bits, hashes, minConsecutiveMatches, |
| 293 |
rcomp, ecco, merge, memFraction); |
| 294 |
if(serialOut!=null){ |
| 295 |
ReadWrite.writeObjectInThread(filter, serialOut, true); |
| 296 |
} |
| 297 |
}else{ |
| 298 |
filter=ReadWrite.read(BloomFilter.class, serialIn, true); |
| 299 |
} |
| 300 |
t.stop("Filter creation: \t\t"); |
| 301 |
outstream.println(filter.filter.toShortString()); |
| 302 |
if(verbose){ |
| 303 |
outstream.println("Keys Counted: "+KmerCountAbstract.keysCounted); |
| 304 |
outstream.println("Increments: "+KmerCountAbstract.increments); |
| 305 |
} |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
void process(Timer t){ |
| 315 |
|
| 316 |
|
| 317 |
final boolean vic=Read.VALIDATE_IN_CONSTRUCTOR; |
| 318 |
Read.VALIDATE_IN_CONSTRUCTOR=Shared.threads()<4; |
| 319 |
|
| 320 |
|
| 321 |
final ConcurrentReadInputStream cris; |
| 322 |
{ |
| 323 |
cris=ConcurrentReadInputStream.getReadInputStream(maxReads, true, ffin1, ffin2, qfin1, qfin2); |
| 324 |
cris.start(); |
| 325 |
if(verbose){outstream.println("Started cris");} |
| 326 |
} |
| 327 |
boolean paired=cris.paired(); |
| 328 |
if(!ffin1.samOrBam()){outstream.println("Input is being processed as "+(paired ? "paired" : "unpaired"));} |
| 329 |
|
| 330 |
|
| 331 |
final ConcurrentReadOutputStream rosu, rosm, rosc; |
| 332 |
if(ffout1!=null){ |
| 333 |
|
| 334 |
final int buff=(ordered ? Tools.mid(16, 128, (Shared.threads()*2)/3) : 8); |
| 335 |
|
| 336 |
|
| 337 |
if(cris.paired() && out2==null && (in1!=null && !ffin1.samOrBam() && !ffout1.samOrBam())){ |
| 338 |
outstream.println("Writing interleaved."); |
| 339 |
} |
| 340 |
|
| 341 |
rosu=ConcurrentReadOutputStream.getStream(ffout1, ffout2, qfout1, qfout2, buff, null, false); |
| 342 |
rosu.start(); |
| 343 |
}else{rosu=null;} |
| 344 |
|
| 345 |
if(ffoutm1!=null){ |
| 346 |
|
| 347 |
final int buff=(ordered ? Tools.mid(16, 128, (Shared.threads()*2)/3) : 8); |
| 348 |
|
| 349 |
rosm=ConcurrentReadOutputStream.getStream(ffoutm1, ffoutm2, qfoutm1, qfoutm2, buff, null, false); |
| 350 |
rosm.start(); |
| 351 |
}else{rosm=null;} |
| 352 |
|
| 353 |
if(ffoutc!=null){ |
| 354 |
|
| 355 |
final int buff=(ordered ? Tools.mid(16, 128, (Shared.threads()*2)/3) : 8); |
| 356 |
|
| 357 |
rosc=ConcurrentReadOutputStream.getStream(ffoutc, null, buff, null, false); |
| 358 |
rosc.start(); |
| 359 |
}else{rosc=null;} |
| 360 |
|
| 361 |
|
| 362 |
readsProcessed=readsOut=0; |
| 363 |
basesProcessed=basesOut=0; |
| 364 |
|
| 365 |
Timer t2=new Timer(outstream, true); |
| 366 |
|
| 367 |
|
| 368 |
spawnThreads(cris, rosu, rosm, rosc); |
| 369 |
|
| 370 |
if(verbose){outstream.println("Finished; closing streams.");} |
| 371 |
|
| 372 |
|
| 373 |
errorState|=ReadStats.writeAll(); |
| 374 |
|
| 375 |
errorState|=ReadWrite.closeStreams(cris, rosu, rosm, rosc); |
| 376 |
|
| 377 |
|
| 378 |
Read.VALIDATE_IN_CONSTRUCTOR=vic; |
| 379 |
|
| 380 |
|
| 381 |
t.stop(); |
| 382 |
t2.stop("\nFiltering Time: \t\t"); |
| 383 |
outstream.println(Tools.timeReadsBasesProcessed(t, readsProcessed, basesProcessed, 8)); |
| 384 |
{ |
| 385 |
long readsMatched=(readsProcessed-readsOut); |
| 386 |
long basesMatched=(basesProcessed-basesOut); |
| 387 |
double rpct=readsMatched*100.0/readsProcessed; |
| 388 |
double bpct=basesMatched*100.0/basesProcessed; |
| 389 |
String rstring=Tools.padKMB(readsMatched, 8); |
| 390 |
String bstring=Tools.padKMB(basesMatched, 8); |
| 391 |
StringBuilder sb=new StringBuilder(); |
| 392 |
sb.append("Reads Matched: ").append(rstring).append(Tools.format(" \t%.2f%%", rpct)).append('\n'); |
| 393 |
sb.append("Bases Matched: ").append(bstring).append(Tools.format(" \t%.2f%%", bpct)); |
| 394 |
outstream.println(sb); |
| 395 |
} |
| 396 |
|
| 397 |
|
| 398 |
if(errorState){ |
| 399 |
throw new RuntimeException(getClass().getName()+" terminated in an error state; the output may be corrupt."); |
| 400 |
} |
| 401 |
} |
| 402 |
|
| 403 |
|
| 404 |
private void spawnThreads(final ConcurrentReadInputStream cris, |
| 405 |
final ConcurrentReadOutputStream rosu, final ConcurrentReadOutputStream rosm, |
| 406 |
final ConcurrentReadOutputStream rosc){ |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
final int threads=Shared.threads(); |
| 412 |
|
| 413 |
|
| 414 |
ArrayList<ProcessThread> alpt=new ArrayList<ProcessThread>(threads); |
| 415 |
for(int i=0; i<threads; i++){ |
| 416 |
alpt.add(new ProcessThread(cris, rosu, rosm, rosc, i)); |
| 417 |
} |
| 418 |
|
| 419 |
|
| 420 |
for(ProcessThread pt : alpt){ |
| 421 |
pt.start(); |
| 422 |
} |
| 423 |
|
| 424 |
|
| 425 |
boolean success=true; |
| 426 |
for(ProcessThread pt : alpt){ |
| 427 |
|
| 428 |
|
| 429 |
while(pt.getState()!=Thread.State.TERMINATED){ |
| 430 |
try { |
| 431 |
|
| 432 |
pt.join(); |
| 433 |
} catch (InterruptedException e) { |
| 434 |
|
| 435 |
e.printStackTrace(); |
| 436 |
} |
| 437 |
} |
| 438 |
|
| 439 |
|
| 440 |
readsProcessed+=pt.readsProcessedT; |
| 441 |
basesProcessed+=pt.basesProcessedT; |
| 442 |
readsOut+=pt.readsOutT; |
| 443 |
basesOut+=pt.basesOutT; |
| 444 |
success&=pt.success; |
| 445 |
} |
| 446 |
|
| 447 |
|
| 448 |
if(!success){errorState=true;} |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
} |
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
private class ProcessThread extends Thread { |
| 463 |
|
| 464 |
|
| 465 |
ProcessThread(final ConcurrentReadInputStream cris_, |
| 466 |
final ConcurrentReadOutputStream rosu_, final ConcurrentReadOutputStream rosm_, |
| 467 |
final ConcurrentReadOutputStream rosc_, final int tid_){ |
| 468 |
cris=cris_; |
| 469 |
rosu=rosu_; |
| 470 |
rosm=rosm_; |
| 471 |
rosc=rosc_; |
| 472 |
tid=tid_; |
| 473 |
} |
| 474 |
|
| 475 |
|
| 476 |
@Override |
| 477 |
public void run(){ |
| 478 |
|
| 479 |
|
| 480 |
processInner(); |
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
success=true; |
| 486 |
} |
| 487 |
|
| 488 |
|
| 489 |
void processInner(){ |
| 490 |
|
| 491 |
|
| 492 |
ListNum<Read> ln=cris.nextList(); |
| 493 |
|
| 494 |
ArrayList<Read> reads=(ln!=null ? ln.list : null); |
| 495 |
|
| 496 |
|
| 497 |
if(reads!=null && !reads.isEmpty()){ |
| 498 |
Read r=reads.get(0); |
| 499 |
assert(ffin1.samOrBam() || (r.mate!=null)==cris.paired()); |
| 500 |
} |
| 501 |
|
| 502 |
|
| 503 |
while(ln!=null && reads!=null && reads.size()>0){ |
| 504 |
|
| 505 |
ArrayList<Read> matched=new ArrayList<Read>(reads.size()); |
| 506 |
ArrayList<Read> counts=(rosc==null ? null : new ArrayList<Read>(reads.size())); |
| 507 |
|
| 508 |
|
| 509 |
for(int idx=0; idx<reads.size(); idx++){ |
| 510 |
Read r1=reads.get(idx); |
| 511 |
Read r2=r1.mate; |
| 512 |
final String r2id=r1.mateId(); |
| 513 |
|
| 514 |
|
| 515 |
if(!r1.validated()){r1.validate(true);} |
| 516 |
if(r2!=null && !r2.validated()){r2.validate(true);} |
| 517 |
|
| 518 |
|
| 519 |
final int initialLength1=r1.length(); |
| 520 |
final int initialLength2=r1.mateLength(); |
| 521 |
|
| 522 |
|
| 523 |
readsProcessedT+=r1.pairCount(); |
| 524 |
basesProcessedT+=initialLength1+initialLength2; |
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
{ |
| 529 |
if((ecco || merge) && r1!=null && r2!=null){ |
| 530 |
if(merge){ |
| 531 |
final int insert=BBMerge.findOverlapStrict(r1, r2, false); |
| 532 |
if(insert>0){ |
| 533 |
r2.reverseComplement(); |
| 534 |
r1=r1.joinRead(insert); |
| 535 |
r2=null; |
| 536 |
} |
| 537 |
}else if(ecco){ |
| 538 |
BBMerge.findOverlapStrict(r1, r2, true); |
| 539 |
} |
| 540 |
} |
| 541 |
|
| 542 |
if(rosc!=null){ |
| 543 |
addCounts(r1, counts); |
| 544 |
addCounts(r2, counts); |
| 545 |
} |
| 546 |
final boolean match=matchesFilter(r1, r2); |
| 547 |
if(match){ |
| 548 |
reads.set(idx, null); |
| 549 |
matched.add(r1); |
| 550 |
}else{ |
| 551 |
readsOutT+=r1.pairCount(); |
| 552 |
basesOutT+=r1.pairLength(); |
| 553 |
} |
| 554 |
} |
| 555 |
} |
| 556 |
|
| 557 |
|
| 558 |
if(rosu!=null){rosu.add(reads, ln.id);} |
| 559 |
if(rosm!=null){rosm.add(matched, ln.id);} |
| 560 |
if(rosc!=null){rosc.add(counts, ln.id);} |
| 561 |
|
| 562 |
|
| 563 |
cris.returnList(ln); |
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
ln=cris.nextList(); |
| 568 |
reads=(ln!=null ? ln.list : null); |
| 569 |
} |
| 570 |
|
| 571 |
|
| 572 |
if(ln!=null){ |
| 573 |
cris.returnList(ln.id, ln.list==null || ln.list.isEmpty()); |
| 574 |
} |
| 575 |
} |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
private void addCounts(Read r, ArrayList<Read> counts){ |
| 583 |
if(r==null){return;} |
| 584 |
final byte[] bases=r.bases; |
| 585 |
|
| 586 |
long kmer=0; |
| 587 |
long rkmer=0; |
| 588 |
int len=0; |
| 589 |
|
| 590 |
for(int i=0; i<bases.length; i++){ |
| 591 |
byte b=bases[i]; |
| 592 |
long x=AminoAcid.baseToNumber[b]; |
| 593 |
long x2=AminoAcid.baseToComplementNumber[b]; |
| 594 |
kmer=((kmer<<bitsPerBase)|x)&mask; |
| 595 |
rkmer=((rkmer>>>bitsPerBase)|(x2<<shift2))&mask; |
| 596 |
if(x<0){ |
| 597 |
len=0; |
| 598 |
kmer=rkmer=0; |
| 599 |
}else{ |
| 600 |
len++; |
| 601 |
if(len>=k){ |
| 602 |
long key=rcomp ? Tools.max(kmer, rkmer) : kmer; |
| 603 |
int count=filter.getCount(key); |
| 604 |
if(count>=minCount){ |
| 605 |
String s=AminoAcid.kmerToString(key, k); |
| 606 |
Read cread=new Read(s.getBytes(), null, ""+count, r.numericID); |
| 607 |
counts.add(cread); |
| 608 |
} |
| 609 |
} |
| 610 |
} |
| 611 |
} |
| 612 |
} |
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
boolean matchesFilter(final Read r1, final Read r2){ |
| 621 |
if(r2!=null && requireBothToMatch){ |
| 622 |
|
| 623 |
return filter.matches(r1, buffer, minCount) && filter.matches(r2, buffer, minCount); |
| 624 |
}else{ |
| 625 |
|
| 626 |
return filter.matchesEither(r1, r2, buffer, minCount); |
| 627 |
} |
| 628 |
} |
| 629 |
|
| 630 |
private final LongList buffer=minConsecutiveMatches>1 ? new LongList(150) : null; |
| 631 |
|
| 632 |
|
| 633 |
protected long readsProcessedT=0; |
| 634 |
|
| 635 |
protected long basesProcessedT=0; |
| 636 |
|
| 637 |
|
| 638 |
protected long readsOutT=0; |
| 639 |
|
| 640 |
protected long basesOutT=0; |
| 641 |
|
| 642 |
|
| 643 |
boolean success=false; |
| 644 |
|
| 645 |
|
| 646 |
private final ConcurrentReadInputStream cris; |
| 647 |
|
| 648 |
private final ConcurrentReadOutputStream rosu; |
| 649 |
|
| 650 |
private final ConcurrentReadOutputStream rosm; |
| 651 |
|
| 652 |
private final ConcurrentReadOutputStream rosc; |
| 653 |
|
| 654 |
final int tid; |
| 655 |
} |
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
private ArrayList<String> ref=new ArrayList<String>(); |
| 662 |
|
| 663 |
|
| 664 |
private String in1=null; |
| 665 |
|
| 666 |
private String in2=null; |
| 667 |
|
| 668 |
private String qfin1=null; |
| 669 |
private String qfin2=null; |
| 670 |
|
| 671 |
|
| 672 |
private String out1=null; |
| 673 |
|
| 674 |
private String out2=null; |
| 675 |
|
| 676 |
|
| 677 |
private String outc=null; |
| 678 |
|
| 679 |
private String qfout1=null; |
| 680 |
private String qfout2=null; |
| 681 |
|
| 682 |
|
| 683 |
private String outm1=null; |
| 684 |
|
| 685 |
private String outm2=null; |
| 686 |
|
| 687 |
private String qfoutm1=null; |
| 688 |
private String qfoutm2=null; |
| 689 |
|
| 690 |
|
| 691 |
private String extin=null; |
| 692 |
|
| 693 |
private String extout=null; |
| 694 |
|
| 695 |
private String serialIn=null; |
| 696 |
private String serialOut=null; |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
protected long readsProcessed=0; |
| 702 |
|
| 703 |
protected long basesProcessed=0; |
| 704 |
|
| 705 |
|
| 706 |
protected long readsOut=0; |
| 707 |
|
| 708 |
protected long basesOut=0; |
| 709 |
|
| 710 |
|
| 711 |
private long maxReads=-1; |
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
final FileFormat ffin1; |
| 719 |
|
| 720 |
final FileFormat ffin2; |
| 721 |
|
| 722 |
|
| 723 |
private final FileFormat ffout1; |
| 724 |
|
| 725 |
private final FileFormat ffout2; |
| 726 |
|
| 727 |
|
| 728 |
private final FileFormat ffoutm1; |
| 729 |
|
| 730 |
private final FileFormat ffoutm2; |
| 731 |
|
| 732 |
|
| 733 |
private final FileFormat ffoutc; |
| 734 |
|
| 735 |
final BloomFilter filter; |
| 736 |
|
| 737 |
final int k; |
| 738 |
final int hashes; |
| 739 |
final int bits; |
| 740 |
final int minConsecutiveMatches; |
| 741 |
final boolean rcomp; |
| 742 |
final boolean requireBothToMatch; |
| 743 |
final boolean ecco; |
| 744 |
final boolean merge; |
| 745 |
final int minCount; |
| 746 |
float memFraction=1.0f; |
| 747 |
|
| 748 |
final int bitsPerBase=BloomFilter.bitsPerBase; |
| 749 |
final int shift; |
| 750 |
final int shift2; |
| 751 |
final long mask; |
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
private PrintStream outstream=System.err; |
| 759 |
|
| 760 |
public static boolean verbose=false; |
| 761 |
|
| 762 |
public boolean errorState=false; |
| 763 |
|
| 764 |
private boolean overwrite=true; |
| 765 |
|
| 766 |
private boolean append=false; |
| 767 |
|
| 768 |
private boolean ordered=false; |
| 769 |
|
| 770 |
} |