Debian Codegraph @

current/align2/BBMap.java

raw symbols SCIP
1 package align2;
2
3 import java.io.File;
4 import java.util.ArrayList;
5
6 import bloom.BloomFilter;
7 import dna.ChromosomeArray;
8 import dna.Data;
9 import fileIO.ReadWrite;
10 import jgi.CoveragePileup;
11 import shared.Shared;
12 import shared.Timer;
13 import shared.Tools;
14 import stream.FastaReadInputStream;
15 import stream.ReadStreamWriter;
16 import stream.SamLine;
17
18 /**
19 *
20 * @author Brian Bushnell
21 * @date Dec 22, 2012
22 *
23 */
24 public final class BBMap extends AbstractMapper {
25
26
27 public static void main(String[] args){
28 Timer t=new Timer();
29 BBMap mapper=new BBMap(args);
30 args=Tools.condenseStrict(args);
31 if(!INDEX_LOADED){mapper.loadIndex();}
32 if(Data.scaffoldPrefixes){mapper.processAmbig2();}
33 mapper.testSpeed(args);
34 ReadWrite.waitForWritingToFinish();
35 t.stop();
36 outstream.println("\nTotal time: \t"+t);
37 clearStatics();
38 }
39
40 public BBMap(String[] args){
41 super(args);
42 }
43
44 @Override
45 public void setDefaults(){
46 ReadWrite.USE_PIGZ=ReadWrite.USE_UNPIGZ=false;
47 ReadWrite.USE_BGZIP=ReadWrite.USE_UNBGZIP=true;
48 ReadWrite.PREFER_BGZIP=true;
49 ReadWrite.ZIPLEVEL=2;
50 MAKE_MATCH_STRING=true;
51 keylen=13;
52
53 MINIMUM_ALIGNMENT_SCORE_RATIO=0.56f;
54
55 keyDensity=1.9f;//2.3f;
56 maxKeyDensity=3f;//4f;
57 minKeyDensity=1.5f;//1.8f;
58 maxDesiredKeys=15;
59
60 SLOW_ALIGN_PADDING=4;
61 SLOW_RESCUE_PADDING=4+SLOW_ALIGN_PADDING;
62 TIP_SEARCH_DIST=100;
63
64 MSA_TYPE="MultiStateAligner11ts";
65 MAX_SITESCORES_TO_PRINT=5;
66 PRINT_SECONDARY_ALIGNMENTS=false;
67 AbstractIndex.MIN_APPROX_HITS_TO_KEEP=1;
68 }
69
70 @Override
71 public String[] preparse(String[] args){
72 if(fast){
73 ArrayList<String> list=new ArrayList<String>();
74 list.add("tipsearch="+TIP_SEARCH_DIST/5);
75 list.add("maxindel=80");
76 list.add("minhits=2");
77 list.add("bwr=0.18");
78 list.add("bw=40");
79 list.add("minratio=0.65");
80 list.add("midpad=150");
81 list.add("minscaf=50");
82 list.add("quickmatch=t");
83 list.add("rescuemismatches=15");
84 list.add("rescuedist=800");
85 list.add("maxsites=3");
86 list.add("maxsites2=100");
87 // list.add("k=13");
88
89 //TODO: Make these adjustable.
90 // MIN_TRIM_SITES_TO_RETAIN_SINGLE
91 // MIN_TRIM_SITES_TO_RETAIN_PAIRED
92 // MAX_TRIM_SITES_TO_RETAIN
93 //TODO: Make trimLists adjustable via an offset or multiplier
94
95 BBIndex.setFractionToExclude(BBIndex.FRACTION_GENOME_TO_EXCLUDE*1.25f);
96
97 for(String s : args){if(s!=null){list.add(s);}}
98 args=list.toArray(new String[list.size()]);
99
100 keyDensity*=0.9f;
101 maxKeyDensity*=0.9f;
102 minKeyDensity*=0.9f;
103 }else if(vslow){
104 ArrayList<String> list=new ArrayList<String>();
105 list.add("tipsearch="+(TIP_SEARCH_DIST*3)/2);
106 list.add("minhits=1");
107 list.add("minratio=0.22");
108 list.add("usequality=f");
109 list.add("rescuemismatches=50");
110 list.add("rescuedist=2500");
111 list.add("maxindel=100");
112
113 BBIndex.setFractionToExclude(0);
114
115 for(String s : args){if(s!=null){list.add(s);}}
116 args=list.toArray(new String[list.size()]);
117
118 SLOW_ALIGN_PADDING=SLOW_ALIGN_PADDING*2+8;
119 SLOW_RESCUE_PADDING=SLOW_RESCUE_PADDING*2+2;
120
121 AbstractIndex.SLOW=true;
122 AbstractIndex.VSLOW=true;
123 keyDensity*=2.5f;
124 maxKeyDensity*=2.5f;
125 minKeyDensity*=2.5f;
126 }else if(slow){
127 ArrayList<String> list=new ArrayList<String>();
128 list.add("tipsearch="+(TIP_SEARCH_DIST*3)/2);
129 // list.add("maxindel=80");
130 list.add("minhits=1");
131 // list.add("bwr=0.18");
132 // list.add("bw=40");
133 list.add("minratio=0.45");
134 // list.add("midpad=150");
135 // list.add("minscaf=50");
136 // list.add("k=13");
137
138 BBIndex.setFractionToExclude(BBIndex.FRACTION_GENOME_TO_EXCLUDE*0.4f);
139
140 for(String s : args){if(s!=null){list.add(s);}}
141 args=list.toArray(new String[list.size()]);
142
143 AbstractIndex.SLOW=true;
144 keyDensity*=1.2f;
145 maxKeyDensity*=1.2f;
146 minKeyDensity*=1.2f;
147 }
148
149 if(excludeFraction>=0){
150 BBIndex.setFractionToExclude(excludeFraction);
151 }
152 return args;
153 }
154
155 @Override
156 void postparse(String[] args){
157
158 if(MSA.bandwidthRatio>0 && MSA.bandwidthRatio<.2){
159 SLOW_ALIGN_PADDING=Tools.min(SLOW_ALIGN_PADDING, 3);
160 SLOW_RESCUE_PADDING=Tools.min(SLOW_RESCUE_PADDING, 6);
161 }
162
163 if(maxIndel1>-1){
164 TIP_SEARCH_DIST=Tools.min(TIP_SEARCH_DIST, maxIndel1);
165 BBIndex.MAX_INDEL=maxIndel1;
166 }
167 if(maxIndel2>-1){
168 BBIndex.MAX_INDEL2=maxIndel2;
169 }
170
171 if(minApproxHits>-1){
172 BBIndex.MIN_APPROX_HITS_TO_KEEP=minApproxHits;
173 }
174
175 if(expectedSites>-1){
176 BBMapThread.setExpectedSites(expectedSites);
177 outstream.println("Set EXPECTED_SITES to "+expectedSites);
178 }
179
180 if(fractionGenomeToExclude>=0){
181 BBIndex.setFractionToExclude(fractionGenomeToExclude);
182 }
183
184 {
185 final String a=(args.length>0 ? args[0] : null);
186 final String b=(args.length>1 ? args[1] : null);
187 if(in1==null && a!=null && a.indexOf('=')<0 && (a.startsWith("stdin") || new File(a).exists())){in1=a;}
188 if(in2==null && b!=null && b.indexOf('=')<0 && new File(b).exists()){in2=b;}
189 if(ERROR_ON_NO_OUTPUT && !OUTPUT_READS && in1!=null){throw new RuntimeException("Error: no output file, and ERROR_ON_NO_OUTPUT="+ERROR_ON_NO_OUTPUT);}
190 }
191
192 assert(synthReadlen<BBMapThread.ALIGN_ROWS);
193
194 if(MSA.bandwidth>0){
195 int halfwidth=MSA.bandwidth/2;
196 TIP_SEARCH_DIST=Tools.min(TIP_SEARCH_DIST, halfwidth/2);
197 BBIndex.MAX_INDEL=Tools.min(BBIndex.MAX_INDEL, halfwidth/2);
198 BBIndex.MAX_INDEL2=Tools.min(BBIndex.MAX_INDEL2, halfwidth);
199 SLOW_ALIGN_PADDING=Tools.min(SLOW_ALIGN_PADDING, halfwidth/4);
200 SLOW_RESCUE_PADDING=Tools.min(SLOW_RESCUE_PADDING, halfwidth/4);
201 }
202
203 if(PRINT_SECONDARY_ALIGNMENTS){
204 REMOVE_DUPLICATE_BEST_ALIGNMENTS=false;
205 BBIndex.QUIT_AFTER_TWO_PERFECTS=false;
206 }
207
208 if(in1!=null){
209 if(ambigMode==AMBIG_BEST){
210 REMOVE_DUPLICATE_BEST_ALIGNMENTS=false;
211 if(!PRINT_SECONDARY_ALIGNMENTS){BBIndex.QUIT_AFTER_TWO_PERFECTS=true;}
212 outstream.println("Retaining first best site only for ambiguous mappings.");
213 }else if(ambigMode==AMBIG_ALL){
214 PRINT_SECONDARY_ALIGNMENTS=ReadStreamWriter.OUTPUT_SAM_SECONDARY_ALIGNMENTS=true;
215 REMOVE_DUPLICATE_BEST_ALIGNMENTS=false;
216 BBIndex.QUIT_AFTER_TWO_PERFECTS=false;
217 SamLine.MAKE_NH_TAG=true;
218 ambiguousAll=true;
219 outstream.println("Retaining all best sites for ambiguous mappings.");
220 }else if(ambigMode==AMBIG_RANDOM){
221 REMOVE_DUPLICATE_BEST_ALIGNMENTS=false;
222 BBIndex.QUIT_AFTER_TWO_PERFECTS=false;
223 ambiguousRandom=true;
224 outstream.println("Choosing a site randomly for ambiguous mappings.");
225 }else if(ambigMode==AMBIG_TOSS){
226 REMOVE_DUPLICATE_BEST_ALIGNMENTS=true;
227 BBIndex.QUIT_AFTER_TWO_PERFECTS=true;
228 outstream.println("Ambiguously mapped reads will be considered unmapped.");
229 }else{
230 throw new RuntimeException("Unknown ambiguous mapping mode: "+ambigMode);
231 }
232 }
233
234 }
235
236 @Override
237 public void setup(){
238
239 assert(!useRandomReads || maxReads>0 || (in1!=null && in1.equals("sequential"))) : "Please specify number of reads to use.";
240
241 if(minid!=-1){
242 MINIMUM_ALIGNMENT_SCORE_RATIO=MSA.minIdToMinRatio(minid, MSA_TYPE);
243 outstream.println("Set MINIMUM_ALIGNMENT_SCORE_RATIO to "+Tools.format("%.3f",MINIMUM_ALIGNMENT_SCORE_RATIO));
244 }
245
246 if(!setxs){SamLine.MAKE_XS_TAG=(SamLine.INTRON_LIMIT<1000000000);}
247 if(setxs && !setintron){SamLine.INTRON_LIMIT=10;}
248
249 if(outFile==null && outFile2==null && outFileM==null && outFileM2==null && outFileU==null && outFileU2==null
250 && outFileB==null && outFileB2==null && splitterOutputs==null && BBSplitter.streamTable==null){
251 outstream.println("No output file.");
252 OUTPUT_READS=false;
253 }else{
254 OUTPUT_READS=true;
255 if(bamscript!=null){
256 BBSplitter.makeBamScript(bamscript, splitterOutputs, outFile, outFile2, outFileM, outFileM2, outFileU, outFileU2, outFileB, outFileB2);
257 }
258 }
259 // assert(false) : bamscript+", "+BBSplitter.streamTable+", "+OUTPUT_READS;
260
261
262
263 FastaReadInputStream.MIN_READ_LEN=Tools.max(keylen+2, FastaReadInputStream.MIN_READ_LEN);
264 assert(FastaReadInputStream.settingsOK());
265
266 if(build<0){throw new RuntimeException("Must specify a build number, e.g. build=1");}
267 else{Data.GENOME_BUILD=build;}
268
269 if(blacklist!=null && blacklist.size()>0){
270 Timer t=new Timer();
271 t.start();
272 for(String s : blacklist){
273 Blacklist.addToBlacklist(s);
274 }
275 t.stop();
276 outstream.println("Created blacklist:\t"+t);
277 t.start();
278 }
279
280 if(ziplevel!=-1){ReadWrite.ZIPLEVEL=ziplevel;}
281 if(reference!=null){RefToIndex.makeIndex(reference, build, outstream, keylen);}
282 }
283
284
285 @Override
286 void processAmbig2(){
287 assert(Data.scaffoldPrefixes) : "Only process this block if there are multiple references.";
288 if(BBSplitter.AMBIGUOUS2_MODE==BBSplitter.AMBIGUOUS2_SPLIT){
289 REMOVE_DUPLICATE_BEST_ALIGNMENTS=false;
290 BBIndex.QUIT_AFTER_TWO_PERFECTS=false;
291 outstream.println("Reads that map to multiple references will be written to special output streams.");
292 }else if(BBSplitter.AMBIGUOUS2_MODE==BBSplitter.AMBIGUOUS2_FIRST){
293 REMOVE_DUPLICATE_BEST_ALIGNMENTS=false;
294 BBIndex.QUIT_AFTER_TWO_PERFECTS=false;
295 outstream.println("Reads that map to multiple references will be written to the first reference's stream only.");
296 }else if(BBSplitter.AMBIGUOUS2_MODE==BBSplitter.AMBIGUOUS2_TOSS){
297 BBIndex.QUIT_AFTER_TWO_PERFECTS=true;
298 outstream.println("Reads that map to multiple references will be considered unmapped.");
299 }else if(BBSplitter.AMBIGUOUS2_MODE==BBSplitter.AMBIGUOUS2_RANDOM){
300 REMOVE_DUPLICATE_BEST_ALIGNMENTS=false;
301 BBIndex.QUIT_AFTER_TWO_PERFECTS=false;
302 outstream.println("Reads that map to multiple references will be written to a random stream.");
303 }else if(BBSplitter.AMBIGUOUS2_MODE==BBSplitter.AMBIGUOUS2_ALL){
304 REMOVE_DUPLICATE_BEST_ALIGNMENTS=false;
305 BBIndex.QUIT_AFTER_TWO_PERFECTS=false;
306 outstream.println("Reads that map to multiple references will be written to all relevant output streams.");
307 }else{
308 BBSplitter.AMBIGUOUS2_MODE=BBSplitter.AMBIGUOUS2_FIRST;
309 }
310 }
311
312 @Override
313 void loadIndex(){
314 Timer t=new Timer(outstream, true);
315
316 if(build>-1){
317 Data.setGenome(build);
318 AbstractIndex.MINCHROM=1;
319 AbstractIndex.MAXCHROM=Data.numChroms;
320 if(minChrom<0){minChrom=1;}
321 if(maxChrom<0 || maxChrom>Data.numChroms){maxChrom=Data.numChroms;}
322 outstream.println("Set genome to "+Data.GENOME_BUILD);
323
324 if(RefToIndex.AUTO_CHROMBITS){
325 int maxLength=Tools.max(Data.chromLengths);
326 RefToIndex.chrombits=Integer.numberOfLeadingZeros(maxLength)-1;
327 RefToIndex.chrombits=Tools.min(RefToIndex.chrombits, 16);
328 }
329 if(RefToIndex.chrombits!=-1){
330 BBIndex.setChromBits(RefToIndex.chrombits);
331 if(verbose_stats>0){outstream.println("Set CHROMBITS to "+RefToIndex.chrombits);}
332 }
333 }
334
335 assert(minChrom>=AbstractIndex.MINCHROM && maxChrom<=AbstractIndex.MAXCHROM) :
336 minChrom+", "+maxChrom+", "+AbstractIndex.MINCHROM+", "+AbstractIndex.MAXCHROM;
337 AbstractIndex.MINCHROM=minChrom;
338 AbstractIndex.MAXCHROM=maxChrom;
339
340 if(targetGenomeSize>0){
341 long bases=Data.numDefinedBases;
342 long x=Tools.max(1, Math.round(0.25f+bases*1d/targetGenomeSize));
343 BBMapThread.setExpectedSites((int)x);
344 outstream.println("Set EXPECTED_SITES to "+x);
345 }
346
347 assert(!(PERFECTMODE && SEMIPERFECTMODE));
348 if(PERFECTMODE){setPerfectMode();}
349 if(SEMIPERFECTMODE){setSemiperfectMode();}
350
351 //Optional section for discrete timing of chrom array loading
352 if(SLOW_ALIGN || AbstractIndex.USE_EXTENDED_SCORE || useRandomReads || MAKE_MATCH_STRING){
353 outstream.println();
354 if(INDEX_LOADED){
355 //do nothing
356 }else if(RefToIndex.chromlist==null){
357 Data.loadChromosomes(minChrom, maxChrom);
358 }else{
359 assert(RefToIndex.chromlist.size()==maxChrom-minChrom+1) : RefToIndex.chromlist.size();
360 for(ChromosomeArray cha : RefToIndex.chromlist){
361 Data.chromosomePlusMatrix[cha.chromosome]=cha;
362 }
363 }
364 if(Shared.TRIM_RNAME){Data.trimScaffoldNames();}
365 t.stop();
366 outstream.println("Loaded Reference:\t"+t);
367 t.start();
368 }
369 RefToIndex.chromlist=null;
370
371 t.start();
372 BBIndex.loadIndex(minChrom, maxChrom, keylen, !RefToIndex.NODISK, RefToIndex.NODISK);
373
374 {
375 long len=Data.numDefinedBases;
376 if(len<300000000){
377 BBIndex.MAX_HITS_REDUCTION2+=1;
378 BBIndex.MAXIMUM_MAX_HITS_REDUCTION+=1;
379 if(len<30000000){
380 BBIndex.setFractionToExclude(BBIndex.FRACTION_GENOME_TO_EXCLUDE*0.5f);
381 BBIndex.MAXIMUM_MAX_HITS_REDUCTION+=1;
382 BBIndex.HIT_REDUCTION_DIV=Tools.max(BBIndex.HIT_REDUCTION_DIV-1, 3);
383 }else if(len<100000000){
384 BBIndex.setFractionToExclude(BBIndex.FRACTION_GENOME_TO_EXCLUDE*0.6f);
385 }else{
386 BBIndex.setFractionToExclude(BBIndex.FRACTION_GENOME_TO_EXCLUDE*0.75f);
387 }
388 }
389 }
390
391 t.stop();
392 outstream.println("Generated Index:\t"+t);
393 t.start();
394
395 if(!SLOW_ALIGN && !AbstractIndex.USE_EXTENDED_SCORE && !useRandomReads && !MAKE_MATCH_STRING){
396 for(int chrom=minChrom; chrom<=maxChrom; chrom++){
397 Data.unload(chrom, true);
398 }
399 }
400
401 if(ReadWrite.countActiveThreads()>0){
402 ReadWrite.waitForWritingToFinish();
403 t.stop();
404 outstream.println("Finished Writing:\t"+t);
405 t.start();
406 }
407
408 if(coverageBinned!=null || coverageBase!=null || rangeCov!=null || coverageHist!=null || coverageStats!=null || coverageRPKM!=null || normcov!=null || normcovOverall!=null || calcCov){
409 String[] cvargs=("covhist="+coverageHist+"\tcovstats="+coverageStats+"\tbasecov="+coverageBase+"\trangecov="+rangeCov+"\tbincov="+coverageBinned+"\tphyscov="+coveragePhysical+
410 "\t32bit="+cov32bit+"\tnzo="+covNzo+"\ttwocolumn="+covTwocolumn+"\tsecondary="+PRINT_SECONDARY_ALIGNMENTS+"\tcovminscaf="+coverageMinScaf+
411 "\tksb="+covKsb+"\tbinsize="+covBinSize+"\tk="+covK+"\tstartcov="+covStartOnly+"\tstopcov="+covStopOnly+"\tstrandedcov="+covStranded+"\trpkm="+coverageRPKM+
412 "\tnormcov="+normcov+"\tnormcovo="+normcovOverall+(in1==null ? "" : "\tin1="+in1)+(in2==null ? "" : "\tin2="+in2)+
413 (covSetbs ? ("\tbitset="+covBitset+"\tarrays="+covArrays) : "")).split("\t");
414 pileup=new CoveragePileup(cvargs);
415 pileup.createDataStructures();
416 pileup.loadScaffoldsFromIndex(minChrom, maxChrom);
417 }
418
419 if(!forceanalyze && (in1==null || maxReads==0)){return;}
420
421 BBIndex.analyzeIndex(minChrom, maxChrom, BBIndex.FRACTION_GENOME_TO_EXCLUDE, keylen);
422
423 t.stop("Analyzed Index: ");
424 t.start();
425
426 if(makeBloomFilter){
427 String serialPath=RefToIndex.bloomLoc(build);
428 File serialFile=new File(serialPath);
429 // System.err.println(serialPath+", "+serialFile.exists()+", "+bloomSerial+", "+RefToIndex.NODISK);
430 if(bloomSerial && !RefToIndex.NODISK && serialFile.exists()){
431 bloomFilter=ReadWrite.read(BloomFilter.class, RefToIndex.bloomLoc(build), true);
432 t.stop("Loaded Bloom Filter: ");
433 }else{
434 if(bloomSerial){System.out.println("Could not read "+serialPath+", generating filter from reference.");}
435 bloomFilter=new BloomFilter(true, bloomFilterK, bloomFilterK, 1, bloomFilterHashes, bloomFilterMinHits, true);
436 t.stop("Made Bloom Filter: ");
437 if(bloomSerial && !RefToIndex.NODISK && !RefToIndex.FORCE_READ_ONLY){
438 // && serialFile.canWrite()
439 try {
440 ReadWrite.writeObjectInThread(bloomFilter, serialPath, true);
441 outstream.println("Writing Bloom Filter.");
442 } catch (Throwable e) {
443 e.printStackTrace();
444 outstream.println("Can't Write Bloom Filter.");
445 }
446 }
447 }
448 outstream.println(bloomFilter.filter.toShortString());
449 t.start();
450 }
451 // assert(false) : makeBloomFilter;
452 // assert(false) : RefToIndex.chrombits+", "+AbstractIndex.CHROMS_PER_BLOCK;
453 }
454
455 @Override
456 public void testSpeed(String[] args){
457
458 if(in1==null || maxReads==0){
459 outstream.println("No reads to process; quitting.");
460 return;
461 }
462
463 Timer t=new Timer();
464
465 final boolean paired=openStreams(t, args);
466 if(paired){BBIndex.QUIT_AFTER_TWO_PERFECTS=false;}
467
468 t.start();
469
470 if(Shared.USE_JNI){
471 final int threads=Shared.threads();
472 adjustThreadsforMemory(105);
473 if(Shared.threads()<threads*0.9){
474 outstream.println("Disabling JNI due to low system memory.");
475 Shared.USE_JNI=false;
476 Shared.setThreads(threads);
477 }
478 }
479 if(!Shared.USE_JNI){
480 adjustThreadsforMemory(65);
481 }
482
483 AbstractMapThread.CALC_STATISTICS=CALC_STATISTICS;
484 AbstractMapThread[] mtts=new AbstractMapThread[Shared.threads()];
485 for(int i=0; i<mtts.length; i++){
486 try {
487 mtts[i]=new BBMapThread(cris, keylen,
488 pileup, SLOW_ALIGN, CORRECT_THRESH, minChrom,
489 maxChrom, keyDensity, maxKeyDensity, minKeyDensity, maxDesiredKeys, REMOVE_DUPLICATE_BEST_ALIGNMENTS,
490 SAVE_AMBIGUOUS_XY, MINIMUM_ALIGNMENT_SCORE_RATIO, TRIM_LIST, MAKE_MATCH_STRING, QUICK_MATCH_STRINGS, rosA, rosM, rosU, rosB,
491 SLOW_ALIGN_PADDING, SLOW_RESCUE_PADDING, OUTPUT_MAPPED_ONLY, DONT_OUTPUT_BLACKLISTED_READS, MAX_SITESCORES_TO_PRINT, PRINT_SECONDARY_ALIGNMENTS,
492 REQUIRE_CORRECT_STRANDS_PAIRS, SAME_STRAND_PAIRS, KILL_BAD_PAIRS, rcompMate,
493 PERFECTMODE, SEMIPERFECTMODE, FORBID_SELF_MAPPING, TIP_SEARCH_DIST,
494 ambiguousRandom, ambiguousAll, KFILTER, MIN_IDFILTER, qtrimLeft, qtrimRight, untrim, TRIM_QUALITY, minTrimLength,
495 LOCAL_ALIGN, RESCUE, STRICT_MAX_INDEL, MSA_TYPE, bloomFilter);
496 } catch (Throwable e) {
497 e.printStackTrace();
498 abort(mtts, "Aborting due to prior error when making thread "+i+".");
499 }
500 mtts[i].idmodulo=idmodulo;
501 if(verbose){
502 mtts[i].verbose=verbose;
503 mtts[i].index().verbose=verbose;
504 }
505 }
506
507 cris.start(); //4567
508 outstream.println("Processing reads in "+(paired ? "paired" : "single")+"-ended mode.");
509 outstream.println("Started read stream.");
510
511 /* The threads are started after initialization to prevent resource competition between initialization and mapping */
512 for(int i=0; i<mtts.length; i++){mtts[i].start();}
513 outstream.println("Started "+mtts.length+" mapping thread"+(mtts.length==1 ? "" : "s")+".");
514
515 final int broken=shutDownThreads(mtts, false);
516
517 if(printStats){outstream.println("\n\n ------------------ Results ------------------ ");}
518 closeStreams(cris, rosA, rosM, rosU, rosB);
519 outstream.println();
520 if(printSettings){printSettings(keylen);}
521
522 printOutput(mtts, t, keylen, paired, false, pileup, scafNzo, sortStats, statsOutputFile);
523 if(broken>0 || errorState){throw new RuntimeException("BBMap terminated in an error state; the output may be corrupt.");}
524 }
525
526 @Override
527 void setSemiperfectMode() {
528 assert(SEMIPERFECTMODE);
529 if(SEMIPERFECTMODE){
530 TRIM_LIST=false;
531 keyDensity/=2;
532 maxKeyDensity/=2;
533 minKeyDensity=1.1f;
534 maxDesiredKeys/=2;
535 MINIMUM_ALIGNMENT_SCORE_RATIO=0.45f;
536 BBIndex.setSemiperfectMode();
537 }
538 }
539
540 @Override
541 void setPerfectMode() {
542 assert(PERFECTMODE);
543 if(PERFECTMODE){
544 TRIM_LIST=false;
545 keyDensity/=2;
546 maxKeyDensity/=2;
547 minKeyDensity=1.1f;
548 maxDesiredKeys/=2;
549 MINIMUM_ALIGNMENT_SCORE_RATIO=1.0f;
550 BBIndex.setPerfectMode();
551 }
552 }
553
554
555 @Override
556 void printSettings(int k){
557
558 printSettings0(k, BBIndex.MAX_INDEL, MINIMUM_ALIGNMENT_SCORE_RATIO);
559
560 if(verbose_stats>=2){
561 outstream.println("Key Density: \t"+keyDensity+" ("+minKeyDensity+" ~ "+maxKeyDensity+")");
562 outstream.println("Max keys: \t"+maxDesiredKeys);
563
564 outstream.println("Block Subsections: \t"+BBIndex.CHROMS_PER_BLOCK);
565 outstream.println("Fraction To Remove: \t"+Tools.format("%.4f", (BBIndex.REMOVE_FREQUENT_GENOME_FRACTION ? BBIndex.FRACTION_GENOME_TO_EXCLUDE : 0)));
566 // sysout.println("ADD_SCORE_Z: \t"+Index4.ADD_SCORE_Z);
567 outstream.println("Hits To Keep: \t"+BBIndex.MIN_APPROX_HITS_TO_KEEP);
568 }
569
570 if(verbose_stats>=3){
571 outstream.println("Remove Clumpy: \t"+BBIndex.REMOVE_CLUMPY);
572 if(BBIndex.REMOVE_CLUMPY){
573 outstream.println("CLUMPY_MAX_DIST: \t"+BBIndex.CLUMPY_MAX_DIST);
574 outstream.println("CLUMPY_MIN_LENGTH: \t"+BBIndex.CLUMPY_MIN_LENGTH_INDEX);
575 outstream.println("CLUMPY_FRACTION: \t"+BBIndex.CLUMPY_FRACTION);
576 }
577 outstream.println("Remove Long Lists: \t"+BBIndex.TRIM_LONG_HIT_LISTS);
578 if(BBIndex.TRIM_LONG_HIT_LISTS){
579 outstream.println("HIT_FRACTION_TO_RETAIN:\t"+BBIndex.HIT_FRACTION_TO_RETAIN);
580 }
581 outstream.println("Trim By Greedy: \t"+BBIndex.TRIM_BY_GREEDY);
582 outstream.println("Trim By Total Sites: \t"+BBIndex.TRIM_BY_TOTAL_SITE_COUNT);
583 if(BBIndex.TRIM_BY_TOTAL_SITE_COUNT){
584 outstream.println("MAX_AVG_SITES: \t"+BBIndex.MAX_AVERAGE_LIST_TO_SEARCH);
585 outstream.println("MAX_AVG_SITES_2: \t"+BBIndex.MAX_AVERAGE_LIST_TO_SEARCH2);
586 outstream.println("MAX_SHORTEST_SITE: \t"+BBIndex.MAX_SHORTEST_LIST_TO_SEARCH);
587 }
588 outstream.println("Index Min Score: \t"+BBIndex.MIN_SCORE_MULT);
589
590 outstream.println("Dynamic Trim: \t"+BBIndex.DYNAMICALLY_TRIM_LOW_SCORES);
591 if(BBIndex.DYNAMICALLY_TRIM_LOW_SCORES){
592 outstream.println("DYNAMIC_SCORE_THRESH: \t"+BBIndex.DYNAMIC_SCORE_THRESH);
593 }
594 }
595
596 }
597
598 }