6 static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
10 float **cpmxpd = floatwork;
11 int **cpmxpdn = intwork;
16 for( j=0; j<lgth2; j++ )
23 cpmxpd[count][j] = cpmx2[l][j];
24 cpmxpdn[count][j] = l;
28 cpmxpdn[count][j] = -1;
36 scarr[l] += n_dis[k][l] * cpmx1[k][i1];
38 for( j=0; j<lgth2; j++ )
41 for( k=0; cpmxpdn[k][j] > -1; k++ )
42 match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j];
46 static float Atracking( float *lasthorizontalw, float *lastverticalw,
47 char **seq1, char **seq2,
48 char **mseq1, char **mseq2,
49 float **cpmx1, float **cpmx2,
50 int **ijp, int icyc, int jcyc )
52 int i, j, k, l, iin, jin, ifi, jfi, lgth1, lgth2;
57 lgth1 = strlen( seq1[0] );
58 lgth2 = strlen( seq2[0] );
61 for( i=0; i<lgth1; i++ )
63 fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
71 wm = lastverticalw[0];
72 for( i=0; i<lgth1; i++ )
74 if( lastverticalw[i] >= wm )
76 wm = lastverticalw[i];
77 iin = i; jin = lgth2-1;
78 ijp[lgth1][lgth2] = +( lgth1 - i );
81 for( j=0; j<lgth2; j++ )
83 if( lasthorizontalw[j] >= wm )
85 wm = lasthorizontalw[j];
86 iin = lgth1-1; jin = j;
87 ijp[lgth1][lgth2] = -( lgth2 - j );
92 for( i=0; i<lgth1+1; i++ )
96 for( j=0; j<lgth2+1; j++ )
98 ijp[0][j] = -( j + 1 );
101 for( i=0; i<icyc; i++ )
103 mseq1[i] += lgth1+lgth2;
106 for( j=0; j<jcyc; j++ )
108 mseq2[j] += lgth1+lgth2;
111 iin = lgth1; jin = lgth2;
112 for( k=0; k<=lgth1+lgth2; k++ )
114 if( ijp[iin][jin] < 0 )
116 ifi = iin-1; jfi = jin+ijp[iin][jin];
118 else if( ijp[iin][jin] > 0 )
120 ifi = iin-ijp[iin][jin]; jfi = jin-1;
124 ifi = iin-1; jfi = jin-1;
129 for( i=0; i<icyc; i++ )
130 *--mseq1[i] = seq1[i][ifi+l];
131 for( j=0; j<jcyc; j++ )
138 for( i=0; i<icyc; i++ )
140 for( j=0; j<jcyc; j++ )
141 *--mseq2[j] = seq2[j][jfi+l];
144 if( iin <= 0 || jin <= 0 ) break;
145 for( i=0; i<icyc; i++ )
146 *--mseq1[i] = seq1[i][ifi];
147 for( j=0; j<jcyc; j++ )
148 *--mseq2[j] = seq2[j][jfi];
150 iin = ifi; jin = jfi;
156 float Aalign( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen )
157 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
160 int lasti; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
163 float wm = 0.0; /* int ?????? */
166 static TLS float mi, *m;
167 static TLS int **ijp;
168 static TLS int mpi, *mp;
169 static TLS float *currentw;
170 static TLS float *previousw;
171 static TLS float *match;
172 static TLS float *initverticalw; /* kufuu sureba iranai */
173 static TLS float *lastverticalw; /* kufuu sureba iranai */
174 static TLS char **mseq1;
175 static TLS char **mseq2;
176 static TLS char **mseq;
177 static TLS float **cpmx1;
178 static TLS float **cpmx2;
179 static TLS int **intwork;
180 static TLS float **floatwork;
181 static TLS int orlgth1 = 0, orlgth2 = 0;
184 fprintf( stderr, "eff in SA+++align\n" );
185 for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
189 mseq1 = AllocateCharMtx( njob, 1 );
190 mseq2 = AllocateCharMtx( njob, 1 ); /* by J. Thompson */
193 lgth1 = strlen( seq1[0] );
194 lgth2 = strlen( seq2[0] );
196 if( lgth1 > orlgth1 || lgth2 > orlgth2 )
200 if( orlgth1 > 0 && orlgth2 > 0 )
202 FreeFloatVec( currentw );
203 FreeFloatVec( previousw );
204 FreeFloatVec( match );
205 FreeFloatVec( initverticalw );
206 FreeFloatVec( lastverticalw );
213 FreeFloatMtx( cpmx1 );
214 FreeFloatMtx( cpmx2 );
216 FreeFloatMtx( floatwork );
217 FreeIntMtx( intwork );
220 ll1 = MAX( (int)(1.1*lgth1), orlgth1 ) + 100;
221 ll2 = MAX( (int)(1.1*lgth2), orlgth2 ) + 100;
223 fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
225 currentw = AllocateFloatVec( ll2+2 );
226 previousw = AllocateFloatVec( ll2+2 );
227 match = AllocateFloatVec( ll2+2 );
229 initverticalw = AllocateFloatVec( ll1+2 );
230 lastverticalw = AllocateFloatVec( ll1+2 );
232 m = AllocateFloatVec( ll2+2 );
233 mp = AllocateIntVec( ll2+2 );
235 mseq = AllocateCharMtx( njob, ll1+ll2 );
237 cpmx1 = AllocateFloatMtx( 26, ll1+2 );
238 cpmx2 = AllocateFloatMtx( 26, ll2+2 );
240 floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 );
241 intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 );
243 fprintf( stderr, "succeeded\n" );
249 for( i=0; i<icyc; i++ ) mseq1[i] = mseq[i];
250 for( j=0; j<jcyc; j++ ) mseq2[j] = mseq[icyc+j];
253 if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
257 if( commonAlloc1 && commonAlloc2 )
259 FreeIntMtx( commonIP );
262 ll1 = MAX( orlgth1, commonAlloc1 );
263 ll2 = MAX( orlgth2, commonAlloc2 );
265 fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
267 commonIP = AllocateIntMtx( ll1+10, ll2+10 );
269 fprintf( stderr, "succeeded\n\n" );
276 cpmx_calc( seq1, cpmx1, eff1, strlen( seq1[0] ), icyc );
277 cpmx_calc( seq2, cpmx2, eff2, strlen( seq2[0] ), jcyc );
279 match_calc( initverticalw, cpmx2, cpmx1, 0, lgth1, floatwork, intwork, 1 );
280 match_calc( currentw, cpmx1, cpmx2, 0, lgth2, floatwork, intwork, 1 );
284 for( i=1; i<lgth1+1; i++ )
286 initverticalw[i] += penalty * 0.5;
288 for( j=1; j<lgth2+1; j++ )
290 currentw[j] += penalty * 0.5;
294 for( j=0; j<lgth2+1; ++j )
296 m[j] = currentw[j-1] + penalty * 0.5; mp[j] = 0;
299 lastverticalw[0] = currentw[lgth2-1];
301 if( outgap ) lasti = lgth1+1; else lasti = lgth1;
303 for( i=1; i<lasti; i++ )
306 floatncpy( previousw, currentw, lgth2+1 );
307 previousw[0] = initverticalw[i-1];
309 match_calc( currentw, cpmx1, cpmx2, i, lgth2, floatwork, intwork, 0 );
310 currentw[0] = initverticalw[i];
312 mi = previousw[0] + penalty * 0.5; mpi = 0;
313 for( j=1; j<lgth2+1; j++ )
323 ijp[i][j] = -( j - mpi );
326 x = previousw[j-1] + g;
338 ijp[i][j] = +( i - mp[j] );
341 x = previousw[j-1] + g;
349 lastverticalw[i] = currentw[lgth2-1];
352 fprintf( stderr, "\n" );
353 for( i=0; i<icyc; i++ ) fprintf( stderr,"%s\n", seq1[i] );
354 fprintf( stderr, "#####\n" );
355 for( j=0; j<jcyc; j++ ) fprintf( stderr,"%s\n", seq2[j] );
356 fprintf( stderr, "====>" );
357 for( i=0; i<icyc; i++ ) strcpy( mseq1[i], seq1[i] );
358 for( j=0; j<jcyc; j++ ) strcpy( mseq2[j], seq2[j] );
360 Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
362 resultlen = strlen( mseq1[0] );
363 if( alloclen < resultlen || resultlen > N )
365 fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
366 ErrorExit( "LENGTH OVER!\n" );
369 for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
370 for( j=0; j<jcyc; j++ ) strcpy( seq2[j], mseq2[j] );
372 fprintf( stderr, "\n" );
373 for( i=0; i<icyc; i++ ) fprintf( stderr, "%s\n", mseq1[i] );
374 fprintf( stderr, "#####\n" );
375 for( j=0; j<jcyc; j++ ) fprintf( stderr, "%s\n", mseq2[j] );