Debian Codegraph @

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