| 1 |
package clump; |
| 2 |
|
| 3 |
import java.util.ArrayList; |
| 4 |
|
| 5 |
import dna.AminoAcid; |
| 6 |
import hiseq.FlowcellCoordinate; |
| 7 |
import shared.KillSwitch; |
| 8 |
import shared.Parse; |
| 9 |
import shared.Tools; |
| 10 |
import stream.Read; |
| 11 |
import structures.ByteBuilder; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
public class Clump extends ArrayList<Read> implements Comparable<Clump> { |
| 20 |
|
| 21 |
public static Clump makeClump(long kmer){ |
| 22 |
try { |
| 23 |
return new Clump(kmer); |
| 24 |
} catch (OutOfMemoryError e) { |
| 25 |
KillSwitch.memKill(e); |
| 26 |
throw new RuntimeException(); |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
private Clump(long kmer_){ |
| 31 |
this(kmer_, 4); |
| 32 |
} |
| 33 |
|
| 34 |
private Clump(long kmer_, int size){ |
| 35 |
super(size); |
| 36 |
kmer=kmer_; |
| 37 |
} |
| 38 |
|
| 39 |
@Override |
| 40 |
public boolean add(Read r){ |
| 41 |
ReadKey key=(ReadKey) r.obj; |
| 42 |
assert(key.kmer==kmer); |
| 43 |
key.clump=this; |
| 44 |
return super.add(r); |
| 45 |
} |
| 46 |
|
| 47 |
private void setMaxima(){ |
| 48 |
maxLeft=-1; |
| 49 |
maxRight=-1; |
| 50 |
width=-1; |
| 51 |
for(Read r : this){ |
| 52 |
ReadKey key=(ReadKey) r.obj; |
| 53 |
final int pos=key.position; |
| 54 |
maxLeft=Tools.max(maxLeft, pos); |
| 55 |
maxRight=Tools.max(maxRight, r.length()-pos); |
| 56 |
} |
| 57 |
width=maxLeft+maxRight; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
private int[][] count(final boolean qualityScores){ |
| 62 |
if(width<0){setMaxima();} |
| 63 |
|
| 64 |
|
| 65 |
final int[][] counts=new int[4][width]; |
| 66 |
for(Read r : this){ |
| 67 |
ReadKey key=(ReadKey) r.obj; |
| 68 |
final int pos=key.position; |
| 69 |
byte[] bases=r.bases, quals=r.quality; |
| 70 |
if(quals==null){useQuality=false;} |
| 71 |
|
| 72 |
|
| 73 |
for(int cloc=0, rloc=maxLeft-pos; cloc<bases.length; cloc++, rloc++){ |
| 74 |
|
| 75 |
int x=AminoAcid.baseToNumber[bases[cloc]]; |
| 76 |
if(x>-1){ |
| 77 |
final int q; |
| 78 |
if(qualityScores){q=(quals==null ? 20 : quals[cloc]);} |
| 79 |
else{q=1;} |
| 80 |
counts[x][rloc]+=q; |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
return counts; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
public Read makeSimpleConsensus(){ |
| 90 |
|
| 91 |
if(size()==1){ |
| 92 |
Read r=get(0); |
| 93 |
if(renameConsensus){r.id=r.numericID+" size=1";} |
| 94 |
return r; |
| 95 |
} |
| 96 |
final int[][] bcounts=baseCounts(); |
| 97 |
final int[][] qcounts=qualityCounts(); |
| 98 |
|
| 99 |
final byte[] bases=new byte[width], quals=new byte[width]; |
| 100 |
for(int i=0; i<width; i++){ |
| 101 |
int x=getConsensusAtPosition(qcounts, i); |
| 102 |
int y=getSecondHighest(qcounts, i); |
| 103 |
if(x>=0 && qcounts[x][i]==qcounts[y][i]){ |
| 104 |
x=getConsensusAtPosition(bcounts, i); |
| 105 |
y=getSecondHighest(bcounts, i); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
if(x<0){ |
| 110 |
|
| 111 |
bases[i]='N'; |
| 112 |
quals[i]=0; |
| 113 |
assert(getSumAtPosition(qcounts, i)==0) : "\n"+bcounts[0][i]+", "+bcounts[1][i]+", "+bcounts[2][i]+", "+bcounts[3][i]+ |
| 114 |
"\n"+qcounts[0][i]+", "+qcounts[1][i]+", "+qcounts[2][i]+", "+qcounts[3][i]+ |
| 115 |
"\nwidth="+width+", i="+i+", size="+size()+"\n"+new String(bases, 0, i)+"\n"+get(0)+"\n"+get(1)+"\n"; |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
}else{ |
| 120 |
final long bsum=getSumAtPosition(bcounts, i); |
| 121 |
final long bmajor=bcounts[x][i]; |
| 122 |
final long bminor=bsum-bcounts[x][i]; |
| 123 |
final long bsecond=bcounts[y][i]; |
| 124 |
|
| 125 |
final long qsum=getSumAtPosition(qcounts, i); |
| 126 |
final long qmajor=qcounts[x][i]; |
| 127 |
final long qminor=qsum-qcounts[x][i]; |
| 128 |
final long qsecond=qcounts[y][i]; |
| 129 |
|
| 130 |
float bratio=bminor/(float)(bmajor+bminor); |
| 131 |
double phred=(bminor==0 ? Read.MAX_CALLED_QUALITY() : -10*Math.log10(bratio)); |
| 132 |
phred=Tools.min(phred, qmajor-qminor); |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
byte q=Read.capQuality((long)Math.round(phred)); |
| 143 |
bases[i]=AminoAcid.numberToBase[x]; |
| 144 |
quals[i]=q; |
| 145 |
assert(q>0); |
| 146 |
assert(x>-1); |
| 147 |
assert(bases[i]!='N'); |
| 148 |
} |
| 149 |
} |
| 150 |
Read leftmost=this.get(0); |
| 151 |
Read r=new Read(bases, quals, leftmost.numericID+" size="+size(), 0); |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
return r; |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
public int removeDuplicates(){ |
| 161 |
assert(KmerComparator.compareSequence); |
| 162 |
if(size()<2){return 0;} |
| 163 |
|
| 164 |
int removedTotal=0, removed=0; |
| 165 |
|
| 166 |
final boolean sortXY=(forceSortXY || sortYEarly() || (opticalOnly && (sortX || sortY) && size()>=sortXYSize)); |
| 167 |
|
| 168 |
final int maxDiscarded; |
| 169 |
final int scan; |
| 170 |
|
| 171 |
if(opticalOnly && sortXY){ |
| 172 |
scan=Tools.max(scanLimit, 200); |
| 173 |
maxDiscarded=scan+10; |
| 174 |
}else if(!sortXY && ((maxSubstitutions<1 && dupeSubRate<=0) || scanLimit<0)){ |
| 175 |
scan=0; |
| 176 |
maxDiscarded=0; |
| 177 |
}else{ |
| 178 |
scan=scanLimit; |
| 179 |
maxDiscarded=scan+10; |
| 180 |
} |
| 181 |
|
| 182 |
if(sortXY){ |
| 183 |
assert(sortX || sortY); |
| 184 |
|
| 185 |
if(sortY){ |
| 186 |
if(!sortYEarly()){ |
| 187 |
this.sort(KmerComparatorY.comparator); |
| 188 |
}else{ |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
} |
| 196 |
|
| 197 |
removed=removeDuplicates_inner(maxSubstitutions, dupeSubRate, scan, maxDiscarded, opticalOnly, true, markOnly, markAll, renameByCount, maxOpticalDistance); |
| 198 |
removedTotal+=removed; |
| 199 |
|
| 200 |
while((maxSubstitutions>0 || dupeSubRate>0) && scanLimit>0 && removed>maxDiscarded){ |
| 201 |
removed=removeDuplicates_inner(maxSubstitutions, dupeSubRate, scan+10, maxDiscarded*2+20, opticalOnly, true, markOnly, markAll, renameByCount, maxOpticalDistance); |
| 202 |
removedTotal+=removed; |
| 203 |
|
| 204 |
} |
| 205 |
} |
| 206 |
if(sortX && (ReadKey.spanTilesX || !sortY)){ |
| 207 |
this.sort(KmerComparatorX.comparator); |
| 208 |
removed=removeDuplicates_inner(maxSubstitutions, dupeSubRate, scan, maxDiscarded, opticalOnly, true, markOnly, markAll, renameByCount, maxOpticalDistance); |
| 209 |
removedTotal+=removed; |
| 210 |
|
| 211 |
while((maxSubstitutions>0 || dupeSubRate>0) && scanLimit>0 && removed>maxDiscarded){ |
| 212 |
removed=removeDuplicates_inner(maxSubstitutions, dupeSubRate, scan+10, maxDiscarded*2+20, opticalOnly, true, markOnly, markAll, renameByCount, maxOpticalDistance); |
| 213 |
removedTotal+=removed; |
| 214 |
|
| 215 |
} |
| 216 |
} |
| 217 |
}else{ |
| 218 |
removed=removeDuplicates_inner(maxSubstitutions, dupeSubRate, scan, maxDiscarded, opticalOnly, false, markOnly, markAll, renameByCount, maxOpticalDistance); |
| 219 |
removedTotal+=removed; |
| 220 |
while((maxSubstitutions>0 || dupeSubRate>0) && scanLimit>0 && removed>maxDiscarded){ |
| 221 |
removed=removeDuplicates_inner(maxSubstitutions, dupeSubRate, scan+10, maxDiscarded*2+20, opticalOnly, false, markOnly, markAll, renameByCount, maxOpticalDistance); |
| 222 |
removedTotal+=removed; |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
return removedTotal; |
| 227 |
} |
| 228 |
|
| 229 |
private int removeDuplicates_inner(final int maxSubs, final float subRate, final int scanLimit, final int maxDiscarded, |
| 230 |
final boolean optical, final boolean xySorted, final boolean mark, final boolean markAll, final boolean rename, final float dist){ |
| 231 |
final int size=size(); |
| 232 |
if(size<2){return 0;} |
| 233 |
int dupePairs=0; |
| 234 |
int dupeReads=0; |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
for(int i=0, lim=size-1; i<lim; i++){ |
| 241 |
final Read a=get(i); |
| 242 |
if(!a.discarded()){ |
| 243 |
final ReadKey keyA=(ReadKey) a.obj; |
| 244 |
final int aLen=a.length(); |
| 245 |
int unequals=0; |
| 246 |
int discarded=0; |
| 247 |
for(int j=i+1; j<size && unequals<=scanLimit && discarded<=maxDiscarded && (!a.discarded() || markAll); j++){ |
| 248 |
final Read b=get(j); |
| 249 |
if(b.discarded()){ |
| 250 |
discarded++; |
| 251 |
}else{ |
| 252 |
final int bLen=b.length(); |
| 253 |
final ReadKey keyB=(ReadKey) b.obj; |
| 254 |
if(!containment && !keyA.equals(keyB)){break;} |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
if(optical && xySorted && !keyA.nearXY(keyB, dist)){break;} |
| 259 |
if(compareUMI && !keyA.umiMatches(keyB, umiSubs)) {break;} |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
if(equals(a, b, maxSubs, subRate)){ |
| 270 |
if(!optical || keyA.near(keyB, dist)){ |
| 271 |
if(printDuplicates){ |
| 272 |
System.out.println(a.toFasta()); |
| 273 |
System.out.println(b.toFasta()); |
| 274 |
} |
| 275 |
float errA=a.expectedErrorsIncludingMate(true); |
| 276 |
float errB=b.expectedErrorsIncludingMate(true); |
| 277 |
if(markAll){ |
| 278 |
b.setDiscarded(true); |
| 279 |
assert(!a.discarded() || markAll); |
| 280 |
dupePairs++; |
| 281 |
dupeReads+=1+b.mateCount(); |
| 282 |
unequals=0; |
| 283 |
if(!a.discarded()){ |
| 284 |
a.setDiscarded(true); |
| 285 |
dupePairs++; |
| 286 |
dupeReads+=1+a.mateCount(); |
| 287 |
} |
| 288 |
}else if(containment || errB>=errA){ |
| 289 |
b.setDiscarded(true); |
| 290 |
assert(!a.discarded() || markAll); |
| 291 |
a.copies+=b.copies+parseExtraCopies(b); |
| 292 |
dupePairs++; |
| 293 |
dupeReads+=1+b.mateCount(); |
| 294 |
unequals=0; |
| 295 |
}else{ |
| 296 |
a.setDiscarded(true); |
| 297 |
assert(!b.discarded() || markAll); |
| 298 |
b.copies+=a.copies+parseExtraCopies(a); |
| 299 |
dupePairs++; |
| 300 |
dupeReads+=1+a.mateCount(); |
| 301 |
} |
| 302 |
} |
| 303 |
}else{ |
| 304 |
unequals++; |
| 305 |
} |
| 306 |
} |
| 307 |
} |
| 308 |
} |
| 309 |
} |
| 310 |
if(dupeReads>0){ |
| 311 |
for(int i=0; i<size; i++){ |
| 312 |
Read a=get(i); |
| 313 |
if(a.discarded()){ |
| 314 |
if(mark){ |
| 315 |
if(!a.id.endsWith(" duplicate")){ |
| 316 |
a.id+=" duplicate"; |
| 317 |
if(a.mate!=null){a.mate.id+=" duplicate";} |
| 318 |
} |
| 319 |
}else{ |
| 320 |
set(i, null); |
| 321 |
} |
| 322 |
}else if(rename && a.copies>1){ |
| 323 |
renameFromCount(a); |
| 324 |
} |
| 325 |
a.copies=1; |
| 326 |
} |
| 327 |
if(!mark){ |
| 328 |
int x=Tools.condenseStrict(this); |
| 329 |
assert(x==dupePairs) : size()+", "+size+", "+dupePairs+", "+x; |
| 330 |
assert((size()>0 || markAll) && size()==size-dupePairs) : size()+", "+size+", "+dupePairs; |
| 331 |
} |
| 332 |
} |
| 333 |
|
| 334 |
if(containment){ |
| 335 |
dupeReads+=removeDuplicates_backwards(maxSubs, subRate, scanLimit, maxDiscarded, optical, xySorted, mark, markAll, rename, dist); |
| 336 |
} |
| 337 |
|
| 338 |
return dupeReads; |
| 339 |
} |
| 340 |
|
| 341 |
|
| 342 |
private int removeDuplicates_backwards(final int maxSubs, final float subRate, final int scanLimit, final int maxDiscarded, |
| 343 |
final boolean optical, final boolean xySorted, final boolean mark, final boolean markAll, final boolean rename, final float dist){ |
| 344 |
final int size=size(); |
| 345 |
if(size<2){return 0;} |
| 346 |
int dupePairs=0; |
| 347 |
int dupeReads=0; |
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
for(int i=size-1; i>0; i--){ |
| 354 |
final Read a=get(i); |
| 355 |
if(!a.discarded()){ |
| 356 |
final ReadKey keyA=(ReadKey) a.obj; |
| 357 |
final int aLen=a.length(); |
| 358 |
int unequals=0; |
| 359 |
int discarded=0; |
| 360 |
for(int j=i-1; j>=0 && unequals<=scanLimit && discarded<=maxDiscarded && (!a.discarded() || markAll); j--){ |
| 361 |
final Read b=get(j); |
| 362 |
if(b.discarded()){ |
| 363 |
discarded++; |
| 364 |
}else{ |
| 365 |
final int bLen=b.length(); |
| 366 |
final ReadKey keyB=(ReadKey) b.obj; |
| 367 |
if(!containment && !keyA.equals(keyB)){break;} |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
if(optical && xySorted && !keyA.nearXY(keyB, dist)){break;} |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
if(equals(a, b, maxSubs, subRate)){ |
| 382 |
if(!optical || keyA.near(keyB, dist)){ |
| 383 |
if(printDuplicates){ |
| 384 |
System.out.println(a.toFasta()); |
| 385 |
System.out.println(b.toFasta()); |
| 386 |
} |
| 387 |
float errA=a.expectedErrorsIncludingMate(true); |
| 388 |
float errB=b.expectedErrorsIncludingMate(true); |
| 389 |
if(markAll){ |
| 390 |
b.setDiscarded(true); |
| 391 |
assert(!a.discarded() || markAll); |
| 392 |
dupePairs++; |
| 393 |
dupeReads+=1+b.mateCount(); |
| 394 |
unequals=0; |
| 395 |
if(!a.discarded()){ |
| 396 |
a.setDiscarded(true); |
| 397 |
dupePairs++; |
| 398 |
dupeReads+=1+a.mateCount(); |
| 399 |
} |
| 400 |
}else if(containment || errB>=errA){ |
| 401 |
b.setDiscarded(true); |
| 402 |
assert(!a.discarded() || markAll); |
| 403 |
a.copies+=b.copies+parseExtraCopies(b); |
| 404 |
dupePairs++; |
| 405 |
dupeReads+=1+b.mateCount(); |
| 406 |
unequals=0; |
| 407 |
}else{ |
| 408 |
a.setDiscarded(true); |
| 409 |
assert(!b.discarded() || markAll); |
| 410 |
b.copies+=a.copies+parseExtraCopies(a); |
| 411 |
dupePairs++; |
| 412 |
dupeReads+=1+a.mateCount(); |
| 413 |
} |
| 414 |
} |
| 415 |
}else{ |
| 416 |
unequals++; |
| 417 |
} |
| 418 |
} |
| 419 |
} |
| 420 |
} |
| 421 |
} |
| 422 |
if(dupeReads>0){ |
| 423 |
for(int i=0; i<size; i++){ |
| 424 |
Read a=get(i); |
| 425 |
if(a.discarded()){ |
| 426 |
if(mark){ |
| 427 |
if(!a.id.endsWith(" duplicate")){ |
| 428 |
a.id+=" duplicate"; |
| 429 |
if(a.mate!=null){a.mate.id+=" duplicate";} |
| 430 |
} |
| 431 |
}else{ |
| 432 |
set(i, null); |
| 433 |
} |
| 434 |
}else if(rename && a.copies>1){ |
| 435 |
renameFromCount(a); |
| 436 |
} |
| 437 |
a.copies=1; |
| 438 |
} |
| 439 |
if(!mark){ |
| 440 |
int x=Tools.condenseStrict(this); |
| 441 |
assert(x==dupePairs) : size()+", "+size+", "+dupePairs+", "+x; |
| 442 |
assert((size()>0 || markAll) && size()==size-dupePairs) : size()+", "+size+", "+dupePairs; |
| 443 |
} |
| 444 |
} |
| 445 |
return dupeReads; |
| 446 |
} |
| 447 |
|
| 448 |
public int parseExtraCopies(final Read a){ |
| 449 |
final String id=a.id; |
| 450 |
final int space=id.lastIndexOf(' '); |
| 451 |
int extraCopies=0; |
| 452 |
if(space<0){return 0;} |
| 453 |
if(space>=0 && Tools.contains(id, "copies=", space+1)){ |
| 454 |
extraCopies=Integer.parseInt(id.substring(space+8))-1; |
| 455 |
} |
| 456 |
return extraCopies; |
| 457 |
} |
| 458 |
|
| 459 |
private void renameFromCount(final Read a){ |
| 460 |
final int newExtraCopies=a.copies-1; |
| 461 |
assert(newExtraCopies>0) : newExtraCopies; |
| 462 |
final int oldExtraCopies=parseExtraCopies(a); |
| 463 |
final int total=1+newExtraCopies+oldExtraCopies; |
| 464 |
renameToTotal(a, total); |
| 465 |
if(a.pairnum()==0 && a.mate!=null){ |
| 466 |
assert(a.mate.pairnum()==1); |
| 467 |
renameToTotal(a.mate, total); |
| 468 |
} |
| 469 |
} |
| 470 |
|
| 471 |
private static void renameToTotal(final Read a, final int total){ |
| 472 |
final String id=a.id; |
| 473 |
final int space=id.lastIndexOf(' '); |
| 474 |
if(space>=0 && Tools.contains(id, "copies=", space+1)){ |
| 475 |
a.id=a.id.substring(0, space); |
| 476 |
} |
| 477 |
a.id=a.id+" copies="+total; |
| 478 |
} |
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
public static boolean equals(Read a, Read b, int maxSubs, float dupeSubRate){ |
| 493 |
if(a.numericID==b.numericID){return false;} |
| 494 |
if(dupeSubRate>0){maxSubs=Tools.max(maxSubs, (int)(dupeSubRate*Tools.min(a.length(), b.length())));} |
| 495 |
if(containment){ |
| 496 |
return contains(a, b, maxSubs); |
| 497 |
} |
| 498 |
if(!equals(a.bases, b.bases, maxSubs)){return false;} |
| 499 |
if(a.mate!=null && !equals(a.mate.bases, b.mate.bases, maxSubs)){return false;} |
| 500 |
return true; |
| 501 |
} |
| 502 |
|
| 503 |
public static boolean equals(byte[] a, byte[] b, int maxSubs){ |
| 504 |
if(a==b){return false;} |
| 505 |
if(a==null || b==null){return false;} |
| 506 |
if(a.length!=b.length){return false;} |
| 507 |
int subs=0; |
| 508 |
if(allowNs){ |
| 509 |
for(int i=0; i<a.length; i++){ |
| 510 |
if(a[i]!=b[i] && (a[i]!='N' && b[i]!='N')){ |
| 511 |
subs++; |
| 512 |
if(subs>maxSubs){return false;} |
| 513 |
} |
| 514 |
} |
| 515 |
}else{ |
| 516 |
for(int i=0; i<a.length; i++){ |
| 517 |
if(a[i]!=b[i]){ |
| 518 |
subs++; |
| 519 |
if(subs>maxSubs){return false;} |
| 520 |
} |
| 521 |
} |
| 522 |
} |
| 523 |
return true; |
| 524 |
} |
| 525 |
|
| 526 |
public static boolean contains(Read a, Read b, int maxSubs){ |
| 527 |
if(a.numericID==b.numericID){return false;} |
| 528 |
boolean ok=contains_inner(a, b, maxSubs); |
| 529 |
if(!ok || a.mate==null){return ok;} |
| 530 |
ok=contains_inner(a.mate, b.mate, maxSubs); |
| 531 |
if(!ok){return false;} |
| 532 |
ReadKey rka1=(ReadKey)a.obj; |
| 533 |
ReadKey rkb1=(ReadKey)b.obj; |
| 534 |
ReadKey rka2=(ReadKey)a.mate.obj; |
| 535 |
ReadKey rkb2=(ReadKey)b.mate.obj; |
| 536 |
return ((rka1.kmerMinusStrand==rkb1.kmerMinusStrand) && (rka2.kmerMinusStrand==rkb2.kmerMinusStrand)); |
| 537 |
} |
| 538 |
|
| 539 |
public static boolean contains_inner(Read a, Read b, int maxSubs){ |
| 540 |
|
| 541 |
ReadKey rka=(ReadKey)a.obj; |
| 542 |
ReadKey rkb=(ReadKey)b.obj; |
| 543 |
if(affix ? !rka.physicalAffix(rkb, a.length(), b.length()) : !rka.physicallyContains(rkb, a.length(), b.length())){return false;} |
| 544 |
boolean flipped=false; |
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
if(rka.kmerMinusStrand!=rkb.kmerMinusStrand){ |
| 562 |
rkb.flip(b, k); |
| 563 |
flipped=true; |
| 564 |
} |
| 565 |
boolean ok=contains(a.bases, b.bases, rka.position, rkb.position, maxSubs); |
| 566 |
if(flipped){rkb.flip(b, k);} |
| 567 |
return ok; |
| 568 |
} |
| 569 |
|
| 570 |
public static boolean contains(byte[] a, byte[] b, int posA, int posB, int maxSubs){ |
| 571 |
if(a==null || b==null){return false;} |
| 572 |
assert(a.length>=b.length); |
| 573 |
if(a==b){return false;} |
| 574 |
int subs=0; |
| 575 |
|
| 576 |
int ai, bi; |
| 577 |
final int dif=posA-posB; |
| 578 |
if(dif>0){ |
| 579 |
ai=0; |
| 580 |
bi=-dif; |
| 581 |
}else{ |
| 582 |
ai=dif; |
| 583 |
bi=0; |
| 584 |
} |
| 585 |
|
| 586 |
if(allowNs){ |
| 587 |
for(; ai<a.length && bi<b.length; ai++, bi++){ |
| 588 |
if(ai>=0 && bi>=0){ |
| 589 |
final byte na=a[ai], nb=b[bi]; |
| 590 |
if(na!=nb && na!='N' && nb!='N'){ |
| 591 |
subs++; |
| 592 |
if(subs>maxSubs){return false;} |
| 593 |
} |
| 594 |
} |
| 595 |
} |
| 596 |
}else{ |
| 597 |
for(; ai<a.length && bi<b.length; ai++, bi++){ |
| 598 |
if(ai>=0 && bi>=0 && a[ai]!=b[bi]){ |
| 599 |
subs++; |
| 600 |
if(subs>maxSubs){return false;} |
| 601 |
} |
| 602 |
} |
| 603 |
} |
| 604 |
return true; |
| 605 |
} |
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
public long splitAndErrorCorrect(){ |
| 610 |
if(size()<Splitter.minSizeSplit){ |
| 611 |
return errorCorrect(); |
| 612 |
} |
| 613 |
long sum=0; |
| 614 |
ArrayList<Clump> list=Splitter.splitOnPivot(this); |
| 615 |
for(Clump c : list){ |
| 616 |
sum+=c.errorCorrect(); |
| 617 |
} |
| 618 |
return sum; |
| 619 |
} |
| 620 |
|
| 621 |
public long errorCorrect(){ |
| 622 |
if(size()<=minCountCorrect){return 0;} |
| 623 |
|
| 624 |
Read consen=makeSimpleConsensus(); |
| 625 |
long sum=0; |
| 626 |
final int[] rvector=KillSwitch.allocInt1D(2); |
| 627 |
for(Read r : this){ |
| 628 |
sum+=errorCorrect(r, consen, rvector); |
| 629 |
} |
| 630 |
return sum; |
| 631 |
} |
| 632 |
|
| 633 |
private int errorCorrect(Read call, Read ref, int[] rvector){ |
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
final float identity=identity(call, ref.bases, rvector); |
| 640 |
if((identity<minIdentity && (rvector[1]>0 || rvector[0]<50)) || (identity==1 && !call.containsNocalls())){ |
| 641 |
|
| 642 |
return 0; |
| 643 |
} |
| 644 |
final byte[] cbases=call.bases, cquals=call.quality; |
| 645 |
final byte[] rbases=ref.bases, rquals=ref.quality; |
| 646 |
|
| 647 |
ReadKey key=(ReadKey) call.obj; |
| 648 |
final int pos=key.position; |
| 649 |
|
| 650 |
final int[][] bcounts=baseCounts(); |
| 651 |
final int[][] qcounts=qualityCounts(); |
| 652 |
final float[][] qAvgs=qualityAverages(); |
| 653 |
|
| 654 |
final int minDepth=(int)Tools.max(minCountCorrect, minSizeFractionCorrect*size()); |
| 655 |
|
| 656 |
int corrections=0; |
| 657 |
|
| 658 |
final int cStart=0, rStart=maxLeft-pos, max=cbases.length; |
| 659 |
for(int cloc=cStart, rloc=rStart; cloc<max; cloc++, rloc++){ |
| 660 |
|
| 661 |
final byte cb=cbases[cloc], rb=rbases[rloc]; |
| 662 |
|
| 663 |
final byte cq=(cquals==null ? 20 : cquals[cloc]), rq=rquals[rloc]; |
| 664 |
|
| 665 |
final byte cx=AminoAcid.baseToNumber[cb]; |
| 666 |
|
| 667 |
final byte rx=AminoAcid.baseToNumber[rb]; |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
final byte b, q; |
| 672 |
if(cx<0){ |
| 673 |
b=rb; |
| 674 |
q=(byte)Tools.min(20, rq); |
| 675 |
}else if(cb==rb){ |
| 676 |
b=cb; |
| 677 |
q=(byte)Tools.mid(cq, cq+1, rq); |
| 678 |
assert(q>=cq && (q<=rq || q<=cq)); |
| 679 |
}else{ |
| 680 |
final int cCount=bcounts[cx][rloc]; |
| 681 |
final int rCount=bcounts[rx][rloc]; |
| 682 |
final int altQSum=qcounts[cx][rloc]; |
| 683 |
final int rQSum=qcounts[rx][rloc]; |
| 684 |
final float rQAvg=qAvgs[rx][rloc]; |
| 685 |
if(cCount<=maxCIncorrect && cq<=maxQIncorrect && cq*minQRatio<rQSum && cq*minAQRatio<8+rQAvg){ |
| 686 |
final byte pminor=getSecondHighest(bcounts, rloc); |
| 687 |
|
| 688 |
assert(rx>=0 && rx<bcounts.length) : rx+", "+rloc+", "+bcounts.length+"\n"+call.toFastq()+"\n"+ref.toFastq(); |
| 689 |
assert(rloc>=0 && rloc<bcounts[rx].length) : rx+", "+rloc+", "+bcounts[rloc].length+"\n"+call.toFastq()+"\n"+ref.toFastq(); |
| 690 |
final int minorCount=bcounts[pminor][rloc]; |
| 691 |
|
| 692 |
final long sum=getSumAtPosition(bcounts, rloc); |
| 693 |
|
| 694 |
|
| 695 |
boolean change=false; |
| 696 |
if(rCount>=minCountCorrect && sum>=minDepth){ |
| 697 |
final float ratioNeeded=Tools.min(minRatio, minRatioMult*minorCount+minRatioOffset+minRatioQMult*cq); |
| 698 |
|
| 699 |
if(minorCount*ratioNeeded<=rCount && altQSum*ratioNeeded<=rQSum){ |
| 700 |
change=true; |
| 701 |
} |
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
} |
| 707 |
if(change){ |
| 708 |
corrections++; |
| 709 |
b=rb; |
| 710 |
q=(byte)Tools.min(cq+1, 25, rq); |
| 711 |
|
| 712 |
}else{ |
| 713 |
b=cb; |
| 714 |
q=(byte)Tools.mid(cq, cq-1, 6); |
| 715 |
assert(q<=cq || q>=6) : q+","+cq; |
| 716 |
} |
| 717 |
}else{ |
| 718 |
b=cb; |
| 719 |
q=cq; |
| 720 |
} |
| 721 |
} |
| 722 |
cbases[cloc]=b; |
| 723 |
if(cquals!=null){ |
| 724 |
byte q2=(byte)Tools.mid(q, cq+maxQAdjust, cq-maxQAdjust); |
| 725 |
if(q2==0 && AminoAcid.isFullyDefined(b)){ |
| 726 |
assert(!AminoAcid.isFullyDefined(cb)); |
| 727 |
q2=(byte)Tools.mid(2, 25, (rq+25)/2); |
| 728 |
}else if(!AminoAcid.isFullyDefined(b)){ |
| 729 |
q2=0; |
| 730 |
} |
| 731 |
cquals[cloc]=q2; |
| 732 |
assert((b=='N') == (cquals[cloc]==0)) : "b="+(char)b+", cb="+(char)cb+", rb="+(char)rb+", cx="+cx+", " |
| 733 |
+ "new="+cquals[cloc]+", q="+q+", old="+cq+", rq="+rq+", loc="+rloc+"\n"+call.toFastq()+"\n"+ref.toFastq(); |
| 734 |
} |
| 735 |
} |
| 736 |
return corrections; |
| 737 |
} |
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
public ArrayList<Read> makeConsensus(){ |
| 743 |
if(size()==1){ |
| 744 |
Read r=get(0); |
| 745 |
r.id=r.numericID+" size=1"; |
| 746 |
return this; |
| 747 |
} |
| 748 |
|
| 749 |
ArrayList<Clump> clumps=Splitter.splitOnPivot(this); |
| 750 |
|
| 751 |
ArrayList<Read> list=new ArrayList<Read>(clumps.size()); |
| 752 |
for(Clump c : clumps){ |
| 753 |
Read temp=c.makeSimpleConsensus(); |
| 754 |
list.add(temp); |
| 755 |
} |
| 756 |
return list; |
| 757 |
} |
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
private float identity(Read call, byte[] rbases, int[] rvector){ |
| 762 |
ReadKey key=(ReadKey) call.obj; |
| 763 |
final int pos=key.position; |
| 764 |
byte[] cbases=call.bases, quals=call.quality; |
| 765 |
int good=0, bad=0; |
| 766 |
|
| 767 |
final int cStart=0, rStart=maxLeft-pos, max=cbases.length; |
| 768 |
for(int cloc=cStart, rloc=rStart; cloc<max; cloc++, rloc++){ |
| 769 |
final byte cb=cbases[cloc], rb=rbases[rloc]; |
| 770 |
if(AminoAcid.isFullyDefined(cb) && AminoAcid.isFullyDefined(rb)){ |
| 771 |
if(cb==rb){good++;} |
| 772 |
else{bad++;} |
| 773 |
} |
| 774 |
} |
| 775 |
rvector[0]=good; |
| 776 |
rvector[1]=bad; |
| 777 |
return good==0 ? 0 : good/(float)(good+bad); |
| 778 |
} |
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
long getSumAtPosition(int[][] counts, int pos){ |
| 783 |
long sum=0; |
| 784 |
for(int x=0; x<4; x++){ |
| 785 |
sum+=counts[x][pos]; |
| 786 |
} |
| 787 |
return sum; |
| 788 |
} |
| 789 |
|
| 790 |
byte getConsensusAtPosition(int[][] counts, int pos){ |
| 791 |
byte xMax=0; |
| 792 |
for(byte x=1; x<4; x++){ |
| 793 |
|
| 794 |
if(counts[x][pos]>counts[xMax][pos]){xMax=x;} |
| 795 |
} |
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
return (counts[xMax][pos]>0 ? xMax : -1); |
| 801 |
} |
| 802 |
|
| 803 |
byte getSecondHighest(int[][] counts, int pos){ |
| 804 |
byte first=0; |
| 805 |
byte second=1; |
| 806 |
if(counts[first][pos]<counts[second][pos]){ |
| 807 |
first=1; second=0; |
| 808 |
} |
| 809 |
for(byte x=2; x<4; x++){ |
| 810 |
|
| 811 |
if(counts[x][pos]>counts[first][pos]){ |
| 812 |
second=first; |
| 813 |
first=x; |
| 814 |
}else if(counts[x][pos]>counts[second][pos]){ |
| 815 |
second=x; |
| 816 |
} |
| 817 |
} |
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
return second; |
| 824 |
|
| 825 |
} |
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
public String toStringStaggered(){ |
| 830 |
ByteBuilder sb=new ByteBuilder(); |
| 831 |
for(Read r : this){ |
| 832 |
ReadKey key=(ReadKey) r.obj; |
| 833 |
final int pos=key.position; |
| 834 |
byte[] bases=r.bases, quals=r.quality; |
| 835 |
int rloc=0, cloc=rloc+pos-maxLeft; |
| 836 |
while(cloc<0){sb.append(' '); cloc++;} |
| 837 |
sb.append(bases); |
| 838 |
sb.append('\n'); |
| 839 |
} |
| 840 |
return sb.toString(); |
| 841 |
} |
| 842 |
|
| 843 |
public Read consensusRead(){ |
| 844 |
if(consensusRead==null){ |
| 845 |
consensusRead=makeSimpleConsensus(); |
| 846 |
} |
| 847 |
return consensusRead; |
| 848 |
} |
| 849 |
|
| 850 |
public int width(){ |
| 851 |
assert(width>=0) : width; |
| 852 |
return width; |
| 853 |
} |
| 854 |
|
| 855 |
public int maxLeft(){ |
| 856 |
assert(maxLeft>=0); |
| 857 |
return maxLeft; |
| 858 |
} |
| 859 |
|
| 860 |
public int maxRight(){ |
| 861 |
assert(maxRight>=0); |
| 862 |
return maxRight; |
| 863 |
} |
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
int[][] baseCounts(){ |
| 868 |
if(baseCounts==null){ |
| 869 |
baseCounts=count(false); |
| 870 |
int len=baseCounts[0].length; |
| 871 |
assert(width==-1 || width==len); |
| 872 |
} |
| 873 |
return baseCounts; |
| 874 |
} |
| 875 |
|
| 876 |
int[][] qualityCounts(){ |
| 877 |
if(qualityCounts==null){ |
| 878 |
qualityCounts=count(true); |
| 879 |
int len=qualityCounts[0].length; |
| 880 |
assert(width==-1 || width==len); |
| 881 |
} |
| 882 |
return qualityCounts; |
| 883 |
} |
| 884 |
|
| 885 |
float[][] qualityAverages(){ |
| 886 |
if(qualityAverages==null){ |
| 887 |
qualityAverages=new float[4][width]; |
| 888 |
for(int i=0; i<4; i++){ |
| 889 |
for(int j=0; j<width; j++){ |
| 890 |
int b=baseCounts[i][j]; |
| 891 |
int q=qualityCounts[i][j]; |
| 892 |
qualityAverages[i][j]=(b==0 ? 0 : q/(float)b); |
| 893 |
} |
| 894 |
} |
| 895 |
} |
| 896 |
return qualityAverages; |
| 897 |
} |
| 898 |
|
| 899 |
void clearCounts(){ |
| 900 |
baseCounts=qualityCounts=null; |
| 901 |
qualityAverages=null; |
| 902 |
} |
| 903 |
|
| 904 |
private void clearConsensus(){ |
| 905 |
consensusRead=null; |
| 906 |
} |
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
@Override |
| 911 |
public boolean equals(Object b){ |
| 912 |
return this==b; |
| 913 |
} |
| 914 |
|
| 915 |
@Override |
| 916 |
public int hashCode(){ |
| 917 |
return Long.hashCode(kmer); |
| 918 |
} |
| 919 |
|
| 920 |
@Override |
| 921 |
public int compareTo(Clump o) { |
| 922 |
int x=Long.compare(kmer, o.kmer); |
| 923 |
return x!=0 ? x : o.size()-size(); |
| 924 |
} |
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
public final long kmer; |
| 929 |
|
| 930 |
private int width=-1; |
| 931 |
private int maxLeft=-1; |
| 932 |
private int maxRight=-1; |
| 933 |
|
| 934 |
private int[][] baseCounts; |
| 935 |
private int[][] qualityCounts; |
| 936 |
private float[][] qualityAverages; |
| 937 |
|
| 938 |
private Read consensusRead; |
| 939 |
|
| 940 |
boolean useQuality(){return useQuality;} |
| 941 |
private boolean useQuality=true; |
| 942 |
|
| 943 |
boolean added=false; |
| 944 |
|
| 945 |
public static final int overhead=overhead(); |
| 946 |
private static int overhead(){ |
| 947 |
return 16+ |
| 948 |
16+ |
| 949 |
4+ |
| 950 |
4*(8)+ |
| 951 |
1*(8)+ |
| 952 |
3*(4)+ |
| 953 |
4*(8)+ |
| 954 |
2*(4); |
| 955 |
} |
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
public static boolean parseStatic(String arg, String a, String b){ |
| 960 |
if(a.equals("mincountcorrect") || a.equals("mincc")){ |
| 961 |
minCountCorrect=Integer.parseInt(b); |
| 962 |
}else if(a.equals("minsizesplit") || a.equals("minss")){ |
| 963 |
Splitter.minSizeSplit=Integer.parseInt(b); |
| 964 |
}else if(a.equals("minsizefractionsplit") || a.equals("minsfs")){ |
| 965 |
Splitter.minSizeFractionSplit=Float.parseFloat(b); |
| 966 |
}else if(a.equals("minsizefractioncorrect") || a.equals("minsfc")){ |
| 967 |
minSizeFractionCorrect=Float.parseFloat(b); |
| 968 |
}else if(a.equals("minratio") || a.equals("minr")){ |
| 969 |
minRatio=Float.parseFloat(b); |
| 970 |
}else if(a.equals("minqratio") || a.equals("minqr")){ |
| 971 |
minQRatio=Float.parseFloat(b); |
| 972 |
}else if(a.equals("minaqratio") || a.equals("minaqr")){ |
| 973 |
minAQRatio=Float.parseFloat(b); |
| 974 |
}else if(a.equals("minratiooffset") || a.equals("minro")){ |
| 975 |
minRatioOffset=Float.parseFloat(b); |
| 976 |
}else if(a.equals("minratiomult") || a.equals("minrm")){ |
| 977 |
minRatioMult=Float.parseFloat(b); |
| 978 |
}else if(a.equals("minratioqmult") || a.equals("minrqm")){ |
| 979 |
minRatioQMult=Float.parseFloat(b); |
| 980 |
}else if(a.equals("minidentity") || a.equals("minid")){ |
| 981 |
minIdentity=Float.parseFloat(b); |
| 982 |
}else if(a.equals("maxqadjust")){ |
| 983 |
maxQAdjust=(byte)Integer.parseInt(b); |
| 984 |
}else if(a.equals("maxqi") || a.equals("maxqincorrect") || a.equals("maxqualityincorrect")){ |
| 985 |
maxQIncorrect=Integer.parseInt(b); |
| 986 |
if(maxCIncorrect<0){maxQIncorrect=Integer.MAX_VALUE;} |
| 987 |
}else if(a.equals("maxci") || a.equals("maxcincorrect") || a.equals("maxcountincorrect")){ |
| 988 |
maxCIncorrect=Integer.parseInt(b); |
| 989 |
if(maxCIncorrect<0){maxCIncorrect=Integer.MAX_VALUE;} |
| 990 |
}else if(a.equals("border")){ |
| 991 |
KmerComparator.defaultBorder=Integer.parseInt(b); |
| 992 |
}else if(a.equals("conservative")){ |
| 993 |
conservativeFlag=Parse.parseBoolean(b); |
| 994 |
}else if(a.equals("aggressive")){ |
| 995 |
aggressiveFlag=Parse.parseBoolean(b); |
| 996 |
}else if(a.equals("forceprocess")){ |
| 997 |
forceProcess=Parse.parseBoolean(b); |
| 998 |
}else if(a.equals("mergefirst")){ |
| 999 |
KmerComparator.mergeFirst=Parse.parseBoolean(b); |
| 1000 |
}else if(a.equals("findcorrelations")){ |
| 1001 |
Splitter.FIND_CORRELATIONS=Parse.parseBoolean(b); |
| 1002 |
}else if(a.equals("maxcorrelations")){ |
| 1003 |
Splitter.MAX_CORRELATIONS=Integer.parseInt(b); |
| 1004 |
} |
| 1005 |
|
| 1006 |
else if(a.equals("sortx")){ |
| 1007 |
sortX=Parse.parseBoolean(b); |
| 1008 |
}else if(a.equals("sorty")){ |
| 1009 |
sortY=Parse.parseBoolean(b); |
| 1010 |
}else if(a.equals("sortxy")){ |
| 1011 |
sortX=sortY=Parse.parseBoolean(b); |
| 1012 |
}else if(a.equals("forcesortxy") || a.equals("forcexy")){ |
| 1013 |
forceSortXY=Parse.parseBoolean(b); |
| 1014 |
}else if(a.equals("sortxysize") || a.equals("xysize")){ |
| 1015 |
sortXYSize=Integer.parseInt(b); |
| 1016 |
} |
| 1017 |
|
| 1018 |
else if(a.equals("removeallduplicates") || a.equals("allduplicates")){ |
| 1019 |
markAll=Parse.parseBoolean(b); |
| 1020 |
}else if(a.equals("addcount") || a.equals("renamebycount")){ |
| 1021 |
renameByCount=Parse.parseBoolean(b); |
| 1022 |
}else if(a.equals("optical") || a.equals("opticalonly")){ |
| 1023 |
opticalOnly=Parse.parseBoolean(b); |
| 1024 |
}else if(a.equals("dupesubs") || a.equals("duplicatesubs") || a.equals("dsubs") || a.equals("subs") || a.equals("s")){ |
| 1025 |
maxSubstitutions=Integer.parseInt(b); |
| 1026 |
}else if(a.equals("dupedist") || a.equals("duplicatedistance") || a.equals("ddist") || a.equals("dist") || a.equals("opticaldist") || a.equals("distance")){ |
| 1027 |
try { |
| 1028 |
maxOpticalDistance=Float.parseFloat(b); |
| 1029 |
} catch (NumberFormatException e) { |
| 1030 |
maxOpticalDistance=Parse.parseKMG(b); |
| 1031 |
} |
| 1032 |
opticalOnly=maxOpticalDistance>=0; |
| 1033 |
}else if(a.equals("scanlimit") || a.equals("scan")){ |
| 1034 |
scanLimit=Integer.parseInt(b); |
| 1035 |
}else if(a.equals("allowns")){ |
| 1036 |
allowNs=Parse.parseBoolean(b); |
| 1037 |
}else if(a.equals("containment") || a.equals("absorbcontainment") || a.equals("ac") || a.equals("contains")){ |
| 1038 |
containment=Parse.parseBoolean(b); |
| 1039 |
}else if(a.equals("compareumi") || a.equals("umi")){ |
| 1040 |
compareUMI=FlowcellCoordinate.parseUMI=Parse.parseBoolean(b); |
| 1041 |
}else if(a.equals("umisubs")){ |
| 1042 |
umiSubs=Integer.parseInt(b); |
| 1043 |
}else if(a.equalsIgnoreCase("prefixOrSuffix") || a.equalsIgnoreCase("suffixOrPrefix") || a.equals("affix") || a.equals("pos")){ |
| 1044 |
affix=Parse.parseBoolean(b); |
| 1045 |
}else if(a.equals("printduplicates")){ |
| 1046 |
printDuplicates=Parse.parseBoolean(b); |
| 1047 |
}else if(a.equals("dupeidentity")){ |
| 1048 |
float dupeIdentity=Float.parseFloat(b); |
| 1049 |
if(dupeIdentity>1){dupeIdentity=dupeIdentity/100;} |
| 1050 |
assert(dupeIdentity<=1); |
| 1051 |
dupeSubRate=1-dupeIdentity; |
| 1052 |
}else if(a.equals("dupesubrate") || a.equals("dsr") || a.equals("subrate")){ |
| 1053 |
dupeSubRate=Float.parseFloat(b); |
| 1054 |
if(dupeSubRate>1){dupeSubRate=dupeSubRate/100;} |
| 1055 |
assert(dupeSubRate<=1); |
| 1056 |
} |
| 1057 |
|
| 1058 |
else if(a.equals("minsizesplit")){ |
| 1059 |
Splitter.minSizeSplit=Integer.parseInt(b); |
| 1060 |
}else if(a.equals("minsizefractionsplit")){ |
| 1061 |
Splitter.minSizeFractionSplit=Float.parseFloat(b); |
| 1062 |
}else{ |
| 1063 |
return false; |
| 1064 |
} |
| 1065 |
|
| 1066 |
return true; |
| 1067 |
} |
| 1068 |
|
| 1069 |
static void setConservative(boolean newState){ |
| 1070 |
|
| 1071 |
if(aggressiveFlag){return;} |
| 1072 |
if(newState==conservativeMode){return;} |
| 1073 |
conservativeMode=newState; |
| 1074 |
|
| 1075 |
Splitter.conservative=conservativeMode; |
| 1076 |
|
| 1077 |
if(conservativeMode){ |
| 1078 |
minCountCorrect++; |
| 1079 |
minSizeFractionCorrect*=1.5f; |
| 1080 |
minRatio*=1.25f; |
| 1081 |
minQRatio*=1.5f; |
| 1082 |
minAQRatio*=1.4f; |
| 1083 |
minRatioOffset*=1.25f; |
| 1084 |
minRatioQMult*=1.50f; |
| 1085 |
minRatioMult*=1.4f; |
| 1086 |
minIdentity=1-((1-minIdentity)*0.7f); |
| 1087 |
if(maxQIncorrect==Integer.MAX_VALUE){maxQIncorrect=35;} |
| 1088 |
}else{ |
| 1089 |
minCountCorrect--; |
| 1090 |
minSizeFractionCorrect/=1.5f; |
| 1091 |
minRatio/=1.25f; |
| 1092 |
minQRatio/=1.5f; |
| 1093 |
minAQRatio/=1.4f; |
| 1094 |
minRatioOffset/=1.25f; |
| 1095 |
minRatioQMult/=1.50f; |
| 1096 |
minRatioMult/=1.4f; |
| 1097 |
minIdentity=1-((1-minIdentity)/0.7f); |
| 1098 |
if(maxQIncorrect==35){maxQIncorrect=Integer.MAX_VALUE;} |
| 1099 |
} |
| 1100 |
} |
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
public static void setXY() { |
| 1105 |
if(ReadKey.spanTilesX){sortX=true;} |
| 1106 |
if(ReadKey.spanTilesY){sortY=true;} |
| 1107 |
} |
| 1108 |
|
| 1109 |
static boolean allowNs=true; |
| 1110 |
static boolean markAll=false; |
| 1111 |
static boolean markOnly=false; |
| 1112 |
static boolean opticalOnly=false; |
| 1113 |
static boolean containment=false; |
| 1114 |
static boolean compareUMI=false; |
| 1115 |
static int umiSubs=0; |
| 1116 |
static boolean affix=false; |
| 1117 |
static boolean printDuplicates=false; |
| 1118 |
|
| 1119 |
private static boolean renameByCount=false; |
| 1120 |
private static int scanLimit=5; |
| 1121 |
private static int maxSubstitutions=2; |
| 1122 |
private static float dupeSubRate=0; |
| 1123 |
private static float maxOpticalDistance=40; |
| 1124 |
|
| 1125 |
static boolean forceProcess=false; |
| 1126 |
static boolean conservativeFlag=false; |
| 1127 |
static boolean aggressiveFlag=false; |
| 1128 |
static boolean conservativeMode=false; |
| 1129 |
static boolean renameConsensus=false; |
| 1130 |
static int minCountCorrect=4; |
| 1131 |
static float minSizeFractionCorrect=0.20f; |
| 1132 |
static float minRatio=30.0f; |
| 1133 |
static float minQRatio=2.8f; |
| 1134 |
static float minAQRatio=0.7f; |
| 1135 |
static float minRatioOffset=1.9f; |
| 1136 |
static float minRatioQMult=0.08f; |
| 1137 |
static float minRatioMult=1.80f; |
| 1138 |
static float minIdentity=0.97f; |
| 1139 |
static byte maxQAdjust=0; |
| 1140 |
static int maxQIncorrect=Integer.MAX_VALUE; |
| 1141 |
static int maxCIncorrect=Integer.MAX_VALUE; |
| 1142 |
|
| 1143 |
static boolean sortX=false; |
| 1144 |
static boolean sortY=true; |
| 1145 |
static boolean forceSortXY=false; |
| 1146 |
static int sortXYSize=6; |
| 1147 |
|
| 1148 |
|
| 1149 |
static boolean sortYEarly(){return sortY && (forceSortXY || opticalOnly);} |
| 1150 |
|
| 1151 |
|
| 1152 |
public static int k=31; |
| 1153 |
private static final long serialVersionUID = 1L; |
| 1154 |
|
| 1155 |
} |