jpayne@68
|
1 package aligner;
|
jpayne@68
|
2
|
jpayne@68
|
3 import java.util.Arrays;
|
jpayne@68
|
4
|
jpayne@68
|
5 import shared.KillSwitch;
|
jpayne@68
|
6 import shared.Tools;
|
jpayne@68
|
7
|
jpayne@68
|
8 /**
|
jpayne@68
|
9 * Based on MSA9PBA, but reduced to a single matrix. */
|
jpayne@68
|
10 public final class SingleStateAlignerPacBioAdapter {
|
jpayne@68
|
11
|
jpayne@68
|
12
|
jpayne@68
|
13 public SingleStateAlignerPacBioAdapter(int maxRows_, int maxColumns_, int qlen){
|
jpayne@68
|
14 // assert(maxColumns_>=200);
|
jpayne@68
|
15 // assert(maxRows_>=200);
|
jpayne@68
|
16 maxRows=maxRows_;
|
jpayne@68
|
17 maxColumns=maxColumns_;
|
jpayne@68
|
18 packed=new int[maxRows+1][maxColumns+1];
|
jpayne@68
|
19
|
jpayne@68
|
20 insScoreArray=KillSwitch.allocInt1D(5);
|
jpayne@68
|
21 delScoreArray=KillSwitch.allocInt1D(5);
|
jpayne@68
|
22 matchScoreArray=KillSwitch.allocInt1D(5);
|
jpayne@68
|
23 subScoreArray=KillSwitch.allocInt1D(5);
|
jpayne@68
|
24
|
jpayne@68
|
25 Arrays.fill(insScoreArray, POINTSoff_INS|MODE_INS);
|
jpayne@68
|
26 Arrays.fill(delScoreArray, POINTSoff_DEL|MODE_DEL);
|
jpayne@68
|
27 Arrays.fill(matchScoreArray, POINTSoff_MATCH|MODE_MATCH);
|
jpayne@68
|
28 Arrays.fill(subScoreArray, POINTSoff_SUB|MODE_SUB);
|
jpayne@68
|
29
|
jpayne@68
|
30 insScoreArray[MODE_INS]=POINTSoff_INS2|MODE_INS;
|
jpayne@68
|
31 delScoreArray[MODE_DEL]=POINTSoff_DEL2|MODE_DEL;
|
jpayne@68
|
32 matchScoreArray[MODE_MATCH]=POINTSoff_MATCH2|MODE_MATCH;
|
jpayne@68
|
33 subScoreArray[MODE_SUB]=POINTSoff_SUB2|MODE_SUB;
|
jpayne@68
|
34
|
jpayne@68
|
35 vertLimit=new int[maxRows+1];
|
jpayne@68
|
36 horizLimit=new int[maxColumns+1];
|
jpayne@68
|
37 Arrays.fill(vertLimit, BADoff);
|
jpayne@68
|
38 Arrays.fill(horizLimit, BADoff);
|
jpayne@68
|
39
|
jpayne@68
|
40 // for(int i=0; i<maxColumns+1; i++){
|
jpayne@68
|
41 // scores[0][i]=0-i;
|
jpayne@68
|
42 // }
|
jpayne@68
|
43
|
jpayne@68
|
44 for(int i=1; i<=maxRows; i++){
|
jpayne@68
|
45 for(int j=1; j<packed[i].length; j++){
|
jpayne@68
|
46 packed[i][j]|=BADoff;
|
jpayne@68
|
47 }
|
jpayne@68
|
48 }
|
jpayne@68
|
49 for(int i=0; i<=maxRows; i++){
|
jpayne@68
|
50
|
jpayne@68
|
51 int prevScore=(i<2 ? 0 : packed[i-1][0]);
|
jpayne@68
|
52 int score=(i<2 ? (i*POINTSoff_INS) : prevScore+POINTSoff_INS2);
|
jpayne@68
|
53
|
jpayne@68
|
54 packed[i][0]=score;
|
jpayne@68
|
55 }
|
jpayne@68
|
56 for(int i=0; i<packed[0].length; i++){
|
jpayne@68
|
57 packed[0][i]=packed[0][i]|(i<<STARTOFFSET);
|
jpayne@68
|
58 int x=packed[0].length-i;
|
jpayne@68
|
59 int qbases=qlen-x;
|
jpayne@68
|
60 if(qbases>0){
|
jpayne@68
|
61 packed[0][i]|=calcDelScoreOffset(qbases); //Forces consumption of query
|
jpayne@68
|
62 }
|
jpayne@68
|
63 }
|
jpayne@68
|
64 }
|
jpayne@68
|
65
|
jpayne@68
|
66
|
jpayne@68
|
67 /** return new int[] {rows, maxCol, maxState, maxScore, maxStart};
|
jpayne@68
|
68 * Will not fill areas that cannot match minScore */
|
jpayne@68
|
69 public final int[] fillLimited(byte[] read, byte[] ref, int refStartLoc, int refEndLoc, int minScore){
|
jpayne@68
|
70 return fillLimitedX(read, ref, refStartLoc, refEndLoc, minScore);
|
jpayne@68
|
71 }
|
jpayne@68
|
72
|
jpayne@68
|
73
|
jpayne@68
|
74 /** return new int[] {rows, maxCol, maxState, maxScore, maxStart};
|
jpayne@68
|
75 * Will not fill areas that cannot match minScore */
|
jpayne@68
|
76 private final int[] fillLimitedX(byte[] read, byte[] ref, int refStartLoc, int refEndLoc, int minScore){
|
jpayne@68
|
77 return fillUnlimited(read, ref, refStartLoc, refEndLoc, minScore);
|
jpayne@68
|
78 }
|
jpayne@68
|
79
|
jpayne@68
|
80
|
jpayne@68
|
81 /** return new int[] {rows, maxCol, maxState, maxScore, maxStart};
|
jpayne@68
|
82 * Does not require a min score (ie, same as old method) */
|
jpayne@68
|
83 private final int[] fillUnlimited(byte[] read, byte[] ref, int refStartLoc, int refEndLoc, final int minScore){
|
jpayne@68
|
84 rows=read.length;
|
jpayne@68
|
85 columns=refEndLoc-refStartLoc+1;
|
jpayne@68
|
86
|
jpayne@68
|
87 //temporary, for finding a bug
|
jpayne@68
|
88 if(rows>maxRows || columns>maxColumns){
|
jpayne@68
|
89 throw new RuntimeException("rows="+rows+", maxRows="+maxRows+", cols="+columns+", maxCols="+maxColumns+"\n"+new String(read)+"\n");
|
jpayne@68
|
90 }
|
jpayne@68
|
91
|
jpayne@68
|
92 assert(rows<=maxRows) : "Check that values are in-bounds before calling this function: "+rows+", "+maxRows;
|
jpayne@68
|
93 assert(columns<=maxColumns) : "Check that values are in-bounds before calling this function: "+columns+", "+maxColumns;
|
jpayne@68
|
94
|
jpayne@68
|
95 assert(refStartLoc>=0) : "Check that values are in-bounds before calling this function: "+refStartLoc;
|
jpayne@68
|
96 assert(refEndLoc<ref.length) : "Check that values are in-bounds before calling this function: "+refEndLoc+", "+ref.length;
|
jpayne@68
|
97
|
jpayne@68
|
98 final int refOffset=refStartLoc-1;
|
jpayne@68
|
99 for(int row=1; row<=rows; row++){
|
jpayne@68
|
100
|
jpayne@68
|
101 final byte qBase=read[row-1];
|
jpayne@68
|
102 for(int col=1; col<=columns; col++){
|
jpayne@68
|
103 iterationsUnlimited++;
|
jpayne@68
|
104
|
jpayne@68
|
105 final byte rBase=ref[refOffset+col];
|
jpayne@68
|
106
|
jpayne@68
|
107 final boolean match=(qBase==rBase);//Note that qBase will never be 'N'
|
jpayne@68
|
108
|
jpayne@68
|
109 final int valueFromDiag=packed[row-1][col-1];
|
jpayne@68
|
110 final int valueFromDel=packed[row][col-1];
|
jpayne@68
|
111 final int valueFromIns=packed[row-1][col];
|
jpayne@68
|
112 final int stateFromDiag=valueFromDiag&MODEMASK;
|
jpayne@68
|
113 final int scoreFromDiag=valueFromDiag&HIGHMASK;
|
jpayne@68
|
114 final int stateFromDel=valueFromDel&MODEMASK;
|
jpayne@68
|
115 final int scoreFromDel=valueFromDel&HIGHMASK;
|
jpayne@68
|
116 final int stateFromIns=valueFromIns&MODEMASK;
|
jpayne@68
|
117 final int scoreFromIns=valueFromIns&HIGHMASK;
|
jpayne@68
|
118
|
jpayne@68
|
119 // final boolean prevMatch=stateFromDiag==MODE_MATCH;
|
jpayne@68
|
120 // final boolean prevSub=stateFromDiag==MODE_SUB;
|
jpayne@68
|
121 // final boolean prevDel=stateFromDel==MODE_DEL;
|
jpayne@68
|
122 // final boolean prevIns=stateFromIns==MODE_INS;
|
jpayne@68
|
123
|
jpayne@68
|
124 //Old conditional code, replaced by faster arrays
|
jpayne@68
|
125 // final int diagScoreM=MODE_MATCH|(prevMatch ? POINTSoff_MATCH2 : POINTSoff_MATCH);
|
jpayne@68
|
126 // final int diagScoreS=MODE_SUB|(prevSub ? POINTSoff_SUB2 : POINTSoff_SUB);
|
jpayne@68
|
127 // final int delScore=scoreFromDel+(prevDel ? POINTSoff_DEL2 : POINTSoff_DEL)|MODE_DEL;
|
jpayne@68
|
128 // final int insScore=scoreFromIns+(prevIns ? POINTSoff_INS2 : POINTSoff_INS)|MODE_INS;
|
jpayne@68
|
129
|
jpayne@68
|
130 final int diagScoreM=matchScoreArray[stateFromDiag];
|
jpayne@68
|
131 final int diagScoreS=subScoreArray[stateFromDiag];
|
jpayne@68
|
132 final int delScore=scoreFromDel+delScoreArray[stateFromDel];
|
jpayne@68
|
133 final int insScore=scoreFromIns+insScoreArray[stateFromIns];
|
jpayne@68
|
134
|
jpayne@68
|
135 int diagScore=(match ? diagScoreM : diagScoreS);
|
jpayne@68
|
136 diagScore=scoreFromDiag+(rBase!='N' ? diagScore : POINTSoff_NOREF_MODE_SUB);
|
jpayne@68
|
137
|
jpayne@68
|
138 int score=diagScore>=delScore ? diagScore : delScore;
|
jpayne@68
|
139 score=score>=insScore ? score : insScore;
|
jpayne@68
|
140
|
jpayne@68
|
141 packed[row][col]=score;
|
jpayne@68
|
142 }
|
jpayne@68
|
143 }
|
jpayne@68
|
144
|
jpayne@68
|
145
|
jpayne@68
|
146 int maxCol=-1;
|
jpayne@68
|
147 int maxState=-1;
|
jpayne@68
|
148 int maxStart=-1;
|
jpayne@68
|
149 int maxScore=Integer.MIN_VALUE;
|
jpayne@68
|
150
|
jpayne@68
|
151 for(int col=1; col<=columns; col++){
|
jpayne@68
|
152 int x=packed[rows][col];
|
jpayne@68
|
153 if((x&SCOREMASK)>maxScore){
|
jpayne@68
|
154 maxScore=x;
|
jpayne@68
|
155 maxCol=col;
|
jpayne@68
|
156 maxState=x&MODEMASK;
|
jpayne@68
|
157 maxStart=x&STARTMASK;
|
jpayne@68
|
158 }
|
jpayne@68
|
159 }
|
jpayne@68
|
160 maxScore>>=SCOREOFFSET;
|
jpayne@68
|
161
|
jpayne@68
|
162 // System.err.println("Returning "+rows+", "+maxCol+", "+maxState+", "+maxScore+"; minScore="+minScore);
|
jpayne@68
|
163 return maxScore<minScore ? null : new int[] {rows, maxCol, maxState, maxScore, maxStart};
|
jpayne@68
|
164 }
|
jpayne@68
|
165
|
jpayne@68
|
166
|
jpayne@68
|
167
|
jpayne@68
|
168 /** Generates the match string */
|
jpayne@68
|
169 public final byte[] traceback(int refStartLoc, int refEndLoc, int row, int col, int state){
|
jpayne@68
|
170 // assert(false);
|
jpayne@68
|
171 assert(refStartLoc<=refEndLoc) : refStartLoc+", "+refEndLoc;
|
jpayne@68
|
172 assert(row==rows);
|
jpayne@68
|
173
|
jpayne@68
|
174 byte[] out=new byte[row+col-1]; //TODO if an out of bound crash occurs, try removing the "-1".
|
jpayne@68
|
175 int outPos=0;
|
jpayne@68
|
176
|
jpayne@68
|
177 // assert(state==(packed[row][col]&MODEMASK));
|
jpayne@68
|
178
|
jpayne@68
|
179 while(row>0 && col>0){
|
jpayne@68
|
180 state=(packed[row][col]&MODEMASK);
|
jpayne@68
|
181 if(state==MODE_MATCH){
|
jpayne@68
|
182 col--;
|
jpayne@68
|
183 row--;
|
jpayne@68
|
184 out[outPos]='m';
|
jpayne@68
|
185 }else if(state==MODE_SUB){
|
jpayne@68
|
186 col--;
|
jpayne@68
|
187 row--;
|
jpayne@68
|
188 out[outPos]='S';
|
jpayne@68
|
189 }else if(state==MODE_DEL){
|
jpayne@68
|
190 col--;
|
jpayne@68
|
191 out[outPos]='D';
|
jpayne@68
|
192 }else if(state==MODE_INS){
|
jpayne@68
|
193 row--;
|
jpayne@68
|
194 out[outPos]='I';
|
jpayne@68
|
195 }else{
|
jpayne@68
|
196 assert(false) : state;
|
jpayne@68
|
197 }
|
jpayne@68
|
198 outPos++;
|
jpayne@68
|
199 }
|
jpayne@68
|
200
|
jpayne@68
|
201 assert(row==0 || col==0);
|
jpayne@68
|
202 if(col!=row){
|
jpayne@68
|
203 while(row>0){
|
jpayne@68
|
204 out[outPos]='X';
|
jpayne@68
|
205 outPos++;
|
jpayne@68
|
206 row--;
|
jpayne@68
|
207 col--;
|
jpayne@68
|
208 }
|
jpayne@68
|
209 if(col>0){
|
jpayne@68
|
210 //do nothing
|
jpayne@68
|
211 }
|
jpayne@68
|
212 }
|
jpayne@68
|
213
|
jpayne@68
|
214 //Shrink and reverse the string
|
jpayne@68
|
215 byte[] out2=new byte[outPos];
|
jpayne@68
|
216 for(int i=0; i<outPos; i++){
|
jpayne@68
|
217 out2[i]=out[outPos-i-1];
|
jpayne@68
|
218 }
|
jpayne@68
|
219 out=null;
|
jpayne@68
|
220
|
jpayne@68
|
221 return out2;
|
jpayne@68
|
222 }
|
jpayne@68
|
223
|
jpayne@68
|
224 /** @return {score, bestRefStart, bestRefStop} */
|
jpayne@68
|
225 public final int[] score(final byte[] read, final byte[] ref, final int refStartLoc, final int refEndLoc,
|
jpayne@68
|
226 final int maxRow, final int maxCol, final int maxState/*, final int maxScore, final int maxStart*/){
|
jpayne@68
|
227
|
jpayne@68
|
228 int row=maxRow;
|
jpayne@68
|
229 int col=maxCol;
|
jpayne@68
|
230 int state=maxState;
|
jpayne@68
|
231
|
jpayne@68
|
232 assert(maxState>=0 && maxState<packed.length) :
|
jpayne@68
|
233 maxState+", "+maxRow+", "+maxCol+"\n"+new String(read)+"\n"+toString(ref, refStartLoc, refEndLoc);
|
jpayne@68
|
234 assert(maxRow>=0 && maxRow<packed.length) :
|
jpayne@68
|
235 maxState+", "+maxRow+", "+maxCol+"\n"+new String(read)+"\n"+toString(ref, refStartLoc, refEndLoc);
|
jpayne@68
|
236 assert(maxCol>=0 && maxCol<packed[0].length) :
|
jpayne@68
|
237 maxState+", "+maxRow+", "+maxCol+"\n"+new String(read)+"\n"+toString(ref, refStartLoc, refEndLoc);
|
jpayne@68
|
238
|
jpayne@68
|
239 int score=packed[maxRow][maxCol]&SCOREMASK; //Or zero, if it is to be recalculated
|
jpayne@68
|
240
|
jpayne@68
|
241 if(row<rows){
|
jpayne@68
|
242 int difR=rows-row;
|
jpayne@68
|
243 int difC=columns-col;
|
jpayne@68
|
244
|
jpayne@68
|
245 while(difR>difC){
|
jpayne@68
|
246 score+=POINTSoff_NOREF;
|
jpayne@68
|
247 difR--;
|
jpayne@68
|
248 }
|
jpayne@68
|
249
|
jpayne@68
|
250 row+=difR;
|
jpayne@68
|
251 col+=difR;
|
jpayne@68
|
252
|
jpayne@68
|
253 }
|
jpayne@68
|
254
|
jpayne@68
|
255 assert(refStartLoc<=refEndLoc);
|
jpayne@68
|
256 assert(row==rows);
|
jpayne@68
|
257
|
jpayne@68
|
258
|
jpayne@68
|
259 final int bestRefStop=refStartLoc+col-1;
|
jpayne@68
|
260
|
jpayne@68
|
261 while(row>0 && col>0){
|
jpayne@68
|
262 state=(packed[row][col]&MODEMASK);
|
jpayne@68
|
263 if(state==MODE_MATCH){
|
jpayne@68
|
264 col--;
|
jpayne@68
|
265 row--;
|
jpayne@68
|
266 }else if(state==MODE_SUB){
|
jpayne@68
|
267 col--;
|
jpayne@68
|
268 row--;
|
jpayne@68
|
269 }else if(state==MODE_DEL){
|
jpayne@68
|
270 col--;
|
jpayne@68
|
271 }else if(state==MODE_INS){
|
jpayne@68
|
272 row--;
|
jpayne@68
|
273 }else{
|
jpayne@68
|
274 assert(false) : state;
|
jpayne@68
|
275 }
|
jpayne@68
|
276 }
|
jpayne@68
|
277 // assert(false) : row+", "+col;
|
jpayne@68
|
278 if(row>col){
|
jpayne@68
|
279 col-=row;
|
jpayne@68
|
280 }
|
jpayne@68
|
281
|
jpayne@68
|
282 final int bestRefStart=refStartLoc+col;
|
jpayne@68
|
283
|
jpayne@68
|
284 score>>=SCOREOFFSET;
|
jpayne@68
|
285 // System.err.println("t2\t"+score+", "+maxScore+", "+maxStart+", "+bestRefStart);
|
jpayne@68
|
286 int[] rvec;
|
jpayne@68
|
287 if(bestRefStart<refStartLoc || bestRefStop>refEndLoc){ //Suggest extra padding in cases of overflow
|
jpayne@68
|
288 int padLeft=Tools.max(0, refStartLoc-bestRefStart);
|
jpayne@68
|
289 int padRight=Tools.max(0, bestRefStop-refEndLoc);
|
jpayne@68
|
290 rvec=new int[] {score, bestRefStart, bestRefStop, padLeft, padRight};
|
jpayne@68
|
291 }else{
|
jpayne@68
|
292 rvec=new int[] {score, bestRefStart, bestRefStop};
|
jpayne@68
|
293 }
|
jpayne@68
|
294 return rvec;
|
jpayne@68
|
295 }
|
jpayne@68
|
296
|
jpayne@68
|
297
|
jpayne@68
|
298 /** Will not fill areas that cannot match minScore.
|
jpayne@68
|
299 * @return {score, bestRefStart, bestRefStop} */
|
jpayne@68
|
300 public final int[] fillAndScoreLimited(byte[] read, byte[] ref, int refStartLoc, int refEndLoc, int minScore){
|
jpayne@68
|
301 int a=Tools.max(0, refStartLoc);
|
jpayne@68
|
302 int b=Tools.min(ref.length-1, refEndLoc);
|
jpayne@68
|
303 assert(b>=a);
|
jpayne@68
|
304
|
jpayne@68
|
305 if(b-a>=maxColumns){
|
jpayne@68
|
306 System.err.println("Warning: Max alignment columns exceeded; restricting range. "+(b-a+1)+" > "+maxColumns);
|
jpayne@68
|
307 assert(false) : refStartLoc+", "+refEndLoc;
|
jpayne@68
|
308 b=Tools.min(ref.length-1, a+maxColumns-1);
|
jpayne@68
|
309 }
|
jpayne@68
|
310 int[] max=fillLimited(read, ref, a, b, minScore);
|
jpayne@68
|
311 // return max==null ? null : new int[] {max[3], 0, max[1]};
|
jpayne@68
|
312
|
jpayne@68
|
313 int[] score=(max==null ? null : score(read, ref, a, b, max[0], max[1], max[2]/*, max[3], max[4]*/));
|
jpayne@68
|
314
|
jpayne@68
|
315 return score;
|
jpayne@68
|
316 }
|
jpayne@68
|
317
|
jpayne@68
|
318 public static final String toString(byte[] ref, int startLoc, int stopLoc){
|
jpayne@68
|
319 StringBuilder sb=new StringBuilder(stopLoc-startLoc+1);
|
jpayne@68
|
320 for(int i=startLoc; i<=stopLoc; i++){sb.append((char)ref[i]);}
|
jpayne@68
|
321 return sb.toString();
|
jpayne@68
|
322 }
|
jpayne@68
|
323
|
jpayne@68
|
324 public static int calcDelScore(int len){
|
jpayne@68
|
325 if(len<=0){return 0;}
|
jpayne@68
|
326 int score=POINTS_DEL;
|
jpayne@68
|
327 if(len>1){
|
jpayne@68
|
328 score+=(len-1)*POINTS_DEL2;
|
jpayne@68
|
329 }
|
jpayne@68
|
330 return score;
|
jpayne@68
|
331 }
|
jpayne@68
|
332
|
jpayne@68
|
333 private static int calcDelScoreOffset(int len){
|
jpayne@68
|
334 if(len<=0){return 0;}
|
jpayne@68
|
335 int score=POINTSoff_DEL;
|
jpayne@68
|
336 if(len>1){
|
jpayne@68
|
337 score+=(len-1)*POINTSoff_DEL2;
|
jpayne@68
|
338 }
|
jpayne@68
|
339 return score;
|
jpayne@68
|
340 }
|
jpayne@68
|
341
|
jpayne@68
|
342 public static int calcInsScore(int len){
|
jpayne@68
|
343 if(len<=0){return 0;}
|
jpayne@68
|
344 int score=POINTS_INS;
|
jpayne@68
|
345
|
jpayne@68
|
346 if(len>1){
|
jpayne@68
|
347 score+=(len-1)*POINTS_INS2;
|
jpayne@68
|
348 }
|
jpayne@68
|
349 return score;
|
jpayne@68
|
350 }
|
jpayne@68
|
351
|
jpayne@68
|
352 private static int calcInsScoreOffset(int len){
|
jpayne@68
|
353 if(len<=0){return 0;}
|
jpayne@68
|
354 int score=POINTSoff_INS;
|
jpayne@68
|
355
|
jpayne@68
|
356 if(len>1){
|
jpayne@68
|
357 score+=(len-1)*POINTSoff_INS2;
|
jpayne@68
|
358 }
|
jpayne@68
|
359 return score;
|
jpayne@68
|
360 }
|
jpayne@68
|
361
|
jpayne@68
|
362
|
jpayne@68
|
363 private final int maxRows;
|
jpayne@68
|
364 public final int maxColumns;
|
jpayne@68
|
365
|
jpayne@68
|
366 private final int[][] packed;
|
jpayne@68
|
367
|
jpayne@68
|
368 private final int[] vertLimit;
|
jpayne@68
|
369 private final int[] horizLimit;
|
jpayne@68
|
370
|
jpayne@68
|
371 private final int[] insScoreArray;
|
jpayne@68
|
372 private final int[] delScoreArray;
|
jpayne@68
|
373 private final int[] matchScoreArray;
|
jpayne@68
|
374 private final int[] subScoreArray;
|
jpayne@68
|
375
|
jpayne@68
|
376 public static final int MODEBITS=3;
|
jpayne@68
|
377 public static final int STARTBITS=9;
|
jpayne@68
|
378 public static final int LOWBITS=MODEBITS+STARTBITS;
|
jpayne@68
|
379 public static final int SCOREBITS=32-STARTBITS;
|
jpayne@68
|
380 public static final int MAX_START=((1<<STARTBITS)-1);
|
jpayne@68
|
381 public static final int MAX_SCORE=((1<<(SCOREBITS-1))-1)-2000;
|
jpayne@68
|
382 public static final int MIN_SCORE=0-MAX_SCORE; //Keeps it 1 point above "BAD".
|
jpayne@68
|
383
|
jpayne@68
|
384 // public static final int MODEOFFSET=0; //Always zero.
|
jpayne@68
|
385 public static final int STARTOFFSET=MODEBITS;
|
jpayne@68
|
386 public static final int SCOREOFFSET=LOWBITS;
|
jpayne@68
|
387
|
jpayne@68
|
388 public static final int MODEMASK=~((-1)<<MODEBITS);
|
jpayne@68
|
389 public static final int STARTMASK=(~((-1)<<STARTBITS))<<STARTOFFSET;
|
jpayne@68
|
390 public static final int SCOREMASK=(~((-1)<<SCOREBITS))<<SCOREOFFSET;
|
jpayne@68
|
391 public static final int HIGHMASK=SCOREMASK|STARTMASK;
|
jpayne@68
|
392
|
jpayne@68
|
393 //For some reason changing MODE_DEL from 1 to 0 breaks everything
|
jpayne@68
|
394 private static final byte MODE_DEL=1;
|
jpayne@68
|
395 private static final byte MODE_INS=2;
|
jpayne@68
|
396 private static final byte MODE_SUB=3;
|
jpayne@68
|
397 private static final byte MODE_MATCH=4;
|
jpayne@68
|
398
|
jpayne@68
|
399 public static final int POINTS_NOREF=-10;
|
jpayne@68
|
400 public static final int POINTS_MATCH=90;
|
jpayne@68
|
401 public static final int POINTS_MATCH2=100; //Note: Changing to 90 substantially reduces false positives
|
jpayne@68
|
402 public static final int POINTS_SUB=-143;
|
jpayne@68
|
403 public static final int POINTS_SUB2=-54;
|
jpayne@68
|
404 public static final int POINTS_INS=-207;
|
jpayne@68
|
405 public static final int POINTS_INS2=-51;
|
jpayne@68
|
406 public static final int POINTS_INS3=-37;
|
jpayne@68
|
407 public static final int POINTS_DEL=-273;
|
jpayne@68
|
408 public static final int POINTS_DEL2=-38;
|
jpayne@68
|
409
|
jpayne@68
|
410
|
jpayne@68
|
411 // public static final int POINTS_NOREF=-10;
|
jpayne@68
|
412 // public static final int POINTS_NOCALL=-10;
|
jpayne@68
|
413 // public static final int POINTS_MATCH=90;
|
jpayne@68
|
414 // public static final int POINTS_MATCH2=100; //Note: Changing to 90 substantially reduces false positives
|
jpayne@68
|
415 // public static final int POINTS_SUB=-143;
|
jpayne@68
|
416 // public static final int POINTS_SUB2=-54;
|
jpayne@68
|
417 // public static final int POINTS_INS=-207;
|
jpayne@68
|
418 // public static final int POINTS_INS2=-51;
|
jpayne@68
|
419 // public static final int POINTS_INS3=-37;
|
jpayne@68
|
420 // public static final int POINTS_DEL=-273;
|
jpayne@68
|
421 // public static final int POINTS_DEL2=-38;
|
jpayne@68
|
422
|
jpayne@68
|
423 public static final int BAD=MIN_SCORE-1;
|
jpayne@68
|
424
|
jpayne@68
|
425
|
jpayne@68
|
426 public static final int POINTSoff_NOREF=(POINTS_NOREF<<SCOREOFFSET);
|
jpayne@68
|
427 public static final int POINTSoff_NOREF_MODE_SUB=POINTSoff_NOREF|MODE_SUB;
|
jpayne@68
|
428 public static final int POINTSoff_MATCH=(POINTS_MATCH<<SCOREOFFSET);
|
jpayne@68
|
429 public static final int POINTSoff_MATCH2=(POINTS_MATCH2<<SCOREOFFSET);
|
jpayne@68
|
430 public static final int POINTSoff_SUB=(POINTS_SUB<<SCOREOFFSET);
|
jpayne@68
|
431 public static final int POINTSoff_SUB2=(POINTS_SUB2<<SCOREOFFSET);
|
jpayne@68
|
432 public static final int POINTSoff_INS=(POINTS_INS<<SCOREOFFSET);
|
jpayne@68
|
433 public static final int POINTSoff_INS2=(POINTS_INS2<<SCOREOFFSET);
|
jpayne@68
|
434 public static final int POINTSoff_DEL=(POINTS_DEL<<SCOREOFFSET);
|
jpayne@68
|
435 public static final int POINTSoff_DEL2=(POINTS_DEL2<<SCOREOFFSET);
|
jpayne@68
|
436 public static final int BADoff=(BAD<<SCOREOFFSET);
|
jpayne@68
|
437 public static final int MAXoff_SCORE=MAX_SCORE<<SCOREOFFSET;
|
jpayne@68
|
438 public static final int MINoff_SCORE=MIN_SCORE<<SCOREOFFSET;
|
jpayne@68
|
439
|
jpayne@68
|
440 private int rows;
|
jpayne@68
|
441 private int columns;
|
jpayne@68
|
442
|
jpayne@68
|
443 public long iterationsLimited=0;
|
jpayne@68
|
444 public long iterationsUnlimited=0;
|
jpayne@68
|
445
|
jpayne@68
|
446 public boolean verbose=false;
|
jpayne@68
|
447 public boolean verbose2=false;
|
jpayne@68
|
448
|
jpayne@68
|
449 }
|