| 1 |
package align2; |
| 2 |
|
| 3 |
import java.util.Arrays; |
| 4 |
|
| 5 |
import dna.AminoAcid; |
| 6 |
import shared.Tools; |
| 7 |
import stream.SiteScore; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
public final class MultiStateAligner10ts extends MSA{ |
| 16 |
|
| 17 |
|
| 18 |
public static void main(String[] args){ |
| 19 |
byte[] read=args[0].getBytes(); |
| 20 |
byte[] ref=args[1].getBytes(); |
| 21 |
|
| 22 |
byte[] original=ref; |
| 23 |
|
| 24 |
MultiStateAligner10ts msa=new MultiStateAligner10ts(read.length, ref.length); |
| 25 |
|
| 26 |
System.out.println("Initial: "); |
| 27 |
printMatrix(msa.packed, read.length, ref.length, TIMEMASK, SCOREOFFSET); |
| 28 |
|
| 29 |
int[] max=msa.fillLimited(read, ref, 0, ref.length-1, 0, null); |
| 30 |
|
| 31 |
System.out.println("Max: "+Arrays.toString(max)); |
| 32 |
|
| 33 |
System.out.println("Final: "); |
| 34 |
printMatrix(msa.packed, read.length, ref.length, TIMEMASK, SCOREOFFSET); |
| 35 |
|
| 36 |
byte[] out=msa.traceback(read, ref, 0, ref.length-1, max[0], max[1], max[2], false); |
| 37 |
|
| 38 |
int[] score=null; |
| 39 |
score=msa.score(read, ref, 0, ref.length-1, max[0], max[1], max[2], false); |
| 40 |
|
| 41 |
System.out.println(new String(ref)); |
| 42 |
System.out.println(new String(read)); |
| 43 |
System.out.println(new String(out)); |
| 44 |
System.out.println("Score: "+Arrays.toString(score)); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
public MultiStateAligner10ts(int maxRows_, int maxColumns_){ |
| 49 |
super(maxRows_, maxColumns_); |
| 50 |
|
| 51 |
packed=new int[3][maxRows+1][maxColumns+1]; |
| 52 |
bpacked=new int[3][maxRows+1][]; |
| 53 |
startmatrix=new int[3][maxRows+1][]; |
| 54 |
grefbuffer=new byte[maxColumns+2]; |
| 55 |
col0score=new int[maxRows+1]; |
| 56 |
|
| 57 |
vertLimit=new int[maxRows+1]; |
| 58 |
horizLimit=new int[maxColumns+1]; |
| 59 |
Arrays.fill(vertLimit, BADoff); |
| 60 |
Arrays.fill(horizLimit, BADoff); |
| 61 |
|
| 62 |
for(int matrix=0; matrix<packed.length; matrix++){ |
| 63 |
for(int i=1; i<=maxRows; i++){ |
| 64 |
for(int j=0; j<packed[matrix][i].length; j++){ |
| 65 |
packed[matrix][i][j]|=BADoff; |
| 66 |
} |
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
for(int i=0; i<=maxRows; i++){ |
| 73 |
|
| 74 |
int prevScore=(i<2 ? 0 : packed[matrix][i-1][0]); |
| 75 |
int score=(i<2 ? (i*POINTSoff_INS) : |
| 76 |
(i<LIMIT_FOR_COST_3 ? prevScore+POINTSoff_INS2 : |
| 77 |
(i<LIMIT_FOR_COST_4 ? prevScore+POINTSoff_INS3 : prevScore+POINTSoff_INS4))); |
| 78 |
|
| 79 |
packed[matrix][i][0]=score; |
| 80 |
} |
| 81 |
|
| 82 |
for(int i=0; i<3; i++){ |
| 83 |
bpacked[matrix][i]=packed[matrix][i]; |
| 84 |
startmatrix[matrix][i]=new int[maxColumns+1]; |
| 85 |
Arrays.fill(startmatrix[matrix][i], -1); |
| 86 |
} |
| 87 |
|
| 88 |
for(int i=3; i<bpacked[matrix].length; i++){ |
| 89 |
bpacked[matrix][i]=bpacked[matrix][i-2]; |
| 90 |
startmatrix[matrix][i]=startmatrix[matrix][i-2]; |
| 91 |
} |
| 92 |
|
| 93 |
for(int i=0; i<startmatrix[matrix][0].length; i++){ |
| 94 |
startmatrix[matrix][0][i]=i; |
| 95 |
} |
| 96 |
} |
| 97 |
for(int i=0; i<packed[0].length; i++){ |
| 98 |
col0score[i]=packed[0][i][0]; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
@Override |
| 106 |
public final int[] fillLimited(byte[] read, byte[] ref, int refStartLoc, int refEndLoc, int minScore, int[] gaps){ |
| 107 |
if(gaps==null){return fillLimitedX(read, ref, refStartLoc, refEndLoc, minScore);} |
| 108 |
else{ |
| 109 |
byte[] gref=makeGref(ref, gaps, refStartLoc, refEndLoc); |
| 110 |
|
| 111 |
if(verbose && greflimit>0 && greflimit<500){ |
| 112 |
System.err.println(new String(gref, 0, greflimit)); |
| 113 |
} |
| 114 |
|
| 115 |
assert(gref!=null) : "Excessively long read:\n"+new String(read); |
| 116 |
return fillLimitedX(read, gref, 0, greflimit, minScore); |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
private final int[] fillLimitedX(byte[] read, byte[] ref, int refStartLoc, int refEndLoc, int minScore){ |
| 124 |
if(verbose){System.err.println("fillLimitedX");} |
| 125 |
if(bandwidth>0 && bandwidth<read.length){return fillBanded1(read, ref, refStartLoc, refEndLoc, minScore);} |
| 126 |
|
| 127 |
|
| 128 |
rows=read.length; |
| 129 |
columns=refEndLoc-refStartLoc+1; |
| 130 |
|
| 131 |
if(false || minScore<=0 || columns>read.length+Tools.min(170, read.length+20)){ |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
return fillUnlimited(read, ref, refStartLoc, refEndLoc); |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
final int BARRIER_I2=rows-BARRIER_I1, BARRIER_I2b=columns-1; |
| 140 |
final int BARRIER_D2=rows-BARRIER_D1; |
| 141 |
|
| 142 |
minScore-=MIN_SCORE_ADJUST; |
| 143 |
|
| 144 |
assert(rows<=maxRows) : "Check that values are in-bounds before calling this function: "+rows+", "+maxRows+"\n"+ |
| 145 |
refStartLoc+", "+refEndLoc+", "+rows+", "+maxRows+", "+columns+", "+maxColumns+"\n"+new String(read)+"\n"; |
| 146 |
assert(columns<=maxColumns) : "Check that values are in-bounds before calling this function: "+columns+", "+maxColumns+"\n"+ |
| 147 |
refStartLoc+", "+refEndLoc+", "+rows+", "+maxRows+", "+columns+", "+maxColumns+"\n"+new String(read)+"\n"; |
| 148 |
|
| 149 |
assert(refStartLoc>=0) : "Check that values are in-bounds before calling this function: "+refStartLoc+"\n"+ |
| 150 |
refStartLoc+", "+refEndLoc+", "+rows+", "+maxRows+", "+columns+", "+maxColumns+"\n"+new String(read)+"\n"; |
| 151 |
assert(refEndLoc<ref.length) : "Check that values are in-bounds before calling this function: "+refEndLoc+", "+ref.length+"\n"+ |
| 152 |
refStartLoc+", "+refEndLoc+", "+rows+", "+maxRows+", "+columns+", "+maxColumns+"\n"+new String(read)+"\n"; |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
for(int x=0; x<packed.length; x++){ |
| 160 |
|
| 161 |
|
| 162 |
Arrays.fill(packed[x][rows], 1, columns+1, BADoff); |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
} |
| 167 |
|
| 168 |
int minGoodCol=1; |
| 169 |
int maxGoodCol=columns; |
| 170 |
|
| 171 |
final int minScore_off=(minScore<<SCOREOFFSET); |
| 172 |
final int maxGain=(read.length-1)*POINTSoff_MATCH2+POINTSoff_MATCH; |
| 173 |
final int floor=minScore_off-maxGain; |
| 174 |
|
| 175 |
final int subfloor=floor-5*POINTSoff_MATCH2; |
| 176 |
assert(subfloor>BADoff); |
| 177 |
assert(subfloor<minScore_off) : minScore_off+", "+floor+", "+BADoff+", "+subfloor; |
| 178 |
|
| 179 |
if(verbose2){ |
| 180 |
System.out.println(); |
| 181 |
System.out.println("minScore="+minScore+"\t"+minScore_off); |
| 182 |
System.out.println("maxGain="+(maxGain>>SCOREOFFSET)+"\t"+(maxGain)); |
| 183 |
System.out.println("floor="+(floor>>SCOREOFFSET)+"\t"+(floor)); |
| 184 |
System.out.println("subfloor="+(subfloor>>SCOREOFFSET)+"\t"+(subfloor)); |
| 185 |
System.out.println("BADoff="+(BADoff>>SCOREOFFSET)+"\t"+(BADoff)); |
| 186 |
System.out.println("maxGain="+(maxGain>>SCOREOFFSET)+"\t"+(maxGain)); |
| 187 |
System.out.println(); |
| 188 |
} |
| 189 |
|
| 190 |
vertLimit[rows]=minScore_off; |
| 191 |
boolean prevDefined=false; |
| 192 |
for(int i=rows-1; i>=0; i--){ |
| 193 |
byte c=read[i]; |
| 194 |
if(AminoAcid.isFullyDefined(c)){ |
| 195 |
vertLimit[i]=Tools.max(vertLimit[i+1]-(prevDefined ? POINTSoff_MATCH2 : POINTSoff_MATCH), floor); |
| 196 |
prevDefined=true; |
| 197 |
}else{ |
| 198 |
vertLimit[i]=Tools.max(vertLimit[i+1]-POINTSoff_NOCALL, floor); |
| 199 |
prevDefined=false; |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
horizLimit[columns]=minScore_off; |
| 204 |
prevDefined=false; |
| 205 |
for(int i=columns-1; i>=0; i--){ |
| 206 |
byte c=ref[refStartLoc+i]; |
| 207 |
if(AminoAcid.isFullyDefined(c)){ |
| 208 |
horizLimit[i]=Tools.max(horizLimit[i+1]-(prevDefined ? POINTSoff_MATCH2 : POINTSoff_MATCH), floor); |
| 209 |
prevDefined=true; |
| 210 |
}else{ |
| 211 |
horizLimit[i]=Tools.max(horizLimit[i+1]-(prevDefined && c==GAPC ? POINTSoff_DEL : POINTSoff_NOREF), floor); |
| 212 |
prevDefined=false; |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
for(int row=1; row<=rows; row++){ |
| 227 |
|
| 228 |
int colStart=minGoodCol; |
| 229 |
int colStop=maxGoodCol; |
| 230 |
|
| 231 |
minGoodCol=-1; |
| 232 |
maxGoodCol=-2; |
| 233 |
|
| 234 |
final int vlimit=vertLimit[row]; |
| 235 |
|
| 236 |
if(verbose2){ |
| 237 |
System.out.println(); |
| 238 |
System.out.println("row="+row); |
| 239 |
System.out.println("colStart="+colStart); |
| 240 |
System.out.println("colStop="+colStop); |
| 241 |
System.out.println("vlimit="+(vlimit>>SCOREOFFSET)+"\t"+(vlimit)); |
| 242 |
} |
| 243 |
|
| 244 |
if(colStart<0 || colStop<colStart){break;} |
| 245 |
|
| 246 |
|
| 247 |
if(colStart>1){ |
| 248 |
assert(row>0); |
| 249 |
packed[MODE_MS][row][colStart-1]=subfloor; |
| 250 |
packed[MODE_INS][row][colStart-1]=subfloor; |
| 251 |
packed[MODE_DEL][row][colStart-1]=subfloor; |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
for(int col=colStart; col<=columns; col++){ |
| 256 |
|
| 257 |
|
| 258 |
if(verbose2){ |
| 259 |
System.out.println("\ncol "+col); |
| 260 |
} |
| 261 |
|
| 262 |
final byte call0=(row<2 ? (byte)'?' : read[row-2]); |
| 263 |
final byte call1=read[row-1]; |
| 264 |
final byte ref0=(col<2 ? (byte)'!' : ref[refStartLoc+col-2]); |
| 265 |
final byte ref1=ref[refStartLoc+col-1]; |
| 266 |
|
| 267 |
final boolean gap=(ref1==GAPC); |
| 268 |
assert(call1!=GAPC); |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
final boolean match=(call1==ref1 && ref1!='N'); |
| 273 |
final boolean prevMatch=(call0==ref0 && ref0!='N'); |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
iterationsLimited++; |
| 278 |
final int limit=Tools.max(vlimit, horizLimit[col]); |
| 279 |
final int limit3=Tools.max(floor, (match ? limit-POINTSoff_MATCH2 : limit-POINTSoff_SUB3)); |
| 280 |
|
| 281 |
final int delNeeded=Tools.max(0, row-col-1); |
| 282 |
final int insNeeded=Tools.max(0, (rows-row)-(columns-col)-1); |
| 283 |
|
| 284 |
final int delPenalty=calcDelScoreOffset(delNeeded); |
| 285 |
final int insPenalty=calcInsScoreOffset(insNeeded); |
| 286 |
|
| 287 |
|
| 288 |
final int scoreFromDiag_MS=packed[MODE_MS][row-1][col-1]&SCOREMASK; |
| 289 |
final int scoreFromDel_MS=packed[MODE_DEL][row-1][col-1]&SCOREMASK; |
| 290 |
final int scoreFromIns_MS=packed[MODE_INS][row-1][col-1]&SCOREMASK; |
| 291 |
|
| 292 |
final int scoreFromDiag_DEL=packed[MODE_MS][row][col-1]&SCOREMASK; |
| 293 |
final int scoreFromDel_DEL=packed[MODE_DEL][row][col-1]&SCOREMASK; |
| 294 |
|
| 295 |
final int scoreFromDiag_INS=packed[MODE_MS][row-1][col]&SCOREMASK; |
| 296 |
final int scoreFromIns_INS=packed[MODE_INS][row-1][col]&SCOREMASK; |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
if(gap || (scoreFromDiag_MS<=limit3 && scoreFromDel_MS<=limit3 && scoreFromIns_MS<=limit3)){ |
| 304 |
packed[MODE_MS][row][col]=subfloor; |
| 305 |
}else{ |
| 306 |
final int streak=(packed[MODE_MS][row-1][col-1]&TIMEMASK); |
| 307 |
|
| 308 |
{ |
| 309 |
|
| 310 |
int score; |
| 311 |
int time; |
| 312 |
byte prevState; |
| 313 |
|
| 314 |
if(match){ |
| 315 |
|
| 316 |
int scoreMS=scoreFromDiag_MS+(prevMatch ? POINTSoff_MATCH2 : POINTSoff_MATCH); |
| 317 |
int scoreD=scoreFromDel_MS+POINTSoff_MATCH; |
| 318 |
int scoreI=scoreFromIns_MS+POINTSoff_MATCH; |
| 319 |
|
| 320 |
|
| 321 |
if(scoreMS>=scoreD && scoreMS>=scoreI){ |
| 322 |
score=scoreMS; |
| 323 |
time=(prevMatch ? streak+1 : 1); |
| 324 |
prevState=MODE_MS; |
| 325 |
}else if(scoreD>=scoreI){ |
| 326 |
score=scoreD; |
| 327 |
time=1; |
| 328 |
prevState=MODE_DEL; |
| 329 |
}else{ |
| 330 |
score=scoreI; |
| 331 |
time=1; |
| 332 |
prevState=MODE_INS; |
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
}else{ |
| 345 |
|
| 346 |
int scoreMS; |
| 347 |
if(ref1!='N' && call1!='N'){ |
| 348 |
scoreMS=scoreFromDiag_MS+(prevMatch ? (streak<=1 ? POINTSoff_SUBR : POINTSoff_SUB) : |
| 349 |
(streak==0 ? POINTSoff_SUB : streak<LIMIT_FOR_COST_3 ? POINTSoff_SUB2 : POINTSoff_SUB3)); |
| 350 |
}else{ |
| 351 |
scoreMS=scoreFromDiag_MS+POINTSoff_NOCALL; |
| 352 |
} |
| 353 |
|
| 354 |
int scoreD=scoreFromDel_MS+POINTSoff_SUB; |
| 355 |
int scoreI=scoreFromIns_MS+POINTSoff_SUB; |
| 356 |
|
| 357 |
if(scoreMS>=scoreD && scoreMS>=scoreI){ |
| 358 |
score=scoreMS; |
| 359 |
time=(prevMatch ? 1 : streak+1); |
| 360 |
|
| 361 |
prevState=MODE_MS; |
| 362 |
}else if(scoreD>=scoreI){ |
| 363 |
score=scoreD; |
| 364 |
time=1; |
| 365 |
prevState=MODE_DEL; |
| 366 |
}else{ |
| 367 |
score=scoreI; |
| 368 |
time=1; |
| 369 |
prevState=MODE_INS; |
| 370 |
} |
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
} |
| 381 |
|
| 382 |
final int limit2; |
| 383 |
if(delNeeded>0){ |
| 384 |
limit2=limit-delPenalty; |
| 385 |
}else if(insNeeded>0){ |
| 386 |
limit2=limit-insPenalty; |
| 387 |
}else{ |
| 388 |
limit2=limit; |
| 389 |
} |
| 390 |
assert(limit2>=limit); |
| 391 |
|
| 392 |
if(verbose2){System.err.println("MS: \tlimit2="+(limit2>>SCOREOFFSET)+"\t, score="+(score>>SCOREOFFSET));} |
| 393 |
|
| 394 |
if(score>=limit2){ |
| 395 |
maxGoodCol=col; |
| 396 |
if(minGoodCol<0){minGoodCol=col;} |
| 397 |
}else{ |
| 398 |
score=subfloor; |
| 399 |
} |
| 400 |
|
| 401 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 402 |
assert(score>=MINoff_SCORE || score==BADoff) : "Score overflow - use MSA2 instead"; |
| 403 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 404 |
|
| 405 |
packed[MODE_MS][row][col]=(score|time); |
| 406 |
assert((score&SCOREMASK)==score); |
| 407 |
|
| 408 |
assert((time&TIMEMASK)==time); |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
if((scoreFromDiag_DEL<=limit && scoreFromDel_DEL<=limit) || row<BARRIER_D1 || row>BARRIER_D2){ |
| 413 |
|
| 414 |
packed[MODE_DEL][row][col]=subfloor; |
| 415 |
}else{ |
| 416 |
|
| 417 |
final int streak=packed[MODE_DEL][row][col-1]&TIMEMASK; |
| 418 |
|
| 419 |
int scoreMS=scoreFromDiag_DEL+POINTSoff_DEL; |
| 420 |
int scoreD=scoreFromDel_DEL+(streak==0 ? POINTSoff_DEL : |
| 421 |
streak<LIMIT_FOR_COST_3 ? POINTSoff_DEL2 : |
| 422 |
streak<LIMIT_FOR_COST_4 ? POINTSoff_DEL3 : |
| 423 |
streak<LIMIT_FOR_COST_5 ? POINTSoff_DEL4 : |
| 424 |
((streak&MASK5)==0 ? POINTSoff_DEL5 : 0)); |
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
if(ref1=='N'){ |
| 429 |
scoreMS+=POINTSoff_DEL_REF_N; |
| 430 |
scoreD+=POINTSoff_DEL_REF_N; |
| 431 |
}else if(gap){ |
| 432 |
scoreMS+=POINTSoff_GAP; |
| 433 |
scoreD+=POINTSoff_GAP; |
| 434 |
} |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
int score; |
| 439 |
int time; |
| 440 |
byte prevState; |
| 441 |
if(scoreMS>=scoreD){ |
| 442 |
score=scoreMS; |
| 443 |
time=1; |
| 444 |
prevState=MODE_MS; |
| 445 |
}else{ |
| 446 |
score=scoreD; |
| 447 |
time=streak+1; |
| 448 |
prevState=MODE_DEL; |
| 449 |
} |
| 450 |
|
| 451 |
final int limit2; |
| 452 |
if(insNeeded>0){ |
| 453 |
limit2=limit-insPenalty; |
| 454 |
}else if(delNeeded>0){ |
| 455 |
limit2=limit-calcDelScoreOffset(time+delNeeded)+calcDelScoreOffset(time); |
| 456 |
}else{ |
| 457 |
limit2=limit; |
| 458 |
} |
| 459 |
assert(limit2>=limit); |
| 460 |
if(verbose2){System.err.println("DEL: \tlimit2="+(limit2>>SCOREOFFSET)+"\t, score="+(score>>SCOREOFFSET));} |
| 461 |
|
| 462 |
if(score>=limit2){ |
| 463 |
maxGoodCol=col; |
| 464 |
if(minGoodCol<0){minGoodCol=col;} |
| 465 |
}else{ |
| 466 |
score=subfloor; |
| 467 |
} |
| 468 |
|
| 469 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 470 |
assert(score>=MINoff_SCORE || score==BADoff) : "Score overflow - use MSA2 instead"; |
| 471 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 472 |
|
| 473 |
packed[MODE_DEL][row][col]=(score|time); |
| 474 |
assert((score&SCOREMASK)==score); |
| 475 |
|
| 476 |
assert((time&TIMEMASK)==time); |
| 477 |
} |
| 478 |
|
| 479 |
|
| 480 |
if(gap || (scoreFromDiag_INS<=limit && scoreFromIns_INS<=limit) || (row<BARRIER_I1 && col>1) || (row>BARRIER_I2 && col<BARRIER_I2b)){ |
| 481 |
packed[MODE_INS][row][col]=subfloor; |
| 482 |
}else{ |
| 483 |
|
| 484 |
final int streak=packed[MODE_INS][row-1][col]&TIMEMASK; |
| 485 |
|
| 486 |
int scoreMS=scoreFromDiag_INS+POINTSoff_INS; |
| 487 |
|
| 488 |
int scoreI=scoreFromIns_INS+(streak==0 ? POINTSoff_INS : |
| 489 |
streak<LIMIT_FOR_COST_3 ? POINTSoff_INS2 : |
| 490 |
streak<LIMIT_FOR_COST_4 ? POINTSoff_INS3 : POINTSoff_INS4); |
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
int score; |
| 501 |
int time; |
| 502 |
byte prevState; |
| 503 |
if(scoreMS>=scoreI){ |
| 504 |
score=scoreMS; |
| 505 |
time=1; |
| 506 |
prevState=MODE_MS; |
| 507 |
}else{ |
| 508 |
score=scoreI; |
| 509 |
time=streak+1; |
| 510 |
prevState=MODE_INS; |
| 511 |
} |
| 512 |
|
| 513 |
final int limit2; |
| 514 |
if(delNeeded>0){ |
| 515 |
limit2=limit-delPenalty; |
| 516 |
}else if(insNeeded>0){ |
| 517 |
limit2=limit-calcInsScoreOffset(time+insNeeded)+calcInsScoreOffset(time); |
| 518 |
}else{ |
| 519 |
limit2=limit; |
| 520 |
} |
| 521 |
assert(limit2>=limit); |
| 522 |
|
| 523 |
if(verbose2){System.err.println("INS: \tlimit2="+(limit2>>SCOREOFFSET)+"\t, score="+(score>>SCOREOFFSET));} |
| 524 |
if(score>=limit2){ |
| 525 |
maxGoodCol=col; |
| 526 |
if(minGoodCol<0){minGoodCol=col;} |
| 527 |
}else{ |
| 528 |
score=subfloor; |
| 529 |
} |
| 530 |
|
| 531 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 532 |
assert(score>=MINoff_SCORE || score==BADoff) : "Score overflow - use MSA2 instead"; |
| 533 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 534 |
|
| 535 |
packed[MODE_INS][row][col]=(score|time); |
| 536 |
assert((score&SCOREMASK)==score); |
| 537 |
|
| 538 |
assert((time&TIMEMASK)==time); |
| 539 |
} |
| 540 |
|
| 541 |
|
| 542 |
if(col>=colStop){ |
| 543 |
if(col>colStop && maxGoodCol<col){break;} |
| 544 |
if(row>1){ |
| 545 |
packed[MODE_MS][row-1][col+1]=subfloor; |
| 546 |
packed[MODE_INS][row-1][col+1]=subfloor; |
| 547 |
packed[MODE_DEL][row-1][col+1]=subfloor; |
| 548 |
} |
| 549 |
} |
| 550 |
} |
| 551 |
} |
| 552 |
|
| 553 |
|
| 554 |
int maxCol=-1; |
| 555 |
int maxState=-1; |
| 556 |
int maxScore=Integer.MIN_VALUE; |
| 557 |
|
| 558 |
for(int state=0; state<packed.length; state++){ |
| 559 |
for(int col=1; col<=columns; col++){ |
| 560 |
int x=packed[state][rows][col]&SCOREMASK; |
| 561 |
if(x>maxScore){ |
| 562 |
maxScore=x; |
| 563 |
maxCol=col; |
| 564 |
maxState=state; |
| 565 |
} |
| 566 |
} |
| 567 |
} |
| 568 |
|
| 569 |
assert(maxScore>=BADoff); |
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
if(verbose){ |
| 578 |
System.out.println("Filled matrix."); |
| 579 |
printMatrix(packed, rows, columns, TIMEMASK, SCOREOFFSET); |
| 580 |
} |
| 581 |
if(verbose){System.err.println("maxscore="+(maxScore>>SCOREOFFSET)+", minscore="+(minScore_off>>SCOREOFFSET));} |
| 582 |
|
| 583 |
if(maxScore<minScore_off){ |
| 584 |
return null; |
| 585 |
} |
| 586 |
|
| 587 |
maxScore>>=SCOREOFFSET; |
| 588 |
|
| 589 |
|
| 590 |
return new int[] {rows, maxCol, maxState, maxScore}; |
| 591 |
} |
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
private final int[] fillBanded1(byte[] read, byte[] ref, int refStartLoc, int refEndLoc, int minScore){ |
| 599 |
if(verbose){System.err.println("fillBanded1()");} |
| 600 |
|
| 601 |
|
| 602 |
rows=read.length; |
| 603 |
columns=refEndLoc-refStartLoc+1; |
| 604 |
final int halfband=bandwidth/2; |
| 605 |
|
| 606 |
if(false || minScore<=0 || columns>read.length+Tools.min(170, read.length+20)){ |
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
return fillUnlimited(read, ref, refStartLoc, refEndLoc); |
| 611 |
} |
| 612 |
|
| 613 |
|
| 614 |
final int BARRIER_I2=rows-BARRIER_I1, BARRIER_I2b=columns-1; |
| 615 |
final int BARRIER_D2=rows-BARRIER_D1; |
| 616 |
|
| 617 |
minScore-=MIN_SCORE_ADJUST; |
| 618 |
|
| 619 |
assert(rows<=maxRows) : "Check that values are in-bounds before calling this function: "+rows+", "+maxRows+"\n"+ |
| 620 |
refStartLoc+", "+refEndLoc+", "+rows+", "+maxRows+", "+columns+", "+maxColumns+"\n"+new String(read)+"\n"; |
| 621 |
assert(columns<=maxColumns) : "Check that values are in-bounds before calling this function: "+columns+", "+maxColumns+"\n"+ |
| 622 |
refStartLoc+", "+refEndLoc+", "+rows+", "+maxRows+", "+columns+", "+maxColumns+"\n"+new String(read)+"\n"; |
| 623 |
|
| 624 |
assert(refStartLoc>=0) : "Check that values are in-bounds before calling this function: "+refStartLoc+"\n"+ |
| 625 |
refStartLoc+", "+refEndLoc+", "+rows+", "+maxRows+", "+columns+", "+maxColumns+"\n"+new String(read)+"\n"; |
| 626 |
assert(refEndLoc<ref.length) : "Check that values are in-bounds before calling this function: "+refEndLoc+", "+ref.length+"\n"+ |
| 627 |
refStartLoc+", "+refEndLoc+", "+rows+", "+maxRows+", "+columns+", "+maxColumns+"\n"+new String(read)+"\n"; |
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
for(int x=0; x<packed.length; x++){ |
| 635 |
|
| 636 |
|
| 637 |
Arrays.fill(packed[x][rows], 1, columns+1, BADoff); |
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
} |
| 642 |
|
| 643 |
int minGoodCol=1; |
| 644 |
int maxGoodCol=columns; |
| 645 |
|
| 646 |
final int minScore_off=(minScore<<SCOREOFFSET); |
| 647 |
final int maxGain=(read.length-1)*POINTSoff_MATCH2+POINTSoff_MATCH; |
| 648 |
final int floor=minScore_off-maxGain; |
| 649 |
|
| 650 |
final int subfloor=floor-5*POINTSoff_MATCH2; |
| 651 |
assert(subfloor>BADoff); |
| 652 |
assert(subfloor<minScore_off) : minScore_off+", "+floor+", "+BADoff+", "+subfloor; |
| 653 |
|
| 654 |
if(verbose2){ |
| 655 |
System.out.println(); |
| 656 |
System.out.println("minScore="+minScore+"\t"+minScore_off); |
| 657 |
System.out.println("maxGain="+(maxGain>>SCOREOFFSET)+"\t"+(maxGain)); |
| 658 |
System.out.println("floor="+(floor>>SCOREOFFSET)+"\t"+(floor)); |
| 659 |
System.out.println("subfloor="+(subfloor>>SCOREOFFSET)+"\t"+(subfloor)); |
| 660 |
System.out.println("BADoff="+(BADoff>>SCOREOFFSET)+"\t"+(BADoff)); |
| 661 |
System.out.println("maxGain="+(maxGain>>SCOREOFFSET)+"\t"+(maxGain)); |
| 662 |
System.out.println(); |
| 663 |
} |
| 664 |
|
| 665 |
vertLimit[rows]=minScore_off; |
| 666 |
boolean prevDefined=false; |
| 667 |
for(int i=rows-1; i>=0; i--){ |
| 668 |
byte c=read[i]; |
| 669 |
if(AminoAcid.isFullyDefined(c)){ |
| 670 |
vertLimit[i]=Tools.max(vertLimit[i+1]-(prevDefined ? POINTSoff_MATCH2 : POINTSoff_MATCH), floor); |
| 671 |
prevDefined=true; |
| 672 |
}else{ |
| 673 |
vertLimit[i]=Tools.max(vertLimit[i+1]-POINTSoff_NOCALL, floor); |
| 674 |
prevDefined=false; |
| 675 |
} |
| 676 |
} |
| 677 |
|
| 678 |
horizLimit[columns]=minScore_off; |
| 679 |
prevDefined=false; |
| 680 |
for(int i=columns-1; i>=0; i--){ |
| 681 |
byte c=ref[refStartLoc+i]; |
| 682 |
if(AminoAcid.isFullyDefined(c)){ |
| 683 |
horizLimit[i]=Tools.max(horizLimit[i+1]-(prevDefined ? POINTSoff_MATCH2 : POINTSoff_MATCH), floor); |
| 684 |
prevDefined=true; |
| 685 |
}else{ |
| 686 |
horizLimit[i]=Tools.max(horizLimit[i+1]-(prevDefined && c==GAPC ? POINTSoff_DEL : POINTSoff_NOREF), floor); |
| 687 |
prevDefined=false; |
| 688 |
} |
| 689 |
} |
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
for(int row=1; row<=rows; row++){ |
| 702 |
|
| 703 |
int colStart=Tools.max(minGoodCol, row-halfband); |
| 704 |
int colStop=Tools.min(maxGoodCol, row+halfband); |
| 705 |
|
| 706 |
minGoodCol=-1; |
| 707 |
maxGoodCol=-2; |
| 708 |
|
| 709 |
final int vlimit=vertLimit[row]; |
| 710 |
|
| 711 |
if(verbose2){ |
| 712 |
System.out.println(); |
| 713 |
System.out.println("row="+row); |
| 714 |
System.out.println("colStart="+colStart); |
| 715 |
System.out.println("colStop="+colStop); |
| 716 |
System.out.println("vlimit="+(vlimit>>SCOREOFFSET)+"\t"+(vlimit)); |
| 717 |
} |
| 718 |
|
| 719 |
if(colStart<0 || colStop<colStart){break;} |
| 720 |
|
| 721 |
|
| 722 |
if(colStart>1){ |
| 723 |
assert(row>0); |
| 724 |
packed[MODE_MS][row][colStart-1]=subfloor; |
| 725 |
packed[MODE_INS][row][colStart-1]=subfloor; |
| 726 |
packed[MODE_DEL][row][colStart-1]=subfloor; |
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
for(int col=colStart; col<=columns; col++){ |
| 731 |
|
| 732 |
|
| 733 |
if(verbose2){ |
| 734 |
System.out.println("\ncol "+col); |
| 735 |
} |
| 736 |
|
| 737 |
final byte call0=(row<2 ? (byte)'?' : read[row-2]); |
| 738 |
final byte call1=read[row-1]; |
| 739 |
final byte ref0=(col<2 ? (byte)'!' : ref[refStartLoc+col-2]); |
| 740 |
final byte ref1=ref[refStartLoc+col-1]; |
| 741 |
|
| 742 |
final boolean gap=(ref1==GAPC); |
| 743 |
assert(call1!=GAPC); |
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
final boolean match=(call1==ref1 && ref1!='N'); |
| 748 |
final boolean prevMatch=(call0==ref0 && ref0!='N'); |
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
iterationsLimited++; |
| 753 |
final int limit=Tools.max(vlimit, horizLimit[col]); |
| 754 |
final int limit3=Tools.max(floor, (match ? limit-POINTSoff_MATCH2 : limit-POINTSoff_SUB3)); |
| 755 |
|
| 756 |
final int delNeeded=Tools.max(0, row-col-1); |
| 757 |
final int insNeeded=Tools.max(0, (rows-row)-(columns-col)-1); |
| 758 |
|
| 759 |
final int delPenalty=calcDelScoreOffset(delNeeded); |
| 760 |
final int insPenalty=calcInsScoreOffset(insNeeded); |
| 761 |
|
| 762 |
|
| 763 |
final int scoreFromDiag_MS=packed[MODE_MS][row-1][col-1]&SCOREMASK; |
| 764 |
final int scoreFromDel_MS=packed[MODE_DEL][row-1][col-1]&SCOREMASK; |
| 765 |
final int scoreFromIns_MS=packed[MODE_INS][row-1][col-1]&SCOREMASK; |
| 766 |
|
| 767 |
final int scoreFromDiag_DEL=packed[MODE_MS][row][col-1]&SCOREMASK; |
| 768 |
final int scoreFromDel_DEL=packed[MODE_DEL][row][col-1]&SCOREMASK; |
| 769 |
|
| 770 |
final int scoreFromDiag_INS=packed[MODE_MS][row-1][col]&SCOREMASK; |
| 771 |
final int scoreFromIns_INS=packed[MODE_INS][row-1][col]&SCOREMASK; |
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
if(gap || (scoreFromDiag_MS<=limit3 && scoreFromDel_MS<=limit3 && scoreFromIns_MS<=limit3)){ |
| 779 |
packed[MODE_MS][row][col]=subfloor; |
| 780 |
}else{ |
| 781 |
final int streak=(packed[MODE_MS][row-1][col-1]&TIMEMASK); |
| 782 |
|
| 783 |
{ |
| 784 |
|
| 785 |
int score; |
| 786 |
int time; |
| 787 |
byte prevState; |
| 788 |
|
| 789 |
if(match){ |
| 790 |
|
| 791 |
int scoreMS=scoreFromDiag_MS+(prevMatch ? POINTSoff_MATCH2 : POINTSoff_MATCH); |
| 792 |
int scoreD=scoreFromDel_MS+POINTSoff_MATCH; |
| 793 |
int scoreI=scoreFromIns_MS+POINTSoff_MATCH; |
| 794 |
|
| 795 |
|
| 796 |
if(scoreMS>=scoreD && scoreMS>=scoreI){ |
| 797 |
score=scoreMS; |
| 798 |
time=(prevMatch ? streak+1 : 1); |
| 799 |
prevState=MODE_MS; |
| 800 |
}else if(scoreD>=scoreI){ |
| 801 |
score=scoreD; |
| 802 |
time=1; |
| 803 |
prevState=MODE_DEL; |
| 804 |
}else{ |
| 805 |
score=scoreI; |
| 806 |
time=1; |
| 807 |
prevState=MODE_INS; |
| 808 |
} |
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
}else{ |
| 820 |
|
| 821 |
int scoreMS; |
| 822 |
if(ref1!='N' && call1!='N'){ |
| 823 |
scoreMS=scoreFromDiag_MS+(prevMatch ? (streak<=1 ? POINTSoff_SUBR : POINTSoff_SUB) : |
| 824 |
(streak==0 ? POINTSoff_SUB : streak<LIMIT_FOR_COST_3 ? POINTSoff_SUB2 : POINTSoff_SUB3)); |
| 825 |
}else{ |
| 826 |
scoreMS=scoreFromDiag_MS+POINTSoff_NOCALL; |
| 827 |
} |
| 828 |
|
| 829 |
int scoreD=scoreFromDel_MS+POINTSoff_SUB; |
| 830 |
int scoreI=scoreFromIns_MS+POINTSoff_SUB; |
| 831 |
|
| 832 |
if(scoreMS>=scoreD && scoreMS>=scoreI){ |
| 833 |
score=scoreMS; |
| 834 |
time=(prevMatch ? 1 : streak+1); |
| 835 |
|
| 836 |
prevState=MODE_MS; |
| 837 |
}else if(scoreD>=scoreI){ |
| 838 |
score=scoreD; |
| 839 |
time=1; |
| 840 |
prevState=MODE_DEL; |
| 841 |
}else{ |
| 842 |
score=scoreI; |
| 843 |
time=1; |
| 844 |
prevState=MODE_INS; |
| 845 |
} |
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
} |
| 856 |
|
| 857 |
final int limit2; |
| 858 |
if(delNeeded>0){ |
| 859 |
limit2=limit-delPenalty; |
| 860 |
}else if(insNeeded>0){ |
| 861 |
limit2=limit-insPenalty; |
| 862 |
}else{ |
| 863 |
limit2=limit; |
| 864 |
} |
| 865 |
assert(limit2>=limit); |
| 866 |
|
| 867 |
if(verbose2){System.err.println("MS: \tlimit2="+(limit2>>SCOREOFFSET)+"\t, score="+(score>>SCOREOFFSET));} |
| 868 |
|
| 869 |
if(score>=limit2){ |
| 870 |
maxGoodCol=col; |
| 871 |
if(minGoodCol<0){minGoodCol=col;} |
| 872 |
}else{ |
| 873 |
score=subfloor; |
| 874 |
} |
| 875 |
|
| 876 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 877 |
assert(score>=MINoff_SCORE || score==BADoff) : "Score overflow - use MSA2 instead"; |
| 878 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 879 |
|
| 880 |
packed[MODE_MS][row][col]=(score|time); |
| 881 |
assert((score&SCOREMASK)==score); |
| 882 |
|
| 883 |
assert((time&TIMEMASK)==time); |
| 884 |
} |
| 885 |
} |
| 886 |
|
| 887 |
if((scoreFromDiag_DEL<=limit && scoreFromDel_DEL<=limit) || row<BARRIER_D1 || row>BARRIER_D2){ |
| 888 |
|
| 889 |
packed[MODE_DEL][row][col]=subfloor; |
| 890 |
}else{ |
| 891 |
|
| 892 |
final int streak=packed[MODE_DEL][row][col-1]&TIMEMASK; |
| 893 |
|
| 894 |
int scoreMS=scoreFromDiag_DEL+POINTSoff_DEL; |
| 895 |
int scoreD=scoreFromDel_DEL+(streak==0 ? POINTSoff_DEL : |
| 896 |
streak<LIMIT_FOR_COST_3 ? POINTSoff_DEL2 : |
| 897 |
streak<LIMIT_FOR_COST_4 ? POINTSoff_DEL3 : |
| 898 |
streak<LIMIT_FOR_COST_5 ? POINTSoff_DEL4 : |
| 899 |
((streak&MASK5)==0 ? POINTSoff_DEL5 : 0)); |
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
if(ref1=='N'){ |
| 904 |
scoreMS+=POINTSoff_DEL_REF_N; |
| 905 |
scoreD+=POINTSoff_DEL_REF_N; |
| 906 |
}else if(gap){ |
| 907 |
scoreMS+=POINTSoff_GAP; |
| 908 |
scoreD+=POINTSoff_GAP; |
| 909 |
} |
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
int score; |
| 914 |
int time; |
| 915 |
byte prevState; |
| 916 |
if(scoreMS>=scoreD){ |
| 917 |
score=scoreMS; |
| 918 |
time=1; |
| 919 |
prevState=MODE_MS; |
| 920 |
}else{ |
| 921 |
score=scoreD; |
| 922 |
time=streak+1; |
| 923 |
prevState=MODE_DEL; |
| 924 |
} |
| 925 |
|
| 926 |
final int limit2; |
| 927 |
if(insNeeded>0){ |
| 928 |
limit2=limit-insPenalty; |
| 929 |
}else if(delNeeded>0){ |
| 930 |
limit2=limit-calcDelScoreOffset(time+delNeeded)+calcDelScoreOffset(time); |
| 931 |
}else{ |
| 932 |
limit2=limit; |
| 933 |
} |
| 934 |
assert(limit2>=limit); |
| 935 |
if(verbose2){System.err.println("DEL: \tlimit2="+(limit2>>SCOREOFFSET)+"\t, score="+(score>>SCOREOFFSET));} |
| 936 |
|
| 937 |
if(score>=limit2){ |
| 938 |
maxGoodCol=col; |
| 939 |
if(minGoodCol<0){minGoodCol=col;} |
| 940 |
}else{ |
| 941 |
score=subfloor; |
| 942 |
} |
| 943 |
|
| 944 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 945 |
assert(score>=MINoff_SCORE || score==BADoff) : "Score overflow - use MSA2 instead"; |
| 946 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 947 |
|
| 948 |
packed[MODE_DEL][row][col]=(score|time); |
| 949 |
assert((score&SCOREMASK)==score); |
| 950 |
|
| 951 |
assert((time&TIMEMASK)==time); |
| 952 |
} |
| 953 |
|
| 954 |
|
| 955 |
if(gap || (scoreFromDiag_INS<=limit && scoreFromIns_INS<=limit) || (row<BARRIER_I1 && col>1) || (row>BARRIER_I2 && col<BARRIER_I2b)){ |
| 956 |
packed[MODE_INS][row][col]=subfloor; |
| 957 |
}else{ |
| 958 |
|
| 959 |
final int streak=packed[MODE_INS][row-1][col]&TIMEMASK; |
| 960 |
|
| 961 |
int scoreMS=scoreFromDiag_INS+POINTSoff_INS; |
| 962 |
|
| 963 |
int scoreI=scoreFromIns_INS+(streak==0 ? POINTSoff_INS : |
| 964 |
streak<LIMIT_FOR_COST_3 ? POINTSoff_INS2 : |
| 965 |
streak<LIMIT_FOR_COST_4 ? POINTSoff_INS3 : POINTSoff_INS4); |
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
int score; |
| 976 |
int time; |
| 977 |
byte prevState; |
| 978 |
if(scoreMS>=scoreI){ |
| 979 |
score=scoreMS; |
| 980 |
time=1; |
| 981 |
prevState=MODE_MS; |
| 982 |
}else{ |
| 983 |
score=scoreI; |
| 984 |
time=streak+1; |
| 985 |
prevState=MODE_INS; |
| 986 |
} |
| 987 |
|
| 988 |
final int limit2; |
| 989 |
if(delNeeded>0){ |
| 990 |
limit2=limit-delPenalty; |
| 991 |
}else if(insNeeded>0){ |
| 992 |
limit2=limit-calcInsScoreOffset(time+insNeeded)+calcInsScoreOffset(time); |
| 993 |
}else{ |
| 994 |
limit2=limit; |
| 995 |
} |
| 996 |
assert(limit2>=limit); |
| 997 |
|
| 998 |
if(verbose2){System.err.println("INS: \tlimit2="+(limit2>>SCOREOFFSET)+"\t, score="+(score>>SCOREOFFSET));} |
| 999 |
if(score>=limit2){ |
| 1000 |
maxGoodCol=col; |
| 1001 |
if(minGoodCol<0){minGoodCol=col;} |
| 1002 |
}else{ |
| 1003 |
score=subfloor; |
| 1004 |
} |
| 1005 |
|
| 1006 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 1007 |
assert(score>=MINoff_SCORE || score==BADoff) : "Score overflow - use MSA2 instead"; |
| 1008 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 1009 |
|
| 1010 |
packed[MODE_INS][row][col]=(score|time); |
| 1011 |
assert((score&SCOREMASK)==score); |
| 1012 |
|
| 1013 |
assert((time&TIMEMASK)==time); |
| 1014 |
} |
| 1015 |
|
| 1016 |
|
| 1017 |
if(col>=colStop){ |
| 1018 |
if(col>colStop && maxGoodCol<col){break;} |
| 1019 |
if(row>1){ |
| 1020 |
packed[MODE_MS][row-1][col+1]=subfloor; |
| 1021 |
packed[MODE_INS][row-1][col+1]=subfloor; |
| 1022 |
packed[MODE_DEL][row-1][col+1]=subfloor; |
| 1023 |
} |
| 1024 |
} |
| 1025 |
} |
| 1026 |
} |
| 1027 |
|
| 1028 |
|
| 1029 |
int maxCol=-1; |
| 1030 |
int maxState=-1; |
| 1031 |
int maxScore=Integer.MIN_VALUE; |
| 1032 |
|
| 1033 |
for(int state=0; state<packed.length; state++){ |
| 1034 |
for(int col=1; col<=columns; col++){ |
| 1035 |
int x=packed[state][rows][col]&SCOREMASK; |
| 1036 |
if(x>maxScore){ |
| 1037 |
maxScore=x; |
| 1038 |
maxCol=col; |
| 1039 |
maxState=state; |
| 1040 |
} |
| 1041 |
} |
| 1042 |
} |
| 1043 |
|
| 1044 |
assert(maxScore>=BADoff); |
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
if(maxScore<minScore_off){ |
| 1052 |
return null; |
| 1053 |
} |
| 1054 |
|
| 1055 |
maxScore>>=SCOREOFFSET; |
| 1056 |
|
| 1057 |
|
| 1058 |
return new int[] {rows, maxCol, maxState, maxScore}; |
| 1059 |
} |
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
private final int[] fillBanded(byte[] read, byte[] ref, int refStartLoc, int refEndLoc, int minScore){ |
| 1065 |
assert(false) : "TODO"; |
| 1066 |
|
| 1067 |
|
| 1068 |
rows=read.length; |
| 1069 |
columns=refEndLoc-refStartLoc+1; |
| 1070 |
|
| 1071 |
final int BARRIER_I2=rows-BARRIER_I1, BARRIER_I2b=columns-1; |
| 1072 |
final int BARRIER_D2=rows-BARRIER_D1; |
| 1073 |
|
| 1074 |
minScore-=MIN_SCORE_ADJUST; |
| 1075 |
|
| 1076 |
assert(rows<=maxRows) : "Check that values are in-bounds before calling this function: "+rows+", "+maxRows+"\n"+ |
| 1077 |
refStartLoc+", "+refEndLoc+", "+rows+", "+maxRows+", "+columns+", "+maxColumns+"\n"+new String(read)+"\n"; |
| 1078 |
assert(columns<=maxColumns) : "Check that values are in-bounds before calling this function: "+columns+", "+maxColumns+"\n"+ |
| 1079 |
refStartLoc+", "+refEndLoc+", "+rows+", "+maxRows+", "+columns+", "+maxColumns+"\n"+new String(read)+"\n"; |
| 1080 |
|
| 1081 |
assert(refStartLoc>=0) : "Check that values are in-bounds before calling this function: "+refStartLoc+"\n"+ |
| 1082 |
refStartLoc+", "+refEndLoc+", "+rows+", "+maxRows+", "+columns+", "+maxColumns+"\n"+new String(read)+"\n"; |
| 1083 |
assert(refEndLoc<ref.length) : "Check that values are in-bounds before calling this function: "+refEndLoc+", "+ref.length+"\n"+ |
| 1084 |
refStartLoc+", "+refEndLoc+", "+rows+", "+maxRows+", "+columns+", "+maxColumns+"\n"+new String(read)+"\n"; |
| 1085 |
|
| 1086 |
for(int x=0; x<packed.length; x++){ |
| 1087 |
|
| 1088 |
|
| 1089 |
Arrays.fill(bpacked[x][rows], 1, columns+1, BADoff); |
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
} |
| 1094 |
|
| 1095 |
int minGoodCol=1; |
| 1096 |
int maxGoodCol=columns; |
| 1097 |
|
| 1098 |
final int minScore_off=(minScore<<SCOREOFFSET); |
| 1099 |
final int maxGain=(read.length-1)*POINTSoff_MATCH2+POINTSoff_MATCH; |
| 1100 |
final int floor=minScore_off-maxGain; |
| 1101 |
|
| 1102 |
final int subfloor=floor-5*POINTSoff_MATCH2; |
| 1103 |
assert(subfloor>BADoff); |
| 1104 |
assert(subfloor<minScore_off) : minScore_off+", "+floor+", "+BADoff+", "+subfloor; |
| 1105 |
|
| 1106 |
if(verbose2){ |
| 1107 |
System.out.println(); |
| 1108 |
System.out.println("minScore="+minScore+"\t"+minScore_off); |
| 1109 |
System.out.println("maxGain="+(maxGain>>SCOREOFFSET)+"\t"+(maxGain)); |
| 1110 |
System.out.println("floor="+(floor>>SCOREOFFSET)+"\t"+(floor)); |
| 1111 |
System.out.println("subfloor="+(subfloor>>SCOREOFFSET)+"\t"+(subfloor)); |
| 1112 |
System.out.println("BADoff="+(BADoff>>SCOREOFFSET)+"\t"+(BADoff)); |
| 1113 |
System.out.println("maxGain="+(maxGain>>SCOREOFFSET)+"\t"+(maxGain)); |
| 1114 |
System.out.println(); |
| 1115 |
} |
| 1116 |
|
| 1117 |
vertLimit[rows]=minScore_off; |
| 1118 |
boolean prevDefined=false; |
| 1119 |
for(int i=rows-1; i>=0; i--){ |
| 1120 |
byte c=read[i]; |
| 1121 |
if(AminoAcid.isFullyDefined(c)){ |
| 1122 |
vertLimit[i]=Tools.max(vertLimit[i+1]-(prevDefined ? POINTSoff_MATCH2 : POINTSoff_MATCH), floor); |
| 1123 |
prevDefined=true; |
| 1124 |
}else{ |
| 1125 |
vertLimit[i]=Tools.max(vertLimit[i+1]-POINTSoff_NOCALL, floor); |
| 1126 |
prevDefined=false; |
| 1127 |
} |
| 1128 |
} |
| 1129 |
|
| 1130 |
horizLimit[columns]=minScore_off; |
| 1131 |
prevDefined=false; |
| 1132 |
for(int i=columns-1; i>=0; i--){ |
| 1133 |
byte c=ref[refStartLoc+i]; |
| 1134 |
if(AminoAcid.isFullyDefined(c)){ |
| 1135 |
horizLimit[i]=Tools.max(horizLimit[i+1]-(prevDefined ? POINTSoff_MATCH2 : POINTSoff_MATCH), floor); |
| 1136 |
prevDefined=true; |
| 1137 |
}else{ |
| 1138 |
horizLimit[i]=Tools.max(horizLimit[i+1]-(prevDefined && c==GAPC ? POINTSoff_DEL : POINTSoff_NOREF), floor); |
| 1139 |
prevDefined=false; |
| 1140 |
} |
| 1141 |
} |
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
for(int row=1; row<=rows; row++){ |
| 1154 |
|
| 1155 |
int colStart=minGoodCol; |
| 1156 |
int colStop=maxGoodCol; |
| 1157 |
|
| 1158 |
minGoodCol=-1; |
| 1159 |
maxGoodCol=-2; |
| 1160 |
|
| 1161 |
final int vlimit=vertLimit[row]; |
| 1162 |
|
| 1163 |
if(verbose2){ |
| 1164 |
System.out.println(); |
| 1165 |
System.out.println("row="+row); |
| 1166 |
System.out.println("colStart="+colStart); |
| 1167 |
System.out.println("colStop="+colStop); |
| 1168 |
System.out.println("vlimit="+(vlimit>>SCOREOFFSET)+"\t"+(vlimit)); |
| 1169 |
} |
| 1170 |
|
| 1171 |
if(colStart<0 || colStop<colStart){break;} |
| 1172 |
|
| 1173 |
|
| 1174 |
if(colStart>1){ |
| 1175 |
assert(row>0); |
| 1176 |
bpacked[MODE_MS][row][colStart-1]=subfloor; |
| 1177 |
bpacked[MODE_INS][row][colStart-1]=subfloor; |
| 1178 |
bpacked[MODE_DEL][row][colStart-1]=subfloor; |
| 1179 |
}else{ |
| 1180 |
bpacked[MODE_MS][row-1][0]=bpacked[MODE_INS][row-1][0]=bpacked[MODE_DEL][row-1][0]=col0score[row-1]; |
| 1181 |
bpacked[MODE_MS][row][0]=bpacked[MODE_INS][row][0]=bpacked[MODE_DEL][row][0]=col0score[row]; |
| 1182 |
} |
| 1183 |
|
| 1184 |
|
| 1185 |
for(int col=colStart; col<=columns; col++){ |
| 1186 |
|
| 1187 |
|
| 1188 |
if(verbose2){ |
| 1189 |
System.out.println("\ncol "+col); |
| 1190 |
} |
| 1191 |
|
| 1192 |
final byte call0=(row<2 ? (byte)'?' : read[row-2]); |
| 1193 |
final byte call1=read[row-1]; |
| 1194 |
final byte ref0=(col<2 ? (byte)'!' : ref[refStartLoc+col-2]); |
| 1195 |
final byte ref1=ref[refStartLoc+col-1]; |
| 1196 |
|
| 1197 |
final boolean gap=(ref1==GAPC); |
| 1198 |
assert(call1!=GAPC); |
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
final boolean match=(call1==ref1 && ref1!='N'); |
| 1203 |
final boolean prevMatch=(call0==ref0 && ref0!='N'); |
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
iterationsLimited++; |
| 1208 |
final int limit=Tools.max(vlimit, horizLimit[col]); |
| 1209 |
final int limit3=Tools.max(floor, (match ? limit-POINTSoff_MATCH2 : limit-POINTSoff_SUB3)); |
| 1210 |
|
| 1211 |
final int delNeeded=Tools.max(0, row-col-1); |
| 1212 |
final int insNeeded=Tools.max(0, (rows-row)-(columns-col)-1); |
| 1213 |
|
| 1214 |
final int delPenalty=calcDelScoreOffset(delNeeded); |
| 1215 |
final int insPenalty=calcInsScoreOffset(insNeeded); |
| 1216 |
|
| 1217 |
|
| 1218 |
final int scoreFromDiag_MS=bpacked[MODE_MS][row-1][col-1]&SCOREMASK; |
| 1219 |
final int scoreFromDel_MS=bpacked[MODE_DEL][row-1][col-1]&SCOREMASK; |
| 1220 |
final int scoreFromIns_MS=bpacked[MODE_INS][row-1][col-1]&SCOREMASK; |
| 1221 |
|
| 1222 |
final int scoreFromDiag_DEL=bpacked[MODE_MS][row][col-1]&SCOREMASK; |
| 1223 |
final int scoreFromDel_DEL=bpacked[MODE_DEL][row][col-1]&SCOREMASK; |
| 1224 |
|
| 1225 |
final int scoreFromDiag_INS=bpacked[MODE_MS][row-1][col]&SCOREMASK; |
| 1226 |
final int scoreFromIns_INS=bpacked[MODE_INS][row-1][col]&SCOREMASK; |
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
if(gap || (scoreFromDiag_MS<=limit3 && scoreFromDel_MS<=limit3 && scoreFromIns_MS<=limit3)){ |
| 1234 |
bpacked[MODE_MS][row][col]=subfloor; |
| 1235 |
startmatrix[MODE_MS][row][col]=-1; |
| 1236 |
}else{ |
| 1237 |
final int streak=(bpacked[MODE_MS][row-1][col-1]&TIMEMASK); |
| 1238 |
|
| 1239 |
{ |
| 1240 |
|
| 1241 |
int score; |
| 1242 |
int time; |
| 1243 |
int start; |
| 1244 |
byte prevState; |
| 1245 |
|
| 1246 |
if(match){ |
| 1247 |
|
| 1248 |
int scoreMS=scoreFromDiag_MS+(prevMatch ? POINTSoff_MATCH2 : POINTSoff_MATCH); |
| 1249 |
int scoreD=scoreFromDel_MS+POINTSoff_MATCH; |
| 1250 |
int scoreI=scoreFromIns_MS+POINTSoff_MATCH; |
| 1251 |
|
| 1252 |
|
| 1253 |
if(scoreMS>=scoreD && scoreMS>=scoreI){ |
| 1254 |
score=scoreMS; |
| 1255 |
time=(prevMatch ? streak+1 : 1); |
| 1256 |
prevState=MODE_MS; |
| 1257 |
}else if(scoreD>=scoreI){ |
| 1258 |
score=scoreD; |
| 1259 |
time=1; |
| 1260 |
prevState=MODE_DEL; |
| 1261 |
}else{ |
| 1262 |
score=scoreI; |
| 1263 |
time=1; |
| 1264 |
prevState=MODE_INS; |
| 1265 |
} |
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
}else{ |
| 1277 |
|
| 1278 |
int scoreMS; |
| 1279 |
if(ref1!='N' && call1!='N'){ |
| 1280 |
scoreMS=scoreFromDiag_MS+(prevMatch ? (streak<=1 ? POINTSoff_SUBR : POINTSoff_SUB) : |
| 1281 |
(streak==0 ? POINTSoff_SUB : streak<LIMIT_FOR_COST_3 ? POINTSoff_SUB2 : POINTSoff_SUB3)); |
| 1282 |
}else{ |
| 1283 |
scoreMS=scoreFromDiag_MS+POINTSoff_NOCALL; |
| 1284 |
} |
| 1285 |
|
| 1286 |
int scoreD=scoreFromDel_MS+POINTSoff_SUB; |
| 1287 |
int scoreI=scoreFromIns_MS+POINTSoff_SUB; |
| 1288 |
|
| 1289 |
if(scoreMS>=scoreD && scoreMS>=scoreI){ |
| 1290 |
score=scoreMS; |
| 1291 |
time=(prevMatch ? 1 : streak+1); |
| 1292 |
|
| 1293 |
prevState=MODE_MS; |
| 1294 |
}else if(scoreD>=scoreI){ |
| 1295 |
score=scoreD; |
| 1296 |
time=1; |
| 1297 |
prevState=MODE_DEL; |
| 1298 |
}else{ |
| 1299 |
score=scoreI; |
| 1300 |
time=1; |
| 1301 |
prevState=MODE_INS; |
| 1302 |
} |
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
} |
| 1313 |
start=startmatrix[prevState][row-1][col-1]; |
| 1314 |
|
| 1315 |
final int limit2; |
| 1316 |
if(delNeeded>0){ |
| 1317 |
limit2=limit-delPenalty; |
| 1318 |
}else if(insNeeded>0){ |
| 1319 |
limit2=limit-insPenalty; |
| 1320 |
}else{ |
| 1321 |
limit2=limit; |
| 1322 |
} |
| 1323 |
assert(limit2>=limit); |
| 1324 |
|
| 1325 |
if(verbose2){System.err.println("MS: \tlimit2="+(limit2>>SCOREOFFSET)+"\t, score="+(score>>SCOREOFFSET));} |
| 1326 |
|
| 1327 |
if(score>=limit2){ |
| 1328 |
maxGoodCol=col; |
| 1329 |
if(minGoodCol<0){minGoodCol=col;} |
| 1330 |
}else{ |
| 1331 |
score=subfloor; |
| 1332 |
} |
| 1333 |
|
| 1334 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 1335 |
assert(score>=MINoff_SCORE || score==BADoff) : "Score overflow - use MSA2 instead"; |
| 1336 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 1337 |
|
| 1338 |
bpacked[MODE_MS][row][col]=(score|time); |
| 1339 |
startmatrix[MODE_MS][row][col]=start; |
| 1340 |
assert((score&SCOREMASK)==score); |
| 1341 |
|
| 1342 |
assert((time&TIMEMASK)==time); |
| 1343 |
} |
| 1344 |
} |
| 1345 |
|
| 1346 |
if((scoreFromDiag_DEL<=limit && scoreFromDel_DEL<=limit) || row<BARRIER_D1 || row>BARRIER_D2){ |
| 1347 |
|
| 1348 |
bpacked[MODE_DEL][row][col]=subfloor; |
| 1349 |
startmatrix[MODE_MS][row][col]=-1; |
| 1350 |
}else{ |
| 1351 |
|
| 1352 |
final int streak=bpacked[MODE_DEL][row][col-1]&TIMEMASK; |
| 1353 |
|
| 1354 |
int scoreMS=scoreFromDiag_DEL+POINTSoff_DEL; |
| 1355 |
int scoreD=scoreFromDel_DEL+(streak==0 ? POINTSoff_DEL : |
| 1356 |
streak<LIMIT_FOR_COST_3 ? POINTSoff_DEL2 : |
| 1357 |
streak<LIMIT_FOR_COST_4 ? POINTSoff_DEL3 : |
| 1358 |
streak<LIMIT_FOR_COST_5 ? POINTSoff_DEL4 : |
| 1359 |
((streak&MASK5)==0 ? POINTSoff_DEL5 : 0)); |
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
if(ref1=='N'){ |
| 1364 |
scoreMS+=POINTSoff_DEL_REF_N; |
| 1365 |
scoreD+=POINTSoff_DEL_REF_N; |
| 1366 |
}else if(gap){ |
| 1367 |
scoreMS+=POINTSoff_GAP; |
| 1368 |
scoreD+=POINTSoff_GAP; |
| 1369 |
} |
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
int score; |
| 1374 |
int time; |
| 1375 |
int start; |
| 1376 |
byte prevState; |
| 1377 |
|
| 1378 |
if(scoreMS>=scoreD){ |
| 1379 |
score=scoreMS; |
| 1380 |
time=1; |
| 1381 |
prevState=MODE_MS; |
| 1382 |
}else{ |
| 1383 |
score=scoreD; |
| 1384 |
time=streak+1; |
| 1385 |
prevState=MODE_DEL; |
| 1386 |
} |
| 1387 |
start=startmatrix[prevState][row][col-1]; |
| 1388 |
|
| 1389 |
final int limit2; |
| 1390 |
if(insNeeded>0){ |
| 1391 |
limit2=limit-insPenalty; |
| 1392 |
}else if(delNeeded>0){ |
| 1393 |
limit2=limit-calcDelScoreOffset(time+delNeeded)+calcDelScoreOffset(time); |
| 1394 |
}else{ |
| 1395 |
limit2=limit; |
| 1396 |
} |
| 1397 |
assert(limit2>=limit); |
| 1398 |
if(verbose2){System.err.println("DEL: \tlimit2="+(limit2>>SCOREOFFSET)+"\t, score="+(score>>SCOREOFFSET));} |
| 1399 |
|
| 1400 |
if(score>=limit2){ |
| 1401 |
maxGoodCol=col; |
| 1402 |
if(minGoodCol<0){minGoodCol=col;} |
| 1403 |
}else{ |
| 1404 |
score=subfloor; |
| 1405 |
} |
| 1406 |
|
| 1407 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 1408 |
assert(score>=MINoff_SCORE || score==BADoff) : "Score overflow - use MSA2 instead"; |
| 1409 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 1410 |
|
| 1411 |
bpacked[MODE_DEL][row][col]=(score|time); |
| 1412 |
startmatrix[MODE_MS][row][col]=start; |
| 1413 |
assert((score&SCOREMASK)==score); |
| 1414 |
|
| 1415 |
assert((time&TIMEMASK)==time); |
| 1416 |
} |
| 1417 |
|
| 1418 |
|
| 1419 |
if(gap || (scoreFromDiag_INS<=limit && scoreFromIns_INS<=limit) || (row<BARRIER_I1 && col>1) || (row>BARRIER_I2 && col<BARRIER_I2b)){ |
| 1420 |
bpacked[MODE_INS][row][col]=subfloor; |
| 1421 |
startmatrix[MODE_MS][row][col]=-1; |
| 1422 |
}else{ |
| 1423 |
|
| 1424 |
final int streak=bpacked[MODE_INS][row-1][col]&TIMEMASK; |
| 1425 |
|
| 1426 |
int scoreMS=scoreFromDiag_INS+POINTSoff_INS; |
| 1427 |
|
| 1428 |
int scoreI=scoreFromIns_INS+(streak==0 ? POINTSoff_INS : |
| 1429 |
streak<LIMIT_FOR_COST_3 ? POINTSoff_INS2 : |
| 1430 |
streak<LIMIT_FOR_COST_4 ? POINTSoff_INS3 : POINTSoff_INS4); |
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
int score; |
| 1441 |
int time; |
| 1442 |
int start; |
| 1443 |
byte prevState; |
| 1444 |
|
| 1445 |
if(scoreMS>=scoreI){ |
| 1446 |
score=scoreMS; |
| 1447 |
time=1; |
| 1448 |
prevState=MODE_MS; |
| 1449 |
}else{ |
| 1450 |
score=scoreI; |
| 1451 |
time=streak+1; |
| 1452 |
prevState=MODE_INS; |
| 1453 |
} |
| 1454 |
start=startmatrix[prevState][row-1][col]; |
| 1455 |
|
| 1456 |
final int limit2; |
| 1457 |
if(delNeeded>0){ |
| 1458 |
limit2=limit-delPenalty; |
| 1459 |
}else if(insNeeded>0){ |
| 1460 |
limit2=limit-calcInsScoreOffset(time+insNeeded)+calcInsScoreOffset(time); |
| 1461 |
}else{ |
| 1462 |
limit2=limit; |
| 1463 |
} |
| 1464 |
assert(limit2>=limit); |
| 1465 |
|
| 1466 |
if(verbose2){System.err.println("INS: \tlimit2="+(limit2>>SCOREOFFSET)+"\t, score="+(score>>SCOREOFFSET));} |
| 1467 |
if(score>=limit2){ |
| 1468 |
maxGoodCol=col; |
| 1469 |
if(minGoodCol<0){minGoodCol=col;} |
| 1470 |
}else{ |
| 1471 |
score=subfloor; |
| 1472 |
} |
| 1473 |
|
| 1474 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 1475 |
assert(score>=MINoff_SCORE || score==BADoff) : "Score overflow - use MSA2 instead"; |
| 1476 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 1477 |
|
| 1478 |
bpacked[MODE_INS][row][col]=(score|time); |
| 1479 |
startmatrix[MODE_MS][row][col]=start; |
| 1480 |
assert((score&SCOREMASK)==score); |
| 1481 |
|
| 1482 |
assert((time&TIMEMASK)==time); |
| 1483 |
} |
| 1484 |
|
| 1485 |
|
| 1486 |
if(col>=colStop){ |
| 1487 |
if(col>colStop && maxGoodCol<col){break;} |
| 1488 |
if(row>1){ |
| 1489 |
bpacked[MODE_MS][row-1][col+1]=subfloor; |
| 1490 |
bpacked[MODE_INS][row-1][col+1]=subfloor; |
| 1491 |
bpacked[MODE_DEL][row-1][col+1]=subfloor; |
| 1492 |
startmatrix[MODE_MS][row-1][col+1]=-1; |
| 1493 |
startmatrix[MODE_INS][row-1][col+1]=-1; |
| 1494 |
startmatrix[MODE_DEL][row-1][col+1]=-1; |
| 1495 |
} |
| 1496 |
} |
| 1497 |
} |
| 1498 |
} |
| 1499 |
|
| 1500 |
|
| 1501 |
int maxCol=-1; |
| 1502 |
int maxState=-1; |
| 1503 |
int maxStart=-1; |
| 1504 |
int maxScore=Integer.MIN_VALUE; |
| 1505 |
|
| 1506 |
for(int state=0; state<packed.length; state++){ |
| 1507 |
for(int col=1; col<=columns; col++){ |
| 1508 |
int x=bpacked[state][rows][col]&SCOREMASK; |
| 1509 |
if(x>maxScore){ |
| 1510 |
maxScore=x; |
| 1511 |
maxStart=startmatrix[state][rows][col]; |
| 1512 |
maxCol=col; |
| 1513 |
maxState=state; |
| 1514 |
} |
| 1515 |
} |
| 1516 |
} |
| 1517 |
|
| 1518 |
assert(maxScore>=BADoff); |
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
if(maxScore<minScore_off){ |
| 1526 |
return null; |
| 1527 |
} |
| 1528 |
|
| 1529 |
maxScore>>=SCOREOFFSET; |
| 1530 |
|
| 1531 |
|
| 1532 |
return new int[] {rows, maxCol, maxState, maxScore, maxStart}; |
| 1533 |
} |
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
@Override |
| 1539 |
public final int[] fillUnlimited(byte[] read, byte[] ref, int refStartLoc, int refEndLoc, int[] gaps){ |
| 1540 |
if(gaps==null){return fillUnlimited(read, ref, refStartLoc, refEndLoc);} |
| 1541 |
else{ |
| 1542 |
byte[] gref=makeGref(ref, gaps, refStartLoc, refEndLoc); |
| 1543 |
assert(gref!=null) : "Excessively long read:\n"+new String(read); |
| 1544 |
return fillUnlimited(read, gref, 0, greflimit); |
| 1545 |
} |
| 1546 |
} |
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
private final int[] fillUnlimited(byte[] read, byte[] ref, int refStartLoc, int refEndLoc){ |
| 1552 |
if(verbose){System.err.println("fillUnlimited()");} |
| 1553 |
rows=read.length; |
| 1554 |
columns=refEndLoc-refStartLoc+1; |
| 1555 |
|
| 1556 |
final int maxGain=(read.length-1)*POINTSoff_MATCH2+POINTSoff_MATCH; |
| 1557 |
final int subfloor=0-2*maxGain; |
| 1558 |
assert(subfloor>BADoff && subfloor*2>BADoff); |
| 1559 |
|
| 1560 |
final int BARRIER_I2=rows-BARRIER_I1, BARRIER_I2b=columns-1; |
| 1561 |
final int BARRIER_D2=rows-BARRIER_D1; |
| 1562 |
|
| 1563 |
|
| 1564 |
if(rows>maxRows || columns>maxColumns){ |
| 1565 |
throw new RuntimeException(); |
| 1566 |
} |
| 1567 |
|
| 1568 |
assert(rows<=maxRows) : "Check that values are in-bounds before calling this function: "+rows+", "+maxRows; |
| 1569 |
assert(columns<=maxColumns) : "Check that values are in-bounds before calling this function: "+columns+", "+maxColumns; |
| 1570 |
|
| 1571 |
assert(refStartLoc>=0) : "Check that values are in-bounds before calling this function: "+refStartLoc; |
| 1572 |
assert(refEndLoc<ref.length) : "Check that values are in-bounds before calling this function: "+refEndLoc+", "+ref.length; |
| 1573 |
|
| 1574 |
for(int row=1; row<=rows; row++){ |
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
for(int col=1; col<=columns; col++){ |
| 1580 |
iterationsUnlimited++; |
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
final byte call0=(row<2 ? (byte)'?' : read[row-2]); |
| 1586 |
final byte call1=read[row-1]; |
| 1587 |
final byte ref0=(col<2 ? (byte)'!' : ref[refStartLoc+col-2]); |
| 1588 |
final byte ref1=ref[refStartLoc+col-1]; |
| 1589 |
|
| 1590 |
final boolean match=(call1==ref1 && ref1!='N'); |
| 1591 |
final boolean prevMatch=(call0==ref0 && ref0!='N'); |
| 1592 |
|
| 1593 |
final boolean gap=(ref1==GAPC); |
| 1594 |
assert(call1!=GAPC); |
| 1595 |
|
| 1596 |
if(gap){ |
| 1597 |
packed[MODE_MS][row][col]=subfloor; |
| 1598 |
}else{ |
| 1599 |
|
| 1600 |
final int scoreFromDiag=packed[MODE_MS][row-1][col-1]&SCOREMASK; |
| 1601 |
final int scoreFromDel=packed[MODE_DEL][row-1][col-1]&SCOREMASK; |
| 1602 |
final int scoreFromIns=packed[MODE_INS][row-1][col-1]&SCOREMASK; |
| 1603 |
final int streak=(packed[MODE_MS][row-1][col-1]&TIMEMASK); |
| 1604 |
|
| 1605 |
{ |
| 1606 |
|
| 1607 |
if(match){ |
| 1608 |
|
| 1609 |
int scoreMS=scoreFromDiag+(prevMatch ? POINTSoff_MATCH2 : POINTSoff_MATCH); |
| 1610 |
int scoreD=scoreFromDel+POINTSoff_MATCH; |
| 1611 |
int scoreI=scoreFromIns+POINTSoff_MATCH; |
| 1612 |
|
| 1613 |
int score; |
| 1614 |
int time; |
| 1615 |
|
| 1616 |
if(scoreMS>=scoreD && scoreMS>=scoreI){ |
| 1617 |
score=scoreMS; |
| 1618 |
time=(prevMatch ? streak+1 : 1); |
| 1619 |
|
| 1620 |
}else if(scoreD>=scoreI){ |
| 1621 |
score=scoreD; |
| 1622 |
time=1; |
| 1623 |
|
| 1624 |
}else{ |
| 1625 |
score=scoreI; |
| 1626 |
time=1; |
| 1627 |
|
| 1628 |
} |
| 1629 |
|
| 1630 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 1631 |
assert(score>=MINoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 1632 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 1633 |
|
| 1634 |
packed[MODE_MS][row][col]=(score|time); |
| 1635 |
assert((score&SCOREMASK)==score); |
| 1636 |
|
| 1637 |
assert((time&TIMEMASK)==time); |
| 1638 |
|
| 1639 |
}else{ |
| 1640 |
|
| 1641 |
int scoreMS; |
| 1642 |
if(ref1!='N' && call1!='N'){ |
| 1643 |
scoreMS=scoreFromDiag+(prevMatch ? (streak<=1 ? POINTSoff_SUBR : POINTSoff_SUB) : |
| 1644 |
(streak==0 ? POINTSoff_SUB : streak<LIMIT_FOR_COST_3 ? POINTSoff_SUB2 : POINTSoff_SUB3)); |
| 1645 |
}else{ |
| 1646 |
scoreMS=scoreFromDiag+POINTSoff_NOCALL; |
| 1647 |
} |
| 1648 |
|
| 1649 |
int scoreD=scoreFromDel+POINTSoff_SUB; |
| 1650 |
int scoreI=scoreFromIns+POINTSoff_SUB; |
| 1651 |
|
| 1652 |
int score; |
| 1653 |
int time; |
| 1654 |
byte prevState; |
| 1655 |
if(scoreMS>=scoreD && scoreMS>=scoreI){ |
| 1656 |
score=scoreMS; |
| 1657 |
time=(prevMatch ? 1 : streak+1); |
| 1658 |
|
| 1659 |
prevState=MODE_MS; |
| 1660 |
}else if(scoreD>=scoreI){ |
| 1661 |
score=scoreD; |
| 1662 |
time=1; |
| 1663 |
prevState=MODE_DEL; |
| 1664 |
}else{ |
| 1665 |
score=scoreI; |
| 1666 |
time=1; |
| 1667 |
prevState=MODE_INS; |
| 1668 |
} |
| 1669 |
|
| 1670 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 1671 |
assert(score>=MINoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 1672 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 1673 |
|
| 1674 |
packed[MODE_MS][row][col]=(score|time); |
| 1675 |
assert((score&SCOREMASK)==score); |
| 1676 |
|
| 1677 |
assert((time&TIMEMASK)==time); |
| 1678 |
} |
| 1679 |
} |
| 1680 |
} |
| 1681 |
|
| 1682 |
if(row<BARRIER_D1 || row>BARRIER_D2){ |
| 1683 |
packed[MODE_DEL][row][col]=subfloor; |
| 1684 |
}else{ |
| 1685 |
|
| 1686 |
final int streak=packed[MODE_DEL][row][col-1]&TIMEMASK; |
| 1687 |
|
| 1688 |
final int scoreFromDiag=packed[MODE_MS][row][col-1]&SCOREMASK; |
| 1689 |
final int scoreFromDel=packed[MODE_DEL][row][col-1]&SCOREMASK; |
| 1690 |
|
| 1691 |
int scoreMS=scoreFromDiag+POINTSoff_DEL; |
| 1692 |
int scoreD=scoreFromDel+(streak==0 ? POINTSoff_DEL : |
| 1693 |
streak<LIMIT_FOR_COST_3 ? POINTSoff_DEL2 : |
| 1694 |
streak<LIMIT_FOR_COST_4 ? POINTSoff_DEL3 : |
| 1695 |
streak<LIMIT_FOR_COST_5 ? POINTSoff_DEL4 : |
| 1696 |
((streak&MASK5)==0 ? POINTSoff_DEL5 : 0)); |
| 1697 |
|
| 1698 |
|
| 1699 |
if(ref1=='N'){ |
| 1700 |
scoreMS+=POINTSoff_DEL_REF_N; |
| 1701 |
scoreD+=POINTSoff_DEL_REF_N; |
| 1702 |
}else if(gap){ |
| 1703 |
scoreMS+=POINTSoff_GAP; |
| 1704 |
scoreD+=POINTSoff_GAP; |
| 1705 |
} |
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
int score; |
| 1710 |
int time; |
| 1711 |
byte prevState; |
| 1712 |
if(scoreMS>=scoreD){ |
| 1713 |
score=scoreMS; |
| 1714 |
time=1; |
| 1715 |
prevState=MODE_MS; |
| 1716 |
}else{ |
| 1717 |
score=scoreD; |
| 1718 |
time=streak+1; |
| 1719 |
prevState=MODE_DEL; |
| 1720 |
} |
| 1721 |
|
| 1722 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 1723 |
assert(score>=MINoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 1724 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 1725 |
|
| 1726 |
packed[MODE_DEL][row][col]=(score|time); |
| 1727 |
assert((score&SCOREMASK)==score); |
| 1728 |
|
| 1729 |
assert((time&TIMEMASK)==time); |
| 1730 |
} |
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
if(gap || (row<BARRIER_I1 && col>1) || (row>BARRIER_I2 && col<BARRIER_I2b)){ |
| 1735 |
packed[MODE_INS][row][col]=subfloor; |
| 1736 |
}else{ |
| 1737 |
|
| 1738 |
final int streak=packed[MODE_INS][row-1][col]&TIMEMASK; |
| 1739 |
|
| 1740 |
final int scoreFromDiag=packed[MODE_MS][row-1][col]&SCOREMASK; |
| 1741 |
final int scoreFromIns=packed[MODE_INS][row-1][col]&SCOREMASK; |
| 1742 |
|
| 1743 |
int scoreMS=scoreFromDiag+POINTSoff_INS; |
| 1744 |
|
| 1745 |
int scoreI=scoreFromIns+(streak==0 ? POINTSoff_INS : |
| 1746 |
streak<LIMIT_FOR_COST_3 ? POINTSoff_INS2 : |
| 1747 |
streak<LIMIT_FOR_COST_4 ? POINTSoff_INS3 : POINTSoff_INS4); |
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
int score; |
| 1757 |
int time; |
| 1758 |
byte prevState; |
| 1759 |
if(scoreMS>=scoreI){ |
| 1760 |
score=scoreMS; |
| 1761 |
time=1; |
| 1762 |
prevState=MODE_MS; |
| 1763 |
}else{ |
| 1764 |
score=scoreI; |
| 1765 |
time=streak+1; |
| 1766 |
prevState=MODE_INS; |
| 1767 |
} |
| 1768 |
|
| 1769 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 1770 |
assert(score>=MINoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 1771 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 1772 |
|
| 1773 |
packed[MODE_INS][row][col]=(score|time); |
| 1774 |
assert((score&SCOREMASK)==score); |
| 1775 |
|
| 1776 |
assert((time&TIMEMASK)==time); |
| 1777 |
} |
| 1778 |
} |
| 1779 |
} |
| 1780 |
|
| 1781 |
|
| 1782 |
int maxCol=-1; |
| 1783 |
int maxState=-1; |
| 1784 |
int maxScore=Integer.MIN_VALUE; |
| 1785 |
|
| 1786 |
for(int state=0; state<packed.length; state++){ |
| 1787 |
for(int col=1; col<=columns; col++){ |
| 1788 |
int x=packed[state][rows][col]&SCOREMASK; |
| 1789 |
if(x>maxScore){ |
| 1790 |
maxScore=x; |
| 1791 |
maxCol=col; |
| 1792 |
maxState=state; |
| 1793 |
} |
| 1794 |
} |
| 1795 |
} |
| 1796 |
maxScore>>=SCOREOFFSET; |
| 1797 |
|
| 1798 |
|
| 1799 |
return new int[] {rows, maxCol, maxState, maxScore}; |
| 1800 |
} |
| 1801 |
|
| 1802 |
@Override |
| 1803 |
@Deprecated |
| 1804 |
|
| 1805 |
public final int[] fillQ(byte[] read, byte[] ref, byte[] baseScores, int refStartLoc, int refEndLoc){ |
| 1806 |
assert(false) : "Needs to be redone to work with score cutoffs. Not difficult."; |
| 1807 |
rows=read.length; |
| 1808 |
columns=refEndLoc-refStartLoc+1; |
| 1809 |
|
| 1810 |
assert(rows<=maxRows) : "Check that values are in-bounds before calling this function: "+rows+", "+maxRows; |
| 1811 |
assert(columns<=maxColumns) : "Check that values are in-bounds before calling this function: "+columns+", "+maxColumns; |
| 1812 |
|
| 1813 |
assert(refStartLoc>=0) : "Check that values are in-bounds before calling this function: "+refStartLoc; |
| 1814 |
assert(refEndLoc<ref.length) : "Check that values are in-bounds before calling this function: "+refEndLoc+", "+ref.length; |
| 1815 |
|
| 1816 |
for(int row=1; row<=rows; row++){ |
| 1817 |
|
| 1818 |
|
| 1819 |
|
| 1820 |
|
| 1821 |
for(int col=1; col<=columns; col++){ |
| 1822 |
|
| 1823 |
final boolean match=(read[row-1]==ref[refStartLoc+col-1]); |
| 1824 |
final boolean prevMatch=(row<2 || col<2 ? false : read[row-2]==ref[refStartLoc+col-2]); |
| 1825 |
|
| 1826 |
{ |
| 1827 |
|
| 1828 |
final int scoreFromDiag=packed[MODE_MS][row-1][col-1]&SCOREMASK; |
| 1829 |
final int scoreFromDel=packed[MODE_DEL][row-1][col-1]&SCOREMASK; |
| 1830 |
final int scoreFromIns=packed[MODE_INS][row-1][col-1]&SCOREMASK; |
| 1831 |
final int streak=(packed[MODE_MS][row-1][col-1]&TIMEMASK); |
| 1832 |
|
| 1833 |
{ |
| 1834 |
|
| 1835 |
if(match){ |
| 1836 |
|
| 1837 |
int scoreMS=scoreFromDiag+(prevMatch ? POINTSoff_MATCH2 : POINTSoff_MATCH); |
| 1838 |
int scoreD=scoreFromDel+POINTSoff_MATCH; |
| 1839 |
int scoreI=scoreFromIns+POINTSoff_MATCH; |
| 1840 |
|
| 1841 |
int score; |
| 1842 |
int time; |
| 1843 |
|
| 1844 |
if(scoreMS>=scoreD && scoreMS>=scoreI){ |
| 1845 |
score=scoreMS; |
| 1846 |
time=(prevMatch ? streak+1 : 1); |
| 1847 |
|
| 1848 |
}else if(scoreD>=scoreI){ |
| 1849 |
score=scoreD; |
| 1850 |
time=1; |
| 1851 |
|
| 1852 |
}else{ |
| 1853 |
score=scoreI; |
| 1854 |
time=1; |
| 1855 |
|
| 1856 |
} |
| 1857 |
score+=(((int)baseScores[row-1])<<SCOREOFFSET); |
| 1858 |
|
| 1859 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 1860 |
assert(score>=MINoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 1861 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 1862 |
|
| 1863 |
packed[MODE_MS][row][col]=(score|time); |
| 1864 |
assert((score&SCOREMASK)==score); |
| 1865 |
|
| 1866 |
assert((time&TIMEMASK)==time); |
| 1867 |
|
| 1868 |
}else{ |
| 1869 |
|
| 1870 |
int scoreMS=scoreFromDiag+(prevMatch ? (streak<=1 ? POINTSoff_SUBR : POINTSoff_SUB) : |
| 1871 |
(streak==0 ? POINTSoff_SUB : streak<LIMIT_FOR_COST_3 ? POINTSoff_SUB2 : POINTSoff_SUB3)); |
| 1872 |
int scoreD=scoreFromDel+POINTSoff_SUB; |
| 1873 |
int scoreI=scoreFromIns+POINTSoff_SUB; |
| 1874 |
|
| 1875 |
int score; |
| 1876 |
int time; |
| 1877 |
byte prevState; |
| 1878 |
if(scoreMS>=scoreD && scoreMS>=scoreI){ |
| 1879 |
score=scoreMS; |
| 1880 |
time=(prevMatch ? 1 : streak+1); |
| 1881 |
|
| 1882 |
prevState=MODE_MS; |
| 1883 |
}else if(scoreD>=scoreI){ |
| 1884 |
score=scoreD; |
| 1885 |
time=1; |
| 1886 |
prevState=MODE_DEL; |
| 1887 |
}else{ |
| 1888 |
score=scoreI; |
| 1889 |
time=1; |
| 1890 |
prevState=MODE_INS; |
| 1891 |
} |
| 1892 |
|
| 1893 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 1894 |
assert(score>=MINoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 1895 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 1896 |
|
| 1897 |
packed[MODE_MS][row][col]=(score|time); |
| 1898 |
assert((score&SCOREMASK)==score); |
| 1899 |
|
| 1900 |
assert((time&TIMEMASK)==time); |
| 1901 |
} |
| 1902 |
} |
| 1903 |
} |
| 1904 |
|
| 1905 |
{ |
| 1906 |
|
| 1907 |
final int streak=packed[MODE_DEL][row][col-1]&TIMEMASK; |
| 1908 |
|
| 1909 |
final int scoreFromDiag=packed[MODE_MS][row][col-1]&SCOREMASK; |
| 1910 |
final int scoreFromDel=packed[MODE_DEL][row][col-1]&SCOREMASK; |
| 1911 |
|
| 1912 |
int scoreMS=scoreFromDiag+POINTSoff_DEL; |
| 1913 |
int scoreD=scoreFromDel+(streak==0 ? POINTSoff_DEL : |
| 1914 |
streak<LIMIT_FOR_COST_3 ? POINTSoff_DEL2 : |
| 1915 |
streak<LIMIT_FOR_COST_4 ? POINTSoff_DEL3 : |
| 1916 |
streak<LIMIT_FOR_COST_5 ? POINTSoff_DEL4 : |
| 1917 |
((streak&MASK5)==0 ? POINTSoff_DEL5 : 0)); |
| 1918 |
|
| 1919 |
|
| 1920 |
int score; |
| 1921 |
int time; |
| 1922 |
byte prevState; |
| 1923 |
if(scoreMS>=scoreD){ |
| 1924 |
score=scoreMS; |
| 1925 |
time=1; |
| 1926 |
prevState=MODE_MS; |
| 1927 |
}else{ |
| 1928 |
score=scoreD; |
| 1929 |
time=streak+1; |
| 1930 |
prevState=MODE_DEL; |
| 1931 |
} |
| 1932 |
|
| 1933 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 1934 |
assert(score>=MINoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 1935 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 1936 |
|
| 1937 |
packed[MODE_DEL][row][col]=(score|time); |
| 1938 |
assert((score&SCOREMASK)==score); |
| 1939 |
|
| 1940 |
assert((time&TIMEMASK)==time); |
| 1941 |
} |
| 1942 |
|
| 1943 |
{ |
| 1944 |
|
| 1945 |
final int streak=packed[MODE_INS][row-1][col]&TIMEMASK; |
| 1946 |
|
| 1947 |
final int scoreFromDiag=packed[MODE_MS][row-1][col]&SCOREMASK; |
| 1948 |
final int scoreFromIns=packed[MODE_INS][row-1][col]&SCOREMASK; |
| 1949 |
|
| 1950 |
int scoreMS=scoreFromDiag+POINTSoff_INS; |
| 1951 |
|
| 1952 |
int scoreI=scoreFromIns+(streak==0 ? POINTSoff_INS : |
| 1953 |
streak<LIMIT_FOR_COST_3 ? POINTSoff_INS2 : |
| 1954 |
streak<LIMIT_FOR_COST_4 ? POINTSoff_INS3 : POINTSoff_INS4); |
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
|
| 1960 |
|
| 1961 |
int score; |
| 1962 |
int time; |
| 1963 |
byte prevState; |
| 1964 |
if(scoreMS>=scoreI){ |
| 1965 |
score=scoreMS; |
| 1966 |
time=1; |
| 1967 |
prevState=MODE_MS; |
| 1968 |
}else{ |
| 1969 |
score=scoreI; |
| 1970 |
time=streak+1; |
| 1971 |
prevState=MODE_INS; |
| 1972 |
} |
| 1973 |
|
| 1974 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 1975 |
assert(score>=MINoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 1976 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 1977 |
|
| 1978 |
packed[MODE_INS][row][col]=(score|time); |
| 1979 |
assert((score&SCOREMASK)==score); |
| 1980 |
|
| 1981 |
assert((time&TIMEMASK)==time); |
| 1982 |
} |
| 1983 |
} |
| 1984 |
} |
| 1985 |
|
| 1986 |
|
| 1987 |
int maxCol=-1; |
| 1988 |
int maxState=-1; |
| 1989 |
int maxScore=Integer.MIN_VALUE; |
| 1990 |
|
| 1991 |
for(int state=0; state<packed.length; state++){ |
| 1992 |
for(int col=1; col<=columns; col++){ |
| 1993 |
int x=packed[state][rows][col]&SCOREMASK; |
| 1994 |
if(x>maxScore){ |
| 1995 |
maxScore=x; |
| 1996 |
maxCol=col; |
| 1997 |
maxState=state; |
| 1998 |
} |
| 1999 |
} |
| 2000 |
} |
| 2001 |
maxScore>>=SCOREOFFSET; |
| 2002 |
|
| 2003 |
|
| 2004 |
return new int[] {rows, maxCol, maxState, maxScore}; |
| 2005 |
} |
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
@Override |
| 2011 |
public final byte[] traceback(byte[] read, byte[] ref, int refStartLoc, int refEndLoc, int row, int col, int state, boolean gapped){ |
| 2012 |
if(gapped){ |
| 2013 |
final byte[] gref=grefbuffer; |
| 2014 |
int gstart=translateToGappedCoordinate(refStartLoc, gref); |
| 2015 |
int gstop=translateToGappedCoordinate(refEndLoc, gref); |
| 2016 |
byte[] out=traceback2(read, gref, gstart, gstop, row, col, state); |
| 2017 |
return out; |
| 2018 |
}else{ |
| 2019 |
return traceback2(read, ref, refStartLoc, refEndLoc, row, col, state); |
| 2020 |
} |
| 2021 |
} |
| 2022 |
|
| 2023 |
|
| 2024 |
|
| 2025 |
@Override |
| 2026 |
public final byte[] traceback2(byte[] read, byte[] ref, int refStartLoc, int refEndLoc, int row, int col, int state){ |
| 2027 |
|
| 2028 |
assert(refStartLoc<=refEndLoc) : refStartLoc+", "+refEndLoc; |
| 2029 |
assert(row==rows); |
| 2030 |
|
| 2031 |
byte[] out=new byte[row+col-1]; |
| 2032 |
int outPos=0; |
| 2033 |
|
| 2034 |
int gaps=0; |
| 2035 |
|
| 2036 |
if(state==MODE_INS){ |
| 2037 |
|
| 2038 |
} |
| 2039 |
|
| 2040 |
while(row>0 && col>0){ |
| 2041 |
|
| 2042 |
|
| 2043 |
|
| 2044 |
final int time=packed[state][row][col]&TIMEMASK; |
| 2045 |
final byte prev; |
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
if(state==MODE_MS){ |
| 2050 |
if(time>1){prev=(byte)state;} |
| 2051 |
else{ |
| 2052 |
final int scoreFromDiag=packed[MODE_MS][row-1][col-1]&SCOREMASK; |
| 2053 |
final int scoreFromDel=packed[MODE_DEL][row-1][col-1]&SCOREMASK; |
| 2054 |
final int scoreFromIns=packed[MODE_INS][row-1][col-1]&SCOREMASK; |
| 2055 |
if(scoreFromDiag>=scoreFromDel && scoreFromDiag>=scoreFromIns){prev=MODE_MS;} |
| 2056 |
else if(scoreFromDel>=scoreFromIns){prev=MODE_DEL;} |
| 2057 |
else{prev=MODE_INS;} |
| 2058 |
} |
| 2059 |
|
| 2060 |
byte c=read[row-1]; |
| 2061 |
byte r=ref[refStartLoc+col-1]; |
| 2062 |
if(c==r){ |
| 2063 |
out[outPos]='m'; |
| 2064 |
}else{ |
| 2065 |
if(!AminoAcid.isFullyDefined(c)){ |
| 2066 |
out[outPos]='N'; |
| 2067 |
}else if(!AminoAcid.isFullyDefined(r)){ |
| 2068 |
|
| 2069 |
out[outPos]='N'; |
| 2070 |
}else{ |
| 2071 |
out[outPos]='S'; |
| 2072 |
} |
| 2073 |
} |
| 2074 |
|
| 2075 |
row--; |
| 2076 |
col--; |
| 2077 |
}else if(state==MODE_DEL){ |
| 2078 |
if(time>1){prev=(byte)state;} |
| 2079 |
else{ |
| 2080 |
final int scoreFromDiag=packed[MODE_MS][row][col-1]&SCOREMASK; |
| 2081 |
final int scoreFromDel=packed[MODE_DEL][row][col-1]&SCOREMASK; |
| 2082 |
if(scoreFromDiag>=scoreFromDel){prev=MODE_MS;} |
| 2083 |
else{prev=MODE_DEL;} |
| 2084 |
} |
| 2085 |
|
| 2086 |
byte r=ref[refStartLoc+col-1]; |
| 2087 |
if(r==GAPC){ |
| 2088 |
out[outPos]='-'; |
| 2089 |
gaps++; |
| 2090 |
}else{ |
| 2091 |
out[outPos]='D'; |
| 2092 |
} |
| 2093 |
col--; |
| 2094 |
}else{ |
| 2095 |
if(time>1){prev=(byte)state;} |
| 2096 |
else{ |
| 2097 |
final int scoreFromDiag=packed[MODE_MS][row-1][col]&SCOREMASK; |
| 2098 |
final int scoreFromIns=packed[MODE_INS][row-1][col]&SCOREMASK; |
| 2099 |
if(scoreFromDiag>=scoreFromIns){prev=MODE_MS;} |
| 2100 |
else{prev=MODE_INS;} |
| 2101 |
} |
| 2102 |
|
| 2103 |
assert(state==MODE_INS) : state; |
| 2104 |
if(col==0){ |
| 2105 |
out[outPos]='X'; |
| 2106 |
}else if(col>=columns){ |
| 2107 |
out[outPos]='Y'; |
| 2108 |
}else{ |
| 2109 |
out[outPos]='I'; |
| 2110 |
} |
| 2111 |
row--; |
| 2112 |
} |
| 2113 |
|
| 2114 |
|
| 2115 |
state=prev; |
| 2116 |
outPos++; |
| 2117 |
} |
| 2118 |
|
| 2119 |
assert(row==0 || col==0); |
| 2120 |
if(col!=row){ |
| 2121 |
while(row>0){ |
| 2122 |
out[outPos]='X'; |
| 2123 |
outPos++; |
| 2124 |
row--; |
| 2125 |
col--; |
| 2126 |
} |
| 2127 |
if(col>0){ |
| 2128 |
|
| 2129 |
} |
| 2130 |
} |
| 2131 |
|
| 2132 |
|
| 2133 |
|
| 2134 |
byte[] out2=new byte[outPos]; |
| 2135 |
for(int i=0; i<outPos; i++){ |
| 2136 |
out2[i]=out[outPos-i-1]; |
| 2137 |
} |
| 2138 |
out=null; |
| 2139 |
|
| 2140 |
if(gaps==0){return out2;} |
| 2141 |
|
| 2142 |
|
| 2143 |
byte[] out3=new byte[out2.length+gaps*(GAPLEN-1)]; |
| 2144 |
for(int i=0, j=0; i<out2.length; i++){ |
| 2145 |
byte c=out2[i]; |
| 2146 |
if(c!=GAPC){ |
| 2147 |
out3[j]=c; |
| 2148 |
j++; |
| 2149 |
}else{ |
| 2150 |
int lim=j+GAPLEN; |
| 2151 |
for(; j<lim; j++){ |
| 2152 |
out3[j]='D'; |
| 2153 |
} |
| 2154 |
} |
| 2155 |
} |
| 2156 |
return out3; |
| 2157 |
} |
| 2158 |
|
| 2159 |
|
| 2160 |
@Override |
| 2161 |
public final int[] score(final byte[] read, final byte[] ref, final int refStartLoc, final int refEndLoc, |
| 2162 |
final int maxRow, final int maxCol, final int maxState, boolean gapped){ |
| 2163 |
if(gapped){ |
| 2164 |
if(verbose){ |
| 2165 |
System.err.println("score():"); |
| 2166 |
System.err.println("origin="+grefRefOrigin+", "+refStartLoc+", "+refEndLoc+", "+maxRow+", "+maxCol); |
| 2167 |
} |
| 2168 |
final byte[] gref=grefbuffer; |
| 2169 |
int gstart=translateToGappedCoordinate(refStartLoc, gref); |
| 2170 |
int gstop=translateToGappedCoordinate(refEndLoc, gref); |
| 2171 |
|
| 2172 |
assert(translateFromGappedCoordinate(gstart, gref)==refStartLoc); |
| 2173 |
assert(translateFromGappedCoordinate(gstop, gref)==refEndLoc); |
| 2174 |
|
| 2175 |
assert(gstart==0) : gstart; |
| 2176 |
|
| 2177 |
if(verbose){System.err.println("gstart, gstop: "+gstart+", "+gstop);} |
| 2178 |
int[] out=score2(read, gref, gstart, gstop, maxRow, maxCol, maxState); |
| 2179 |
if(verbose){System.err.println("got score "+Arrays.toString(out));} |
| 2180 |
|
| 2181 |
assert(out[1]==translateToGappedCoordinate(translateFromGappedCoordinate(out[1], gref), gref)) : |
| 2182 |
"Verifying: "+out[1]+" -> "+translateFromGappedCoordinate(out[1], gref)+" -> "+ |
| 2183 |
translateToGappedCoordinate(translateFromGappedCoordinate(out[1], gref), gref); |
| 2184 |
assert(out[2]==translateToGappedCoordinate(translateFromGappedCoordinate(out[2], gref), gref)); |
| 2185 |
|
| 2186 |
out[1]=translateFromGappedCoordinate(out[1], gref); |
| 2187 |
out[2]=translateFromGappedCoordinate(out[2], gref); |
| 2188 |
if(verbose){System.err.println("returning score "+Arrays.toString(out));} |
| 2189 |
return out; |
| 2190 |
}else{ |
| 2191 |
return score2(read, ref, refStartLoc, refEndLoc, maxRow, maxCol, maxState); |
| 2192 |
} |
| 2193 |
} |
| 2194 |
|
| 2195 |
|
| 2196 |
@Override |
| 2197 |
public final int[] score2(final byte[] read, final byte[] ref, final int refStartLoc, final int refEndLoc, |
| 2198 |
final int maxRow, final int maxCol, final int maxState){ |
| 2199 |
|
| 2200 |
int row=maxRow; |
| 2201 |
int col=maxCol; |
| 2202 |
int state=maxState; |
| 2203 |
|
| 2204 |
assert(maxState>=0 && maxState<packed.length) : |
| 2205 |
maxState+", "+maxRow+", "+maxCol+"\n"+new String(read)+"\n"+toString(ref, refStartLoc, refEndLoc); |
| 2206 |
assert(maxRow>=0 && maxRow<packed[0].length) : |
| 2207 |
maxState+", "+maxRow+", "+maxCol+"\n"+new String(read)+"\n"+toString(ref, refStartLoc, refEndLoc); |
| 2208 |
assert(maxCol>=0 && maxCol<packed[0][0].length) : |
| 2209 |
maxState+", "+maxRow+", "+maxCol+"\n"+new String(read)+"\n"+toString(ref, refStartLoc, refEndLoc); |
| 2210 |
|
| 2211 |
int score=packed[maxState][maxRow][maxCol]&SCOREMASK; |
| 2212 |
|
| 2213 |
if(row<rows){ |
| 2214 |
int difR=rows-row; |
| 2215 |
int difC=columns-col; |
| 2216 |
|
| 2217 |
while(difR>difC){ |
| 2218 |
score+=POINTSoff_NOREF; |
| 2219 |
difR--; |
| 2220 |
} |
| 2221 |
|
| 2222 |
row+=difR; |
| 2223 |
col+=difR; |
| 2224 |
|
| 2225 |
} |
| 2226 |
|
| 2227 |
assert(refStartLoc<=refEndLoc); |
| 2228 |
assert(row==rows); |
| 2229 |
|
| 2230 |
|
| 2231 |
final int bestRefStop=refStartLoc+col-1; |
| 2232 |
|
| 2233 |
while(row>0 && col>0){ |
| 2234 |
|
| 2235 |
|
| 2236 |
|
| 2237 |
|
| 2238 |
|
| 2239 |
|
| 2240 |
final int time=packed[state][row][col]&TIMEMASK; |
| 2241 |
final byte prev; |
| 2242 |
|
| 2243 |
if(state==MODE_MS){ |
| 2244 |
if(time>1){prev=(byte)state;} |
| 2245 |
else{ |
| 2246 |
final int scoreFromDiag=packed[MODE_MS][row-1][col-1]&SCOREMASK; |
| 2247 |
final int scoreFromDel=packed[MODE_DEL][row-1][col-1]&SCOREMASK; |
| 2248 |
final int scoreFromIns=packed[MODE_INS][row-1][col-1]&SCOREMASK; |
| 2249 |
if(scoreFromDiag>=scoreFromDel && scoreFromDiag>=scoreFromIns){prev=MODE_MS;} |
| 2250 |
else if(scoreFromDel>=scoreFromIns){prev=MODE_DEL;} |
| 2251 |
else{prev=MODE_INS;} |
| 2252 |
} |
| 2253 |
row--; |
| 2254 |
col--; |
| 2255 |
}else if(state==MODE_DEL){ |
| 2256 |
if(time>1){prev=(byte)state;} |
| 2257 |
else{ |
| 2258 |
final int scoreFromDiag=packed[MODE_MS][row][col-1]&SCOREMASK; |
| 2259 |
final int scoreFromDel=packed[MODE_DEL][row][col-1]&SCOREMASK; |
| 2260 |
if(scoreFromDiag>=scoreFromDel){prev=MODE_MS;} |
| 2261 |
else{prev=MODE_DEL;} |
| 2262 |
} |
| 2263 |
col--; |
| 2264 |
}else{ |
| 2265 |
assert(state==MODE_INS); |
| 2266 |
if(time>1){prev=(byte)state;} |
| 2267 |
else{ |
| 2268 |
final int scoreFromDiag=packed[MODE_MS][row-1][col]&SCOREMASK; |
| 2269 |
final int scoreFromIns=packed[MODE_INS][row-1][col]&SCOREMASK; |
| 2270 |
if(scoreFromDiag>=scoreFromIns){prev=MODE_MS;} |
| 2271 |
else{prev=MODE_INS;} |
| 2272 |
} |
| 2273 |
row--; |
| 2274 |
} |
| 2275 |
|
| 2276 |
if(col<0){ |
| 2277 |
System.err.println(row); |
| 2278 |
break; |
| 2279 |
|
| 2280 |
} |
| 2281 |
|
| 2282 |
|
| 2283 |
state=prev; |
| 2284 |
|
| 2285 |
|
| 2286 |
} |
| 2287 |
|
| 2288 |
if(row>col){ |
| 2289 |
col-=row; |
| 2290 |
} |
| 2291 |
|
| 2292 |
final int bestRefStart=refStartLoc+col; |
| 2293 |
|
| 2294 |
score>>=SCOREOFFSET; |
| 2295 |
int[] rvec; |
| 2296 |
if(bestRefStart<refStartLoc || bestRefStop>refEndLoc){ |
| 2297 |
int padLeft=Tools.max(0, refStartLoc-bestRefStart); |
| 2298 |
int padRight=Tools.max(0, bestRefStop-refEndLoc); |
| 2299 |
rvec=new int[] {score, bestRefStart, bestRefStop, maxRow, maxCol, maxState, padLeft, padRight}; |
| 2300 |
}else{ |
| 2301 |
rvec=new int[] {score, bestRefStart, bestRefStop, maxRow, maxCol, maxState}; |
| 2302 |
} |
| 2303 |
return rvec; |
| 2304 |
} |
| 2305 |
|
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
|
| 2313 |
|
| 2314 |
private final byte[] makeGref(byte[] ref, int[] gaps, int refStartLoc, int refEndLoc){ |
| 2315 |
assert(gaps!=null && gaps.length>0); |
| 2316 |
|
| 2317 |
assert(refStartLoc<=gaps[0]) : refStartLoc+", "+refEndLoc+", "+Arrays.toString(gaps); |
| 2318 |
assert(refEndLoc>=gaps[gaps.length-1]); |
| 2319 |
|
| 2320 |
final int g0_old=gaps[0]; |
| 2321 |
final int gN_old=gaps[gaps.length-1]; |
| 2322 |
gaps[0]=Tools.min(gaps[0], refStartLoc); |
| 2323 |
gaps[gaps.length-1]=Tools.max(gN_old, refEndLoc); |
| 2324 |
grefRefOrigin=gaps[0]; |
| 2325 |
|
| 2326 |
if(verbose){System.err.println("\ngaps2: "+Arrays.toString(gaps));} |
| 2327 |
|
| 2328 |
|
| 2329 |
|
| 2330 |
|
| 2331 |
|
| 2332 |
|
| 2333 |
|
| 2334 |
|
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
|
| 2339 |
|
| 2340 |
|
| 2341 |
|
| 2342 |
|
| 2343 |
|
| 2344 |
|
| 2345 |
|
| 2346 |
|
| 2347 |
|
| 2348 |
|
| 2349 |
|
| 2350 |
|
| 2351 |
|
| 2352 |
byte[] gref=grefbuffer; |
| 2353 |
|
| 2354 |
int gpos=0; |
| 2355 |
for(int i=0; i<gaps.length; i+=2){ |
| 2356 |
int x=gaps[i]; |
| 2357 |
int y=gaps[i+1]; |
| 2358 |
|
| 2359 |
for(int r=x; r<=y; r++, gpos++){ |
| 2360 |
|
| 2361 |
|
| 2362 |
gref[gpos]=ref[r]; |
| 2363 |
} |
| 2364 |
|
| 2365 |
if(i+2<gaps.length){ |
| 2366 |
int z=gaps[i+2]; |
| 2367 |
assert(z>y); |
| 2368 |
int gap=z-y-1; |
| 2369 |
assert(gap>=MINGAP) : gap+"\t"+MINGAP; |
| 2370 |
if(gap<MINGAP){ |
| 2371 |
assert(false) : "TODO - just fill in normally"; |
| 2372 |
}else{ |
| 2373 |
int rem=gap%GAPLEN; |
| 2374 |
int lim=y+GAPBUFFER+rem; |
| 2375 |
|
| 2376 |
int div=(gap-GAPBUFFER2)/GAPLEN; |
| 2377 |
if(verbose){ |
| 2378 |
System.err.println("div = "+div); |
| 2379 |
} |
| 2380 |
assert(div>0); |
| 2381 |
|
| 2382 |
for(int r=y+1; r<=lim; r++, gpos++){ |
| 2383 |
gref[gpos]=ref[r]; |
| 2384 |
} |
| 2385 |
for(int g=0; g<div; g++, gpos++){ |
| 2386 |
gref[gpos]=GAPC; |
| 2387 |
} |
| 2388 |
for(int r=z-GAPBUFFER; r<z; r++, gpos++){ |
| 2389 |
gref[gpos]=ref[r]; |
| 2390 |
} |
| 2391 |
} |
| 2392 |
} |
| 2393 |
} |
| 2394 |
|
| 2395 |
greflimit=gpos; |
| 2396 |
|
| 2397 |
assert(gref[gpos-1]==ref[refEndLoc]); |
| 2398 |
|
| 2399 |
|
| 2400 |
{ |
| 2401 |
final int lim=Tools.min(gref.length, greflimit+GREFLIMIT2_CUSHION); |
| 2402 |
if(lim>gref.length){ |
| 2403 |
System.err.println("gref buffer overflow: "+lim+" > "+gref.length); |
| 2404 |
return null; |
| 2405 |
} |
| 2406 |
for(int i=greflimit, r=refEndLoc+1; i<lim; i++, r++){ |
| 2407 |
gref[i]=(r<ref.length ? ref[r] : (byte)'N'); |
| 2408 |
greflimit2=i; |
| 2409 |
} |
| 2410 |
} |
| 2411 |
|
| 2412 |
if(verbose){ |
| 2413 |
System.err.println("gref:\n"+new String(gref)); |
| 2414 |
} |
| 2415 |
|
| 2416 |
gaps[0]=g0_old; |
| 2417 |
gaps[gaps.length-1]=gN_old; |
| 2418 |
|
| 2419 |
if(verbose){ |
| 2420 |
System.err.println("\ngaps3: "+Arrays.toString(gaps)); |
| 2421 |
} |
| 2422 |
|
| 2423 |
return gref; |
| 2424 |
} |
| 2425 |
|
| 2426 |
|
| 2427 |
|
| 2428 |
|
| 2429 |
|
| 2430 |
|
| 2431 |
|
| 2432 |
|
| 2433 |
|
| 2434 |
|
| 2435 |
|
| 2436 |
|
| 2437 |
|
| 2438 |
|
| 2439 |
|
| 2440 |
|
| 2441 |
|
| 2442 |
|
| 2443 |
|
| 2444 |
|
| 2445 |
|
| 2446 |
|
| 2447 |
|
| 2448 |
|
| 2449 |
|
| 2450 |
|
| 2451 |
|
| 2452 |
private final int translateFromGappedCoordinate(int point, byte[] gref){ |
| 2453 |
if(verbose){System.err.println("translateFromGappedCoordinate("+point+"), gro="+grefRefOrigin+", grl="+greflimit);} |
| 2454 |
if(point<=0){return grefRefOrigin+point;} |
| 2455 |
for(int i=0, j=grefRefOrigin; i<greflimit2; i++){ |
| 2456 |
|
| 2457 |
byte c=gref[i]; |
| 2458 |
assert(point>=i) : "\n"+grefRefOrigin+"\n"+point+"\n"+new String(gref)+"\n"; |
| 2459 |
|
| 2460 |
if(i==point){ |
| 2461 |
if(verbose){System.err.println(" -> "+j);} |
| 2462 |
return j; |
| 2463 |
} |
| 2464 |
|
| 2465 |
j+=(c==GAPC ? GAPLEN : 1); |
| 2466 |
|
| 2467 |
|
| 2468 |
} |
| 2469 |
|
| 2470 |
System.err.println(grefRefOrigin); |
| 2471 |
System.err.println(point); |
| 2472 |
System.err.println(new String(gref)); |
| 2473 |
|
| 2474 |
throw new RuntimeException("Out of bounds."); |
| 2475 |
} |
| 2476 |
|
| 2477 |
private final int translateToGappedCoordinate(int point, byte[] gref){ |
| 2478 |
if(verbose){System.err.println("translateToGappedCoordinate("+point+"), gro="+grefRefOrigin+", grl="+greflimit);} |
| 2479 |
if(point<=grefRefOrigin){return point-grefRefOrigin;} |
| 2480 |
for(int i=0, j=grefRefOrigin; i<greflimit2; i++){ |
| 2481 |
|
| 2482 |
assert(point>=j) : "\n"+grefRefOrigin+"\n"+point+"\n"+new String(gref)+"\n"; |
| 2483 |
byte c=gref[i]; |
| 2484 |
|
| 2485 |
if(j==point){ |
| 2486 |
if(verbose){System.err.println(" -> "+i);} |
| 2487 |
return i; |
| 2488 |
} |
| 2489 |
|
| 2490 |
j+=(c==GAPC ? GAPLEN : 1); |
| 2491 |
|
| 2492 |
|
| 2493 |
} |
| 2494 |
|
| 2495 |
System.err.println(grefRefOrigin); |
| 2496 |
System.err.println(point); |
| 2497 |
System.err.println(new String(gref)); |
| 2498 |
|
| 2499 |
throw new RuntimeException("Out of bounds."); |
| 2500 |
} |
| 2501 |
|
| 2502 |
|
| 2503 |
|
| 2504 |
|
| 2505 |
|
| 2506 |
|
| 2507 |
|
| 2508 |
|
| 2509 |
|
| 2510 |
|
| 2511 |
|
| 2512 |
|
| 2513 |
|
| 2514 |
|
| 2515 |
|
| 2516 |
|
| 2517 |
|
| 2518 |
|
| 2519 |
|
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
|
| 2524 |
|
| 2525 |
|
| 2526 |
|
| 2527 |
|
| 2528 |
|
| 2529 |
|
| 2530 |
|
| 2531 |
|
| 2532 |
|
| 2533 |
|
| 2534 |
|
| 2535 |
|
| 2536 |
|
| 2537 |
|
| 2538 |
|
| 2539 |
|
| 2540 |
|
| 2541 |
|
| 2542 |
|
| 2543 |
|
| 2544 |
|
| 2545 |
|
| 2546 |
|
| 2547 |
|
| 2548 |
|
| 2549 |
|
| 2550 |
|
| 2551 |
|
| 2552 |
|
| 2553 |
|
| 2554 |
|
| 2555 |
|
| 2556 |
|
| 2557 |
|
| 2558 |
|
| 2559 |
|
| 2560 |
|
| 2561 |
|
| 2562 |
|
| 2563 |
|
| 2564 |
|
| 2565 |
|
| 2566 |
|
| 2567 |
|
| 2568 |
|
| 2569 |
|
| 2570 |
|
| 2571 |
|
| 2572 |
|
| 2573 |
|
| 2574 |
|
| 2575 |
|
| 2576 |
|
| 2577 |
|
| 2578 |
|
| 2579 |
|
| 2580 |
|
| 2581 |
|
| 2582 |
|
| 2583 |
|
| 2584 |
|
| 2585 |
|
| 2586 |
|
| 2587 |
|
| 2588 |
|
| 2589 |
|
| 2590 |
|
| 2591 |
|
| 2592 |
|
| 2593 |
|
| 2594 |
|
| 2595 |
|
| 2596 |
|
| 2597 |
|
| 2598 |
|
| 2599 |
|
| 2600 |
|
| 2601 |
private final int calcAffineScore(int[] locArray){ |
| 2602 |
int score=0; |
| 2603 |
int lastLoc=-2; |
| 2604 |
int lastValue=-1; |
| 2605 |
int timeInMode=0; |
| 2606 |
|
| 2607 |
for(int i=0; i<locArray.length; i++){ |
| 2608 |
int loc=locArray[i]; |
| 2609 |
|
| 2610 |
if(loc>0){ |
| 2611 |
if(loc==lastValue){ |
| 2612 |
score+=POINTS_MATCH2; |
| 2613 |
}else if(loc==lastLoc || lastLoc<0){ |
| 2614 |
score+=POINTS_MATCH; |
| 2615 |
}else if(loc<lastLoc){ |
| 2616 |
assert(lastLoc>=0); |
| 2617 |
score+=POINTS_MATCH; |
| 2618 |
score+=POINTS_DEL; |
| 2619 |
int dif=lastLoc-loc+1; |
| 2620 |
if(dif>MINGAP){ |
| 2621 |
int rem=dif%GAPLEN; |
| 2622 |
int div=(dif-GAPBUFFER2)/GAPLEN; |
| 2623 |
score+=(div*POINTS_GAP); |
| 2624 |
assert(rem+GAPBUFFER2<dif); |
| 2625 |
dif=rem+GAPBUFFER2; |
| 2626 |
assert(dif>LIMIT_FOR_COST_4); |
| 2627 |
|
| 2628 |
} |
| 2629 |
if(dif>LIMIT_FOR_COST_5){ |
| 2630 |
score+=((dif-LIMIT_FOR_COST_5+MASK5)/TIMESLIP)*POINTS_DEL5; |
| 2631 |
dif=LIMIT_FOR_COST_5; |
| 2632 |
} |
| 2633 |
if(dif>LIMIT_FOR_COST_4){ |
| 2634 |
score+=(dif-LIMIT_FOR_COST_4)*POINTS_DEL4; |
| 2635 |
dif=LIMIT_FOR_COST_4; |
| 2636 |
} |
| 2637 |
if(dif>LIMIT_FOR_COST_3){ |
| 2638 |
score+=(dif-LIMIT_FOR_COST_3)*POINTS_DEL3; |
| 2639 |
dif=LIMIT_FOR_COST_3; |
| 2640 |
} |
| 2641 |
if(dif>1){ |
| 2642 |
score+=(dif-1)*POINTS_DEL2; |
| 2643 |
} |
| 2644 |
timeInMode=1; |
| 2645 |
}else if(loc>lastLoc){ |
| 2646 |
assert(lastLoc>=0); |
| 2647 |
score+=POINTS_MATCH; |
| 2648 |
score+=POINTS_INS; |
| 2649 |
int dif=Tools.min(loc-lastLoc+1, 5); |
| 2650 |
assert(dif>0); |
| 2651 |
if(dif>LIMIT_FOR_COST_4){ |
| 2652 |
score+=(dif-LIMIT_FOR_COST_4)*POINTS_INS4; |
| 2653 |
dif=LIMIT_FOR_COST_4; |
| 2654 |
} |
| 2655 |
if(dif>LIMIT_FOR_COST_3){ |
| 2656 |
score+=(dif-LIMIT_FOR_COST_3)*POINTS_INS3; |
| 2657 |
dif=LIMIT_FOR_COST_3; |
| 2658 |
} |
| 2659 |
if(dif>1){ |
| 2660 |
score+=(dif-1)*POINTS_INS2; |
| 2661 |
} |
| 2662 |
timeInMode=1; |
| 2663 |
}else{ |
| 2664 |
assert(false); |
| 2665 |
} |
| 2666 |
lastLoc=loc; |
| 2667 |
}else{ |
| 2668 |
if(lastValue<0 && timeInMode>0){ |
| 2669 |
if(timeInMode<LIMIT_FOR_COST_3){score+=POINTS_SUB2;} |
| 2670 |
else{score+=POINTS_SUB3;} |
| 2671 |
timeInMode++; |
| 2672 |
}else{ |
| 2673 |
score+=POINTS_SUB; |
| 2674 |
timeInMode=1; |
| 2675 |
} |
| 2676 |
} |
| 2677 |
lastValue=loc; |
| 2678 |
} |
| 2679 |
assert(score<=maxQuality(locArray.length)); |
| 2680 |
return score; |
| 2681 |
} |
| 2682 |
|
| 2683 |
@Override |
| 2684 |
public final int calcAffineScore(int[] locArray, byte[] baseScores, byte[] bases){ |
| 2685 |
int score=0; |
| 2686 |
int lastLoc=-3; |
| 2687 |
int lastValue=-1; |
| 2688 |
int timeInMode=0; |
| 2689 |
|
| 2690 |
for(int i=0; i<locArray.length; i++){ |
| 2691 |
int loc=locArray[i]; |
| 2692 |
|
| 2693 |
if(loc>0){ |
| 2694 |
if(loc==lastValue){ |
| 2695 |
score+=(POINTS_MATCH2+baseScores[i]); |
| 2696 |
}else if(loc==lastLoc || lastLoc<0){ |
| 2697 |
score+=(POINTS_MATCH+baseScores[i]); |
| 2698 |
}else if(loc<lastLoc){ |
| 2699 |
assert(lastLoc>=0); |
| 2700 |
score+=(POINTS_MATCH+baseScores[i]); |
| 2701 |
score+=POINTS_DEL; |
| 2702 |
int dif=lastLoc-loc+1; |
| 2703 |
if(dif>MINGAP){ |
| 2704 |
int rem=dif%GAPLEN; |
| 2705 |
int div=(dif-GAPBUFFER2)/GAPLEN; |
| 2706 |
score+=(div*POINTS_GAP); |
| 2707 |
assert(rem+GAPBUFFER2<dif); |
| 2708 |
dif=rem+GAPBUFFER2; |
| 2709 |
assert(dif>LIMIT_FOR_COST_4); |
| 2710 |
|
| 2711 |
} |
| 2712 |
if(dif>LIMIT_FOR_COST_5){ |
| 2713 |
score+=((dif-LIMIT_FOR_COST_5+MASK5)/TIMESLIP)*POINTS_DEL5; |
| 2714 |
dif=LIMIT_FOR_COST_5; |
| 2715 |
} |
| 2716 |
if(dif>LIMIT_FOR_COST_4){ |
| 2717 |
score+=(dif-LIMIT_FOR_COST_4)*POINTS_DEL4; |
| 2718 |
dif=LIMIT_FOR_COST_4; |
| 2719 |
} |
| 2720 |
if(dif>LIMIT_FOR_COST_3){ |
| 2721 |
score+=(dif-LIMIT_FOR_COST_3)*POINTS_DEL3; |
| 2722 |
dif=LIMIT_FOR_COST_3; |
| 2723 |
} |
| 2724 |
if(dif>1){ |
| 2725 |
score+=(dif-1)*POINTS_DEL2; |
| 2726 |
} |
| 2727 |
timeInMode=1; |
| 2728 |
}else if(loc>lastLoc){ |
| 2729 |
assert(lastLoc>=0); |
| 2730 |
score+=(POINTS_MATCH+baseScores[i]); |
| 2731 |
score+=POINTS_INS; |
| 2732 |
int dif=Tools.min(loc-lastLoc+1, 5); |
| 2733 |
assert(dif>0); |
| 2734 |
if(dif>LIMIT_FOR_COST_4){ |
| 2735 |
score+=(dif-LIMIT_FOR_COST_4)*POINTS_INS4; |
| 2736 |
dif=LIMIT_FOR_COST_4; |
| 2737 |
} |
| 2738 |
if(dif>LIMIT_FOR_COST_3){ |
| 2739 |
score+=(dif-LIMIT_FOR_COST_3)*POINTS_INS3; |
| 2740 |
dif=LIMIT_FOR_COST_3; |
| 2741 |
} |
| 2742 |
if(dif>1){ |
| 2743 |
score+=(dif-1)*POINTS_INS2; |
| 2744 |
} |
| 2745 |
timeInMode=1; |
| 2746 |
}else{ |
| 2747 |
assert(false); |
| 2748 |
} |
| 2749 |
lastLoc=loc; |
| 2750 |
}else if(loc==-1){ |
| 2751 |
if(lastValue<0 && timeInMode>0){ |
| 2752 |
if(timeInMode<LIMIT_FOR_COST_3){score+=POINTS_SUB2;} |
| 2753 |
else{score+=POINTS_SUB3;} |
| 2754 |
timeInMode++; |
| 2755 |
}else{ |
| 2756 |
score+=POINTS_SUB; |
| 2757 |
timeInMode=1; |
| 2758 |
} |
| 2759 |
}else{ |
| 2760 |
assert(loc==-2) : loc+"\n"+Arrays.toString(locArray)+"\n"+Arrays.toString(baseScores)+"\n"+new String(bases)+"\n" |
| 2761 |
+"If this happens please ensure that the reference has a startpad of Ns longer than readlength."; |
| 2762 |
timeInMode=0; |
| 2763 |
score+=POINTS_NOCALL; |
| 2764 |
} |
| 2765 |
lastValue=loc; |
| 2766 |
} |
| 2767 |
assert(score<=maxQuality(locArray.length)); |
| 2768 |
return score; |
| 2769 |
} |
| 2770 |
|
| 2771 |
@Override |
| 2772 |
public final int calcAffineScore(int[] locArray, byte[] baseScores, byte[] bases, int minContig){ |
| 2773 |
assert(minContig>1) : minContig; |
| 2774 |
|
| 2775 |
int contig=0; |
| 2776 |
int maxContig=0; |
| 2777 |
|
| 2778 |
int score=0; |
| 2779 |
int lastLoc=-3; |
| 2780 |
int lastValue=-1; |
| 2781 |
int timeInMode=0; |
| 2782 |
|
| 2783 |
for(int i=0; i<locArray.length; i++){ |
| 2784 |
int loc=locArray[i]; |
| 2785 |
|
| 2786 |
if(loc>0){ |
| 2787 |
if(loc==lastValue){ |
| 2788 |
contig++; |
| 2789 |
score+=(POINTS_MATCH2+baseScores[i]); |
| 2790 |
}else if(loc==lastLoc || lastLoc<0){ |
| 2791 |
maxContig=Tools.max(maxContig, contig); |
| 2792 |
contig=1; |
| 2793 |
score+=(POINTS_MATCH+baseScores[i]); |
| 2794 |
}else if(loc<lastLoc){ |
| 2795 |
maxContig=Tools.max(maxContig, contig); |
| 2796 |
contig=0; |
| 2797 |
assert(lastLoc>=0); |
| 2798 |
score+=(POINTS_MATCH+baseScores[i]); |
| 2799 |
score+=POINTS_DEL; |
| 2800 |
int dif=lastLoc-loc+1; |
| 2801 |
if(dif>MINGAP){ |
| 2802 |
int rem=dif%GAPLEN; |
| 2803 |
int div=(dif-GAPBUFFER2)/GAPLEN; |
| 2804 |
score+=(div*POINTS_GAP); |
| 2805 |
assert(rem+GAPBUFFER2<dif); |
| 2806 |
dif=rem+GAPBUFFER2; |
| 2807 |
assert(dif>LIMIT_FOR_COST_4); |
| 2808 |
|
| 2809 |
} |
| 2810 |
if(dif>LIMIT_FOR_COST_5){ |
| 2811 |
score+=((dif-LIMIT_FOR_COST_5+MASK5)/TIMESLIP)*POINTS_DEL5; |
| 2812 |
dif=LIMIT_FOR_COST_5; |
| 2813 |
} |
| 2814 |
if(dif>LIMIT_FOR_COST_4){ |
| 2815 |
score+=(dif-LIMIT_FOR_COST_4)*POINTS_DEL4; |
| 2816 |
dif=LIMIT_FOR_COST_4; |
| 2817 |
} |
| 2818 |
if(dif>LIMIT_FOR_COST_3){ |
| 2819 |
score+=(dif-LIMIT_FOR_COST_3)*POINTS_DEL3; |
| 2820 |
dif=LIMIT_FOR_COST_3; |
| 2821 |
} |
| 2822 |
if(dif>1){ |
| 2823 |
score+=(dif-1)*POINTS_DEL2; |
| 2824 |
} |
| 2825 |
timeInMode=1; |
| 2826 |
}else if(loc>lastLoc){ |
| 2827 |
maxContig=Tools.max(maxContig, contig); |
| 2828 |
contig=0; |
| 2829 |
assert(lastLoc>=0); |
| 2830 |
score+=(POINTS_MATCH+baseScores[i]); |
| 2831 |
score+=POINTS_INS; |
| 2832 |
int dif=Tools.min(loc-lastLoc+1, 5); |
| 2833 |
assert(dif>0); |
| 2834 |
if(dif>LIMIT_FOR_COST_4){ |
| 2835 |
score+=(dif-LIMIT_FOR_COST_4)*POINTS_INS4; |
| 2836 |
dif=LIMIT_FOR_COST_4; |
| 2837 |
} |
| 2838 |
if(dif>LIMIT_FOR_COST_3){ |
| 2839 |
score+=(dif-LIMIT_FOR_COST_3)*POINTS_INS3; |
| 2840 |
dif=LIMIT_FOR_COST_3; |
| 2841 |
} |
| 2842 |
if(dif>1){ |
| 2843 |
score+=(dif-1)*POINTS_INS2; |
| 2844 |
} |
| 2845 |
timeInMode=1; |
| 2846 |
}else{ |
| 2847 |
assert(false); |
| 2848 |
} |
| 2849 |
lastLoc=loc; |
| 2850 |
}else if(loc==-1){ |
| 2851 |
if(lastValue<0 && timeInMode>0){ |
| 2852 |
if(timeInMode<LIMIT_FOR_COST_3){score+=POINTS_SUB2;} |
| 2853 |
else{score+=POINTS_SUB3;} |
| 2854 |
timeInMode++; |
| 2855 |
}else{ |
| 2856 |
score+=POINTS_SUB; |
| 2857 |
timeInMode=1; |
| 2858 |
} |
| 2859 |
}else{ |
| 2860 |
assert(loc==-2) : loc+"\n"+Arrays.toString(locArray)+"\n"+Arrays.toString(baseScores)+"\n"+new String(bases)+"\n" |
| 2861 |
+"If this happens please ensure that the reference has a startpad of Ns longer than readlength."; |
| 2862 |
timeInMode=0; |
| 2863 |
score+=POINTS_NOCALL; |
| 2864 |
} |
| 2865 |
lastValue=loc; |
| 2866 |
} |
| 2867 |
assert(score<=maxQuality(locArray.length)); |
| 2868 |
if(Tools.max(contig, maxContig)<minContig){score=Tools.min(score, -50*locArray.length);} |
| 2869 |
return score; |
| 2870 |
} |
| 2871 |
|
| 2872 |
@Override |
| 2873 |
public final int scoreNoIndels(byte[] read, byte[] ref, final int refStart){ |
| 2874 |
|
| 2875 |
int score=0; |
| 2876 |
int mode=-1; |
| 2877 |
int timeInMode=0; |
| 2878 |
|
| 2879 |
|
| 2880 |
|
| 2881 |
int readStart=0; |
| 2882 |
int readStop=read.length; |
| 2883 |
final int refStop=refStart+read.length; |
| 2884 |
if(refStart<0){ |
| 2885 |
readStart=0-refStart; |
| 2886 |
score+=POINTS_NOREF*readStart; |
| 2887 |
} |
| 2888 |
if(refStop>ref.length){ |
| 2889 |
int dif=(refStop-ref.length); |
| 2890 |
readStop-=dif; |
| 2891 |
score+=POINTS_NOREF*dif; |
| 2892 |
} |
| 2893 |
|
| 2894 |
|
| 2895 |
|
| 2896 |
for(int i=readStart; i<readStop; i++){ |
| 2897 |
byte c=read[i]; |
| 2898 |
byte r=ref[refStart+i]; |
| 2899 |
|
| 2900 |
if(c==r && c!='N'){ |
| 2901 |
if(mode==MODE_MS){ |
| 2902 |
timeInMode++; |
| 2903 |
score+=POINTS_MATCH2; |
| 2904 |
}else{ |
| 2905 |
timeInMode=0; |
| 2906 |
score+=POINTS_MATCH; |
| 2907 |
} |
| 2908 |
mode=MODE_MS; |
| 2909 |
}else if(c<0 || c=='N'){ |
| 2910 |
score+=POINTS_NOCALL; |
| 2911 |
}else if(r<0 || r=='N'){ |
| 2912 |
score+=POINTS_NOREF; |
| 2913 |
}else{ |
| 2914 |
if(mode==MODE_SUB){timeInMode++;} |
| 2915 |
else{timeInMode=0;} |
| 2916 |
|
| 2917 |
if(timeInMode==0){score+=POINTS_SUB;} |
| 2918 |
else if(timeInMode<LIMIT_FOR_COST_3){score+=POINTS_SUB2;} |
| 2919 |
else{score+=POINTS_SUB3;} |
| 2920 |
mode=MODE_SUB; |
| 2921 |
} |
| 2922 |
} |
| 2923 |
|
| 2924 |
return score; |
| 2925 |
} |
| 2926 |
|
| 2927 |
@Override |
| 2928 |
public final byte[] genMatchNoIndels(byte[] read, byte[] ref, final int refStart){ |
| 2929 |
if(read==null || ref==null){return null;} |
| 2930 |
|
| 2931 |
final byte[] match=new byte[read.length]; |
| 2932 |
|
| 2933 |
for(int i=0, j=refStart; i<read.length; i++, j++){ |
| 2934 |
byte c=read[i]; |
| 2935 |
byte r=(j<0 || j>=ref.length) ? (byte)'N' : ref[j]; |
| 2936 |
|
| 2937 |
if(c=='N' || r=='N'){match[i]='N';} |
| 2938 |
else if(c==r){match[i]='m';} |
| 2939 |
else{match[i]='S';} |
| 2940 |
|
| 2941 |
} |
| 2942 |
|
| 2943 |
return match; |
| 2944 |
} |
| 2945 |
|
| 2946 |
@Override |
| 2947 |
public final int scoreNoIndels(byte[] read, byte[] ref, byte[] baseScores, final int refStart){ |
| 2948 |
|
| 2949 |
int score=0; |
| 2950 |
int mode=-1; |
| 2951 |
int timeInMode=0; |
| 2952 |
|
| 2953 |
|
| 2954 |
|
| 2955 |
int readStart=0; |
| 2956 |
int readStop=read.length; |
| 2957 |
final int refStop=refStart+read.length; |
| 2958 |
if(refStart<0){ |
| 2959 |
readStart=0-refStart; |
| 2960 |
score+=POINTS_NOREF*readStart; |
| 2961 |
} |
| 2962 |
if(refStop>ref.length){ |
| 2963 |
int dif=(refStop-ref.length); |
| 2964 |
readStop-=dif; |
| 2965 |
score+=POINTS_NOREF*dif; |
| 2966 |
} |
| 2967 |
|
| 2968 |
|
| 2969 |
|
| 2970 |
for(int i=readStart; i<readStop; i++){ |
| 2971 |
byte c=read[i]; |
| 2972 |
byte r=ref[refStart+i]; |
| 2973 |
|
| 2974 |
if(c==r && c!='N'){ |
| 2975 |
if(mode==MODE_MS){ |
| 2976 |
timeInMode++; |
| 2977 |
score+=POINTS_MATCH2; |
| 2978 |
}else{ |
| 2979 |
timeInMode=0; |
| 2980 |
score+=POINTS_MATCH; |
| 2981 |
} |
| 2982 |
score+=baseScores[i]; |
| 2983 |
mode=MODE_MS; |
| 2984 |
}else if(c<0 || c=='N'){ |
| 2985 |
score+=POINTS_NOCALL; |
| 2986 |
}else if(r<0 || r=='N'){ |
| 2987 |
score+=POINTS_NOREF; |
| 2988 |
}else{ |
| 2989 |
if(mode==MODE_SUB){timeInMode++;} |
| 2990 |
else{timeInMode=0;} |
| 2991 |
|
| 2992 |
if(timeInMode==0){score+=POINTS_SUB;} |
| 2993 |
else if(timeInMode<LIMIT_FOR_COST_3){score+=POINTS_SUB2;} |
| 2994 |
else{score+=POINTS_SUB3;} |
| 2995 |
mode=MODE_SUB; |
| 2996 |
} |
| 2997 |
} |
| 2998 |
|
| 2999 |
return score; |
| 3000 |
} |
| 3001 |
|
| 3002 |
@Override |
| 3003 |
public final int scoreNoIndelsAndMakeMatchString(byte[] read, byte[] ref, byte[] baseScores, final int refStart, byte[][] matchReturn){ |
| 3004 |
int score=0; |
| 3005 |
int mode=-1; |
| 3006 |
int timeInMode=0; |
| 3007 |
|
| 3008 |
assert(refStart<=ref.length) : refStart+", "+ref.length; |
| 3009 |
|
| 3010 |
|
| 3011 |
|
| 3012 |
int readStart=0; |
| 3013 |
int readStop=read.length; |
| 3014 |
final int refStop=refStart+read.length; |
| 3015 |
if(refStart<0 || refStop>ref.length){return -99999;} |
| 3016 |
if(refStart<0){ |
| 3017 |
readStart=0-refStart; |
| 3018 |
score+=POINTS_NOREF*readStart; |
| 3019 |
} |
| 3020 |
if(refStop>ref.length){ |
| 3021 |
int dif=(refStop-ref.length); |
| 3022 |
System.err.println(new String(read)+"\ndif="+dif+", ref.length="+ref.length+", refStop="+refStop); |
| 3023 |
readStop-=dif; |
| 3024 |
score+=POINTS_NOREF*dif; |
| 3025 |
} |
| 3026 |
assert(refStart+readStop<=ref.length) : "readStart="+readStart+", readStop="+readStop+ |
| 3027 |
", refStart="+refStart+", refStop="+refStop+", ref.length="+ref.length+", read.length="+read.length; |
| 3028 |
|
| 3029 |
assert(matchReturn!=null); |
| 3030 |
assert(matchReturn.length==1); |
| 3031 |
if(matchReturn[0]==null || matchReturn[0].length!=read.length){ |
| 3032 |
assert(matchReturn[0]==null || matchReturn[0].length<read.length) : matchReturn[0].length+"!="+read.length; |
| 3033 |
matchReturn[0]=new byte[read.length]; |
| 3034 |
} |
| 3035 |
final byte[] match=matchReturn[0]; |
| 3036 |
|
| 3037 |
|
| 3038 |
|
| 3039 |
for(int i=readStart; i<readStop; i++){ |
| 3040 |
byte c=read[i]; |
| 3041 |
byte r=ref[refStart+i]; |
| 3042 |
|
| 3043 |
assert(r!='.' && c!='.'); |
| 3044 |
|
| 3045 |
if(c==r && c!='N'){ |
| 3046 |
if(mode==MODE_MS){ |
| 3047 |
timeInMode++; |
| 3048 |
score+=POINTS_MATCH2; |
| 3049 |
}else{ |
| 3050 |
timeInMode=0; |
| 3051 |
score+=POINTS_MATCH; |
| 3052 |
} |
| 3053 |
score+=baseScores[i]; |
| 3054 |
match[i]='m'; |
| 3055 |
mode=MODE_MS; |
| 3056 |
}else if(c<0 || c=='N'){ |
| 3057 |
score+=POINTS_NOCALL; |
| 3058 |
match[i]='N'; |
| 3059 |
}else if(r<0 || r=='N'){ |
| 3060 |
score+=POINTS_NOREF; |
| 3061 |
|
| 3062 |
match[i]='N'; |
| 3063 |
}else{ |
| 3064 |
match[i]='S'; |
| 3065 |
if(mode==MODE_SUB){timeInMode++;} |
| 3066 |
else{timeInMode=0;} |
| 3067 |
|
| 3068 |
if(timeInMode==0){score+=POINTS_SUB;} |
| 3069 |
else if(timeInMode<LIMIT_FOR_COST_3){score+=POINTS_SUB2;} |
| 3070 |
else{score+=POINTS_SUB3;} |
| 3071 |
mode=MODE_SUB; |
| 3072 |
} |
| 3073 |
} |
| 3074 |
|
| 3075 |
return score; |
| 3076 |
} |
| 3077 |
|
| 3078 |
@Override |
| 3079 |
public final int scoreNoIndelsAndMakeMatchString(byte[] read, byte[] ref, final int refStart, byte[][] matchReturn){ |
| 3080 |
int score=0; |
| 3081 |
int mode=-1; |
| 3082 |
int timeInMode=0; |
| 3083 |
|
| 3084 |
assert(refStart<=ref.length) : refStart+", "+ref.length; |
| 3085 |
|
| 3086 |
|
| 3087 |
|
| 3088 |
int readStart=0; |
| 3089 |
int readStop=read.length; |
| 3090 |
final int refStop=refStart+read.length; |
| 3091 |
if(refStart<0 || refStop>ref.length){return -99999;} |
| 3092 |
if(refStart<0){ |
| 3093 |
readStart=0-refStart; |
| 3094 |
score+=POINTS_NOREF*readStart; |
| 3095 |
} |
| 3096 |
if(refStop>ref.length){ |
| 3097 |
int dif=(refStop-ref.length); |
| 3098 |
System.err.println(new String(read)+"\ndif="+dif+", ref.length="+ref.length+", refStop="+refStop); |
| 3099 |
readStop-=dif; |
| 3100 |
score+=POINTS_NOREF*dif; |
| 3101 |
} |
| 3102 |
assert(refStart+readStop<=ref.length) : "readStart="+readStart+", readStop="+readStop+ |
| 3103 |
", refStart="+refStart+", refStop="+refStop+", ref.length="+ref.length+", read.length="+read.length; |
| 3104 |
|
| 3105 |
assert(matchReturn!=null); |
| 3106 |
assert(matchReturn.length==1); |
| 3107 |
if(matchReturn[0]==null || matchReturn[0].length!=read.length){ |
| 3108 |
assert(matchReturn[0]==null || matchReturn[0].length<read.length) : matchReturn[0].length+"!="+read.length; |
| 3109 |
matchReturn[0]=new byte[read.length]; |
| 3110 |
} |
| 3111 |
final byte[] match=matchReturn[0]; |
| 3112 |
|
| 3113 |
|
| 3114 |
|
| 3115 |
for(int i=readStart; i<readStop; i++){ |
| 3116 |
byte c=read[i]; |
| 3117 |
byte r=ref[refStart+i]; |
| 3118 |
|
| 3119 |
assert(r!='.' && c!='.'); |
| 3120 |
|
| 3121 |
if(c==r && c!='N'){ |
| 3122 |
if(mode==MODE_MS){ |
| 3123 |
timeInMode++; |
| 3124 |
score+=POINTS_MATCH2; |
| 3125 |
}else{ |
| 3126 |
timeInMode=0; |
| 3127 |
score+=POINTS_MATCH; |
| 3128 |
} |
| 3129 |
match[i]='m'; |
| 3130 |
mode=MODE_MS; |
| 3131 |
}else if(c<0 || c=='N'){ |
| 3132 |
score+=POINTS_NOCALL; |
| 3133 |
match[i]='N'; |
| 3134 |
}else if(r<0 || r=='N'){ |
| 3135 |
score+=POINTS_NOREF; |
| 3136 |
|
| 3137 |
match[i]='N'; |
| 3138 |
}else{ |
| 3139 |
match[i]='S'; |
| 3140 |
if(mode==MODE_SUB){timeInMode++;} |
| 3141 |
else{timeInMode=0;} |
| 3142 |
|
| 3143 |
if(timeInMode==0){score+=POINTS_SUB;} |
| 3144 |
else if(timeInMode<LIMIT_FOR_COST_3){score+=POINTS_SUB2;} |
| 3145 |
else{score+=POINTS_SUB3;} |
| 3146 |
mode=MODE_SUB; |
| 3147 |
} |
| 3148 |
} |
| 3149 |
|
| 3150 |
return score; |
| 3151 |
} |
| 3152 |
|
| 3153 |
@Override |
| 3154 |
public final int scoreNoIndels(byte[] read, byte[] ref, final int refStart, final SiteScore ss){ |
| 3155 |
|
| 3156 |
int score=0; |
| 3157 |
int mode=-1; |
| 3158 |
int timeInMode=0; |
| 3159 |
|
| 3160 |
|
| 3161 |
|
| 3162 |
int readStart=0; |
| 3163 |
int readStop=read.length; |
| 3164 |
final int refStop=refStart+read.length; |
| 3165 |
boolean semiperfect=true; |
| 3166 |
int norefs=0; |
| 3167 |
|
| 3168 |
if(refStart<0){ |
| 3169 |
readStart=0-refStart; |
| 3170 |
score+=POINTS_NOREF*readStart; |
| 3171 |
norefs+=readStart; |
| 3172 |
} |
| 3173 |
if(refStop>ref.length){ |
| 3174 |
int dif=(refStop-ref.length); |
| 3175 |
readStop-=dif; |
| 3176 |
score+=POINTS_NOREF*dif; |
| 3177 |
norefs+=dif; |
| 3178 |
} |
| 3179 |
|
| 3180 |
|
| 3181 |
|
| 3182 |
for(int i=readStart; i<readStop; i++){ |
| 3183 |
byte c=read[i]; |
| 3184 |
byte r=ref[refStart+i]; |
| 3185 |
|
| 3186 |
if(c==r && c!='N'){ |
| 3187 |
if(mode==MODE_MS){ |
| 3188 |
timeInMode++; |
| 3189 |
score+=POINTS_MATCH2; |
| 3190 |
}else{ |
| 3191 |
timeInMode=0; |
| 3192 |
score+=POINTS_MATCH; |
| 3193 |
} |
| 3194 |
mode=MODE_MS; |
| 3195 |
}else if(c<0 || c=='N'){ |
| 3196 |
score+=POINTS_NOCALL; |
| 3197 |
semiperfect=false; |
| 3198 |
}else if(r<0 || r=='N'){ |
| 3199 |
score+=POINTS_NOREF; |
| 3200 |
norefs++; |
| 3201 |
}else{ |
| 3202 |
if(mode==MODE_SUB){timeInMode++;} |
| 3203 |
else{timeInMode=0;} |
| 3204 |
|
| 3205 |
if(timeInMode==0){score+=POINTS_SUB;} |
| 3206 |
else if(timeInMode<LIMIT_FOR_COST_3){score+=POINTS_SUB2;} |
| 3207 |
else{score+=POINTS_SUB3;} |
| 3208 |
mode=MODE_SUB; |
| 3209 |
semiperfect=false; |
| 3210 |
} |
| 3211 |
} |
| 3212 |
|
| 3213 |
|
| 3214 |
|
| 3215 |
|
| 3216 |
return score; |
| 3217 |
} |
| 3218 |
|
| 3219 |
@Override |
| 3220 |
public final int scoreNoIndels(byte[] read, byte[] ref, byte[] baseScores, final int refStart, SiteScore ss){ |
| 3221 |
|
| 3222 |
int score=0; |
| 3223 |
int mode=-1; |
| 3224 |
int timeInMode=0; |
| 3225 |
int norefs=0; |
| 3226 |
|
| 3227 |
|
| 3228 |
|
| 3229 |
int readStart=0; |
| 3230 |
int readStop=read.length; |
| 3231 |
final int refStop=refStart+read.length; |
| 3232 |
boolean semiperfect=true; |
| 3233 |
|
| 3234 |
if(refStart<0){ |
| 3235 |
readStart=0-refStart; |
| 3236 |
score+=POINTS_NOREF*readStart; |
| 3237 |
norefs+=readStart; |
| 3238 |
} |
| 3239 |
if(refStop>ref.length){ |
| 3240 |
int dif=(refStop-ref.length); |
| 3241 |
readStop-=dif; |
| 3242 |
score+=POINTS_NOREF*dif; |
| 3243 |
norefs+=dif; |
| 3244 |
} |
| 3245 |
|
| 3246 |
|
| 3247 |
|
| 3248 |
for(int i=readStart; i<readStop; i++){ |
| 3249 |
byte c=read[i]; |
| 3250 |
byte r=ref[refStart+i]; |
| 3251 |
|
| 3252 |
if(c==r && c!='N'){ |
| 3253 |
if(mode==MODE_MS){ |
| 3254 |
timeInMode++; |
| 3255 |
score+=POINTS_MATCH2; |
| 3256 |
}else{ |
| 3257 |
timeInMode=0; |
| 3258 |
score+=POINTS_MATCH; |
| 3259 |
} |
| 3260 |
score+=baseScores[i]; |
| 3261 |
mode=MODE_MS; |
| 3262 |
}else if(c<0 || c=='N'){ |
| 3263 |
score+=POINTS_NOCALL; |
| 3264 |
semiperfect=false; |
| 3265 |
}else if(r<0 || r=='N'){ |
| 3266 |
score+=POINTS_NOREF; |
| 3267 |
norefs++; |
| 3268 |
}else{ |
| 3269 |
if(mode==MODE_SUB){timeInMode++;} |
| 3270 |
else{timeInMode=0;} |
| 3271 |
|
| 3272 |
if(timeInMode==0){score+=POINTS_SUB;} |
| 3273 |
else if(timeInMode<LIMIT_FOR_COST_3){score+=POINTS_SUB2;} |
| 3274 |
else{score+=POINTS_SUB3;} |
| 3275 |
mode=MODE_SUB; |
| 3276 |
semiperfect=false; |
| 3277 |
} |
| 3278 |
} |
| 3279 |
|
| 3280 |
|
| 3281 |
|
| 3282 |
|
| 3283 |
|
| 3284 |
return score; |
| 3285 |
} |
| 3286 |
|
| 3287 |
@Override |
| 3288 |
public final int maxQuality(int numBases){ |
| 3289 |
return POINTS_MATCH+(numBases-1)*(POINTS_MATCH2); |
| 3290 |
} |
| 3291 |
|
| 3292 |
@Override |
| 3293 |
public final int maxQuality(byte[] baseScores){ |
| 3294 |
return POINTS_MATCH+(baseScores.length-1)*(POINTS_MATCH2)+Tools.sumInt(baseScores); |
| 3295 |
} |
| 3296 |
|
| 3297 |
@Override |
| 3298 |
public final int maxImperfectScore(int numBases){ |
| 3299 |
|
| 3300 |
|
| 3301 |
|
| 3302 |
|
| 3303 |
|
| 3304 |
|
| 3305 |
int maxQ=maxQuality(numBases); |
| 3306 |
int maxI=maxQ+Tools.min(POINTS_DEL, POINTS_INS-POINTS_MATCH2); |
| 3307 |
assert(maxI<(maxQ-(POINTS_MATCH2+POINTS_MATCH2)+(POINTS_MATCH+POINTS_SUB))); |
| 3308 |
return maxI; |
| 3309 |
} |
| 3310 |
|
| 3311 |
@Override |
| 3312 |
public final int maxImperfectScore(byte[] baseScores){ |
| 3313 |
|
| 3314 |
|
| 3315 |
|
| 3316 |
|
| 3317 |
|
| 3318 |
|
| 3319 |
int maxQ=maxQuality(baseScores); |
| 3320 |
int maxI=maxQ+Tools.min(POINTS_DEL, POINTS_INS-POINTS_MATCH2); |
| 3321 |
assert(maxI<(maxQ-(POINTS_MATCH2+POINTS_MATCH2)+(POINTS_MATCH+POINTS_SUB))); |
| 3322 |
return maxI; |
| 3323 |
} |
| 3324 |
|
| 3325 |
@Override |
| 3326 |
public int calcDelScore(int len, boolean approximateGaps){ |
| 3327 |
if(len<=0){return 0;} |
| 3328 |
int score=POINTS_DEL; |
| 3329 |
|
| 3330 |
if(approximateGaps && len>MINGAP){ |
| 3331 |
int rem=len%GAPLEN; |
| 3332 |
int div=(len-GAPBUFFER2)/GAPLEN; |
| 3333 |
score+=(div*POINTS_GAP); |
| 3334 |
assert(rem+GAPBUFFER2<len); |
| 3335 |
len=rem+GAPBUFFER2; |
| 3336 |
assert(len>LIMIT_FOR_COST_4); |
| 3337 |
|
| 3338 |
} |
| 3339 |
|
| 3340 |
if(len>LIMIT_FOR_COST_5){ |
| 3341 |
score+=((len-LIMIT_FOR_COST_5+MASK5)/TIMESLIP)*POINTS_DEL5; |
| 3342 |
len=LIMIT_FOR_COST_5; |
| 3343 |
} |
| 3344 |
if(len>LIMIT_FOR_COST_4){ |
| 3345 |
score+=(len-LIMIT_FOR_COST_4)*POINTS_DEL4; |
| 3346 |
len=LIMIT_FOR_COST_4; |
| 3347 |
} |
| 3348 |
if(len>LIMIT_FOR_COST_3){ |
| 3349 |
score+=(len-LIMIT_FOR_COST_3)*POINTS_DEL3; |
| 3350 |
len=LIMIT_FOR_COST_3; |
| 3351 |
} |
| 3352 |
if(len>1){ |
| 3353 |
score+=(len-1)*POINTS_DEL2; |
| 3354 |
} |
| 3355 |
return score; |
| 3356 |
} |
| 3357 |
|
| 3358 |
private static int calcDelScoreOffset(int len){ |
| 3359 |
if(len<=0){return 0;} |
| 3360 |
int score=POINTSoff_DEL; |
| 3361 |
|
| 3362 |
if(len>LIMIT_FOR_COST_5){ |
| 3363 |
score+=((len-LIMIT_FOR_COST_5+MASK5)/TIMESLIP)*POINTSoff_DEL5; |
| 3364 |
len=LIMIT_FOR_COST_5; |
| 3365 |
} |
| 3366 |
if(len>LIMIT_FOR_COST_4){ |
| 3367 |
score+=(len-LIMIT_FOR_COST_4)*POINTSoff_DEL4; |
| 3368 |
len=LIMIT_FOR_COST_4; |
| 3369 |
} |
| 3370 |
if(len>LIMIT_FOR_COST_3){ |
| 3371 |
score+=(len-LIMIT_FOR_COST_3)*POINTSoff_DEL3; |
| 3372 |
len=LIMIT_FOR_COST_3; |
| 3373 |
} |
| 3374 |
if(len>1){ |
| 3375 |
score+=(len-1)*POINTSoff_DEL2; |
| 3376 |
} |
| 3377 |
return score; |
| 3378 |
} |
| 3379 |
|
| 3380 |
@Override |
| 3381 |
public int calcInsScore(int len){ |
| 3382 |
if(len<=0){return 0;} |
| 3383 |
int score=POINTS_INS; |
| 3384 |
|
| 3385 |
if(len>LIMIT_FOR_COST_4){ |
| 3386 |
score+=(len-LIMIT_FOR_COST_4)*POINTS_INS4; |
| 3387 |
len=LIMIT_FOR_COST_4; |
| 3388 |
} |
| 3389 |
if(len>LIMIT_FOR_COST_3){ |
| 3390 |
score+=(len-LIMIT_FOR_COST_3)*POINTS_INS3; |
| 3391 |
len=LIMIT_FOR_COST_3; |
| 3392 |
} |
| 3393 |
if(len>1){ |
| 3394 |
score+=(len-1)*POINTS_INS2; |
| 3395 |
} |
| 3396 |
return score; |
| 3397 |
} |
| 3398 |
|
| 3399 |
private static int calcInsScoreOffset(int len){ |
| 3400 |
if(len<=0){return 0;} |
| 3401 |
int score=POINTSoff_INS; |
| 3402 |
if(len>LIMIT_FOR_COST_4){ |
| 3403 |
score+=(len-LIMIT_FOR_COST_4)*POINTSoff_INS4; |
| 3404 |
len=LIMIT_FOR_COST_4; |
| 3405 |
} |
| 3406 |
if(len>LIMIT_FOR_COST_3){ |
| 3407 |
score+=(len-LIMIT_FOR_COST_3)*POINTSoff_INS3; |
| 3408 |
len=LIMIT_FOR_COST_3; |
| 3409 |
} |
| 3410 |
if(len>1){ |
| 3411 |
score+=(len-1)*POINTSoff_INS2; |
| 3412 |
} |
| 3413 |
return score; |
| 3414 |
} |
| 3415 |
|
| 3416 |
|
| 3417 |
private final int[][][] packed; |
| 3418 |
|
| 3419 |
private final int[][][] bpacked; |
| 3420 |
|
| 3421 |
private final int[][][] startmatrix; |
| 3422 |
|
| 3423 |
private final int[] col0score; |
| 3424 |
|
| 3425 |
private final byte[] grefbuffer; |
| 3426 |
private int greflimit=-1; |
| 3427 |
private int greflimit2=-1; |
| 3428 |
private int grefRefOrigin=-1; |
| 3429 |
|
| 3430 |
|
| 3431 |
|
| 3432 |
@Override |
| 3433 |
public final byte[] getGrefbuffer(){ |
| 3434 |
return grefbuffer; |
| 3435 |
} |
| 3436 |
|
| 3437 |
public final int[] vertLimit; |
| 3438 |
public final int[] horizLimit; |
| 3439 |
|
| 3440 |
@Override |
| 3441 |
public CharSequence showVertLimit(){ |
| 3442 |
StringBuilder sb=new StringBuilder(); |
| 3443 |
for(int i=0; i<=rows; i++){sb.append(vertLimit[i]>>SCOREOFFSET).append(",");} |
| 3444 |
return sb; |
| 3445 |
} |
| 3446 |
@Override |
| 3447 |
public CharSequence showHorizLimit(){ |
| 3448 |
StringBuilder sb=new StringBuilder(); |
| 3449 |
for(int i=0; i<=columns; i++){sb.append(horizLimit[i]>>SCOREOFFSET).append(",");} |
| 3450 |
return sb; |
| 3451 |
} |
| 3452 |
|
| 3453 |
public static float minIdToMinRatio(double minid){ |
| 3454 |
if(minid>1){minid=minid/100;} |
| 3455 |
assert(minid>0 && minid<=1) : "Min identity should be between 0 and 1. Values above 1 will be assumed to be percent and divided by 100."; |
| 3456 |
double matchdif=POINTS_MATCH-POINTS_MATCH2; |
| 3457 |
double match=POINTS_MATCH2; |
| 3458 |
double sub=-POINTS_MATCH2+0.5*(matchdif+POINTS_SUB)+0.5*POINTS_SUB2; |
| 3459 |
double del=0.1*(matchdif+POINTS_DEL)+0.2*POINTS_DEL2+0.4*POINTS_DEL3+0.3*POINTS_DEL4; |
| 3460 |
double ins=-POINTS_MATCH2+0.4*(matchdif+POINTS_INS)+0.3*(POINTS_INS2)+0.3*(POINTS_INS3); |
| 3461 |
double badAvg=.7*sub+.2*del+.1*ins; |
| 3462 |
double badFraction=1-minid; |
| 3463 |
double minratio=(match+badFraction*badAvg)/match; |
| 3464 |
assert(minratio<=1); |
| 3465 |
minratio=Tools.max(0.05, minratio); |
| 3466 |
return (float)minratio; |
| 3467 |
} |
| 3468 |
|
| 3469 |
public static final int TIMEBITS=11; |
| 3470 |
public static final int SCOREBITS=32-TIMEBITS; |
| 3471 |
public static final int MAX_TIME=((1<<TIMEBITS)-1); |
| 3472 |
public static final int MAX_SCORE=((1<<(SCOREBITS-1))-1)-2000; |
| 3473 |
public static final int MIN_SCORE=0-MAX_SCORE; |
| 3474 |
|
| 3475 |
public static final int SCOREOFFSET=TIMEBITS; |
| 3476 |
|
| 3477 |
public static final int TIMEMASK=~((-1)<<TIMEBITS); |
| 3478 |
public static final int SCOREMASK=(~((-1)<<SCOREBITS))<<SCOREOFFSET; |
| 3479 |
|
| 3480 |
public static final int POINTS_NOREF=0; |
| 3481 |
public static final int POINTS_NOCALL=0; |
| 3482 |
public static final int POINTS_MATCH=70; |
| 3483 |
public static final int POINTS_MATCH2=100; |
| 3484 |
public static final int POINTS_COMPATIBLE=50; |
| 3485 |
public static final int POINTS_SUB=-127; |
| 3486 |
public static final int POINTS_SUBR=-147; |
| 3487 |
public static final int POINTS_SUB2=-51; |
| 3488 |
public static final int POINTS_SUB3=-25; |
| 3489 |
public static final int POINTS_MATCHSUB=-10; |
| 3490 |
public static final int POINTS_INS=-395; |
| 3491 |
public static final int POINTS_INS2=-39; |
| 3492 |
public static final int POINTS_INS3=-23; |
| 3493 |
public static final int POINTS_INS4=-8; |
| 3494 |
public static final int POINTS_DEL=-472; |
| 3495 |
public static final int POINTS_DEL2=-33; |
| 3496 |
public static final int POINTS_DEL3=-9; |
| 3497 |
public static final int POINTS_DEL4=-1; |
| 3498 |
public static final int POINTS_DEL5=-1; |
| 3499 |
public static final int POINTS_DEL_REF_N=-10; |
| 3500 |
public static final int POINTS_GAP=0-GAPCOST; |
| 3501 |
|
| 3502 |
public static final int TIMESLIP=4; |
| 3503 |
public static final int MASK5=TIMESLIP-1; |
| 3504 |
static{assert(Integer.bitCount(TIMESLIP)==1);} |
| 3505 |
|
| 3506 |
|
| 3507 |
private static final int BARRIER_I1=2; |
| 3508 |
private static final int BARRIER_D1=3; |
| 3509 |
|
| 3510 |
|
| 3511 |
public static final int LIMIT_FOR_COST_3=5; |
| 3512 |
public static final int LIMIT_FOR_COST_4=20; |
| 3513 |
public static final int LIMIT_FOR_COST_5=80; |
| 3514 |
|
| 3515 |
public static final int BAD=MIN_SCORE-1; |
| 3516 |
|
| 3517 |
|
| 3518 |
public static final int POINTSoff_NOREF=(POINTS_NOREF<<SCOREOFFSET); |
| 3519 |
public static final int POINTSoff_NOCALL=(POINTS_NOCALL<<SCOREOFFSET); |
| 3520 |
public static final int POINTSoff_MATCH=(POINTS_MATCH<<SCOREOFFSET); |
| 3521 |
public static final int POINTSoff_MATCH2=(POINTS_MATCH2<<SCOREOFFSET); |
| 3522 |
public static final int POINTSoff_COMPATIBLE=(POINTS_COMPATIBLE<<SCOREOFFSET); |
| 3523 |
public static final int POINTSoff_SUB=(POINTS_SUB<<SCOREOFFSET); |
| 3524 |
public static final int POINTSoff_SUBR=(POINTS_SUBR<<SCOREOFFSET); |
| 3525 |
public static final int POINTSoff_SUB2=(POINTS_SUB2<<SCOREOFFSET); |
| 3526 |
public static final int POINTSoff_SUB3=(POINTS_SUB3<<SCOREOFFSET); |
| 3527 |
public static final int POINTSoff_MATCHSUB=(POINTS_MATCHSUB<<SCOREOFFSET); |
| 3528 |
public static final int POINTSoff_INS=(POINTS_INS<<SCOREOFFSET); |
| 3529 |
public static final int POINTSoff_INS2=(POINTS_INS2<<SCOREOFFSET); |
| 3530 |
public static final int POINTSoff_INS3=(POINTS_INS3<<SCOREOFFSET); |
| 3531 |
public static final int POINTSoff_INS4=(POINTS_INS4<<SCOREOFFSET); |
| 3532 |
public static final int POINTSoff_DEL=(POINTS_DEL<<SCOREOFFSET); |
| 3533 |
public static final int POINTSoff_DEL2=(POINTS_DEL2<<SCOREOFFSET); |
| 3534 |
public static final int POINTSoff_DEL3=(POINTS_DEL3<<SCOREOFFSET); |
| 3535 |
public static final int POINTSoff_DEL4=(POINTS_DEL4<<SCOREOFFSET); |
| 3536 |
public static final int POINTSoff_DEL5=(POINTS_DEL5<<SCOREOFFSET); |
| 3537 |
public static final int POINTSoff_GAP=(POINTS_GAP<<SCOREOFFSET); |
| 3538 |
public static final int POINTSoff_DEL_REF_N=(POINTS_DEL_REF_N<<SCOREOFFSET); |
| 3539 |
public static final int BADoff=(BAD<<SCOREOFFSET); |
| 3540 |
public static final int MAXoff_SCORE=MAX_SCORE<<SCOREOFFSET; |
| 3541 |
public static final int MINoff_SCORE=MIN_SCORE<<SCOREOFFSET; |
| 3542 |
|
| 3543 |
|
| 3544 |
@Override |
| 3545 |
public final int POINTS_NOREF(){return POINTS_NOREF;} |
| 3546 |
@Override |
| 3547 |
public final int POINTS_NOCALL(){return POINTS_NOCALL;} |
| 3548 |
@Override |
| 3549 |
public final int POINTS_MATCH(){return POINTS_MATCH;} |
| 3550 |
@Override |
| 3551 |
public final int POINTS_MATCH2(){return POINTS_MATCH2;} |
| 3552 |
@Override |
| 3553 |
public final int POINTS_COMPATIBLE(){return POINTS_COMPATIBLE;} |
| 3554 |
@Override |
| 3555 |
public final int POINTS_SUB(){return POINTS_SUB;} |
| 3556 |
@Override |
| 3557 |
public final int POINTS_SUBR(){return POINTS_SUBR;} |
| 3558 |
@Override |
| 3559 |
public final int POINTS_SUB2(){return POINTS_SUB2;} |
| 3560 |
@Override |
| 3561 |
public final int POINTS_SUB3(){return POINTS_SUB3;} |
| 3562 |
@Override |
| 3563 |
public final int POINTS_MATCHSUB(){return POINTS_MATCHSUB;} |
| 3564 |
@Override |
| 3565 |
public final int POINTS_INS(){return POINTS_INS;} |
| 3566 |
@Override |
| 3567 |
public final int POINTS_INS2(){return POINTS_INS2;} |
| 3568 |
@Override |
| 3569 |
public final int POINTS_INS3(){return POINTS_INS3;} |
| 3570 |
@Override |
| 3571 |
public final int POINTS_INS4(){return POINTS_INS4;} |
| 3572 |
@Override |
| 3573 |
public final int POINTS_DEL(){return POINTS_DEL;} |
| 3574 |
@Override |
| 3575 |
public final int POINTS_DEL2(){return POINTS_DEL2;} |
| 3576 |
@Override |
| 3577 |
public final int POINTS_DEL3(){return POINTS_DEL3;} |
| 3578 |
@Override |
| 3579 |
public final int POINTS_DEL4(){return POINTS_DEL4;} |
| 3580 |
@Override |
| 3581 |
public final int POINTS_DEL5(){return POINTS_DEL5;} |
| 3582 |
@Override |
| 3583 |
public final int POINTS_DEL_REF_N(){return POINTS_DEL_REF_N;} |
| 3584 |
@Override |
| 3585 |
public final int POINTS_GAP(){return POINTS_GAP;} |
| 3586 |
|
| 3587 |
@Override |
| 3588 |
public final int TIMESLIP(){return TIMESLIP;} |
| 3589 |
@Override |
| 3590 |
public final int MASK5(){return MASK5;} |
| 3591 |
@Override |
| 3592 |
public final int SCOREOFFSET(){return SCOREOFFSET();} |
| 3593 |
|
| 3594 |
@Override |
| 3595 |
final int BARRIER_I1(){return BARRIER_I1;} |
| 3596 |
@Override |
| 3597 |
final int BARRIER_D1(){return BARRIER_D1;} |
| 3598 |
|
| 3599 |
@Override |
| 3600 |
public final int LIMIT_FOR_COST_3(){return LIMIT_FOR_COST_3;} |
| 3601 |
@Override |
| 3602 |
public final int LIMIT_FOR_COST_4(){return LIMIT_FOR_COST_4;} |
| 3603 |
@Override |
| 3604 |
public final int LIMIT_FOR_COST_5(){return LIMIT_FOR_COST_5;} |
| 3605 |
|
| 3606 |
@Override |
| 3607 |
public final int BAD(){return BAD;} |
| 3608 |
|
| 3609 |
|
| 3610 |
private int rows; |
| 3611 |
private int columns; |
| 3612 |
|
| 3613 |
} |