7 #define USE_PENALTY_EX 1
10 static TLS int localstop; // 060910
13 static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 )
18 intptr = amino_dis[(int)s1[0][i1]];
20 *match++ = intptr[(int)*seq2++];
23 static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 )
27 for( j=0; j<lgth2; j++ )
28 match[j] = amino_dis[(*s1)[i1]][(*s2)[j]];
33 static void match_calc_bk( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
37 float **cpmxpd = floatwork;
38 int **cpmxpdn = intwork;
43 for( j=0; j<lgth2; j++ )
50 cpmxpd[count][j] = cpmx2[l][j];
51 cpmxpdn[count][j] = l;
55 cpmxpdn[count][j] = -1;
63 scarr[l] += n_dis[k][l] * cpmx1[k][i1];
65 #if 0 /* ¤³¤ì¤ò»È¤¦¤È¤
\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
67 float *fpt, **fptpt, *fpt2;
75 ipt=*iptpt,fpt=*fptpt;
77 *fpt2 += scarr[*ipt++] * *fpt++;
78 fpt2++,iptpt++,fptpt++;
82 for( j=0; j<lgth2; j++ )
85 for( k=0; cpmxpdn[k][j]>-1; k++ )
86 match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j];
92 static float Ltracking( float *lasthorizontalw, float *lastverticalw,
93 char **seq1, char **seq2,
94 char **mseq1, char **mseq2,
95 int **ijp, int *off1pt, int *off2pt, int endi, int endj )
97 int i, j, l, iin, jin, lgth1, lgth2, k, limk;
98 int ifi=0, jfi=0; // by D.Mathog, a guess
102 lgth1 = strlen( seq1[0] );
103 lgth2 = strlen( seq2[0] );
106 for( i=0; i<lgth1; i++ )
108 fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
112 for( i=0; i<lgth1+1; i++ )
114 ijp[i][0] = localstop;
116 for( j=0; j<lgth2+1; j++ )
118 ijp[0][j] = localstop;
121 mseq1[0] += lgth1+lgth2;
123 mseq2[0] += lgth1+lgth2;
125 iin = endi; jin = endj;
127 for( k=0; k<=limk; k++ )
129 if( ijp[iin][jin] < 0 )
131 ifi = iin-1; jfi = jin+ijp[iin][jin];
133 else if( ijp[iin][jin] > 0 )
135 ifi = iin-ijp[iin][jin]; jfi = jin-1;
139 ifi = iin-1; jfi = jin-1;
144 *--mseq1[0] = seq1[0][ifi+l];
152 *--mseq2[0] = seq2[0][jfi+l];
156 if( iin <= 0 || jin <= 0 ) break;
157 *--mseq1[0] = seq1[0][ifi];
158 *--mseq2[0] = seq2[0][jfi];
159 if( ijp[ifi][jfi] == localstop ) break;
161 iin = ifi; jin = jfi;
163 if( ifi == -1 ) *off1pt = 0; else *off1pt = ifi;
164 if( jfi == -1 ) *off2pt = 0; else *off2pt = jfi;
166 // fprintf( stderr, "ifn = %d, jfn = %d\n", ifi, jfi );
173 float L__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt )
174 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
178 int lasti, lastj; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
181 float wm = 0.0; /* int ?????? */
183 float *currentw, *previousw;
187 float *mjpt, *prept, *curpt;
190 static TLS float mi, *m;
191 static TLS int **ijp;
192 static TLS int mpi, *mp;
193 static TLS float *w1, *w2;
194 static TLS float *match;
195 static TLS float *initverticalw; /* kufuu sureba iranai */
196 static TLS float *lastverticalw; /* kufuu sureba iranai */
197 static TLS char **mseq1;
198 static TLS char **mseq2;
199 static TLS char **mseq;
200 // static TLS int **intwork;
201 // static TLS float **floatwork;
202 static TLS int orlgth1 = 0, orlgth2 = 0;
204 int endali = 0, endalj = 0; // by D.Mathog, a guess
205 // int endali, endalj;
206 float localthr = -offset;
207 float localthr2 = -offset;
208 // float localthr = 100;
209 // float localthr2 = 100;
210 float fpenalty = (float)penalty;
211 float fpenalty_ex = (float)penalty_ex;
215 if( orlgth1 > 0 && orlgth2 > 0 )
223 FreeFloatVec( match );
224 FreeFloatVec( initverticalw );
225 FreeFloatVec( lastverticalw );
239 mseq1 = AllocateCharMtx( njob, 0 );
240 mseq2 = AllocateCharMtx( njob, 0 );
244 lgth1 = strlen( seq1[0] );
245 lgth2 = strlen( seq2[0] );
247 if( lgth1 > orlgth1 || lgth2 > orlgth2 )
251 if( orlgth1 > 0 && orlgth2 > 0 )
255 FreeFloatVec( match );
256 FreeFloatVec( initverticalw );
257 FreeFloatVec( lastverticalw );
266 // FreeFloatMtx( floatwork );
267 // FreeIntMtx( intwork );
270 ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
271 ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
274 fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
277 w1 = AllocateFloatVec( ll2+2 );
278 w2 = AllocateFloatVec( ll2+2 );
279 match = AllocateFloatVec( ll2+2 );
281 initverticalw = AllocateFloatVec( ll1+2 );
282 lastverticalw = AllocateFloatVec( ll1+2 );
284 m = AllocateFloatVec( ll2+2 );
285 mp = AllocateIntVec( ll2+2 );
287 mseq = AllocateCharMtx( njob, ll1+ll2 );
290 // floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 );
291 // intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 );
294 fprintf( stderr, "succeeded\n" );
306 if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
310 if( commonAlloc1 && commonAlloc2 )
312 FreeIntMtx( commonIP );
315 ll1 = MAX( orlgth1, commonAlloc1 );
316 ll2 = MAX( orlgth2, commonAlloc2 );
319 fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
322 commonIP = AllocateIntMtx( ll1+10, ll2+10 );
325 fprintf( stderr, "succeeded\n\n" );
335 for( i=0; i<lgth1; i++ )
336 fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
342 match_calc( initverticalw, seq2, seq1, 0, lgth1 );
344 match_calc( currentw, seq1, seq2, 0, lgth2 );
348 for( j=1; j<lasti; ++j )
350 m[j] = currentw[j-1]; mp[j] = 0;
352 if( m[j] < localthr ) m[j] = localthr2;
356 lastverticalw[0] = currentw[lgth2-1];
361 fprintf( stderr, "currentw = \n" );
362 for( i=0; i<lgth1+1; i++ )
364 fprintf( stderr, "%5.2f ", currentw[i] );
366 fprintf( stderr, "\n" );
367 fprintf( stderr, "initverticalw = \n" );
368 for( i=0; i<lgth2+1; i++ )
370 fprintf( stderr, "%5.2f ", initverticalw[i] );
372 fprintf( stderr, "\n" );
375 fprintf( stderr, "\n" );
376 fprintf( stderr, " " );
377 for( j=0; j<lgth2; j++ )
378 fprintf( stderr, "%c ", seq2[0][j] );
379 fprintf( stderr, "\n" );
382 localstop = lgth1+lgth2+1;
383 maxwm = -999999999.9;
385 fprintf( stderr, "\n" );
386 fprintf( stderr, "%c ", seq1[0][0] );
388 for( j=0; j<lgth2+1; j++ )
389 fprintf( stderr, "%5.0f ", currentw[j] );
390 fprintf( stderr, "\n" );
393 for( i=1; i<lasti; i++ )
396 previousw = currentw;
399 previousw[0] = initverticalw[i-1];
401 match_calc( currentw, seq1, seq2, i, lgth2 );
403 fprintf( stderr, "%c ", seq1[0][i] );
404 fprintf( stderr, "%5.0f ", currentw[0] );
408 fprintf( stderr, "\n" );
409 fprintf( stderr, "i=%d\n", i );
410 fprintf( stderr, "currentw = \n" );
411 for( j=0; j<lgth2; j++ )
413 fprintf( stderr, "%5.2f ", currentw[j] );
415 fprintf( stderr, "\n" );
418 fprintf( stderr, "\n" );
419 fprintf( stderr, "i=%d\n", i );
420 fprintf( stderr, "currentw = \n" );
421 for( j=0; j<lgth2; j++ )
423 fprintf( stderr, "%5.2f ", currentw[j] );
425 fprintf( stderr, "\n" );
427 currentw[0] = initverticalw[i];
429 mi = previousw[0]; mpi = 0;
432 if( mi < localthr ) mi = localthr2;
438 curpt = currentw + 1;
441 for( j=1; j<lastj; j++ )
447 fprintf( stderr, "%5.0f->", wm );
450 fprintf( stderr, "%5.0f?", g );
452 if( (g=mi+fpenalty) > wm )
455 *ijppt = -( j - mpi );
468 fprintf( stderr, "%5.0f?", g );
470 if( (g=*mjpt+fpenalty) > wm )
473 *ijppt = +( i - *mpjpt );
481 *mjpt += fpenalty_ex;
493 // fprintf( stderr, "stop i=%d, j=%d, curpt=%f\n", i, j, *curpt );
499 fprintf( stderr, "%5.0f ", *curpt );
502 fprintf( stderr, "%5.0f ", wm );
503 // fprintf( stderr, "%c-%c *ijppt = %d, localstop = %d\n", seq1[0][i], seq2[0][j], *ijppt, localstop );
513 fprintf( stderr, "\n" );
516 lastverticalw[i] = currentw[lgth2-1];
521 fprintf( stderr, "maxwm = %f\n", maxwm );
522 fprintf( stderr, "endali = %d\n", endali );
523 fprintf( stderr, "endalj = %d\n", endalj );
526 if( ijp[endali][endalj] == localstop )
528 strcpy( seq1[0], "" );
529 strcpy( seq2[0], "" );
530 *off1pt = *off2pt = 0;
534 Ltracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, ijp, off1pt, off2pt, endali, endalj );
537 resultlen = strlen( mseq1[0] );
538 if( alloclen < resultlen || resultlen > N )
540 fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
541 ErrorExit( "LENGTH OVER!\n" );
545 strcpy( seq1[0], mseq1[0] );
546 strcpy( seq2[0], mseq2[0] );
549 fprintf( stderr, "wm=%f\n", wm );
550 fprintf( stderr, ">\n%s\n", mseq1[0] );
551 fprintf( stderr, ">\n%s\n", mseq2[0] );
553 fprintf( stderr, "maxwm = %f\n", maxwm );
554 fprintf( stderr, " wm = %f\n", wm );