Debian Codegraph @

current/jgi/CountDuplicates.java

raw symbols SCIP
1 package jgi;
2
3 import java.io.File;
4 import java.io.PrintStream;
5 import java.util.ArrayList;
6 import java.util.Random;
7 import java.util.concurrent.locks.ReadWriteLock;
8 import java.util.concurrent.locks.ReentrantReadWriteLock;
9
10 import fileIO.ByteFile;
11 import fileIO.FileFormat;
12 import fileIO.ReadWrite;
13 import kmer.HashArray1D;
14 import kmer.KmerTableSet;
15 import shared.Parse;
16 import shared.Parser;
17 import shared.PreParser;
18 import shared.Shared;
19 import shared.Timer;
20 import shared.Tools;
21 import stream.ConcurrentReadInputStream;
22 import stream.ConcurrentReadOutputStream;
23 import stream.FASTQ;
24 import stream.FastaReadInputStream;
25 import stream.Read;
26 import structures.ByteBuilder;
27 import structures.ListNum;
28 import structures.LongList;
29 import template.Accumulator;
30 import template.ThreadWaiter;
31 import tracker.ReadStats;
32
33 /**
34 * Counts duplicate sequences probabilistically,
35 * using around 20 bytes per unique read. Read pairs are treated
36 * as a single read. Reads are converted to a hashcode and only
37 * the hashcode is stored when tracking duplicates, so (rare) hash
38 * collisions will result in false positive duplicate detection.
39 * Optionally outputs the deduplicated and/or duplicate reads.
40 *
41 * @author Brian Bushnell
42 * @date November 19, 2022
43 *
44 */
45 public class CountDuplicates implements Accumulator<CountDuplicates.ProcessThread> {
46
47 /*--------------------------------------------------------------*/
48 /*---------------- Initialization ----------------*/
49 /*--------------------------------------------------------------*/
50
51 /**
52 * Code entrance from the command line.
53 * @param args Command line arguments
54 */
55 public static void main(String[] args){
56 //Start a timer immediately upon code entrance.
57 Timer t=new Timer();
58
59 //Create an instance of this class
60 CountDuplicates x=new CountDuplicates(args);
61
62 //Run the object
63 x.process(t);
64
65 //Close the print stream if it was redirected
66 Shared.closeStream(x.outstream);
67 }
68
69 /**
70 * Constructor.
71 * @param args Command line arguments
72 */
73 public CountDuplicates(String[] args){
74
75 {//Preparse block for help, config files, and outstream
76 PreParser pp=new PreParser(args, getClass(), false);
77 args=pp.args;
78 outstream=pp.outstream;
79 }
80
81 //Set shared static variables prior to parsing
82 ReadWrite.USE_PIGZ=ReadWrite.USE_UNPIGZ=true;
83 ReadWrite.setZipThreads(Shared.threads());
84
85 {//Parse the arguments
86 final Parser parser=parse(args);
87 Parser.processQuality();
88
89 maxReads=parser.maxReads;
90 overwrite=ReadStats.overwrite=parser.overwrite;
91 append=ReadStats.append=parser.append;
92 setInterleaved=parser.setInterleaved;
93
94 in1=parser.in1;
95 in2=parser.in2;
96 qfin1=parser.qfin1;
97 qfin2=parser.qfin2;
98 extin=parser.extin;
99
100 out1=parser.out1;
101 out2=parser.out2;
102 qfout1=parser.qfout1;
103 qfout2=parser.qfout2;
104 extout=parser.extout;
105 }
106
107 Shared.capThreads(20); //Does not need more than ~6 threads. So this accounts for 4-way SMT.
108
109 validateParams();
110 doPoundReplacement(); //Replace # with 1 and 2
111 adjustInterleaving(); //Make sure interleaving agrees with number of input and output files
112 fixExtensions(); //Add or remove .gz or .bz2 as needed
113 checkFileExistence(); //Ensure files can be read and written
114 checkStatics(); //Adjust file-related static fields as needed for this program
115
116 //Create output FileFormat objects
117 ffout1=FileFormat.testOutput(out1, FileFormat.FASTQ, extout, true, overwrite, append, ordered);
118 ffout2=FileFormat.testOutput(out2, FileFormat.FASTQ, extout, true, overwrite, append, ordered);
119
120 //Create output FileFormat objects
121 ffoutd1=FileFormat.testOutput(outd1, FileFormat.HEADER, null, true, overwrite, append, ordered);
122 ffoutd2=FileFormat.testOutput(outd2, FileFormat.HEADER, null, true, overwrite, append, ordered);
123
124 //Create input FileFormat objects
125 ffin1=FileFormat.testInput(in1, FileFormat.FASTQ, extin, true, true);
126 ffin2=FileFormat.testInput(in2, FileFormat.FASTQ, extin, true, true);
127
128 sampleThresh=(int)(samplerate*(sampleMask+1));
129
130 Parser.silent=PreParser.silent=true;
131 tables=new KmerTableSet(args, 12);
132 tables.allocateTables();
133 }
134
135 /*--------------------------------------------------------------*/
136 /*---------------- Initialization Helpers ----------------*/
137 /*--------------------------------------------------------------*/
138
139 /** Parse arguments from the command line */
140 private Parser parse(String[] args){
141
142 //Create a parser object
143 Parser parser=new Parser();
144
145 //Set any necessary Parser defaults here
146 //parser.foo=bar;
147
148 //Parse each argument
149 for(int i=0; i<args.length; i++){
150 String arg=args[i];
151
152 //Break arguments into their constituent parts, in the form of "a=b"
153 String[] split=arg.split("=");
154 String a=split[0].toLowerCase();
155 String b=split.length>1 ? split[1] : null;
156 if(b!=null && b.equalsIgnoreCase("null")){b=null;}
157
158 if(a.equals("verbose")){
159 verbose=Parse.parseBoolean(b);
160 }else if(a.equals("ordered")){
161 ordered=Parse.parseBoolean(b);
162 }else if(a.equals("bases") || a.equals("hashbases")){
163 hashBases=Parse.parseBoolean(b);
164 }else if(a.equals("names") || a.equals("headers") || a.equals("hashnames")){
165 hashNames=Parse.parseBoolean(b);
166 }else if(a.equals("qualities") || a.equals("hashqualities") || a.equals("quals")){
167 hashQualities=Parse.parseBoolean(b);
168 }else if(a.equals("stats") || a.equals("outstats")){
169 stats=b;
170 }else if(a.equals("maxfraction")){
171 maxFraction=Double.parseDouble(b);
172 }else if(a.equals("maxrate")){
173 maxRate=Double.parseDouble(b);
174 }else if(a.equals("exitcode") || a.equals("failcode")){
175 failCode=Integer.parseInt(b);
176 }else if(a.equals("samplerate")){
177 samplerate=Double.parseDouble(b);
178 }else if(a.equals("outd") || a.equals("dupes") || a.equals("outd1") || a.equals("dupes1")){
179 outd1=b;
180 }else if(a.equals("outd2") || a.equals("dupes2")){
181 outd2=b;
182 }else if(a.equals("parse_flag_goes_here")){
183 long fake_variable=Parse.parseKMG(b);
184 //Set a variable here
185 }else if(parser.parse(arg, a, b)){//Parse standard flags in the parser
186 //do nothing
187 }else{
188 outstream.println("Unknown parameter "+args[i]);
189 assert(false) : "Unknown parameter "+args[i];
190 }
191 }
192
193 return parser;
194 }
195
196 /** Replace # with 1 and 2 in headers */
197 private void doPoundReplacement(){
198 //Do input file # replacement
199 if(in1!=null && in2==null && in1.indexOf('#')>-1 && !new File(in1).exists()){
200 in2=in1.replace("#", "2");
201 in1=in1.replace("#", "1");
202 }
203
204 //Do output file # replacement
205 if(out1!=null && out2==null && out1.indexOf('#')>-1){
206 out2=out1.replace("#", "2");
207 out1=out1.replace("#", "1");
208 }
209
210 //Do output file # replacement
211 if(outd1!=null && outd2==null && outd1.indexOf('#')>-1){
212 outd2=outd1.replace("#", "2");
213 outd1=outd1.replace("#", "1");
214 }
215
216 //Ensure there is an input file
217 if(in1==null){throw new RuntimeException("Error - at least one input file is required.");}
218
219 //Ensure out2 is not set without out1
220 if(out1==null && out2!=null){throw new RuntimeException("Error - cannot define out2 without defining out1.");}
221 }
222
223 /** Add or remove .gz or .bz2 as needed */
224 private void fixExtensions(){
225 in1=Tools.fixExtension(in1);
226 in2=Tools.fixExtension(in2);
227 qfin1=Tools.fixExtension(qfin1);
228 qfin2=Tools.fixExtension(qfin2);
229 }
230
231 /** Ensure files can be read and written */
232 private void checkFileExistence(){
233 //Ensure output files can be written
234 if(!Tools.testOutputFiles(overwrite, append, false, out1, out2, outd1, outd2)){
235 outstream.println((out1==null)+", "+(out2==null)+", "+out1+", "+out2);
236 throw new RuntimeException("\n\noverwrite="+overwrite+"; Can't write to output files "+out1+", "+out2+"\n");
237 }
238
239 //Ensure input files can be read
240 if(!Tools.testInputFiles(false, true, in1, in2)){
241 throw new RuntimeException("\nCan't read some input files.\n");
242 }
243
244 //Ensure that no file was specified multiple times
245 if(!Tools.testForDuplicateFiles(true, in1, in2, out1, out2, outd1, outd2)){
246 throw new RuntimeException("\nSome file names were specified multiple times.\n");
247 }
248 }
249
250 /** Make sure interleaving agrees with number of input and output files */
251 private void adjustInterleaving(){
252 //Adjust interleaved detection based on the number of input files
253 if(in2!=null){
254 if(FASTQ.FORCE_INTERLEAVED){outstream.println("Reset INTERLEAVED to false because paired input files were specified.");}
255 FASTQ.FORCE_INTERLEAVED=FASTQ.TEST_INTERLEAVED=false;
256 }
257
258 //Adjust interleaved settings based on number of output files
259 if(!setInterleaved){
260 assert(in1!=null && (out1!=null || out2==null)) : "\nin1="+in1+"\nin2="+in2+"\nout1="+out1+"\nout2="+out2+"\n";
261 if(in2!=null){ //If there are 2 input streams.
262 FASTQ.FORCE_INTERLEAVED=FASTQ.TEST_INTERLEAVED=false;
263 outstream.println("Set INTERLEAVED to "+FASTQ.FORCE_INTERLEAVED);
264 }else{ //There is one input stream.
265 if(out2!=null){
266 FASTQ.FORCE_INTERLEAVED=true;
267 FASTQ.TEST_INTERLEAVED=false;
268 outstream.println("Set INTERLEAVED to "+FASTQ.FORCE_INTERLEAVED);
269 }
270 }
271 }
272 }
273
274 /** Adjust file-related static fields as needed for this program */
275 private static void checkStatics(){
276 //Adjust the number of threads for input file reading
277 if(!ByteFile.FORCE_MODE_BF1 && !ByteFile.FORCE_MODE_BF2 && Shared.threads()>2){
278 ByteFile.FORCE_MODE_BF2=true;
279 }
280
281 assert(FastaReadInputStream.settingsOK());
282 }
283
284 /** Ensure parameter ranges are within bounds and required parameters are set */
285 private boolean validateParams(){
286 assert(samplerate>=0 && samplerate<=1) : "Invalid samplerate: Range is 0-1.";
287 assert(maxFraction<0 || maxFraction<=1) : "Invalid maxFraction: Range is negative, or 0-1.";
288 assert(maxRate<0 || maxRate>=1) : "Invalid maxRate: Range is negative, or 1+.";
289 return true;
290 }
291
292 /*--------------------------------------------------------------*/
293 /*---------------- Outer Methods ----------------*/
294 /*--------------------------------------------------------------*/
295
296 /** Create read streams and process all data */
297 void process(Timer t){
298
299 //Turn off read validation in the input threads to increase speed
300 final boolean vic=Read.VALIDATE_IN_CONSTRUCTOR;
301 Read.VALIDATE_IN_CONSTRUCTOR=Shared.threads()<4;
302
303 //Create a read input stream
304 final ConcurrentReadInputStream cris=makeCris();
305
306 //Optionally create a read output stream
307 final ConcurrentReadOutputStream ros=makeCros(cris.paired());
308
309 //Optionally create a duplicate read output stream
310 final ConcurrentReadOutputStream rosd=makeCrosD(cris.paired());
311
312 //Reset counters
313 readsProcessed=readsOut=0;
314 basesProcessed=basesOut=0;
315
316 //Process the reads in separate threads
317 spawnThreads(cris, ros, rosd);
318
319 if(verbose){outstream.println("Finished; closing streams.");}
320
321 System.err.println();
322 calcStatistics(stats);
323
324 //Write anything that was accumulated by ReadStats
325 errorState|=ReadStats.writeAll();
326 //Close the read streams
327 errorState|=ReadWrite.closeStreams(cris, ros, rosd);
328
329 //Reset read validation
330 Read.VALIDATE_IN_CONSTRUCTOR=vic;
331
332 //Report timing and results
333 t.stop();
334 outstream.println(Tools.timeReadsBasesProcessed(t, readsProcessed, basesProcessed, 8));
335 outstream.println(Tools.readsBasesOut(readsProcessed, basesProcessed, readsOut, basesOut, 8, false));
336
337 //Throw an exception of there was an error in a thread
338 if(errorState){
339 throw new RuntimeException(getClass().getName()+" terminated in an error state; the output may be corrupt.");
340 }
341
342 if(failed){
343 System.err.println("FAIL");
344 System.exit(failCode);
345 }else if(maxFraction>=0 || maxRate>=0){
346 System.err.println("PASS");
347 }
348 }
349
350 private ConcurrentReadInputStream makeCris(){
351 ConcurrentReadInputStream cris=ConcurrentReadInputStream.getReadInputStream(maxReads, true, ffin1, ffin2, qfin1, qfin2);
352 cris.start(); //Start the stream
353 if(verbose){outstream.println("Started cris");}
354 boolean paired=cris.paired();
355 if(!ffin1.samOrBam()){outstream.println("Input is being processed as "+(paired ? "paired" : "unpaired"));}
356 return cris;
357 }
358
359 private ConcurrentReadOutputStream makeCros(boolean pairedInput){
360 if(ffout1==null){return null;}
361
362 //Select output buffer size based on whether it needs to be ordered
363 final int buff=(ordered ? Tools.mid(16, 128, (Shared.threads()*2)/3) : 8);
364
365 //Notify user of output mode
366 if(pairedInput && out2==null && (in1!=null && !ffin1.samOrBam() && !ffout1.samOrBam())){
367 outstream.println("Writing interleaved.");
368 }
369
370 final ConcurrentReadOutputStream ros=ConcurrentReadOutputStream.getStream(ffout1, ffout2, qfout1, qfout2, buff, null, false);
371 ros.start(); //Start the stream
372 return ros;
373 }
374
375 private ConcurrentReadOutputStream makeCrosD(boolean pairedInput){
376 if(ffoutd1==null){return null;}
377
378 //Select output buffer size based on whether it needs to be ordered
379 final int buff=(ordered ? Tools.mid(16, 128, (Shared.threads()*2)/3) : 8);
380
381 final ConcurrentReadOutputStream rosd=ConcurrentReadOutputStream.getStream(ffoutd1, ffoutd2, null, null, buff, null, false);
382 rosd.start(); //Start the stream
383 return rosd;
384 }
385
386 private void calcStatistics(String fname){
387 ByteBuilder bb=new ByteBuilder();
388
389 long[] counts=tables.fillHistogram(4000);
390 long sumTotal=Tools.sumHistogram(counts);
391 long sumUnique=Tools.sum(counts);
392
393 long[] multiplicity=new long[10];
394 multiplicity[1]=counts[1];
395 for(int i=1; i<counts.length; i++){
396 long count=counts[i];
397 for(int j=2; j<multiplicity.length; j++){
398 if(i%j==0){multiplicity[j]+=count*i;}
399 }
400 }
401 final double mult=(sumTotal<1 ? 0 : 1.0/sumTotal);
402 final long x1=counts[1];
403 double fraction=mult*(sumTotal-x1);
404 double rate=sumTotal*1.0/sumUnique;
405 bb.appendln("#Fraction of reads with duplicates:"+
406 Tools.format("\t%.4f", fraction));
407 bb.appendln("#Average duplication rate: "+
408 Tools.format("\t%.4f", rate));
409 bb.appendln("#Read Copy Count Distribution");
410 bb.appendln("#Copies\tCount\tFraction");
411 bb.appendln("1\t"+x1+Tools.format("\t%.4f", mult*x1));
412 for(int i=2; i<multiplicity.length; i++){
413 long x=multiplicity[i];
414 bb.appendln(i+"N\t"+x+Tools.format("\t%.4f", mult*x));
415 }
416 if(fname!=null){
417 ReadWrite.writeString(bb, fname);
418 }
419
420 if(maxFraction>=0 && fraction>maxFraction){failed=true;}
421 if(maxRate>=0 && rate>maxRate){failed=true;}
422 }
423
424 /*--------------------------------------------------------------*/
425 /*---------------- Thread Management ----------------*/
426 /*--------------------------------------------------------------*/
427
428 /** Spawn process threads */
429 private void spawnThreads(final ConcurrentReadInputStream cris,
430 final ConcurrentReadOutputStream ros, final ConcurrentReadOutputStream rosd){
431
432 //Do anything necessary prior to processing
433
434 //Determine how many threads may be used
435 final int threads=Shared.threads();
436
437 //Fill a list with ProcessThreads
438 ArrayList<ProcessThread> alpt=new ArrayList<ProcessThread>(threads);
439 for(int i=0; i<threads; i++){
440 alpt.add(new ProcessThread(cris, ros, rosd, i));
441 }
442
443 //Start the threads and wait for them to finish
444 boolean success=ThreadWaiter.startAndWait(alpt, this);
445 errorState&=!success;
446
447 //Do anything necessary after processing
448
449 }
450
451 @Override
452 public final void accumulate(ProcessThread pt){
453 readsProcessed+=pt.readsProcessedT;
454 basesProcessed+=pt.basesProcessedT;
455 readsOut+=pt.readsOutT;
456 basesOut+=pt.basesOutT;
457 errorState|=(!pt.success);
458 }
459
460 @Override
461 public final boolean success(){return !errorState;}
462
463 /*--------------------------------------------------------------*/
464 /*---------------- Inner Methods ----------------*/
465 /*--------------------------------------------------------------*/
466
467 /*--------------------------------------------------------------*/
468 /*---------------- Inner Classes ----------------*/
469 /*--------------------------------------------------------------*/
470
471 class ProcessThread extends Thread {
472
473 //Constructor
474 ProcessThread(final ConcurrentReadInputStream cris_,
475 final ConcurrentReadOutputStream ros_, final ConcurrentReadOutputStream rosd_, final int tid_){
476 cris=cris_;
477 ros=ros_;
478 rosd=rosd_;
479 tid=tid_;
480 }
481
482 //Called by start()
483 @Override
484 public void run(){
485 //Do anything necessary prior to processing
486
487 //Process the reads
488 processInner();
489
490 //Indicate successful exit status
491 success=true;
492 }
493
494 /** Iterate through the reads */
495 void processInner(){
496
497 //Grab the first ListNum of reads
498 ListNum<Read> ln=cris.nextList();
499
500 //Check to ensure pairing is as expected
501 if(ln!=null && !ln.isEmpty()){
502 Read r=ln.get(0);
503 // assert(ffin1.samOrBam() || (r.mate!=null)==cris.paired()); //Disabled due to non-static access
504 }
505
506 //As long as there is a nonempty read list...
507 while(ln!=null && ln.size()>0){
508 // if(verbose){outstream.println("Fetched "+reads.size()+" reads.");} //Disabled due to non-static access
509
510 processList(ln);
511
512 //Notify the input stream that the list was used
513 cris.returnList(ln);
514 // if(verbose){outstream.println("Returned a list.");} //Disabled due to non-static access
515
516 //Fetch a new list
517 ln=cris.nextList();
518 }
519
520 //Notify the input stream that the final list was used
521 if(ln!=null){
522 cris.returnList(ln.id, ln.list==null || ln.list.isEmpty());
523 }
524 }
525
526 void processList(ListNum<Read> ln){
527
528 //Grab the actual read list from the ListNum
529 final ArrayList<Read> reads=ln.list;
530 final ArrayList<Read> dupes=new ArrayList<Read>(reads.size());
531
532 //Generate hashcodes and place them in counts array.
533 //This is the slow bit so it goes outside the lock.
534 hashList(reads);
535
536 //This involves the lock
537 int numDupes=processCodes();
538
539 //Loop through each read in the list
540 for(int idx=0; idx<reads.size(); idx++){
541 final Read r1=reads.get(idx);
542 final Read r2=r1.mate;
543
544 //Validate reads in worker threads
545 if(!r1.validated()){r1.validate(true);}
546 if(r2!=null && !r2.validated()){r2.validate(true);}
547
548 //Track the initial length for statistics
549 final int initialLength1=r1.length();
550 final int initialLength2=r1.mateLength();
551
552 //Increment counters
553 readsProcessedT+=r1.pairCount();
554 basesProcessedT+=initialLength1+initialLength2;
555
556 long code=codes.get(idx);
557 if(code>=0){
558 readsOutT+=r1.pairCount();
559 basesOutT+=r1.pairLength();
560 }else{
561 reads.set(idx, null);
562 if(code==DUPLICATE){dupes.add(r1);}
563 }
564 }
565
566 //Output reads to the output stream
567 if(ros!=null){ros.add(reads, ln.id);}
568 if(rosd!=null){rosd.add(dupes, ln.id);}
569 }
570
571 //Critical section
572 private int processCodes(){
573 int dupes=0;
574 synchronized(tables){
575 for(int i=0; i<codes.size; i++){
576 long code=codes.get(i);
577 if(code>=0){
578 HashArray1D table=tables.getTableForKey(code);
579 int count=table.increment(code, 1);
580 if(count>maxCount){
581 codes.set(i, DUPLICATE);
582 dupes++;
583 }
584 }
585 }
586 }
587 return dupes;
588 }
589
590 private void hashList(ArrayList<Read> reads){
591 codes.clear();
592 for(final Read r1 : reads){
593 codes.add(r1==null ? 0 : hashRead(r1, r1.mate));
594 }
595 }
596
597 long hashRead(final Read r1, final Read r2){
598 long code=(hashBases ? hashBases(r1, r2) : 0);
599 code^=(hashNames ? hashNames(r1, r2) : 0);
600 code^=(hashQualities ? hashQualities(r1, r2) : 0);
601 if(samplerate<1 && (code&sampleMask)<sampleThresh){return UNSAMPLED;}
602 return code&Long.MAX_VALUE;
603 }
604
605 private long hashBases(final Read r1, final Read r2){
606 long code=hash(r1.bases, 0);
607 if(r2!=null){code=code^Long.rotateRight(hash(r2.bases, 1), 3);}
608 return code;
609 }
610
611 private long hashNames(final Read r1, final Read r2){
612 long code=hash(r1.id.getBytes(), 7);
613 return code;
614 }
615
616 private long hashQualities(final Read r1, final Read r2){
617 long code=hash(r1.quality, 0);
618 if(r2!=null){code=code^Long.rotateRight(hash(r2.quality, 1), 3);}
619 return code;
620 }
621
622 /** Number of reads processed by this thread */
623 protected long readsProcessedT=0;
624 /** Number of bases processed by this thread */
625 protected long basesProcessedT=0;
626
627 /** Number of reads retained by this thread */
628 protected long readsOutT=0;
629 /** Number of bases retained by this thread */
630 protected long basesOutT=0;
631
632 /** True only if this thread has completed successfully */
633 boolean success=false;
634
635 /** Shared input stream */
636 private final ConcurrentReadInputStream cris;
637 /** Shared output stream */
638 private final ConcurrentReadOutputStream ros;
639 /** Shared output stream for duplicate reads */
640 private final ConcurrentReadOutputStream rosd;
641 /** Thread ID */
642 final int tid;
643
644 final LongList codes=new LongList(Shared.bufferLen());
645 }
646
647 public static long hash(byte[] bytes, int pairnum){
648 if(bytes==null){return 0;}
649 long code=(bytes.length+pairnum)^salt;
650 for(int i=0; i<bytes.length; i++){
651 byte b=bytes[i];
652 int mode=(int)(code&31);
653 assert(hashcodes[b]!=null) : "Invalid sequence character: '"+(char)b+"'";
654 code=code^hashcodes[b][mode];
655 code=Long.rotateLeft(code, 1);
656 }
657 return code;
658 }
659
660 /*--------------------------------------------------------------*/
661 /*---------------- Fields ----------------*/
662 /*--------------------------------------------------------------*/
663
664 /** Primary input file path */
665 private String in1=null;
666 /** Secondary input file path */
667 private String in2=null;
668
669 private String qfin1=null;
670 private String qfin2=null;
671
672 /** Primary output file path */
673 private String out1=null;
674 /** Secondary output file path */
675 private String out2=null;
676
677 private String qfout1=null;
678 private String qfout2=null;
679
680 /** Primary dupe output file path */
681 private String outd1=null;
682 /** Secondary dupe output file path */
683 private String outd2=null;
684
685 /** Override input file extension */
686 private String extin=null;
687 /** Override output file extension */
688 private String extout=null;
689
690 /** Stats output */
691 private String stats="stdout.txt";
692
693 private double maxFraction=-1;
694 private double maxRate=-1;
695 private int failCode=0;
696 boolean failed=false;
697
698 /** Whether interleaved was explicitly set. */
699 private boolean setInterleaved=false;
700
701 private KmerTableSet tables;
702
703 private boolean hashBases=true;
704 private boolean hashNames=false;
705 private boolean hashQualities=false;
706
707 /*--------------------------------------------------------------*/
708
709 /** Number of reads processed */
710 protected long readsProcessed=0;
711 /** Number of bases processed */
712 protected long basesProcessed=0;
713
714 /** Number of reads retained */
715 protected long readsOut=0;
716 /** Number of bases retained */
717 protected long basesOut=0;
718
719 /** Quit after processing this many input reads; -1 means no limit */
720 private long maxReads=-1;
721 private double samplerate=1;
722 private int maxCount=1;
723
724 /*--------------------------------------------------------------*/
725 /*---------------- Final Fields ----------------*/
726 /*--------------------------------------------------------------*/
727
728 /** Primary input file */
729 private final FileFormat ffin1;
730 /** Secondary input file */
731 private final FileFormat ffin2;
732
733 /** Primary output file */
734 private final FileFormat ffout1;
735 /** Secondary output file */
736 private final FileFormat ffout2;
737
738 /** Primary dupe output file */
739 private final FileFormat ffoutd1;
740 /** Secondary dupe output file */
741 private final FileFormat ffoutd2;
742
743 private static final long[][] hashcodes=Dedupe.makeCodes2(32);
744 private static final long salt=new Random(173).nextLong();
745 private final int sampleMask=1023;
746 private final int sampleThresh;
747
748 private final int UNSAMPLED=-1;
749 private final int DUPLICATE=-2;
750
751 @Override
752 public final ReadWriteLock rwlock() {return rwlock;}
753 private final ReadWriteLock rwlock=new ReentrantReadWriteLock();
754
755 /*--------------------------------------------------------------*/
756 /*---------------- Common Fields ----------------*/
757 /*--------------------------------------------------------------*/
758
759 /** Print status messages to this output stream */
760 private PrintStream outstream=System.err;
761 /** Print verbose messages */
762 public static boolean verbose=false;
763 /** True if an error was encountered */
764 public boolean errorState=false;
765 /** Overwrite existing output files */
766 private boolean overwrite=true;
767 /** Append to existing output files */
768 private boolean append=false;
769 /** Reads are output in input order */
770 private boolean ordered=false;
771
772 }