| 1 |
package jgi; |
| 2 |
|
| 3 |
import java.io.File; |
| 4 |
import java.io.PrintStream; |
| 5 |
import java.util.ArrayList; |
| 6 |
import java.util.Random; |
| 7 |
|
| 8 |
import fileIO.ByteFile; |
| 9 |
import fileIO.ByteFile1; |
| 10 |
import fileIO.ByteFile2; |
| 11 |
import fileIO.FileFormat; |
| 12 |
import fileIO.ReadWrite; |
| 13 |
import fileIO.TextStreamWriter; |
| 14 |
import kmer.AbstractKmerTable; |
| 15 |
import kmer.HashArray1D; |
| 16 |
import kmer.HashForest; |
| 17 |
import kmer.KmerTable; |
| 18 |
import kmer.ScheduleMaker; |
| 19 |
import shared.Parse; |
| 20 |
import shared.Parser; |
| 21 |
import shared.PreParser; |
| 22 |
import shared.Shared; |
| 23 |
import shared.Timer; |
| 24 |
import shared.Tools; |
| 25 |
import stream.ConcurrentGenericReadInputStream; |
| 26 |
import stream.ConcurrentReadInputStream; |
| 27 |
import stream.FASTQ; |
| 28 |
import stream.FastaReadInputStream; |
| 29 |
import stream.Read; |
| 30 |
import structures.ListNum; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public class CalcUniqueness { |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public static void main(String[] args){ |
| 46 |
Timer t=new Timer(); |
| 47 |
CalcUniqueness x=new CalcUniqueness(args); |
| 48 |
x.process(t); |
| 49 |
|
| 50 |
|
| 51 |
Shared.closeStream(x.outstream); |
| 52 |
} |
| 53 |
|
| 54 |
public CalcUniqueness(String[] args){ |
| 55 |
|
| 56 |
{ |
| 57 |
PreParser pp=new PreParser(args, getClass(), false); |
| 58 |
args=pp.args; |
| 59 |
outstream=pp.outstream; |
| 60 |
} |
| 61 |
|
| 62 |
boolean setInterleaved=false; |
| 63 |
|
| 64 |
Shared.capBuffers(4); |
| 65 |
ReadWrite.USE_UNPIGZ=true; |
| 66 |
|
| 67 |
int k_=25; |
| 68 |
|
| 69 |
Parser parser=new Parser(); |
| 70 |
for(int i=0; i<args.length; i++){ |
| 71 |
String arg=args[i]; |
| 72 |
String[] split=arg.split("="); |
| 73 |
String a=split[0].toLowerCase(); |
| 74 |
String b=split.length>1 ? split[1] : null; |
| 75 |
|
| 76 |
if(parser.parse(arg, a, b)){ |
| 77 |
|
| 78 |
}else if(a.equals("printlastbin") || a.equals("plb")){ |
| 79 |
printLastBin=Parse.parseBoolean(b); |
| 80 |
}else if(a.equals("verbose")){ |
| 81 |
verbose=Parse.parseBoolean(b); |
| 82 |
ByteFile1.verbose=verbose; |
| 83 |
ByteFile2.verbose=verbose; |
| 84 |
stream.FastaReadInputStream.verbose=verbose; |
| 85 |
stream.FastqReadInputStream.verbose=verbose; |
| 86 |
ConcurrentGenericReadInputStream.verbose=verbose; |
| 87 |
ReadWrite.verbose=verbose; |
| 88 |
}else if(a.equals("cumulative")){ |
| 89 |
cumulative=Parse.parseBoolean(b); |
| 90 |
}else if(a.equals("offset")){ |
| 91 |
singleOffset=Integer.parseInt(b); |
| 92 |
}else if(a.equals("percent") || a.equals("percents")){ |
| 93 |
showPercents=Parse.parseBoolean(b); |
| 94 |
}else if(a.equals("count") || a.equals("counts")){ |
| 95 |
showCounts=Parse.parseBoolean(b); |
| 96 |
}else if(a.equals("minprob") || a.equals("percents")){ |
| 97 |
minprob=Float.parseFloat(b); |
| 98 |
}else if(a.equals("k")){ |
| 99 |
k_=Integer.parseInt(b); |
| 100 |
}else if(a.equals("fixpeaks") || a.equals("fixspikes") || a.equals("fs")){ |
| 101 |
fixSpikes=Parse.parseBoolean(b); |
| 102 |
}else if(a.equals("bin") || a.equals("interval")){ |
| 103 |
interval=Parse.parseKMG(b); |
| 104 |
}else if(parser.in1==null && i==0 && Tools.looksLikeInputStream(arg)){ |
| 105 |
parser.in1=arg; |
| 106 |
}else{ |
| 107 |
|
| 108 |
|
| 109 |
throw new RuntimeException("Unknown parameter "+args[i]); |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
{ |
| 114 |
Parser.processQuality(); |
| 115 |
minAverageQuality=parser.minAvgQuality; |
| 116 |
minAverageQualityBases=parser.minAvgQualityBases; |
| 117 |
|
| 118 |
maxReads=parser.maxReads; |
| 119 |
samplerate=parser.samplerate; |
| 120 |
sampleseed=parser.sampleseed; |
| 121 |
|
| 122 |
overwrite=parser.overwrite; |
| 123 |
append=parser.append; |
| 124 |
testsize=parser.testsize; |
| 125 |
|
| 126 |
setInterleaved=parser.setInterleaved; |
| 127 |
|
| 128 |
in1=parser.in1; |
| 129 |
in2=parser.in2; |
| 130 |
|
| 131 |
out=parser.out1; |
| 132 |
|
| 133 |
extin=parser.extin; |
| 134 |
extout=parser.extout; |
| 135 |
} |
| 136 |
setSampleSeed(-1); |
| 137 |
|
| 138 |
k=k_; |
| 139 |
k2=k-1; |
| 140 |
assert(k>0 && k<32) : "k="+k+"; valid range is 1-31"; |
| 141 |
|
| 142 |
if(in1!=null && in2==null && in1.indexOf('#')>-1 && !new File(in1).exists()){ |
| 143 |
in2=in1.replace("#", "2"); |
| 144 |
in1=in1.replace("#", "1"); |
| 145 |
} |
| 146 |
if(in2!=null){ |
| 147 |
if(FASTQ.FORCE_INTERLEAVED){System.err.println("Reset INTERLEAVED to false because paired input files were specified.");} |
| 148 |
FASTQ.FORCE_INTERLEAVED=FASTQ.TEST_INTERLEAVED=false; |
| 149 |
} |
| 150 |
|
| 151 |
assert(FastaReadInputStream.settingsOK()); |
| 152 |
|
| 153 |
if(in1==null){throw new RuntimeException("Error - at least one input file is required.");} |
| 154 |
if(!ByteFile.FORCE_MODE_BF1 && !ByteFile.FORCE_MODE_BF2 && Shared.threads()>2){ |
| 155 |
ByteFile.FORCE_MODE_BF2=true; |
| 156 |
} |
| 157 |
|
| 158 |
if(out==null){ |
| 159 |
out="stdout.txt"; |
| 160 |
} |
| 161 |
|
| 162 |
if(!setInterleaved){ |
| 163 |
assert(in1!=null && out!=null) : "\nin1="+in1+"\nin2="+in2+"\nout="+out+"\n"; |
| 164 |
if(in2!=null){ |
| 165 |
FASTQ.FORCE_INTERLEAVED=FASTQ.TEST_INTERLEAVED=false; |
| 166 |
outstream.println("Set INTERLEAVED to "+FASTQ.FORCE_INTERLEAVED); |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
if(!Tools.testOutputFiles(overwrite, append, false, out)){ |
| 171 |
throw new RuntimeException("\n\noverwrite="+overwrite+"; Can't write to output file "+out+"\n"); |
| 172 |
} |
| 173 |
|
| 174 |
ffout=FileFormat.testOutput(out, FileFormat.TEXT, extout, false, overwrite, append, false); |
| 175 |
|
| 176 |
ffin1=FileFormat.testInput(in1, FileFormat.FASTQ, extin, true, true); |
| 177 |
ffin2=FileFormat.testInput(in2, FileFormat.FASTQ, extin, true, true); |
| 178 |
|
| 179 |
keySets=new AbstractKmerTable[WAYS]; |
| 180 |
|
| 181 |
|
| 182 |
ScheduleMaker scheduleMaker=new ScheduleMaker(WAYS, 12, false, 1); |
| 183 |
int[] schedule=scheduleMaker.makeSchedule(); |
| 184 |
for(int j=0; j<WAYS; j++){ |
| 185 |
if(useForest){ |
| 186 |
keySets[j]=new HashForest(initialSize, true, false); |
| 187 |
}else if(useTable){ |
| 188 |
keySets[j]=new KmerTable(initialSize, true); |
| 189 |
}else if(useArray){ |
| 190 |
|
| 191 |
keySets[j]=new HashArray1D(schedule, -1L); |
| 192 |
}else{ |
| 193 |
throw new RuntimeException("Must use forest, table, or array data structure."); |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
private class Counter{ |
| 204 |
|
| 205 |
Counter(int mask_){ |
| 206 |
mask=mask_; |
| 207 |
} |
| 208 |
|
| 209 |
void incrementQuality(Read r){ |
| 210 |
qualCounts++; |
| 211 |
double q=r.avgQualityByProbabilityDouble(true, r.length()); |
| 212 |
quality+=q; |
| 213 |
double p=r.probabilityErrorFree(true, r.length()); |
| 214 |
perfectProb+=p; |
| 215 |
} |
| 216 |
|
| 217 |
void increment(final long kmer){ |
| 218 |
if(kmer<0){return;} |
| 219 |
AbstractKmerTable table=keySets[(int)(kmer%WAYS)]; |
| 220 |
int count=table.getValue(kmer); |
| 221 |
if(count<1){ |
| 222 |
table.set(kmer, mask); |
| 223 |
misses++; |
| 224 |
cmisses++; |
| 225 |
}else if((count&mask)==0){ |
| 226 |
table.set(kmer, count|mask); |
| 227 |
misses++; |
| 228 |
cmisses++; |
| 229 |
}else{ |
| 230 |
hits++; |
| 231 |
chits++; |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
void reset(){ |
| 236 |
prevPercent=percent(); |
| 237 |
prevHits=hits; |
| 238 |
prevMisses=misses; |
| 239 |
|
| 240 |
hits=misses=0; |
| 241 |
quality=0; |
| 242 |
perfectProb=0; |
| 243 |
qualCounts=0; |
| 244 |
} |
| 245 |
|
| 246 |
public double averageQuality() { |
| 247 |
return qualCounts<1 ? 0 : quality/qualCounts; |
| 248 |
} |
| 249 |
|
| 250 |
public double averagePerfectProb() { |
| 251 |
return qualCounts<1 ? 0 : 100*perfectProb/qualCounts; |
| 252 |
} |
| 253 |
|
| 254 |
double percent(){ |
| 255 |
final long sum=hits()+misses(), prevSum=prevHits+prevMisses; |
| 256 |
if(sum==0){return 0;} |
| 257 |
double percent=misses()*100.0/sum; |
| 258 |
if(cumulative || !fixSpikes || prevSum==0){return percent;} |
| 259 |
assert(!cumulative && fixSpikes); |
| 260 |
return Tools.min(percent, prevPercent+0.2); |
| 261 |
} |
| 262 |
|
| 263 |
String percentS(){ |
| 264 |
return Tools.format("%.3f",percent()); |
| 265 |
} |
| 266 |
|
| 267 |
long hits(){return cumulative ? chits : hits;} |
| 268 |
long misses(){return cumulative ? cmisses : misses;} |
| 269 |
|
| 270 |
final int mask; |
| 271 |
|
| 272 |
double perfectProb; |
| 273 |
double quality; |
| 274 |
long qualCounts; |
| 275 |
|
| 276 |
|
| 277 |
long hits=0; |
| 278 |
|
| 279 |
long misses=0; |
| 280 |
|
| 281 |
|
| 282 |
long chits=0; |
| 283 |
|
| 284 |
long cmisses=0; |
| 285 |
|
| 286 |
long prevHits=0; |
| 287 |
long prevMisses=0; |
| 288 |
double prevPercent=0; |
| 289 |
} |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
void process(Timer t){ |
| 296 |
|
| 297 |
final ConcurrentReadInputStream cris; |
| 298 |
{ |
| 299 |
cris=ConcurrentReadInputStream.getReadInputStream(maxReads, true, ffin1, ffin2, null, null); |
| 300 |
cris.setSampleRate(samplerate, sampleseed); |
| 301 |
if(verbose){System.err.println("Started cris");} |
| 302 |
cris.start(); |
| 303 |
} |
| 304 |
final boolean paired=cris.paired(); |
| 305 |
if(verbose){System.err.println("Input is "+(paired ? "paired" : "unpaired"));} |
| 306 |
|
| 307 |
TextStreamWriter tsw=null; |
| 308 |
if(out!=null){ |
| 309 |
tsw=new TextStreamWriter(ffout); |
| 310 |
tsw.start(); |
| 311 |
tsw.print("#count"); |
| 312 |
if(showPercents){ |
| 313 |
tsw.print("\tfirst\trand"); |
| 314 |
if(paired){tsw.print("\tr1_first\tr1_rand\tr2_first\tr2_rand\tpair");} |
| 315 |
} |
| 316 |
if(showCounts){ |
| 317 |
tsw.print("\tfirst_cnt\trand_cnt"); |
| 318 |
if(paired){tsw.print("\tr1_first_cnt\tr1_rand_cnt\tr2_first_cnt\tr2_rand_cnt\tpair_cnt");} |
| 319 |
} |
| 320 |
if(showQuality){ |
| 321 |
tsw.print("\tavg_quality\tperfect_prob"); |
| 322 |
} |
| 323 |
tsw.print("\n"); |
| 324 |
} |
| 325 |
|
| 326 |
|
| 327 |
long pairsProcessed=0; |
| 328 |
long readsProcessed=0; |
| 329 |
long basesProcessed=0; |
| 330 |
|
| 331 |
|
| 332 |
long remaining=interval; |
| 333 |
|
| 334 |
final StringBuilder sb=new StringBuilder(1024); |
| 335 |
|
| 336 |
{ |
| 337 |
|
| 338 |
ListNum<Read> ln=cris.nextList(); |
| 339 |
ArrayList<Read> reads=(ln!=null ? ln.list : null); |
| 340 |
|
| 341 |
if(reads!=null && !reads.isEmpty()){ |
| 342 |
Read r=reads.get(0); |
| 343 |
assert((ffin1==null || ffin1.samOrBam()) || (r.mate!=null)==cris.paired()); |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
while(ln!=null && reads!=null && reads.size()>0){ |
| 348 |
|
| 349 |
for(Read r1 : reads){ |
| 350 |
if(minAverageQuality<1 || r1.avgQualityFirstNBases(minAverageQualityBases)>=minAverageQuality){ |
| 351 |
final Read r2=r1.mate; |
| 352 |
final byte[] bases1=(r1==null ? null : r1.bases); |
| 353 |
final byte[] bases2=(r2==null ? null : r2.bases); |
| 354 |
final byte[] quals1=(r1==null ? null : r1.quality); |
| 355 |
final byte[] quals2=(r2==null ? null : r2.quality); |
| 356 |
final int length1=(bases1==null ? 0 : bases1.length); |
| 357 |
final int length2=(bases2==null ? 0 : bases2.length); |
| 358 |
|
| 359 |
pairsProcessed++; |
| 360 |
|
| 361 |
|
| 362 |
if(r1!=null){ |
| 363 |
|
| 364 |
bothCounterFirst.incrementQuality(r1); |
| 365 |
|
| 366 |
readsProcessed++; |
| 367 |
basesProcessed+=length1; |
| 368 |
|
| 369 |
if(length1>=k){ |
| 370 |
if(length1>=k+singleOffset){ |
| 371 |
final long kmer=toKmer(bases1, quals1, singleOffset, k); |
| 372 |
r1CounterFirst.increment(kmer); |
| 373 |
bothCounterFirst.increment(kmer); |
| 374 |
} |
| 375 |
{ |
| 376 |
final long kmer=toKmer(bases1, quals1, randy.nextInt(length1-k2), k); |
| 377 |
r1CounterRand.increment(kmer); |
| 378 |
bothCounterRand.increment(kmer); |
| 379 |
} |
| 380 |
} |
| 381 |
} |
| 382 |
|
| 383 |
|
| 384 |
if(r2!=null){ |
| 385 |
|
| 386 |
bothCounterFirst.incrementQuality(r2); |
| 387 |
|
| 388 |
readsProcessed++; |
| 389 |
basesProcessed+=length2; |
| 390 |
|
| 391 |
if(length2>=k){ |
| 392 |
if(length2>=k+singleOffset){ |
| 393 |
final long kmer=toKmer(bases2, quals2, singleOffset, k); |
| 394 |
r2CounterFirst.increment(kmer); |
| 395 |
bothCounterFirst.increment(kmer); |
| 396 |
} |
| 397 |
{ |
| 398 |
final long kmer=toKmer(bases2, quals2, randy.nextInt(length2-k2), k); |
| 399 |
r2CounterRand.increment(kmer); |
| 400 |
bothCounterRand.increment(kmer); |
| 401 |
} |
| 402 |
} |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
if(r1!=null && r2!=null){ |
| 407 |
|
| 408 |
if(length1>k+PAIR_OFFSET && length2>k+PAIR_OFFSET){ |
| 409 |
final long kmer1=toKmer(bases1, quals1, PAIR_OFFSET, k); |
| 410 |
final long kmer2=toKmer(bases2, quals2, PAIR_OFFSET, k); |
| 411 |
if(kmer1!=-1 && kmer2!=-1){ |
| 412 |
final long kmer=(~((-1L)>>2))|((kmer1<<(2*(31-k)))^(kmer2)); |
| 413 |
assert(kmer>=0) : k+", "+kmer1+", "+kmer2+", "+kmer; |
| 414 |
{ |
| 415 |
pairCounter.increment(kmer); |
| 416 |
} |
| 417 |
} |
| 418 |
} |
| 419 |
} |
| 420 |
|
| 421 |
remaining--; |
| 422 |
if(remaining<=0){ |
| 423 |
|
| 424 |
printCountsToBuffer(sb, pairsProcessed, paired); |
| 425 |
|
| 426 |
if(tsw!=null){tsw.print(sb.toString());} |
| 427 |
|
| 428 |
|
| 429 |
sb.setLength(0); |
| 430 |
remaining=interval; |
| 431 |
} |
| 432 |
} |
| 433 |
} |
| 434 |
|
| 435 |
|
| 436 |
cris.returnList(ln); |
| 437 |
ln=cris.nextList(); |
| 438 |
reads=(ln!=null ? ln.list : null); |
| 439 |
} |
| 440 |
if(ln!=null){ |
| 441 |
cris.returnList(ln.id, ln.list==null || ln.list.isEmpty()); |
| 442 |
} |
| 443 |
} |
| 444 |
|
| 445 |
if(remaining<interval && printLastBin){ |
| 446 |
|
| 447 |
printCountsToBuffer(sb, pairsProcessed, paired); |
| 448 |
|
| 449 |
if(tsw!=null){tsw.print(sb.toString());} |
| 450 |
|
| 451 |
|
| 452 |
sb.setLength(0); |
| 453 |
remaining=interval; |
| 454 |
} |
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
errorState|=ReadWrite.closeStream(cris); |
| 459 |
if(tsw!=null){ |
| 460 |
tsw.poisonAndWait(); |
| 461 |
errorState|=tsw.errorState; |
| 462 |
} |
| 463 |
|
| 464 |
t.stop(); |
| 465 |
outstream.println(Tools.timeReadsBasesProcessed(t, readsProcessed, basesProcessed, 8)); |
| 466 |
|
| 467 |
if(testsize){ |
| 468 |
long bytesProcessed=(new File(in1).length()+(in2==null ? 0 : new File(in2).length())); |
| 469 |
double xpnano=bytesProcessed/(double)(t.elapsed); |
| 470 |
String xpstring=(bytesProcessed<100000 ? ""+bytesProcessed : bytesProcessed<100000000 ? (bytesProcessed/1000)+"k" : (bytesProcessed/1000000)+"m"); |
| 471 |
while(xpstring.length()<8){xpstring=" "+xpstring;} |
| 472 |
outstream.println("Bytes Processed: "+xpstring+" \t"+Tools.format("%.2fm bytes/sec", xpnano*1000)); |
| 473 |
} |
| 474 |
|
| 475 |
if(errorState){ |
| 476 |
throw new RuntimeException("CalcUniqueness terminated in an error state; the output may be corrupt."); |
| 477 |
} |
| 478 |
} |
| 479 |
|
| 480 |
|
| 481 |
private void printCountsToBuffer(StringBuilder sb, long pairsProcessed, boolean paired){ |
| 482 |
|
| 483 |
|
| 484 |
sb.append(pairsProcessed); |
| 485 |
|
| 486 |
if(showPercents){ |
| 487 |
sb.append('\t'); |
| 488 |
sb.append(bothCounterFirst.percentS()); |
| 489 |
sb.append('\t'); |
| 490 |
sb.append(bothCounterRand.percentS()); |
| 491 |
if(paired){ |
| 492 |
sb.append('\t'); |
| 493 |
sb.append(r1CounterFirst.percentS()); |
| 494 |
sb.append('\t'); |
| 495 |
sb.append(r1CounterRand.percentS()); |
| 496 |
sb.append('\t'); |
| 497 |
sb.append(r2CounterFirst.percentS()); |
| 498 |
sb.append('\t'); |
| 499 |
sb.append(r2CounterRand.percentS()); |
| 500 |
sb.append('\t'); |
| 501 |
sb.append(pairCounter.percentS()); |
| 502 |
} |
| 503 |
} |
| 504 |
|
| 505 |
if(showCounts){ |
| 506 |
sb.append('\t'); |
| 507 |
sb.append(bothCounterFirst.misses()); |
| 508 |
sb.append('\t'); |
| 509 |
sb.append(bothCounterRand.misses()); |
| 510 |
if(paired){ |
| 511 |
sb.append('\t'); |
| 512 |
sb.append(r1CounterFirst.misses()); |
| 513 |
sb.append('\t'); |
| 514 |
sb.append(r1CounterRand.misses()); |
| 515 |
sb.append('\t'); |
| 516 |
sb.append(r2CounterFirst.misses()); |
| 517 |
sb.append('\t'); |
| 518 |
sb.append(r2CounterRand.misses()); |
| 519 |
sb.append('\t'); |
| 520 |
sb.append(pairCounter.misses()); |
| 521 |
} |
| 522 |
} |
| 523 |
|
| 524 |
if(showQuality){ |
| 525 |
sb.append('\t').append(Tools.format("%.2f", bothCounterFirst.averageQuality())); |
| 526 |
sb.append('\t').append(Tools.format("%.2f", bothCounterFirst.averagePerfectProb())); |
| 527 |
} |
| 528 |
|
| 529 |
sb.append('\n'); |
| 530 |
|
| 531 |
bothCounterFirst.reset(); |
| 532 |
bothCounterRand.reset(); |
| 533 |
r1CounterFirst.reset(); |
| 534 |
r1CounterRand.reset(); |
| 535 |
r2CounterFirst.reset(); |
| 536 |
r2CounterRand.reset(); |
| 537 |
pairCounter.reset(); |
| 538 |
} |
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
private final long toKmer(final byte[] bases, byte[] quals, final int start, final int klen){ |
| 553 |
if(minprob>0 && quals!=null){ |
| 554 |
float prob=toProb(quals, start, klen); |
| 555 |
if(prob<minprob){return -1;} |
| 556 |
} |
| 557 |
final int stop=start+klen; |
| 558 |
assert(stop<=bases.length); |
| 559 |
long kmer=0; |
| 560 |
|
| 561 |
for(int i=start; i<stop; i++){ |
| 562 |
final byte b=bases[i]; |
| 563 |
final long x=Dedupe.baseToNumber[b]; |
| 564 |
kmer=((kmer<<2)|x); |
| 565 |
} |
| 566 |
return kmer; |
| 567 |
} |
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
private final static float toProb(final byte[] quals, final int start, final int klen){ |
| 577 |
final int stop=start+klen; |
| 578 |
assert(stop<=quals.length); |
| 579 |
float prob=1f; |
| 580 |
|
| 581 |
for(int i=start; i<stop; i++){ |
| 582 |
final byte q=quals[i]; |
| 583 |
float pq=probCorrect[q]; |
| 584 |
prob*=pq; |
| 585 |
} |
| 586 |
return prob; |
| 587 |
} |
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
public void setSampleSeed(long seed){ |
| 592 |
randy=Shared.threadLocalRandom(seed); |
| 593 |
} |
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
private String in1=null; |
| 600 |
private String in2=null; |
| 601 |
|
| 602 |
private String out=null; |
| 603 |
|
| 604 |
private String extin=null; |
| 605 |
private String extout=null; |
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
private final Counter r1CounterFirst=new Counter(1); |
| 611 |
private final Counter r1CounterRand=new Counter(2); |
| 612 |
private final Counter r2CounterFirst=new Counter(4); |
| 613 |
private final Counter r2CounterRand=new Counter(8); |
| 614 |
private final Counter pairCounter=new Counter(16); |
| 615 |
|
| 616 |
private final Counter bothCounterFirst=new Counter(32); |
| 617 |
private final Counter bothCounterRand=new Counter(64); |
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
private long maxReads=-1; |
| 623 |
private float samplerate=1f; |
| 624 |
private long sampleseed=-1; |
| 625 |
|
| 626 |
private long interval=25000; |
| 627 |
private float minprob=0; |
| 628 |
private float minAverageQuality=0; |
| 629 |
private int minAverageQualityBases=20; |
| 630 |
private int singleOffset=0; |
| 631 |
private boolean cumulative=false; |
| 632 |
private boolean showPercents=true; |
| 633 |
private boolean showCounts=false; |
| 634 |
private boolean printLastBin=false; |
| 635 |
private boolean showQuality=true; |
| 636 |
private boolean fixSpikes=false; |
| 637 |
|
| 638 |
private final int k, k2; |
| 639 |
private static final int WAYS=31; |
| 640 |
private static final int PAIR_OFFSET=10; |
| 641 |
|
| 642 |
|
| 643 |
private int initialSize=512000; |
| 644 |
|
| 645 |
|
| 646 |
private final AbstractKmerTable[] keySets; |
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
private final FileFormat ffin1; |
| 651 |
private final FileFormat ffin2; |
| 652 |
|
| 653 |
private final FileFormat ffout; |
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
private PrintStream outstream=System.err; |
| 659 |
public static boolean verbose=false; |
| 660 |
public boolean errorState=false; |
| 661 |
private boolean overwrite=true; |
| 662 |
private boolean append=false; |
| 663 |
private boolean testsize=false; |
| 664 |
|
| 665 |
private static final boolean useForest=false, useTable=false, useArray=true; |
| 666 |
|
| 667 |
private Random randy; |
| 668 |
|
| 669 |
private static final float[] probCorrect= |
| 670 |
{0.0000f, 0.2501f, 0.3690f, 0.4988f, 0.6019f, 0.6838f, 0.7488f, 0.8005f, 0.8415f, 0.8741f, 0.9000f, 0.9206f, 0.9369f, 0.9499f, |
| 671 |
0.9602f, 0.9684f, 0.9749f, 0.9800f, 0.9842f, 0.9874f, 0.9900f, 0.9921f, 0.9937f, 0.9950f, 0.9960f, 0.9968f, 0.9975f, 0.9980f, |
| 672 |
0.9984f, 0.9987f, 0.9990f, 0.9992f, 0.9994f, 0.9995f, 0.9996f, 0.9997f, 0.9997f, 0.9998f, 0.9998f, 0.9999f, 0.9999f, 0.9999f, |
| 673 |
0.9999f, 0.9999f, 0.9999f, 0.9999f, 0.9999f, 0.9999f, 0.9999f, 0.9999f, 0.9999f, 0.9999f, 0.9999f, 0.9999f, 0.9999f, 0.9999f, |
| 674 |
0.9999f, 0.9999f, 0.9999f, 0.9999f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f}; |
| 675 |
|
| 676 |
|
| 677 |
} |