comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/opt/bbmap-39.01-1/current/shared/Parser.java @ 68:5028fdace37b

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