| 1 |
package sketch; |
| 2 |
|
| 3 |
import java.util.Comparator; |
| 4 |
|
| 5 |
import aligner.Aligner; |
| 6 |
import prok.GeneCaller; |
| 7 |
import shared.Tools; |
| 8 |
import tax.TaxNode; |
| 9 |
|
| 10 |
public final class Comparison extends SketchObject implements Comparable<Comparison> { |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
public Comparison(CompareBuffer buffer, Sketch a_, Sketch b_){ |
| 25 |
|
| 26 |
a=a_; |
| 27 |
b=b_; |
| 28 |
|
| 29 |
if(buffer!=null){setFrom(buffer);} |
| 30 |
|
| 31 |
if(b!=null){ |
| 32 |
taxName=b.taxName(); |
| 33 |
taxID=b.taxID; |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public void setFrom(CompareBuffer buffer){ |
| 45 |
hits=buffer.hits(); |
| 46 |
multiHits=buffer.multiHits(); |
| 47 |
unique2=buffer.unique2(); |
| 48 |
unique3=buffer.unique3(); |
| 49 |
noHits=buffer.noHits(); |
| 50 |
|
| 51 |
contamHits=buffer.contamHits(); |
| 52 |
contam2Hits=buffer.contam2Hits(); |
| 53 |
multiContamHits=buffer.multiContamHits(); |
| 54 |
|
| 55 |
refDivisor=buffer.refDivisor(); |
| 56 |
queryDivisor=buffer.queryDivisor(); |
| 57 |
|
| 58 |
refSize=buffer.refSize(); |
| 59 |
querySize=buffer.querySize(); |
| 60 |
|
| 61 |
depth=buffer.depth(); |
| 62 |
depth2=buffer.depth2(); |
| 63 |
float x=buffer.avgRefHits(); |
| 64 |
if(x>0){avgRefHits=x;} |
| 65 |
|
| 66 |
score=score0(); |
| 67 |
|
| 68 |
hits1=buffer.hits1(); |
| 69 |
qSeen1=buffer.qSeen1(); |
| 70 |
rSeen1=buffer.rSeen1(); |
| 71 |
} |
| 72 |
|
| 73 |
public void recompare(CompareBuffer buffer, int[][] taxHits, int contamLevel){ |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
assert(a.merged()); |
| 82 |
|
| 83 |
int x=a.countMatches(b, buffer, a.compareBitSet(), false, taxHits, contamLevel); |
| 84 |
assert(x==hits); |
| 85 |
setFrom(buffer); |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
@Override |
| 94 |
public boolean equals(Object b){ |
| 95 |
if(b==null || b.getClass()!=this.getClass()){return false;} |
| 96 |
return scoreComparator.compare(this, (Comparison)b)==0; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
public float idQueryDivisor(){ |
| 116 |
return hits/(float)(Tools.max(1, refDivisor)); |
| 117 |
} |
| 118 |
|
| 119 |
public float idRefDivisor(){ |
| 120 |
return hits/(float)(Tools.max(1, refDivisor)); |
| 121 |
} |
| 122 |
|
| 123 |
public float completeness(){ |
| 124 |
float complt=Tools.min(1, (queryDivisor-contamHits)/(float)Tools.max(1, refDivisor)); |
| 125 |
return complt; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
} |
| 134 |
|
| 135 |
public float contamFraction(){ |
| 136 |
return Tools.min(1, contamHits/(float)Tools.max(1, queryDivisor)); |
| 137 |
} |
| 138 |
|
| 139 |
public float contam2Fraction(){ |
| 140 |
return Tools.min(1, contam2Hits/(float)Tools.max(1, queryDivisor)); |
| 141 |
} |
| 142 |
|
| 143 |
public float uContamFraction() { |
| 144 |
int uContamHits=contamHits-multiContamHits; |
| 145 |
return Tools.min(1, uContamHits/(float)Tools.max(1, queryDivisor)); |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
final float wkid(){ |
| 153 |
final int div=minDivisor(); |
| 154 |
return hits/(float)div; |
| 155 |
} |
| 156 |
final float kid(){ |
| 157 |
final int div=maxDivisor(); |
| 158 |
return hits/(float)div; |
| 159 |
} |
| 160 |
final float aniOld(){ |
| 161 |
float wkid=wkid(); |
| 162 |
|
| 163 |
final float ani=wkidToAni(wkid); |
| 164 |
return ani; |
| 165 |
} |
| 166 |
final float ani(){ |
| 167 |
if(hits<1){return 0;} |
| 168 |
final float ani; |
| 169 |
if(k2>0 && useToValue2){ |
| 170 |
float ani1=ani1(); |
| 171 |
float ani2=ani2(); |
| 172 |
|
| 173 |
ani=0.5f*(Tools.max(0.9f*ani2, ani1)+Tools.max(0.8f*ani1, ani2)); |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
}else{ |
| 181 |
ani=aniOld(); |
| 182 |
} |
| 183 |
return ani; |
| 184 |
} |
| 185 |
|
| 186 |
final float wkid1(){ |
| 187 |
final int div=minDivisor1(); |
| 188 |
return hits1()/(float)div; |
| 189 |
} |
| 190 |
final float kid1(){ |
| 191 |
final int div=maxDivisor1(); |
| 192 |
return hits1()/(float)div; |
| 193 |
} |
| 194 |
final float ani1(){ |
| 195 |
float wkid=wkid1(); |
| 196 |
final float ani=wkidToAniExact(wkid, k); |
| 197 |
return ani; |
| 198 |
} |
| 199 |
|
| 200 |
final float wkid2(){ |
| 201 |
final int div=minDivisor2(); |
| 202 |
return hits2()/(float)div; |
| 203 |
} |
| 204 |
final float kid2(){ |
| 205 |
final int div=maxDivisor2(); |
| 206 |
return hits2()/(float)div; |
| 207 |
} |
| 208 |
final float ani2(){ |
| 209 |
assert(k2>0); |
| 210 |
float wkid=wkid2(); |
| 211 |
final float ani=wkidToAniExact(wkid, k2); |
| 212 |
return ani; |
| 213 |
} |
| 214 |
|
| 215 |
final float aniDual(){ |
| 216 |
assert(k2>0); |
| 217 |
float wkid1=wkid1(); |
| 218 |
float wkid2=wkid2(); |
| 219 |
float ratio=(wkid1/wkid2); |
| 220 |
float exp=1f/(k-k2); |
| 221 |
double ani=Math.pow(ratio, exp); |
| 222 |
double gf=wkid2/Math.pow(ani, k2); |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
return (float)ani; |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
int hits1(){return hits1;} |
| 235 |
int qSeen1(){return qSeen1;} |
| 236 |
int rSeen1(){return rSeen1;} |
| 237 |
int minDivisor1(){return Tools.max(1, Tools.min(qSeen1, rSeen1));} |
| 238 |
int maxDivisor1(){return Tools.max(1, qSeen1, rSeen1);} |
| 239 |
|
| 240 |
int hits2(){return hits-hits1;} |
| 241 |
int qSeen2(){return queryDivisor-qSeen1;} |
| 242 |
int rSeen2(){return refDivisor-rSeen1;} |
| 243 |
int minDivisor2(){return Tools.max(1, Tools.min(qSeen2(), rSeen2()));} |
| 244 |
int maxDivisor2(){return Tools.max(1, qSeen2(), rSeen2());} |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
int minDivisor(){return Tools.max(1, Tools.min(refDivisor, queryDivisor));} |
| 266 |
int maxDivisor(){return Tools.max(1, refDivisor, queryDivisor);} |
| 267 |
|
| 268 |
private float score0_old(){ |
| 269 |
long est=useSizeEstimate ? genomeSizeEstimate() : genomeSizeKmers(); |
| 270 |
float wkid=wkid(); |
| 271 |
float kid=kid(); |
| 272 |
float complt=completeness(); |
| 273 |
float contam=contamFraction(); |
| 274 |
float refHits=Tools.max(avgRefHits, 1f); |
| 275 |
float refHitMult=1f+(0.6f/(float)Math.sqrt(refHits+1)); |
| 276 |
return (float)((Math.log(hits+2)*.25f+0.5f)*(refHitMult*0.2*Math.log(hits+2+(1.2*uHits()+0.25*unique2()+0.1*unique3())) |
| 277 |
*Math.sqrt(40*(20000+hits+uHits())*(wkid*kid*Math.pow(est*complt, 0.2)*(1-contam*0.1)))+0.1)); |
| 278 |
} |
| 279 |
|
| 280 |
private float score0(){ |
| 281 |
final long est=useSizeEstimate ? genomeSizeEstimate() : genomeSizeKmers(); |
| 282 |
final float wkid=wkid(); |
| 283 |
final float kid=kid(); |
| 284 |
final float ani=ani(); |
| 285 |
final float complt=completeness(); |
| 286 |
final float contam=contamFraction(); |
| 287 |
final float refHits=Tools.max(avgRefHits, 1f); |
| 288 |
final float refHitMult=1f+(0.6f/(float)Math.sqrt(refHits+1)); |
| 289 |
final float uhits=uHits(); |
| 290 |
final float uhits2=unique2(); |
| 291 |
final float uhits3=unique3(); |
| 292 |
final float contamMult=(1-contam*0.95f); |
| 293 |
final float estMult=(float)(Math.pow(est, 0.2)*Math.sqrt(complt)); |
| 294 |
final float aniMult=(float)(ani*Math.sqrt(wkid*kid)); |
| 295 |
|
| 296 |
final float hitsSum=1+hits+uhits+0.5f*uhits2+0.25f*uhits3; |
| 297 |
|
| 298 |
final float score=(float)(Math.log(Tools.max(1.2f, hits-1))*hitsSum*refHitMult*contamMult*aniMult*estMult); |
| 299 |
return (float)(8*Math.sqrt(score)); |
| 300 |
} |
| 301 |
|
| 302 |
private long range(){ |
| 303 |
long maxA=a.keys[Tools.max(0, queryDivisor-1)]; |
| 304 |
long maxB=b.keys[Tools.max(0, refDivisor-1)]; |
| 305 |
|
| 306 |
|
| 307 |
return Tools.min(maxA, maxB); |
| 308 |
} |
| 309 |
|
| 310 |
private static double eValue(int hits, int minDiv, int maxDiv, long range){ |
| 311 |
if(hits>=range || maxDiv>=range){return 1.0;} |
| 312 |
double probHit=maxDiv/(double)range; |
| 313 |
|
| 314 |
double eValue=Math.pow(probHit, hits); |
| 315 |
|
| 316 |
|
| 317 |
return eValue; |
| 318 |
} |
| 319 |
|
| 320 |
public double eValue(){ |
| 321 |
double eValue=eValue1()*eValue2(); |
| 322 |
|
| 323 |
return eValue; |
| 324 |
} |
| 325 |
|
| 326 |
public double eValue1(){ |
| 327 |
long range0=range(); |
| 328 |
int missingBits=64-(aminoOrTranslate() ? 5 : 2)*k; |
| 329 |
double quantizer=1.0/(aminoOrTranslate() ? Math.pow(2, missingBits*aaBitValue) : 1L<<missingBits); |
| 330 |
int hits=hits1; |
| 331 |
int minDiv=Tools.min(qSeen1, rSeen1); |
| 332 |
int maxDiv=Tools.max(qSeen1, rSeen1); |
| 333 |
long range=Tools.max((long)Math.ceil(range0*quantizer), maxDiv); |
| 334 |
return eValue(hits, minDiv, maxDiv, range); |
| 335 |
} |
| 336 |
|
| 337 |
public double eValue2(){ |
| 338 |
if(k2<1){return 1.0;} |
| 339 |
|
| 340 |
long range0=range(); |
| 341 |
int missingBits=64-(aminoOrTranslate() ? 5 : 2)*k2; |
| 342 |
double quantizer=1.0/(aminoOrTranslate() ? Math.pow(2, missingBits*aaBitValue) : 1L<<missingBits); |
| 343 |
int hits=hits2(); |
| 344 |
int minDiv=Tools.min(qSeen2(), rSeen2()); |
| 345 |
int maxDiv=Tools.max(qSeen2(), rSeen2()); |
| 346 |
long range=Tools.max((long)Math.ceil(range0*quantizer), maxDiv); |
| 347 |
|
| 348 |
return eValue(hits, minDiv, maxDiv, range); |
| 349 |
} |
| 350 |
|
| 351 |
public String scoreS(){ |
| 352 |
float x=score; |
| 353 |
return format3(x); |
| 354 |
} |
| 355 |
|
| 356 |
public double depth(boolean observedToActual){ |
| 357 |
return observedToActual ? Tools.observedToActualCoverage(depth) : depth; |
| 358 |
} |
| 359 |
|
| 360 |
public double depth2(boolean observedToActual){ |
| 361 |
return observedToActual ? Tools.observedToActualCoverage(depth2) : depth2; |
| 362 |
} |
| 363 |
|
| 364 |
public String depthS(boolean observedToActual){ |
| 365 |
float x=depth; |
| 366 |
if(observedToActual){x=(float)Tools.observedToActualCoverage(x);} |
| 367 |
return format3(x); |
| 368 |
} |
| 369 |
|
| 370 |
public float avgRefHits(){ |
| 371 |
return avgRefHits; |
| 372 |
} |
| 373 |
|
| 374 |
public String avgRefHitsS(){ |
| 375 |
return format2(avgRefHits); |
| 376 |
} |
| 377 |
|
| 378 |
public String depth2S(boolean observedToActual){ |
| 379 |
float x=depth2; |
| 380 |
if(observedToActual){ |
| 381 |
x=(float)(Tools.observedToActualCoverage(depth)*(depth2/depth)); |
| 382 |
} |
| 383 |
return format3(x); |
| 384 |
} |
| 385 |
|
| 386 |
public String volumeS(){ |
| 387 |
double x=volume()*0.001; |
| 388 |
return format3(x); |
| 389 |
} |
| 390 |
|
| 391 |
static String format3(double x){ |
| 392 |
if(x>=999.95){ |
| 393 |
return(""+(long)Math.round(x)); |
| 394 |
}else if(x>=99.995){ |
| 395 |
return Tools.format("%.1f", x); |
| 396 |
}else if(x>=9.9995){ |
| 397 |
return Tools.format("%.2f", x); |
| 398 |
} |
| 399 |
return Tools.format("%.3f", x); |
| 400 |
} |
| 401 |
|
| 402 |
static String format2(double x){ |
| 403 |
if(x>=999.95){ |
| 404 |
return(""+(long)Math.round(x)); |
| 405 |
}else if(x>=99.995){ |
| 406 |
return Tools.format("%.1f", x); |
| 407 |
}else if(x>=9.9995){ |
| 408 |
return Tools.format("%.2f", x); |
| 409 |
} |
| 410 |
return Tools.format("%.2f", x); |
| 411 |
} |
| 412 |
|
| 413 |
float volume(){ |
| 414 |
return Tools.max(1f, depth)*hits; |
| 415 |
} |
| 416 |
|
| 417 |
@Override |
| 418 |
public String toString(){ |
| 419 |
return "hits="+hits+", refDivisor="+refDivisor+", queryDivisor="+queryDivisor+", refSize="+refSize+", querySize="+querySize+ |
| 420 |
", contamHits="+contamHits+", contam2Hits="+contam2Hits+", multiContamHits="+multiContamHits+", depth="+depth+", depth2="+depth2+", volume="+volume()+ |
| 421 |
", hits="+hits+", multiHits="+multiHits+", unique2="+unique2+", unique3="+unique3+", noHits="+noHits+", taxID="+taxID+", taxName="+taxName; |
| 422 |
} |
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
public String name(){return taxName!=null ? taxName : name0()!=null ? name0() : fname()!=null ? fname() : ""+taxID();} |
| 443 |
public String taxName(){return taxName;} |
| 444 |
String name0(){return b.name0();} |
| 445 |
String fname(){return b.fname();} |
| 446 |
|
| 447 |
|
| 448 |
public int taxID(){return (taxID<minFakeID && taxID>=0) ? taxID : -1;} |
| 449 |
long imgID(){return (b.imgID>0 ? b.imgID : -1);} |
| 450 |
|
| 451 |
long genomeSizeBases(){return b.genomeSizeBases;} |
| 452 |
long genomeSizeKmers(){return b.genomeSizeKmers;} |
| 453 |
long genomeSequences(){return b.genomeSequences;} |
| 454 |
long genomeSizeEstimate(){return b.genomeSizeEstimate();} |
| 455 |
float gc(){return b.gc();} |
| 456 |
boolean hasGC(){return b.baseCounts!=null;} |
| 457 |
|
| 458 |
public boolean hasSSU() { |
| 459 |
return (a.r16S()!=null && b.r16S()!=null) || (a.r18S()!=null && b.r18S()!=null); |
| 460 |
} |
| 461 |
public boolean hasSSUIdentity() { |
| 462 |
return ssuIdentity>=0; |
| 463 |
} |
| 464 |
public boolean needsAlignment() { |
| 465 |
return hasSSU() && !hasSSUIdentity(); |
| 466 |
} |
| 467 |
public boolean hasQueryTaxID() { |
| 468 |
return a.taxID>0 && a.taxID<minFakeID; |
| 469 |
} |
| 470 |
|
| 471 |
|
| 472 |
public int uHits() {return hits-multiHits;} |
| 473 |
|
| 474 |
|
| 475 |
public int commonAncestor() { |
| 476 |
if(a.taxID<1 || b.taxID<1){return -1;} |
| 477 |
assert(taxtree!=null); |
| 478 |
int id=taxtree.commonAncestor(a.taxID, b.taxID); |
| 479 |
return id; |
| 480 |
} |
| 481 |
|
| 482 |
|
| 483 |
public String commonAncestorLevel() { |
| 484 |
int id=commonAncestor(); |
| 485 |
if(id<1){return ".";} |
| 486 |
TaxNode tn=taxtree.getNode(id); |
| 487 |
while(!tn.isRanked() && tn.pid!=tn.id){tn=taxtree.getNode(tn.pid);} |
| 488 |
String s=tn.levelStringExtended(false); |
| 489 |
return s; |
| 490 |
} |
| 491 |
|
| 492 |
|
| 493 |
public int commonAncestorLevelInt() { |
| 494 |
int id=commonAncestor(); |
| 495 |
if(id<1){return 0;} |
| 496 |
TaxNode tn=taxtree.getNode(id); |
| 497 |
while(!tn.isRanked() && tn.pid!=tn.id){tn=taxtree.getNode(tn.pid);} |
| 498 |
return tn.levelExtended; |
| 499 |
} |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
static class ScoreComparator implements Comparator<Comparison>{ |
| 508 |
|
| 509 |
@Override |
| 510 |
public int compare(Comparison a, Comparison b) { |
| 511 |
{ |
| 512 |
float pa=a.score, pb=b.score; |
| 513 |
if(pa>pb){ |
| 514 |
return 1; |
| 515 |
}else if (pa<pb){ |
| 516 |
return -1; |
| 517 |
} |
| 518 |
} |
| 519 |
|
| 520 |
int x=a.hits-b.hits; |
| 521 |
if(x!=0){return x;} |
| 522 |
x=b.minDivisor()-a.minDivisor(); |
| 523 |
if(x!=0){return x;} |
| 524 |
x=b.maxDivisor()-a.maxDivisor(); |
| 525 |
if(x!=0){return x;} |
| 526 |
x=b.refDivisor-a.refDivisor; |
| 527 |
if(x!=0){return x;} |
| 528 |
x=a.taxID()-b.taxID(); |
| 529 |
if(x!=0){return x;} |
| 530 |
if(a.name0()!=null && b.name0()!=null){ |
| 531 |
return a.name0().compareTo(b.name0()); |
| 532 |
} |
| 533 |
if(a.taxName()!=null && b.taxName()!=null){ |
| 534 |
return a.taxName().compareTo(b.taxName()); |
| 535 |
} |
| 536 |
return 0; |
| 537 |
} |
| 538 |
|
| 539 |
@Override |
| 540 |
public String toString(){return "sortByScore";} |
| 541 |
|
| 542 |
} |
| 543 |
|
| 544 |
static class DepthComparator implements Comparator<Comparison>{ |
| 545 |
|
| 546 |
@Override |
| 547 |
public int compare(Comparison a, Comparison b) { |
| 548 |
final float da=Tools.max(0.1f, a.depth-0.5f), db=Tools.max(0.1f, b.depth-0.5f); |
| 549 |
final float sa, sb; |
| 550 |
if(sqrt){ |
| 551 |
sa=da*(float)Math.sqrt(a.score); |
| 552 |
sb=db*(float)Math.sqrt(b.score); |
| 553 |
}else{ |
| 554 |
sa=da*a.score; |
| 555 |
sb=db*b.score; |
| 556 |
} |
| 557 |
return sa>sb ? 1 : sa<sb ? -1 : scoreComparator.compare(a, b); |
| 558 |
} |
| 559 |
|
| 560 |
@Override |
| 561 |
public String toString(){return "sortByDepth";} |
| 562 |
|
| 563 |
} |
| 564 |
|
| 565 |
static class Depth2Comparator implements Comparator<Comparison>{ |
| 566 |
|
| 567 |
@Override |
| 568 |
public int compare(Comparison a, Comparison b) { |
| 569 |
final float da=Tools.max(0.1f, a.depth2-0.8f), db=Tools.max(0.1f, b.depth2-0.8f); |
| 570 |
final float sa, sb; |
| 571 |
if(sqrt){ |
| 572 |
sa=da*(float)Math.sqrt(a.score); |
| 573 |
sb=db*(float)Math.sqrt(b.score); |
| 574 |
}else{ |
| 575 |
sa=da*a.score; |
| 576 |
sb=db*b.score; |
| 577 |
} |
| 578 |
return sa>sb ? 1 : sa<sb ? -1 : scoreComparator.compare(a, b); |
| 579 |
} |
| 580 |
|
| 581 |
@Override |
| 582 |
public String toString(){return "sortByDepth2";} |
| 583 |
|
| 584 |
} |
| 585 |
|
| 586 |
static class VolumeComparator implements Comparator<Comparison>{ |
| 587 |
|
| 588 |
@Override |
| 589 |
public int compare(Comparison a, Comparison b) { |
| 590 |
final float da=a.volume(), db=b.volume(); |
| 591 |
final float sa, sb; |
| 592 |
if(sqrt){ |
| 593 |
sa=da*(float)Math.sqrt(a.score); |
| 594 |
sb=db*(float)Math.sqrt(b.score); |
| 595 |
}else{ |
| 596 |
sa=da*a.score; |
| 597 |
sb=db*b.score; |
| 598 |
} |
| 599 |
return sa>sb ? 1 : sa<sb ? -1 : scoreComparator.compare(a, b); |
| 600 |
} |
| 601 |
|
| 602 |
@Override |
| 603 |
public String toString(){return "sortByVolume";} |
| 604 |
|
| 605 |
} |
| 606 |
|
| 607 |
static class KIDComparator implements Comparator<Comparison>{ |
| 608 |
|
| 609 |
@Override |
| 610 |
public int compare(Comparison a, Comparison b) { |
| 611 |
final float sa=a.kid(), sb=b.kid(); |
| 612 |
return sa>sb ? 1 : sa<sb ? -1 : scoreComparator.compare(a, b); |
| 613 |
} |
| 614 |
|
| 615 |
@Override |
| 616 |
public String toString(){return "sortByKID";} |
| 617 |
|
| 618 |
} |
| 619 |
|
| 620 |
static class WKIDComparator implements Comparator<Comparison>{ |
| 621 |
|
| 622 |
@Override |
| 623 |
public int compare(Comparison a, Comparison b) { |
| 624 |
final float sa=a.wkid(), sb=b.wkid(); |
| 625 |
return sa>sb ? 1 : sa<sb ? -1 : scoreComparator.compare(a, b); |
| 626 |
} |
| 627 |
|
| 628 |
@Override |
| 629 |
public String toString(){return "sortByWKID";} |
| 630 |
|
| 631 |
} |
| 632 |
|
| 633 |
static class SSUComparator implements Comparator<Comparison>{ |
| 634 |
|
| 635 |
@Override |
| 636 |
public int compare(Comparison a, Comparison b) { |
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
if(a.hasSSUIdentity() && b.hasSSUIdentity()){ |
| 647 |
final float sa=a.ssuIdentity(), sb=b.ssuIdentity(); |
| 648 |
return sa>sb ? 1 : sa<sb ? -1 : scoreComparator.compare(a, b); |
| 649 |
}else if(a.hasSSUIdentity()){ |
| 650 |
return 1; |
| 651 |
}else if(b.hasSSUIdentity()){ |
| 652 |
return -1; |
| 653 |
}else{ |
| 654 |
return scoreComparator.compare(a, b); |
| 655 |
} |
| 656 |
|
| 657 |
} |
| 658 |
|
| 659 |
@Override |
| 660 |
public String toString(){return "sortBySSU";} |
| 661 |
|
| 662 |
} |
| 663 |
|
| 664 |
static class HitsComparator implements Comparator<Comparison>{ |
| 665 |
|
| 666 |
@Override |
| 667 |
public int compare(Comparison a, Comparison b) { |
| 668 |
final float sa=a.hits(), sb=b.hits(); |
| 669 |
return sa>sb ? 1 : sa<sb ? -1 : scoreComparator.compare(a, b); |
| 670 |
} |
| 671 |
|
| 672 |
@Override |
| 673 |
public String toString(){return "sortByHits";} |
| 674 |
|
| 675 |
} |
| 676 |
|
| 677 |
@Override |
| 678 |
public int compareTo(Comparison b) { |
| 679 |
assert(false) : "Please use comparators instead."; |
| 680 |
return scoreComparator.compare(this, b); |
| 681 |
} |
| 682 |
|
| 683 |
@Override |
| 684 |
public int hashCode() { |
| 685 |
assert(false) : "TODO"; |
| 686 |
return super.hashCode(); |
| 687 |
} |
| 688 |
|
| 689 |
public static final ScoreComparator scoreComparator=new ScoreComparator(); |
| 690 |
public static final DepthComparator depthComparator=new DepthComparator(); |
| 691 |
public static final Depth2Comparator depth2Comparator=new Depth2Comparator(); |
| 692 |
public static final VolumeComparator volumeComparator=new VolumeComparator(); |
| 693 |
public static final KIDComparator KIDComparator=new KIDComparator(); |
| 694 |
public static final SSUComparator SSUComparator=new SSUComparator(); |
| 695 |
public static final WKIDComparator WKIDComparator=new WKIDComparator(); |
| 696 |
public static final HitsComparator HitsComparator=new HitsComparator(); |
| 697 |
private static final boolean sqrt=false; |
| 698 |
private static final double aaBitValue=0.86438561897747246957406388589788; |
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
int hits(){return hits;} |
| 703 |
int multiHits(){return multiHits;} |
| 704 |
int noHits(){return noHits;} |
| 705 |
int unique2(){return unique2;} |
| 706 |
int unique3(){return unique3;} |
| 707 |
|
| 708 |
float depth(){return depth;} |
| 709 |
float depth2(){return depth2;} |
| 710 |
float score(){return score;} |
| 711 |
|
| 712 |
int contamHits(){return contamHits;} |
| 713 |
int contam2Hits(){return contam2Hits;} |
| 714 |
int multiContamHits(){return multiContamHits;} |
| 715 |
|
| 716 |
int queryDivisor(){return queryDivisor;} |
| 717 |
int refDivisor(){return refDivisor;} |
| 718 |
|
| 719 |
int querySize(){return querySize;} |
| 720 |
int refSize(){return refSize;} |
| 721 |
|
| 722 |
int ssuType(){return has18S() ? 18 : has16S() ? 16 : 0;} |
| 723 |
int ssuLen(){return has18S() ? b.r18SLen() : has16S() ? b.r16SLen() : 0;} |
| 724 |
boolean has16S(){return a.r16S()!=null && b.r16S()!=null;} |
| 725 |
boolean has18S(){return a.r18S()!=null && b.r18S()!=null;} |
| 726 |
|
| 727 |
float ssuIdentity(){ |
| 728 |
if(ssuIdentity>0){return ssuIdentity;} |
| 729 |
if(has18S()){ssuIdentity=calcIdentity(a.r18S(), b.r18S());} |
| 730 |
else if(has16S()){ssuIdentity=calcIdentity(a.r16S(), b.r16S());} |
| 731 |
return ssuIdentity; |
| 732 |
} |
| 733 |
|
| 734 |
private static float calcIdentity(byte[] ssuA, byte[] ssuB){ |
| 735 |
|
| 736 |
if(ssuA.length>ssuB.length){ |
| 737 |
byte[] c=ssuA; |
| 738 |
ssuA=ssuB; |
| 739 |
ssuB=c; |
| 740 |
} |
| 741 |
if(useSSA){ |
| 742 |
Aligner ssa=(useSSA3 ? GeneCaller.getSSA3() : GeneCaller.getSSA()); |
| 743 |
int[] max=ssa.fillUnlimited(ssuA, ssuB, 0, ssuB.length-1, 0); |
| 744 |
if(max==null){return 0;} |
| 745 |
|
| 746 |
final int rows=max[0]; |
| 747 |
final int maxCol=max[1]; |
| 748 |
final int maxState=max[2]; |
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
int[] score=ssa.score(ssuA, ssuB, 0, ssuB.length-1, rows, maxCol, maxState); |
| 753 |
int rstart=score[1]; |
| 754 |
int rstop=score[2]; |
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
float id=ssa.tracebackIdentity(ssuA, ssuB, 0, ssuB.length-1, rows, maxCol, maxState, null); |
| 759 |
return id; |
| 760 |
}else{ |
| 761 |
GlocalAligner ga=new GlocalAligner(); |
| 762 |
return ga.alignForward(ssuA, ssuB); |
| 763 |
} |
| 764 |
} |
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
public Sketch a, b; |
| 771 |
|
| 772 |
String taxName; |
| 773 |
int taxID; |
| 774 |
|
| 775 |
private int hits; |
| 776 |
private int multiHits; |
| 777 |
private int unique2; |
| 778 |
private int unique3; |
| 779 |
private int noHits; |
| 780 |
|
| 781 |
private float depth; |
| 782 |
private float depth2; |
| 783 |
private float avgRefHits; |
| 784 |
private float score; |
| 785 |
|
| 786 |
private int contamHits; |
| 787 |
private int contam2Hits; |
| 788 |
private int multiContamHits; |
| 789 |
|
| 790 |
private int refDivisor; |
| 791 |
private int queryDivisor; |
| 792 |
|
| 793 |
private int refSize; |
| 794 |
private int querySize; |
| 795 |
|
| 796 |
private int hits1; |
| 797 |
private int qSeen1; |
| 798 |
private int rSeen1; |
| 799 |
|
| 800 |
private float ssuIdentity=-1; |
| 801 |
|
| 802 |
} |