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