7 #define USE_PENALTY_EX 1
9 static int localstop; // 060910
12 static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 )
17 intptr = amino_dis[(int)s1[0][i1]];
19 *match++ = intptr[(int)*seq2++];
22 static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 )
26 for( j=0; j<lgth2; j++ )
27 match[j] = amino_dis[(*s1)[i1]][(*s2)[j]];
32 static void match_calc_bk( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
36 float **cpmxpd = floatwork;
37 int **cpmxpdn = intwork;
42 for( j=0; j<lgth2; j++ )
49 cpmxpd[count][j] = cpmx2[l][j];
50 cpmxpdn[count][j] = l;
54 cpmxpdn[count][j] = -1;
62 scarr[l] += n_dis[k][l] * cpmx1[k][i1];
64 #if 0 /* ¤³¤ì¤ò»È¤¦¤È¤
\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
66 float *fpt, **fptpt, *fpt2;
74 ipt=*iptpt,fpt=*fptpt;
76 *fpt2 += scarr[*ipt++] * *fpt++;
77 fpt2++,iptpt++,fptpt++;
81 for( j=0; j<lgth2; j++ )
84 for( k=0; cpmxpdn[k][j]>-1; k++ )
85 match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j];
91 static float Ltracking( float *lasthorizontalw, float *lastverticalw,
92 char **seq1, char **seq2,
93 char **mseq1, char **mseq2,
94 int **ijp, int *off1pt, int *off2pt, int endi, int endj )
96 int i, j, l, iin, jin, lgth1, lgth2, k, limk;
97 int ifi=0, jfi=0; // by D.Mathog, a guess
99 lgth1 = strlen( seq1[0] );
100 lgth2 = strlen( seq2[0] );
103 for( i=0; i<lgth1; i++ )
105 fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
109 for( i=0; i<lgth1+1; i++ )
111 ijp[i][0] = localstop;
113 for( j=0; j<lgth2+1; j++ )
115 ijp[0][j] = localstop;
118 mseq1[0] += lgth1+lgth2;
120 mseq2[0] += lgth1+lgth2;
122 iin = endi; jin = endj;
124 for( k=0; k<=limk; k++ )
126 if( ijp[iin][jin] < 0 )
128 ifi = iin-1; jfi = jin+ijp[iin][jin];
130 else if( ijp[iin][jin] > 0 )
132 ifi = iin-ijp[iin][jin]; jfi = jin-1;
136 ifi = iin-1; jfi = jin-1;
141 *--mseq1[0] = seq1[0][ifi+l];
149 *--mseq2[0] = seq2[0][jfi+l];
153 if( iin <= 0 || jin <= 0 ) break;
154 *--mseq1[0] = seq1[0][ifi];
155 *--mseq2[0] = seq2[0][jfi];
156 if( ijp[ifi][jfi] == localstop ) break;
158 iin = ifi; jin = jfi;
160 if( ifi == -1 ) *off1pt = 0; else *off1pt = ifi;
161 if( jfi == -1 ) *off2pt = 0; else *off2pt = jfi;
163 // fprintf( stderr, "ifn = %d, jfn = %d\n", ifi, jfi );
170 float L__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt )
171 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
175 int lasti, lastj; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
178 float wm = 0.0; /* int ?????? */
180 float *currentw, *previousw;
184 float *mjpt, *prept, *curpt;
190 static float *w1, *w2;
192 static float *initverticalw; /* kufuu sureba iranai */
193 static float *lastverticalw; /* kufuu sureba iranai */
197 // static int **intwork;
198 // static float **floatwork;
199 static int orlgth1 = 0, orlgth2 = 0;
201 int endali = 0, endalj = 0; // by D.Mathog, a guess
202 // int endali, endalj;
203 float localthr = -offset;
204 float localthr2 = -offset;
205 // float localthr = 100;
206 // float localthr2 = 100;
207 float fpenalty = (float)penalty;
208 float fpenalty_ex = (float)penalty_ex;
213 mseq1 = AllocateCharMtx( njob, 0 );
214 mseq2 = AllocateCharMtx( njob, 0 );
218 lgth1 = strlen( seq1[0] );
219 lgth2 = strlen( seq2[0] );
221 if( lgth1 > orlgth1 || lgth2 > orlgth2 )
225 if( orlgth1 > 0 && orlgth2 > 0 )
229 FreeFloatVec( match );
230 FreeFloatVec( initverticalw );
231 FreeFloatVec( lastverticalw );
240 // FreeFloatMtx( floatwork );
241 // FreeIntMtx( intwork );
244 ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
245 ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
248 fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
251 w1 = AllocateFloatVec( ll2+2 );
252 w2 = AllocateFloatVec( ll2+2 );
253 match = AllocateFloatVec( ll2+2 );
255 initverticalw = AllocateFloatVec( ll1+2 );
256 lastverticalw = AllocateFloatVec( ll1+2 );
258 m = AllocateFloatVec( ll2+2 );
259 mp = AllocateIntVec( ll2+2 );
261 mseq = AllocateCharMtx( njob, ll1+ll2 );
264 // floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 );
265 // intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 );
268 fprintf( stderr, "succeeded\n" );
280 if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
284 if( commonAlloc1 && commonAlloc2 )
286 FreeIntMtx( commonIP );
289 ll1 = MAX( orlgth1, commonAlloc1 );
290 ll2 = MAX( orlgth2, commonAlloc2 );
293 fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
296 commonIP = AllocateIntMtx( ll1+10, ll2+10 );
299 fprintf( stderr, "succeeded\n\n" );
309 for( i=0; i<lgth1; i++ )
310 fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
316 match_calc( initverticalw, seq2, seq1, 0, lgth1 );
318 match_calc( currentw, seq1, seq2, 0, lgth2 );
322 for( j=1; j<lasti; ++j )
324 m[j] = currentw[j-1]; mp[j] = 0;
326 if( m[j] < localthr ) m[j] = localthr2;
330 lastverticalw[0] = currentw[lgth2-1];
335 fprintf( stderr, "currentw = \n" );
336 for( i=0; i<lgth1+1; i++ )
338 fprintf( stderr, "%5.2f ", currentw[i] );
340 fprintf( stderr, "\n" );
341 fprintf( stderr, "initverticalw = \n" );
342 for( i=0; i<lgth2+1; i++ )
344 fprintf( stderr, "%5.2f ", initverticalw[i] );
346 fprintf( stderr, "\n" );
349 fprintf( stderr, "\n" );
350 fprintf( stderr, " " );
351 for( j=0; j<lgth2; j++ )
352 fprintf( stderr, "%c ", seq2[0][j] );
353 fprintf( stderr, "\n" );
356 localstop = lgth1+lgth2+1;
357 maxwm = -999999999.9;
359 fprintf( stderr, "\n" );
360 fprintf( stderr, "%c ", seq1[0][0] );
362 for( j=0; j<lgth2+1; j++ )
363 fprintf( stderr, "%5.0f ", currentw[j] );
364 fprintf( stderr, "\n" );
367 for( i=1; i<lasti; i++ )
370 previousw = currentw;
373 previousw[0] = initverticalw[i-1];
375 match_calc( currentw, seq1, seq2, i, lgth2 );
377 fprintf( stderr, "%c ", seq1[0][i] );
378 fprintf( stderr, "%5.0f ", currentw[0] );
382 fprintf( stderr, "\n" );
383 fprintf( stderr, "i=%d\n", i );
384 fprintf( stderr, "currentw = \n" );
385 for( j=0; j<lgth2; j++ )
387 fprintf( stderr, "%5.2f ", currentw[j] );
389 fprintf( stderr, "\n" );
392 fprintf( stderr, "\n" );
393 fprintf( stderr, "i=%d\n", i );
394 fprintf( stderr, "currentw = \n" );
395 for( j=0; j<lgth2; j++ )
397 fprintf( stderr, "%5.2f ", currentw[j] );
399 fprintf( stderr, "\n" );
401 currentw[0] = initverticalw[i];
403 mi = previousw[0]; mpi = 0;
406 if( mi < localthr ) mi = localthr2;
412 curpt = currentw + 1;
415 for( j=1; j<lastj; j++ )
421 fprintf( stderr, "%5.0f->", wm );
424 fprintf( stderr, "%5.0f?", g );
426 if( (g=mi+fpenalty) > wm )
429 *ijppt = -( j - mpi );
442 fprintf( stderr, "%5.0f?", g );
444 if( (g=*mjpt+fpenalty) > wm )
447 *ijppt = +( i - *mpjpt );
455 *mjpt += fpenalty_ex;
467 // fprintf( stderr, "stop i=%d, j=%d, curpt=%f\n", i, j, *curpt );
473 fprintf( stderr, "%5.0f ", *curpt );
476 fprintf( stderr, "%5.0f ", wm );
477 // fprintf( stderr, "%c-%c *ijppt = %d, localstop = %d\n", seq1[0][i], seq2[0][j], *ijppt, localstop );
487 fprintf( stderr, "\n" );
490 lastverticalw[i] = currentw[lgth2-1];
495 fprintf( stderr, "maxwm = %f\n", maxwm );
496 fprintf( stderr, "endali = %d\n", endali );
497 fprintf( stderr, "endalj = %d\n", endalj );
500 if( ijp[endali][endalj] == localstop )
502 strcpy( seq1[0], "" );
503 strcpy( seq2[0], "" );
504 *off1pt = *off2pt = 0;
508 Ltracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, ijp, off1pt, off2pt, endali, endalj );
511 resultlen = strlen( mseq1[0] );
512 if( alloclen < resultlen || resultlen > N )
514 fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
515 ErrorExit( "LENGTH OVER!\n" );
519 strcpy( seq1[0], mseq1[0] );
520 strcpy( seq2[0], mseq2[0] );
523 fprintf( stderr, "wm=%f\n", wm );
524 fprintf( stderr, ">\n%s\n", mseq1[0] );
525 fprintf( stderr, ">\n%s\n", mseq2[0] );
527 fprintf( stderr, "maxwm = %f\n", maxwm );
528 fprintf( stderr, " wm = %f\n", wm );