| 1 |
package align2; |
| 2 |
|
| 3 |
import java.util.Arrays; |
| 4 |
|
| 5 |
import dna.AminoAcid; |
| 6 |
import shared.KillSwitch; |
| 7 |
import shared.Tools; |
| 8 |
import stream.Read; |
| 9 |
import stream.SiteScore; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
public final class MultiStateAligner9PacBio extends MSA{ |
| 14 |
|
| 15 |
|
| 16 |
public static void main(String[] args){ |
| 17 |
byte[] read=args[0].getBytes(); |
| 18 |
byte[] ref=args[1].getBytes(); |
| 19 |
|
| 20 |
byte[] original=ref; |
| 21 |
|
| 22 |
MultiStateAligner9PacBio msa=new MultiStateAligner9PacBio(read.length, ref.length); |
| 23 |
|
| 24 |
System.out.println("Initial: "); |
| 25 |
printMatrix(msa.packed, read.length, ref.length, TIMEMASK, SCOREOFFSET); |
| 26 |
|
| 27 |
int[] max=msa.fillLimited(read, ref, 0, ref.length-1, 0, null); |
| 28 |
|
| 29 |
System.out.println("Max: "+Arrays.toString(max)); |
| 30 |
|
| 31 |
System.out.println("Final: "); |
| 32 |
printMatrix(msa.packed, read.length, ref.length, TIMEMASK, SCOREOFFSET); |
| 33 |
|
| 34 |
byte[] out=msa.traceback(read, ref, 0, ref.length-1, max[0], max[1], max[2], false); |
| 35 |
|
| 36 |
int[] score=null; |
| 37 |
score=msa.score(read, ref, 0, ref.length-1, max[0], max[1], max[2], false); |
| 38 |
|
| 39 |
System.out.println(new String(ref)); |
| 40 |
System.out.println(new String(read)); |
| 41 |
System.out.println(new String(out)); |
| 42 |
System.out.println("Score: "+Arrays.toString(score)); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
public MultiStateAligner9PacBio(int maxRows_, int maxColumns_){ |
| 47 |
super(maxRows_, maxColumns_); |
| 48 |
|
| 49 |
packed=KillSwitch.allocInt3D(3, maxRows+1, maxColumns+1); |
| 50 |
grefbuffer=KillSwitch.allocByte1D(maxColumns+2); |
| 51 |
vertLimit=KillSwitch.allocInt1D(maxRows+1); |
| 52 |
horizLimit=KillSwitch.allocInt1D(maxColumns+1); |
| 53 |
|
| 54 |
Arrays.fill(vertLimit, BADoff); |
| 55 |
Arrays.fill(horizLimit, BADoff); |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
for(int matrix=0; matrix<packed.length; matrix++){ |
| 62 |
for(int i=1; i<=maxRows; i++){ |
| 63 |
for(int j=0; j<packed[matrix][i].length; j++){ |
| 64 |
packed[matrix][i][j]|=BADoff; |
| 65 |
} |
| 66 |
|
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
for(int i=0; i<=maxRows; i++){ |
| 72 |
|
| 73 |
int prevScore=(i<2 ? 0 : packed[matrix][i-1][0]); |
| 74 |
int score=(i<2 ? (i*POINTSoff_INS) : |
| 75 |
(i<LIMIT_FOR_COST_3 ? prevScore+POINTSoff_INS2 : |
| 76 |
(i<LIMIT_FOR_COST_4 ? prevScore+POINTSoff_INS3 : prevScore+POINTSoff_INS4))); |
| 77 |
|
| 78 |
packed[matrix][i][0]=score; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
@Override |
| 90 |
|
| 91 |
|
| 92 |
public final int[] fillLimited(byte[] read, byte[] ref, int refStartLoc, int refEndLoc, int minScore, int[] gaps){ |
| 93 |
if(gaps==null){return fillLimitedX(read, ref, refStartLoc, refEndLoc, minScore);} |
| 94 |
else{ |
| 95 |
byte[] gref=makeGref(ref, gaps, refStartLoc, refEndLoc, read); |
| 96 |
|
| 97 |
if(verbose && greflimit>0 && greflimit<500){ |
| 98 |
System.err.println(new String(gref, 0, greflimit)); |
| 99 |
} |
| 100 |
|
| 101 |
assert(gref!=null) : "Excessively long read:\n"+new String(read); |
| 102 |
return fillLimitedX(read, gref, 0, greflimit, minScore); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
private final int[] fillLimitedX(byte[] read, byte[] ref, int refStartLoc, int refEndLoc, int minScore){ |
| 110 |
if(verbose){System.err.println("fillLimitedX");} |
| 111 |
|
| 112 |
|
| 113 |
rows=read.length; |
| 114 |
columns=refEndLoc-refStartLoc+1; |
| 115 |
|
| 116 |
final int halfband=(bandwidth<1 && bandwidthRatio<=0) ? 0 : |
| 117 |
Tools.max(Tools.min(bandwidth<1 ? 9999999 : bandwidth, bandwidthRatio<=0 ? 9999999 : 8+(int)(rows*bandwidthRatio)), (columns-rows+8))/2; |
| 118 |
|
| 119 |
if(minScore<1 || (columns+rows<90) || ((halfband<1 || halfband*3>columns) && (columns>read.length+Tools.min(170, read.length+20)))){ |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
return fillUnlimited(read, ref, refStartLoc, refEndLoc); |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
final int BARRIER_I2=rows-BARRIER_I1, BARRIER_I2b=columns-1; |
| 128 |
final int BARRIER_D2=rows-BARRIER_D1; |
| 129 |
|
| 130 |
minScore-=MIN_SCORE_ADJUST; |
| 131 |
|
| 132 |
assert(rows<=maxRows) : "Check that values are in-bounds before calling this function: "+rows+", "+maxRows+"\n"+ |
| 133 |
refStartLoc+", "+refEndLoc+", "+rows+", "+maxRows+", "+columns+", "+maxColumns+"\n"+new String(read)+"\n"; |
| 134 |
assert(columns<=maxColumns) : "Check that values are in-bounds before calling this function: "+columns+", "+maxColumns+"\n"+ |
| 135 |
refStartLoc+", "+refEndLoc+", "+rows+", "+maxRows+", "+columns+", "+maxColumns+"\n"+new String(read)+"\n"; |
| 136 |
|
| 137 |
assert(refStartLoc>=0) : "Check that values are in-bounds before calling this function: "+refStartLoc+"\n"+ |
| 138 |
refStartLoc+", "+refEndLoc+", "+rows+", "+maxRows+", "+columns+", "+maxColumns+"\n"+new String(read)+"\n"; |
| 139 |
assert(refEndLoc<ref.length) : "Check that values are in-bounds before calling this function: "+refEndLoc+", "+ref.length+"\n"+ |
| 140 |
refStartLoc+", "+refEndLoc+", "+rows+", "+maxRows+", "+columns+", "+maxColumns+"\n"+new String(read)+"\n"; |
| 141 |
|
| 142 |
if(verbose){ |
| 143 |
System.err.println("Clearing matrix due to verbose mode."); |
| 144 |
for(int x=0; x<packed.length; x++){ |
| 145 |
for(int y=1; y<rows+1; y++){ |
| 146 |
Arrays.fill(packed[x][y], 1, columns+1, BADoff); |
| 147 |
} |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
for(int x=0; x<packed.length; x++){ |
| 152 |
|
| 153 |
|
| 154 |
Arrays.fill(packed[x][rows], 1, columns+1, BADoff); |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
} |
| 159 |
|
| 160 |
int minGoodCol=1; |
| 161 |
int maxGoodCol=columns; |
| 162 |
|
| 163 |
final int minScore_off=(minScore<<SCOREOFFSET); |
| 164 |
final int maxGain=(read.length-1)*POINTSoff_MATCH2+POINTSoff_MATCH; |
| 165 |
final int floor=minScore_off-maxGain; |
| 166 |
|
| 167 |
final int subfloor=floor-5*POINTSoff_MATCH2; |
| 168 |
assert(subfloor>BADoff); |
| 169 |
assert(subfloor<minScore_off) : minScore_off+", "+floor+", "+BADoff+", "+subfloor; |
| 170 |
|
| 171 |
if(verbose2){ |
| 172 |
System.out.println(); |
| 173 |
System.out.println("minScore="+minScore+"\t"+minScore_off); |
| 174 |
System.out.println("maxGain="+(maxGain>>SCOREOFFSET)+"\t"+(maxGain)); |
| 175 |
System.out.println("floor="+(floor>>SCOREOFFSET)+"\t"+(floor)); |
| 176 |
System.out.println("subfloor="+(subfloor>>SCOREOFFSET)+"\t"+(subfloor)); |
| 177 |
System.out.println("BADoff="+(BADoff>>SCOREOFFSET)+"\t"+(BADoff)); |
| 178 |
System.out.println("maxGain="+(maxGain>>SCOREOFFSET)+"\t"+(maxGain)); |
| 179 |
System.out.println(); |
| 180 |
} |
| 181 |
|
| 182 |
vertLimit[rows]=minScore_off; |
| 183 |
boolean prevDefined=false; |
| 184 |
for(int i=rows-1; i>=0; i--){ |
| 185 |
byte c=read[i]; |
| 186 |
if(AminoAcid.isFullyDefined(c)){ |
| 187 |
vertLimit[i]=Tools.max(vertLimit[i+1]-(prevDefined ? POINTSoff_MATCH2 : POINTSoff_MATCH), floor); |
| 188 |
prevDefined=true; |
| 189 |
}else{ |
| 190 |
vertLimit[i]=Tools.max(vertLimit[i+1]-POINTSoff_NOCALL, floor); |
| 191 |
prevDefined=false; |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
horizLimit[columns]=minScore_off; |
| 196 |
prevDefined=false; |
| 197 |
for(int i=columns-1; i>=0; i--){ |
| 198 |
byte c=ref[refStartLoc+i]; |
| 199 |
if(AminoAcid.isFullyDefined(c)){ |
| 200 |
horizLimit[i]=Tools.max(horizLimit[i+1]-(prevDefined ? POINTSoff_MATCH2 : POINTSoff_MATCH), floor); |
| 201 |
prevDefined=true; |
| 202 |
}else{ |
| 203 |
horizLimit[i]=Tools.max(horizLimit[i+1]-(prevDefined && c==GAPC ? POINTSoff_DEL : POINTSoff_NOREF), floor); |
| 204 |
prevDefined=false; |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
for(int row=1; row<=rows; row++){ |
| 219 |
|
| 220 |
final int colStart=(halfband<1 ? minGoodCol : Tools.max(minGoodCol, row-halfband)); |
| 221 |
final int colStop=(halfband<1 ? maxGoodCol : Tools.min(maxGoodCol, row+halfband*2-1)); |
| 222 |
|
| 223 |
minGoodCol=-1; |
| 224 |
maxGoodCol=-2; |
| 225 |
|
| 226 |
final int vlimit=vertLimit[row]; |
| 227 |
|
| 228 |
if(verbose2){ |
| 229 |
System.out.println(); |
| 230 |
System.out.println("row="+row); |
| 231 |
System.out.println("colStart="+colStart); |
| 232 |
System.out.println("colStop="+colStop); |
| 233 |
System.out.println("vlimit="+(vlimit>>SCOREOFFSET)+"\t"+(vlimit)); |
| 234 |
} |
| 235 |
|
| 236 |
if(colStart<0 || colStop<colStart){break;} |
| 237 |
|
| 238 |
|
| 239 |
if(colStart>1){ |
| 240 |
assert(row>0); |
| 241 |
packed[MODE_MS][row][colStart-1]=subfloor; |
| 242 |
packed[MODE_INS][row][colStart-1]=subfloor; |
| 243 |
packed[MODE_DEL][row][colStart-1]=subfloor; |
| 244 |
} |
| 245 |
|
| 246 |
|
| 247 |
for(int col=colStart; col<=columns; col++){ |
| 248 |
|
| 249 |
|
| 250 |
if(verbose2){ |
| 251 |
System.err.println("\ncol "+col); |
| 252 |
} |
| 253 |
|
| 254 |
final byte call0=(row<2 ? (byte)'?' : read[row-2]); |
| 255 |
final byte call1=read[row-1]; |
| 256 |
final byte ref0=(col<2 ? (byte)'!' : ref[refStartLoc+col-2]); |
| 257 |
final byte ref1=ref[refStartLoc+col-1]; |
| 258 |
|
| 259 |
final boolean gap=(ref1==GAPC); |
| 260 |
assert(call1!=GAPC); |
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
final boolean match=(call1==ref1 && ref1!='N'); |
| 265 |
final boolean prevMatch=(call0==ref0 && ref0!='N'); |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
iterationsLimited++; |
| 270 |
final int limit=Tools.max(vlimit, horizLimit[col]); |
| 271 |
final int limit3=Tools.max(floor, (match ? limit-POINTSoff_MATCH2 : limit-POINTSoff_SUB3)); |
| 272 |
|
| 273 |
final int delNeeded=Tools.max(0, row-col-1); |
| 274 |
final int insNeeded=Tools.max(0, (rows-row)-(columns-col)-1); |
| 275 |
|
| 276 |
final int delPenalty=calcDelScoreOffset(delNeeded); |
| 277 |
final int insPenalty=calcInsScoreOffset(insNeeded); |
| 278 |
|
| 279 |
|
| 280 |
final int scoreFromDiag_MS=packed[MODE_MS][row-1][col-1]&SCOREMASK; |
| 281 |
final int scoreFromDel_MS=packed[MODE_DEL][row-1][col-1]&SCOREMASK; |
| 282 |
final int scoreFromIns_MS=packed[MODE_INS][row-1][col-1]&SCOREMASK; |
| 283 |
|
| 284 |
final int scoreFromDiag_DEL=packed[MODE_MS][row][col-1]&SCOREMASK; |
| 285 |
final int scoreFromDel_DEL=packed[MODE_DEL][row][col-1]&SCOREMASK; |
| 286 |
|
| 287 |
final int scoreFromDiag_INS=packed[MODE_MS][row-1][col]&SCOREMASK; |
| 288 |
final int scoreFromIns_INS=packed[MODE_INS][row-1][col]&SCOREMASK; |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
if(gap || (scoreFromDiag_MS<=limit3 && scoreFromDel_MS<=limit3 && scoreFromIns_MS<=limit3)){ |
| 296 |
packed[MODE_MS][row][col]=subfloor; |
| 297 |
}else{ |
| 298 |
final int streak=(packed[MODE_MS][row-1][col-1]&TIMEMASK); |
| 299 |
|
| 300 |
{ |
| 301 |
|
| 302 |
int score; |
| 303 |
int time; |
| 304 |
byte prevState; |
| 305 |
|
| 306 |
if(match){ |
| 307 |
|
| 308 |
int scoreMS=scoreFromDiag_MS+(prevMatch ? POINTSoff_MATCH2 : POINTSoff_MATCH); |
| 309 |
int scoreD=scoreFromDel_MS+POINTSoff_MATCH; |
| 310 |
int scoreI=scoreFromIns_MS+POINTSoff_MATCH; |
| 311 |
|
| 312 |
|
| 313 |
if(scoreMS>=scoreD && scoreMS>=scoreI){ |
| 314 |
score=scoreMS; |
| 315 |
time=(prevMatch ? streak+1 : 1); |
| 316 |
prevState=MODE_MS; |
| 317 |
}else if(scoreD>=scoreI){ |
| 318 |
score=scoreD; |
| 319 |
time=1; |
| 320 |
prevState=MODE_DEL; |
| 321 |
}else{ |
| 322 |
score=scoreI; |
| 323 |
time=1; |
| 324 |
prevState=MODE_INS; |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
}else{ |
| 337 |
|
| 338 |
int scoreMS; |
| 339 |
if(ref1!='N' && call1!='N'){ |
| 340 |
scoreMS=scoreFromDiag_MS+(prevMatch ? (streak<=1 ? POINTSoff_SUBR : POINTSoff_SUB) : |
| 341 |
(streak==0 ? POINTSoff_SUB : streak<LIMIT_FOR_COST_3 ? POINTSoff_SUB2 : POINTSoff_SUB3)); |
| 342 |
}else{ |
| 343 |
scoreMS=scoreFromDiag_MS+POINTSoff_NOCALL; |
| 344 |
} |
| 345 |
|
| 346 |
int scoreD=scoreFromDel_MS+POINTSoff_SUB; |
| 347 |
int scoreI=scoreFromIns_MS+POINTSoff_SUB; |
| 348 |
|
| 349 |
if(scoreMS>=scoreD && scoreMS>=scoreI){ |
| 350 |
score=scoreMS; |
| 351 |
time=(prevMatch ? 1 : streak+1); |
| 352 |
|
| 353 |
prevState=MODE_MS; |
| 354 |
}else if(scoreD>=scoreI){ |
| 355 |
score=scoreD; |
| 356 |
time=1; |
| 357 |
prevState=MODE_DEL; |
| 358 |
}else{ |
| 359 |
score=scoreI; |
| 360 |
time=1; |
| 361 |
prevState=MODE_INS; |
| 362 |
} |
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
} |
| 373 |
|
| 374 |
final int limit2; |
| 375 |
if(delNeeded>0){ |
| 376 |
limit2=limit-delPenalty; |
| 377 |
}else if(insNeeded>0){ |
| 378 |
limit2=limit-insPenalty; |
| 379 |
}else{ |
| 380 |
limit2=limit; |
| 381 |
} |
| 382 |
assert(limit2>=limit); |
| 383 |
|
| 384 |
if(verbose2){System.err.println("MS: \tlimit2="+(limit2>>SCOREOFFSET)+"\t, score="+(score>>SCOREOFFSET));} |
| 385 |
|
| 386 |
if(score>=limit2){ |
| 387 |
maxGoodCol=col; |
| 388 |
if(minGoodCol<0){minGoodCol=col;} |
| 389 |
}else{ |
| 390 |
score=subfloor; |
| 391 |
} |
| 392 |
|
| 393 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 394 |
assert(score>=MINoff_SCORE || score==BADoff) : "Score overflow - use MSA2 instead"; |
| 395 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 396 |
|
| 397 |
packed[MODE_MS][row][col]=(score|time); |
| 398 |
assert((score&SCOREMASK)==score); |
| 399 |
|
| 400 |
assert((time&TIMEMASK)==time); |
| 401 |
} |
| 402 |
} |
| 403 |
|
| 404 |
if((scoreFromDiag_DEL<=limit && scoreFromDel_DEL<=limit) || row<BARRIER_D1 || row>BARRIER_D2){ |
| 405 |
|
| 406 |
packed[MODE_DEL][row][col]=subfloor; |
| 407 |
}else{ |
| 408 |
|
| 409 |
final int streak=packed[MODE_DEL][row][col-1]&TIMEMASK; |
| 410 |
|
| 411 |
int scoreMS=scoreFromDiag_DEL+POINTSoff_DEL; |
| 412 |
int scoreD=scoreFromDel_DEL+(streak==0 ? POINTSoff_DEL : |
| 413 |
streak<LIMIT_FOR_COST_3 ? POINTSoff_DEL2 : |
| 414 |
streak<LIMIT_FOR_COST_4 ? POINTSoff_DEL3 : |
| 415 |
streak<LIMIT_FOR_COST_5 ? POINTSoff_DEL4 : |
| 416 |
((streak&MASK5)==0 ? POINTSoff_DEL5 : 0)); |
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
if(ref1=='N'){ |
| 421 |
scoreMS+=POINTSoff_DEL_REF_N; |
| 422 |
scoreD+=POINTSoff_DEL_REF_N; |
| 423 |
}else if(gap){ |
| 424 |
scoreMS+=POINTSoff_GAP; |
| 425 |
scoreD+=POINTSoff_GAP; |
| 426 |
} |
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
int score; |
| 431 |
int time; |
| 432 |
byte prevState; |
| 433 |
if(scoreMS>=scoreD){ |
| 434 |
score=scoreMS; |
| 435 |
time=1; |
| 436 |
prevState=MODE_MS; |
| 437 |
}else{ |
| 438 |
score=scoreD; |
| 439 |
time=streak+1; |
| 440 |
prevState=MODE_DEL; |
| 441 |
} |
| 442 |
|
| 443 |
final int limit2; |
| 444 |
if(insNeeded>0){ |
| 445 |
limit2=limit-insPenalty; |
| 446 |
}else if(delNeeded>0){ |
| 447 |
limit2=limit-calcDelScoreOffset(time+delNeeded)+calcDelScoreOffset(time); |
| 448 |
}else{ |
| 449 |
limit2=limit; |
| 450 |
} |
| 451 |
assert(limit2>=limit); |
| 452 |
if(verbose2){System.err.println("DEL: \tlimit2="+(limit2>>SCOREOFFSET)+"\t, score="+(score>>SCOREOFFSET));} |
| 453 |
|
| 454 |
if(score>=limit2){ |
| 455 |
maxGoodCol=col; |
| 456 |
if(minGoodCol<0){minGoodCol=col;} |
| 457 |
}else{ |
| 458 |
score=subfloor; |
| 459 |
} |
| 460 |
|
| 461 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 462 |
assert(score>=MINoff_SCORE || score==BADoff) : "Score overflow - use MSA2 instead"; |
| 463 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 464 |
|
| 465 |
packed[MODE_DEL][row][col]=(score|time); |
| 466 |
assert((score&SCOREMASK)==score); |
| 467 |
|
| 468 |
assert((time&TIMEMASK)==time); |
| 469 |
} |
| 470 |
|
| 471 |
|
| 472 |
if(gap || (scoreFromDiag_INS<=limit && scoreFromIns_INS<=limit) || (row<BARRIER_I1 && col>1) || (row>BARRIER_I2 && col<BARRIER_I2b)){ |
| 473 |
packed[MODE_INS][row][col]=subfloor; |
| 474 |
}else{ |
| 475 |
|
| 476 |
final int streak=packed[MODE_INS][row-1][col]&TIMEMASK; |
| 477 |
|
| 478 |
int scoreMS=scoreFromDiag_INS+POINTSoff_INS; |
| 479 |
|
| 480 |
int scoreI=scoreFromIns_INS+(streak==0 ? POINTSoff_INS : |
| 481 |
streak<LIMIT_FOR_COST_3 ? POINTSoff_INS2 : |
| 482 |
streak<LIMIT_FOR_COST_4 ? POINTSoff_INS3 : POINTSoff_INS4); |
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
int score; |
| 493 |
int time; |
| 494 |
byte prevState; |
| 495 |
if(scoreMS>=scoreI){ |
| 496 |
score=scoreMS; |
| 497 |
time=1; |
| 498 |
prevState=MODE_MS; |
| 499 |
}else{ |
| 500 |
score=scoreI; |
| 501 |
time=streak+1; |
| 502 |
prevState=MODE_INS; |
| 503 |
} |
| 504 |
|
| 505 |
final int limit2; |
| 506 |
if(delNeeded>0){ |
| 507 |
limit2=limit-delPenalty; |
| 508 |
}else if(insNeeded>0){ |
| 509 |
limit2=limit-calcInsScoreOffset(time+insNeeded)+calcInsScoreOffset(time); |
| 510 |
}else{ |
| 511 |
limit2=limit; |
| 512 |
} |
| 513 |
assert(limit2>=limit); |
| 514 |
|
| 515 |
if(verbose2){System.err.println("INS: \tlimit2="+(limit2>>SCOREOFFSET)+"\t, score="+(score>>SCOREOFFSET));} |
| 516 |
if(score>=limit2){ |
| 517 |
maxGoodCol=col; |
| 518 |
if(minGoodCol<0){minGoodCol=col;} |
| 519 |
}else{ |
| 520 |
score=subfloor; |
| 521 |
} |
| 522 |
|
| 523 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 524 |
assert(score>=MINoff_SCORE || score==BADoff) : "Score overflow - use MSA2 instead"; |
| 525 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 526 |
|
| 527 |
packed[MODE_INS][row][col]=(score|time); |
| 528 |
assert((score&SCOREMASK)==score); |
| 529 |
|
| 530 |
assert((time&TIMEMASK)==time); |
| 531 |
} |
| 532 |
|
| 533 |
|
| 534 |
if(col>=colStop){ |
| 535 |
if(col>colStop && (maxGoodCol<col || halfband>0)){break;} |
| 536 |
if(row>1){ |
| 537 |
packed[MODE_MS][row-1][col+1]=subfloor; |
| 538 |
packed[MODE_INS][row-1][col+1]=subfloor; |
| 539 |
packed[MODE_DEL][row-1][col+1]=subfloor; |
| 540 |
} |
| 541 |
} |
| 542 |
} |
| 543 |
} |
| 544 |
|
| 545 |
|
| 546 |
int maxCol=-1; |
| 547 |
int maxState=-1; |
| 548 |
int maxScore=Integer.MIN_VALUE; |
| 549 |
|
| 550 |
for(int state=0; state<packed.length; state++){ |
| 551 |
for(int col=1; col<=columns; col++){ |
| 552 |
int x=packed[state][rows][col]&SCOREMASK; |
| 553 |
if(x>maxScore){ |
| 554 |
maxScore=x; |
| 555 |
maxCol=col; |
| 556 |
maxState=state; |
| 557 |
} |
| 558 |
} |
| 559 |
} |
| 560 |
|
| 561 |
assert(maxScore>=BADoff); |
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
if(verbose){ |
| 570 |
System.out.println("Filled matrix."); |
| 571 |
printMatrix(packed, rows, columns, TIMEMASK, SCOREOFFSET); |
| 572 |
} |
| 573 |
if(verbose){System.err.println("maxscore="+(maxScore>>SCOREOFFSET)+", minscore="+(minScore_off>>SCOREOFFSET));} |
| 574 |
|
| 575 |
if(maxScore<minScore_off){ |
| 576 |
return null; |
| 577 |
} |
| 578 |
|
| 579 |
maxScore>>=SCOREOFFSET; |
| 580 |
|
| 581 |
if(verbose){ |
| 582 |
System.err.println("Returning "+rows+", "+maxCol+", "+maxState+", "+maxScore); |
| 583 |
} |
| 584 |
return new int[] {rows, maxCol, maxState, maxScore}; |
| 585 |
} |
| 586 |
|
| 587 |
@Override |
| 588 |
|
| 589 |
|
| 590 |
public final int[] fillUnlimited(byte[] read, byte[] ref, int refStartLoc, int refEndLoc, int[] gaps){ |
| 591 |
if(gaps==null){return fillUnlimited(read, ref, refStartLoc, refEndLoc);} |
| 592 |
else{ |
| 593 |
byte[] gref=makeGref(ref, gaps, refStartLoc, refEndLoc, read); |
| 594 |
assert(gref!=null) : "Excessively long read:\n"+new String(read); |
| 595 |
return fillUnlimited(read, gref, 0, greflimit); |
| 596 |
} |
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
private final int[] fillUnlimited(byte[] read, byte[] ref, int refStartLoc, int refEndLoc){ |
| 603 |
rows=read.length; |
| 604 |
columns=refEndLoc-refStartLoc+1; |
| 605 |
|
| 606 |
final int maxGain=(read.length-1)*POINTSoff_MATCH2+POINTSoff_MATCH; |
| 607 |
final int subfloor=0-2*maxGain; |
| 608 |
assert(subfloor>BADoff && subfloor*2>BADoff) : (read.length-1)+", "+maxGain+", "+subfloor+", "+(subfloor*2)+", "+BADoff+"\n" |
| 609 |
+rows+", "+columns+", "+POINTSoff_MATCH2+", "+SCOREOFFSET+"\n"+new String(read)+"\n"; |
| 610 |
|
| 611 |
final int BARRIER_I2=rows-BARRIER_I1, BARRIER_I2b=columns-1; |
| 612 |
final int BARRIER_D2=rows-BARRIER_D1; |
| 613 |
|
| 614 |
|
| 615 |
if(rows>maxRows || columns>maxColumns){ |
| 616 |
throw new RuntimeException("rows="+rows+", maxRows="+maxRows+", cols="+columns+", maxCols="+maxColumns+"\n"+new String(read)+"\n"); |
| 617 |
} |
| 618 |
|
| 619 |
assert(rows<=maxRows) : "Check that values are in-bounds before calling this function: "+rows+", "+maxRows; |
| 620 |
assert(columns<=maxColumns) : "Check that values are in-bounds before calling this function: "+columns+", "+maxColumns; |
| 621 |
|
| 622 |
assert(refStartLoc>=0) : "Check that values are in-bounds before calling this function: "+refStartLoc; |
| 623 |
assert(refEndLoc<ref.length) : "Check that values are in-bounds before calling this function: "+refEndLoc+", "+ref.length; |
| 624 |
|
| 625 |
for(int row=1; row<=rows; row++){ |
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
for(int col=1; col<=columns; col++){ |
| 631 |
iterationsUnlimited++; |
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
final byte call0=(row<2 ? (byte)'?' : read[row-2]); |
| 637 |
final byte call1=read[row-1]; |
| 638 |
final byte ref0=(col<2 ? (byte)'!' : ref[refStartLoc+col-2]); |
| 639 |
final byte ref1=ref[refStartLoc+col-1]; |
| 640 |
|
| 641 |
final boolean match=(call1==ref1 && ref1!='N'); |
| 642 |
final boolean prevMatch=(call0==ref0 && ref0!='N'); |
| 643 |
|
| 644 |
final boolean gap=(ref1==GAPC); |
| 645 |
assert(call1!=GAPC); |
| 646 |
|
| 647 |
if(gap){ |
| 648 |
packed[MODE_MS][row][col]=subfloor; |
| 649 |
}else{ |
| 650 |
|
| 651 |
final int scoreFromDiag=packed[MODE_MS][row-1][col-1]&SCOREMASK; |
| 652 |
final int scoreFromDel=packed[MODE_DEL][row-1][col-1]&SCOREMASK; |
| 653 |
final int scoreFromIns=packed[MODE_INS][row-1][col-1]&SCOREMASK; |
| 654 |
final int streak=(packed[MODE_MS][row-1][col-1]&TIMEMASK); |
| 655 |
|
| 656 |
{ |
| 657 |
|
| 658 |
if(match){ |
| 659 |
|
| 660 |
int scoreMS=scoreFromDiag+(prevMatch ? POINTSoff_MATCH2 : POINTSoff_MATCH); |
| 661 |
int scoreD=scoreFromDel+POINTSoff_MATCH; |
| 662 |
int scoreI=scoreFromIns+POINTSoff_MATCH; |
| 663 |
|
| 664 |
int score; |
| 665 |
int time; |
| 666 |
|
| 667 |
if(scoreMS>=scoreD && scoreMS>=scoreI){ |
| 668 |
score=scoreMS; |
| 669 |
time=(prevMatch ? streak+1 : 1); |
| 670 |
|
| 671 |
}else if(scoreD>=scoreI){ |
| 672 |
score=scoreD; |
| 673 |
time=1; |
| 674 |
|
| 675 |
}else{ |
| 676 |
score=scoreI; |
| 677 |
time=1; |
| 678 |
|
| 679 |
} |
| 680 |
|
| 681 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 682 |
assert(score>=MINoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 683 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 684 |
|
| 685 |
packed[MODE_MS][row][col]=(score|time); |
| 686 |
assert((score&SCOREMASK)==score); |
| 687 |
|
| 688 |
assert((time&TIMEMASK)==time); |
| 689 |
|
| 690 |
}else{ |
| 691 |
|
| 692 |
int scoreMS; |
| 693 |
if(ref1!='N' && call1!='N'){ |
| 694 |
scoreMS=scoreFromDiag+(prevMatch ? (streak<=1 ? POINTSoff_SUBR : POINTSoff_SUB) : |
| 695 |
(streak==0 ? POINTSoff_SUB : streak<LIMIT_FOR_COST_3 ? POINTSoff_SUB2 : POINTSoff_SUB3)); |
| 696 |
}else{ |
| 697 |
scoreMS=scoreFromDiag+POINTSoff_NOCALL; |
| 698 |
} |
| 699 |
|
| 700 |
int scoreD=scoreFromDel+POINTSoff_SUB; |
| 701 |
int scoreI=scoreFromIns+POINTSoff_SUB; |
| 702 |
|
| 703 |
int score; |
| 704 |
int time; |
| 705 |
byte prevState; |
| 706 |
if(scoreMS>=scoreD && scoreMS>=scoreI){ |
| 707 |
score=scoreMS; |
| 708 |
time=(prevMatch ? 1 : streak+1); |
| 709 |
|
| 710 |
prevState=MODE_MS; |
| 711 |
}else if(scoreD>=scoreI){ |
| 712 |
score=scoreD; |
| 713 |
time=1; |
| 714 |
prevState=MODE_DEL; |
| 715 |
}else{ |
| 716 |
score=scoreI; |
| 717 |
time=1; |
| 718 |
prevState=MODE_INS; |
| 719 |
} |
| 720 |
|
| 721 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 722 |
assert(score>=MINoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 723 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 724 |
|
| 725 |
packed[MODE_MS][row][col]=(score|time); |
| 726 |
assert((score&SCOREMASK)==score); |
| 727 |
|
| 728 |
assert((time&TIMEMASK)==time); |
| 729 |
} |
| 730 |
} |
| 731 |
} |
| 732 |
|
| 733 |
if(row<BARRIER_D1 || row>BARRIER_D2){ |
| 734 |
packed[MODE_DEL][row][col]=subfloor; |
| 735 |
}else{ |
| 736 |
|
| 737 |
final int streak=packed[MODE_DEL][row][col-1]&TIMEMASK; |
| 738 |
|
| 739 |
final int scoreFromDiag=packed[MODE_MS][row][col-1]&SCOREMASK; |
| 740 |
final int scoreFromDel=packed[MODE_DEL][row][col-1]&SCOREMASK; |
| 741 |
|
| 742 |
int scoreMS=scoreFromDiag+POINTSoff_DEL; |
| 743 |
int scoreD=scoreFromDel+(streak==0 ? POINTSoff_DEL : |
| 744 |
streak<LIMIT_FOR_COST_3 ? POINTSoff_DEL2 : |
| 745 |
streak<LIMIT_FOR_COST_4 ? POINTSoff_DEL3 : |
| 746 |
streak<LIMIT_FOR_COST_5 ? POINTSoff_DEL4 : |
| 747 |
((streak&MASK5)==0 ? POINTSoff_DEL5 : 0)); |
| 748 |
|
| 749 |
|
| 750 |
if(ref1=='N'){ |
| 751 |
scoreMS+=POINTSoff_DEL_REF_N; |
| 752 |
scoreD+=POINTSoff_DEL_REF_N; |
| 753 |
}else if(gap){ |
| 754 |
scoreMS+=POINTSoff_GAP; |
| 755 |
scoreD+=POINTSoff_GAP; |
| 756 |
} |
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
int score; |
| 761 |
int time; |
| 762 |
byte prevState; |
| 763 |
if(scoreMS>=scoreD){ |
| 764 |
score=scoreMS; |
| 765 |
time=1; |
| 766 |
prevState=MODE_MS; |
| 767 |
}else{ |
| 768 |
score=scoreD; |
| 769 |
time=streak+1; |
| 770 |
prevState=MODE_DEL; |
| 771 |
} |
| 772 |
|
| 773 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 774 |
assert(score>=MINoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 775 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 776 |
|
| 777 |
packed[MODE_DEL][row][col]=(score|time); |
| 778 |
assert((score&SCOREMASK)==score); |
| 779 |
|
| 780 |
assert((time&TIMEMASK)==time); |
| 781 |
} |
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
if(gap || (row<BARRIER_I1 && col>1) || (row>BARRIER_I2 && col<BARRIER_I2b)){ |
| 786 |
packed[MODE_INS][row][col]=subfloor; |
| 787 |
}else{ |
| 788 |
|
| 789 |
final int streak=packed[MODE_INS][row-1][col]&TIMEMASK; |
| 790 |
|
| 791 |
final int scoreFromDiag=packed[MODE_MS][row-1][col]&SCOREMASK; |
| 792 |
final int scoreFromIns=packed[MODE_INS][row-1][col]&SCOREMASK; |
| 793 |
|
| 794 |
int scoreMS=scoreFromDiag+POINTSoff_INS; |
| 795 |
|
| 796 |
int scoreI=scoreFromIns+(streak==0 ? POINTSoff_INS : |
| 797 |
streak<LIMIT_FOR_COST_3 ? POINTSoff_INS2 : |
| 798 |
streak<LIMIT_FOR_COST_4 ? POINTSoff_INS3 : POINTSoff_INS4); |
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
int score; |
| 808 |
int time; |
| 809 |
byte prevState; |
| 810 |
if(scoreMS>=scoreI){ |
| 811 |
score=scoreMS; |
| 812 |
time=1; |
| 813 |
prevState=MODE_MS; |
| 814 |
}else{ |
| 815 |
score=scoreI; |
| 816 |
time=streak+1; |
| 817 |
prevState=MODE_INS; |
| 818 |
} |
| 819 |
|
| 820 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 821 |
assert(score>=MINoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 822 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 823 |
|
| 824 |
packed[MODE_INS][row][col]=(score|time); |
| 825 |
assert((score&SCOREMASK)==score); |
| 826 |
|
| 827 |
assert((time&TIMEMASK)==time); |
| 828 |
} |
| 829 |
} |
| 830 |
} |
| 831 |
|
| 832 |
|
| 833 |
int maxCol=-1; |
| 834 |
int maxState=-1; |
| 835 |
int maxScore=Integer.MIN_VALUE; |
| 836 |
|
| 837 |
for(int state=0; state<packed.length; state++){ |
| 838 |
for(int col=1; col<=columns; col++){ |
| 839 |
int x=packed[state][rows][col]&SCOREMASK; |
| 840 |
if(x>maxScore){ |
| 841 |
maxScore=x; |
| 842 |
maxCol=col; |
| 843 |
maxState=state; |
| 844 |
} |
| 845 |
} |
| 846 |
} |
| 847 |
maxScore>>=SCOREOFFSET; |
| 848 |
|
| 849 |
|
| 850 |
return new int[] {rows, maxCol, maxState, maxScore}; |
| 851 |
} |
| 852 |
|
| 853 |
@Override |
| 854 |
@Deprecated |
| 855 |
|
| 856 |
public final int[] fillQ(byte[] read, byte[] ref, byte[] baseScores, int refStartLoc, int refEndLoc){ |
| 857 |
assert(false) : "Needs to be redone to work with score cutoffs. Not difficult."; |
| 858 |
rows=read.length; |
| 859 |
columns=refEndLoc-refStartLoc+1; |
| 860 |
|
| 861 |
assert(rows<=maxRows) : "Check that values are in-bounds before calling this function: "+rows+", "+maxRows; |
| 862 |
assert(columns<=maxColumns) : "Check that values are in-bounds before calling this function: "+columns+", "+maxColumns; |
| 863 |
|
| 864 |
assert(refStartLoc>=0) : "Check that values are in-bounds before calling this function: "+refStartLoc; |
| 865 |
assert(refEndLoc<ref.length) : "Check that values are in-bounds before calling this function: "+refEndLoc+", "+ref.length; |
| 866 |
|
| 867 |
for(int row=1; row<=rows; row++){ |
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
for(int col=1; col<=columns; col++){ |
| 873 |
|
| 874 |
final boolean match=(read[row-1]==ref[refStartLoc+col-1]); |
| 875 |
final boolean prevMatch=(row<2 || col<2 ? false : read[row-2]==ref[refStartLoc+col-2]); |
| 876 |
|
| 877 |
{ |
| 878 |
|
| 879 |
final int scoreFromDiag=packed[MODE_MS][row-1][col-1]&SCOREMASK; |
| 880 |
final int scoreFromDel=packed[MODE_DEL][row-1][col-1]&SCOREMASK; |
| 881 |
final int scoreFromIns=packed[MODE_INS][row-1][col-1]&SCOREMASK; |
| 882 |
final int streak=(packed[MODE_MS][row-1][col-1]&TIMEMASK); |
| 883 |
|
| 884 |
{ |
| 885 |
|
| 886 |
if(match){ |
| 887 |
|
| 888 |
int scoreMS=scoreFromDiag+(prevMatch ? POINTSoff_MATCH2 : POINTSoff_MATCH); |
| 889 |
int scoreD=scoreFromDel+POINTSoff_MATCH; |
| 890 |
int scoreI=scoreFromIns+POINTSoff_MATCH; |
| 891 |
|
| 892 |
int score; |
| 893 |
int time; |
| 894 |
|
| 895 |
if(scoreMS>=scoreD && scoreMS>=scoreI){ |
| 896 |
score=scoreMS; |
| 897 |
time=(prevMatch ? streak+1 : 1); |
| 898 |
|
| 899 |
}else if(scoreD>=scoreI){ |
| 900 |
score=scoreD; |
| 901 |
time=1; |
| 902 |
|
| 903 |
}else{ |
| 904 |
score=scoreI; |
| 905 |
time=1; |
| 906 |
|
| 907 |
} |
| 908 |
score+=(((int)baseScores[row-1])<<SCOREOFFSET); |
| 909 |
|
| 910 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 911 |
assert(score>=MINoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 912 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 913 |
|
| 914 |
packed[MODE_MS][row][col]=(score|time); |
| 915 |
assert((score&SCOREMASK)==score); |
| 916 |
|
| 917 |
assert((time&TIMEMASK)==time); |
| 918 |
|
| 919 |
}else{ |
| 920 |
|
| 921 |
int scoreMS=scoreFromDiag+(prevMatch ? (streak<=1 ? POINTSoff_SUBR : POINTSoff_SUB) : |
| 922 |
(streak==0 ? POINTSoff_SUB : streak<LIMIT_FOR_COST_3 ? POINTSoff_SUB2 : POINTSoff_SUB3)); |
| 923 |
int scoreD=scoreFromDel+POINTSoff_SUB; |
| 924 |
int scoreI=scoreFromIns+POINTSoff_SUB; |
| 925 |
|
| 926 |
int score; |
| 927 |
int time; |
| 928 |
byte prevState; |
| 929 |
if(scoreMS>=scoreD && scoreMS>=scoreI){ |
| 930 |
score=scoreMS; |
| 931 |
time=(prevMatch ? 1 : streak+1); |
| 932 |
|
| 933 |
prevState=MODE_MS; |
| 934 |
}else if(scoreD>=scoreI){ |
| 935 |
score=scoreD; |
| 936 |
time=1; |
| 937 |
prevState=MODE_DEL; |
| 938 |
}else{ |
| 939 |
score=scoreI; |
| 940 |
time=1; |
| 941 |
prevState=MODE_INS; |
| 942 |
} |
| 943 |
|
| 944 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 945 |
assert(score>=MINoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 946 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 947 |
|
| 948 |
packed[MODE_MS][row][col]=(score|time); |
| 949 |
assert((score&SCOREMASK)==score); |
| 950 |
|
| 951 |
assert((time&TIMEMASK)==time); |
| 952 |
} |
| 953 |
} |
| 954 |
} |
| 955 |
|
| 956 |
{ |
| 957 |
|
| 958 |
final int streak=packed[MODE_DEL][row][col-1]&TIMEMASK; |
| 959 |
|
| 960 |
final int scoreFromDiag=packed[MODE_MS][row][col-1]&SCOREMASK; |
| 961 |
final int scoreFromDel=packed[MODE_DEL][row][col-1]&SCOREMASK; |
| 962 |
|
| 963 |
int scoreMS=scoreFromDiag+POINTSoff_DEL; |
| 964 |
int scoreD=scoreFromDel+(streak==0 ? POINTSoff_DEL : |
| 965 |
streak<LIMIT_FOR_COST_3 ? POINTSoff_DEL2 : |
| 966 |
streak<LIMIT_FOR_COST_4 ? POINTSoff_DEL3 : |
| 967 |
streak<LIMIT_FOR_COST_5 ? POINTSoff_DEL4 : |
| 968 |
((streak&MASK5)==0 ? POINTSoff_DEL5 : 0)); |
| 969 |
|
| 970 |
|
| 971 |
int score; |
| 972 |
int time; |
| 973 |
byte prevState; |
| 974 |
if(scoreMS>=scoreD){ |
| 975 |
score=scoreMS; |
| 976 |
time=1; |
| 977 |
prevState=MODE_MS; |
| 978 |
}else{ |
| 979 |
score=scoreD; |
| 980 |
time=streak+1; |
| 981 |
prevState=MODE_DEL; |
| 982 |
} |
| 983 |
|
| 984 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 985 |
assert(score>=MINoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 986 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 987 |
|
| 988 |
packed[MODE_DEL][row][col]=(score|time); |
| 989 |
assert((score&SCOREMASK)==score); |
| 990 |
|
| 991 |
assert((time&TIMEMASK)==time); |
| 992 |
} |
| 993 |
|
| 994 |
{ |
| 995 |
|
| 996 |
final int streak=packed[MODE_INS][row-1][col]&TIMEMASK; |
| 997 |
|
| 998 |
final int scoreFromDiag=packed[MODE_MS][row-1][col]&SCOREMASK; |
| 999 |
final int scoreFromIns=packed[MODE_INS][row-1][col]&SCOREMASK; |
| 1000 |
|
| 1001 |
int scoreMS=scoreFromDiag+POINTSoff_INS; |
| 1002 |
|
| 1003 |
int scoreI=scoreFromIns+(streak==0 ? POINTSoff_INS : |
| 1004 |
streak<LIMIT_FOR_COST_3 ? POINTSoff_INS2 : |
| 1005 |
streak<LIMIT_FOR_COST_4 ? POINTSoff_INS3 : POINTSoff_INS4); |
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
int score; |
| 1013 |
int time; |
| 1014 |
byte prevState; |
| 1015 |
if(scoreMS>=scoreI){ |
| 1016 |
score=scoreMS; |
| 1017 |
time=1; |
| 1018 |
prevState=MODE_MS; |
| 1019 |
}else{ |
| 1020 |
score=scoreI; |
| 1021 |
time=streak+1; |
| 1022 |
prevState=MODE_INS; |
| 1023 |
} |
| 1024 |
|
| 1025 |
if(time>MAX_TIME){time=MAX_TIME-MASK5;} |
| 1026 |
assert(score>=MINoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 1027 |
assert(score<=MAXoff_SCORE) : "Score overflow - use MSA2 instead"; |
| 1028 |
|
| 1029 |
packed[MODE_INS][row][col]=(score|time); |
| 1030 |
assert((score&SCOREMASK)==score); |
| 1031 |
|
| 1032 |
assert((time&TIMEMASK)==time); |
| 1033 |
} |
| 1034 |
} |
| 1035 |
} |
| 1036 |
|
| 1037 |
|
| 1038 |
int maxCol=-1; |
| 1039 |
int maxState=-1; |
| 1040 |
int maxScore=Integer.MIN_VALUE; |
| 1041 |
|
| 1042 |
for(int state=0; state<packed.length; state++){ |
| 1043 |
for(int col=1; col<=columns; col++){ |
| 1044 |
int x=packed[state][rows][col]&SCOREMASK; |
| 1045 |
if(x>maxScore){ |
| 1046 |
maxScore=x; |
| 1047 |
maxCol=col; |
| 1048 |
maxState=state; |
| 1049 |
} |
| 1050 |
} |
| 1051 |
} |
| 1052 |
maxScore>>=SCOREOFFSET; |
| 1053 |
|
| 1054 |
|
| 1055 |
return new int[] {rows, maxCol, maxState, maxScore}; |
| 1056 |
} |
| 1057 |
|
| 1058 |
@Override |
| 1059 |
|
| 1060 |
|
| 1061 |
public final byte[] traceback(byte[] read, byte[] ref, int refStartLoc, int refEndLoc, int row, int col, int state, boolean gapped){ |
| 1062 |
if(gapped){ |
| 1063 |
final byte[] gref=grefbuffer; |
| 1064 |
int gstart=translateToGappedCoordinate(refStartLoc, gref); |
| 1065 |
int gstop=translateToGappedCoordinate(refEndLoc, gref); |
| 1066 |
byte[] out=traceback2(read, gref, gstart, gstop, row, col, state); |
| 1067 |
return out; |
| 1068 |
}else{ |
| 1069 |
return traceback2(read, ref, refStartLoc, refEndLoc, row, col, state); |
| 1070 |
} |
| 1071 |
} |
| 1072 |
|
| 1073 |
@Override |
| 1074 |
|
| 1075 |
public final byte[] traceback2(byte[] read, byte[] ref, int refStartLoc, int refEndLoc, int row, int col, int state){ |
| 1076 |
|
| 1077 |
assert(refStartLoc<=refEndLoc) : refStartLoc+", "+refEndLoc; |
| 1078 |
assert(row==rows); |
| 1079 |
|
| 1080 |
byte[] out=new byte[row+col-1]; |
| 1081 |
int outPos=0; |
| 1082 |
|
| 1083 |
int gaps=0; |
| 1084 |
|
| 1085 |
if(state==MODE_INS){ |
| 1086 |
|
| 1087 |
} |
| 1088 |
|
| 1089 |
while(row>0 && col>0){ |
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
final int time=packed[state][row][col]&TIMEMASK; |
| 1094 |
final byte prev; |
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
if(state==MODE_MS){ |
| 1099 |
if(time>1){prev=(byte)state;} |
| 1100 |
else{ |
| 1101 |
final int scoreFromDiag=packed[MODE_MS][row-1][col-1]&SCOREMASK; |
| 1102 |
final int scoreFromDel=packed[MODE_DEL][row-1][col-1]&SCOREMASK; |
| 1103 |
final int scoreFromIns=packed[MODE_INS][row-1][col-1]&SCOREMASK; |
| 1104 |
if(scoreFromDiag>=scoreFromDel && scoreFromDiag>=scoreFromIns){prev=MODE_MS;} |
| 1105 |
else if(scoreFromDel>=scoreFromIns){prev=MODE_DEL;} |
| 1106 |
else{prev=MODE_INS;} |
| 1107 |
} |
| 1108 |
|
| 1109 |
byte c=read[row-1]; |
| 1110 |
byte r=ref[refStartLoc+col-1]; |
| 1111 |
if(c==r){ |
| 1112 |
out[outPos]='m'; |
| 1113 |
}else{ |
| 1114 |
if(!AminoAcid.isFullyDefined(c)){ |
| 1115 |
out[outPos]='N'; |
| 1116 |
}else if(!AminoAcid.isFullyDefined(r)){ |
| 1117 |
|
| 1118 |
out[outPos]='N'; |
| 1119 |
}else{ |
| 1120 |
out[outPos]='S'; |
| 1121 |
} |
| 1122 |
} |
| 1123 |
|
| 1124 |
row--; |
| 1125 |
col--; |
| 1126 |
}else if(state==MODE_DEL){ |
| 1127 |
if(time>1){prev=(byte)state;} |
| 1128 |
else{ |
| 1129 |
final int scoreFromDiag=packed[MODE_MS][row][col-1]&SCOREMASK; |
| 1130 |
final int scoreFromDel=packed[MODE_DEL][row][col-1]&SCOREMASK; |
| 1131 |
if(scoreFromDiag>=scoreFromDel){prev=MODE_MS;} |
| 1132 |
else{prev=MODE_DEL;} |
| 1133 |
} |
| 1134 |
|
| 1135 |
byte r=ref[refStartLoc+col-1]; |
| 1136 |
if(r==GAPC){ |
| 1137 |
out[outPos]='-'; |
| 1138 |
gaps++; |
| 1139 |
}else{ |
| 1140 |
out[outPos]='D'; |
| 1141 |
} |
| 1142 |
col--; |
| 1143 |
}else{ |
| 1144 |
if(time>1){prev=(byte)state;} |
| 1145 |
else{ |
| 1146 |
final int scoreFromDiag=packed[MODE_MS][row-1][col]&SCOREMASK; |
| 1147 |
final int scoreFromIns=packed[MODE_INS][row-1][col]&SCOREMASK; |
| 1148 |
if(scoreFromDiag>=scoreFromIns){prev=MODE_MS;} |
| 1149 |
else{prev=MODE_INS;} |
| 1150 |
} |
| 1151 |
|
| 1152 |
assert(state==MODE_INS) : state; |
| 1153 |
if(col==0){ |
| 1154 |
out[outPos]='X'; |
| 1155 |
}else if(col>=columns){ |
| 1156 |
out[outPos]='Y'; |
| 1157 |
}else{ |
| 1158 |
out[outPos]='I'; |
| 1159 |
} |
| 1160 |
row--; |
| 1161 |
} |
| 1162 |
|
| 1163 |
|
| 1164 |
state=prev; |
| 1165 |
outPos++; |
| 1166 |
} |
| 1167 |
|
| 1168 |
assert(row==0 || col==0); |
| 1169 |
if(col!=row){ |
| 1170 |
while(row>0){ |
| 1171 |
out[outPos]='X'; |
| 1172 |
outPos++; |
| 1173 |
row--; |
| 1174 |
col--; |
| 1175 |
} |
| 1176 |
if(col>0){ |
| 1177 |
|
| 1178 |
} |
| 1179 |
} |
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
byte[] out2=new byte[outPos]; |
| 1184 |
for(int i=0; i<outPos; i++){ |
| 1185 |
out2[i]=out[outPos-i-1]; |
| 1186 |
} |
| 1187 |
out=null; |
| 1188 |
|
| 1189 |
if(gaps==0){return out2;} |
| 1190 |
|
| 1191 |
|
| 1192 |
byte[] out3=new byte[out2.length+gaps*(GAPLEN-1)]; |
| 1193 |
for(int i=0, j=0; i<out2.length; i++){ |
| 1194 |
byte c=out2[i]; |
| 1195 |
if(c!=GAPC){ |
| 1196 |
out3[j]=c; |
| 1197 |
j++; |
| 1198 |
}else{ |
| 1199 |
int lim=j+GAPLEN; |
| 1200 |
for(; j<lim; j++){ |
| 1201 |
out3[j]='D'; |
| 1202 |
} |
| 1203 |
} |
| 1204 |
} |
| 1205 |
return out3; |
| 1206 |
} |
| 1207 |
|
| 1208 |
@Override |
| 1209 |
|
| 1210 |
public final int[] score(final byte[] read, final byte[] ref, final int refStartLoc, final int refEndLoc, |
| 1211 |
final int maxRow, final int maxCol, final int maxState, boolean gapped){ |
| 1212 |
if(gapped){ |
| 1213 |
if(verbose){ |
| 1214 |
System.err.println("score():"); |
| 1215 |
System.err.println("origin="+grefRefOrigin+", "+refStartLoc+", "+refEndLoc+", "+maxRow+", "+maxCol); |
| 1216 |
} |
| 1217 |
final byte[] gref=grefbuffer; |
| 1218 |
int gstart=translateToGappedCoordinate(refStartLoc, gref); |
| 1219 |
int gstop=translateToGappedCoordinate(refEndLoc, gref); |
| 1220 |
|
| 1221 |
assert(translateFromGappedCoordinate(gstart, gref)==refStartLoc); |
| 1222 |
assert(translateFromGappedCoordinate(gstop, gref)==refEndLoc); |
| 1223 |
|
| 1224 |
assert(gstart==0) : gstart; |
| 1225 |
|
| 1226 |
if(verbose){System.err.println("gstart, gstop: "+gstart+", "+gstop);} |
| 1227 |
int[] out=score2(read, gref, gstart, gstop, maxRow, maxCol, maxState); |
| 1228 |
if(verbose){System.err.println("got score "+Arrays.toString(out));} |
| 1229 |
|
| 1230 |
assert(out[1]==translateToGappedCoordinate(translateFromGappedCoordinate(out[1], gref), gref)) : |
| 1231 |
"Verifying: "+out[1]+" -> "+translateFromGappedCoordinate(out[1], gref)+" -> "+ |
| 1232 |
translateToGappedCoordinate(translateFromGappedCoordinate(out[1], gref), gref); |
| 1233 |
assert(out[2]==translateToGappedCoordinate(translateFromGappedCoordinate(out[2], gref), gref)); |
| 1234 |
|
| 1235 |
out[1]=translateFromGappedCoordinate(out[1], gref); |
| 1236 |
out[2]=translateFromGappedCoordinate(out[2], gref); |
| 1237 |
if(verbose){System.err.println("returning score "+Arrays.toString(out));} |
| 1238 |
return out; |
| 1239 |
}else{ |
| 1240 |
return score2(read, ref, refStartLoc, refEndLoc, maxRow, maxCol, maxState); |
| 1241 |
} |
| 1242 |
} |
| 1243 |
|
| 1244 |
@Override |
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
public final int[] score2(final byte[] read, final byte[] ref, final int refStartLoc, final int refEndLoc, |
| 1249 |
final int maxRow, final int maxCol, final int maxState){ |
| 1250 |
|
| 1251 |
int row=maxRow; |
| 1252 |
int col=maxCol; |
| 1253 |
int state=maxState; |
| 1254 |
|
| 1255 |
assert(maxState>=0 && maxState<packed.length) : |
| 1256 |
maxState+", "+maxRow+", "+maxCol+"\n"+new String(read)+"\n"+toString(ref, refStartLoc, refEndLoc); |
| 1257 |
assert(maxRow>=0 && maxRow<packed[0].length) : |
| 1258 |
maxState+", "+maxRow+", "+maxCol+"\n"+new String(read)+"\n"+toString(ref, refStartLoc, refEndLoc); |
| 1259 |
assert(maxCol>=0 && maxCol<packed[0][0].length) : |
| 1260 |
maxState+", "+maxRow+", "+maxCol+"\n"+new String(read)+"\n"+toString(ref, refStartLoc, refEndLoc); |
| 1261 |
|
| 1262 |
int score=packed[maxState][maxRow][maxCol]&SCOREMASK; |
| 1263 |
|
| 1264 |
if(row<rows){ |
| 1265 |
int difR=rows-row; |
| 1266 |
int difC=columns-col; |
| 1267 |
|
| 1268 |
while(difR>difC){ |
| 1269 |
score+=POINTSoff_NOREF; |
| 1270 |
difR--; |
| 1271 |
} |
| 1272 |
|
| 1273 |
row+=difR; |
| 1274 |
col+=difR; |
| 1275 |
|
| 1276 |
} |
| 1277 |
|
| 1278 |
assert(refStartLoc<=refEndLoc); |
| 1279 |
assert(row==rows); |
| 1280 |
|
| 1281 |
|
| 1282 |
final int bestRefStop=refStartLoc+col-1; |
| 1283 |
|
| 1284 |
if(verbose){System.err.println("Scoring.");} |
| 1285 |
|
| 1286 |
int stateTime=0; |
| 1287 |
|
| 1288 |
while(row>0 && col>0){ |
| 1289 |
|
| 1290 |
if(verbose){System.err.println("state="+state+", row="+row+", col="+col);} |
| 1291 |
|
| 1292 |
final int time=packed[state][row][col]&TIMEMASK; |
| 1293 |
final byte prev; |
| 1294 |
|
| 1295 |
if(state==MODE_MS){ |
| 1296 |
if(time>1){prev=(byte)state;} |
| 1297 |
else{ |
| 1298 |
final int scoreFromDiag=packed[MODE_MS][row-1][col-1]&SCOREMASK; |
| 1299 |
final int scoreFromDel=packed[MODE_DEL][row-1][col-1]&SCOREMASK; |
| 1300 |
final int scoreFromIns=packed[MODE_INS][row-1][col-1]&SCOREMASK; |
| 1301 |
if(scoreFromDiag>=scoreFromDel && scoreFromDiag>=scoreFromIns){prev=MODE_MS;} |
| 1302 |
else if(scoreFromDel>=scoreFromIns){prev=MODE_DEL;} |
| 1303 |
else{prev=MODE_INS;} |
| 1304 |
} |
| 1305 |
row--; |
| 1306 |
col--; |
| 1307 |
}else if(state==MODE_DEL){ |
| 1308 |
if(time>1){prev=(byte)state;} |
| 1309 |
else{ |
| 1310 |
final int scoreFromDiag=packed[MODE_MS][row][col-1]&SCOREMASK; |
| 1311 |
final int scoreFromDel=packed[MODE_DEL][row][col-1]&SCOREMASK; |
| 1312 |
if(scoreFromDiag>=scoreFromDel){prev=MODE_MS;} |
| 1313 |
else{prev=MODE_DEL;} |
| 1314 |
} |
| 1315 |
col--; |
| 1316 |
}else{ |
| 1317 |
assert(state==MODE_INS); |
| 1318 |
if(time>1){prev=(byte)state;} |
| 1319 |
else{ |
| 1320 |
final int scoreFromDiag=packed[MODE_MS][row-1][col]&SCOREMASK; |
| 1321 |
final int scoreFromIns=packed[MODE_INS][row-1][col]&SCOREMASK; |
| 1322 |
if(scoreFromDiag>=scoreFromIns){prev=MODE_MS;} |
| 1323 |
else{prev=MODE_INS;} |
| 1324 |
} |
| 1325 |
row--; |
| 1326 |
} |
| 1327 |
|
| 1328 |
if(col<0){ |
| 1329 |
if(verbose){ |
| 1330 |
System.err.println("Warning, column went below 0 at row="+row); |
| 1331 |
} |
| 1332 |
break; |
| 1333 |
} |
| 1334 |
|
| 1335 |
|
| 1336 |
if(state==prev){stateTime++;}else{stateTime=0;} |
| 1337 |
state=prev; |
| 1338 |
|
| 1339 |
if(verbose){System.err.println("state2="+state+", time="+time+", stateTime="+stateTime+", row2="+row+", col2="+col+"\n");} |
| 1340 |
} |
| 1341 |
|
| 1342 |
if(row>col){ |
| 1343 |
col-=row; |
| 1344 |
} |
| 1345 |
|
| 1346 |
final int bestRefStart=refStartLoc+col; |
| 1347 |
|
| 1348 |
score>>=SCOREOFFSET; |
| 1349 |
|
| 1350 |
if(verbose){ |
| 1351 |
System.err.println("bestRefStart="+bestRefStart+", refStartLoc="+refStartLoc); |
| 1352 |
System.err.println("bestRefStop="+bestRefStop+", refEndLoc="+refEndLoc); |
| 1353 |
} |
| 1354 |
|
| 1355 |
int padLeft=0; |
| 1356 |
int padRight=0; |
| 1357 |
if(bestRefStart<refStartLoc){ |
| 1358 |
padLeft=Tools.max(0, refStartLoc-bestRefStart); |
| 1359 |
}else if(bestRefStart==refStartLoc && state==MODE_INS){ |
| 1360 |
padLeft=stateTime; |
| 1361 |
} |
| 1362 |
if(bestRefStop>refEndLoc){ |
| 1363 |
padRight=Tools.max(0, bestRefStop-refEndLoc); |
| 1364 |
}else if(bestRefStop==refEndLoc && maxState==MODE_INS){ |
| 1365 |
padRight=packed[maxState][maxRow][maxCol]&TIMEMASK; |
| 1366 |
} |
| 1367 |
|
| 1368 |
int[] rvec; |
| 1369 |
if(padLeft>0 || padRight>0){ |
| 1370 |
rvec=new int[] {score, bestRefStart, bestRefStop, maxRow, maxCol, maxState, padLeft, padRight}; |
| 1371 |
}else{ |
| 1372 |
rvec=new int[] {score, bestRefStart, bestRefStop, maxRow, maxCol, maxState}; |
| 1373 |
} |
| 1374 |
return rvec; |
| 1375 |
} |
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
private final byte[] makeGref(byte[] ref, int[] gaps, int refStartLoc, int refEndLoc, byte[] read){ |
| 1386 |
assert(gaps!=null && gaps.length>0); |
| 1387 |
|
| 1388 |
assert(refStartLoc<=gaps[0]) : refStartLoc+", "+refEndLoc+", "+Arrays.toString(gaps)+"\n"+new String(read); |
| 1389 |
assert(refEndLoc>=gaps[gaps.length-1]); |
| 1390 |
|
| 1391 |
final int g0_old=gaps[0]; |
| 1392 |
final int gN_old=gaps[gaps.length-1]; |
| 1393 |
gaps[0]=Tools.min(gaps[0], refStartLoc); |
| 1394 |
gaps[gaps.length-1]=Tools.max(gN_old, refEndLoc); |
| 1395 |
grefRefOrigin=gaps[0]; |
| 1396 |
|
| 1397 |
if(verbose){System.err.println("\ngaps2: "+Arrays.toString(gaps));} |
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
byte[] gref=grefbuffer; |
| 1424 |
|
| 1425 |
int gpos=0; |
| 1426 |
for(int i=0; i<gaps.length; i+=2){ |
| 1427 |
int x=gaps[i]; |
| 1428 |
int y=gaps[i+1]; |
| 1429 |
|
| 1430 |
for(int r=x; r<=y; r++, gpos++){ |
| 1431 |
|
| 1432 |
assert(gpos<gref.length) : |
| 1433 |
"\ngpos="+gpos+", gref.length="+gref.length+", read.length="+read.length+", gaps2="+Arrays.toString(gaps)+ |
| 1434 |
"\ni="+i+", r="+r+", x="+x+", y="+y+ |
| 1435 |
"\nGapTools.calcGrefLen("+gaps[0]+", "+gaps[gaps.length-1]+", gaps)="+GapTools.calcGrefLen(gaps[0], gaps[gaps.length-1], gaps)+ |
| 1436 |
"\nGapTools.calcGrefLen("+gaps[0]+", "+gaps[gaps.length-1]+", gaps)="+GapTools.calcGrefLen(gaps[0], gaps[gaps.length-1], gaps)+ |
| 1437 |
"\n"+refStartLoc+", "+refEndLoc+", "+greflimit+", "+GREFLIMIT2_CUSHION+"\n"+new String(gref)+"\n"+new String(read)+"\n"; |
| 1438 |
gref[gpos]=ref[r]; |
| 1439 |
} |
| 1440 |
|
| 1441 |
if(i+2<gaps.length){ |
| 1442 |
int z=gaps[i+2]; |
| 1443 |
assert(z>y); |
| 1444 |
int gap=z-y-1; |
| 1445 |
assert(gap>=MINGAP) : gap+"\t"+MINGAP; |
| 1446 |
if(gap<MINGAP){ |
| 1447 |
assert(false) : "TODO - just fill in normally"; |
| 1448 |
}else{ |
| 1449 |
int rem=gap%GAPLEN; |
| 1450 |
int lim=y+GAPBUFFER+rem; |
| 1451 |
|
| 1452 |
int div=(gap-GAPBUFFER2)/GAPLEN; |
| 1453 |
if(verbose){ |
| 1454 |
System.err.println("div = "+div); |
| 1455 |
} |
| 1456 |
assert(div>0); |
| 1457 |
|
| 1458 |
for(int r=y+1; r<=lim; r++, gpos++){ |
| 1459 |
gref[gpos]=ref[r]; |
| 1460 |
} |
| 1461 |
for(int g=0; g<div; g++, gpos++){ |
| 1462 |
gref[gpos]=GAPC; |
| 1463 |
} |
| 1464 |
for(int r=z-GAPBUFFER; r<z; r++, gpos++){ |
| 1465 |
gref[gpos]=ref[r]; |
| 1466 |
} |
| 1467 |
} |
| 1468 |
} |
| 1469 |
} |
| 1470 |
|
| 1471 |
greflimit=gpos; |
| 1472 |
|
| 1473 |
assert(gref[gpos-1]==ref[refEndLoc]); |
| 1474 |
|
| 1475 |
|
| 1476 |
{ |
| 1477 |
final int lim=Tools.min(gref.length, greflimit+GREFLIMIT2_CUSHION); |
| 1478 |
if(lim>gref.length){ |
| 1479 |
System.err.println("gref buffer overflow: "+lim+" > "+gref.length); |
| 1480 |
return null; |
| 1481 |
} |
| 1482 |
for(int i=greflimit, r=refEndLoc+1; i<lim; i++, r++){ |
| 1483 |
gref[i]=(r<ref.length ? ref[r] : (byte)'N'); |
| 1484 |
greflimit2=i; |
| 1485 |
} |
| 1486 |
} |
| 1487 |
|
| 1488 |
if(verbose){ |
| 1489 |
System.err.println("gref:\n"+new String(gref)); |
| 1490 |
} |
| 1491 |
|
| 1492 |
gaps[0]=g0_old; |
| 1493 |
gaps[gaps.length-1]=gN_old; |
| 1494 |
|
| 1495 |
if(verbose){ |
| 1496 |
System.err.println("\ngaps3: "+Arrays.toString(gaps)); |
| 1497 |
} |
| 1498 |
|
| 1499 |
return gref; |
| 1500 |
} |
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
private final int translateFromGappedCoordinate(int point, byte[] gref){ |
| 1529 |
if(verbose){System.err.println("translateFromGappedCoordinate("+point+"), gro="+grefRefOrigin+", grl="+greflimit);} |
| 1530 |
if(point<=0){return grefRefOrigin+point;} |
| 1531 |
for(int i=0, j=grefRefOrigin; i<greflimit2; i++){ |
| 1532 |
|
| 1533 |
byte c=gref[i]; |
| 1534 |
assert(point>=i) : "\n"+grefRefOrigin+"\n"+point+"\n"+new String(gref)+"\n"; |
| 1535 |
|
| 1536 |
if(i==point){ |
| 1537 |
if(verbose){System.err.println(" -> "+j);} |
| 1538 |
return j; |
| 1539 |
} |
| 1540 |
|
| 1541 |
j+=(c==GAPC ? GAPLEN : 1); |
| 1542 |
|
| 1543 |
|
| 1544 |
} |
| 1545 |
|
| 1546 |
System.err.println(grefRefOrigin); |
| 1547 |
System.err.println(point); |
| 1548 |
System.err.println(new String(gref)); |
| 1549 |
|
| 1550 |
throw new RuntimeException("Out of bounds."); |
| 1551 |
} |
| 1552 |
|
| 1553 |
private final int translateToGappedCoordinate(int point, byte[] gref){ |
| 1554 |
if(verbose){System.err.println("translateToGappedCoordinate("+point+"), gro="+grefRefOrigin+", grl="+greflimit);} |
| 1555 |
if(point<=grefRefOrigin){return point-grefRefOrigin;} |
| 1556 |
for(int i=0, j=grefRefOrigin; i<greflimit2; i++){ |
| 1557 |
|
| 1558 |
assert(point>=j) : "\n"+grefRefOrigin+"\n"+point+"\n"+new String(gref)+"\n"; |
| 1559 |
byte c=gref[i]; |
| 1560 |
|
| 1561 |
if(j==point){ |
| 1562 |
if(verbose){System.err.println(" -> "+i);} |
| 1563 |
return i; |
| 1564 |
} |
| 1565 |
|
| 1566 |
j+=(c==GAPC ? GAPLEN : 1); |
| 1567 |
|
| 1568 |
|
| 1569 |
} |
| 1570 |
|
| 1571 |
System.err.println(grefRefOrigin); |
| 1572 |
System.err.println(point); |
| 1573 |
System.err.println(new String(gref)); |
| 1574 |
|
| 1575 |
throw new RuntimeException("Out of bounds."); |
| 1576 |
} |
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
private final int calcAffineScore(int[] locArray){ |
| 1581 |
int score=0; |
| 1582 |
int lastLoc=-2; |
| 1583 |
int lastValue=-1; |
| 1584 |
int timeInMode=0; |
| 1585 |
|
| 1586 |
for(int i=0; i<locArray.length; i++){ |
| 1587 |
int loc=locArray[i]; |
| 1588 |
|
| 1589 |
if(loc>0){ |
| 1590 |
if(loc==lastValue){ |
| 1591 |
score+=POINTS_MATCH2; |
| 1592 |
}else if(loc==lastLoc || lastLoc<0){ |
| 1593 |
score+=POINTS_MATCH; |
| 1594 |
}else if(loc<lastLoc){ |
| 1595 |
assert(lastLoc>=0); |
| 1596 |
score+=POINTS_MATCH; |
| 1597 |
score+=POINTS_DEL; |
| 1598 |
int dif=lastLoc-loc+1; |
| 1599 |
if(dif>MINGAP){ |
| 1600 |
int rem=dif%GAPLEN; |
| 1601 |
int div=(dif-GAPBUFFER2)/GAPLEN; |
| 1602 |
score+=(div*POINTS_GAP); |
| 1603 |
assert(rem+GAPBUFFER2<dif); |
| 1604 |
dif=rem+GAPBUFFER2; |
| 1605 |
assert(dif>LIMIT_FOR_COST_4); |
| 1606 |
|
| 1607 |
} |
| 1608 |
if(dif>LIMIT_FOR_COST_5){ |
| 1609 |
score+=((dif-LIMIT_FOR_COST_5+MASK5)/TIMESLIP)*POINTS_DEL5; |
| 1610 |
dif=LIMIT_FOR_COST_5; |
| 1611 |
} |
| 1612 |
if(dif>LIMIT_FOR_COST_4){ |
| 1613 |
score+=(dif-LIMIT_FOR_COST_4)*POINTS_DEL4; |
| 1614 |
dif=LIMIT_FOR_COST_4; |
| 1615 |
} |
| 1616 |
if(dif>LIMIT_FOR_COST_3){ |
| 1617 |
score+=(dif-LIMIT_FOR_COST_3)*POINTS_DEL3; |
| 1618 |
dif=LIMIT_FOR_COST_3; |
| 1619 |
} |
| 1620 |
if(dif>1){ |
| 1621 |
score+=(dif-1)*POINTS_DEL2; |
| 1622 |
} |
| 1623 |
timeInMode=1; |
| 1624 |
}else if(loc>lastLoc){ |
| 1625 |
assert(lastLoc>=0); |
| 1626 |
score+=POINTS_MATCH; |
| 1627 |
score+=POINTS_INS; |
| 1628 |
int dif=Tools.min(loc-lastLoc+1, 5); |
| 1629 |
assert(dif>0); |
| 1630 |
if(dif>LIMIT_FOR_COST_4){ |
| 1631 |
score+=(dif-LIMIT_FOR_COST_4)*POINTS_INS4; |
| 1632 |
dif=LIMIT_FOR_COST_4; |
| 1633 |
} |
| 1634 |
if(dif>LIMIT_FOR_COST_3){ |
| 1635 |
score+=(dif-LIMIT_FOR_COST_3)*POINTS_INS3; |
| 1636 |
dif=LIMIT_FOR_COST_3; |
| 1637 |
} |
| 1638 |
if(dif>1){ |
| 1639 |
score+=(dif-1)*POINTS_INS2; |
| 1640 |
} |
| 1641 |
timeInMode=1; |
| 1642 |
}else{ |
| 1643 |
assert(false); |
| 1644 |
} |
| 1645 |
lastLoc=loc; |
| 1646 |
}else{ |
| 1647 |
if(lastValue<0 && timeInMode>0){ |
| 1648 |
if(timeInMode<LIMIT_FOR_COST_3){score+=POINTS_SUB2;} |
| 1649 |
else{score+=POINTS_SUB3;} |
| 1650 |
timeInMode++; |
| 1651 |
}else{ |
| 1652 |
score+=POINTS_SUB; |
| 1653 |
timeInMode=1; |
| 1654 |
} |
| 1655 |
} |
| 1656 |
lastValue=loc; |
| 1657 |
} |
| 1658 |
assert(score<=maxQuality(locArray.length)); |
| 1659 |
return score; |
| 1660 |
} |
| 1661 |
|
| 1662 |
@Override |
| 1663 |
public final int calcAffineScore(final int[] locArray, final byte[] baseScores, final byte bases[]){ |
| 1664 |
int score=0; |
| 1665 |
int lastLoc=-3; |
| 1666 |
int lastValue=-1; |
| 1667 |
int timeInMode=0; |
| 1668 |
|
| 1669 |
for(int i=0; i<locArray.length; i++){ |
| 1670 |
final int loc=locArray[i]; |
| 1671 |
|
| 1672 |
if(loc>0){ |
| 1673 |
if(loc==lastValue){ |
| 1674 |
score+=(POINTS_MATCH2+baseScores[i]); |
| 1675 |
}else if(loc==lastLoc || lastLoc<0){ |
| 1676 |
score+=(POINTS_MATCH+baseScores[i]); |
| 1677 |
}else if(loc<lastLoc){ |
| 1678 |
assert(lastLoc>=0); |
| 1679 |
score+=(POINTS_MATCH+baseScores[i]); |
| 1680 |
score+=POINTS_DEL; |
| 1681 |
int dif=lastLoc-loc+1; |
| 1682 |
if(dif>MINGAP){ |
| 1683 |
int rem=dif%GAPLEN; |
| 1684 |
int div=(dif-GAPBUFFER2)/GAPLEN; |
| 1685 |
score+=(div*POINTS_GAP); |
| 1686 |
assert(rem+GAPBUFFER2<dif); |
| 1687 |
dif=rem+GAPBUFFER2; |
| 1688 |
assert(dif>LIMIT_FOR_COST_4); |
| 1689 |
|
| 1690 |
} |
| 1691 |
if(dif>LIMIT_FOR_COST_5){ |
| 1692 |
score+=((dif-LIMIT_FOR_COST_5+MASK5)/TIMESLIP)*POINTS_DEL5; |
| 1693 |
dif=LIMIT_FOR_COST_5; |
| 1694 |
} |
| 1695 |
if(dif>LIMIT_FOR_COST_4){ |
| 1696 |
score+=(dif-LIMIT_FOR_COST_4)*POINTS_DEL4; |
| 1697 |
dif=LIMIT_FOR_COST_4; |
| 1698 |
} |
| 1699 |
if(dif>LIMIT_FOR_COST_3){ |
| 1700 |
score+=(dif-LIMIT_FOR_COST_3)*POINTS_DEL3; |
| 1701 |
dif=LIMIT_FOR_COST_3; |
| 1702 |
} |
| 1703 |
if(dif>1){ |
| 1704 |
score+=(dif-1)*POINTS_DEL2; |
| 1705 |
} |
| 1706 |
timeInMode=1; |
| 1707 |
}else if(loc>lastLoc){ |
| 1708 |
assert(lastLoc>=0); |
| 1709 |
score+=(POINTS_MATCH+baseScores[i]); |
| 1710 |
score+=POINTS_INS; |
| 1711 |
int dif=Tools.min(loc-lastLoc+1, 5); |
| 1712 |
assert(dif>0); |
| 1713 |
if(dif>LIMIT_FOR_COST_4){ |
| 1714 |
score+=(dif-LIMIT_FOR_COST_4)*POINTS_INS4; |
| 1715 |
dif=LIMIT_FOR_COST_4; |
| 1716 |
} |
| 1717 |
if(dif>LIMIT_FOR_COST_3){ |
| 1718 |
score+=(dif-LIMIT_FOR_COST_3)*POINTS_INS3; |
| 1719 |
dif=LIMIT_FOR_COST_3; |
| 1720 |
} |
| 1721 |
if(dif>1){ |
| 1722 |
score+=(dif-1)*POINTS_INS2; |
| 1723 |
} |
| 1724 |
timeInMode=1; |
| 1725 |
}else{ |
| 1726 |
assert(false); |
| 1727 |
} |
| 1728 |
lastLoc=loc; |
| 1729 |
}else if(loc==-1){ |
| 1730 |
if(lastValue<0 && timeInMode>0){ |
| 1731 |
if(timeInMode<LIMIT_FOR_COST_3){score+=POINTS_SUB2;} |
| 1732 |
else{score+=POINTS_SUB3;} |
| 1733 |
timeInMode++; |
| 1734 |
}else{ |
| 1735 |
score+=POINTS_SUB; |
| 1736 |
timeInMode=1; |
| 1737 |
} |
| 1738 |
}else{ |
| 1739 |
assert(loc==-2) : "\ni="+i+", loc="+loc+", score="+score+", lastLoc="+lastLoc+", lastValue="+lastValue |
| 1740 |
+", time="+timeInMode+", length="+locArray.length+"\nbases=\n"+new String(bases) |
| 1741 |
+"\nlocs[]=\n"+Arrays.toString(locArray)+"\n"+new String(bases)+"\n" |
| 1742 |
+"If this happens please ensure that the reference has a startpad of Ns longer than readlength."; |
| 1743 |
timeInMode=0; |
| 1744 |
score+=POINTS_NOCALL; |
| 1745 |
} |
| 1746 |
lastValue=loc; |
| 1747 |
} |
| 1748 |
assert(score<=maxQuality(locArray.length)); |
| 1749 |
return score; |
| 1750 |
} |
| 1751 |
|
| 1752 |
@Override |
| 1753 |
public final int calcAffineScore(int[] locArray, byte[] baseScores, byte[] bases, int minContig){ |
| 1754 |
assert(minContig>1) : minContig; |
| 1755 |
|
| 1756 |
int contig=0; |
| 1757 |
int maxContig=0; |
| 1758 |
|
| 1759 |
int score=0; |
| 1760 |
int lastLoc=-3; |
| 1761 |
int lastValue=-1; |
| 1762 |
int timeInMode=0; |
| 1763 |
|
| 1764 |
for(int i=0; i<locArray.length; i++){ |
| 1765 |
int loc=locArray[i]; |
| 1766 |
|
| 1767 |
if(loc>0){ |
| 1768 |
if(loc==lastValue){ |
| 1769 |
contig++; |
| 1770 |
score+=(POINTS_MATCH2+baseScores[i]); |
| 1771 |
}else if(loc==lastLoc || lastLoc<0){ |
| 1772 |
maxContig=Tools.max(maxContig, contig); |
| 1773 |
contig=1; |
| 1774 |
score+=(POINTS_MATCH+baseScores[i]); |
| 1775 |
}else if(loc<lastLoc){ |
| 1776 |
maxContig=Tools.max(maxContig, contig); |
| 1777 |
contig=0; |
| 1778 |
assert(lastLoc>=0); |
| 1779 |
score+=(POINTS_MATCH+baseScores[i]); |
| 1780 |
score+=POINTS_DEL; |
| 1781 |
int dif=lastLoc-loc+1; |
| 1782 |
if(dif>MINGAP){ |
| 1783 |
int rem=dif%GAPLEN; |
| 1784 |
int div=(dif-GAPBUFFER2)/GAPLEN; |
| 1785 |
score+=(div*POINTS_GAP); |
| 1786 |
assert(rem+GAPBUFFER2<dif); |
| 1787 |
dif=rem+GAPBUFFER2; |
| 1788 |
assert(dif>LIMIT_FOR_COST_4); |
| 1789 |
|
| 1790 |
} |
| 1791 |
if(dif>LIMIT_FOR_COST_5){ |
| 1792 |
score+=((dif-LIMIT_FOR_COST_5+MASK5)/TIMESLIP)*POINTS_DEL5; |
| 1793 |
dif=LIMIT_FOR_COST_5; |
| 1794 |
} |
| 1795 |
if(dif>LIMIT_FOR_COST_4){ |
| 1796 |
score+=(dif-LIMIT_FOR_COST_4)*POINTS_DEL4; |
| 1797 |
dif=LIMIT_FOR_COST_4; |
| 1798 |
} |
| 1799 |
if(dif>LIMIT_FOR_COST_3){ |
| 1800 |
score+=(dif-LIMIT_FOR_COST_3)*POINTS_DEL3; |
| 1801 |
dif=LIMIT_FOR_COST_3; |
| 1802 |
} |
| 1803 |
if(dif>1){ |
| 1804 |
score+=(dif-1)*POINTS_DEL2; |
| 1805 |
} |
| 1806 |
timeInMode=1; |
| 1807 |
}else if(loc>lastLoc){ |
| 1808 |
maxContig=Tools.max(maxContig, contig); |
| 1809 |
contig=0; |
| 1810 |
assert(lastLoc>=0); |
| 1811 |
score+=(POINTS_MATCH+baseScores[i]); |
| 1812 |
score+=POINTS_INS; |
| 1813 |
int dif=Tools.min(loc-lastLoc+1, 5); |
| 1814 |
assert(dif>0); |
| 1815 |
if(dif>LIMIT_FOR_COST_4){ |
| 1816 |
score+=(dif-LIMIT_FOR_COST_4)*POINTS_INS4; |
| 1817 |
dif=LIMIT_FOR_COST_4; |
| 1818 |
} |
| 1819 |
if(dif>LIMIT_FOR_COST_3){ |
| 1820 |
score+=(dif-LIMIT_FOR_COST_3)*POINTS_INS3; |
| 1821 |
dif=LIMIT_FOR_COST_3; |
| 1822 |
} |
| 1823 |
if(dif>1){ |
| 1824 |
score+=(dif-1)*POINTS_INS2; |
| 1825 |
} |
| 1826 |
timeInMode=1; |
| 1827 |
}else{ |
| 1828 |
assert(false); |
| 1829 |
} |
| 1830 |
lastLoc=loc; |
| 1831 |
}else if(loc==-1){ |
| 1832 |
if(lastValue<0 && timeInMode>0){ |
| 1833 |
if(timeInMode<LIMIT_FOR_COST_3){score+=POINTS_SUB2;} |
| 1834 |
else{score+=POINTS_SUB3;} |
| 1835 |
timeInMode++; |
| 1836 |
}else{ |
| 1837 |
score+=POINTS_SUB; |
| 1838 |
timeInMode=1; |
| 1839 |
} |
| 1840 |
}else{ |
| 1841 |
assert(loc==-2) : loc+"\n"+Arrays.toString(locArray)+"\n"+Arrays.toString(baseScores)+"\n"+new String(bases)+"\n" |
| 1842 |
+"If this happens please ensure that the reference has a startpad of Ns longer than readlength."; |
| 1843 |
timeInMode=0; |
| 1844 |
score+=POINTS_NOCALL; |
| 1845 |
} |
| 1846 |
lastValue=loc; |
| 1847 |
} |
| 1848 |
assert(score<=maxQuality(locArray.length)); |
| 1849 |
if(Tools.max(contig, maxContig)<minContig){score=Tools.min(score, -50*locArray.length);} |
| 1850 |
return score; |
| 1851 |
} |
| 1852 |
|
| 1853 |
@Override |
| 1854 |
public final int scoreNoIndels(byte[] read, byte[] ref, final int refStart){ |
| 1855 |
return scoreNoIndels(read, ref, refStart, null); |
| 1856 |
} |
| 1857 |
@Override |
| 1858 |
public final int scoreNoIndels(byte[] read, byte[] ref, final int refStart, final SiteScore ss){ |
| 1859 |
|
| 1860 |
int score=0; |
| 1861 |
int mode=-1; |
| 1862 |
int timeInMode=0; |
| 1863 |
|
| 1864 |
|
| 1865 |
|
| 1866 |
int readStart=0; |
| 1867 |
int readStop=read.length; |
| 1868 |
final int refStop=refStart+read.length; |
| 1869 |
boolean semiperfect=true; |
| 1870 |
int norefs=0; |
| 1871 |
|
| 1872 |
if(refStart<0){ |
| 1873 |
readStart=0-refStart; |
| 1874 |
score+=POINTS_NOREF*readStart; |
| 1875 |
norefs+=readStart; |
| 1876 |
} |
| 1877 |
if(refStop>ref.length){ |
| 1878 |
int dif=(refStop-ref.length); |
| 1879 |
readStop-=dif; |
| 1880 |
score+=POINTS_NOREF*dif; |
| 1881 |
norefs+=dif; |
| 1882 |
} |
| 1883 |
|
| 1884 |
|
| 1885 |
|
| 1886 |
for(int i=readStart; i<readStop; i++){ |
| 1887 |
byte c=read[i]; |
| 1888 |
byte r=ref[refStart+i]; |
| 1889 |
|
| 1890 |
if(c==r && c!='N'){ |
| 1891 |
if(mode==MODE_MS){ |
| 1892 |
timeInMode++; |
| 1893 |
score+=POINTS_MATCH2; |
| 1894 |
}else{ |
| 1895 |
timeInMode=0; |
| 1896 |
score+=POINTS_MATCH; |
| 1897 |
} |
| 1898 |
mode=MODE_MS; |
| 1899 |
}else if(c<0 || c=='N'){ |
| 1900 |
score+=POINTS_NOCALL; |
| 1901 |
semiperfect=false; |
| 1902 |
}else if(r<0 || r=='N'){ |
| 1903 |
score+=POINTS_NOREF; |
| 1904 |
norefs++; |
| 1905 |
}else{ |
| 1906 |
if(mode==MODE_SUB){timeInMode++;} |
| 1907 |
else{timeInMode=0;} |
| 1908 |
|
| 1909 |
if(timeInMode==0){score+=POINTS_SUB;} |
| 1910 |
else if(timeInMode<LIMIT_FOR_COST_3){score+=POINTS_SUB2;} |
| 1911 |
else{score+=POINTS_SUB3;} |
| 1912 |
mode=MODE_SUB; |
| 1913 |
semiperfect=false; |
| 1914 |
} |
| 1915 |
} |
| 1916 |
|
| 1917 |
|
| 1918 |
if(semiperfect && ss!=null){ss.semiperfect=((ss.stop==ss.start+read.length-1) && (norefs<=read.length/2));} |
| 1919 |
|
| 1920 |
return score; |
| 1921 |
} |
| 1922 |
|
| 1923 |
@Override |
| 1924 |
public final byte[] genMatchNoIndels(byte[] read, byte[] ref, final int refStart){ |
| 1925 |
if(read==null || ref==null){return null;} |
| 1926 |
|
| 1927 |
final byte[] match=new byte[read.length]; |
| 1928 |
|
| 1929 |
for(int i=0, j=refStart; i<read.length; i++, j++){ |
| 1930 |
byte c=read[i]; |
| 1931 |
byte r=(j<0 || j>=ref.length) ? (byte)'N' : ref[j]; |
| 1932 |
|
| 1933 |
if(c=='N' || r=='N'){match[i]='N';} |
| 1934 |
else if(c==r){match[i]='m';} |
| 1935 |
else{match[i]='S';} |
| 1936 |
|
| 1937 |
} |
| 1938 |
|
| 1939 |
return match; |
| 1940 |
} |
| 1941 |
|
| 1942 |
@Override |
| 1943 |
public final int scoreNoIndels(byte[] read, byte[] ref, byte[] baseScores, final int refStart){ |
| 1944 |
return scoreNoIndels(read, ref, baseScores, refStart, null); |
| 1945 |
} |
| 1946 |
@Override |
| 1947 |
public final int scoreNoIndels(byte[] read, byte[] ref, byte[] baseScores, final int refStart, SiteScore ss){ |
| 1948 |
|
| 1949 |
int score=0; |
| 1950 |
int mode=-1; |
| 1951 |
int timeInMode=0; |
| 1952 |
int norefs=0; |
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
int readStart=0; |
| 1957 |
int readStop=read.length; |
| 1958 |
final int refStop=refStart+read.length; |
| 1959 |
boolean semiperfect=true; |
| 1960 |
|
| 1961 |
if(refStart<0){ |
| 1962 |
readStart=0-refStart; |
| 1963 |
score+=POINTS_NOREF*readStart; |
| 1964 |
norefs+=readStart; |
| 1965 |
} |
| 1966 |
if(refStop>ref.length){ |
| 1967 |
int dif=(refStop-ref.length); |
| 1968 |
readStop-=dif; |
| 1969 |
score+=POINTS_NOREF*dif; |
| 1970 |
norefs+=dif; |
| 1971 |
} |
| 1972 |
|
| 1973 |
|
| 1974 |
|
| 1975 |
for(int i=readStart; i<readStop; i++){ |
| 1976 |
byte c=read[i]; |
| 1977 |
byte r=ref[refStart+i]; |
| 1978 |
|
| 1979 |
if(c==r && c!='N'){ |
| 1980 |
if(mode==MODE_MS){ |
| 1981 |
timeInMode++; |
| 1982 |
score+=POINTS_MATCH2; |
| 1983 |
}else{ |
| 1984 |
timeInMode=0; |
| 1985 |
score+=POINTS_MATCH; |
| 1986 |
} |
| 1987 |
score+=baseScores[i]; |
| 1988 |
mode=MODE_MS; |
| 1989 |
}else if(c<0 || c=='N'){ |
| 1990 |
score+=POINTS_NOCALL; |
| 1991 |
semiperfect=false; |
| 1992 |
}else if(r<0 || r=='N'){ |
| 1993 |
score+=POINTS_NOREF; |
| 1994 |
norefs++; |
| 1995 |
}else{ |
| 1996 |
if(mode==MODE_SUB){timeInMode++;} |
| 1997 |
else{timeInMode=0;} |
| 1998 |
|
| 1999 |
if(timeInMode==0){score+=POINTS_SUB;} |
| 2000 |
else if(timeInMode<LIMIT_FOR_COST_3){score+=POINTS_SUB2;} |
| 2001 |
else{score+=POINTS_SUB3;} |
| 2002 |
mode=MODE_SUB; |
| 2003 |
semiperfect=false; |
| 2004 |
} |
| 2005 |
} |
| 2006 |
|
| 2007 |
|
| 2008 |
if(semiperfect && ss!=null){ss.semiperfect=((ss.stop==ss.start+read.length-1) && (norefs<=read.length/2));} |
| 2009 |
assert(Read.CHECKSITE(ss, read, -1)); |
| 2010 |
|
| 2011 |
return score; |
| 2012 |
} |
| 2013 |
|
| 2014 |
@Override |
| 2015 |
public final int scoreNoIndelsAndMakeMatchString(byte[] read, byte[] ref, byte[] baseScores, final int refStart, byte[][] matchReturn){ |
| 2016 |
int score=0; |
| 2017 |
int mode=-1; |
| 2018 |
int timeInMode=0; |
| 2019 |
|
| 2020 |
assert(refStart<=ref.length) : refStart+", "+ref.length; |
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
int readStart=0; |
| 2025 |
int readStop=read.length; |
| 2026 |
final int refStop=refStart+read.length; |
| 2027 |
if(refStart<0 || refStop>ref.length){return -99999;} |
| 2028 |
if(refStart<0){ |
| 2029 |
readStart=0-refStart; |
| 2030 |
score+=POINTS_NOREF*readStart; |
| 2031 |
} |
| 2032 |
if(refStop>ref.length){ |
| 2033 |
int dif=(refStop-ref.length); |
| 2034 |
System.err.println(new String(read)+"\ndif="+dif+", ref.length="+ref.length+", refStop="+refStop); |
| 2035 |
readStop-=dif; |
| 2036 |
score+=POINTS_NOREF*dif; |
| 2037 |
} |
| 2038 |
assert(refStart+readStop<=ref.length) : "readStart="+readStart+", readStop="+readStop+ |
| 2039 |
", refStart="+refStart+", refStop="+refStop+", ref.length="+ref.length+", read.length="+read.length; |
| 2040 |
|
| 2041 |
assert(matchReturn!=null); |
| 2042 |
assert(matchReturn.length==1); |
| 2043 |
if(matchReturn[0]==null || matchReturn[0].length!=read.length){ |
| 2044 |
assert(matchReturn[0]==null || matchReturn[0].length<read.length) : matchReturn[0].length+"!="+read.length; |
| 2045 |
matchReturn[0]=new byte[read.length]; |
| 2046 |
} |
| 2047 |
final byte[] match=matchReturn[0]; |
| 2048 |
|
| 2049 |
|
| 2050 |
|
| 2051 |
for(int i=readStart; i<readStop; i++){ |
| 2052 |
byte c=read[i]; |
| 2053 |
byte r=ref[refStart+i]; |
| 2054 |
|
| 2055 |
assert(r!='.' && c!='.'); |
| 2056 |
|
| 2057 |
if(c==r && c!='N'){ |
| 2058 |
if(mode==MODE_MS){ |
| 2059 |
timeInMode++; |
| 2060 |
score+=POINTS_MATCH2; |
| 2061 |
}else{ |
| 2062 |
timeInMode=0; |
| 2063 |
score+=POINTS_MATCH; |
| 2064 |
} |
| 2065 |
score+=baseScores[i]; |
| 2066 |
match[i]='m'; |
| 2067 |
mode=MODE_MS; |
| 2068 |
}else if(c<0 || c=='N'){ |
| 2069 |
score+=POINTS_NOCALL; |
| 2070 |
match[i]='N'; |
| 2071 |
}else if(r<0 || r=='N'){ |
| 2072 |
score+=POINTS_NOREF; |
| 2073 |
|
| 2074 |
match[i]='N'; |
| 2075 |
}else{ |
| 2076 |
match[i]='S'; |
| 2077 |
if(mode==MODE_SUB){timeInMode++;} |
| 2078 |
else{timeInMode=0;} |
| 2079 |
|
| 2080 |
if(timeInMode==0){score+=POINTS_SUB;} |
| 2081 |
else if(timeInMode<LIMIT_FOR_COST_3){score+=POINTS_SUB2;} |
| 2082 |
else{score+=POINTS_SUB3;} |
| 2083 |
mode=MODE_SUB; |
| 2084 |
} |
| 2085 |
} |
| 2086 |
|
| 2087 |
return score; |
| 2088 |
} |
| 2089 |
|
| 2090 |
@Override |
| 2091 |
public final int scoreNoIndelsAndMakeMatchString(byte[] read, byte[] ref, final int refStart, byte[][] matchReturn){ |
| 2092 |
int score=0; |
| 2093 |
int mode=-1; |
| 2094 |
int timeInMode=0; |
| 2095 |
|
| 2096 |
assert(refStart<=ref.length) : refStart+", "+ref.length; |
| 2097 |
|
| 2098 |
|
| 2099 |
|
| 2100 |
int readStart=0; |
| 2101 |
int readStop=read.length; |
| 2102 |
final int refStop=refStart+read.length; |
| 2103 |
if(refStart<0 || refStop>ref.length){return -99999;} |
| 2104 |
if(refStart<0){ |
| 2105 |
readStart=0-refStart; |
| 2106 |
score+=POINTS_NOREF*readStart; |
| 2107 |
} |
| 2108 |
if(refStop>ref.length){ |
| 2109 |
int dif=(refStop-ref.length); |
| 2110 |
System.err.println(new String(read)+"\ndif="+dif+", ref.length="+ref.length+", refStop="+refStop); |
| 2111 |
readStop-=dif; |
| 2112 |
score+=POINTS_NOREF*dif; |
| 2113 |
} |
| 2114 |
assert(refStart+readStop<=ref.length) : "readStart="+readStart+", readStop="+readStop+ |
| 2115 |
", refStart="+refStart+", refStop="+refStop+", ref.length="+ref.length+", read.length="+read.length; |
| 2116 |
|
| 2117 |
assert(matchReturn!=null); |
| 2118 |
assert(matchReturn.length==1); |
| 2119 |
if(matchReturn[0]==null || matchReturn[0].length!=read.length){ |
| 2120 |
assert(matchReturn[0]==null || matchReturn[0].length<read.length) : matchReturn[0].length+"!="+read.length; |
| 2121 |
matchReturn[0]=new byte[read.length]; |
| 2122 |
} |
| 2123 |
final byte[] match=matchReturn[0]; |
| 2124 |
|
| 2125 |
|
| 2126 |
|
| 2127 |
for(int i=readStart; i<readStop; i++){ |
| 2128 |
byte c=read[i]; |
| 2129 |
byte r=ref[refStart+i]; |
| 2130 |
|
| 2131 |
assert(r!='.' && c!='.'); |
| 2132 |
|
| 2133 |
if(c==r && c!='N'){ |
| 2134 |
if(mode==MODE_MS){ |
| 2135 |
timeInMode++; |
| 2136 |
score+=POINTS_MATCH2; |
| 2137 |
}else{ |
| 2138 |
timeInMode=0; |
| 2139 |
score+=POINTS_MATCH; |
| 2140 |
} |
| 2141 |
match[i]='m'; |
| 2142 |
mode=MODE_MS; |
| 2143 |
}else if(c<0 || c=='N'){ |
| 2144 |
score+=POINTS_NOCALL; |
| 2145 |
match[i]='N'; |
| 2146 |
}else if(r<0 || r=='N'){ |
| 2147 |
score+=POINTS_NOREF; |
| 2148 |
|
| 2149 |
match[i]='N'; |
| 2150 |
}else{ |
| 2151 |
match[i]='S'; |
| 2152 |
if(mode==MODE_SUB){timeInMode++;} |
| 2153 |
else{timeInMode=0;} |
| 2154 |
|
| 2155 |
if(timeInMode==0){score+=POINTS_SUB;} |
| 2156 |
else if(timeInMode<LIMIT_FOR_COST_3){score+=POINTS_SUB2;} |
| 2157 |
else{score+=POINTS_SUB3;} |
| 2158 |
mode=MODE_SUB; |
| 2159 |
} |
| 2160 |
} |
| 2161 |
|
| 2162 |
return score; |
| 2163 |
} |
| 2164 |
|
| 2165 |
@Override |
| 2166 |
public final int maxQuality(int numBases){ |
| 2167 |
return POINTS_MATCH+(numBases-1)*(POINTS_MATCH2); |
| 2168 |
} |
| 2169 |
|
| 2170 |
@Override |
| 2171 |
public final int maxQuality(byte[] baseScores){ |
| 2172 |
return POINTS_MATCH+(baseScores.length-1)*(POINTS_MATCH2)+Tools.sumInt(baseScores); |
| 2173 |
} |
| 2174 |
|
| 2175 |
@Override |
| 2176 |
public final int maxImperfectScore(int numBases){ |
| 2177 |
|
| 2178 |
|
| 2179 |
|
| 2180 |
|
| 2181 |
|
| 2182 |
|
| 2183 |
int maxQ=maxQuality(numBases); |
| 2184 |
int maxI=maxQ+Tools.min(POINTS_DEL, POINTS_INS-POINTS_MATCH2); |
| 2185 |
assert(maxI<(maxQ-(POINTS_MATCH2+POINTS_MATCH2)+(POINTS_MATCH+POINTS_SUB))); |
| 2186 |
return maxI; |
| 2187 |
} |
| 2188 |
|
| 2189 |
@Override |
| 2190 |
public final int maxImperfectScore(byte[] baseScores){ |
| 2191 |
|
| 2192 |
|
| 2193 |
|
| 2194 |
|
| 2195 |
|
| 2196 |
|
| 2197 |
int maxQ=maxQuality(baseScores); |
| 2198 |
int maxI=maxQ+Tools.min(POINTS_DEL, POINTS_INS-POINTS_MATCH2); |
| 2199 |
assert(maxI<(maxQ-(POINTS_MATCH2+POINTS_MATCH2)+(POINTS_MATCH+POINTS_SUB))); |
| 2200 |
return maxI; |
| 2201 |
} |
| 2202 |
|
| 2203 |
@Override |
| 2204 |
public int calcDelScore(int len, boolean approximateGaps){ |
| 2205 |
if(len<=0){return 0;} |
| 2206 |
int score=POINTS_DEL; |
| 2207 |
|
| 2208 |
if(approximateGaps && len>MINGAP){ |
| 2209 |
int rem=len%GAPLEN; |
| 2210 |
int div=(len-GAPBUFFER2)/GAPLEN; |
| 2211 |
score+=(div*POINTS_GAP); |
| 2212 |
assert(rem+GAPBUFFER2<len); |
| 2213 |
len=rem+GAPBUFFER2; |
| 2214 |
assert(len>LIMIT_FOR_COST_4); |
| 2215 |
|
| 2216 |
} |
| 2217 |
|
| 2218 |
if(len>LIMIT_FOR_COST_5){ |
| 2219 |
score+=((len-LIMIT_FOR_COST_5+MASK5)/TIMESLIP)*POINTS_DEL5; |
| 2220 |
len=LIMIT_FOR_COST_5; |
| 2221 |
} |
| 2222 |
if(len>LIMIT_FOR_COST_4){ |
| 2223 |
score+=(len-LIMIT_FOR_COST_4)*POINTS_DEL4; |
| 2224 |
len=LIMIT_FOR_COST_4; |
| 2225 |
} |
| 2226 |
if(len>LIMIT_FOR_COST_3){ |
| 2227 |
score+=(len-LIMIT_FOR_COST_3)*POINTS_DEL3; |
| 2228 |
len=LIMIT_FOR_COST_3; |
| 2229 |
} |
| 2230 |
if(len>1){ |
| 2231 |
score+=(len-1)*POINTS_DEL2; |
| 2232 |
} |
| 2233 |
return score; |
| 2234 |
} |
| 2235 |
|
| 2236 |
private static int calcDelScoreOffset(int len){ |
| 2237 |
if(len<=0){return 0;} |
| 2238 |
int score=POINTSoff_DEL; |
| 2239 |
|
| 2240 |
if(len>LIMIT_FOR_COST_5){ |
| 2241 |
score+=((len-LIMIT_FOR_COST_5+MASK5)/TIMESLIP)*POINTSoff_DEL5; |
| 2242 |
len=LIMIT_FOR_COST_5; |
| 2243 |
} |
| 2244 |
if(len>LIMIT_FOR_COST_4){ |
| 2245 |
score+=(len-LIMIT_FOR_COST_4)*POINTSoff_DEL4; |
| 2246 |
len=LIMIT_FOR_COST_4; |
| 2247 |
} |
| 2248 |
if(len>LIMIT_FOR_COST_3){ |
| 2249 |
score+=(len-LIMIT_FOR_COST_3)*POINTSoff_DEL3; |
| 2250 |
len=LIMIT_FOR_COST_3; |
| 2251 |
} |
| 2252 |
if(len>1){ |
| 2253 |
score+=(len-1)*POINTSoff_DEL2; |
| 2254 |
} |
| 2255 |
return score; |
| 2256 |
} |
| 2257 |
|
| 2258 |
@Override |
| 2259 |
public int calcInsScore(int len){ |
| 2260 |
if(len<=0){return 0;} |
| 2261 |
int score=POINTS_INS; |
| 2262 |
|
| 2263 |
if(len>LIMIT_FOR_COST_4){ |
| 2264 |
score+=(len-LIMIT_FOR_COST_4)*POINTS_INS4; |
| 2265 |
len=LIMIT_FOR_COST_4; |
| 2266 |
} |
| 2267 |
if(len>LIMIT_FOR_COST_3){ |
| 2268 |
score+=(len-LIMIT_FOR_COST_3)*POINTS_INS3; |
| 2269 |
len=LIMIT_FOR_COST_3; |
| 2270 |
} |
| 2271 |
if(len>1){ |
| 2272 |
score+=(len-1)*POINTS_INS2; |
| 2273 |
} |
| 2274 |
return score; |
| 2275 |
} |
| 2276 |
|
| 2277 |
private static int calcInsScoreOffset(int len){ |
| 2278 |
if(len<=0){return 0;} |
| 2279 |
int score=POINTSoff_INS; |
| 2280 |
if(len>LIMIT_FOR_COST_4){ |
| 2281 |
score+=(len-LIMIT_FOR_COST_4)*POINTSoff_INS4; |
| 2282 |
len=LIMIT_FOR_COST_4; |
| 2283 |
} |
| 2284 |
if(len>LIMIT_FOR_COST_3){ |
| 2285 |
score+=(len-LIMIT_FOR_COST_3)*POINTSoff_INS3; |
| 2286 |
len=LIMIT_FOR_COST_3; |
| 2287 |
} |
| 2288 |
if(len>1){ |
| 2289 |
score+=(len-1)*POINTSoff_INS2; |
| 2290 |
} |
| 2291 |
return score; |
| 2292 |
} |
| 2293 |
|
| 2294 |
|
| 2295 |
private final int[][][] packed; |
| 2296 |
private final byte[] grefbuffer; |
| 2297 |
private int greflimit=-1; |
| 2298 |
private int greflimit2=-1; |
| 2299 |
private int grefRefOrigin=-1; |
| 2300 |
|
| 2301 |
|
| 2302 |
@Override |
| 2303 |
|
| 2304 |
public final byte[] getGrefbuffer(){ |
| 2305 |
return grefbuffer; |
| 2306 |
} |
| 2307 |
|
| 2308 |
public final int[] vertLimit; |
| 2309 |
public final int[] horizLimit; |
| 2310 |
|
| 2311 |
@Override |
| 2312 |
public CharSequence showVertLimit(){ |
| 2313 |
StringBuilder sb=new StringBuilder(); |
| 2314 |
for(int i=0; i<=rows; i++){sb.append(vertLimit[i]>>SCOREOFFSET).append(",");} |
| 2315 |
return sb; |
| 2316 |
} |
| 2317 |
|
| 2318 |
@Override |
| 2319 |
public CharSequence showHorizLimit(){ |
| 2320 |
StringBuilder sb=new StringBuilder(); |
| 2321 |
for(int i=0; i<=columns; i++){sb.append(horizLimit[i]>>SCOREOFFSET).append(",");} |
| 2322 |
return sb; |
| 2323 |
} |
| 2324 |
|
| 2325 |
public static float minIdToMinRatio(double minid){ |
| 2326 |
if(minid>1){minid=minid/100;} |
| 2327 |
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."; |
| 2328 |
double matchdif=POINTS_MATCH-POINTS_MATCH2; |
| 2329 |
double match=POINTS_MATCH2; |
| 2330 |
double sub=-POINTS_MATCH2+0.5*(matchdif+POINTS_SUB)+0.5*POINTS_SUB2; |
| 2331 |
double del=0.8*(matchdif+POINTS_DEL)+0.1*POINTS_DEL2+0.05*POINTS_DEL3+0.05*POINTS_DEL4; |
| 2332 |
double ins=-POINTS_MATCH2+0.8*(matchdif+POINTS_INS)+0.15*(POINTS_INS2)+0.05*(POINTS_INS3); |
| 2333 |
double badAvg=.2*sub+.3*del+.5*ins; |
| 2334 |
double badFraction=1-minid; |
| 2335 |
double minratio=(match+badFraction*badAvg)/match; |
| 2336 |
assert(minratio<=1); |
| 2337 |
minratio=Tools.max(0.1, minratio); |
| 2338 |
return (float)minratio; |
| 2339 |
} |
| 2340 |
|
| 2341 |
public static final int TIMEBITS=9; |
| 2342 |
public static final int SCOREBITS=32-TIMEBITS; |
| 2343 |
public static final int MAX_TIME=((1<<TIMEBITS)-1); |
| 2344 |
public static final int MAX_SCORE=((1<<(SCOREBITS-1))-1)-2000; |
| 2345 |
public static final int MIN_SCORE=0-MAX_SCORE; |
| 2346 |
|
| 2347 |
public static final int SCOREOFFSET=TIMEBITS; |
| 2348 |
|
| 2349 |
public static final int TIMEMASK=~((-1)<<TIMEBITS); |
| 2350 |
public static final int SCOREMASK=(~((-1)<<SCOREBITS))<<SCOREOFFSET; |
| 2351 |
|
| 2352 |
public static final int POINTS_NOREF=0; |
| 2353 |
public static final int POINTS_NOCALL=0; |
| 2354 |
public static final int POINTS_MATCH=90; |
| 2355 |
public static final int POINTS_MATCH2=100; |
| 2356 |
public static final int POINTS_COMPATIBLE=50; |
| 2357 |
public static final int POINTS_SUB=-137; |
| 2358 |
public static final int POINTS_SUBR=-157; |
| 2359 |
public static final int POINTS_SUB2=-49; |
| 2360 |
public static final int POINTS_SUB3=-25; |
| 2361 |
public static final int POINTS_MATCHSUB=-10; |
| 2362 |
public static final int POINTS_INS=-205; |
| 2363 |
public static final int POINTS_INS2=-42; |
| 2364 |
public static final int POINTS_INS3=-23; |
| 2365 |
public static final int POINTS_INS4=-8; |
| 2366 |
public static final int POINTS_DEL=-292; |
| 2367 |
public static final int POINTS_DEL2=-37; |
| 2368 |
public static final int POINTS_DEL3=-17; |
| 2369 |
public static final int POINTS_DEL4=-2; |
| 2370 |
public static final int POINTS_DEL5=-1; |
| 2371 |
public static final int POINTS_DEL_REF_N=-10; |
| 2372 |
public static final int POINTS_GAP=0-GAPCOST; |
| 2373 |
|
| 2374 |
public static final int TIMESLIP=4; |
| 2375 |
public static final int MASK5=TIMESLIP-1; |
| 2376 |
static{assert(Integer.bitCount(TIMESLIP)==1);} |
| 2377 |
|
| 2378 |
|
| 2379 |
private static final int BARRIER_I1=1; |
| 2380 |
private static final int BARRIER_D1=1; |
| 2381 |
|
| 2382 |
|
| 2383 |
public static final int LIMIT_FOR_COST_3=5; |
| 2384 |
public static final int LIMIT_FOR_COST_4=20; |
| 2385 |
public static final int LIMIT_FOR_COST_5=80; |
| 2386 |
|
| 2387 |
public static final int BAD=MIN_SCORE-1; |
| 2388 |
|
| 2389 |
|
| 2390 |
public static final int POINTSoff_NOREF=(POINTS_NOREF<<SCOREOFFSET); |
| 2391 |
public static final int POINTSoff_NOCALL=(POINTS_NOCALL<<SCOREOFFSET); |
| 2392 |
public static final int POINTSoff_MATCH=(POINTS_MATCH<<SCOREOFFSET); |
| 2393 |
public static final int POINTSoff_MATCH2=(POINTS_MATCH2<<SCOREOFFSET); |
| 2394 |
public static final int POINTSoff_COMPATIBLE=(POINTS_COMPATIBLE<<SCOREOFFSET); |
| 2395 |
public static final int POINTSoff_SUB=(POINTS_SUB<<SCOREOFFSET); |
| 2396 |
public static final int POINTSoff_SUBR=(POINTS_SUBR<<SCOREOFFSET); |
| 2397 |
public static final int POINTSoff_SUB2=(POINTS_SUB2<<SCOREOFFSET); |
| 2398 |
public static final int POINTSoff_SUB3=(POINTS_SUB3<<SCOREOFFSET); |
| 2399 |
public static final int POINTSoff_MATCHSUB=(POINTS_MATCHSUB<<SCOREOFFSET); |
| 2400 |
public static final int POINTSoff_INS=(POINTS_INS<<SCOREOFFSET); |
| 2401 |
public static final int POINTSoff_INS2=(POINTS_INS2<<SCOREOFFSET); |
| 2402 |
public static final int POINTSoff_INS3=(POINTS_INS3<<SCOREOFFSET); |
| 2403 |
public static final int POINTSoff_INS4=(POINTS_INS4<<SCOREOFFSET); |
| 2404 |
public static final int POINTSoff_DEL=(POINTS_DEL<<SCOREOFFSET); |
| 2405 |
public static final int POINTSoff_DEL2=(POINTS_DEL2<<SCOREOFFSET); |
| 2406 |
public static final int POINTSoff_DEL3=(POINTS_DEL3<<SCOREOFFSET); |
| 2407 |
public static final int POINTSoff_DEL4=(POINTS_DEL4<<SCOREOFFSET); |
| 2408 |
public static final int POINTSoff_DEL5=(POINTS_DEL5<<SCOREOFFSET); |
| 2409 |
public static final int POINTSoff_GAP=(POINTS_GAP<<SCOREOFFSET); |
| 2410 |
public static final int POINTSoff_DEL_REF_N=(POINTS_DEL_REF_N<<SCOREOFFSET); |
| 2411 |
public static final int BADoff=(BAD<<SCOREOFFSET); |
| 2412 |
public static final int MAXoff_SCORE=MAX_SCORE<<SCOREOFFSET; |
| 2413 |
public static final int MINoff_SCORE=MIN_SCORE<<SCOREOFFSET; |
| 2414 |
|
| 2415 |
|
| 2416 |
public static final boolean AFFINE_ARRAYS=false; |
| 2417 |
public static final int[] POINTS_INS_ARRAY; |
| 2418 |
public static final int[] POINTSoff_INS_ARRAY; |
| 2419 |
public static final int[] POINTS_INS_ARRAY_C; |
| 2420 |
public static final int[] POINTSoff_INS_ARRAY_C; |
| 2421 |
|
| 2422 |
public static final int[] POINTS_SUB_ARRAY; |
| 2423 |
public static final int[] POINTSoff_SUB_ARRAY; |
| 2424 |
public static final int[] POINTS_SUB_ARRAY_C; |
| 2425 |
public static final int[] POINTSoff_SUB_ARRAY_C; |
| 2426 |
|
| 2427 |
static{ |
| 2428 |
POINTS_INS_ARRAY=new int[604]; |
| 2429 |
POINTSoff_INS_ARRAY=new int[604]; |
| 2430 |
POINTS_INS_ARRAY_C=new int[604]; |
| 2431 |
POINTSoff_INS_ARRAY_C=new int[604]; |
| 2432 |
|
| 2433 |
for(int i=1; i<POINTS_INS_ARRAY.length; i++){ |
| 2434 |
int pts, ptsoff; |
| 2435 |
if(i>LIMIT_FOR_COST_4){ |
| 2436 |
pts=POINTS_INS4; |
| 2437 |
ptsoff=POINTSoff_INS4; |
| 2438 |
}else if(i>LIMIT_FOR_COST_3){ |
| 2439 |
pts=POINTS_INS3; |
| 2440 |
ptsoff=POINTSoff_INS3; |
| 2441 |
}else if(i>1){ |
| 2442 |
pts=POINTS_INS2; |
| 2443 |
ptsoff=POINTSoff_INS2; |
| 2444 |
}else{ |
| 2445 |
pts=POINTS_INS; |
| 2446 |
ptsoff=POINTSoff_INS; |
| 2447 |
} |
| 2448 |
POINTS_INS_ARRAY[i]=pts; |
| 2449 |
POINTSoff_INS_ARRAY[i]=ptsoff; |
| 2450 |
POINTS_INS_ARRAY_C[i]=Tools.max(MIN_SCORE, pts+POINTS_INS_ARRAY_C[i-1]); |
| 2451 |
POINTSoff_INS_ARRAY_C[i]=Tools.max(MINoff_SCORE, ptsoff+POINTSoff_INS_ARRAY_C[i-1]); |
| 2452 |
} |
| 2453 |
|
| 2454 |
|
| 2455 |
POINTS_SUB_ARRAY=new int[604]; |
| 2456 |
POINTSoff_SUB_ARRAY=new int[604]; |
| 2457 |
POINTS_SUB_ARRAY_C=new int[604]; |
| 2458 |
POINTSoff_SUB_ARRAY_C=new int[604]; |
| 2459 |
|
| 2460 |
for(int i=1; i<POINTS_SUB_ARRAY.length; i++){ |
| 2461 |
int pts, ptsoff; |
| 2462 |
if(i>LIMIT_FOR_COST_3){ |
| 2463 |
pts=POINTS_SUB3; |
| 2464 |
ptsoff=POINTSoff_SUB3; |
| 2465 |
}else if(i>1){ |
| 2466 |
pts=POINTS_SUB2; |
| 2467 |
ptsoff=POINTSoff_SUB2; |
| 2468 |
}else{ |
| 2469 |
pts=POINTS_SUB; |
| 2470 |
ptsoff=POINTSoff_SUB; |
| 2471 |
} |
| 2472 |
POINTS_SUB_ARRAY[i]=pts; |
| 2473 |
POINTSoff_SUB_ARRAY[i]=ptsoff; |
| 2474 |
POINTS_SUB_ARRAY_C[i]=Tools.max(MIN_SCORE, pts+POINTS_SUB_ARRAY_C[i-1]); |
| 2475 |
POINTSoff_SUB_ARRAY_C[i]=Tools.max(MINoff_SCORE, ptsoff+POINTSoff_SUB_ARRAY_C[i-1]); |
| 2476 |
} |
| 2477 |
} |
| 2478 |
|
| 2479 |
@Override |
| 2480 |
public final int POINTS_NOREF(){return POINTS_NOREF;} |
| 2481 |
@Override |
| 2482 |
public final int POINTS_NOCALL(){return POINTS_NOCALL;} |
| 2483 |
@Override |
| 2484 |
public final int POINTS_MATCH(){return POINTS_MATCH;} |
| 2485 |
@Override |
| 2486 |
public final int POINTS_MATCH2(){return POINTS_MATCH2;} |
| 2487 |
@Override |
| 2488 |
public final int POINTS_COMPATIBLE(){return POINTS_COMPATIBLE;} |
| 2489 |
@Override |
| 2490 |
public final int POINTS_SUB(){return POINTS_SUB;} |
| 2491 |
@Override |
| 2492 |
public final int POINTS_SUBR(){return POINTS_SUBR;} |
| 2493 |
@Override |
| 2494 |
public final int POINTS_SUB2(){return POINTS_SUB2;} |
| 2495 |
@Override |
| 2496 |
public final int POINTS_SUB3(){return POINTS_SUB3;} |
| 2497 |
@Override |
| 2498 |
public final int POINTS_MATCHSUB(){return POINTS_MATCHSUB;} |
| 2499 |
@Override |
| 2500 |
public final int POINTS_INS(){return POINTS_INS;} |
| 2501 |
@Override |
| 2502 |
public final int POINTS_INS2(){return POINTS_INS2;} |
| 2503 |
@Override |
| 2504 |
public final int POINTS_INS3(){return POINTS_INS3;} |
| 2505 |
@Override |
| 2506 |
public final int POINTS_INS4(){return POINTS_INS4;} |
| 2507 |
@Override |
| 2508 |
public final int POINTS_DEL(){return POINTS_DEL;} |
| 2509 |
@Override |
| 2510 |
public final int POINTS_DEL2(){return POINTS_DEL2;} |
| 2511 |
@Override |
| 2512 |
public final int POINTS_DEL3(){return POINTS_DEL3;} |
| 2513 |
@Override |
| 2514 |
public final int POINTS_DEL4(){return POINTS_DEL4;} |
| 2515 |
@Override |
| 2516 |
public final int POINTS_DEL5(){return POINTS_DEL5;} |
| 2517 |
@Override |
| 2518 |
public final int POINTS_DEL_REF_N(){return POINTS_DEL_REF_N;} |
| 2519 |
@Override |
| 2520 |
public final int POINTS_GAP(){return POINTS_GAP;} |
| 2521 |
|
| 2522 |
@Override |
| 2523 |
public final int TIMESLIP(){return TIMESLIP;} |
| 2524 |
@Override |
| 2525 |
public final int MASK5(){return MASK5;} |
| 2526 |
@Override |
| 2527 |
public final int SCOREOFFSET(){return SCOREOFFSET();} |
| 2528 |
|
| 2529 |
@Override |
| 2530 |
final int BARRIER_I1(){return BARRIER_I1;} |
| 2531 |
@Override |
| 2532 |
final int BARRIER_D1(){return BARRIER_D1;} |
| 2533 |
|
| 2534 |
@Override |
| 2535 |
public final int LIMIT_FOR_COST_3(){return LIMIT_FOR_COST_3;} |
| 2536 |
@Override |
| 2537 |
public final int LIMIT_FOR_COST_4(){return LIMIT_FOR_COST_4;} |
| 2538 |
@Override |
| 2539 |
public final int LIMIT_FOR_COST_5(){return LIMIT_FOR_COST_5;} |
| 2540 |
|
| 2541 |
@Override |
| 2542 |
public final int BAD(){return BAD;} |
| 2543 |
|
| 2544 |
|
| 2545 |
private int rows; |
| 2546 |
private int columns; |
| 2547 |
|
| 2548 |
} |