6 #define USE_PENALTY_EX 1
10 static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 )
13 int *intptr = amino_dis[(int)s1[0][i1]];
16 *match++ = intptr[(int)*seq2++];
18 static void match_calc_mtx( int mtx[0x80][0x80], float *match, char **s1, char **s2, int i1, int lgth2 )
21 int *intptr = mtx[(int)s1[0][i1]];
24 *match++ = intptr[(int)*seq2++];
27 static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 )
31 for( j=0; j<lgth2; j++ )
32 match[j] = amino_dis[(*s1)[i1]][(*s2)[j]];
36 static float Atracking( float *lasthorizontalw, float *lastverticalw,
37 char **seq1, char **seq2,
38 char **mseq1, char **mseq2,
41 int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, limk;
43 lgth1 = strlen( seq1[0] );
44 lgth2 = strlen( seq2[0] );
48 for( i=0; i<lgth1; i++ )
50 fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
54 for( i=0; i<lgth1+1; i++ )
58 for( j=0; j<lgth2+1; j++ )
60 ijp[0][j] = -( j + 1 );
64 mseq1[0] += lgth1+lgth2;
66 mseq2[0] += lgth1+lgth2;
68 iin = lgth1; jin = lgth2;
69 limk = lgth1+lgth2 + 1;
70 for( k=0; k<limk; k++ )
72 if( ijp[iin][jin] < 0 )
74 ifi = iin-1; jfi = jin+ijp[iin][jin];
76 else if( ijp[iin][jin] > 0 )
78 ifi = iin-ijp[iin][jin]; jfi = jin-1;
82 ifi = iin-1; jfi = jin-1;
87 *--mseq1[0] = seq1[0][ifi+l];
95 *--mseq2[0] = seq2[0][jfi+l];
98 if( iin <= 0 || jin <= 0 ) break;
99 *--mseq1[0] = seq1[0][ifi];
100 *--mseq2[0] = seq2[0][jfi];
102 iin = ifi; jin = jfi;
108 float G__align11( char **seq1, char **seq2, int alloclen )
109 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
113 int lasti; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
116 float wm; /* int ?????? */
118 float *currentw, *previousw;
119 float fpenalty = (float)penalty;
121 float fpenalty_ex = (float)penalty_ex;
126 float *mjpt, *prept, *curpt;
132 static float *w1, *w2;
134 static float *initverticalw; /* kufuu sureba iranai */
135 static float *lastverticalw; /* kufuu sureba iranai */
139 static int **intwork;
140 static float **floatwork;
141 static int orlgth1 = 0, orlgth2 = 0;
147 mseq1 = AllocateCharMtx( njob, 0 );
148 mseq2 = AllocateCharMtx( njob, 0 );
152 lgth1 = strlen( seq1[0] );
153 lgth2 = strlen( seq2[0] );
157 if( lgth1 <= 0 || lgth2 <= 0 )
159 fprintf( stderr, "WARNING (g11): lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
162 if( lgth1 > orlgth1 || lgth2 > orlgth2 )
166 if( orlgth1 > 0 && orlgth2 > 0 )
170 FreeFloatVec( match );
171 FreeFloatVec( initverticalw );
172 FreeFloatVec( lastverticalw );
181 FreeFloatMtx( floatwork );
182 FreeIntMtx( intwork );
185 ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
186 ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
189 fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
192 w1 = AllocateFloatVec( ll2+2 );
193 w2 = AllocateFloatVec( ll2+2 );
194 match = AllocateFloatVec( ll2+2 );
196 initverticalw = AllocateFloatVec( ll1+2 );
197 lastverticalw = AllocateFloatVec( ll1+2 );
199 m = AllocateFloatVec( ll2+2 );
200 mp = AllocateIntVec( ll2+2 );
202 mseq = AllocateCharMtx( njob, ll1+ll2 );
205 floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 );
206 intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 );
209 fprintf( stderr, "succeeded\n" );
221 if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
225 if( commonAlloc1 && commonAlloc2 )
227 FreeIntMtx( commonIP );
230 ll1 = MAX( orlgth1, commonAlloc1 );
231 ll2 = MAX( orlgth2, commonAlloc2 );
234 fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
237 commonIP = AllocateIntMtx( ll1+10, ll2+10 );
240 fprintf( stderr, "succeeded\n\n" );
250 for( i=0; i<lgth1; i++ )
251 fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
258 match_calc( initverticalw, seq2, seq1, 0, lgth1 );
261 match_calc( currentw, seq1, seq2, 0, lgth2 );
265 for( i=1; i<lgth1+1; i++ )
267 initverticalw[i] += fpenalty;
269 for( j=1; j<lgth2+1; j++ )
271 currentw[j] += fpenalty;
275 for( j=1; j<lgth2+1; ++j )
277 m[j] = currentw[j-1]; mp[j] = 0;
281 lastverticalw[0] = 0.0; // lgth2==0 no toki error
283 lastverticalw[0] = currentw[lgth2-1]; // lgth2==0 no toki error
285 if( outgap ) lasti = lgth1+1; else lasti = lgth1;
288 fprintf( stderr, "currentw = \n" );
289 for( i=0; i<lgth1+1; i++ )
291 fprintf( stderr, "%5.2f ", currentw[i] );
293 fprintf( stderr, "\n" );
294 fprintf( stderr, "initverticalw = \n" );
295 for( i=0; i<lgth2+1; i++ )
297 fprintf( stderr, "%5.2f ", initverticalw[i] );
299 fprintf( stderr, "\n" );
302 for( i=1; i<lasti; i++ )
305 previousw = currentw;
308 previousw[0] = initverticalw[i-1];
310 match_calc( currentw, seq1, seq2, i, lgth2 );
312 fprintf( stderr, "\n" );
313 fprintf( stderr, "i=%d\n", i );
314 fprintf( stderr, "currentw = \n" );
315 for( j=0; j<lgth2; j++ )
317 fprintf( stderr, "%5.2f ", currentw[j] );
319 fprintf( stderr, "\n" );
322 fprintf( stderr, "\n" );
323 fprintf( stderr, "i=%d\n", i );
324 fprintf( stderr, "currentw = \n" );
325 for( j=0; j<lgth2; j++ )
327 fprintf( stderr, "%5.2f ", currentw[j] );
329 fprintf( stderr, "\n" );
331 currentw[0] = initverticalw[i];
333 mi = previousw[0]; mpi = 0;
338 curpt = currentw + 1;
340 for( j=1; j<lgth2+1; j++ )
346 fprintf( stderr, "%5.0f->", wm );
349 fprintf( stderr, "%5.0f?", g );
351 if( (g=mi+fpenalty) > wm )
354 *ijppt = -( j - mpi );
356 if( (g=*prept) >= mi )
366 fprintf( stderr, "%5.0f?", g );
368 if( (g=*mjpt + fpenalty) > wm )
371 *ijppt = +( i - *mpjpt );
373 if( (g=*prept) >= *mjpt )
383 fprintf( stderr, "%5.0f ", wm );
391 lastverticalw[i] = currentw[lgth2-1]; // lgth2==0 no toki error
394 Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, ijp );
396 resultlen = strlen( mseq1[0] );
397 if( alloclen < resultlen || resultlen > N )
399 fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
400 ErrorExit( "LENGTH OVER!\n" );
404 strcpy( seq1[0], mseq1[0] );
405 strcpy( seq2[0], mseq2[0] );
407 fprintf( stderr, "\n" );
408 fprintf( stderr, ">\n%s\n", mseq1[0] );
409 fprintf( stderr, ">\n%s\n", mseq2[0] );
410 fprintf( stderr, "wm = %f\n", wm );
416 float G__align11_noalign( int scoremtx[0x80][0x80], int penal, int penal_ex, char **seq1, char **seq2, int alloclen )
417 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
421 int lasti; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
424 float wm; /* int ?????? */
426 float *currentw, *previousw;
427 float fpenalty = (float)penal;
429 float fpenalty_ex = (float)penal_ex;
433 float *mjpt, *prept, *curpt;
437 static float *w1, *w2;
439 static float *initverticalw; /* kufuu sureba iranai */
440 static float *lastverticalw; /* kufuu sureba iranai */
441 static int **intwork;
442 static float **floatwork;
443 static int orlgth1 = 0, orlgth2 = 0;
449 lgth1 = strlen( seq1[0] );
450 lgth2 = strlen( seq2[0] );
454 if( lgth1 <= 0 || lgth2 <= 0 )
456 fprintf( stderr, "WARNING (g11): lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
459 if( lgth1 > orlgth1 || lgth2 > orlgth2 )
463 if( orlgth1 > 0 && orlgth2 > 0 )
467 FreeFloatVec( match );
468 FreeFloatVec( initverticalw );
469 FreeFloatVec( lastverticalw );
476 FreeFloatMtx( floatwork );
477 FreeIntMtx( intwork );
480 ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
481 ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
484 fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
487 w1 = AllocateFloatVec( ll2+2 );
488 w2 = AllocateFloatVec( ll2+2 );
489 match = AllocateFloatVec( ll2+2 );
491 initverticalw = AllocateFloatVec( ll1+2 );
492 lastverticalw = AllocateFloatVec( ll1+2 );
494 m = AllocateFloatVec( ll2+2 );
498 floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 );
499 intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 );
502 fprintf( stderr, "succeeded\n" );
515 for( i=0; i<lgth1; i++ )
516 fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
523 match_calc_mtx( scoremtx, initverticalw, seq2, seq1, 0, lgth1 );
526 match_calc_mtx( scoremtx, currentw, seq1, seq2, 0, lgth2 );
530 for( i=1; i<lgth1+1; i++ )
532 initverticalw[i] += fpenalty;
534 for( j=1; j<lgth2+1; j++ )
536 currentw[j] += fpenalty;
540 for( j=1; j<lgth2+1; ++j )
542 m[j] = currentw[j-1];
546 lastverticalw[0] = 0.0; // lgth2==0 no toki error
548 lastverticalw[0] = currentw[lgth2-1]; // lgth2==0 no toki error
550 if( outgap ) lasti = lgth1+1; else lasti = lgth1;
553 fprintf( stderr, "currentw = \n" );
554 for( i=0; i<lgth1+1; i++ )
556 fprintf( stderr, "%5.2f ", currentw[i] );
558 fprintf( stderr, "\n" );
559 fprintf( stderr, "initverticalw = \n" );
560 for( i=0; i<lgth2+1; i++ )
562 fprintf( stderr, "%5.2f ", initverticalw[i] );
564 fprintf( stderr, "\n" );
567 for( i=1; i<lasti; i++ )
570 previousw = currentw;
573 previousw[0] = initverticalw[i-1];
575 match_calc_mtx( scoremtx, currentw, seq1, seq2, i, lgth2 );
577 fprintf( stderr, "\n" );
578 fprintf( stderr, "i=%d\n", i );
579 fprintf( stderr, "currentw = \n" );
580 for( j=0; j<lgth2; j++ )
582 fprintf( stderr, "%5.2f ", currentw[j] );
584 fprintf( stderr, "\n" );
587 fprintf( stderr, "\n" );
588 fprintf( stderr, "i=%d\n", i );
589 fprintf( stderr, "currentw = \n" );
590 for( j=0; j<lgth2; j++ )
592 fprintf( stderr, "%5.2f ", currentw[j] );
594 fprintf( stderr, "\n" );
596 currentw[0] = initverticalw[i];
602 curpt = currentw + 1;
603 for( j=1; j<lgth2+1; j++ )
608 fprintf( stderr, "%5.0f->", wm );
611 fprintf( stderr, "%5.0f?", g );
613 if( (g=mi+fpenalty) > wm )
617 if( (g=*prept) >= mi )
626 fprintf( stderr, "%5.0f?", g );
628 if( (g=*mjpt + fpenalty) > wm )
632 if( (g=*prept) >= *mjpt )
641 fprintf( stderr, "%5.0f ", wm );
647 lastverticalw[i] = currentw[lgth2-1]; // lgth2==0 no toki error
651 fprintf( stderr, "\n" );
652 fprintf( stderr, ">\n%s\n", mseq1[0] );
653 fprintf( stderr, ">\n%s\n", mseq2[0] );
654 fprintf( stderr, "wm = %f\n", wm );