7 #define USE_PENALTY_EX 1
9 static short localstop;
12 static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 )
15 char tmpc = s1[0][i1];
19 *match++ = amino_dis[tmpc][*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]];
31 static void match_calc_bk( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
35 float **cpmxpd = floatwork;
36 int **cpmxpdn = intwork;
41 for( j=0; j<lgth2; j++ )
48 cpmxpd[count][j] = cpmx2[l][j];
49 cpmxpdn[count][j] = l;
53 cpmxpdn[count][j] = -1;
61 scarr[l] += n_dis[k][l] * cpmx1[k][i1];
63 #if 0 /* ¤³¤ì¤ò»È¤¦¤È¤
\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
65 float *fpt, **fptpt, *fpt2;
73 ipt=*iptpt,fpt=*fptpt;
75 *fpt2 += scarr[*ipt++] * *fpt++;
76 fpt2++,iptpt++,fptpt++;
80 for( j=0; j<lgth2; j++ )
83 for( k=0; cpmxpdn[k][j]>-1; k++ )
84 match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j];
89 static float gentracking( float *lasthorizontalw, float *lastverticalw,
90 char **seq1, char **seq2,
91 char **mseq1, char **mseq2,
92 float **cpmx1, float **cpmx2,
93 short **ijpi, short **ijpj, int *off1pt, int *off2pt, int endi, int endj )
95 int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, limk;
98 lgth1 = strlen( seq1[0] );
99 lgth2 = strlen( seq2[0] );
102 for( i=0; i<lgth1; i++ )
104 fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
108 for( i=0; i<lgth1+1; i++ )
110 ijpi[i][0] = localstop;
111 ijpj[i][0] = localstop;
113 for( j=0; j<lgth2+1; j++ )
115 ijpi[0][j] = localstop;
116 ijpj[0][j] = localstop;
119 mseq1[0] += lgth1+lgth2;
121 mseq2[0] += lgth1+lgth2;
123 iin = endi; jin = endj;
125 for( k=0; k<=limk; k++ )
128 ifi = ( ijpi[iin][jin] );
129 jfi = ( ijpj[iin][jin] );
131 // if( ijpi[iin][jin] < 0 || ijpj[iin][jin] < 0 )
133 // fprintf( stderr, "skip! %d-%d\n", ijpi[iin][jin], ijpj[iin][jin] );
134 // fprintf( stderr, "1: %c-%c\n", seq1[0][iin], seq1[0][ifi] );
135 // fprintf( stderr, "2: %c-%c\n", seq2[0][jin], seq2[0][jfi] );
139 *--mseq1[0] = seq1[0][ifi+l];
147 *--mseq2[0] = seq2[0][jfi+l];
151 if( iin <= 0 || jin <= 0 ) break;
152 *--mseq1[0] = seq1[0][ifi];
153 *--mseq2[0] = seq2[0][jfi];
154 if( ijpi[ifi][jfi] == localstop ) break;
155 if( ijpj[ifi][jfi] == localstop ) break; /*¤¤¤é¤Ê¤¤*/
157 iin = ifi; jin = jfi;
159 if( ifi == -1 ) *off1pt = 0; else *off1pt = ifi;
160 if( jfi == -1 ) *off2pt = 0; else *off2pt = jfi;
162 // fprintf( stderr, "ifn = %d, jfn = %d\n", ifi, jfi );
169 float genL__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt )
170 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
177 float wm; /* int ?????? */
179 float *currentw, *previousw;
184 float *mjpt, *Mjpt, *prept, *curpt;
188 static float Mi, *largeM;
193 static float *w1, *w2;
195 static float *initverticalw; /* kufuu sureba iranai */
196 static float *lastverticalw; /* kufuu sureba iranai */
200 static float **cpmx1;
201 static float **cpmx2;
202 static int **intwork;
203 static float **floatwork;
204 static int orlgth1 = 0, orlgth2 = 0;
209 // float localthr = 0.0;
210 // float localthr2 = 0.0;
211 float fpenalty = (float)penalty;
212 float fpenalty_OP = (float)penalty_OP;
213 float fpenalty_ex = (float)penalty_ex;
214 float fpenalty_EX = (float)penalty_EX;
215 float foffset = (float)offset;
216 float localthr = -foffset;
217 float localthr2 = -foffset;
220 // fprintf( stderr, "@@@@@@@@@@@@@ penalty_OP = %f, penalty_EX = %f, pelanty = %f\n", fpenalty_OP, fpenalty_EX, fpenalty );
224 mseq1 = AllocateCharMtx( njob, 0 );
225 mseq2 = AllocateCharMtx( njob, 0 );
229 lgth1 = strlen( seq1[0] );
230 lgth2 = strlen( seq2[0] );
232 if( lgth1 > orlgth1 || lgth2 > orlgth2 )
236 if( orlgth1 > 0 && orlgth2 > 0 )
240 FreeFloatVec( match );
241 FreeFloatVec( initverticalw );
242 FreeFloatVec( lastverticalw );
246 FreeFloatVec( largeM );
251 FreeFloatMtx( cpmx1 );
252 FreeFloatMtx( cpmx2 );
254 FreeFloatMtx( floatwork );
255 FreeIntMtx( intwork );
258 ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
259 ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
262 fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
265 w1 = AllocateFloatVec( ll2+2 );
266 w2 = AllocateFloatVec( ll2+2 );
267 match = AllocateFloatVec( ll2+2 );
269 initverticalw = AllocateFloatVec( ll1+2 );
270 lastverticalw = AllocateFloatVec( ll1+2 );
272 m = AllocateFloatVec( ll2+2 );
273 mp = AllocateIntVec( ll2+2 );
274 largeM = AllocateFloatVec( ll2+2 );
275 Mp = AllocateIntVec( ll2+2 );
277 mseq = AllocateCharMtx( njob, ll1+ll2 );
279 cpmx1 = AllocateFloatMtx( 26, ll1+2 );
280 cpmx2 = AllocateFloatMtx( 26, ll2+2 );
282 floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 );
283 intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 );
286 fprintf( stderr, "succeeded\n" );
298 if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
302 if( commonAlloc1 && commonAlloc2 )
304 FreeShortMtx( commonIP );
305 FreeShortMtx( commonJP );
308 ll1 = MAX( orlgth1, commonAlloc1 );
309 ll2 = MAX( orlgth2, commonAlloc2 );
312 fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
315 commonIP = AllocateShortMtx( ll1+10, ll2+10 );
316 commonJP = AllocateShortMtx( ll1+10, ll2+10 );
319 fprintf( stderr, "succeeded\n\n" );
330 for( i=0; i<lgth1; i++ )
331 fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
337 match_calc( initverticalw, seq2, seq1, 0, lgth1 );
339 match_calc( currentw, seq1, seq2, 0, lgth2 );
343 for( j=1; j<lasti; ++j )
345 m[j] = currentw[j-1]; mp[j] = 0;
346 largeM[j] = currentw[j-1]; Mp[j] = 0;
349 lastverticalw[0] = currentw[lgth2-1];
353 fprintf( stderr, "currentw = \n" );
354 for( i=0; i<lgth1+1; i++ )
356 fprintf( stderr, "%5.2f ", currentw[i] );
358 fprintf( stderr, "\n" );
359 fprintf( stderr, "initverticalw = \n" );
360 for( i=0; i<lgth2+1; i++ )
362 fprintf( stderr, "%5.2f ", initverticalw[i] );
364 fprintf( stderr, "\n" );
367 fprintf( stderr, "\n" );
368 fprintf( stderr, " " );
369 for( j=0; j<lgth2+1; j++ )
370 fprintf( stderr, "%c ", seq2[0][j] );
371 fprintf( stderr, "\n" );
374 localstop = lgth1+lgth2+1;
378 fprintf( stderr, "\n" );
379 fprintf( stderr, "%c ", seq1[0][0] );
381 for( j=0; j<lgth2+1; j++ )
382 fprintf( stderr, "%5.0f ", currentw[j] );
383 fprintf( stderr, "\n" );
387 for( i=1; i<lasti; i++ )
390 previousw = currentw;
393 previousw[0] = initverticalw[i-1];
395 match_calc( currentw, seq1, seq2, i, lgth2 );
397 fprintf( stderr, "%c ", seq1[0][i] );
398 fprintf( stderr, "%5.0f ", currentw[0] );
402 fprintf( stderr, "\n" );
403 fprintf( stderr, "i=%d\n", i );
404 fprintf( stderr, "currentw = \n" );
405 for( j=0; j<lgth2; j++ )
407 fprintf( stderr, "%5.2f ", currentw[j] );
409 fprintf( stderr, "\n" );
412 fprintf( stderr, "\n" );
413 fprintf( stderr, "i=%d\n", i );
414 fprintf( stderr, "currentw = \n" );
415 for( j=0; j<lgth2; j++ )
417 fprintf( stderr, "%5.2f ", currentw[j] );
419 fprintf( stderr, "\n" );
421 currentw[0] = initverticalw[i];
423 mi = previousw[0]; mpi = 0;
424 Mi = previousw[0]; Mpi = 0;
427 if( mi < localthr ) mi = localthr2;
430 ijpipt = ijpi[i] + 1;
431 ijpjpt = ijpj[i] + 1;
435 curpt = currentw + 1;
442 for( j=1; j<lastj; j++ )
449 // fprintf( stderr, "i,j=%d,%d %c-%c\n", i, j, seq1[0][i], seq2[0][j] );
450 // fprintf( stderr, "wm=%f\n", wm );
452 fprintf( stderr, "%5.0f->", wm );
456 fprintf( stderr, "%5.0f?", g );
461 // *ijpipt = i - 1; /*¤¤¤é¤Ê¤¤*/
476 fprintf( stderr, "%5.0f->", wm );
478 g = *mjpt + fpenalty;
480 fprintf( stderr, "m%5.0f?", g );
486 *ijpjpt = j - 1; /*¤¤¤é¤Ê¤¤*/ // IRIMASU!!!
495 *mjpt += fpenalty_ex;
499 g = tbk + fpenalty_OP; /*Ê̤ÎÊý¤¬¤¤¤¤¤«¤â*/
500 // g = tbk; /*Ê̤ÎÊý¤¬¤¤¤¤¤«¤â*/
506 // fprintf( stderr, "hit! i%d, j%d, ijpi = %d, ijpj = %d\n", i, j, *ijpipt, *ijpjpt );
522 // tbk += fpenalty_EX;// + foffset;
530 // *Mjpt += fpenalty_EX;// + foffset;
538 // Mi += fpenalty_EX;// + foffset;
541 // fprintf( stderr, "wm=%f, tbk=%f(%c-%c), mi=%f, *mjpt=%f\n", wm, tbk, seq1[0][tbki], seq2[0][tbkj], mi, *mjpt );
542 // fprintf( stderr, "ijp = %c,%c\n", seq1[0][abs(*ijpipt)], seq2[0][abs(*ijpjpt)] );
554 // fprintf( stderr, "stop i=%d, j=%d, curpt=%f\n", i, j, *curpt );
556 // *ijpjpt = localstop; /*¤¤¤é¤Ê¤¤*/
561 fprintf( stderr, "%5.0f ", *curpt );
564 fprintf( stderr, "%5.0f ", wm );
565 // fprintf( stderr, "%c-%c *ijppt = %d, localstop = %d\n", seq1[0][i], seq2[0][j], *ijppt, localstop );
579 fprintf( stderr, "\n" );
582 lastverticalw[i] = currentw[lgth2-1];
587 fprintf( stderr, "maxwm = %f\n", maxwm );
588 fprintf( stderr, "endali = %d\n", endali );
589 fprintf( stderr, "endalj = %d\n", endalj );
592 gentracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijpi, ijpj, off1pt, off2pt, endali, endalj );
594 // fprintf( stderr, "### impmatch = %f\n", *impmatch );
596 resultlen = strlen( mseq1[0] );
597 if( alloclen < resultlen || resultlen > N )
599 fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
600 ErrorExit( "LENGTH OVER!\n" );
604 strcpy( seq1[0], mseq1[0] );
605 strcpy( seq2[0], mseq2[0] );
608 fprintf( stderr, "\n" );
609 fprintf( stderr, ">\n%s\n", mseq1[0] );
610 fprintf( stderr, ">\n%s\n", mseq2[0] );