Debian Codegraph @

current/consensus/FixScaffoldGaps.java

raw symbols SCIP
1 package consensus;
2
3 import java.io.PrintStream;
4 import java.util.ArrayList;
5 import java.util.LinkedHashMap;
6 import java.util.Map.Entry;
7 import java.util.concurrent.atomic.AtomicIntegerArray;
8 import java.util.concurrent.atomic.AtomicLongArray;
9 import java.util.concurrent.locks.ReadWriteLock;
10 import java.util.concurrent.locks.ReentrantReadWriteLock;
11
12 import fileIO.ByteFile;
13 import fileIO.FileFormat;
14 import fileIO.ReadWrite;
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.FastaReadInputStream;
24 import stream.Read;
25 import stream.SamLine;
26 import stream.SamReadStreamer;
27 import stream.SamStreamer;
28 import structures.ByteBuilder;
29 import structures.ListNum;
30 import template.Accumulator;
31 import template.ThreadWaiter;
32 import tracker.ReadStats;
33 import var2.SamFilter;
34
35 /**
36 * Resizes scaffold gaps to represent the best estimate
37 * based on the insert size distribution of paired reads.
38 *
39 * @author Brian Bushnell
40 * @date September 11, 2019
41 *
42 */
43 public class FixScaffoldGaps implements Accumulator<FixScaffoldGaps.ProcessThread> {
44
45 /*--------------------------------------------------------------*/
46 /*---------------- Initialization ----------------*/
47 /*--------------------------------------------------------------*/
48
49 /**
50 * Code entrance from the command line.
51 * @param args Command line arguments
52 */
53 public static void main(String[] args){
54 //Start a timer immediately upon code entrance.
55 Timer t=new Timer();
56
57 //Create an instance of this class
58 FixScaffoldGaps x=new FixScaffoldGaps(args);
59
60 //Run the object
61 x.process(t);
62
63 //Close the print stream if it was redirected
64 Shared.closeStream(x.outstream);
65 }
66
67 /**
68 * Constructor.
69 * @param args Command line arguments
70 */
71 public FixScaffoldGaps(String[] args){
72
73 {//Preparse block for help, config files, and outstream
74 PreParser pp=new PreParser(args, getClass(), false);
75 args=pp.args;
76 outstream=pp.outstream;
77 }
78
79 //Set shared static variables prior to parsing
80 ReadWrite.USE_PIGZ=ReadWrite.USE_UNPIGZ=true;
81 ReadWrite.setZipThreads(Shared.threads());
82
83 samFilter.includeUnmapped=false;
84 samFilter.includeSupplimentary=false;
85 // samFilter.includeDuplicate=false;
86 samFilter.includeNonPrimary=false;
87 samFilter.includeQfail=false;
88 // samFilter.minMapq=4;
89
90 {//Parse the arguments
91 final Parser parser=parse(args);
92
93 Parser.processQuality();
94
95 maxReads=parser.maxReads;
96 overwrite=ReadStats.overwrite=parser.overwrite;
97 append=ReadStats.append=parser.append;
98
99 in=parser.in1;
100 extin=parser.extin;
101
102 out=parser.out1;
103 extout=parser.extout;
104 }
105
106 {
107 // if("auto".equalsIgnoreCase(atomic)){Scaffold.setCA3A(Shared.threads()>8);}
108 // else{Scaffold.setCA3A(Parse.parseBoolean(atomic));}
109 samFilter.setSamtoolsFilter();
110
111 streamerThreads=Tools.max(1, Tools.min(streamerThreads, Shared.threads()));
112 assert(streamerThreads>0) : streamerThreads;
113 }
114
115 validateParams();
116 fixExtensions(); //Add or remove .gz or .bz2 as needed
117 checkFileExistence(); //Ensure files can be read and written
118 checkStatics(); //Adjust file-related static fields as needed for this program
119
120 //Create output FileFormat objects
121 ffout=FileFormat.testOutput(out, FileFormat.FASTA, extout, true, overwrite, append, ordered);
122
123 //Create input FileFormat objects
124 ffin=FileFormat.testInput(in, FileFormat.SAM, extin, true, true);
125 ffref=FileFormat.testInput(ref, FileFormat.FASTA, null, true, true);
126 }
127
128 /*--------------------------------------------------------------*/
129 /*---------------- Initialization Helpers ----------------*/
130 /*--------------------------------------------------------------*/
131
132 /** Parse arguments from the command line */
133 private Parser parse(String[] args){
134
135 //Create a parser object
136 Parser parser=new Parser();
137
138 //Set any necessary Parser defaults here
139 //parser.foo=bar;
140
141 //Parse each argument
142 for(int i=0; i<args.length; i++){
143 String arg=args[i];
144
145 //Break arguments into their constituent parts, in the form of "a=b"
146 String[] split=arg.split("=");
147 String a=split[0].toLowerCase();
148 String b=split.length>1 ? split[1] : null;
149 if(b!=null && b.equalsIgnoreCase("null")){b=null;}
150
151 if(a.equals("verbose")){
152 verbose=Parse.parseBoolean(b);
153 }else if(a.equals("ref") || a.equals("scaffolds")){
154 ref=b;
155 }else if(a.equals("insertlist")){
156 insertList=b;
157 }else if(a.equals("ordered")){
158 ordered=Parse.parseBoolean(b);
159 }else if(a.equalsIgnoreCase("ns") || a.equalsIgnoreCase("n") || a.equalsIgnoreCase("scaffoldbreak") || a.equalsIgnoreCase("gap")){
160 scaffoldBreakNs=Integer.parseInt(b);
161 assert(scaffoldBreakNs>0);
162 }else if(a.equalsIgnoreCase("mindepth")){
163 minDepth=Integer.parseInt(b);
164 assert(minDepth>0);
165 }else if(a.equalsIgnoreCase("trim") || a.equalsIgnoreCase("trimFraction") || a.equalsIgnoreCase("border")){
166 trimFraction=Float.parseFloat(b);
167 assert(trimFraction>=0 && trimFraction<=1) : "trimFraction should be between 0 and 1";
168 }else if(a.equals("clearfilters") || a.equals("clearfilter")){
169 if(Parse.parseBoolean(b)){
170 samFilter.clear();
171 }
172 }else if(a.equals("parse_flag_goes_here")){
173 long fake_variable=Parse.parseKMG(b);
174 //Set a variable here
175 }else if(samFilter.parse(arg, a, b)){
176 //do nothing
177 }else if(parser.parse(arg, a, b)){//Parse standard flags in the parser
178 //do nothing
179 }else{
180 outstream.println("Unknown parameter "+args[i]);
181 assert(false) : "Unknown parameter "+args[i];
182 }
183 }
184
185 return parser;
186 }
187
188 /** Add or remove .gz or .bz2 as needed */
189 private void fixExtensions(){
190 in=Tools.fixExtension(in);
191 ref=Tools.fixExtension(ref);
192 }
193
194 /** Ensure files can be read and written */
195 private void checkFileExistence(){
196
197 //Ensure there is an input file
198 if(in==null){throw new RuntimeException("Error - an input file is required.");}
199
200 //Ensure there is an input file
201 if(ref==null){throw new RuntimeException("Error - a reference file is required.");}
202
203 //Ensure output files can be written
204 if(!Tools.testOutputFiles(overwrite, append, false, out)){
205 outstream.println((out==null)+", "+out);
206 throw new RuntimeException("\n\noverwrite="+overwrite+"; Can't write to output file "+out+"\n");
207 }
208
209 //Ensure input files can be read
210 if(!Tools.testInputFiles(false, true, in, ref)){
211 throw new RuntimeException("\nCan't read some input files.\n");
212 }
213
214 //Ensure that no file was specified multiple times
215 if(!Tools.testForDuplicateFiles(true, in, ref, out)){
216 throw new RuntimeException("\nSome file names were specified multiple times.\n");
217 }
218 }
219
220 /** Adjust file-related static fields as needed for this program */
221 private static void checkStatics(){
222 //Adjust the number of threads for input file reading
223 if(!ByteFile.FORCE_MODE_BF1 && !ByteFile.FORCE_MODE_BF2 && Shared.threads()>2){
224 ByteFile.FORCE_MODE_BF2=true;
225 }
226
227 assert(FastaReadInputStream.settingsOK());
228 }
229
230 /** Ensure parameter ranges are within bounds and required parameters are set */
231 private boolean validateParams(){
232 // assert(minfoo>0 && minfoo<=maxfoo) : minfoo+", "+maxfoo;
233 return true;
234 }
235
236 /*--------------------------------------------------------------*/
237 /*---------------- Outer Methods ----------------*/
238 /*--------------------------------------------------------------*/
239
240 /** Create read streams and process all data */
241 void process(Timer t){
242
243 //Turn off read validation in the input threads to increase speed
244 final boolean vic=Read.VALIDATE_IN_CONSTRUCTOR;
245 Read.VALIDATE_IN_CONSTRUCTOR=Shared.threads()<4;
246
247 //Create a read input stream
248 final SamStreamer ss=makeStreamer(ffin);
249
250 //Load reference
251 loadReferenceCustom();
252
253 //Reset counters
254 readsProcessed=readsOut=0;
255 basesProcessed=basesOut=0;
256
257 //Process the reads in separate threads
258 spawnThreads(ss);
259
260 //Optionally create a read output stream
261 final ConcurrentReadOutputStream ros=makeCros();
262
263 if(verbose){outstream.println("Fixing reference.");}
264
265 fixScaffolds(ros);
266
267 if(verbose){outstream.println("Finished; closing streams.");}
268
269 //Write anything that was accumulated by ReadStats
270 errorState|=ReadStats.writeAll();
271 //Close the read streams
272 errorState|=ReadWrite.closeStream(ros);
273
274 //Reset read validation
275 Read.VALIDATE_IN_CONSTRUCTOR=vic;
276
277 //Report timing and results
278 t.stop();
279 outstream.println(Tools.timeReadsBasesProcessed(t, readsProcessed, basesProcessed, 8));
280 outstream.println(Tools.readsBasesOut(readsProcessed, basesProcessed, scaffoldsOut, scaffoldLengthOut, 8, false));
281
282 outstream.println();
283 outstream.println(Tools.number("Average Insert", totalAverageInsert, 2, 8));
284 outstream.println(Tools.number("Gaps Unchanged", gapsUnchanged, 8));
285 outstream.println(Tools.number("Gaps Widened ", gapsWidened, 8));
286 outstream.println(Tools.number("Gaps Narrowed ", gapsNarrowed, 8));
287 outstream.println(Tools.number("Ns Total ", nsTotal, 8));
288 outstream.println(Tools.number("Ns Added ", nsAdded, 8));
289 outstream.println(Tools.number("Ns Removed ", nsRemoved, 8));
290
291
292 //Throw an exception of there was an error in a thread
293 if(errorState){
294 throw new RuntimeException(getClass().getName()+" terminated in an error state; the output may be corrupt.");
295 }
296 }
297
298 private synchronized void loadReferenceCustom(){
299 assert(!loadedRef);
300 ConcurrentReadInputStream cris=makeRefCris();
301 for(ListNum<Read> ln=cris.nextList(); ln!=null && ln.size()>0; ln=cris.nextList()) {
302 for(Read r : ln){
303 String name=r.id;
304 String name2=Tools.trimToWhitespace(r.id);
305 Scaffold scaf=new Scaffold(name, r.bases, r.numericID);
306 refMap.put(name, scaf);
307 refMap2.put(name2, scaf);
308 }
309 }
310 loadedRef=true;
311 }
312
313 private ConcurrentReadInputStream makeRefCris(){
314 ConcurrentReadInputStream cris=ConcurrentReadInputStream.getReadInputStream(maxReads, true, ffref, null);
315 cris.start(); //Start the stream
316 if(verbose){outstream.println("Started cris");}
317 boolean paired=cris.paired();
318 assert(!paired) : "References should not be paired.";
319 return cris;
320 }
321
322 private SamStreamer makeStreamer(FileFormat ff){
323 if(ff==null){return null;}
324 SamStreamer ss=new SamReadStreamer(ff, streamerThreads, true, maxReads);
325 ss.start(); //Start the stream
326 if(verbose){outstream.println("Started Streamer");}
327 return ss;
328 }
329
330 private ConcurrentReadOutputStream makeCros(){
331 if(ffout==null){return null;}
332
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 final ConcurrentReadOutputStream ros=ConcurrentReadOutputStream.getStream(ffout, null, buff, null, false);
337 ros.start(); //Start the stream
338 return ros;
339 }
340
341 /*--------------------------------------------------------------*/
342 /*---------------- Thread Management ----------------*/
343 /*--------------------------------------------------------------*/
344
345 /** Spawn process threads */
346 private void spawnThreads(final SamStreamer ss){
347
348 //Do anything necessary prior to processing
349
350 //Determine how many threads may be used
351 final int threads=Shared.threads();
352
353 //Fill a list with ProcessThreads
354 ArrayList<ProcessThread> alpt=new ArrayList<ProcessThread>(threads);
355 for(int i=0; i<threads; i++){
356 alpt.add(new ProcessThread(ss, i));
357 }
358
359 //Start the threads
360 for(ProcessThread pt : alpt){
361 pt.start();
362 }
363
364 //Wait for threads to finish
365 boolean success=ThreadWaiter.waitForThreadsToFinish(alpt, this);
366 errorState&=!success;
367
368 //Do anything necessary after processing
369 totalAverageInsert=totalInsertSum/(double)totalInsertCount;
370 insertByPercentile=Tools.makeHistogram(insertCounts, buckets);
371 }
372
373 @Override
374 public final void accumulate(ProcessThread pt){
375 readsProcessed+=pt.readsProcessedT;
376 basesProcessed+=pt.basesProcessedT;
377 readsOut+=pt.readsOutT;
378 basesOut+=pt.basesOutT;
379
380 totalInsertSum+=pt.totalInsertSumT;
381 totalInsertCount+=pt.totalInsertCountT;
382
383 errorState|=(!pt.success);
384 }
385
386 @Override
387 public final boolean success(){return !errorState;}
388
389 /*--------------------------------------------------------------*/
390 /*---------------- Inner Methods ----------------*/
391 /*--------------------------------------------------------------*/
392
393 private void fixScaffolds(ConcurrentReadOutputStream ros){
394 ByteBuilder bb=new ByteBuilder(1000000);
395
396 ArrayList<Read> list=new ArrayList<Read>(200);
397 long num=0;
398 long lengthSum=0;
399 for(Entry<String, Scaffold> e : refMap.entrySet()){
400 Scaffold scaf=e.getValue();
401 Read r=scaf.fixScaffold(bb);
402 lengthSum+=r.length();
403 list.add(r);
404 scaffoldsOut++;
405 scaffoldLengthOut+=r.length();
406
407 if(list.size()>=200 || lengthSum>=100000){
408 if(ros!=null){ros.add(list, num);}
409 list=new ArrayList<Read>(200);
410 num++;
411 lengthSum=0;
412 }
413 }
414 if(list.size()>0){
415 if(ros!=null){ros.add(list, num);}
416 }
417 }
418
419 private static int calcInsertSize(SamLine sl) {
420 assert(sl.mapped() && sl.pairedOnSameChrom());
421 assert(sl.primary());
422 assert(!sl.supplementary());
423 assert(sl.leftmost());
424
425 assert(sl.tlen>0) : sl.tlen+"\n\n"+sl;
426 return sl.tlen>0 ? sl.tlen : -sl.tlen;
427
428 // final int insertSize;
429 // String insertTag=null;
430 // if(sl.optional!=null){
431 // for(String s : sl.optional){
432 // if(s.startsWith("X8:Z:")){
433 // insertTag=s;
434 // break;
435 // }
436 // }
437 // }
438 // if(insertTag!=null){
439 // insertSize=Integer.parseInt(insertTag.substring(5));
440 // }else{
441 // insertSize=sl.tlen;//This is unsafe due to indels.
442 // assert(false) : "Reads need insert size tags.";
443 // }
444 // assert(insertSize>0) : sl;
445 //
446 // return insertSize;
447 }
448
449 /*--------------------------------------------------------------*/
450 /*---------------- Inner Classes ----------------*/
451 /*--------------------------------------------------------------*/
452
453 /** This class is static to prevent accidental writing to shared variables.
454 * It is safe to remove the static modifier. */
455 class ProcessThread extends Thread {
456
457 //Constructor
458 ProcessThread(final SamStreamer ss_, final int tid_){
459 ss=ss_;
460 tid=tid_;
461 }
462
463 //Called by start()
464 @Override
465 public void run(){
466 //Do anything necessary prior to processing
467
468 //Process the reads
469 processInner();
470
471 //Do anything necessary after processing
472
473 //Indicate successful exit status
474 success=true;
475 }
476
477 /** Iterate through the reads */
478 void processInner(){
479
480 //Grab and process all lists
481 for(ListNum<Read> ln=ss.nextReads(); ln!=null; ln=ss.nextReads()){
482 // if(verbose){outstream.println("Got list of size "+list.size());} //Disabled due to non-static access
483
484 processList(ln);
485 }
486
487 }
488
489 void processList(ListNum<Read> ln){
490
491 //Grab the actual read list from the ListNum
492 final ArrayList<Read> reads=ln.list;
493
494 //Loop through each read in the list
495 for(int idx=0; idx<reads.size(); idx++){
496 final Read r=reads.get(idx);
497
498 //Validate reads in worker threads
499 if(!r.validated()){r.validate(true);}
500
501 //Track the initial length for statistics
502 final int initialLength=r.length();
503
504 //Increment counters
505 readsProcessedT+=r.pairCount();
506 basesProcessedT+=initialLength;
507
508 processRead(r);
509 }
510 }
511
512 /**
513 * Process a read or a read pair.
514 * @param r Read 1
515 * @param r2 Read 2 (may be null)
516 * @return True if the reads should be kept, false if they should be discarded.
517 */
518 void processRead(final Read r){
519 final SamLine sl=r.samline;
520 assert(sl!=null) : sl;
521 if(samFilter!=null && !samFilter.passesFilter(sl)){return;}
522
523 //sl.nextMapped();
524 if(sl.mapped() && sl.pairedOnSameChrom() && sl.properPair() && sl.primary() && !sl.supplementary() && sl.leftmost()){
525 final String rname=sl.rnameS();
526 Scaffold scaf=refMap.get(rname);
527 if(scaf==null){scaf=refMap2.get(Tools.trimToWhitespace(rname));}
528 assert(scaf!=null) : "Can't find graph for "+rname;
529
530 if(scaf!=null){
531 final int insertSize=calcInsertSize(sl);
532 insertCounts.incrementAndGet(Tools.mid(0, insertSize, insertCounts.length()));
533 scaf.add(sl, insertSize);
534
535 readsOutT++;
536 basesOutT+=r.length();
537
538 totalInsertSumT+=insertSize;
539 totalInsertCountT++;
540 }
541 }
542 }
543
544 /** Number of reads processed by this thread */
545 protected long readsProcessedT=0;
546 /** Number of bases processed by this thread */
547 protected long basesProcessedT=0;
548
549 /** Number of reads retained by this thread */
550 protected long readsOutT=0;
551 /** Number of bases retained by this thread */
552 protected long basesOutT=0;
553
554 protected long totalInsertSumT=0;
555 protected long totalInsertCountT=0;
556
557 long insertSum=0;
558
559 /** True only if this thread has completed successfully */
560 boolean success=false;
561
562 /** Shared input stream */
563 private final SamStreamer ss;
564 /** Thread ID */
565 final int tid;
566 }
567
568 /*--------------------------------------------------------------*/
569
570 private class Scaffold {
571
572 Scaffold(String name_, byte[] bases_, long numericID_){
573 name=name_;
574 bases=bases_;
575 numericID=(int)numericID_;
576 depthArray=new AtomicIntegerArray(bases.length);
577 insertArray=new AtomicLongArray(bases.length);
578 }
579
580 void add(SamLine sl, int insertSize){
581 assert(sl.mapped() && sl.pairedOnSameChrom());
582 assert(sl.primary());
583 assert(!sl.supplementary());
584 assert(sl.leftmost());
585
586 // final int insertSize=calcInsertSize(sl);
587
588 int start=sl.pos-1;
589 int stop=start+sl.tlen;
590
591 int trim=(int)(sl.length()*trimFraction);
592 start+=trim;
593 stop-=trim;
594
595 for(int i=start; i<stop; i++){
596 if(i>=0 && i<bases.length){
597 depthArray.incrementAndGet(i);
598 insertArray.addAndGet(i, insertSize);
599 }
600 }
601
602 }
603
604 Read fixScaffold(ByteBuilder bb){
605 int streak=0;
606 bb.clear();
607
608 if(insertList!=null){
609 for(int i=0; i<bases.length; i++) {
610 bb.append(i).tab().append(depthArray.get(i)).tab().append(insertArray.get(i)/(Tools.max(1, depthArray.get(i)))).nl();
611 }
612 ReadWrite.writeString(bb, insertList, false);
613 bb.clear();
614 }
615
616 for(int i=0; i<bases.length; i++){
617 byte b=bases[i];
618 if(b=='N'){
619 streak++;
620 }else{
621 if(streak>=scaffoldBreakNs && i-streak>300 && i<bases.length-300){
622 int pivot=i-streak/2-1;
623 long depthSum=depthArray.get(pivot);
624 long insertSum=insertArray.get(pivot);
625 double avgInsert=(insertSum/(double)depthSum);
626
627 int avgDepth=((depthArray.get(i-200-streak)+depthArray.get(i+200))/2);
628 int percentile=(int)(buckets*Tools.max(0.5, 1.0-depthSum/(double)(avgDepth+depthSum)));
629 int insertProxy=insertByPercentile[percentile];
630
631 // assert(false) : Arrays.toString(insertByPercentile);
632
633 int dif=(int)Math.round(insertProxy-avgInsert);
634 int toAdd=Tools.max(scaffoldBreakNs, streak+dif);
635
636 // System.err.println("totalAverageInsert="+(int)totalAverageInsert+", avg="+(int)avgInsert+", dif="+dif);
637 // System.err.println("proxy="+insertProxy+", percentile="+percentile+", avgDepth="+(int)avgDepth+", depth="+depthSum);
638 // System.err.println("pivot="+pivot+", depthSum="+depthSum+", avg="+(int)avgInsert+", streak="+streak+", dif="+dif+", toAdd="+toAdd);
639
640 if(dif>0){
641 //TODO: This is tricky because long-insert reads will be self-selected.
642 //Should be compared to average coverage, or nearby coverage, and then consult a size distribution histogram.
643 gapsWidened++;
644 nsAdded+=dif;
645 }else if(dif<0){
646 gapsNarrowed++;
647 nsRemoved-=dif;
648 }else{
649 gapsUnchanged++;
650 }
651 nsTotal+=toAdd;
652 for(int j=0; j<toAdd; j++){
653 bb.append('N');
654 }
655 }
656 streak=0;
657 bb.append(b);
658 }
659 }
660
661 return new Read(bb.toBytes(), null, name, numericID);
662 }
663
664 final int numericID;
665 final String name;
666 final byte[] bases;
667 final AtomicIntegerArray depthArray;
668 final AtomicLongArray insertArray;
669
670 }
671
672 /*--------------------------------------------------------------*/
673 /*---------------- Fields ----------------*/
674 /*--------------------------------------------------------------*/
675
676 /** Primary input file path */
677 private String in=null;
678 /** Secondary input file path */
679 private String ref=null;
680
681 /** Primary output file path */
682 private String out=null;
683
684 /** Override input file extension */
685 private String extin=null;
686 /** Override output file extension */
687 private String extout=null;
688
689 private String insertList=null;
690
691 /*--------------------------------------------------------------*/
692
693 /** Number of reads processed */
694 protected long readsProcessed=0;
695 /** Number of bases processed */
696 protected long basesProcessed=0;
697
698 /** Number of reads retained */
699 protected long readsOut=0;
700 /** Number of bases retained */
701 protected long basesOut=0;
702
703 protected long scaffoldsOut=0;
704 protected long scaffoldLengthOut=0;
705
706 protected long gapsUnchanged=0;
707 protected long gapsWidened=0;
708 protected long gapsNarrowed=0;
709 protected long nsAdded=0;
710 protected long nsRemoved=0;
711 protected long nsTotal=0;
712
713 protected long totalInsertSum=0;
714 protected long totalInsertCount=0;
715 protected double totalAverageInsert;
716
717 protected AtomicLongArray insertCounts=new AtomicLongArray(20000);
718 protected int[] insertByPercentile;
719
720 /** Quit after processing this many input reads; -1 means no limit */
721 private long maxReads=-1;
722
723 /*--------------------------------------------------------------*/
724
725 /** Threads dedicated to reading the sam file */
726 private int streamerThreads=SamStreamer.DEFAULT_THREADS;
727
728 private boolean loadedRef=false;
729
730 private int scaffoldBreakNs=10;
731
732 int buckets=1000;
733
734 private int minDepth=10;
735
736 private float trimFraction=0.4f;
737
738 public final SamFilter samFilter=new SamFilter();
739
740 /** Uses full ref names */
741 public LinkedHashMap<String, Scaffold> refMap=new LinkedHashMap<String, Scaffold>();
742 /** Uses truncated ref names */
743 public LinkedHashMap<String, Scaffold> refMap2=new LinkedHashMap<String, Scaffold>();;
744
745 /*--------------------------------------------------------------*/
746 /*---------------- Final Fields ----------------*/
747 /*--------------------------------------------------------------*/
748
749 /** Primary input file */
750 private final FileFormat ffin;
751 /** Secondary input file */
752 private final FileFormat ffref;
753
754 /** Primary output file */
755 private final FileFormat ffout;
756
757 @Override
758 public final ReadWriteLock rwlock() {return rwlock;}
759 private final ReadWriteLock rwlock=new ReentrantReadWriteLock();
760
761 /*--------------------------------------------------------------*/
762 /*---------------- Common Fields ----------------*/
763 /*--------------------------------------------------------------*/
764
765 /** Print status messages to this output stream */
766 private PrintStream outstream=System.err;
767 /** Print verbose messages */
768 public static boolean verbose=false;
769 /** True if an error was encountered */
770 public boolean errorState=false;
771 /** Overwrite existing output files */
772 private boolean overwrite=true;
773 /** Append to existing output files */
774 private boolean append=false;
775 /** Reads are output in input order */
776 private boolean ordered=false;
777
778 }