Debian Codegraph @

current/shared/Parser.java

raw symbols SCIP
1 package shared;
2
3 import java.io.File;
4 import java.util.ArrayList;
5 import java.util.Arrays;
6 import java.util.HashSet;
7
8 import align2.QualityTools;
9 import aligner.SideChannel3;
10 import bloom.KCountArray;
11 import bloom.KmerCountAbstract;
12 import cardinality.CardinalityTracker;
13 import cardinality.LogLog16;
14 import cardinality.LogLog2;
15 import dna.AminoAcid;
16 import dna.Data;
17 import fileIO.ByteFile;
18 import fileIO.ByteFile1;
19 import fileIO.FileFormat;
20 import fileIO.ReadWrite;
21 import fileIO.TextFile;
22 import jgi.BBMerge;
23 import jgi.CalcTrueQuality;
24 import kmer.AbstractKmerTable;
25 import sketch.SketchObject;
26 import stream.ConcurrentDepot;
27 import stream.ConcurrentReadInputStream;
28 import stream.FASTQ;
29 import stream.FastaReadInputStream;
30 import stream.Read;
31 import stream.ReadStreamByteWriter;
32 import stream.ReadStreamWriter;
33 import stream.SamLine;
34 import stream.SamStreamer;
35 import structures.IntList;
36 import tax.TaxTree;
37 import tracker.EntropyTracker;
38 import tracker.ReadStats;
39 import var2.CallVariants;
40
41 /**
42 * @author Brian Bushnell
43 * @date Mar 21, 2014
44 *
45 */
46 public class Parser {
47
48 /*--------------------------------------------------------------*/
49 /*---------------- Initialization ----------------*/
50 /*--------------------------------------------------------------*/
51
52 public Parser(){}
53
54 /*--------------------------------------------------------------*/
55 /*---------------- Methods ----------------*/
56 /*--------------------------------------------------------------*/
57
58 public boolean parse(String arg, String a, String b){
59 if(isJavaFlag(arg)){return true;}
60
61 if(parseQuality(arg, a, b)){return true;}
62 if(parseZip(arg, a, b)){return true;}
63 if(parseSam(arg, a, b)){return true;}
64 if(parseFasta(arg, a, b)){return true;}
65 if(parseCommonStatic(arg, a, b)){return true;}
66 if(parseHist(arg, a, b)){return true;}
67 if(parseQualityAdjust(arg, a, b)){return true;}
68
69 if(parseFiles(arg, a, b)){return true;}
70 if(parseCommon(arg, a, b)){return true;}
71 if(parseTrim(arg, a, b)){return true;}
72 if(parseInterleaved(arg, a, b)){return true;}
73 if(parseMapping(arg, a, b)){return true;}
74 if(parseCardinality(arg, a, b)){return true;}
75 return false;
76 }
77
78 public boolean parseCommon(String arg, String a, String b){
79 if(a.equals("reads") || a.equals("maxreads")){
80 maxReads=Parse.parseKMG(b);
81 }else if(a.equals("samplerate")){
82 samplerate=Float.parseFloat(b);
83 assert(samplerate<=1f && samplerate>=0f) : "samplerate="+samplerate+"; should be between 0 and 1";
84 }else if(a.equals("sampleseed")){
85 sampleseed=Long.parseLong(b);
86 }else if(a.equals("append") || a.equals("app")){
87 append=ReadStats.append=Parse.parseBoolean(b);
88 }else if(a.equals("overwrite") || a.equals("ow")){
89 overwrite=Parse.parseBoolean(b);
90 }else if(a.equals("testsize")){
91 testsize=Parse.parseBoolean(b);
92 }else if(a.equals("breaklen") || a.equals("breaklength")){
93 breakLength=Integer.parseInt(b);
94 }else if(a.equals("recalibrate") || a.equals("recalibratequality") || a.equals("recal")){
95 recalibrateQuality=Parse.parseBoolean(b);
96 }else if(a.equals("silent")){
97 silent=Parse.parseBoolean(b);
98 }else{
99 return false;
100 }
101 return true;
102 }
103
104 public boolean parseCardinality(String arg, String a, String b){
105 if(a.equals("cardinality") || a.equals("loglog")){
106 if(b!=null && b.length()>0 && Tools.isDigit(b.charAt(0))){
107 try {
108 loglogk=Integer.parseInt(b);
109 loglog=loglogk>0;
110 } catch (NumberFormatException e) {
111 loglog=Parse.parseBoolean(b);
112 }
113 }else{
114 loglog=Parse.parseBoolean(b);
115 }
116 }else if(a.equals("cardinalityout") || a.equals("loglogout")){
117 if(b!=null && b.length()>0 && Tools.isDigit(b.charAt(0))){
118 try {
119 loglogk=Integer.parseInt(b);
120 loglogOut=loglogk>0;
121 } catch (NumberFormatException e) {
122 loglogOut=Parse.parseBoolean(b);
123 }
124 }else{
125 loglogOut=Parse.parseBoolean(b);
126 }
127 }else if(a.equals("buckets") || a.equals("loglogbuckets")){
128 loglogbuckets=Parse.parseIntKMG(b);
129 assert(loglogbuckets>0);
130 loglogbuckets=CardinalityTracker.powerOf2AtLeast(loglogbuckets);
131 }else if(a.equals("loglogbits")){
132 loglogbits=Integer.parseInt(b);
133 }else if(a.equals("loglogk") || a.equals("cardinalityk") || a.equals("kcardinality")){
134 loglogk=Integer.parseInt(b);
135 loglog=loglogk>0;
136 }else if(a.equals("loglogklist")){
137 String[] split2=b.split(",");
138 for(String k : split2){
139 loglogKlist.add(Integer.parseInt(k));
140 }
141 }else if(a.equals("loglogseed")){
142 loglogseed=Long.parseLong(b);
143 }else if(a.equals("loglogminprob")){
144 loglogMinprob=Float.parseFloat(b);
145 }else if(a.equals("loglogtype")){
146 loglogType=b;
147 }else if(a.equals("loglogmean")){
148 CardinalityTracker.USE_MEAN=true;
149 CardinalityTracker.USE_MEDIAN=CardinalityTracker.USE_MWA=CardinalityTracker.USE_HMEAN=CardinalityTracker.USE_GMEAN=false;
150 }else if(a.equals("loglogmedian")){
151 CardinalityTracker.USE_MEDIAN=true;
152 CardinalityTracker.USE_MEAN=CardinalityTracker.USE_MWA=CardinalityTracker.USE_HMEAN=CardinalityTracker.USE_GMEAN=false;
153 }else if(a.equals("loglogmwa")){
154 CardinalityTracker.USE_MWA=true;
155 CardinalityTracker.USE_MEDIAN=CardinalityTracker.USE_MEAN=CardinalityTracker.USE_HMEAN=CardinalityTracker.USE_GMEAN=false;
156 }else if(a.equals("logloghmean")){
157 CardinalityTracker.USE_HMEAN=true;
158 CardinalityTracker.USE_MEDIAN=CardinalityTracker.USE_MEAN=CardinalityTracker.USE_MWA=CardinalityTracker.USE_GMEAN=false;
159 }else if(a.equals("logloggmean")){
160 CardinalityTracker.USE_GMEAN=true;
161 CardinalityTracker.USE_MEDIAN=CardinalityTracker.USE_MEAN=CardinalityTracker.USE_HMEAN=CardinalityTracker.USE_MWA=false;
162 }else if(a.equals("loglogmantissa")){
163 LogLog2.setMantissaBits(Integer.parseInt(b));
164 LogLog16.setMantissaBits(Integer.parseInt(b));
165 }else if(a.equals("loglogcounts") || a.equals("loglogcount")){
166 CardinalityTracker.trackCounts=Parse.parseBoolean(b);
167 }else{
168 return false;
169 }
170
171 return true;
172 }
173
174 public boolean parseK(String arg, String a, String b){
175 if(a.equalsIgnoreCase("k")){
176 k=Integer.parseInt(b);
177 }else{
178 return false;
179 }
180 return true;
181 }
182
183 public boolean parseInterleaved(String arg, String a, String b){
184 if(a.equals("testinterleaved")){
185 FASTQ.TEST_INTERLEAVED=Parse.parseBoolean(b);
186 System.err.println("Set TEST_INTERLEAVED to "+FASTQ.TEST_INTERLEAVED);
187 setInterleaved=true;
188 }else if(a.equals("forceinterleaved")){
189 FASTQ.FORCE_INTERLEAVED=Parse.parseBoolean(b);
190 System.err.println("Set FORCE_INTERLEAVED to "+FASTQ.FORCE_INTERLEAVED);
191 setInterleaved=true;
192 }else if(a.equals("interleaved") || a.equals("int")){
193 if("auto".equalsIgnoreCase(b)){FASTQ.FORCE_INTERLEAVED=!(FASTQ.TEST_INTERLEAVED=true);}
194 else{
195 FASTQ.FORCE_INTERLEAVED=FASTQ.TEST_INTERLEAVED=Parse.parseBoolean(b);
196 System.err.println("Set INTERLEAVED to "+FASTQ.FORCE_INTERLEAVED);
197 setInterleaved=true;
198 }
199 }else if(a.equals("overrideinterleaved")){
200 boolean x=Parse.parseBoolean(b);
201 ReadStreamByteWriter.ignorePairAssertions=x;
202 if(x){setInterleaved=true;}
203 }else{
204 return false;
205 }
206 return true;
207 }
208
209 public boolean parseQTrim(String arg, String a, String b){
210 if(a.equals("qtrim1")){
211 if(b!=null && ("f".equalsIgnoreCase(b) || "false".equalsIgnoreCase(b))){qtrim1=false;}
212 else{
213 qtrim1=true;
214 qtrim2=false;
215 }
216 a="qtrim";
217 }else if(a.equals("qtrim2")){
218 if(b!=null && ("f".equalsIgnoreCase(b) || "false".equalsIgnoreCase(b))){qtrim2=false;}
219 else{
220 qtrim2=true;
221 qtrim1=false;
222 }
223 a="qtrim";
224 }else if(a.equals("trimq2")){
225 if(b!=null && ("f".equalsIgnoreCase(b) || "false".equalsIgnoreCase(b))){qtrim2=false;}
226 else{
227 qtrim2=true;
228 qtrim1=false;
229 }
230 a="trimq";
231 }
232
233 if(a.equals("qtrim")/* || a.equals("trim")*/){
234 if(b==null || b.length()==0){qtrimRight=qtrimLeft=true;}
235 else if(b.equalsIgnoreCase("left") || b.equalsIgnoreCase("l")){qtrimLeft=true;qtrimRight=false;}
236 else if(b.equalsIgnoreCase("right") || b.equalsIgnoreCase("r")){qtrimLeft=false;qtrimRight=true;}
237 else if(b.equalsIgnoreCase("both") || b.equalsIgnoreCase("rl") || b.equalsIgnoreCase("lr")){qtrimLeft=qtrimRight=true;}
238 else if(b.equalsIgnoreCase("window") || b.equalsIgnoreCase("w") || b.startsWith("window,") || b.startsWith("w,")){
239 qtrimLeft=false;
240 qtrimRight=true;
241 TrimRead.windowMode=true;
242 TrimRead.optimalMode=false;
243 String[] split=b.split(",");
244 if(b.length()>1){
245 TrimRead.windowLength=Integer.parseInt(split[1]);
246 }
247 }else if(Tools.isDigit(b.charAt(0))){
248 parseTrimq(a, b);
249 qtrimRight=true;
250 }else{qtrimRight=qtrimLeft=Parse.parseBoolean(b);}
251 }else if(a.equals("optitrim") || a.equals("otf") || a.equals("otm")){
252 if(b!=null && (b.charAt(0)=='.' || Tools.isDigit(b.charAt(0)))){
253 TrimRead.optimalMode=true;
254 TrimRead.optimalBias=Float.parseFloat(b);
255 assert(TrimRead.optimalBias>=0 && TrimRead.optimalBias<1);
256 }else{
257 TrimRead.optimalMode=Parse.parseBoolean(b);
258 }
259 }else if(a.equals("trimgoodinterval")){
260 TrimRead.minGoodInterval=Integer.parseInt(b);
261 }else if(a.equals("trimright") || a.equals("qtrimright")){
262 qtrimRight=Parse.parseBoolean(b);
263 }else if(a.equals("trimleft") || a.equals("qtrimleft")){
264 qtrimLeft=Parse.parseBoolean(b);
265 }else if(a.equals("trimq") || a.equals("trimquality") || a.equals("trimq2")){
266 parseTrimq(a, b);
267 }else if(a.equals("trimclip")){
268 trimClip=Parse.parseBoolean(b);
269 }else if(a.equals("trimpolya")){
270 trimPolyA=parsePoly(b);
271 }
272
273 else if(a.equals("trimpolyg")){
274 trimPolyGLeft=trimPolyGRight=parsePoly(b);
275 }else if(a.equals("trimpolygleft")){
276 trimPolyGLeft=parsePoly(b);
277 }else if(a.equals("trimpolygright")){
278 trimPolyGRight=parsePoly(b);
279 }else if(a.equals("filterpolyg")){
280 filterPolyG=parsePoly(b);
281 }
282
283 else if(a.equals("trimpolyc")){
284 trimPolyCLeft=trimPolyCRight=parsePoly(b);
285 }else if(a.equals("trimpolycleft")){
286 trimPolyCLeft=parsePoly(b);
287 }else if(a.equals("trimpolycright")){
288 trimPolyCRight=parsePoly(b);
289 }else if(a.equals("filterpolyc")){
290 filterPolyC=parsePoly(b);
291 }
292
293 else if(a.equals("maxnonpoly")){
294 maxNonPoly=parsePoly(b);
295 }
296
297 else{
298 return false;
299 }
300 return true;
301 }
302
303 public static int parsePoly(String b){
304 int r=2;
305 if(b!=null){
306 if(Tools.isDigit(b.charAt(0))){
307 r=Integer.parseInt(b);
308 }else{
309 boolean x=Parse.parseBoolean(b);
310 r=x ? 2 : 0;
311 }
312 }
313 return r;
314 }
315
316 public boolean parseTrim(String arg, String a, String b){
317
318 if(parseQTrim(arg, a, b)){
319 //do nothing
320 }else if(a.equals("forcetrimmod") || a.equals("forcemrimmodulo") || a.equals("ftm")){
321 forceTrimModulo=Integer.parseInt(b);
322 }else if(a.equals("ftl") || a.equals("forcetrimleft")){
323 forceTrimLeft=Integer.parseInt(b);
324 }else if(a.equals("ftr") || a.equals("forcetrimright")){
325 forceTrimRight=Integer.parseInt(b);
326 }else if(a.equals("ftr2") || a.equals("forcetrimright2")){
327 forceTrimRight2=Integer.parseInt(b);
328 }else if(a.equals("trimbadsequence")){
329 trimBadSequence=Parse.parseBoolean(b);
330 }else if(a.equals("chastityfilter") || a.equals("cf")){
331 chastityFilter=Parse.parseBoolean(b);
332 }else if(a.equals("failnobarcode")){
333 failIfNoBarcode=Parse.parseBoolean(b);
334 }else if(a.equals("badbarcodes") || a.equals("barcodefilter")){
335 if(b!=null && (b.equalsIgnoreCase("crash") || b.equalsIgnoreCase("fail"))){
336 failBadBarcodes=true;
337 removeBadBarcodes=true;
338 }else{
339 removeBadBarcodes=Parse.parseBoolean(b);
340 failBadBarcodes=false;
341 }
342 }else if(a.equals("barcodes") || a.equals("barcode")){
343 if(b==null || b.length()<1){
344 barcodes=null;
345 }else{
346 barcodes=new HashSet<String>();
347 for(String s : b.split(",")){
348 Tools.addNames(s, barcodes, false);
349 }
350 }
351 if(barcodes!=null && barcodes.size()>0 && !failBadBarcodes && !removeBadBarcodes){
352 removeBadBarcodes=true;
353 }
354 }else if(a.equals("requirebothbad") || a.equals("rbb")){
355 requireBothBad=Parse.parseBoolean(b);
356 }else if(a.equals("removeifeitherbad") || a.equals("rieb")){
357 requireBothBad=!Parse.parseBoolean(b);
358 }else if(a.equals("ml") || a.equals("minlen") || a.equals("minlength")){
359 minReadLength=Parse.parseIntKMG(b);
360 }else if(a.equals("maxlength") || a.equals("maxreadlength") || a.equals("maxreadlen") || a.equals("maxlen")){
361 maxReadLength=Parse.parseIntKMG(b);
362 }else if(a.equals("mingc")){
363 minGC=Float.parseFloat(b);
364 // if(minGC>0){filterGC=true;}
365 assert(minGC>=0 && minGC<=1) : "mingc should be a decimal number between 0 and 1, inclusive.";
366 }else if(a.equals("maxgc")){
367 maxGC=Float.parseFloat(b);
368 // if(maxGC<1){filterGC=true;}
369 assert(minGC>=0 && minGC<=1) : "maxgc should be a decimal number between 0 and 1, inclusive.";
370 }else if(a.equals("usepairgc") || a.equals("pairgc")){
371 usePairGC=Parse.parseBoolean(b);
372 ReadStats.usePairGC=usePairGC;
373 }else if(a.equals("mlf") || a.equals("minlenfrac") || a.equals("minlenfraction") || a.equals("minlengthfraction")){
374 minLenFraction=Float.parseFloat(b);
375 }else if(a.equals("maxns")){
376 maxNs=Integer.parseInt(b);
377 }else if(a.equals("minconsecutivebases") || a.equals("mcb")){
378 minConsecutiveBases=Integer.parseInt(b);
379 }else if(a.equals("minavgquality") || a.equals("minaveragequality") || a.equals("maq")){
380 if(b.indexOf(',')>-1){
381 String[] split=b.split(",");
382 assert(split.length==2) : "maq should be length 1 or 2 (at most 1 comma).\nFormat: maq=quality,bases; e.g. maq=10 or maq=10,20";
383 minAvgQuality=Float.parseFloat(split[0]);
384 minAvgQualityBases=Integer.parseInt(split[1]);
385 }else{
386 minAvgQuality=Float.parseFloat(b);
387 }
388 }else if(a.equals("minavgqualitybases") || a.equals("maqb")){
389 minAvgQualityBases=Integer.parseInt(b);
390 }else if(a.equals("minbasequality") || a.equals("mbq")){
391 minBaseQuality=Byte.parseByte(b);
392 }else if(a.equals("averagequalitybyprobability") || a.equals("aqbp")){
393 Read.AVERAGE_QUALITY_BY_PROBABILITY=Parse.parseBoolean(b);
394 }else if(a.equals("mintl") || a.equals("mintrimlen") || a.equals("mintrimlength")){
395 minTrimLength=Integer.parseInt(b);
396 }else if(a.equals("untrim")){
397 untrim=Parse.parseBoolean(b);
398 }else if(a.equals("tossjunk")){
399 boolean x=Parse.parseBoolean(b);
400 tossJunk=x;
401 if(x){Read.JUNK_MODE=Read.FLAG_JUNK;}
402 }else{
403 return false;
404 }
405 return true;
406 }
407
408 private void parseTrimq(String a, String b){
409 if(b.indexOf(',')>=0){
410 String[] split=b.split(",");
411 trimq2=new float[split.length];
412 for(int i=0; i<split.length; i++){
413 trimq2[i]=Float.parseFloat(split[i]);
414 }
415 trimq=trimq2.length<1 ? 0 : trimq2[0];
416 }else{
417 trimq=Float.parseFloat(b);
418 trimq2=null;
419 }
420 // assert(false) : Arrays.toString(trimq2);
421 }
422
423 public boolean parseFiles(String arg, String a, String b){
424 if(a.equals("in") || a.equals("input") || a.equals("in1") || a.equals("input1")){
425 in1=b;
426 }else if(a.equals("in2") || a.equals("input2")){
427 in2=b;
428 }else if(a.equals("out") || a.equals("output") || a.equals("out1") || a.equals("output1")){
429 out1=b;
430 setOut=true;
431 }else if(a.equals("out2") || a.equals("output2")){
432 out2=b;
433 setOut=true;
434 }else if(a.equals("qfin") || a.equals("qfin1")){
435 qfin1=b;
436 }else if(a.equals("qfout") || a.equals("qfout1")){
437 qfout1=b;
438 setOut=true;
439 }else if(a.equals("qfin2")){
440 qfin2=b;
441 }else if(a.equals("qfout2")){
442 qfout2=b;
443 setOut=true;
444 }else if(a.equals("extin")){
445 extin=b;
446 }else if(a.equals("extout")){
447 extout=b;
448 }else if(a.equals("outsingle") || a.equals("outs")){
449 outsingle=b;
450 setOut=true;
451 }else{
452 return false;
453 }
454 return true;
455 }
456
457 public boolean parseMapping(String arg, String a, String b){
458 if(a.equals("idfilter") || a.equals("identityfilter") || a.equals("minidfilter") || a.equals("minidentityfilter")){
459 minIdFilter=Float.parseFloat(b);
460 if(minIdFilter>1f){minIdFilter/=100;}
461 assert(minIdFilter<=1f) : "idfilter should be between 0 and 1.";
462 }else if(a.equals("maxidfilter") || a.equals("maxidentityfilter") || a.equals("maxid")){
463 maxIdFilter=Float.parseFloat(b);
464 if(maxIdFilter>1f){maxIdFilter/=100;}
465 assert(maxIdFilter<=1f) : "idfilter should be between 0 and 1.";
466 }else if(a.equals("subfilter")){
467 subfilter=Integer.parseInt(b);
468 }else if(a.equals("clipfilter")){
469 clipfilter=Integer.parseInt(b);
470 }else if(a.equals("nfilter")){
471 nfilter=Integer.parseInt(b);
472 }else if(a.equals("delfilter")){
473 delfilter=Integer.parseInt(b);
474 }else if(a.equals("insfilter")){
475 insfilter=Integer.parseInt(b);
476 }else if(a.equals("indelfilter")){
477 indelfilter=Integer.parseInt(b);
478 }else if(a.equals("dellenfilter")){
479 dellenfilter=Integer.parseInt(b);
480 }else if(a.equals("inslenfilter")){
481 inslenfilter=Integer.parseInt(b);
482 }else if(a.equals("editfilter")){
483 editfilter=Integer.parseInt(b);
484 }else if(a.equals("build") || a.equals("genome")){
485 build=Integer.parseInt(b);
486 Data.GENOME_BUILD=build;
487 }else{
488 return false;
489 }
490 return true;
491 }
492
493
494 /*--------------------------------------------------------------*/
495 /*---------------- Static Methods ----------------*/
496 /*--------------------------------------------------------------*/
497
498 static String[] parseConfig(String[] args){
499 boolean found=false;
500 for(String s : args){
501 if(Tools.startsWithIgnoreCase(s, "config=")){
502 found=true;
503 break;
504 }
505 }
506 if(!found){return args;}
507 ArrayList<String> list=new ArrayList<String>();
508 for(int i=0; i<args.length; i++){
509 final String arg=(args[i]==null ? "null" : args[i]);
510 final String[] split=arg.split("=");
511 final String a=split[0].toLowerCase();
512 String b=split.length>1 ? split[1] : null;
513 if("null".equalsIgnoreCase(b)){b=null;}
514
515 if(a.equals("config")){
516 assert(b!=null) : "Bad parameter: "+arg;
517 for(String bb : b.split(",")){
518 try{
519 TextFile tf=new TextFile(bb);
520 for(String line=tf.nextLine(); line!=null; line=tf.nextLine()){
521 String line2=line.trim();
522 if(line2.length()>0 && !line2.startsWith("#")){
523 list.add(line2);
524 }
525 }
526 tf.close();
527 }catch(Throwable t){
528 throw new RuntimeException("Could not process config file "+b+"\nCaused by:\n"+t.toString()+"\n");
529 }
530 }
531 }else if(arg!=null && !"null".equals(arg)){
532 list.add(arg);
533 }
534 }
535 return list.toArray(new String[list.size()]);
536 }
537
538 public static boolean parseCommonStatic(String arg, String a, String b){
539 if(a.equals("null")){
540 //Do nothing
541 }else if(a.equals("monitor") || a.equals("killswitch")){
542 if(Parse.isNumber(b)){
543 String[] pair=b.split(",");
544 if(pair.length==1){
545 KillSwitch.launch(Double.parseDouble(pair[0]));
546 }else{
547 assert(pair.length==2) : "monitor takes one or two arguments, like this: monitor=600,0.002";
548 KillSwitch.launch(Double.parseDouble(pair[0]), Double.parseDouble(pair[1]));
549 }
550 }else if(Parse.parseBoolean(b)){
551 KillSwitch.launch();
552 }
553 }else if(a.equals("trd") || a.equals("trc") || a.equals("trimreaddescription") || a.equals("trimreaddescriptions")){
554 Shared.TRIM_READ_COMMENTS=Parse.parseBoolean(b);
555 if(!setTrimRname){Shared.TRIM_RNAME=Shared.TRIM_READ_COMMENTS;}
556 }else if(a.equals("trimrefdescription") || a.equals("trimrefdescriptions") || a.equals("trimrname")){
557 Shared.TRIM_RNAME=Parse.parseBoolean(b);
558 setTrimRname=true;
559 }else if(a.equals("tuc") || a.equals("touppercase")){
560 Read.TO_UPPER_CASE=Parse.parseBoolean(b);
561 }else if(a.equals("lctn") || a.equals("lowercaseton")){
562 Read.LOWER_CASE_TO_N=Parse.parseBoolean(b);
563 }else if(a.equals("changequality") || a.equals("cq")){
564 Read.CHANGE_QUALITY=Parse.parseBoolean(b);
565 BBMerge.changeQuality=Read.CHANGE_QUALITY;
566 }else if(a.equals("tossbrokenreads") || a.equals("tbr")){
567 boolean x=Parse.parseBoolean(b);
568 Read.TOSS_BROKEN_QUALITY=x;
569 ConcurrentReadInputStream.REMOVE_DISCARDED_READS=x;
570 }else if(a.equals("nullifybrokenquality") || a.equals("nbq")){
571 boolean x=Parse.parseBoolean(b);
572 Read.NULLIFY_BROKEN_QUALITY=x;
573 }else if(a.equals("dotdashxton")){
574 boolean x=Parse.parseBoolean(b);
575 Read.DOT_DASH_X_TO_N=x;
576 }else if(a.equals("junk")){
577 if("ignore".equalsIgnoreCase(b)){Read.JUNK_MODE=Read.IGNORE_JUNK;}
578 else if("crash".equalsIgnoreCase(b) || "fail".equalsIgnoreCase(b)){Read.JUNK_MODE=Read.CRASH_JUNK;}
579 else if("fix".equalsIgnoreCase(b)){Read.JUNK_MODE=Read.FIX_JUNK;}
580 else if("flag".equalsIgnoreCase(b) || "discard".equalsIgnoreCase(b)){Read.JUNK_MODE=Read.FLAG_JUNK;}
581 else if("iupacton".equalsIgnoreCase(b)){Read.JUNK_MODE=Read.FIX_JUNK_AND_IUPAC;}
582 else{assert(false) : "Bad junk mode: "+arg;}
583 }else if(a.equals("undefinedton") || a.equals("iupacton") || a.equals("itn")){
584 Read.IUPAC_TO_N=Parse.parseBoolean(b);
585 }else if(a.equals("ignorejunk")){
586 boolean x=Parse.parseBoolean(b);
587 if(x){Read.JUNK_MODE=Read.IGNORE_JUNK;}
588 else if(Read.JUNK_MODE==Read.IGNORE_JUNK){Read.JUNK_MODE=Read.CRASH_JUNK;}
589 }else if(a.equals("flagjunk")){
590 boolean x=Parse.parseBoolean(b);
591 if(x){Read.JUNK_MODE=Read.FLAG_JUNK;}
592 else if(Read.JUNK_MODE==Read.FLAG_JUNK){Read.JUNK_MODE=Read.CRASH_JUNK;}
593 }else if(a.equals("fixjunk")){
594 boolean x=Parse.parseBoolean(b);
595 if(x){Read.JUNK_MODE=Read.FIX_JUNK;}
596 else if(Read.JUNK_MODE==Read.FIX_JUNK){Read.JUNK_MODE=Read.CRASH_JUNK;}
597 }else if(a.equals("crashjunk") || a.equals("failjunk")){
598 boolean x=Parse.parseBoolean(b);
599 if(x){Read.JUNK_MODE=Read.CRASH_JUNK;}
600 else if(Read.JUNK_MODE==Read.CRASH_JUNK){Read.JUNK_MODE=Read.IGNORE_JUNK;}
601 }else if(a.equals("skipvalidation")){
602 Read.SKIP_SLOW_VALIDATION=Parse.parseBoolean(b);
603 }else if(a.equals("validate")){
604 Read.SKIP_SLOW_VALIDATION=!Parse.parseBoolean(b);
605 }else if(a.equals("validatebranchless")){
606 // Read.VALIDATE_BRANCHLESS=Parse.parseBoolean(b);
607 }else if(a.equals("bf1")){
608 ByteFile.FORCE_MODE_BF1=Parse.parseBoolean(b);
609 ByteFile.FORCE_MODE_BF2=!ByteFile.FORCE_MODE_BF1;
610 }else if(a.equals("bf1bufferlen")){
611 ByteFile1.bufferlen=(int)Parse.parseKMGBinary(b);
612 }else if(a.equals("utot")){
613 Read.U_TO_T=Parse.parseBoolean(b);
614 }else if(a.equals("bf2")){
615 ByteFile.FORCE_MODE_BF2=Parse.parseBoolean(b);
616 ByteFile.FORCE_MODE_BF1=!ByteFile.FORCE_MODE_BF2;
617 }else if(a.equals("bf3")){
618 ByteFile.FORCE_MODE_BF3=Parse.parseBoolean(b);
619 if(ByteFile.FORCE_MODE_BF3){
620 ByteFile.FORCE_MODE_BF1=true;
621 ByteFile.FORCE_MODE_BF2=false;
622 }
623 }else if(a.equals("usejni") || a.equals("jni")){
624 Shared.USE_JNI=Parse.parseBoolean(b);
625 }else if(a.equals("usempi") || a.equals("mpi")){
626 if(b!=null && Tools.isDigit(b.charAt(0))){
627 Shared.MPI_NUM_RANKS=Integer.parseInt(b);
628 Shared.USE_MPI=Shared.MPI_NUM_RANKS>0;
629 }else{
630 Shared.USE_MPI=Parse.parseBoolean(b);
631 }
632 }else if(a.equals("crismpi")){
633 Shared.USE_CRISMPI=Parse.parseBoolean(b);
634 }else if(a.equals("mpikeepall")){
635 Shared.MPI_KEEP_ALL=Parse.parseBoolean(b);
636 }else if(a.equals("readbufferlength") || a.equals("readbufferlen")){
637 Shared.setBufferLen((int)Parse.parseKMG(b));
638 }else if(a.equals("readbufferdata")){
639 Shared.setBufferData(Parse.parseKMG(b));
640 }else if(a.equals("readbuffers")){
641 Shared.setBuffers(Integer.parseInt(b));
642 }else if(a.equals("rbm") || a.equals("renamebymapping")){
643 FASTQ.TAG_CUSTOM=Parse.parseBoolean(b);
644 }else if(a.equals("don") || a.equals("deleteoldname")){
645 FASTQ.DELETE_OLD_NAME=Parse.parseBoolean(b);
646 }else if(a.equals("assertcigar")){
647 ReadStreamWriter.ASSERT_CIGAR=Parse.parseBoolean(b);
648 }else if(a.equals("verbosesamline")){
649 SamLine.verbose=Parse.parseBoolean(b);
650 }else if(a.equals("parsecustom") || a.equals("fastqparsecustom")){
651 FASTQ.PARSE_CUSTOM=Parse.parseBoolean(b);
652 System.err.println("Set FASTQ.PARSE_CUSTOM to "+FASTQ.PARSE_CUSTOM);
653 }else if(a.equals("shrinkheaders")){
654 FASTQ.SHRINK_HEADERS=Parse.parseBoolean(b);
655 }else if(a.equals("fairqueues")){
656 ConcurrentDepot.fair=Parse.parseBoolean(b);
657 }else if(a.equals("fixheader") || a.equals("fixheaders")){
658 Read.FIX_HEADER=Parse.parseBoolean(b);
659 }else if(a.equals("allownullheader") || a.equals("allownullheaders")){
660 Read.ALLOW_NULL_HEADER=Parse.parseBoolean(b);
661 }else if(a.equals("aminoin") || a.equals("amino")){
662 //TODO: ensure changes to this do not conflict with TranslateSixFrames "aain" flag.
663 Shared.AMINO_IN=SketchObject.amino=Parse.parseBoolean(b);
664 }else if(a.equals("amino8")){
665 SketchObject.amino8=Parse.parseBoolean(b);
666 if(SketchObject.amino8){
667 Shared.AMINO_IN=SketchObject.amino=true;
668 AminoAcid.AMINO_SHIFT=3;
669 }
670 }else if(a.equals("maxcalledquality")){
671 int x=Tools.mid(1, Integer.parseInt(b), 93);
672 Read.setMaxCalledQuality((byte)x);
673 }else if(a.equals("mincalledquality")){
674 int x=Tools.mid(0, Integer.parseInt(b), 93);
675 Read.setMinCalledQuality((byte)x);
676 }else if(a.equals("t") || a.equals("threads")){
677 int old=Shared.threads();
678 Shared.setThreads(b);
679 if(!silent && printSetThreads && old!=Shared.threads()){
680 System.err.println("Set threads to "+Shared.threads());
681 }
682 }else if(a.equals("recalpairnum") || a.equals("recalibratepairnum")){
683 CalcTrueQuality.USE_PAIRNUM=Parse.parseBoolean(b);
684 }else if(a.equals("taxpath")){
685 if("auto".equalsIgnoreCase(b)){
686 TaxTree.TAX_PATH=TaxTree.defaultTaxPath();
687 }else{
688 TaxTree.TAX_PATH=b.replaceAll("\\\\", "/");
689 }
690 }else if(a.equals("parallelsort") || a.equals("paralellsort")){
691 boolean x=Parse.parseBoolean(b);
692 Shared.setParallelSort(x);
693 }else if(a.equals("gcbeforemem")){
694 Shared.GC_BEFORE_PRINT_MEMORY=Parse.parseBoolean(b);
695 }else if(a.equals("warnifnosequence")){
696 FastaReadInputStream.WARN_IF_NO_SEQUENCE=Parse.parseBoolean(b);
697 }else if(a.equals("warnfirsttimeonly")){
698 FastaReadInputStream.WARN_FIRST_TIME_ONLY=Parse.parseBoolean(b);
699 }else if(a.equals("silva")){
700 TaxTree.SILVA_MODE=Parse.parseBoolean(b);
701 }else if(a.equals("unite")){
702 TaxTree.UNITE_MODE=Parse.parseBoolean(b);
703 }else if(a.equals("imghq")){
704 TaxTree.IMG_HQ=Parse.parseBoolean(b);
705 }
706
707 else if(a.equals("callins") || a.equals("callinss")){
708 var2.Var.CALL_INS=Parse.parseBoolean(b);
709 }else if(a.equals("calldel") || a.equals("calldels")){
710 var2.Var.CALL_DEL=Parse.parseBoolean(b);
711 }else if(a.equals("callsub") || a.equals("callsubs") || a.equals("callsnp") || a.equals("callsnps")){
712 var2.Var.CALL_SUB=Parse.parseBoolean(b);
713 }else if(a.equals("callindel") || a.equals("callindels")){
714 var2.Var.CALL_INS=var2.Var.CALL_DEL=Parse.parseBoolean(b);
715 }else if(a.equals("calljunct") || a.equals("calljunction") || a.equals("calljunctions")){
716 var2.Var.CALL_JUNCTION=Parse.parseBoolean(b);
717 }else if(a.equals("callnocall") || a.equals("callnocalls")){
718 var2.Var.CALL_NOCALL=Parse.parseBoolean(b);
719 }else if(a.equals("kmg") || a.equals("outputkmg")){
720 Shared.OUTPUT_KMG=Parse.parseBoolean(b);
721 }
722
723 else if(a.equals("tmpdir")){
724 Shared.setTmpdir(b);
725 }
726
727 else if(a.equals("comment")){
728 Shared.comment=b;
729 }
730
731 else if(a.equals("fixextensions") || a.equals("fixextension") || a.equals("tryallextensions")){
732 Shared.FIX_EXTENSIONS=Parse.parseBoolean(b);
733 }
734
735 else if(a.equals("2passresize") || a.equals("twopassresize")){
736 AbstractKmerTable.TWO_PASS_RESIZE=Parse.parseBoolean(b);
737 }
738
739 else if(a.equalsIgnoreCase("forceJavaParseDouble")){
740 Tools.FORCE_JAVA_PARSE_DOUBLE=Parse.parseBoolean(b);
741 }
742
743 else if(a.equalsIgnoreCase("simd")){
744 Shared.SIMD=Parse.parseBoolean(b);
745 }else if(a.equalsIgnoreCase("simdsparse")){
746 Vector.SIMD_MULT_SPARSE=Vector.SIMD_FMA_SPARSE=Parse.parseBoolean(b);
747 }else if(a.equalsIgnoreCase("simdmultsparse")){
748 Vector.SIMD_MULT_SPARSE=Parse.parseBoolean(b);
749 }else if(a.equalsIgnoreCase("simdfmasparse")){
750 Vector.SIMD_FMA_SPARSE=Parse.parseBoolean(b);
751 }else if(a.equalsIgnoreCase("simdcopy")){
752 Vector.SIMDCOPY=Parse.parseBoolean(b);
753 }
754 // else if(a.equalsIgnoreCase("simdminlen")) {//Disabled.
755 // Vector.MINLEN=Integer.parseInt(b);
756 // }
757
758 else if(a.equalsIgnoreCase("awsServers") || a.equalsIgnoreCase("aws")){
759 Shared.awsServers=Parse.parseBoolean(b);
760 }else if(a.equalsIgnoreCase("nerscServers") || a.equalsIgnoreCase("nersc")){
761 Shared.awsServers=!Parse.parseBoolean(b);
762 }
763
764 else if(a.equals("entropyk") || a.equals("ek")){
765 EntropyTracker.defaultK=Integer.parseInt(b);
766 EntropyTracker.setDefaultK=true;
767 }else if(a.equals("entropywindow") || a.equals("ew")){
768 EntropyTracker.defaultWindowBases=Integer.parseInt(b);
769 EntropyTracker.setDefaultWindow=true;
770 }else if(a.equalsIgnoreCase("protFull")){
771 TaxTree.protFull=true;
772 }
773
774 else if(a.equalsIgnoreCase("lockedincrement") || a.equalsIgnoreCase("symmetricwrite")
775 || a.equalsIgnoreCase("symmetric") || a.equalsIgnoreCase("sw")){
776 if("auto".equalsIgnoreCase(b)){
777 KCountArray.LOCKED_INCREMENT=true;
778 KCountArray.SET_LOCKED_INCREMENT=false;
779 }else{
780 KCountArray.LOCKED_INCREMENT=Parse.parseBoolean(b);
781 KCountArray.SET_LOCKED_INCREMENT=true;
782 }
783 }
784
785 else if(a.equalsIgnoreCase("buffer") || a.equalsIgnoreCase("buffered")){
786 if(b!=null && Character.isDigit(b.charAt(0))){
787 int x=Parse.parseIntKMG(b);
788 KmerCountAbstract.BUFFERED=x>1;
789 if(x>1){KmerCountAbstract.BUFFERLEN=x;}
790 }else{
791 KmerCountAbstract.BUFFERED=Parse.parseBoolean(b);
792 }
793 }
794
795 else if(a.equalsIgnoreCase("pairreads") && b!=null){
796 FASTQ.PAIR_READS=Parse.parseBoolean(b);
797 }else if(a.equalsIgnoreCase("flipr2")){
798 FASTQ.FLIP_R2=Parse.parseBoolean(b);
799 }
800
801 else if(a.equalsIgnoreCase("sidechannelstats")){
802 SideChannel3.TRACK_STATS=Parse.parseBoolean(b);
803 }
804
805 // else if(a.equalsIgnoreCase("sortserial")){
806 // KmerCountAbstract.SORT_SERIAL=Parse.parseBoolean(b);
807 // }
808
809 else{
810 return false;
811 }
812 return true;
813 }
814
815 public static boolean parseQuality(String arg, String a, String b){
816 parsedQuality=true; //For internal verification that this function was indeed called.
817 if(a.equals("ignorebadquality") || a.equals("ibq")){
818 FASTQ.IGNORE_BAD_QUALITY=Parse.parseBoolean(b);
819 if(FASTQ.IGNORE_BAD_QUALITY){Read.CHANGE_QUALITY=false;}
820 }else if(a.equals("ascii") || a.equals("asciioffset") || a.equals("quality") || a.equals("qual")){
821 byte x;
822 if(b.equalsIgnoreCase("sanger")){x=33;}
823 else if(b.equalsIgnoreCase("illumina")){x=64;}
824 else if(b.equalsIgnoreCase("auto")){x=-1;FASTQ.DETECT_QUALITY=FASTQ.DETECT_QUALITY_OUT=true;}
825 else{x=(byte)Integer.parseInt(b);}
826 qin=qout=x;
827 FASTQ.SET_QIN=x>-1;
828 }else if(a.equals("asciiin") || a.equals("qualityin") || a.equals("qualin") || a.equals("qin")){
829 byte x;
830 if(b.equalsIgnoreCase("sanger")){x=33;}
831 else if(b.equalsIgnoreCase("illumina")){x=64;}
832 else if(b.equalsIgnoreCase("auto")){x=-1;FASTQ.DETECT_QUALITY=true;}
833 else{x=(byte)Integer.parseInt(b);}
834 qin=x;
835 FASTQ.SET_QIN=x>-1;
836 }else if(a.equals("asciiout") || a.equals("qualityout") || a.equals("qualout") || a.equals("qout")){
837 byte x;
838 if(b.equalsIgnoreCase("sanger")){x=33;}
839 else if(b.equalsIgnoreCase("illumina")){x=64;}
840 else if(b.equalsIgnoreCase("auto")){x=-1;FASTQ.DETECT_QUALITY_OUT=true;}
841 else{x=(byte)Integer.parseInt(b);}
842 qout=x;
843 }else if(a.equals("fakequality") || a.equals("qfake")){
844 Shared.FAKE_QUAL=Byte.parseByte(b);
845 }else if(a.equals("fakefastaqual") || a.equals("fakefastaquality") || a.equals("ffq")){
846 if(b==null || b.length()<1){b="f";}
847 if(Character.isLetter(b.charAt(0))){
848 FastaReadInputStream.FAKE_QUALITY=Parse.parseBoolean(b);
849 }else{
850 int x=Integer.parseInt(b);
851 if(x<1){
852 FastaReadInputStream.FAKE_QUALITY=false;
853 }else{
854 FastaReadInputStream.FAKE_QUALITY=true;
855 Shared.FAKE_QUAL=(byte)Tools.min(x, 50);
856 }
857 }
858 }else if(a.equals("qauto")){
859 FASTQ.DETECT_QUALITY=FASTQ.DETECT_QUALITY_OUT=true;
860 }else{
861 return false;
862 }
863 return true;
864 }
865
866 private static boolean qhistsNull(){
867 return ReadStats.BQUAL_HIST_FILE==null && ReadStats.QUAL_HIST_FILE!=null && ReadStats.AVG_QUAL_HIST_FILE!=null && ReadStats.BQUAL_HIST_OVERALL_FILE!=null
868 && ReadStats.QUAL_COUNT_HIST_FILE==null;
869 }
870
871 public static boolean parseHist(String arg, String a, String b){
872 if(a.equals("qualityhistogram") || a.equals("qualityhist") || a.equals("qhist")){
873 ReadStats.QUAL_HIST_FILE=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
874 ReadStats.COLLECT_QUALITY_STATS=!qhistsNull();
875 if(ReadStats.COLLECT_QUALITY_STATS){System.err.println("Set quality histogram output to "+ReadStats.QUAL_HIST_FILE);}
876 }else if(a.equals("basequalityhistogram") || a.equals("basequalityhist") || a.equals("bqhist")){
877 ReadStats.BQUAL_HIST_FILE=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
878 ReadStats.COLLECT_QUALITY_STATS=!qhistsNull();
879 if(ReadStats.BQUAL_HIST_FILE!=null){System.err.println("Set bquality histogram output to "+ReadStats.BQUAL_HIST_FILE);}
880 }else if(a.equals("qualitycounthistogram") || a.equals("qualitycounthist") || a.equals("qchist") || a.equals("qdhist") || a.equals("qfhist")){
881 ReadStats.QUAL_COUNT_HIST_FILE=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
882 ReadStats.COLLECT_QUALITY_STATS=!qhistsNull();
883 if(ReadStats.QUAL_COUNT_HIST_FILE!=null){System.err.println("Set qcount histogram output to "+ReadStats.QUAL_COUNT_HIST_FILE);}
884 }else if(a.equals("averagequalityhistogram") || a.equals("aqhist")){
885 ReadStats.AVG_QUAL_HIST_FILE=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
886 ReadStats.COLLECT_QUALITY_STATS=!qhistsNull();
887 if(ReadStats.COLLECT_QUALITY_STATS){System.err.println("Set average quality histogram output to "+ReadStats.AVG_QUAL_HIST_FILE);}
888 }else if(a.equals("overallbasequalityhistogram") || a.equals("overallbasequalityhist") || a.equals("obqhist")){
889 ReadStats.BQUAL_HIST_OVERALL_FILE=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
890 ReadStats.COLLECT_QUALITY_STATS=(ReadStats.BQUAL_HIST_FILE!=null || ReadStats.QUAL_HIST_FILE!=null || ReadStats.AVG_QUAL_HIST_FILE!=null || ReadStats.BQUAL_HIST_OVERALL_FILE!=null);
891 if(ReadStats.COLLECT_QUALITY_STATS){System.err.println("Set quality histogram output to "+ReadStats.QUAL_HIST_FILE);}
892 }else if(a.equals("matchhistogram") || a.equals("matchhist") || a.equals("mhist")){
893 ReadStats.MATCH_HIST_FILE=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
894 ReadStats.COLLECT_MATCH_STATS=(ReadStats.MATCH_HIST_FILE!=null);
895 if(ReadStats.COLLECT_MATCH_STATS){System.err.println("Set match histogram output to "+ReadStats.MATCH_HIST_FILE);}
896 }else if(a.equals("inserthistogram") || a.equals("inserthist") || a.equals("ihist")){
897 ReadStats.INSERT_HIST_FILE=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
898 ReadStats.COLLECT_INSERT_STATS=(ReadStats.INSERT_HIST_FILE!=null);
899 if(ReadStats.COLLECT_INSERT_STATS){System.err.println("Set insert size histogram output to "+ReadStats.INSERT_HIST_FILE);}
900 }else if(a.equals("basehistogram") || a.equals("basehist") || a.equals("bhist")){
901 ReadStats.BASE_HIST_FILE=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
902 ReadStats.COLLECT_BASE_STATS=(ReadStats.BASE_HIST_FILE!=null);
903 if(ReadStats.COLLECT_BASE_STATS){System.err.println("Set base content histogram output to "+ReadStats.BASE_HIST_FILE);}
904 }else if(a.equals("qualityaccuracyhistogram") || a.equals("qahist")){
905 ReadStats.QUAL_ACCURACY_FILE=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
906 ReadStats.COLLECT_QUALITY_ACCURACY=(ReadStats.QUAL_ACCURACY_FILE!=null);
907 if(ReadStats.COLLECT_QUALITY_ACCURACY){
908 ReadStats.COLLECT_QUALITY_STATS=true;
909 ReadStats.COLLECT_MATCH_STATS=true;
910 System.err.println("Set quality accuracy histogram output to "+ReadStats.QUAL_ACCURACY_FILE);
911 }
912 }else if(a.equals("indelhistogram") || a.equals("indelhist")){
913 ReadStats.INDEL_HIST_FILE=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
914 ReadStats.COLLECT_INDEL_STATS=(ReadStats.INDEL_HIST_FILE!=null);
915 if(ReadStats.COLLECT_INDEL_STATS){System.err.println("Set indel histogram output to "+ReadStats.INDEL_HIST_FILE);}
916 }else if(a.equals("errorhistogram") || a.equals("ehist")){
917 ReadStats.ERROR_HIST_FILE=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
918 ReadStats.COLLECT_ERROR_STATS=(ReadStats.ERROR_HIST_FILE!=null);
919 if(ReadStats.COLLECT_ERROR_STATS){System.err.println("Set error histogram output to "+ReadStats.ERROR_HIST_FILE);}
920 }else if(a.equals("lengthhistogram") || a.equals("lhist")){
921 ReadStats.LENGTH_HIST_FILE=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
922 ReadStats.COLLECT_LENGTH_STATS=(ReadStats.LENGTH_HIST_FILE!=null);
923 if(ReadStats.COLLECT_LENGTH_STATS){System.err.println("Set length histogram output to "+ReadStats.LENGTH_HIST_FILE);}
924 }else if(a.equals("gchistogram") || a.equals("gchist")){
925 ReadStats.GC_HIST_FILE=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
926 ReadStats.COLLECT_GC_STATS=(ReadStats.GC_HIST_FILE!=null);
927 if(ReadStats.COLLECT_GC_STATS){System.err.println("Set GC histogram output to "+ReadStats.GC_HIST_FILE);}
928 }else if(a.equals("gcbins") || a.equals("gchistbins")){
929 if("auto".equalsIgnoreCase(b)){
930 ReadStats.GC_BINS=4000;
931 ReadStats.GC_BINS_AUTO=true;
932 }else{
933 ReadStats.GC_BINS=Integer.parseInt(b);
934 ReadStats.GC_BINS_AUTO=false;
935 }
936 }else if(a.equals("gcchart") || a.equals("gcplot")){
937 ReadStats.GC_PLOT_X=Parse.parseBoolean(b);
938 }else if(a.equals("entropyhistogram") || a.equals("entropyhist") || a.equals("enhist") || a.equals("enthist")){
939 ReadStats.ENTROPY_HIST_FILE=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
940 ReadStats.COLLECT_ENTROPY_STATS=(ReadStats.ENTROPY_HIST_FILE!=null);
941 if(ReadStats.COLLECT_ENTROPY_STATS){System.err.println("Set entropy histogram output to "+ReadStats.ENTROPY_HIST_FILE);}
942 }else if(a.equals("entropybins") || a.equals("entropyhistbins") || a.equals("entbins") || a.equals("enthistbins")){
943 if("auto".equalsIgnoreCase(b)){
944 ReadStats.ENTROPY_BINS=1000;
945 // ReadStats.ENTROPY_BINS_AUTO=true;
946 }else{
947 ReadStats.ENTROPY_BINS=Integer.parseInt(b);
948 // ReadStats.ENTROPY_BINS_AUTO=false;
949 }
950 }else if(a.equals("entropyns") || a.equals("entropyhistns")){
951 ReadStats.allowEntropyNs=Parse.parseBoolean(b);
952 }else if(a.equals("barcodestats") || a.equals("barcodecounts")){
953 ReadStats.BARCODE_STATS_FILE=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
954 ReadStats.COLLECT_BARCODE_STATS=(ReadStats.BARCODE_STATS_FILE!=null);
955 }else if(a.equals("timehistogram") || a.equals("thist")){
956 ReadStats.TIME_HIST_FILE=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
957 ReadStats.COLLECT_TIME_STATS=(ReadStats.TIME_HIST_FILE!=null);
958 }else if(a.equals("identityhistogram") || a.equals("idhist")){
959 ReadStats.IDENTITY_HIST_FILE=(b==null || b.equalsIgnoreCase("null") || b.equalsIgnoreCase("none")) ? null : b;
960 ReadStats.COLLECT_IDENTITY_STATS=(ReadStats.IDENTITY_HIST_FILE!=null);
961 if(ReadStats.COLLECT_IDENTITY_STATS){System.err.println("Set identity histogram output to "+ReadStats.IDENTITY_HIST_FILE);}
962 }else if(a.equals("idhistlen") || a.equals("idhistlength") || a.equals("idhistbins") || a.equals("idbins")){
963 if("auto".equalsIgnoreCase(b)){
964 ReadStats.ID_BINS=750;
965 ReadStats.ID_BINS_AUTO=true;
966 }else{
967 ReadStats.ID_BINS=Integer.parseInt(b);
968 ReadStats.ID_BINS_AUTO=false;
969 }
970 }
971
972 else if(a.equals("maxhistlen")){
973 ReadStats.MAXLEN=ReadStats.MAXINSERTLEN=ReadStats.MAXLENGTHLEN=Parse.parseIntKMG(b);
974 }
975
976 else if(a.equals("fixindels") || a.equals("ignorevcfindels")){
977 CallVariants.fixIndels=Parse.parseBoolean(b);
978 }
979
980 else{
981 return false;
982 }
983 return true;
984 }
985
986 public static boolean parseZip(String arg, String a, String b){
987 if(a.equals("ziplevel") || a.equals("zl")){
988 int x=Integer.parseInt(b);
989 if(x>=0){
990 ReadWrite.ZIPLEVEL=Tools.min(x, 11);
991 }
992 }else if(a.equals("bziplevel") || a.equals("bzl")){
993 int x=Integer.parseInt(b);
994 if(x>=0){
995 ReadWrite.BZIPLEVEL=Tools.min(x, 9);
996 }
997 }else if(a.equals("allowziplevelchange")){
998 ReadWrite.ALLOW_ZIPLEVEL_CHANGE=Parse.parseBoolean(b);
999 }else if(a.equals("usegzip") || a.equals("gzip")){
1000 ReadWrite.USE_GZIP=Parse.parseBoolean(b);
1001 }else if(a.equals("usebgzip") || a.equals("bgzip")){
1002
1003 if(b!=null && Tools.isDigit(b.charAt(0))){
1004 int zt=Integer.parseInt(b);
1005 if(zt<1){ReadWrite.USE_BGZIP=false;}
1006 else{
1007 ReadWrite.USE_BGZIP=true;
1008 ReadWrite.setZipThreads(zt);
1009 }
1010 }else{ReadWrite.USE_BGZIP=Parse.parseBoolean(b);}
1011 if(ReadWrite.USE_BGZIP){ReadWrite.PREFER_BGZIP=true;}
1012 }else if(a.equals("forcepigz")){
1013 ReadWrite.FORCE_PIGZ=Parse.parseBoolean(b);
1014 if(ReadWrite.FORCE_PIGZ){ReadWrite.USE_PIGZ=true;}
1015 }else if(a.equals("forcebgzip")){
1016 ReadWrite.FORCE_BGZIP=Parse.parseBoolean(b);
1017 if(ReadWrite.FORCE_BGZIP){ReadWrite.USE_BGZIP=true;}
1018 }else if(a.equals("preferbgzip")){
1019 ReadWrite.PREFER_BGZIP=Parse.parseBoolean(b);
1020 }else if(a.equals("zipthreads")){
1021 ReadWrite.setZipThreads(Integer.parseInt(b));
1022 }else if(a.equals("usepigz") || a.equals("pigz")){
1023 if(b!=null && Tools.isDigit(b.charAt(0))){
1024 int zt=Integer.parseInt(b);
1025 if(zt<1){ReadWrite.USE_PIGZ=false;}
1026 else{
1027 ReadWrite.USE_PIGZ=true;
1028 ReadWrite.setZipThreads(zt);
1029 }
1030 }else{ReadWrite.USE_PIGZ=Parse.parseBoolean(b);}
1031 }else if(a.equals("zipthreaddivisor") || a.equals("ztd")){
1032 ReadWrite.setZipThreadMult(1/Float.parseFloat(b));
1033 }else if(a.equals("blocksize")){
1034 int x=Integer.parseInt(b);
1035 ReadWrite.PIGZ_BLOCKSIZE=Tools.mid(32, x, 1024);
1036 }else if(a.equals("pigziterations") || a.equals("pigziters")){
1037 int x=Integer.parseInt(b);
1038 ReadWrite.PIGZ_ITERATIONS=Tools.mid(32, x, 1024);
1039 }else if(a.equals("usegunzip") || a.equals("gunzip") || a.equals("ungzip")){
1040 ReadWrite.USE_GUNZIP=Parse.parseBoolean(b);
1041 }else if(a.equals("useunpigz") || a.equals("unpigz")){
1042 ReadWrite.USE_UNPIGZ=Parse.parseBoolean(b);
1043 }else if(a.equals("useunbgzip") || a.equals("unbgzip")){
1044 ReadWrite.USE_UNBGZIP=ReadWrite.PREFER_UNBGZIP=Parse.parseBoolean(b);
1045 }else if(a.equals("preferunbgzip")){
1046 ReadWrite.PREFER_UNBGZIP=Parse.parseBoolean(b);
1047 }else if(a.equals("usebzip2") || a.equals("bzip2")){
1048 ReadWrite.USE_BZIP2=Parse.parseBoolean(b);
1049 }else if(a.equals("usepbzip2") || a.equals("pbzip2")){
1050 ReadWrite.USE_PBZIP2=Parse.parseBoolean(b);
1051 }else if(a.equals("uselbzip2") || a.equals("lbzip2")){
1052 ReadWrite.USE_LBZIP2=Parse.parseBoolean(b);
1053 }else{
1054 return false;
1055 }
1056 return true;
1057 }
1058
1059 public static boolean parseSam(String arg, String a, String b){
1060 if(a.equals("samversion") || a.equals("samv") || a.equals("sam")){
1061 assert(b!=null) : "The sam flag requires a version number, e.g. 'sam=1.4'";
1062 SamLine.VERSION=Float.parseFloat(b);
1063 }else if(a.equals("sambamba")){
1064 Data.USE_SAMBAMBA=Parse.parseBoolean(b);
1065 }else if(a.equals("samtools")){
1066 Data.USE_SAMTOOLS=Parse.parseBoolean(b);
1067 }else if(a.equals("streamerthreads")){
1068 SamStreamer.DEFAULT_THREADS=Integer.parseInt(b);
1069 }else if(a.equals("prefermd") || a.equals("prefermdtag")){
1070 SamLine.PREFER_MDTAG=Parse.parseBoolean(b);
1071 }else if(a.equals("notags")){
1072 SamLine.NO_TAGS=Parse.parseBoolean(b);
1073 }else if(a.equals("mdtag") || a.equals("md")){
1074 SamLine.MAKE_MD_TAG=Parse.parseBoolean(b);
1075 }else if(a.equals("idtag")){
1076 SamLine.MAKE_IDENTITY_TAG=Parse.parseBoolean(b);
1077 }else if(a.equals("mateqtag")){
1078 SamLine.MAKE_MATEQ_TAG=Parse.parseBoolean(b);
1079 }else if(a.equals("xmtag") || a.equals("xm")){
1080 SamLine.MAKE_XM_TAG=Parse.parseBoolean(b);
1081 }else if(a.equals("smtag")){
1082 SamLine.MAKE_SM_TAG=Parse.parseBoolean(b);
1083 }else if(a.equals("amtag")){
1084 SamLine.MAKE_AM_TAG=Parse.parseBoolean(b);
1085 }else if(a.equals("nmtag")){
1086 SamLine.MAKE_NM_TAG=Parse.parseBoolean(b);
1087 }else if(a.equals("xttag")){
1088 SamLine.MAKE_XT_TAG=Parse.parseBoolean(b);
1089 }else if(a.equals("stoptag")){
1090 SamLine.MAKE_STOP_TAG=Parse.parseBoolean(b);
1091 }else if(a.equals("lengthtag")){
1092 SamLine.MAKE_LENGTH_TAG=Parse.parseBoolean(b);
1093 }else if(a.equals("boundstag")){
1094 SamLine.MAKE_BOUNDS_TAG=Parse.parseBoolean(b);
1095 }else if(a.equals("scoretag")){
1096 SamLine.MAKE_SCORE_TAG=Parse.parseBoolean(b);
1097 }else if(a.equals("sortscaffolds")){
1098 SamLine.SORT_SCAFFOLDS=Parse.parseBoolean(b);
1099 }else if(a.equals("customtag")){
1100 SamLine.MAKE_CUSTOM_TAGS=Parse.parseBoolean(b);
1101 }else if(a.equals("nhtag")){
1102 SamLine.MAKE_NH_TAG=Parse.parseBoolean(b);
1103 }else if(a.equals("keepnames")){
1104 SamLine.KEEP_NAMES=Parse.parseBoolean(b);
1105 }else if(a.equals("saa") || a.equals("secondaryalignmentasterisks")){
1106 SamLine.SECONDARY_ALIGNMENT_ASTERISKS=Parse.parseBoolean(b);
1107 }else if(a.equals("inserttag")){
1108 SamLine.MAKE_INSERT_TAG=Parse.parseBoolean(b);
1109 }else if(a.equals("correctnesstag")){
1110 SamLine.MAKE_CORRECTNESS_TAG=Parse.parseBoolean(b);
1111 }else if(a.equals("intronlen") || a.equals("intronlength")){
1112 SamLine.INTRON_LIMIT=Integer.parseInt(b);
1113 SamLine.setintron=true;
1114 }else if(a.equals("suppressheader") || a.equals("noheader")){
1115 ReadStreamWriter.NO_HEADER=Parse.parseBoolean(b);
1116 }else if(a.equals("noheadersequences") || a.equals("nhs") || a.equals("suppressheadersequences")){
1117 ReadStreamWriter.NO_HEADER_SEQUENCES=Parse.parseBoolean(b);
1118 }else if(a.equals("tophat")){
1119 if(Parse.parseBoolean(b)){
1120 SamLine.MAKE_TOPHAT_TAGS=true;
1121 FastaReadInputStream.FAKE_QUALITY=true;
1122 Shared.FAKE_QUAL=40;
1123 SamLine.MAKE_MD_TAG=true;
1124 }
1125 }else if(a.equals("xstag") || a.equals("xs")){
1126 SamLine.MAKE_XS_TAG=true;
1127 if(b!=null){
1128 b=b.toLowerCase();
1129 if(b.startsWith("fr-")){b=b.substring(3);}
1130 if(b.equals("ss") || b.equals("secondstrand")){
1131 SamLine.XS_SECONDSTRAND=true;
1132 }else if(b.equals("fs") || b.equals("firststrand")){
1133 SamLine.XS_SECONDSTRAND=false;
1134 }else if(b.equals("us") || b.equals("unstranded")){
1135 SamLine.XS_SECONDSTRAND=false;
1136 }else{
1137 SamLine.MAKE_XS_TAG=Parse.parseBoolean(b);
1138 }
1139 }
1140 SamLine.setxs=true;
1141 }else if(a.equals("flipsam")){
1142 SamLine.FLIP_ON_LOAD=Parse.parseBoolean(b);
1143 }else if(parseReadgroup(arg, a, b)){
1144 //do nothing
1145 }else{
1146 return false;
1147 }
1148 return true;
1149 }
1150
1151 public static boolean parseFasta(String arg, String a, String b){
1152 if(a.equals("fastareadlen") || a.equals("fastareadlength")){
1153 FastaReadInputStream.TARGET_READ_LEN=Integer.parseInt(b);
1154 FastaReadInputStream.SPLIT_READS=(FastaReadInputStream.TARGET_READ_LEN>0);
1155 }else if(a.equals("fastaminread") || a.equals("fastaminlen") || a.equals("fastaminlength")){
1156 FastaReadInputStream.MIN_READ_LEN=Integer.parseInt(b);
1157 }else if(a.equals("forcesectionname")){
1158 FastaReadInputStream.FORCE_SECTION_NAME=Parse.parseBoolean(b);
1159 }else if(a.equals("fastawrap") || a.equals("wrap")){
1160 Shared.FASTA_WRAP=Parse.parseIntKMG(b);
1161 }else if(a.equals("fastadump")){
1162 AbstractKmerTable.FASTA_DUMP=Parse.parseBoolean(b);
1163 }else{
1164 return false;
1165 }
1166 return true;
1167 }
1168
1169 public static boolean parseQualityAdjust(String arg, String a, String b){
1170 int pass=0;
1171 if(a.endsWith("_p1") || a.endsWith("_p2")){
1172 pass=Integer.parseInt(a.substring(a.length()-1))-1;
1173 a=a.substring(0, a.length()-3);
1174 }
1175
1176 if(a.equals("trackall")){
1177 CalcTrueQuality.TRACK_ALL=Parse.parseBoolean(b);
1178 }else if(a.equals("clearmatrices")){
1179 boolean x=Parse.parseBoolean(b);
1180 if(x){
1181 CalcTrueQuality.use_q102=new boolean[] {false, false};
1182 CalcTrueQuality.use_qap=new boolean[] {false, false};
1183 CalcTrueQuality.use_qbp=new boolean[] {false, false};
1184 CalcTrueQuality.use_qpt=new boolean[] {false, false};
1185 CalcTrueQuality.use_qbt=new boolean[] {false, false};
1186 CalcTrueQuality.use_q10=new boolean[] {false, false};
1187 CalcTrueQuality.use_q12=new boolean[] {false, false};
1188 CalcTrueQuality.use_qb12=new boolean[] {false, false};
1189 CalcTrueQuality.use_qb012=new boolean[] {false, false};
1190 CalcTrueQuality.use_qb123=new boolean[] {false, false};
1191 CalcTrueQuality.use_qb234=new boolean[] {false, false};
1192 CalcTrueQuality.use_q12b12=new boolean[] {false, false};
1193 CalcTrueQuality.use_qp=new boolean[] {false, false};
1194 CalcTrueQuality.use_q=new boolean[] {false, false};
1195 }
1196 }else if(a.equals("loadq102")){
1197 CalcTrueQuality.use_q102[pass]=Parse.parseBoolean(b);
1198 }else if(a.equals("loadqap")){
1199 CalcTrueQuality.use_qap[pass]=Parse.parseBoolean(b);
1200 }else if(a.equals("loadqbp")){
1201 CalcTrueQuality.use_qbp[pass]=Parse.parseBoolean(b);
1202 }else if(a.equals("loadqpt")){
1203 CalcTrueQuality.use_qpt[pass]=Parse.parseBoolean(b);
1204 }else if(a.equals("loadqbt")){
1205 CalcTrueQuality.use_qbt[pass]=Parse.parseBoolean(b);
1206 }else if(a.equals("loadq10")){
1207 CalcTrueQuality.use_q10[pass]=Parse.parseBoolean(b);
1208 }else if(a.equals("loadq12")){
1209 CalcTrueQuality.use_q12[pass]=Parse.parseBoolean(b);
1210 }else if(a.equals("loadqb12")){
1211 CalcTrueQuality.use_qb12[pass]=Parse.parseBoolean(b);
1212 }else if(a.equals("loadqb012")){
1213 CalcTrueQuality.use_qb012[pass]=Parse.parseBoolean(b);
1214 }else if(a.equals("loadqb123")){
1215 CalcTrueQuality.use_qb123[pass]=Parse.parseBoolean(b);
1216 }else if(a.equals("loadqb234")){
1217 CalcTrueQuality.use_qb234[pass]=Parse.parseBoolean(b);
1218 }else if(a.equals("loadq12b12")){
1219 CalcTrueQuality.use_q12b12[pass]=Parse.parseBoolean(b);
1220 }else if(a.equals("loadqp")){
1221 CalcTrueQuality.use_qp[pass]=Parse.parseBoolean(b);
1222 }else if(a.equals("loadq")){
1223 CalcTrueQuality.use_q[pass]=Parse.parseBoolean(b);
1224 }else if(a.equals("observationcutoff")){
1225 long x=Parse.parseIntKMG(b);
1226 CalcTrueQuality.OBSERVATION_CUTOFF[pass]=x;
1227 }else if(a.equals("recalpasses")){
1228 CalcTrueQuality.passes=Integer.parseInt(b);
1229 }else if(a.equals("recalqmax")){
1230 int x=Tools.mid(1, Integer.parseInt(b), 93);
1231 CalcTrueQuality.setQmax(x);
1232 Read.setMaxCalledQuality(Tools.max(x, Read.MAX_CALLED_QUALITY()));
1233 }else if(a.equals("recalqmin")){
1234 int x=Tools.mid(0, Integer.parseInt(b), 93);
1235 Read.setMinCalledQuality(Tools.min(x, Read.MIN_CALLED_QUALITY()));
1236 }else if(a.equals("recalwithposition") || a.equals("recalwithpos") || a.equals("recalusepos")){
1237 boolean x=Parse.parseBoolean(b);
1238 if(!x){
1239 Arrays.fill(CalcTrueQuality.use_qp, false);
1240 Arrays.fill(CalcTrueQuality.use_qbp, false);
1241 Arrays.fill(CalcTrueQuality.use_qap, false);
1242 }
1243 }else if(a.equals("qmatrixmode")){
1244 if("smr".equalsIgnoreCase(b) || "squaremeanroot".equalsIgnoreCase(b)){
1245 CalcTrueQuality.USE_SMR=true;
1246 }else if("weighted".equalsIgnoreCase(b) || "wa".equalsIgnoreCase(b) ||
1247 "weightedaverage".equalsIgnoreCase(b)){
1248 CalcTrueQuality.USE_SMR=false;
1249 CalcTrueQuality.USE_WEIGHTED_AVERAGE=true;
1250 }else if("average".equalsIgnoreCase(b) || "avg".equalsIgnoreCase(b)){
1251 CalcTrueQuality.USE_SMR=CalcTrueQuality.USE_WEIGHTED_AVERAGE=false;
1252 CalcTrueQuality.USE_AVERAGE=true;
1253 }else if("max".equalsIgnoreCase(b)){
1254 CalcTrueQuality.USE_SMR=false;
1255 CalcTrueQuality.USE_AVERAGE=CalcTrueQuality.USE_WEIGHTED_AVERAGE=false;
1256 }
1257 }else if(a.equals("recaltile") || a.equals("recaltiles") || a.equals("usetiles")){
1258 CalcTrueQuality.USE_TILES=Parse.parseBoolean(b);
1259 if(CalcTrueQuality.USE_TILES) {
1260 CalcTrueQuality.use_qpt[0]=true;
1261 CalcTrueQuality.use_qpt[1]=false;
1262 CalcTrueQuality.use_qbt[0]=false;
1263 CalcTrueQuality.use_qbt[1]=false;
1264 }else {
1265 CalcTrueQuality.use_qpt[0]=false;
1266 CalcTrueQuality.use_qpt[1]=false;
1267 CalcTrueQuality.use_qbt[0]=false;
1268 CalcTrueQuality.use_qbt[1]=false;
1269 }
1270 }else{
1271 return false;
1272 }
1273 return true;
1274 }
1275
1276 static boolean isJavaFlag(String arg){
1277 if(arg==null){return false;}
1278 if(arg.startsWith("-Xmx") || arg.startsWith("-Xms") || arg.startsWith("-Xmn") || arg.startsWith("-xmx") || arg.startsWith("-xms") || arg.startsWith("-xmn")){
1279 return arg.length()>4 && Tools.isDigit(arg.charAt(4));
1280 }
1281 if(arg.startsWith("Xmx") || arg.startsWith("Xms") || arg.startsWith("Xmn") || arg.startsWith("xmx")){
1282 return arg.length()>3 && (Tools.isDigit(arg.charAt(3)) || arg.charAt(3)=='=');
1283 }
1284 if(arg.equals("-ea") || arg.equals("-da") || arg.equals("ea") || arg.equals("da")){
1285 return true;
1286 }
1287 if(arg.equals("ExitOnOutOfMemoryError") || arg.equals("exitonoutofmemoryerror") || arg.equals("eoom")){return true;}
1288 if(arg.equals("-ExitOnOutOfMemoryError") || arg.equals("-exitonoutofmemoryerror") || arg.equals("-eoom")){return true;}
1289
1290 return false;
1291 }
1292
1293 /** Return true if the user seems confused */
1294 static boolean parseHelp(String[] args, boolean autoExit){
1295 if(args==null || args.length==0 || (args.length==1 && args[0]==null)){
1296 if(autoExit){printHelp(1);}
1297 return true;
1298 }
1299
1300 final String s=args[args.length-1].toLowerCase();
1301
1302 if(s.equals("-version") || s.equals("--version") || (s.equals("version") && !new File(s).exists())){
1303 if(autoExit){printHelp(0);}
1304 return true;
1305 }else if(s.equals("-h") || s.equals("-help") || s.equals("--help")
1306 || s.equals("?") || s.equals("-?") || (s.equals("help") && !new File(s).exists())){
1307 if(autoExit){printHelp(0);}
1308 return true;
1309 }
1310 return false;
1311 }
1312
1313 public static void printHelp(int exitCode){
1314 System.err.println("BBTools version "+Shared.BBTOOLS_VERSION_STRING);
1315 System.err.println("For help, please run the shellscript with no parameters, or look in /docs/.");
1316 System.exit(exitCode);
1317 }
1318
1319 /** Set SamLine Readgroup Strings */
1320 public static boolean parseReadgroup(String arg, String a, String b){
1321 if(a.equals("readgroup") || a.equals("readgroupid") || a.equals("rgid")){
1322 SamLine.READGROUP_ID=b;
1323 if(b!=null){SamLine.READGROUP_TAG="RG:Z:"+b;}
1324 }else if(a.equals("readgroupcn") || a.equals("rgcn")){
1325 SamLine.READGROUP_CN=b;
1326 }else if(a.equals("readgroupds") || a.equals("rgds")){
1327 SamLine.READGROUP_DS=b;
1328 }else if(a.equals("readgroupdt") || a.equals("rgdt")){
1329 SamLine.READGROUP_DT=b;
1330 }else if(a.equals("readgroupfo") || a.equals("rgfo")){
1331 SamLine.READGROUP_FO=b;
1332 }else if(a.equals("readgroupks") || a.equals("rgks")){
1333 SamLine.READGROUP_KS=b;
1334 }else if(a.equals("readgrouplb") || a.equals("rglb")){
1335 SamLine.READGROUP_LB=b;
1336 }else if(a.equals("readgrouppg") || a.equals("rgpg")){
1337 SamLine.READGROUP_PG=b;
1338 }else if(a.equals("readgrouppi") || a.equals("rgpi")){
1339 SamLine.READGROUP_PI=b;
1340 }else if(a.equals("readgrouppl") || a.equals("rgpl")){
1341 SamLine.READGROUP_PL=b;
1342 }else if(a.equals("readgrouppu") || a.equals("rgpu")){
1343 SamLine.READGROUP_PU=b;
1344 }else if(a.equals("readgroupsm") || a.equals("rgsm")){
1345 SamLine.READGROUP_SM=b;
1346 }else{
1347 return false;
1348 }
1349 return true;
1350 }
1351
1352 /** Fix Readgroup Strings */
1353 public static void postparseReadgroup(String fname){
1354 if(fname==null){return;}
1355 fname=ReadWrite.stripToCore(fname);
1356 if("filename".equalsIgnoreCase(SamLine.READGROUP_ID)){
1357 SamLine.READGROUP_ID=fname;
1358 if(fname!=null){SamLine.READGROUP_TAG="RG:Z:"+fname;}
1359 }
1360 if("filename".equalsIgnoreCase(SamLine.READGROUP_CN)){
1361 SamLine.READGROUP_CN=fname;
1362 }
1363 if("filename".equalsIgnoreCase(SamLine.READGROUP_DS)){
1364 SamLine.READGROUP_DS=fname;
1365 }
1366 if("filename".equalsIgnoreCase(SamLine.READGROUP_DT)){
1367 SamLine.READGROUP_DT=fname;
1368 }
1369 if("filename".equalsIgnoreCase(SamLine.READGROUP_FO)){
1370 SamLine.READGROUP_FO=fname;
1371 }
1372 if("filename".equalsIgnoreCase(SamLine.READGROUP_KS)){
1373 SamLine.READGROUP_KS=fname;
1374 }
1375 if("filename".equalsIgnoreCase(SamLine.READGROUP_LB)){
1376 SamLine.READGROUP_LB=fname;
1377 }
1378 if("filename".equalsIgnoreCase(SamLine.READGROUP_PG)){
1379 SamLine.READGROUP_PG=fname;
1380 }
1381 if("filename".equalsIgnoreCase(SamLine.READGROUP_PI)){
1382 SamLine.READGROUP_PI=fname;
1383 }
1384 if("filename".equalsIgnoreCase(SamLine.READGROUP_PL)){
1385 SamLine.READGROUP_PL=fname;
1386 }
1387 if("filename".equalsIgnoreCase(SamLine.READGROUP_PU)){
1388 SamLine.READGROUP_PU=fname;
1389 }
1390 if("filename".equalsIgnoreCase(SamLine.READGROUP_SM)){
1391 SamLine.READGROUP_SM=fname;
1392 }
1393 }
1394
1395
1396 /*--------------------------------------------------------------*/
1397 /*---------------- Fields ----------------*/
1398 /*--------------------------------------------------------------*/
1399
1400 public float trimE(){
1401 return (float)QualityTools.phredToProbError(trimq);
1402 }
1403
1404 public float[] trimE2(){
1405 return QualityTools.phredToProbError(trimq2==null ? new float[] {trimq} : trimq2);
1406 }
1407
1408 public boolean loglog=false;
1409 public boolean loglogOut=false;
1410 public int loglogbuckets=2048;//1999
1411 public int loglogbits=8;
1412 public int loglogk=31;
1413 public long loglogseed=-1;
1414 public float loglogMinprob=0;
1415 public IntList loglogKlist=new IntList();
1416
1417 public boolean recalibrateQuality=false;
1418
1419 public int forceTrimModulo=-1;
1420 public int forceTrimLeft=-1;
1421 public int forceTrimRight=-1;
1422 public int forceTrimRight2=-1;
1423 public int build=1;
1424
1425 public long maxReads=-1;
1426 public float samplerate=1f;
1427 public long sampleseed=-1;
1428
1429 public boolean qtrimLeft=false;
1430 public boolean qtrimRight=false;
1431 public boolean trimClip=false;
1432 public int trimPolyA=0;
1433
1434 public int trimPolyGLeft=0;
1435 public int trimPolyGRight=0;
1436 public int filterPolyG=0;
1437
1438 public int trimPolyCLeft=0;
1439 public int trimPolyCRight=0;
1440 public int filterPolyC=0;
1441 public int maxNonPoly=1;
1442
1443 public boolean qtrim1=false;
1444 public boolean qtrim2=false;
1445
1446 public float trimq=6;
1447 public float[] trimq2=null;
1448 public float minAvgQuality=0;
1449 public byte minBaseQuality=0;
1450 public int minAvgQualityBases=0;
1451 public int maxNs=-1;
1452 public int minConsecutiveBases=0;
1453 public int minReadLength=0;
1454 public int maxReadLength=-1;
1455 public int minTrimLength=-1;
1456 public float minLenFraction=0;
1457 public float minGC=0;
1458 public float maxGC=1;
1459 public boolean usePairGC=true;
1460 // public boolean filterGC=false;
1461 public boolean untrim=false;
1462 public boolean tossJunk=false;
1463
1464 public float minIdFilter=-1;
1465 public float maxIdFilter=999999999;
1466 public int subfilter=-1;
1467 public int clipfilter=-1;
1468 public int delfilter=-1;
1469 public int insfilter=-1;
1470 public int indelfilter=-1;
1471 public int dellenfilter=-1;
1472 public int inslenfilter=-1;
1473 public int editfilter=-1;
1474 public int nfilter=-1;
1475
1476 public int breakLength=0;
1477 /** Toss pair only if both reads are shorter than limit */
1478 public boolean requireBothBad=false;
1479 public boolean trimBadSequence=false;
1480 public boolean chastityFilter=false;
1481 public boolean removeBadBarcodes=false;
1482 public boolean failBadBarcodes=false;
1483 public boolean failIfNoBarcode=false;
1484
1485 public HashSet<String> barcodes=null;
1486
1487 /** Permission to overwrite existing files */
1488 public boolean overwrite=true;
1489
1490 /** Permission to append to existing files */
1491 public boolean append=false;
1492 public boolean testsize=false;
1493
1494 /** Whether input file interleaving was explicitly set */
1495 public boolean setInterleaved=false;
1496
1497 public String in1=null;
1498 public String in2=null;
1499
1500 public String qfin1=null;
1501 public String qfin2=null;
1502
1503 public String out1=null;
1504 public String out2=null;
1505 public String outsingle=null;
1506 public boolean setOut=false;
1507
1508 public String qfout1=null;
1509 public String qfout2=null;
1510
1511 public String extin=null;
1512 public String extout=null;
1513
1514 public int k=31;
1515
1516 /*--------------------------------------------------------------*/
1517 /*---------------- Static Fields ----------------*/
1518 /*--------------------------------------------------------------*/
1519
1520 public static String loglogType="LogLog2";
1521 public static boolean silent=false;
1522 public static boolean printSetThreads=true;
1523
1524 private static boolean setTrimRname=false;
1525 private static byte qin=-1;
1526 private static byte qout=-1;
1527 private static boolean parsedQuality=false;
1528
1529 public static void setQuality(int x){
1530 qin=(byte)x;
1531 parsedQuality=(x>-1);
1532 }
1533 public static void processQuality(){
1534 // assert(parsedQuality);
1535 if(!parsedQuality){return;}
1536 if(qin!=-1 && qout!=-1){
1537 FASTQ.ASCII_OFFSET=qin;
1538 FASTQ.ASCII_OFFSET_OUT=qout;
1539 FASTQ.DETECT_QUALITY=false;
1540 }else if(qin!=-1){
1541 FASTQ.ASCII_OFFSET=qin;
1542 FASTQ.DETECT_QUALITY=false;
1543 }else if(qout!=-1){
1544 FASTQ.ASCII_OFFSET_OUT=qout;
1545 FASTQ.DETECT_QUALITY_OUT=false;
1546 }
1547 }
1548
1549 public boolean validateStdio(FileFormat... ffa) {
1550 boolean b=true;
1551 for(FileFormat ff:ffa){
1552 b=validateStdio(ff)&b;
1553 }
1554 return b;
1555 }
1556
1557 public boolean validateStdio(FileFormat ff) {
1558 if(ff==null || !ff.stdio()){return true;}
1559 if(ff.fastq() && ff.stdin()){
1560 assert(setInterleaved) : "\nERROR: When piping fastq data from stdin, interleaving must be explicitly stated\n"
1561 + "with the flag int=f for unpaired data or int=t for paired data.\n";
1562 }
1563 final int ext=ff.rawExtensionCode();
1564 if(ff.stdout() && ext==FileFormat.UNKNOWN){
1565 assert(false) : "\nERROR: When piping reads to stdout, the output format must be specified with an extension,\n"
1566 + "such as stdout.fq or stdout.sam.gz.\n";
1567 }
1568 if(ff.stdin() && ext==FileFormat.UNKNOWN){
1569 assert(false) : "\nERROR: When piping reads from stdin, the input format should be specified with an extension,\n"
1570 + "such as stdin.fq or stdin.sam.gz.\n";
1571 }
1572 return true;
1573 }
1574
1575 }