Debian Codegraph @

current/bloom/BloomFilterWrapper.java

raw symbols SCIP
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 * Wraps a BloomFilter to filter reads.
30 *
31 * @author Brian Bushnell
32 * @date April 23, 2018
33 *
34 */
35 public class BloomFilterWrapper {
36
37 /*--------------------------------------------------------------*/
38 /*---------------- Initialization ----------------*/
39 /*--------------------------------------------------------------*/
40
41 /**
42 * Code entrance from the command line.
43 * @param args Command line arguments
44 */
45 public static void main(String[] args){
46 //Start a timer immediately upon code entrance.
47 Timer t=new Timer();
48
49 //Create an instance of this class
50 BloomFilterWrapper x=new BloomFilterWrapper(args);
51
52 //Run the object
53 x.process(t);
54
55 //Close the print stream if it was redirected
56 Shared.closeStream(x.outstream);
57 }
58
59 /**
60 * Constructor.
61 * @param args Command line arguments
62 */
63 public BloomFilterWrapper(String[] args){
64
65 {//Preparse block for help, config files, and outstream
66 PreParser pp=new PreParser(args, getClass(), false);
67 args=pp.args;
68 outstream=pp.outstream;
69 }
70
71 boolean setInterleaved=false; //Whether interleaved was explicitly set.
72
73 //Set shared static variables
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 //Create a parser object
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 //Parse each argument
93 for(int i=0; i<args.length; i++){
94 String arg=args[i];
95
96 //Break arguments into their constituent parts, in the form of "a=b"
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 // assert(minCount_>=1) : "mincount must be at least 1.";
122 // minCount_=Tools.max(1, minCount_);
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 //Set a variable here
161 }else if(parser.parse(arg, a, b)){//Parse standard flags in the parser
162 //do nothing
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; //rcomp, or true, perhaps... hmmm.
181
182 shift=bitsPerBase*k;
183 shift2=shift-bitsPerBase;
184 mask=(shift>63 ? -1L : ~((-1L)<<shift));
185
186 {//Process parser fields
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 //Do input file # replacement
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 //Do output file # replacement
214 if(out1!=null && out2==null && out1.indexOf('#')>-1){
215 out2=out1.replace("#", "2");
216 out1=out1.replace("#", "1");
217 }
218
219 //Do output file # replacement
220 if(outm1!=null && outm2==null && outm1.indexOf('#')>-1){
221 outm2=outm1.replace("#", "2");
222 outm1=outm1.replace("#", "1");
223 }
224
225 //Adjust interleaved detection based on the number of input files
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 //Ensure there is an input file
234 if(in1==null){throw new RuntimeException("Error - at least one input file is required.");}
235
236 //Adjust the number of threads for input file reading
237 if(!ByteFile.FORCE_MODE_BF1 && !ByteFile.FORCE_MODE_BF2 && Shared.threads()>2){
238 ByteFile.FORCE_MODE_BF2=true;
239 }
240
241 //Ensure out2 is not set without out1
242 if(out1==null && out2!=null){throw new RuntimeException("Error - cannot define out2 without defining out1.");}
243
244 //Adjust interleaved settings based on number of output files
245 if(!setInterleaved){
246 assert(in1!=null && (out1!=null || out2==null)) : "\nin1="+in1+"\nin2="+in2+"\nout1="+out1+"\nout2="+out2+"\n";
247 if(in2!=null){ //If there are 2 input streams.
248 FASTQ.FORCE_INTERLEAVED=FASTQ.TEST_INTERLEAVED=false;
249 outstream.println("Set INTERLEAVED to "+FASTQ.FORCE_INTERLEAVED);
250 }else{ //There is one input stream.
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 //Ensure output files can be written
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 //Ensure input files can be read
266 if(!Tools.testInputFiles(false, true, in1, in2)){
267 throw new RuntimeException("\nCan't read some input files.\n");
268 }
269
270 //Ensure that no file was specified multiple times
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 //Create output FileFormat objects
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 //Create output FileFormat objects
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 //Create input FileFormat objects
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 /*---------------- Outer Methods ----------------*/
311 /*--------------------------------------------------------------*/
312
313 /** Create read streams and process all data */
314 void process(Timer t){
315
316 //Turn off read validation in the input threads to increase speed
317 final boolean vic=Read.VALIDATE_IN_CONSTRUCTOR;
318 Read.VALIDATE_IN_CONSTRUCTOR=Shared.threads()<4;
319
320 //Create a read input stream
321 final ConcurrentReadInputStream cris;
322 {
323 cris=ConcurrentReadInputStream.getReadInputStream(maxReads, true, ffin1, ffin2, qfin1, qfin2);
324 cris.start(); //Start the stream
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 //Optionally create read output streams
331 final ConcurrentReadOutputStream rosu, rosm, rosc;
332 if(ffout1!=null){
333 //Select output buffer size based on whether it needs to be ordered
334 final int buff=(ordered ? Tools.mid(16, 128, (Shared.threads()*2)/3) : 8);
335
336 //Notify user of output mode
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(); //Start the stream
343 }else{rosu=null;}
344
345 if(ffoutm1!=null){
346 //Select output buffer size based on whether it needs to be ordered
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(); //Start the stream
351 }else{rosm=null;}
352
353 if(ffoutc!=null){
354 //Select output buffer size based on whether it needs to be ordered
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(); //Start the stream
359 }else{rosc=null;}
360
361 //Reset counters
362 readsProcessed=readsOut=0;
363 basesProcessed=basesOut=0;
364
365 Timer t2=new Timer(outstream, true);
366
367 //Process the reads in separate threads
368 spawnThreads(cris, rosu, rosm, rosc);
369
370 if(verbose){outstream.println("Finished; closing streams.");}
371
372 //Write anything that was accumulated by ReadStats
373 errorState|=ReadStats.writeAll();
374 //Close the read streams
375 errorState|=ReadWrite.closeStreams(cris, rosu, rosm, rosc);
376
377 //Reset read validation
378 Read.VALIDATE_IN_CONSTRUCTOR=vic;
379
380 //Report timing and results
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 //Throw an exception of there was an error in a thread
398 if(errorState){
399 throw new RuntimeException(getClass().getName()+" terminated in an error state; the output may be corrupt.");
400 }
401 }
402
403 /** Spawn process threads */
404 private void spawnThreads(final ConcurrentReadInputStream cris,
405 final ConcurrentReadOutputStream rosu, final ConcurrentReadOutputStream rosm,
406 final ConcurrentReadOutputStream rosc){
407
408 //Do anything necessary prior to processing
409
410 //Determine how many threads may be used
411 final int threads=Shared.threads();
412
413 //Fill a list with ProcessThreads
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 //Start the threads
420 for(ProcessThread pt : alpt){
421 pt.start();
422 }
423
424 //Wait for completion of all threads
425 boolean success=true;
426 for(ProcessThread pt : alpt){
427
428 //Wait until this thread has terminated
429 while(pt.getState()!=Thread.State.TERMINATED){
430 try {
431 //Attempt a join operation
432 pt.join();
433 } catch (InterruptedException e) {
434 //Potentially handle this, if it is expected to occur
435 e.printStackTrace();
436 }
437 }
438
439 //Accumulate per-thread statistics
440 readsProcessed+=pt.readsProcessedT;
441 basesProcessed+=pt.basesProcessedT;
442 readsOut+=pt.readsOutT;
443 basesOut+=pt.basesOutT;
444 success&=pt.success;
445 }
446
447 //Track whether any threads failed
448 if(!success){errorState=true;}
449
450 //Do anything necessary after processing
451
452 }
453
454 /*--------------------------------------------------------------*/
455 /*---------------- Inner Methods ----------------*/
456 /*--------------------------------------------------------------*/
457
458 /*--------------------------------------------------------------*/
459 /*---------------- Inner Classes ----------------*/
460 /*--------------------------------------------------------------*/
461
462 private class ProcessThread extends Thread {
463
464 //Constructor
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 //Called by start()
476 @Override
477 public void run(){
478
479 //Process the reads
480 processInner();
481
482 //Do anything necessary after processing
483
484 //Indicate successful exit status
485 success=true;
486 }
487
488 /** Iterate through the reads */
489 void processInner(){
490
491 //Grab the first ListNum of reads
492 ListNum<Read> ln=cris.nextList();
493 //Grab the actual read list from the ListNum
494 ArrayList<Read> reads=(ln!=null ? ln.list : null);
495
496 //Check to ensure pairing is as expected
497 if(reads!=null && !reads.isEmpty()){
498 Read r=reads.get(0);
499 assert(ffin1.samOrBam() || (r.mate!=null)==cris.paired()); //Disabled due to non-static access
500 }
501
502 //As long as there is a nonempty read list...
503 while(ln!=null && reads!=null && reads.size()>0){//ln!=null prevents a compiler potential null access warning
504 // if(verbose){outstream.println("Fetched "+reads.size()+" reads.");} //Disabled due to non-static access
505 ArrayList<Read> matched=new ArrayList<Read>(reads.size());
506 ArrayList<Read> counts=(rosc==null ? null : new ArrayList<Read>(reads.size()));
507
508 //Loop through each read in the list
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 //Validate reads in worker threads
515 if(!r1.validated()){r1.validate(true);}
516 if(r2!=null && !r2.validated()){r2.validate(true);}
517
518 //Track the initial length for statistics
519 final int initialLength1=r1.length();
520 final int initialLength2=r1.mateLength();
521
522 //Increment counters
523 readsProcessedT+=r1.pairCount();
524 basesProcessedT+=initialLength1+initialLength2;
525
526
527 //Reads are processed in this block.
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 //Output reads to the output streams
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 //Notify the input stream that the list was used
563 cris.returnList(ln);
564 // if(verbose){outstream.println("Returned a list.");} //Disabled due to non-static access
565
566 //Fetch a new list
567 ln=cris.nextList();
568 reads=(ln!=null ? ln.list : null);
569 }
570
571 //Notify the input stream that the final list was used
572 if(ln!=null){
573 cris.returnList(ln.id, ln.list==null || ln.list.isEmpty());
574 }
575 }
576
577 /**
578 * Breaks a read into kmers and adds them, with their counts, to the new list.
579 * @param r Read to process
580 * @param counts Output list of kmers (bases) and counts (read name)
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 * Process a read or a read pair.
616 * @param r1 Read 1
617 * @param r2 Read 2 (may be null)
618 * @return True if the reads should be kept (meaning they don't match the filter), false if they should be discarded.
619 */
620 boolean matchesFilter(final Read r1, final Read r2){
621 if(r2!=null && requireBothToMatch){
622 // assert(false) : minCount+", "+filter.matches(r1, buffer, minCount)+", "+filter.matches(r2, buffer, minCount)+" "+filter.matchesEither(r1, r2, buffer, minCount);
623 return filter.matches(r1, buffer, minCount) && filter.matches(r2, buffer, minCount);
624 }else{
625 // assert(false) : minCount+", "+filter.matches(r1, buffer, minCount)+", "+filter.matches(r2, buffer, minCount)+" "+filter.matchesEither(r1, r2, buffer, minCount)+"\n"+r1+"\n"+r2;
626 return filter.matchesEither(r1, r2, buffer, minCount);
627 }
628 }
629
630 private final LongList buffer=minConsecutiveMatches>1 ? new LongList(150) : null;
631
632 /** Number of reads processed by this thread */
633 protected long readsProcessedT=0;
634 /** Number of bases processed by this thread */
635 protected long basesProcessedT=0;
636
637 /** Number of reads retained by this thread */
638 protected long readsOutT=0;
639 /** Number of bases retained by this thread */
640 protected long basesOutT=0;
641
642 /** True only if this thread has completed successfully */
643 boolean success=false;
644
645 /** Shared input stream */
646 private final ConcurrentReadInputStream cris;
647 /** Shared output stream */
648 private final ConcurrentReadOutputStream rosu;
649 /** Matched output stream */
650 private final ConcurrentReadOutputStream rosm;
651 /** Count output stream */
652 private final ConcurrentReadOutputStream rosc;
653 /** Thread ID */
654 final int tid;
655 }
656
657 /*--------------------------------------------------------------*/
658 /*---------------- Fields ----------------*/
659 /*--------------------------------------------------------------*/
660
661 private ArrayList<String> ref=new ArrayList<String>();
662
663 /** Primary input file path */
664 private String in1=null;
665 /** Secondary input file path */
666 private String in2=null;
667
668 private String qfin1=null;
669 private String qfin2=null;
670
671 /** Primary output file path */
672 private String out1=null;
673 /** Secondary output file path */
674 private String out2=null;
675
676 /** Output for kmer counts */
677 private String outc=null;
678
679 private String qfout1=null;
680 private String qfout2=null;
681
682 /** Output file path for matching reads */
683 private String outm1=null;
684 /** Secondary output file path for matching reads */
685 private String outm2=null;
686
687 private String qfoutm1=null;
688 private String qfoutm2=null;
689
690 /** Override input file extension */
691 private String extin=null;
692 /** Override output file extension */
693 private String extout=null;
694
695 private String serialIn=null;
696 private String serialOut=null;
697
698 /*--------------------------------------------------------------*/
699
700 /** Number of reads processed */
701 protected long readsProcessed=0;
702 /** Number of bases processed */
703 protected long basesProcessed=0;
704
705 /** Number of reads retained */
706 protected long readsOut=0;
707 /** Number of bases retained */
708 protected long basesOut=0;
709
710 /** Quit after processing this many input reads; -1 means no limit */
711 private long maxReads=-1;
712
713 /*--------------------------------------------------------------*/
714 /*---------------- Final Fields ----------------*/
715 /*--------------------------------------------------------------*/
716
717 /** Primary input file */
718 final FileFormat ffin1;
719 /** Secondary input file */
720 final FileFormat ffin2;
721
722 /** Primary output file */
723 private final FileFormat ffout1;
724 /** Secondary output file */
725 private final FileFormat ffout2;
726
727 /** Primary output file for matching reads */
728 private final FileFormat ffoutm1;
729 /** Secondary output file for matching reads */
730 private final FileFormat ffoutm2;
731
732 /** Output for kmers and counts */
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 /*---------------- Common Fields ----------------*/
755 /*--------------------------------------------------------------*/
756
757 /** Print status messages to this output stream */
758 private PrintStream outstream=System.err;
759 /** Print verbose messages */
760 public static boolean verbose=false;
761 /** True if an error was encountered */
762 public boolean errorState=false;
763 /** Overwrite existing output files */
764 private boolean overwrite=true;
765 /** Append to existing output files */
766 private boolean append=false;
767 /** Reads are output in input order */
768 private boolean ordered=false;
769
770 }