annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/opt/bbmap-39.01-1/current/aligner/SingleStateAlignerFlat2.java @ 68:5028fdace37b

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 16:23:26 -0400
parents
children
rev   line source
jpayne@68 1 package aligner;
jpayne@68 2
jpayne@68 3 import dna.AminoAcid;
jpayne@68 4 import shared.KillSwitch;
jpayne@68 5 import shared.Tools;
jpayne@68 6
jpayne@68 7 /**
jpayne@68 8 * Based on SSAFlat, but with previous state pointers removed. */
jpayne@68 9 public final class SingleStateAlignerFlat2 implements Aligner {
jpayne@68 10
jpayne@68 11
jpayne@68 12 public SingleStateAlignerFlat2(){}
jpayne@68 13
jpayne@68 14 private void prefillTopRow(){
jpayne@68 15 final int[] header=packed[0];
jpayne@68 16 final int qlen=rows;
jpayne@68 17 for(int i=0; i<=columns; i++){
jpayne@68 18 int x=columns-i+1;
jpayne@68 19 int qbases=qlen-x;
jpayne@68 20
jpayne@68 21 //Minimal points to prefer a leftmost alignment
jpayne@68 22 header[i]=qbases<=0 ? 0 : -qbases;
jpayne@68 23
jpayne@68 24 //Forces consumption of query, but does not allow for insertions...
jpayne@68 25 // header[i]=qbases<=0 ? 0 : calcDelScoreOffset(qbases);
jpayne@68 26 }
jpayne@68 27 }
jpayne@68 28
jpayne@68 29 private void prefillLeftColumnStartingAt(int i){
jpayne@68 30 packed[0][0]=MODE_MATCH;
jpayne@68 31 i=Tools.max(1, i);
jpayne@68 32 for(int score=MODE_INS+(POINTS_INS*i); i<=maxRows; i++){//Fill column 0 with insertions
jpayne@68 33 score+=POINTS_INS;
jpayne@68 34 packed[i][0]=score;
jpayne@68 35 }
jpayne@68 36 }
jpayne@68 37
jpayne@68 38 private void initialize(int rows_, int columns_){
jpayne@68 39 rows=rows_;
jpayne@68 40 columns=columns_;
jpayne@68 41 if(rows<=maxRows && columns<=maxColumns){
jpayne@68 42 prefillTopRow();
jpayne@68 43 // prefillLeftColumn();
jpayne@68 44 return;
jpayne@68 45 }
jpayne@68 46
jpayne@68 47 final int maxRows0=maxRows;
jpayne@68 48 final int maxColumns0=maxColumns;
jpayne@68 49 final int[][] packed0=packed;
jpayne@68 50
jpayne@68 51 //Monotonic increase
jpayne@68 52 maxRows=Tools.max(maxRows, rows+10);
jpayne@68 53 maxColumns=Tools.max(maxColumns, columns+10);
jpayne@68 54
jpayne@68 55 if(packed==null || maxColumns>maxColumns0){//Make a new matrix
jpayne@68 56 packed=KillSwitch.allocInt2D(maxRows+1, maxColumns+1);
jpayne@68 57 prefillLeftColumnStartingAt(1);
jpayne@68 58 }else{//Copy old rows
jpayne@68 59 assert(maxRows0>0 && maxColumns0>0);
jpayne@68 60 assert(maxRows>maxRows0 && maxColumns<=maxColumns0) : "rows="+rows+",maxRows="+maxRows+
jpayne@68 61 ",maxRows0="+maxRows0+",columns="+columns+",maxColumns="+maxColumns+",maxColumns0="+maxColumns0;
jpayne@68 62 packed=KillSwitch.allocInt2D(maxRows+1);
jpayne@68 63 for(int i=0; i<packed.length; i++){
jpayne@68 64 if(i<packed0.length){
jpayne@68 65 packed[i]=packed0[i];
jpayne@68 66 }else{
jpayne@68 67 packed[i]=KillSwitch.allocInt1D(maxColumns+1);
jpayne@68 68 }
jpayne@68 69 }
jpayne@68 70 //Fill column 0 with insertions
jpayne@68 71 prefillLeftColumnStartingAt(maxRows0);
jpayne@68 72 }
jpayne@68 73 prefillTopRow();
jpayne@68 74 }
jpayne@68 75
jpayne@68 76 /** return new int[] {rows, maxCol, maxState, maxScore, maxStart};
jpayne@68 77 * Will not fill areas that cannot match minScore */
jpayne@68 78 @Override
jpayne@68 79 public final int[] fillLimited(byte[] read, byte[] ref, int refStartLoc, int refEndLoc, int minScore){
jpayne@68 80 return fillUnlimited(read, ref, refStartLoc, refEndLoc, minScore);
jpayne@68 81 }
jpayne@68 82
jpayne@68 83 @Override
jpayne@68 84 public final int[] fillUnlimited(byte[] read, byte[] ref, int refStartLoc, int refEndLoc){
jpayne@68 85 return fillUnlimited(read, ref, refStartLoc, refEndLoc, -999999);
jpayne@68 86 }
jpayne@68 87
jpayne@68 88 /** return new int[] {rows, maxCol, maxState, maxScore, maxStart};
jpayne@68 89 * Min score is optional */
jpayne@68 90 @Override
jpayne@68 91 public final int[] fillUnlimited(byte[] read, byte[] ref, int refStartLoc, int refEndLoc, int minScore){
jpayne@68 92 initialize(read.length, refEndLoc-refStartLoc+1);
jpayne@68 93
jpayne@68 94 //temporary, for finding a bug
jpayne@68 95 if(rows>maxRows || columns>maxColumns){
jpayne@68 96 throw new RuntimeException("rows="+rows+", maxRows="+maxRows+", cols="+columns+", maxCols="+maxColumns+"\n"+new String(read)+"\n");
jpayne@68 97 }
jpayne@68 98
jpayne@68 99 assert(rows<=maxRows) : "Check that values are in-bounds before calling this function: "+rows+", "+maxRows;
jpayne@68 100 assert(columns<=maxColumns) : "Check that values are in-bounds before calling this function: "+columns+", "+maxColumns;
jpayne@68 101
jpayne@68 102 assert(refStartLoc>=0) : "Check that values are in-bounds before calling this function: "+refStartLoc;
jpayne@68 103 assert(refEndLoc<ref.length) : "Check that values are in-bounds before calling this function: "+refEndLoc+", "+ref.length;
jpayne@68 104
jpayne@68 105 final int refOffset=refStartLoc-1;
jpayne@68 106 for(int row=1; row<=rows; row++){
jpayne@68 107
jpayne@68 108 final byte qBase=read[row-1];
jpayne@68 109 for(int col=1; col<=columns; col++){
jpayne@68 110
jpayne@68 111 final byte rBase=ref[refOffset+col];
jpayne@68 112
jpayne@68 113 final boolean match=(qBase==rBase);
jpayne@68 114 final boolean defined=(qBase!='N' && rBase!='N');
jpayne@68 115
jpayne@68 116 final int scoreFromDiag=packed[row-1][col-1];
jpayne@68 117 final int scoreFromDel=packed[row][col-1];
jpayne@68 118 final int scoreFromIns=packed[row-1][col];
jpayne@68 119
jpayne@68 120 final int diagScoreM=POINTS_MATCH;
jpayne@68 121 final int diagScoreS=POINTS_SUB;
jpayne@68 122 final int delScore=scoreFromDel+POINTS_DEL;
jpayne@68 123 final int insScore=scoreFromIns+POINTS_INS;
jpayne@68 124
jpayne@68 125 // final int diagScore=scoreFromDiag+(defined ? (match ? diagScoreM : diagScoreS) : POINTS_NOREF);
jpayne@68 126 int diagScore=(match ? diagScoreM : diagScoreS);
jpayne@68 127 diagScore=scoreFromDiag+(defined ? diagScore : POINTS_NOREF);
jpayne@68 128
jpayne@68 129 int score=diagScore>=delScore ? diagScore : delScore;
jpayne@68 130 score=score>=insScore ? score : insScore;
jpayne@68 131
jpayne@68 132 packed[row][col]=score;
jpayne@68 133 }
jpayne@68 134 //iterationsUnlimited+=columns;
jpayne@68 135 }
jpayne@68 136
jpayne@68 137
jpayne@68 138 int maxCol=-1;
jpayne@68 139 int maxState=-1;
jpayne@68 140 int maxStart=-1;
jpayne@68 141 int maxScore=Integer.MIN_VALUE;
jpayne@68 142
jpayne@68 143 for(int col=1; col<=columns; col++){
jpayne@68 144 int x=packed[rows][col];
jpayne@68 145 if(x>maxScore){
jpayne@68 146 maxScore=x;
jpayne@68 147 maxCol=col;
jpayne@68 148
jpayne@68 149 // assert(rows-1<read.length) : (rows-1)+", "+read.length;
jpayne@68 150 // assert(refOffset+col<ref.length) : refOffset+", "+col+", "+ref.length;
jpayne@68 151 maxState=getState(rows, col, read[rows-1], ref[refOffset+col]);
jpayne@68 152 maxStart=x;
jpayne@68 153 }
jpayne@68 154 }
jpayne@68 155
jpayne@68 156 // System.err.println("Returning "+rows+", "+maxCol+", "+maxState+", "+maxScore+"; minScore="+minScore);
jpayne@68 157 return maxScore<minScore ? null : new int[] {rows, maxCol, maxState, maxScore, maxStart};
jpayne@68 158 }
jpayne@68 159
jpayne@68 160 int getState(int row, int col, byte q, byte r){//zxvzxcv TODO: Fix - needs to find max
jpayne@68 161 final boolean match=(q==r);
jpayne@68 162 final boolean defined=(q!='N' && r!='N');
jpayne@68 163
jpayne@68 164 final int scoreFromDiag=packed[row-1][col-1];
jpayne@68 165 final int scoreFromDel=packed[row][col-1];
jpayne@68 166 final int scoreFromIns=packed[row-1][col];
jpayne@68 167 // final int score=packed[row][col];
jpayne@68 168
jpayne@68 169 final int diagScoreM=POINTS_MATCH;
jpayne@68 170 final int diagScoreS=POINTS_SUB;
jpayne@68 171 final int delScore=scoreFromDel+POINTS_DEL;
jpayne@68 172 final int insScore=scoreFromIns+POINTS_INS;
jpayne@68 173
jpayne@68 174 final int diagScore=scoreFromDiag+(defined ? (match ? diagScoreM : diagScoreS) : POINTS_NOREF);
jpayne@68 175
jpayne@68 176 // int score2=diagScore>=delScore ? diagScore : delScore;
jpayne@68 177 // score2=score>=insScore ? score : insScore;
jpayne@68 178
jpayne@68 179 // assert(score==score2) : score+", "+score2;
jpayne@68 180
jpayne@68 181 if(diagScore>=delScore && diagScore>=insScore){
jpayne@68 182 return defined ? match ? MODE_MATCH : MODE_SUB : MODE_N;
jpayne@68 183 }else if(delScore>=insScore){
jpayne@68 184 return MODE_DEL;
jpayne@68 185 }
jpayne@68 186 return MODE_INS;
jpayne@68 187 }
jpayne@68 188
jpayne@68 189
jpayne@68 190 /** Generates the match string.
jpayne@68 191 * State is NOT used. */
jpayne@68 192 @Override
jpayne@68 193 public final byte[] traceback(byte[] query, byte[] ref, int refStartLoc, int refEndLoc, int row, int col, int state){
jpayne@68 194 // assert(false);
jpayne@68 195 assert(refStartLoc<=refEndLoc) : refStartLoc+", "+refEndLoc;
jpayne@68 196 assert(row==rows);
jpayne@68 197
jpayne@68 198 byte[] out=new byte[row+col-1]; //TODO if an out of bound crash occurs, try removing the "-1".
jpayne@68 199 int outPos=0;
jpayne@68 200
jpayne@68 201 // assert(state==(packed[row][col]&MODEMASK));
jpayne@68 202
jpayne@68 203 while(row>0 && col>0){
jpayne@68 204 byte q=query[row-1];
jpayne@68 205 byte r=ref[refStartLoc+col-1];
jpayne@68 206 boolean defined=(AminoAcid.isFullyDefined(q) && AminoAcid.isFullyDefined(r));
jpayne@68 207 state=getState(row, col, q, r);
jpayne@68 208 if(state==MODE_MATCH){
jpayne@68 209 col--;
jpayne@68 210 row--;
jpayne@68 211 out[outPos]=defined ? (byte)'m' : (byte)'N';
jpayne@68 212 }else if(state==MODE_SUB){
jpayne@68 213 col--;
jpayne@68 214 row--;
jpayne@68 215 out[outPos]=defined ? (byte)'S' : (byte)'N';
jpayne@68 216 }else if(state==MODE_N){
jpayne@68 217 col--;
jpayne@68 218 row--;
jpayne@68 219 out[outPos]='N';
jpayne@68 220 }else if(state==MODE_DEL){
jpayne@68 221 col--;
jpayne@68 222 out[outPos]='D';
jpayne@68 223 }else if(state==MODE_INS){
jpayne@68 224 row--;
jpayne@68 225 // out[outPos]='I';
jpayne@68 226 // out[outPos]=(col<0 || col>=columns ? (byte)'C' : (byte)'I');
jpayne@68 227 if(col>=0 && col<columns){
jpayne@68 228 out[outPos]='I';
jpayne@68 229 }else{
jpayne@68 230 out[outPos]='C';
jpayne@68 231 col--;
jpayne@68 232 }
jpayne@68 233 }else{
jpayne@68 234 assert(false) : state;
jpayne@68 235 }
jpayne@68 236 outPos++;
jpayne@68 237 }
jpayne@68 238
jpayne@68 239 assert(row==0 || col==0);
jpayne@68 240 if(col!=row){
jpayne@68 241 while(row>0){
jpayne@68 242 out[outPos]='C';
jpayne@68 243 outPos++;
jpayne@68 244 row--;
jpayne@68 245 col--;
jpayne@68 246 }
jpayne@68 247 if(col>0){
jpayne@68 248 //do nothing
jpayne@68 249 }
jpayne@68 250 }
jpayne@68 251
jpayne@68 252 //Shrink and reverse the string
jpayne@68 253 byte[] out2=new byte[outPos];
jpayne@68 254 for(int i=0; i<outPos; i++){
jpayne@68 255 out2[i]=out[outPos-i-1];
jpayne@68 256 }
jpayne@68 257 out=null;
jpayne@68 258
jpayne@68 259 return out2;
jpayne@68 260 }
jpayne@68 261
jpayne@68 262 @Override
jpayne@68 263 /** Generates identity;
jpayne@68 264 * fills 'extra' with {match, sub, del, ins, N, clip} if present */
jpayne@68 265 public float tracebackIdentity(byte[] query, byte[] ref, int refStartLoc, int refEndLoc, int row, int col, int state, int[] extra){
jpayne@68 266
jpayne@68 267 // assert(false);
jpayne@68 268 assert(refStartLoc<=refEndLoc) : refStartLoc+", "+refEndLoc;
jpayne@68 269 assert(row==rows);
jpayne@68 270
jpayne@68 271 // assert(state==(packed[row][col]&MODEMASK));
jpayne@68 272 int match=0, sub=0, del=0, ins=0, noref=0, clip=0;
jpayne@68 273
jpayne@68 274 while(row>0 && col>0){
jpayne@68 275 byte q=query[row-1];
jpayne@68 276 byte r=ref[refStartLoc+col-1];
jpayne@68 277 boolean defined=(AminoAcid.isFullyDefined(q) && AminoAcid.isFullyDefined(r));
jpayne@68 278 state=getState(row, col, q, r);
jpayne@68 279 if(state==MODE_MATCH){
jpayne@68 280 col--;
jpayne@68 281 row--;
jpayne@68 282 match+=(defined ? 1 : 0);
jpayne@68 283 noref+=(defined ? 0 : 1);
jpayne@68 284 }else if(state==MODE_SUB){
jpayne@68 285 col--;
jpayne@68 286 row--;
jpayne@68 287 sub+=(defined ? 1 : 0);
jpayne@68 288 noref+=(defined ? 0 : 1);
jpayne@68 289 }else if(state==MODE_N){
jpayne@68 290 col--;
jpayne@68 291 row--;
jpayne@68 292 noref++;
jpayne@68 293 }else if(state==MODE_DEL){
jpayne@68 294 col--;
jpayne@68 295 del++;
jpayne@68 296 }else if(state==MODE_INS){
jpayne@68 297 row--;
jpayne@68 298 boolean edge=(col<=1 || col>=columns);
jpayne@68 299 ins+=(edge ? 0 : 1);
jpayne@68 300 clip+=(edge ? 1 : 0);
jpayne@68 301 }else{
jpayne@68 302 assert(false) : state;
jpayne@68 303 }
jpayne@68 304 }
jpayne@68 305
jpayne@68 306 assert(row==0 || col==0);
jpayne@68 307 if(col!=row){//Not sure what this is doing
jpayne@68 308 while(row>0){
jpayne@68 309 clip++;
jpayne@68 310 row--;
jpayne@68 311 col--;
jpayne@68 312 }
jpayne@68 313 if(col>0){
jpayne@68 314 //do nothing
jpayne@68 315 }
jpayne@68 316 }
jpayne@68 317
jpayne@68 318 if(extra!=null){
jpayne@68 319 assert(extra.length==5);
jpayne@68 320 extra[0]=match;
jpayne@68 321 extra[1]=sub;
jpayne@68 322 extra[2]=del;
jpayne@68 323 extra[3]=ins;
jpayne@68 324 extra[4]=noref;
jpayne@68 325 extra[5]=clip;
jpayne@68 326 }
jpayne@68 327
jpayne@68 328 float len=match+sub+ins+del+noref*0.1f;
jpayne@68 329 float id=match/Tools.max(1.0f, len);
jpayne@68 330 return id;
jpayne@68 331 }
jpayne@68 332
jpayne@68 333 /** @return {score, bestRefStart, bestRefStop} */
jpayne@68 334 @Override
jpayne@68 335 public final int[] score(final byte[] read, final byte[] ref, final int refStartLoc, final int refEndLoc,
jpayne@68 336 final int maxRow, final int maxCol, final int maxState/*, final int maxScore, final int maxStart*/){
jpayne@68 337
jpayne@68 338 int row=maxRow;
jpayne@68 339 int col=maxCol;
jpayne@68 340 int state=maxState;
jpayne@68 341
jpayne@68 342 assert(maxState>=0 && maxState<packed.length) :
jpayne@68 343 maxState+", "+maxRow+", "+maxCol+"\n"+new String(read)+"\n"+toString(ref, refStartLoc, refEndLoc);
jpayne@68 344 assert(maxRow>=0 && maxRow<packed.length) :
jpayne@68 345 maxState+", "+maxRow+", "+maxCol+"\n"+new String(read)+"\n"+toString(ref, refStartLoc, refEndLoc);
jpayne@68 346 assert(maxCol>=0 && maxCol<packed[0].length) :
jpayne@68 347 maxState+", "+maxRow+", "+maxCol+"\n"+new String(read)+"\n"+toString(ref, refStartLoc, refEndLoc);
jpayne@68 348
jpayne@68 349 int score=packed[maxRow][maxCol]; //Or zero, if it is to be recalculated
jpayne@68 350
jpayne@68 351 if(row<rows){
jpayne@68 352 int difR=rows-row;
jpayne@68 353 int difC=columns-col;
jpayne@68 354
jpayne@68 355 while(difR>difC){
jpayne@68 356 score+=POINTS_NOREF;
jpayne@68 357 difR--;
jpayne@68 358 }
jpayne@68 359
jpayne@68 360 row+=difR;
jpayne@68 361 col+=difR;
jpayne@68 362
jpayne@68 363 }
jpayne@68 364
jpayne@68 365 assert(refStartLoc<=refEndLoc);
jpayne@68 366 assert(row==rows);
jpayne@68 367
jpayne@68 368
jpayne@68 369 final int bestRefStop=refStartLoc+col-1;
jpayne@68 370
jpayne@68 371 while(row>0 && col>0){
jpayne@68 372 final byte q=read[row-1];
jpayne@68 373 final byte r=ref[refStartLoc+col-1];
jpayne@68 374 // final boolean defined=(AminoAcid.isFullyDefined(q) && AminoAcid.isFullyDefined(r));
jpayne@68 375 state=getState(row, col, q, r);
jpayne@68 376 if(state==MODE_MATCH){
jpayne@68 377 col--;
jpayne@68 378 row--;
jpayne@68 379 }else if(state==MODE_SUB){
jpayne@68 380 col--;
jpayne@68 381 row--;
jpayne@68 382 }else if(state==MODE_N){
jpayne@68 383 col--;
jpayne@68 384 row--;
jpayne@68 385 }else if(state==MODE_DEL){
jpayne@68 386 col--;
jpayne@68 387 }else if(state==MODE_INS){
jpayne@68 388 row--;
jpayne@68 389 }else{
jpayne@68 390 assert(false) : state;
jpayne@68 391 }
jpayne@68 392 }
jpayne@68 393 // assert(false) : row+", "+col;
jpayne@68 394 if(row>col){
jpayne@68 395 col-=row;
jpayne@68 396 }
jpayne@68 397
jpayne@68 398 final int bestRefStart=refStartLoc+col;
jpayne@68 399
jpayne@68 400 // System.err.println("t2\t"+score+", "+maxScore+", "+maxStart+", "+bestRefStart);
jpayne@68 401 int[] rvec;
jpayne@68 402 if(bestRefStart<refStartLoc || bestRefStop>refEndLoc){ //Suggest extra padding in cases of overflow
jpayne@68 403 int padLeft=Tools.max(0, refStartLoc-bestRefStart);
jpayne@68 404 int padRight=Tools.max(0, bestRefStop-refEndLoc);
jpayne@68 405 rvec=new int[] {score, bestRefStart, bestRefStop, padLeft, padRight};
jpayne@68 406 }else{
jpayne@68 407 rvec=new int[] {score, bestRefStart, bestRefStop};
jpayne@68 408 }
jpayne@68 409 return rvec;
jpayne@68 410 }
jpayne@68 411
jpayne@68 412
jpayne@68 413 /** Will not fill areas that cannot match minScore.
jpayne@68 414 * @return {score, bestRefStart, bestRefStop} */
jpayne@68 415 @Override
jpayne@68 416 public final int[] fillAndScoreLimited(byte[] read, byte[] ref, int refStartLoc, int refEndLoc, int minScore){
jpayne@68 417 int a=Tools.max(0, refStartLoc);
jpayne@68 418 int b=Tools.min(ref.length-1, refEndLoc);
jpayne@68 419 assert(b>=a);
jpayne@68 420
jpayne@68 421 if(b-a>=maxColumns){
jpayne@68 422 System.err.println("Warning: Max alignment columns exceeded; restricting range. "+(b-a+1)+" > "+maxColumns);
jpayne@68 423 assert(false) : refStartLoc+", "+refEndLoc;
jpayne@68 424 b=Tools.min(ref.length-1, a+maxColumns-1);
jpayne@68 425 }
jpayne@68 426 int[] max=fillLimited(read, ref, a, b, minScore);
jpayne@68 427 // return max==null ? null : new int[] {max[3], 0, max[1]};
jpayne@68 428
jpayne@68 429 int[] score=(max==null ? null : score(read, ref, a, b, max[0], max[1], max[2]/*, max[3], max[4]*/));
jpayne@68 430
jpayne@68 431 return score;
jpayne@68 432 }
jpayne@68 433
jpayne@68 434 public static final String toString(byte[] ref, int startLoc, int stopLoc){
jpayne@68 435 StringBuilder sb=new StringBuilder(stopLoc-startLoc+1);
jpayne@68 436 for(int i=startLoc; i<=stopLoc; i++){sb.append((char)ref[i]);}
jpayne@68 437 return sb.toString();
jpayne@68 438 }
jpayne@68 439
jpayne@68 440 // public static int calcDelScore(int len){
jpayne@68 441 // if(len<=0){return 0;}
jpayne@68 442 // int score=POINTS_DEL;
jpayne@68 443 // if(len>1){
jpayne@68 444 // score+=(len-1)*POINTS_DEL2;
jpayne@68 445 // }
jpayne@68 446 // return score;
jpayne@68 447 // }
jpayne@68 448
jpayne@68 449 // public int maxScoreByIdentity(int len, float identity){
jpayne@68 450 // assert(identity>=0 && identity<=1);
jpayne@68 451 // return (int)(len*(identity*POINTS_MATCH+(1-identity)*POINTS_SUB));
jpayne@68 452 // }
jpayne@68 453
jpayne@68 454 @Override
jpayne@68 455 public int minScoreByIdentity(int len, float identity){
jpayne@68 456 assert(identity>=0 && identity<=1);
jpayne@68 457
jpayne@68 458 int a=(int)(len*(identity*POINTS_MATCH+(1-identity)*POINTS_SUB));
jpayne@68 459 int b=(int)(len*(identity*POINTS_MATCH+(1-identity)*POINTS_INS));
jpayne@68 460 int c=(int)(len*(1*POINTS_MATCH+((1/(Tools.max(identity, 0.000001f)))-1)*POINTS_DEL));
jpayne@68 461 return Tools.min(a, b, c);
jpayne@68 462 }
jpayne@68 463
jpayne@68 464 private static int calcDelScore(int len){
jpayne@68 465 if(len<=0){return 0;}
jpayne@68 466 int score=POINTS_DEL*len;
jpayne@68 467 return score;
jpayne@68 468 }
jpayne@68 469 //
jpayne@68 470 // public static int calcInsScore(int len){
jpayne@68 471 // if(len<=0){return 0;}
jpayne@68 472 // int score=POINTS_INS;
jpayne@68 473 //
jpayne@68 474 // if(len>1){
jpayne@68 475 // score+=(len-1)*POINTS_INS2;
jpayne@68 476 // }
jpayne@68 477 // return score;
jpayne@68 478 // }
jpayne@68 479 //
jpayne@68 480 // private static int calcInsScoreOffset(int len){
jpayne@68 481 // if(len<=0){return 0;}
jpayne@68 482 // int score=POINTS_INS;
jpayne@68 483 //
jpayne@68 484 // if(len>1){
jpayne@68 485 // score+=(len-1)*POINTS_INS2;
jpayne@68 486 // }
jpayne@68 487 // return score;
jpayne@68 488 // }
jpayne@68 489
jpayne@68 490 @Override
jpayne@68 491 public int rows(){return rows;}
jpayne@68 492 @Override
jpayne@68 493 public int columns(){return columns;}
jpayne@68 494
jpayne@68 495
jpayne@68 496 private int maxRows;
jpayne@68 497 private int maxColumns;
jpayne@68 498
jpayne@68 499 private int[][] packed;
jpayne@68 500
jpayne@68 501 public static final int MAX_SCORE=Integer.MAX_VALUE-2000;
jpayne@68 502 public static final int MIN_SCORE=0-MAX_SCORE; //Keeps it 1 point above "BAD".
jpayne@68 503
jpayne@68 504 //For some reason changing MODE_DEL from 1 to 0 breaks everything
jpayne@68 505 private static final byte MODE_DEL=1;
jpayne@68 506 private static final byte MODE_INS=2;
jpayne@68 507 private static final byte MODE_SUB=3;
jpayne@68 508 private static final byte MODE_MATCH=4;
jpayne@68 509 private static final byte MODE_N=5;
jpayne@68 510
jpayne@68 511 public static final int POINTS_NOREF=-20;
jpayne@68 512 public static final int POINTS_MATCH=100;
jpayne@68 513 public static final int POINTS_SUB=-50;
jpayne@68 514 public static final int POINTS_INS=-121;
jpayne@68 515 public static final int POINTS_DEL=-111;
jpayne@68 516
jpayne@68 517 // public static final int POINTS_NOREF=-150000;
jpayne@68 518 // public static final int POINTS_MATCH=100;
jpayne@68 519 // public static final int POINTS_SUB=-100;
jpayne@68 520 // public static final int POINTS_INS=-100;
jpayne@68 521 // public static final int POINTS_DEL=-100;
jpayne@68 522
jpayne@68 523 public static final int BAD=MIN_SCORE-1;
jpayne@68 524
jpayne@68 525 private int rows;
jpayne@68 526 private int columns;
jpayne@68 527
jpayne@68 528 // public long iterationsLimited=0;
jpayne@68 529 // public long iterationsUnlimited=0;
jpayne@68 530
jpayne@68 531 public boolean verbose=false;
jpayne@68 532 public boolean verbose2=false;
jpayne@68 533
jpayne@68 534 }