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++];
19 static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 )
23 for( j=0; j<lgth2; j++ )
24 match[j] = amino_dis[(*s1)[i1]][(*s2)[j]];
28 static float genGtracking( float *lasthorizontalw, float *lastverticalw,
29 char **seq1, char **seq2,
30 char **mseq1, char **mseq2,
31 float **cpmx1, float **cpmx2,
32 int **ijpi, int **ijpj )
34 int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, limk;
36 lgth1 = strlen( seq1[0] );
37 lgth2 = strlen( seq2[0] );
41 for( i=0; i<lgth1; i++ )
43 fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
47 for( i=0; i<lgth1+1; i++ )
50 ijpj[i][0] = -1; // ???
52 for( j=0; j<lgth2+1; j++ )
54 ijpi[0][j] = -1; // ???
59 mseq1[0] += lgth1+lgth2;
61 mseq2[0] += lgth1+lgth2;
63 iin = lgth1; jin = lgth2;
64 limk = lgth1+lgth2 + 1;
65 for( k=0; k<limk; k++ )
67 ifi = ( ijpi[iin][jin] );
68 jfi = ( ijpj[iin][jin] );
72 *--mseq1[0] = seq1[0][ifi+l];
80 *--mseq2[0] = seq2[0][jfi+l];
83 if( iin <= 0 || jin <= 0 ) break;
84 *--mseq1[0] = seq1[0][ifi];
85 *--mseq2[0] = seq2[0][jfi];
87 // fprintf( stdout, "mseq1 = %s\n", mseq1[0] );
88 // fprintf( stdout, "mseq2 = %s\n", mseq2[0] );
97 float genG__align11( char **seq1, char **seq2, int alloclen )
98 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
102 int lasti; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
105 float wm; /* int ?????? */
107 float *currentw, *previousw;
108 float fpenalty = (float)penalty;
109 float fpenalty_OP = (float)penalty_OP;
111 float fpenalty_ex = (float)penalty_ex;
117 float *mjpt, *Mjpt, *prept, *curpt;
121 static float Mi, *largeM;
126 static float *w1, *w2;
128 static float *initverticalw; /* kufuu sureba iranai */
129 static float *lastverticalw; /* kufuu sureba iranai */
133 static float **cpmx1;
134 static float **cpmx2;
135 static int **intwork;
136 static float **floatwork;
137 static int orlgth1 = 0, orlgth2 = 0;
145 mseq1 = AllocateCharMtx( njob, 0 );
146 mseq2 = AllocateCharMtx( njob, 0 );
150 lgth1 = strlen( seq1[0] );
151 lgth2 = strlen( seq2[0] );
155 if( lgth1 <= 0 || lgth2 <= 0 )
157 fprintf( stderr, "WARNING (g11): lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
160 if( lgth1 > orlgth1 || lgth2 > orlgth2 )
164 if( orlgth1 > 0 && orlgth2 > 0 )
168 FreeFloatVec( match );
169 FreeFloatVec( initverticalw );
170 FreeFloatVec( lastverticalw );
174 FreeFloatVec( largeM );
180 FreeFloatMtx( cpmx1 );
181 FreeFloatMtx( cpmx2 );
183 FreeFloatMtx( floatwork );
184 FreeIntMtx( intwork );
187 ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
188 ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
191 fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
194 w1 = AllocateFloatVec( ll2+2 );
195 w2 = AllocateFloatVec( ll2+2 );
196 match = AllocateFloatVec( ll2+2 );
198 initverticalw = AllocateFloatVec( ll1+2 );
199 lastverticalw = AllocateFloatVec( ll1+2 );
201 m = AllocateFloatVec( ll2+2 );
202 mp = AllocateIntVec( ll2+2 );
203 largeM = AllocateFloatVec( ll2+2 );
204 Mp = AllocateIntVec( ll2+2 );
206 mseq = AllocateCharMtx( njob, ll1+ll2 );
208 cpmx1 = AllocateFloatMtx( 26, ll1+2 );
209 cpmx2 = AllocateFloatMtx( 26, ll2+2 );
211 floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 );
212 intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 );
215 fprintf( stderr, "succeeded\n" );
227 if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
231 if( commonAlloc1 && commonAlloc2 )
233 FreeIntMtx( commonIP );
234 FreeIntMtx( commonJP );
237 ll1 = MAX( orlgth1, commonAlloc1 );
238 ll2 = MAX( orlgth2, commonAlloc2 );
241 fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
244 commonIP = AllocateIntMtx( ll1+10, ll2+10 );
245 commonJP = AllocateIntMtx( ll1+10, ll2+10 );
248 fprintf( stderr, "succeeded\n\n" );
259 for( i=0; i<lgth1; i++ )
260 fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
267 match_calc( initverticalw, seq2, seq1, 0, lgth1 );
270 match_calc( currentw, seq1, seq2, 0, lgth2 );
274 for( i=1; i<lgth1+1; i++ )
276 initverticalw[i] += fpenalty;
278 for( j=1; j<lgth2+1; j++ )
280 currentw[j] += fpenalty;
284 for( j=1; j<lgth2+1; ++j )
286 m[j] = currentw[j-1]; mp[j] = 0;
287 largeM[j] = currentw[j-1]; Mp[j] = 0;
291 lastverticalw[0] = 0.0; // lgth2==0 no toki error
293 lastverticalw[0] = currentw[lgth2-1]; // lgth2==0 no toki error
295 if( outgap ) lasti = lgth1+1; else lasti = lgth1;
298 fprintf( stderr, "currentw = \n" );
299 for( i=0; i<lgth1+1; i++ )
301 fprintf( stderr, "%5.2f ", currentw[i] );
303 fprintf( stderr, "\n" );
304 fprintf( stderr, "initverticalw = \n" );
305 for( i=0; i<lgth2+1; i++ )
307 fprintf( stderr, "%5.2f ", initverticalw[i] );
309 fprintf( stderr, "\n" );
312 for( i=1; i<lasti; i++ )
315 previousw = currentw;
318 previousw[0] = initverticalw[i-1];
320 match_calc( currentw, seq1, seq2, i, lgth2 );
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" );
332 fprintf( stderr, "\n" );
333 fprintf( stderr, "i=%d\n", i );
334 fprintf( stderr, "currentw = \n" );
335 for( j=0; j<lgth2; j++ )
337 fprintf( stderr, "%5.2f ", currentw[j] );
339 fprintf( stderr, "\n" );
341 currentw[0] = initverticalw[i];
343 mi = previousw[0]; mpi = 0;
344 Mi = previousw[0]; Mpi = 0;
346 ijpipt = ijpi[i] + 1;
347 ijpjpt = ijpj[i] + 1;
351 curpt = currentw + 1;
357 for( j=1; j<lgth2+1; j++ )
364 fprintf( stderr, "%5.0f->", wm );
367 fprintf( stderr, "%5.0f?", g );
369 if( (g=mi+fpenalty) > wm )
372 // *ijpipt = i - 1; // iranai
375 if( (g=*prept) >= mi )
385 fprintf( stderr, "%5.0f?", g );
387 if( (g=*mjpt + fpenalty) > wm )
391 *ijpjpt = j - 1; //IRU!
393 if( (g=*prept) >= *mjpt )
403 g = tbk + fpenalty_OP;
409 // fprintf( stderr, "hit! i%d, j%d, ijpi = %d, ijpj = %d\n", i, j, *ijpipt, *ijpjpt );
413 tbk = Mi; //error desu.
439 fprintf( stderr, "%5.0f ", wm );
450 lastverticalw[i] = currentw[lgth2-1]; // lgth2==0 no toki error
453 for( i=0; i<lgth1; i++ )
455 for( j=0; j<lgth2; j++ )
457 fprintf( stdout, "i,j=%d,%d - ijpi,ijpj=%d,%d\n", i, j, ijpi[i][j], ijpj[i][j] );
463 genGtracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijpi, ijpj );
465 resultlen = strlen( mseq1[0] );
466 if( alloclen < resultlen || resultlen > N )
468 fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
469 ErrorExit( "LENGTH OVER!\n" );
473 strcpy( seq1[0], mseq1[0] );
474 strcpy( seq2[0], mseq2[0] );
476 fprintf( stderr, "\n" );
477 fprintf( stderr, ">\n%s\n", mseq1[0] );
478 fprintf( stderr, ">\n%s\n", mseq2[0] );
479 fprintf( stderr, "wm = %f\n", wm );