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;
38
lgth1 = strlen( seq1[0] );
39
lgth2 = strlen( seq2[0] );
43
for( i=0; i<lgth1; i++ )
45
fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
49
for( i=0; i<lgth1+1; i++ )
52
ijpj[i][0] = -1; // ???
54
for( j=0; j<lgth2+1; j++ )
56
ijpi[0][j] = -1; // ???
61
mseq1[0] += lgth1+lgth2;
63
mseq2[0] += lgth1+lgth2;
65
iin = lgth1; jin = lgth2;
66
limk = lgth1+lgth2 + 1;
67
for( k=0; k<limk; k++ )
69
ifi = ( ijpi[iin][jin] );
70
jfi = ( ijpj[iin][jin] );
74
*--mseq1[0] = seq1[0][ifi+l];
82
*--mseq2[0] = seq2[0][jfi+l];
85
if( iin <= 0 || jin <= 0 ) break;
86
*--mseq1[0] = seq1[0][ifi];
87
*--mseq2[0] = seq2[0][jfi];
89
// fprintf( stdout, "mseq1 = %s\n", mseq1[0] );
90
// fprintf( stdout, "mseq2 = %s\n", mseq2[0] );
99
float genG__align11( char **seq1, char **seq2, int alloclen )
100
/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
104
int lasti; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
107
float wm; /* int ?????? */
109
float *currentw, *previousw;
110
float fpenalty = (float)penalty;
111
float fpenalty_OP = (float)penalty_OP;
113
float fpenalty_ex = (float)penalty_ex;
119
float *mjpt, *Mjpt, *prept, *curpt;
123
static float Mi, *largeM;
128
static float *w1, *w2;
130
static float *initverticalw; /* kufuu sureba iranai */
131
static float *lastverticalw; /* kufuu sureba iranai */
135
static float **cpmx1;
136
static float **cpmx2;
137
static int **intwork;
138
static float **floatwork;
139
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 );
176
FreeFloatVec( largeM );
182
FreeFloatMtx( cpmx1 );
183
FreeFloatMtx( cpmx2 );
185
FreeFloatMtx( floatwork );
186
FreeIntMtx( intwork );
189
ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
190
ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
193
fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
196
w1 = AllocateFloatVec( ll2+2 );
197
w2 = AllocateFloatVec( ll2+2 );
198
match = AllocateFloatVec( ll2+2 );
200
initverticalw = AllocateFloatVec( ll1+2 );
201
lastverticalw = AllocateFloatVec( ll1+2 );
203
m = AllocateFloatVec( ll2+2 );
204
mp = AllocateIntVec( ll2+2 );
205
largeM = AllocateFloatVec( ll2+2 );
206
Mp = AllocateIntVec( ll2+2 );
208
mseq = AllocateCharMtx( njob, ll1+ll2 );
210
cpmx1 = AllocateFloatMtx( 26, ll1+2 );
211
cpmx2 = AllocateFloatMtx( 26, ll2+2 );
213
floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 );
214
intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 );
217
fprintf( stderr, "succeeded\n" );
229
if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
233
if( commonAlloc1 && commonAlloc2 )
235
FreeIntMtx( commonIP );
236
FreeIntMtx( commonJP );
239
ll1 = MAX( orlgth1, commonAlloc1 );
240
ll2 = MAX( orlgth2, commonAlloc2 );
243
fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
246
commonIP = AllocateIntMtx( ll1+10, ll2+10 );
247
commonJP = AllocateIntMtx( ll1+10, ll2+10 );
250
fprintf( stderr, "succeeded\n\n" );
261
for( i=0; i<lgth1; i++ )
262
fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
269
match_calc( initverticalw, seq2, seq1, 0, lgth1 );
272
match_calc( currentw, seq1, seq2, 0, lgth2 );
276
for( i=1; i<lgth1+1; i++ )
278
initverticalw[i] += fpenalty;
280
for( j=1; j<lgth2+1; j++ )
282
currentw[j] += fpenalty;
286
for( j=1; j<lgth2+1; ++j )
288
m[j] = currentw[j-1]; mp[j] = 0;
289
largeM[j] = currentw[j-1]; Mp[j] = 0;
293
lastverticalw[0] = 0.0; // lgth2==0 no toki error
295
lastverticalw[0] = currentw[lgth2-1]; // lgth2==0 no toki error
297
if( outgap ) lasti = lgth1+1; else lasti = lgth1;
300
fprintf( stderr, "currentw = \n" );
301
for( i=0; i<lgth1+1; i++ )
303
fprintf( stderr, "%5.2f ", currentw[i] );
305
fprintf( stderr, "\n" );
306
fprintf( stderr, "initverticalw = \n" );
307
for( i=0; i<lgth2+1; i++ )
309
fprintf( stderr, "%5.2f ", initverticalw[i] );
311
fprintf( stderr, "\n" );
314
for( i=1; i<lasti; i++ )
317
previousw = currentw;
320
previousw[0] = initverticalw[i-1];
322
match_calc( currentw, seq1, seq2, i, lgth2 );
324
fprintf( stderr, "\n" );
325
fprintf( stderr, "i=%d\n", i );
326
fprintf( stderr, "currentw = \n" );
327
for( j=0; j<lgth2; j++ )
329
fprintf( stderr, "%5.2f ", currentw[j] );
331
fprintf( stderr, "\n" );
334
fprintf( stderr, "\n" );
335
fprintf( stderr, "i=%d\n", i );
336
fprintf( stderr, "currentw = \n" );
337
for( j=0; j<lgth2; j++ )
339
fprintf( stderr, "%5.2f ", currentw[j] );
341
fprintf( stderr, "\n" );
343
currentw[0] = initverticalw[i];
345
mi = previousw[0]; mpi = 0;
346
Mi = previousw[0]; Mpi = 0;
348
ijpipt = ijpi[i] + 1;
349
ijpjpt = ijpj[i] + 1;
353
curpt = currentw + 1;
359
for( j=1; j<lgth2+1; j++ )
366
fprintf( stderr, "%5.0f->", wm );
369
fprintf( stderr, "%5.0f?", g );
371
if( (g=mi+fpenalty) > wm )
374
// *ijpipt = i - 1; // iranai
377
if( (g=*prept) >= mi )
387
fprintf( stderr, "%5.0f?", g );
389
if( (g=*mjpt + fpenalty) > wm )
393
*ijpjpt = j - 1; //IRU!
395
if( (g=*prept) >= *mjpt )
405
g = tbk + fpenalty_OP;
411
// fprintf( stderr, "hit! i%d, j%d, ijpi = %d, ijpj = %d\n", i, j, *ijpipt, *ijpjpt );
415
tbk = Mi; //error desu.
441
fprintf( stderr, "%5.0f ", wm );
452
lastverticalw[i] = currentw[lgth2-1]; // lgth2==0 no toki error
455
for( i=0; i<lgth1; i++ )
457
for( j=0; j<lgth2; j++ )
459
fprintf( stdout, "i,j=%d,%d - ijpi,ijpj=%d,%d\n", i, j, ijpi[i][j], ijpj[i][j] );
465
genGtracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijpi, ijpj );
467
resultlen = strlen( mseq1[0] );
468
if( alloclen < resultlen || resultlen > N )
470
fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
471
ErrorExit( "LENGTH OVER!\n" );
475
strcpy( seq1[0], mseq1[0] );
476
strcpy( seq2[0], mseq2[0] );
478
fprintf( stderr, "\n" );
479
fprintf( stderr, ">\n%s\n", mseq1[0] );
480
fprintf( stderr, ">\n%s\n", mseq2[0] );
481
fprintf( stderr, "wm = %f\n", wm );