8 #define USE_PENALTY_EX 0
9 #define FASTMATCHCALC 1
13 static TLS float **impmtx = NULL;
14 static TLS int impalloclen = 0;
15 #if 1 // tditeration to naiveQscore_imp de tsukawareru.
16 float imp_match_out_scQ( int i1, int j1 )
18 // fprintf( stderr, "imp+match = %f\n", impmtx[i1][j1] * fastathreshold );
19 // fprintf( stderr, "val = %f\n", impmtx[i1][j1] );
20 return( impmtx[i1][j1] );
24 static void imp_match_out_veadQ_gapmap( float *imp, int i1, int lgth2, int *gapmap2 )
27 float *pt = impmtx[i1];
28 int *gapmappt = gapmap2;
30 *imp++ += pt[*gapmappt++];
33 float *pt = impmtx[i1];
34 for( j=0; j<lgth2; j++ )
35 *imp++ += pt[gapmap2[j]];
40 static void imp_match_out_vead_tateQ_gapmap( float *imp, int j1, int lgth1, int *gapmap1 )
43 int *gapmappt = gapmap1;
45 *imp++ += impmtx[*gapmappt++][j1];
48 for( i=0; i<lgth1; i++ )
49 *imp++ += impmtx[gapmap1[i]][j1];
54 static void imp_match_out_veadQ( float *imp, int i1, int lgth2 )
57 float *pt = impmtx[i1];
62 float *pt = impmtx[i1];
63 for( j=0; j<lgth2; j++ )
67 static void imp_match_out_vead_tateQ( float *imp, int j1, int lgth1 )
70 for( i=0; i<lgth1; i++ )
71 *imp++ += impmtx[i][j1];
74 void imp_rnaQ( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***grouprna1, RNApair ***grouprna2, int *gapmap1, int *gapmap2, RNApair *additionalpair )
76 foldrna( nseq1, nseq2, seq1, seq2, eff1, eff2, grouprna1, grouprna2, impmtx, gapmap1, gapmap2, additionalpair );
79 #if 1 // tbfast.c kara yobareru.
80 void imp_match_init_strictQ( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom, int forscore )
82 int i, j, k1, k2, tmpint, start1, start2, end1, end2;
86 static TLS char *nocount1 = NULL;
87 static TLS char *nocount2 = NULL;
90 if( impalloclen < lgth1 + 2 || impalloclen < lgth2 + 2 )
92 if( impmtx ) FreeFloatMtx( impmtx );
93 if( nocount1 ) free( nocount1 );
94 if( nocount2 ) free( nocount2 );
95 impalloclen = MAX( lgth1, lgth2 ) + 2;
96 impmtx = AllocateFloatMtx( impalloclen, impalloclen );
97 nocount1 = AllocateCharVec( impalloclen );
98 nocount2 = AllocateCharVec( impalloclen );
101 for( i=0; i<lgth1; i++ )
103 for( j=0; j<clus1; j++ )
104 if( seq1[j][i] == '-' ) break;
105 if( j != clus1 ) nocount1[i] = 1;
106 else nocount1[i] = 0;
108 for( i=0; i<lgth2; i++ )
110 for( j=0; j<clus2; j++ )
111 if( seq2[j][i] == '-' ) break;
112 if( j != clus2 ) nocount2[i] = 1;
113 else nocount2[i] = 0;
117 fprintf( stderr, "nocount2 =\n" );
118 for( i = 0; i<impalloclen; i++ )
120 fprintf( stderr, "nocount2[%d] = %d (%c)\n", i, nocount2[i], seq2[0][i] );
127 fprintf( stderr, "eff1 in _init_strict = \n" );
128 for( i=0; i<clus1; i++ )
129 fprintf( stderr, "eff1[] = %f\n", eff1[i] );
130 for( i=0; i<clus2; i++ )
131 fprintf( stderr, "eff2[] = %f\n", eff2[i] );
134 for( i=0; i<lgth1; i++ ) for( j=0; j<lgth2; j++ )
136 effijx = fastathreshold;
137 for( i=0; i<clus1; i++ )
139 for( j=0; j<clus2; j++ )
141 effij = (float)( eff1[i] * eff2[j] * effijx );
142 tmpptr = localhom[i][j];
145 // fprintf( stderr, "start1 = %d\n", tmpptr->start1 );
146 // fprintf( stderr, "end1 = %d\n", tmpptr->end1 );
147 // fprintf( stderr, "i = %d, seq1 = \n%s\n", i, seq1[i] );
148 // fprintf( stderr, "j = %d, seq2 = \n%s\n", j, seq2[j] );
153 if( *pt++ != '-' ) tmpint++;
154 if( tmpint == tmpptr->start1 ) break;
156 start1 = pt - seq1[i] - 1;
158 if( tmpptr->start1 == tmpptr->end1 ) end1 = start1;
164 // fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] );
165 if( tmpint == tmpptr->end1 ) break;
166 if( *pt++ != '-' ) tmpint++;
168 end1 = pt - seq1[i] - 0;
172 // fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] );
173 if( *pt++ != '-' ) tmpint++;
174 if( tmpint == tmpptr->end1 ) break;
176 end1 = pt - seq1[i] - 1;
184 if( *pt++ != '-' ) tmpint++;
185 if( tmpint == tmpptr->start2 ) break;
187 start2 = pt - seq2[j] - 1;
188 if( tmpptr->start2 == tmpptr->end2 ) end2 = start2;
194 if( tmpint == tmpptr->end2 ) break;
195 if( *pt++ != '-' ) tmpint++;
197 end2 = pt - seq2[j] - 0;
201 if( *pt++ != '-' ) tmpint++;
202 if( tmpint == tmpptr->end2 ) break;
204 end2 = pt - seq2[j] - 1;
207 // fprintf( stderr, "start1 = %d (%c), end1 = %d (%c), start2 = %d (%c), end2 = %d (%c)\n", start1, seq1[i][start1], end1, seq1[i][end1], start2, seq2[j][start2], end2, seq2[j][end2] );
208 // fprintf( stderr, "step 0\n" );
209 if( end1 - start1 != end2 - start2 )
211 // fprintf( stderr, "CHUUI!!, start1 = %d, end1 = %d, start2 = %d, end2 = %d\n", start1, end1, start2, end2 );
215 k1 = start1; k2 = start2;
218 while( *pt1 && *pt2 )
220 if( *pt1 != '-' && *pt2 != '-' )
222 // ½Å¤ß¤òÆó½Å¤Ë¤«¤±¤Ê¤¤¤è¤¦¤ËÃðդ·¤Æ²¼¤µ¤¤¡£
223 // impmtx[k1][k2] += tmpptr->wimportance * fastathreshold;
224 // impmtx[k1][k2] += tmpptr->importance * effij;
225 impmtx[k1][k2] += tmpptr->fimportance * effij;
226 // fprintf( stderr, "#### impmtx[k1][k2] = %f, tmpptr->fimportance=%f, effij=%f\n", impmtx[k1][k2], tmpptr->fimportance, effij );
227 // fprintf( stderr, "mark, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
228 // fprintf( stderr, "%d (%c) - %d (%c) - %f\n", k1, *pt1, k2, *pt2, tmpptr->fimportance * effij );
232 else if( *pt1 != '-' && *pt2 == '-' )
234 // fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
237 else if( *pt1 == '-' && *pt2 != '-' )
239 // fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
242 else if( *pt1 == '-' && *pt2 == '-' )
244 // fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
248 if( k1 > end1 || k2 > end2 ) break;
251 while( k1 <= end1 && k2 <= end2 )
253 fprintf( stderr, "k1,k2=%d,%d - ", k1, k2 );
254 if( !nocount1[k1] && !nocount2[k2] )
256 impmtx[k1][k2] += tmpptr->wimportance * eff1[i] * eff2[j] * fastathreshold;
257 fprintf( stderr, "marked\n" );
260 fprintf( stderr, "no count\n" );
264 tmpptr = tmpptr->next;
269 if( clus1 == 1 && clus2 == 6 )
271 fprintf( stderr, "\n" );
272 fprintf( stderr, "seq1[0] = %s\n", seq1[0] );
273 fprintf( stderr, "seq2[0] = %s\n", seq2[0] );
274 fprintf( stderr, "impmtx = \n" );
275 for( k2=0; k2<lgth2; k2++ )
276 fprintf( stderr, "%6.3f ", (double)k2 );
277 fprintf( stderr, "\n" );
278 for( k1=0; k1<lgth1; k1++ )
280 fprintf( stderr, "%d ", k1 );
281 for( k2=0; k2<3; k2++ )
282 fprintf( stderr, "%2.1f ", impmtx[k1][k2] );
283 fprintf( stderr, "\n" );
292 static void clearvec( float *match, int lgth )
294 while( lgth-- ) *match++ = 0.0;
297 static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
302 float **cpmxpd = floatwork;
303 int **cpmxpdn = intwork;
304 float *matchpt, *cpmxpdpt, **cpmxpdptpt;
305 int *cpmxpdnpt, **cpmxpdnptpt;
309 for( j=0; j<lgth2; j++ )
312 for( l=0; l<26; l++ )
316 cpmxpd[j][count] = cpmx2[l][j];
317 cpmxpdn[j][count] = l;
321 cpmxpdn[j][count] = -1;
326 for( l=0; l<26; l++ )
329 for( j=0; j<26; j++ )
330 scarr[l] += n_dis_consweight_multi[j][l] * cpmx1[j][i1];
331 // scarr[l] *= consweight_multi;
334 cpmxpdnptpt = cpmxpdn;
339 cpmxpdnpt = *cpmxpdnptpt++;
340 cpmxpdpt = *cpmxpdptpt++;
341 while( *cpmxpdnpt>-1 )
342 *matchpt += scarr[*cpmxpdnpt++] * *cpmxpdpt++;
349 float **cpmxpd = floatwork;
350 int **cpmxpdn = intwork;
355 for( j=0; j<lgth2; j++ )
358 for( l=0; l<26; l++ )
362 cpmxpd[count][j] = cpmx2[l][j];
363 cpmxpdn[count][j] = l;
367 cpmxpdn[count][j] = -1;
370 for( l=0; l<26; l++ )
373 for( k=0; k<26; k++ )
374 scarr[l] += n_dis_consweight_multi[k][l] * cpmx1[k][i1];
375 // scarr[l] *= consweight_multi;
377 for( j=0; j<lgth2; j++ )
380 for( k=0; cpmxpdn[k][j]>-1; k++ )
381 match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j];
386 static void Atracking_localhom_gapmap( float *impwmpt, float *lasthorizontalw, float *lastverticalw,
387 char **seq1, char **seq2,
388 char **mseq1, char **mseq2,
389 float **cpmx1, float **cpmx2,
390 int **ijp, int icyc, int jcyc,
391 int *gapmap1, int *gapmap2 )
393 int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k;
398 lgth1 = strlen( seq1[0] );
399 lgth2 = strlen( seq2[0] );
402 for( i=0; i<lgth1; i++ )
404 fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
412 wm = lastverticalw[0];
413 for( i=0; i<lgth1; i++ )
415 if( lastverticalw[i] >= wm )
417 wm = lastverticalw[i];
418 iin = i; jin = lgth2-1;
419 ijp[lgth1][lgth2] = +( lgth1 - i );
422 for( j=0; j<lgth2; j++ )
424 if( lasthorizontalw[j] >= wm )
426 wm = lasthorizontalw[j];
427 iin = lgth1-1; jin = j;
428 ijp[lgth1][lgth2] = -( lgth2 - j );
433 for( i=0; i<lgth1+1; i++ )
437 for( j=0; j<lgth2+1; j++ )
439 ijp[0][j] = -( j + 1 );
442 for( i=0; i<icyc; i++ )
444 mseq1[i] += lgth1+lgth2;
447 for( j=0; j<jcyc; j++ )
449 mseq2[j] += lgth1+lgth2;
452 iin = lgth1; jin = lgth2;
454 for( k=0; k<=lgth1+lgth2; k++ )
456 if( ijp[iin][jin] < 0 )
458 ifi = iin-1; jfi = jin+ijp[iin][jin];
460 else if( ijp[iin][jin] > 0 )
462 ifi = iin-ijp[iin][jin]; jfi = jin-1;
466 ifi = iin-1; jfi = jin-1;
471 for( i=0; i<icyc; i++ )
472 *--mseq1[i] = seq1[i][ifi+l];
473 for( j=0; j<jcyc; j++ )
480 for( i=0; i<icyc; i++ )
482 for( j=0; j<jcyc; j++ )
483 *--mseq2[j] = seq2[j][jfi+l];
486 if( iin != lgth1 && jin != lgth2 ) // ??
488 *impwmpt += imp_match_out_scQ( gapmap1[iin], gapmap2[jin] );
489 // fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] );
491 if( iin <= 0 || jin <= 0 ) break;
492 for( i=0; i<icyc; i++ )
493 *--mseq1[i] = seq1[i][ifi];
494 for( j=0; j<jcyc; j++ )
495 *--mseq2[j] = seq2[j][jfi];
497 iin = ifi; jin = jfi;
502 static void Atracking_localhom_gapmap_bk( float *impwmpt, float *lasthorizontalw, float *lastverticalw,
503 char **seq1, char **seq2,
504 char **mseq1, char **mseq2,
505 float **cpmx1, float **cpmx2,
506 int **ijp, int icyc, int jcyc,
507 int *gapmap1, int *gapmap2 )
509 int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k;
511 char *gaptable1, *gt1bk;
512 char *gaptable2, *gt2bk;
513 lgth1 = strlen( seq1[0] );
514 lgth2 = strlen( seq2[0] );
515 gt1bk = AllocateCharVec( lgth1+lgth2+1 );
516 gt2bk = AllocateCharVec( lgth1+lgth2+1 );
519 for( i=0; i<lgth1; i++ )
521 fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
529 wm = lastverticalw[0];
530 for( i=0; i<lgth1; i++ )
532 if( lastverticalw[i] >= wm )
534 wm = lastverticalw[i];
535 iin = i; jin = lgth2-1;
536 ijp[lgth1][lgth2] = +( lgth1 - i );
539 for( j=0; j<lgth2; j++ )
541 if( lasthorizontalw[j] >= wm )
543 wm = lasthorizontalw[j];
544 iin = lgth1-1; jin = j;
545 ijp[lgth1][lgth2] = -( lgth2 - j );
550 for( i=0; i<lgth1+1; i++ )
554 for( j=0; j<lgth2+1; j++ )
556 ijp[0][j] = -( j + 1 );
559 gaptable1 = gt1bk + lgth1+lgth2;
561 gaptable2 = gt2bk + lgth1+lgth2;
564 iin = lgth1; jin = lgth2;
566 for( k=0; k<=lgth1+lgth2; k++ )
568 if( ijp[iin][jin] < 0 )
570 ifi = iin-1; jfi = jin+ijp[iin][jin];
572 else if( ijp[iin][jin] > 0 )
574 ifi = iin-ijp[iin][jin]; jfi = jin-1;
578 ifi = iin-1; jfi = jin-1;
594 if( iin == lgth1 || jin == lgth2 )
598 *impwmpt += imp_match_out_scQ( gapmap1[iin], gapmap2[jin] );
600 // fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] );
602 if( iin <= 0 || jin <= 0 ) break;
606 iin = ifi; jin = jfi;
608 for( i=0; i<icyc; i++ ) gapireru( mseq1[i], seq1[i], gaptable1 );
609 for( j=0; j<jcyc; j++ ) gapireru( mseq2[j], seq2[j], gaptable2 );
611 fprintf( stderr, "mseq1[0] = %s\n", mseq1[0] );
612 fprintf( stderr, "mseq2[0] = %s\n", mseq2[0] );
621 static void Atracking_localhom( float *impwmpt, float *lasthorizontalw, float *lastverticalw,
622 char **seq1, char **seq2,
623 char **mseq1, char **mseq2,
624 float **cpmx1, float **cpmx2,
625 int **ijp, int icyc, int jcyc )
627 int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k;
629 char *gaptable1, *gt1bk;
630 char *gaptable2, *gt2bk;
631 lgth1 = strlen( seq1[0] );
632 lgth2 = strlen( seq2[0] );
633 gt1bk = AllocateCharVec( lgth1+lgth2+1 );
634 gt2bk = AllocateCharVec( lgth1+lgth2+1 );
637 for( i=0; i<lgth1; i++ )
639 fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
647 wm = lastverticalw[0];
648 for( i=0; i<lgth1; i++ )
650 if( lastverticalw[i] >= wm )
652 wm = lastverticalw[i];
653 iin = i; jin = lgth2-1;
654 ijp[lgth1][lgth2] = +( lgth1 - i );
657 for( j=0; j<lgth2; j++ )
659 if( lasthorizontalw[j] >= wm )
661 wm = lasthorizontalw[j];
662 iin = lgth1-1; jin = j;
663 ijp[lgth1][lgth2] = -( lgth2 - j );
668 for( i=0; i<lgth1+1; i++ )
672 for( j=0; j<lgth2+1; j++ )
674 ijp[0][j] = -( j + 1 );
677 gaptable1 = gt1bk + lgth1+lgth2;
679 gaptable2 = gt2bk + lgth1+lgth2;
682 iin = lgth1; jin = lgth2;
684 for( k=0; k<=lgth1+lgth2; k++ )
686 if( ijp[iin][jin] < 0 )
688 ifi = iin-1; jfi = jin+ijp[iin][jin];
690 else if( ijp[iin][jin] > 0 )
692 ifi = iin-ijp[iin][jin]; jfi = jin-1;
696 ifi = iin-1; jfi = jin-1;
712 if( iin == lgth1 || jin == lgth2 )
716 *impwmpt += imp_match_out_scQ( iin, jin );
718 // fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] );
720 if( iin <= 0 || jin <= 0 ) break;
724 iin = ifi; jin = jfi;
727 for( i=0; i<icyc; i++ ) gapireru( mseq1[i], seq1[i], gaptable1 );
728 for( j=0; j<jcyc; j++ ) gapireru( mseq2[j], seq2[j], gaptable2 );
735 static float Atracking( float *lasthorizontalw, float *lastverticalw,
736 char **seq1, char **seq2,
737 char **mseq1, char **mseq2,
738 float **cpmx1, float **cpmx2,
739 int **ijp, int icyc, int jcyc )
741 int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k;
743 char *gaptable1, *gt1bk;
744 char *gaptable2, *gt2bk;
745 lgth1 = strlen( seq1[0] );
746 lgth2 = strlen( seq2[0] );
748 gt1bk = AllocateCharVec( lgth1+lgth2+1 );
749 gt2bk = AllocateCharVec( lgth1+lgth2+1 );
752 for( i=0; i<lgth1; i++ )
754 fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
762 wm = lastverticalw[0];
763 for( i=0; i<lgth1; i++ )
765 if( lastverticalw[i] >= wm )
767 wm = lastverticalw[i];
768 iin = i; jin = lgth2-1;
769 ijp[lgth1][lgth2] = +( lgth1 - i );
772 for( j=0; j<lgth2; j++ )
774 if( lasthorizontalw[j] >= wm )
776 wm = lasthorizontalw[j];
777 iin = lgth1-1; jin = j;
778 ijp[lgth1][lgth2] = -( lgth2 - j );
783 for( i=0; i<lgth1+1; i++ )
787 for( j=0; j<lgth2+1; j++ )
789 ijp[0][j] = -( j + 1 );
792 gaptable1 = gt1bk + lgth1+lgth2;
794 gaptable2 = gt2bk + lgth1+lgth2;
797 iin = lgth1; jin = lgth2;
798 for( k=0; k<=lgth1+lgth2; k++ )
800 if( ijp[iin][jin] < 0 )
802 ifi = iin-1; jfi = jin+ijp[iin][jin];
804 else if( ijp[iin][jin] > 0 )
806 ifi = iin-ijp[iin][jin]; jfi = jin-1;
810 ifi = iin-1; jfi = jin-1;
826 if( iin <= 0 || jin <= 0 ) break;
830 iin = ifi; jin = jfi;
833 for( i=0; i<icyc; i++ ) gapireru( mseq1[i], seq1[i], gaptable1 );
834 for( j=0; j<jcyc; j++ ) gapireru( mseq2[j], seq2[j], gaptable2 );
842 float Q__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *sgap1, char *sgap2, char *egap1, char *egap2 )
843 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
847 int lasti, lastj; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
850 float wm = 0.0; /* int ?????? */
852 float *currentw, *previousw;
853 // float fpenalty = (float)penalty;
855 float fpenalty_ex = (float)penalty_ex;
856 fprintf( stderr, "fpenalty_ex = %f\n", fpenalty_ex );
861 float *mjpt, *prept, *curpt;
864 static TLS float mi, *m;
865 static TLS int **ijp;
866 static TLS int mpi, *mp;
867 static TLS float *w1, *w2;
868 static TLS float *match;
869 static TLS float *initverticalw; /* kufuu sureba iranai */
870 static TLS float *lastverticalw; /* kufuu sureba iranai */
871 static TLS char **mseq1;
872 static TLS char **mseq2;
873 static TLS char **mseq;
874 static TLS float *digf1;
875 static TLS float *digf2;
876 static TLS float *diaf1;
877 static TLS float *diaf2;
878 static TLS float *gapz1;
879 static TLS float *gapz2;
880 static TLS float *gapf1;
881 static TLS float *gapf2;
882 static TLS float *ogcp1g;
883 static TLS float *ogcp2g;
884 static TLS float *fgcp1g;
885 static TLS float *fgcp2g;
886 static TLS float *og_h_dg_n1_p;
887 static TLS float *og_h_dg_n2_p;
888 static TLS float *fg_h_dg_n1_p;
889 static TLS float *fg_h_dg_n2_p;
890 static TLS float *og_t_fg_h_dg_n1_p;
891 static TLS float *og_t_fg_h_dg_n2_p;
892 static TLS float *fg_t_og_h_dg_n1_p;
893 static TLS float *fg_t_og_h_dg_n2_p;
894 static TLS float *gapz_n1;
895 static TLS float *gapz_n2;
896 static TLS float **cpmx1;
897 static TLS float **cpmx2;
898 static TLS int **intwork;
899 static TLS float **floatwork;
900 static TLS int orlgth1 = 0, orlgth2 = 0;
902 float *fg_t_og_h_dg_n2_p_pt;
903 float *og_t_fg_h_dg_n2_p_pt;
904 float *og_h_dg_n2_p_pt;
905 float *fg_h_dg_n2_p_pt;
910 float fg_t_og_h_dg_n1_p_va;
911 float og_t_fg_h_dg_n1_p_va;
912 float og_h_dg_n1_p_va;
913 float fg_h_dg_n1_p_va;
920 float fpenalty = (float)penalty;
923 if( RNAscoremtx != 'r' ) fpenalty = (float)penalty;
924 else fpenalty = (float)penalty * 10;
928 fprintf( stderr, "#### seq1[0] = %s\n", seq1[0] );
929 fprintf( stderr, "#### seq2[0] = %s\n", seq2[0] );
936 mseq1 = AllocateCharMtx( njob, 0 );
937 mseq2 = AllocateCharMtx( njob, 0 );
941 lgth1 = strlen( seq1[0] );
942 lgth2 = strlen( seq2[0] );
944 if( lgth1 == 0 || lgth2 == 0 )
946 fprintf( stderr, "WARNING (Aalignmm): lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
950 if( lgth1 > orlgth1 || lgth2 > orlgth2 )
954 if( orlgth1 > 0 && orlgth2 > 0 )
958 FreeFloatVec( match );
959 FreeFloatVec( initverticalw );
960 FreeFloatVec( lastverticalw );
967 FreeFloatVec( digf1 );
968 FreeFloatVec( digf2 );
969 FreeFloatVec( diaf1 );
970 FreeFloatVec( diaf2 );
971 FreeFloatVec( gapz1 );
972 FreeFloatVec( gapz2 );
973 FreeFloatVec( gapf1 );
974 FreeFloatVec( gapf2 );
975 FreeFloatVec( ogcp1g );
976 FreeFloatVec( ogcp2g );
977 FreeFloatVec( fgcp1g );
978 FreeFloatVec( fgcp2g );
979 FreeFloatVec( og_h_dg_n1_p );
980 FreeFloatVec( og_h_dg_n2_p );
981 FreeFloatVec( fg_h_dg_n1_p );
982 FreeFloatVec( fg_h_dg_n2_p );
983 FreeFloatVec( og_t_fg_h_dg_n1_p );
984 FreeFloatVec( og_t_fg_h_dg_n2_p );
985 FreeFloatVec( fg_t_og_h_dg_n1_p );
986 FreeFloatVec( fg_t_og_h_dg_n2_p );
987 FreeFloatVec( gapz_n1 );
988 FreeFloatVec( gapz_n2 );
990 FreeFloatMtx( cpmx1 );
991 FreeFloatMtx( cpmx2 );
993 FreeFloatMtx( floatwork );
994 FreeIntMtx( intwork );
997 ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
998 ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
1001 fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
1004 w1 = AllocateFloatVec( ll2+2 );
1005 w2 = AllocateFloatVec( ll2+2 );
1006 match = AllocateFloatVec( ll2+2 );
1008 initverticalw = AllocateFloatVec( ll1+2 );
1009 lastverticalw = AllocateFloatVec( ll1+2 );
1011 m = AllocateFloatVec( ll2+2 );
1012 mp = AllocateIntVec( ll2+2 );
1014 mseq = AllocateCharMtx( njob, ll1+ll2 );
1016 digf1 = AllocateFloatVec( ll1+2 );
1017 digf2 = AllocateFloatVec( ll2+2 );
1018 diaf1 = AllocateFloatVec( ll1+2 );
1019 diaf2 = AllocateFloatVec( ll2+2 );
1020 gapz1 = AllocateFloatVec( ll1+2 );
1021 gapz2 = AllocateFloatVec( ll2+2 );
1022 gapf1 = AllocateFloatVec( ll1+2 );
1023 gapf2 = AllocateFloatVec( ll2+2 );
1024 ogcp1g = AllocateFloatVec( ll1+2 );
1025 ogcp2g = AllocateFloatVec( ll2+2 );
1026 fgcp1g = AllocateFloatVec( ll1+2 );
1027 fgcp2g = AllocateFloatVec( ll2+2 );
1028 og_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
1029 og_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
1030 fg_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
1031 fg_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
1032 og_t_fg_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
1033 og_t_fg_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
1034 fg_t_og_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
1035 fg_t_og_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
1036 gapz_n1 = AllocateFloatVec( ll1+2 );
1037 gapz_n2 = AllocateFloatVec( ll2+2 );
1039 cpmx1 = AllocateFloatMtx( 26, ll1+2 );
1040 cpmx2 = AllocateFloatMtx( 26, ll2+2 );
1043 floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 );
1044 intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 );
1046 floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 );
1047 intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 );
1051 fprintf( stderr, "succeeded\n" );
1054 orlgth1 = ll1 - 100;
1055 orlgth2 = ll2 - 100;
1059 for( i=0; i<icyc; i++ )
1064 for( j=0; j<jcyc; j++ )
1066 mseq2[j] = mseq[icyc+j];
1071 if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
1075 if( commonAlloc1 && commonAlloc2 )
1077 FreeIntMtx( commonIP );
1080 ll1 = MAX( orlgth1, commonAlloc1 );
1081 ll2 = MAX( orlgth2, commonAlloc2 );
1084 fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
1087 commonIP = AllocateIntMtx( ll1+10, ll2+10 );
1090 fprintf( stderr, "succeeded\n\n" );
1101 for( i=0; i<icyc; i++ )
1103 fprintf( stderr, "## totaleff = %f\n", t );
1107 cpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
1108 cpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
1112 new_OpeningGapCount_zure( ogcp1g, icyc, seq1, eff1, lgth1, sgap1, egap1 );
1113 new_OpeningGapCount_zure( ogcp2g, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
1114 new_FinalGapCount_zure( fgcp1g, icyc, seq1, eff1, lgth1, sgap1, egap1 );
1115 new_FinalGapCount_zure( fgcp2g, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
1116 getdigapfreq_part( digf1, icyc, seq1, eff1, lgth1, sgap1, egap1 );
1117 getdigapfreq_part( digf2, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
1118 getdiaminofreq_part( diaf1, icyc, seq1, eff1, lgth1, sgap1, egap1 );
1119 getdiaminofreq_part( diaf2, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
1120 getgapfreq( gapf1, icyc, seq1, eff1, lgth1 );
1121 getgapfreq( gapf2, jcyc, seq2, eff2, lgth2 );
1122 getgapfreq_zure_part( gapz1, icyc, seq1, eff1, lgth1, sgap1 );
1123 getgapfreq_zure_part( gapz2, jcyc, seq2, eff2, lgth2, sgap1 );
1127 st_OpeningGapCount( ogcp1g, icyc, seq1, eff1, lgth1 );
1128 st_OpeningGapCount( ogcp2g, jcyc, seq2, eff2, lgth2 );
1129 st_FinalGapCount_zure( fgcp1g, icyc, seq1, eff1, lgth1 );
1130 st_FinalGapCount_zure( fgcp2g, jcyc, seq2, eff2, lgth2 );
1131 getdigapfreq_st( digf1, icyc, seq1, eff1, lgth1 );
1132 getdigapfreq_st( digf2, jcyc, seq2, eff2, lgth2 );
1133 getdiaminofreq_x( diaf1, icyc, seq1, eff1, lgth1 );
1134 getdiaminofreq_x( diaf2, jcyc, seq2, eff2, lgth2 );
1135 getgapfreq( gapf1, icyc, seq1, eff1, lgth1 );
1136 getgapfreq( gapf2, jcyc, seq2, eff2, lgth2 );
1137 getgapfreq_zure( gapz1, icyc, seq1, eff1, lgth1 );
1138 getgapfreq_zure( gapz2, jcyc, seq2, eff2, lgth2 );
1143 for( i=0; i<lastj; i++ )
1145 og_h_dg_n2_p[i] = ( 1.0-ogcp2g[i]-digf2[i] ) * fpenalty * 0.5;
1146 fg_h_dg_n2_p[i] = ( 1.0-fgcp2g[i]-digf2[i] ) * fpenalty * 0.5;
1147 og_t_fg_h_dg_n2_p[i] = (1.0-ogcp2g[i]+fgcp2g[i]-digf2[i]) * 0.5 * fpenalty;
1148 fg_t_og_h_dg_n2_p[i] = (1.0-fgcp2g[i]+ogcp2g[i]-digf2[i]) * 0.5 * fpenalty;
1149 gapz_n2[i] = (1.0-gapz2[i]);
1152 for( i=0; i<lastj; i++ )
1154 og_h_dg_n1_p[i] = ( 1.0-ogcp1g[i]-digf1[i] ) * fpenalty * 0.5;
1155 fg_h_dg_n1_p[i] = ( 1.0-fgcp1g[i]-digf1[i] ) * fpenalty * 0.5;
1156 og_t_fg_h_dg_n1_p[i] = (1.0-ogcp1g[i]+fgcp1g[i]-digf1[i]) * 0.5 * fpenalty;
1157 fg_t_og_h_dg_n1_p[i] = (1.0-fgcp1g[i]+ogcp1g[i]-digf1[i]) * 0.5 * fpenalty;
1158 gapz_n1[i] = (1.0-gapz1[i]);
1165 for( i=0; i<lgth1; i++ )
1166 fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
1172 if( RNAscoremtx != 'r' )
1173 match_calc( initverticalw, cpmx2, cpmx1, 0, lgth1, floatwork, intwork, 1 );
1175 clearvec( initverticalw, lgth1 );
1177 imp_match_out_vead_tateQ( initverticalw, 0, lgth1 ); // 060306
1179 if( RNAscoremtx != 'r' )
1180 match_calc( currentw, cpmx1, cpmx2, 0, lgth2, floatwork, intwork, 1 );
1182 clearvec( currentw, lgth2 );
1184 imp_match_out_veadQ( currentw, 0, lgth2 ); // 060306
1187 #if 0 // -> tbfast.c
1189 imp_match_calc( currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 );
1200 g += ogcp1g[0] * og_h_dg_n2_p[0];
1201 // g += ogcp1g[0] * ( 1.0-ogcp2g[0]-digf2[0] ) * fpenalty * 0.5;
1202 // if( g ) fprintf( stderr, "init-match penal1=%f, %c-%c\n", g, seq1[0][0], seq2[0][0] );
1204 g += ogcp2g[0] * og_h_dg_n1_p[0];
1205 // g += ogcp2g[0] * ( 1.0-ogcp1g[0]-digf1[0] ) * fpenalty * 0.5;
1206 // if( g ) fprintf( stderr, "init-match penal2=%f, %c-%c\n", g, seq1[0][0], seq2[0][0] );
1208 g += fgcp1g[0] * fg_h_dg_n2_p[0];
1209 // g += fgcp1g[0] * ( 1.0-fgcp2g[0]-digf2[0] ) * fpenalty * 0.5;
1210 // if( g ) fprintf( stderr, "match penal1=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
1212 g += fgcp2g[0] * fg_h_dg_n1_p[0];
1213 // g += fgcp2g[0] * ( 1.0-fgcp1g[0]-digf1[0] ) * fpenalty * 0.5;
1214 // if( g ) fprintf( stderr, "match penal2=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
1217 initverticalw[0] += g;
1220 for( i=1; i<lgth1+1; i++ )
1222 tmppenal = gapz_n2[0]*og_t_fg_h_dg_n1_p[0];
1223 // tmppenal = ( (1.0-gapz2[0])*(1.0-ogcp1g[0]+fgcp1g[0]-digf1[0]) ) * 0.5 * fpenalty; // mada
1224 initverticalw[i] += tmppenal;
1226 tmppenal = gapz_n2[1]*fg_t_og_h_dg_n1_p[i];
1227 // tmppenal = ( (1.0-gapz2[1])*(1.0-fgcp1g[i]+ogcp1g[i]-digf1[i]) ) * 0.5 * fpenalty; // mada
1228 initverticalw[i] += tmppenal;
1231 for( j=1; j<lgth2+1; j++ )
1233 tmppenal = gapz_n1[0]*og_t_fg_h_dg_n2_p[0];
1234 // tmppenal = ( (1.0-gapz1[0])*(1.0-ogcp2g[0]+fgcp2g[0]-digf2[0]) ) * 0.5 * fpenalty; // mada
1235 currentw[j] += tmppenal;
1237 tmppenal = gapz_n1[1]*fg_t_og_h_dg_n2_p[j];
1238 // tmppenal = ( (1.0-gapz1[1])*(1.0-fgcp2g[j]+ogcp2g[j]-digf2[j]) ) * 0.5 * fpenalty; // mada
1239 currentw[j] += tmppenal;
1245 for( j=1; j<lgth2+1; j++ )
1246 currentw[j] -= offset * j / 2.0;
1247 for( i=1; i<lgth1+1; i++ )
1248 initverticalw[i] -= offset * i / 2.0;
1252 m[0] = 0.0; // iranai
1253 for( j=1; j<lgth2+1; ++j )
1256 m[j] = currentw[j-1] + 10000 * fpenalty; //iinoka?
1259 lastverticalw[0] = 0.0; // Falign kara yobaretatoki kounarukanousei ari
1261 lastverticalw[0] = currentw[lgth2-1];
1263 if( outgap ) lasti = lgth1+1; else lasti = lgth1;
1266 fprintf( stderr, "currentw = \n" );
1267 for( i=0; i<lgth1+1; i++ )
1269 fprintf( stderr, "%5.2f ", currentw[i] );
1271 fprintf( stderr, "\n" );
1272 fprintf( stderr, "initverticalw = \n" );
1273 for( i=0; i<lgth2+1; i++ )
1275 fprintf( stderr, "%5.2f ", initverticalw[i] );
1277 fprintf( stderr, "\n" );
1278 fprintf( stderr, "fcgp\n" );
1279 for( i=0; i<lgth1; i++ )
1280 fprintf( stderr, "fgcp1[%d]=%f\n", i, ogcp1[i] );
1281 for( i=0; i<lgth2; i++ )
1282 fprintf( stderr, "fgcp2[%d]=%f\n", i, ogcp2[i] );
1285 for( i=1; i<lasti; i++ )
1288 previousw = currentw;
1291 previousw[0] = initverticalw[i-1];
1293 if( RNAscoremtx != 'r' )
1294 match_calc( currentw, cpmx1, cpmx2, i, lgth2, floatwork, intwork, 0 );
1296 clearvec( currentw, lgth2 );
1298 fprintf( stderr, "\n" );
1299 fprintf( stderr, "i=%d\n", i );
1300 fprintf( stderr, "currentw = \n" );
1301 for( j=0; j<lgth2; j++ )
1303 fprintf( stderr, "%5.2f ", currentw[j] );
1305 fprintf( stderr, "\n" );
1309 // fprintf( stderr, "Calling imp_match_calc (o) lgth = %d, i = %d\n", lgth1, i );
1311 imp_match_out_veadQ( currentw, i, lgth2 );
1313 imp_match_out_veadQ( currentw, i, lgth2 );
1317 fprintf( stderr, "\n" );
1318 fprintf( stderr, "i=%d\n", i );
1319 fprintf( stderr, "currentw = \n" );
1320 for( j=0; j<lgth2; j++ )
1322 fprintf( stderr, "%5.2f ", currentw[j] );
1324 fprintf( stderr, "\n" );
1326 currentw[0] = initverticalw[i];
1329 mi = previousw[0] + 10000 * fpenalty;
1334 curpt = currentw + 1;
1336 fg_t_og_h_dg_n2_p_pt = fg_t_og_h_dg_n2_p + 1;
1337 og_t_fg_h_dg_n2_p_pt = og_t_fg_h_dg_n2_p + 1;
1338 og_h_dg_n2_p_pt = og_h_dg_n2_p + 1;
1339 fg_h_dg_n2_p_pt = fg_h_dg_n2_p + 1;
1340 gapz_n2_pt0 = gapz_n2 + 1;
1341 gapz_n2_pt1 = gapz_n2 + 2;
1342 fgcp2pt = fgcp2g + 1;
1343 ogcp2pt = ogcp2g + 1;
1345 fg_t_og_h_dg_n1_p_va = fg_t_og_h_dg_n1_p[i];
1346 og_t_fg_h_dg_n1_p_va = og_t_fg_h_dg_n1_p[i];
1347 og_h_dg_n1_p_va = og_h_dg_n1_p[i];
1348 fg_h_dg_n1_p_va = fg_h_dg_n1_p[i];
1349 gapz_n1_va0 = gapz_n1[i];
1350 gapz_n1_va1 = gapz_n1[i+1];
1351 fgcp1va = fgcp1g[i];
1352 ogcp1va = ogcp1g[i];
1355 for( j=1; j<lastj; j++ )
1359 g = ogcp1va * *og_h_dg_n2_p_pt;
1360 // g = ogcp1g[i] * og_h_dg_n2_p[j];
1361 // g = ogcp1g[i] * ( 1.0-ogcp2g[j]-digf2[j] ) * fpenalty * 0.5;
1362 // if( g && i==j ) fprintf( stderr, "match penal1=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
1365 g = *ogcp2pt * og_h_dg_n1_p_va;
1366 // g = ogcp2g[j] * og_h_dg_n1_p[i];
1367 // g = ogcp2g[j] * ( 1.0-ogcp1g[i]-digf1[i] ) * fpenalty * 0.5;
1368 // if( g && i==j ) fprintf( stderr, "match penal2=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
1371 g = fgcp1va * *fg_h_dg_n2_p_pt;
1372 // g = fgcp1g[i] * fg_h_dg_n2_p[j];
1373 // g = fgcp1g[i] * ( 1.0-fgcp2g[j]-digf2[j] ) * fpenalty * 0.5;
1374 // if( g && i==j ) fprintf( stderr, "match penal3=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
1377 g = *fgcp2pt * fg_h_dg_n1_p_va;
1378 // g = fgcp2g[j] * fg_h_dg_n1_p[i];
1379 // g = fgcp2g[j] * ( 1.0-fgcp1g[i]-digf1[i] ) * fpenalty * 0.5;
1380 // if( g && i==j ) fprintf( stderr, "match penal4=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
1386 fprintf( stderr, "%5.0f->", wm );
1389 fprintf( stderr, "%5.0f?", g );
1391 tmppenal = gapz_n1_va1 * *fg_t_og_h_dg_n2_p_pt;
1392 // tmppenal = gapz_n1[i+1] * fg_t_og_h_dg_n2_p[j];
1393 // tmppenal = ( (1.0-gapz1[i+1])*(1.0-fgcp2g[j]+ogcp2g[j]-digf2[j]) ) * 0.5 * fpenalty; // mada
1394 if( (g=mi+tmppenal) > wm )
1396 // fprintf( stderr, "jump i start=%f (j=%d, fgcp2g[j]=%f, digf2[j]=%f, diaf2[j]=%f), %c-%c\n", g-mi, j, fgcp2g[j], digf2[j], diaf2[j], seq1[0][i], seq2[0][j] );
1398 *ijppt = -( j - mpi );
1400 tmppenal = gapz_n1_va0 * *og_t_fg_h_dg_n2_p_pt;
1401 // tmppenal = gapz_n1[i] * og_t_fg_h_dg_n2_p[j];
1402 // tmppenal = ( (1.0-gapz1[i])*(1.0-ogcp2g[j]+fgcp2g[j]-digf2[j]) ) * 0.5 * fpenalty; // mada
1403 if( (g=*prept+tmppenal) >= mi )
1405 // fprintf( stderr, "jump i end=%f, %c-%c\n", g-*prept, seq1[0][i-1], seq2[0][j-1] );
1415 fprintf( stderr, "%5.0f?", g );
1417 tmppenal = *gapz_n2_pt1 * fg_t_og_h_dg_n1_p_va;
1418 // tmppenal = gapz_n2[j+1] * fg_t_og_h_dg_n1_p[i];
1419 // tmppenal = ( (1.0-gapz2[j+1])*(1.0-fgcp1g[i]+ogcp1g[i]-digf1[i]) ) * 0.5 * fpenalty; // mada
1420 if( (g=*mjpt+tmppenal) > wm )
1423 *ijppt = +( i - *mpjpt );
1425 tmppenal = *gapz_n2_pt0 * og_t_fg_h_dg_n1_p_va;
1426 // tmppenal = gapz_n2[j] * og_t_fg_h_dg_n1_p[i];
1427 // tmppenal = ( (1.0-gapz2[j])*(1.0-ogcp1g[i]+fgcp1g[i]-digf1[i]) ) * 0.5 * fpenalty; // mada
1428 if( (g=*prept+tmppenal) >= *mjpt )
1434 fprintf( stderr, "%5.0f ", wm );
1438 m[j] += fpenalty_ex;
1450 fg_t_og_h_dg_n2_p_pt++;
1451 og_t_fg_h_dg_n2_p_pt++;
1459 lastverticalw[i] = currentw[lgth2-1];
1462 // fprintf( stderr, "wm = %f\n", wm );
1467 for( j=1; j<lgth2+1; j++ )
1468 currentw[j] -= offset * ( lgth2 - j ) / 2.0;
1469 for( i=1; i<lgth1+1; i++ )
1470 lastverticalw[i] -= offset * ( lgth1 - i / 2.0);
1475 fprintf( stderr, "\n" );
1476 for( i=0; i<icyc; i++ ) fprintf( stderr,"%s\n", seq1[i] );
1477 fprintf( stderr, "#####\n" );
1478 for( j=0; j<jcyc; j++ ) fprintf( stderr,"%s\n", seq2[j] );
1479 fprintf( stderr, "====>" );
1480 for( i=0; i<icyc; i++ ) strcpy( mseq1[i], seq1[i] );
1481 for( j=0; j<jcyc; j++ ) strcpy( mseq2[j], seq2[j] );
1485 Atracking_localhom( impmatch, currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
1488 Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
1490 // fprintf( stderr, "### impmatch = %f\n", *impmatch );
1492 resultlen = strlen( mseq1[0] );
1493 if( alloclen < resultlen || resultlen > N )
1495 fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
1496 ErrorExit( "LENGTH OVER!\n" );
1500 for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
1501 for( j=0; j<jcyc; j++ ) strcpy( seq2[j], mseq2[j] );
1503 fprintf( stderr, "\n" );
1504 for( i=0; i<icyc; i++ ) fprintf( stderr, "%s\n", mseq1[i] );
1505 fprintf( stderr, "#####\n" );
1506 for( j=0; j<jcyc; j++ ) fprintf( stderr, "%s\n", mseq2[j] );
1509 // fprintf( stderr, "wm = %f\n", wm );
1515 float Q__align_gapmap( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *sgap1, char *sgap2, char *egap1, char *egap2, int *gapmap1, int *gapmap2 )
1516 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
1520 int lasti, lastj; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
1523 float wm = 0.0; /* int ?????? */
1525 float *currentw, *previousw;
1526 // float fpenalty = (float)penalty;
1528 float fpenalty_ex = (float)penalty_ex;
1529 fprintf( stderr, "fpenalty_ex = %f\n", fpenalty_ex );
1534 float *mjpt, *prept, *curpt;
1537 static TLS float mi, *m;
1538 static TLS int **ijp;
1539 static TLS int mpi, *mp;
1540 static TLS float *w1, *w2;
1541 static TLS float *match;
1542 static TLS float *initverticalw; /* kufuu sureba iranai */
1543 static TLS float *lastverticalw; /* kufuu sureba iranai */
1544 static TLS char **mseq1;
1545 static TLS char **mseq2;
1546 static TLS char **mseq;
1547 static TLS float *digf1;
1548 static TLS float *digf2;
1549 static TLS float *diaf1;
1550 static TLS float *diaf2;
1551 static TLS float *gapz1;
1552 static TLS float *gapz2;
1553 static TLS float *gapf1;
1554 static TLS float *gapf2;
1555 static TLS float *ogcp1g;
1556 static TLS float *ogcp2g;
1557 static TLS float *fgcp1g;
1558 static TLS float *fgcp2g;
1559 static TLS float *og_h_dg_n1_p;
1560 static TLS float *og_h_dg_n2_p;
1561 static TLS float *fg_h_dg_n1_p;
1562 static TLS float *fg_h_dg_n2_p;
1563 static TLS float *og_t_fg_h_dg_n1_p;
1564 static TLS float *og_t_fg_h_dg_n2_p;
1565 static TLS float *fg_t_og_h_dg_n1_p;
1566 static TLS float *fg_t_og_h_dg_n2_p;
1567 static TLS float *gapz_n1;
1568 static TLS float *gapz_n2;
1569 static TLS float **cpmx1;
1570 static TLS float **cpmx2;
1571 static TLS int **intwork;
1572 static TLS float **floatwork;
1573 static TLS int orlgth1 = 0, orlgth2 = 0;
1575 float *fg_t_og_h_dg_n2_p_pt;
1576 float *og_t_fg_h_dg_n2_p_pt;
1577 float *og_h_dg_n2_p_pt;
1578 float *fg_h_dg_n2_p_pt;
1583 float fg_t_og_h_dg_n1_p_va;
1584 float og_t_fg_h_dg_n1_p_va;
1585 float og_h_dg_n1_p_va;
1586 float fg_h_dg_n1_p_va;
1592 float fpenalty = (float)penalty;
1595 fprintf( stderr, "#### seq1[0] = %s\n", seq1[0] );
1596 fprintf( stderr, "#### seq2[0] = %s\n", seq2[0] );
1603 mseq1 = AllocateCharMtx( njob, 0 );
1604 mseq2 = AllocateCharMtx( njob, 0 );
1608 lgth1 = strlen( seq1[0] );
1609 lgth2 = strlen( seq2[0] );
1611 if( lgth1 == 0 || lgth2 == 0 )
1613 fprintf( stderr, "WARNING (Aalignmm): lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
1617 if( lgth1 > orlgth1 || lgth2 > orlgth2 )
1621 if( orlgth1 > 0 && orlgth2 > 0 )
1625 FreeFloatVec( match );
1626 FreeFloatVec( initverticalw );
1627 FreeFloatVec( lastverticalw );
1632 FreeCharMtx( mseq );
1634 FreeFloatVec( digf1 );
1635 FreeFloatVec( digf2 );
1636 FreeFloatVec( diaf1 );
1637 FreeFloatVec( diaf2 );
1638 FreeFloatVec( gapz1 );
1639 FreeFloatVec( gapz2 );
1640 FreeFloatVec( gapf1 );
1641 FreeFloatVec( gapf2 );
1642 FreeFloatVec( ogcp1g );
1643 FreeFloatVec( ogcp2g );
1644 FreeFloatVec( fgcp1g );
1645 FreeFloatVec( fgcp2g );
1646 FreeFloatVec( og_h_dg_n1_p );
1647 FreeFloatVec( og_h_dg_n2_p );
1648 FreeFloatVec( fg_h_dg_n1_p );
1649 FreeFloatVec( fg_h_dg_n2_p );
1650 FreeFloatVec( og_t_fg_h_dg_n1_p );
1651 FreeFloatVec( og_t_fg_h_dg_n2_p );
1652 FreeFloatVec( fg_t_og_h_dg_n1_p );
1653 FreeFloatVec( fg_t_og_h_dg_n2_p );
1654 FreeFloatVec( gapz_n1 );
1655 FreeFloatVec( gapz_n2 );
1657 FreeFloatMtx( cpmx1 );
1658 FreeFloatMtx( cpmx2 );
1660 FreeFloatMtx( floatwork );
1661 FreeIntMtx( intwork );
1664 ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
1665 ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
1668 fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
1671 w1 = AllocateFloatVec( ll2+2 );
1672 w2 = AllocateFloatVec( ll2+2 );
1673 match = AllocateFloatVec( ll2+2 );
1675 initverticalw = AllocateFloatVec( ll1+2 );
1676 lastverticalw = AllocateFloatVec( ll1+2 );
1678 m = AllocateFloatVec( ll2+2 );
1679 mp = AllocateIntVec( ll2+2 );
1681 mseq = AllocateCharMtx( njob, ll1+ll2 );
1683 digf1 = AllocateFloatVec( ll1+2 );
1684 digf2 = AllocateFloatVec( ll2+2 );
1685 diaf1 = AllocateFloatVec( ll1+2 );
1686 diaf2 = AllocateFloatVec( ll2+2 );
1687 gapz1 = AllocateFloatVec( ll1+2 );
1688 gapz2 = AllocateFloatVec( ll2+2 );
1689 gapf1 = AllocateFloatVec( ll1+2 );
1690 gapf2 = AllocateFloatVec( ll2+2 );
1691 ogcp1g = AllocateFloatVec( ll1+2 );
1692 ogcp2g = AllocateFloatVec( ll2+2 );
1693 fgcp1g = AllocateFloatVec( ll1+2 );
1694 fgcp2g = AllocateFloatVec( ll2+2 );
1695 og_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
1696 og_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
1697 fg_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
1698 fg_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
1699 og_t_fg_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
1700 og_t_fg_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
1701 fg_t_og_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
1702 fg_t_og_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
1703 gapz_n1 = AllocateFloatVec( ll1+2 );
1704 gapz_n2 = AllocateFloatVec( ll2+2 );
1706 cpmx1 = AllocateFloatMtx( 26, ll1+2 );
1707 cpmx2 = AllocateFloatMtx( 26, ll2+2 );
1710 floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 );
1711 intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 );
1713 floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 );
1714 intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 );
1718 fprintf( stderr, "succeeded\n" );
1721 orlgth1 = ll1 - 100;
1722 orlgth2 = ll2 - 100;
1726 for( i=0; i<icyc; i++ )
1731 for( j=0; j<jcyc; j++ )
1733 mseq2[j] = mseq[icyc+j];
1738 if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
1742 if( commonAlloc1 && commonAlloc2 )
1744 FreeIntMtx( commonIP );
1747 ll1 = MAX( orlgth1, commonAlloc1 );
1748 ll2 = MAX( orlgth2, commonAlloc2 );
1751 fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
1754 commonIP = AllocateIntMtx( ll1+10, ll2+10 );
1757 fprintf( stderr, "succeeded\n\n" );
1768 for( i=0; i<icyc; i++ )
1770 fprintf( stderr, "## totaleff = %f\n", t );
1774 cpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
1775 cpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
1779 new_OpeningGapCount_zure( ogcp1g, icyc, seq1, eff1, lgth1, sgap1, egap1 );
1780 new_OpeningGapCount_zure( ogcp2g, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
1781 new_FinalGapCount_zure( fgcp1g, icyc, seq1, eff1, lgth1, sgap1, egap1 );
1782 new_FinalGapCount_zure( fgcp2g, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
1783 getdigapfreq_part( digf1, icyc, seq1, eff1, lgth1, sgap1, egap1 );
1784 getdigapfreq_part( digf2, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
1785 getdiaminofreq_part( diaf1, icyc, seq1, eff1, lgth1, sgap1, egap1 );
1786 getdiaminofreq_part( diaf2, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
1787 getgapfreq( gapf1, icyc, seq1, eff1, lgth1 );
1788 getgapfreq( gapf2, jcyc, seq2, eff2, lgth2 );
1789 getgapfreq_zure_part( gapz1, icyc, seq1, eff1, lgth1, sgap1 );
1790 getgapfreq_zure_part( gapz2, jcyc, seq2, eff2, lgth2, sgap1 );
1794 st_OpeningGapCount( ogcp1g, icyc, seq1, eff1, lgth1 );
1795 st_OpeningGapCount( ogcp2g, jcyc, seq2, eff2, lgth2 );
1796 st_FinalGapCount_zure( fgcp1g, icyc, seq1, eff1, lgth1 );
1797 st_FinalGapCount_zure( fgcp2g, jcyc, seq2, eff2, lgth2 );
1798 getdigapfreq_st( digf1, icyc, seq1, eff1, lgth1 );
1799 getdigapfreq_st( digf2, jcyc, seq2, eff2, lgth2 );
1800 getdiaminofreq_x( diaf1, icyc, seq1, eff1, lgth1 );
1801 getdiaminofreq_x( diaf2, jcyc, seq2, eff2, lgth2 );
1802 getgapfreq( gapf1, icyc, seq1, eff1, lgth1 );
1803 getgapfreq( gapf2, jcyc, seq2, eff2, lgth2 );
1804 getgapfreq_zure( gapz1, icyc, seq1, eff1, lgth1 );
1805 getgapfreq_zure( gapz2, jcyc, seq2, eff2, lgth2 );
1810 for( i=0; i<lastj; i++ )
1812 og_h_dg_n2_p[i] = ( 1.0-ogcp2g[i]-digf2[i] ) * fpenalty * 0.5;
1813 fg_h_dg_n2_p[i] = ( 1.0-fgcp2g[i]-digf2[i] ) * fpenalty * 0.5;
1814 og_t_fg_h_dg_n2_p[i] = (1.0-ogcp2g[i]+fgcp2g[i]-digf2[i]) * 0.5 * fpenalty;
1815 fg_t_og_h_dg_n2_p[i] = (1.0-fgcp2g[i]+ogcp2g[i]-digf2[i]) * 0.5 * fpenalty;
1816 gapz_n2[i] = (1.0-gapz2[i]);
1819 for( i=0; i<lastj; i++ )
1821 og_h_dg_n1_p[i] = ( 1.0-ogcp1g[i]-digf1[i] ) * fpenalty * 0.5;
1822 fg_h_dg_n1_p[i] = ( 1.0-fgcp1g[i]-digf1[i] ) * fpenalty * 0.5;
1823 og_t_fg_h_dg_n1_p[i] = (1.0-ogcp1g[i]+fgcp1g[i]-digf1[i]) * 0.5 * fpenalty;
1824 fg_t_og_h_dg_n1_p[i] = (1.0-fgcp1g[i]+ogcp1g[i]-digf1[i]) * 0.5 * fpenalty;
1825 gapz_n1[i] = (1.0-gapz1[i]);
1831 for( i=0; i<lgth1; i++ )
1832 fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
1838 if( RNAscoremtx != 'r' )
1839 match_calc( initverticalw, cpmx2, cpmx1, 0, lgth1, floatwork, intwork, 1 );
1841 clearvec( initverticalw, lgth1 );
1843 imp_match_out_vead_tateQ_gapmap( initverticalw, gapmap2[0], lgth1, gapmap1 ); // 060306
1845 if( RNAscoremtx != 'r' )
1846 match_calc( currentw, cpmx1, cpmx2, 0, lgth2, floatwork, intwork, 1 );
1848 clearvec( currentw, lgth2 );
1850 imp_match_out_veadQ_gapmap( currentw, gapmap1[0], lgth2, gapmap2 ); // 060306
1854 #if 0 // -> tbfast.c
1856 imp_match_calc( currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 );
1867 g += ogcp1g[0] * og_h_dg_n2_p[0];
1868 // g += ogcp1g[0] * ( 1.0-ogcp2g[0]-digf2[0] ) * fpenalty * 0.5;
1869 // if( g ) fprintf( stderr, "init-match penal1=%f, %c-%c\n", g, seq1[0][0], seq2[0][0] );
1871 g += ogcp2g[0] * og_h_dg_n1_p[0];
1872 // g += ogcp2g[0] * ( 1.0-ogcp1g[0]-digf1[0] ) * fpenalty * 0.5;
1873 // if( g ) fprintf( stderr, "init-match penal2=%f, %c-%c\n", g, seq1[0][0], seq2[0][0] );
1875 g += fgcp1g[0] * fg_h_dg_n2_p[0];
1876 // g += fgcp1g[0] * ( 1.0-fgcp2g[0]-digf2[0] ) * fpenalty * 0.5;
1877 // if( g ) fprintf( stderr, "match penal1=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
1879 g += fgcp2g[0] * fg_h_dg_n1_p[0];
1880 // g += fgcp2g[0] * ( 1.0-fgcp1g[0]-digf1[0] ) * fpenalty * 0.5;
1881 // if( g ) fprintf( stderr, "match penal2=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
1884 initverticalw[0] += g;
1887 for( i=1; i<lgth1+1; i++ )
1889 tmppenal = gapz_n2[0]*og_t_fg_h_dg_n1_p[0];
1890 // tmppenal = ( (1.0-gapz2[0])*(1.0-ogcp1g[0]+fgcp1g[0]-digf1[0]) ) * 0.5 * fpenalty; // mada
1891 initverticalw[i] += tmppenal;
1893 tmppenal = gapz_n2[1]*fg_t_og_h_dg_n1_p[i];
1894 // tmppenal = ( (1.0-gapz2[1])*(1.0-fgcp1g[i]+ogcp1g[i]-digf1[i]) ) * 0.5 * fpenalty; // mada
1895 initverticalw[i] += tmppenal;
1898 for( j=1; j<lgth2+1; j++ )
1900 tmppenal = gapz_n1[0]*og_t_fg_h_dg_n2_p[0];
1901 // tmppenal = ( (1.0-gapz1[0])*(1.0-ogcp2g[0]+fgcp2g[0]-digf2[0]) ) * 0.5 * fpenalty; // mada
1902 currentw[j] += tmppenal;
1904 tmppenal = gapz_n1[1]*fg_t_og_h_dg_n2_p[j];
1905 // tmppenal = ( (1.0-gapz1[1])*(1.0-fgcp2g[j]+ogcp2g[j]-digf2[j]) ) * 0.5 * fpenalty; // mada
1906 currentw[j] += tmppenal;
1912 for( j=1; j<lgth2+1; j++ )
1913 currentw[j] -= offset * j / 2.0;
1914 for( i=1; i<lgth1+1; i++ )
1915 initverticalw[i] -= offset * i / 2.0;
1919 m[0] = 0.0; // iranai
1920 for( j=1; j<lgth2+1; ++j )
1923 m[j] = currentw[j-1] + 10000 * fpenalty; //iinoka?
1926 lastverticalw[0] = 0.0; // Falign kara yobaretatoki kounarukanousei ari
1928 lastverticalw[0] = currentw[lgth2-1];
1930 if( outgap ) lasti = lgth1+1; else lasti = lgth1;
1933 fprintf( stderr, "currentw = \n" );
1934 for( i=0; i<lgth1+1; i++ )
1936 fprintf( stderr, "%5.2f ", currentw[i] );
1938 fprintf( stderr, "\n" );
1939 fprintf( stderr, "initverticalw = \n" );
1940 for( i=0; i<lgth2+1; i++ )
1942 fprintf( stderr, "%5.2f ", initverticalw[i] );
1944 fprintf( stderr, "\n" );
1945 fprintf( stderr, "fcgp\n" );
1946 for( i=0; i<lgth1; i++ )
1947 fprintf( stderr, "fgcp1[%d]=%f\n", i, ogcp1[i] );
1948 for( i=0; i<lgth2; i++ )
1949 fprintf( stderr, "fgcp2[%d]=%f\n", i, ogcp2[i] );
1952 for( i=1; i<lasti; i++ )
1955 previousw = currentw;
1958 previousw[0] = initverticalw[i-1];
1960 if( RNAscoremtx != 'r' )
1961 match_calc( currentw, cpmx1, cpmx2, i, lgth2, floatwork, intwork, 0 );
1963 clearvec( currentw, lgth2 );
1965 fprintf( stderr, "\n" );
1966 fprintf( stderr, "i=%d\n", i );
1967 fprintf( stderr, "currentw = \n" );
1968 for( j=0; j<lgth2; j++ )
1970 fprintf( stderr, "%5.2f ", currentw[j] );
1972 fprintf( stderr, "\n" );
1976 // fprintf( stderr, "Calling imp_match_calc (o) lgth = %d, i = %d\n", lgth1, i );
1978 imp_match_out_veadQ( currentw, i, lgth2 );
1980 imp_match_out_veadQ_gapmap( currentw, gapmap1[i], lgth2, gapmap2 );
1984 fprintf( stderr, "\n" );
1985 fprintf( stderr, "i=%d\n", i );
1986 fprintf( stderr, "currentw = \n" );
1987 for( j=0; j<lgth2; j++ )
1989 fprintf( stderr, "%5.2f ", currentw[j] );
1991 fprintf( stderr, "\n" );
1993 currentw[0] = initverticalw[i];
1996 mi = previousw[0] + 10000 * fpenalty;
2001 curpt = currentw + 1;
2003 fg_t_og_h_dg_n2_p_pt = fg_t_og_h_dg_n2_p + 1;
2004 og_t_fg_h_dg_n2_p_pt = og_t_fg_h_dg_n2_p + 1;
2005 og_h_dg_n2_p_pt = og_h_dg_n2_p + 1;
2006 fg_h_dg_n2_p_pt = fg_h_dg_n2_p + 1;
2007 gapz_n2_pt0 = gapz_n2 + 1;
2008 gapz_n2_pt1 = gapz_n2 + 2;
2009 fgcp2pt = fgcp2g + 1;
2010 ogcp2pt = ogcp2g + 1;
2012 fg_t_og_h_dg_n1_p_va = fg_t_og_h_dg_n1_p[i];
2013 og_t_fg_h_dg_n1_p_va = og_t_fg_h_dg_n1_p[i];
2014 og_h_dg_n1_p_va = og_h_dg_n1_p[i];
2015 fg_h_dg_n1_p_va = fg_h_dg_n1_p[i];
2016 gapz_n1_va0 = gapz_n1[i];
2017 gapz_n1_va1 = gapz_n1[i+1];
2018 fgcp1va = fgcp1g[i];
2019 ogcp1va = ogcp1g[i];
2022 for( j=1; j<lastj; j++ )
2026 g = ogcp1va * *og_h_dg_n2_p_pt;
2027 // g = ogcp1g[i] * og_h_dg_n2_p[j];
2028 // g = ogcp1g[i] * ( 1.0-ogcp2g[j]-digf2[j] ) * fpenalty * 0.5;
2029 // if( g && i==j ) fprintf( stderr, "match penal1=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
2032 g = *ogcp2pt * og_h_dg_n1_p_va;
2033 // g = ogcp2g[j] * og_h_dg_n1_p[i];
2034 // g = ogcp2g[j] * ( 1.0-ogcp1g[i]-digf1[i] ) * fpenalty * 0.5;
2035 // if( g && i==j ) fprintf( stderr, "match penal2=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
2038 g = fgcp1va * *fg_h_dg_n2_p_pt;
2039 // g = fgcp1g[i] * fg_h_dg_n2_p[j];
2040 // g = fgcp1g[i] * ( 1.0-fgcp2g[j]-digf2[j] ) * fpenalty * 0.5;
2041 // if( g && i==j ) fprintf( stderr, "match penal3=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
2044 g = *fgcp2pt * fg_h_dg_n1_p_va;
2045 // g = fgcp2g[j] * fg_h_dg_n1_p[i];
2046 // g = fgcp2g[j] * ( 1.0-fgcp1g[i]-digf1[i] ) * fpenalty * 0.5;
2047 // if( g && i==j ) fprintf( stderr, "match penal4=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
2053 fprintf( stderr, "%5.0f->", wm );
2056 fprintf( stderr, "%5.0f?", g );
2058 tmppenal = gapz_n1_va1 * *fg_t_og_h_dg_n2_p_pt;
2059 // tmppenal = gapz_n1[i+1] * fg_t_og_h_dg_n2_p[j];
2060 // tmppenal = ( (1.0-gapz1[i+1])*(1.0-fgcp2g[j]+ogcp2g[j]-digf2[j]) ) * 0.5 * fpenalty; // mada
2061 if( (g=mi+tmppenal) > wm )
2063 // fprintf( stderr, "jump i start=%f (j=%d, fgcp2g[j]=%f, digf2[j]=%f, diaf2[j]=%f), %c-%c\n", g-mi, j, fgcp2g[j], digf2[j], diaf2[j], seq1[0][i], seq2[0][j] );
2065 *ijppt = -( j - mpi );
2067 tmppenal = gapz_n1_va0 * *og_t_fg_h_dg_n2_p_pt;
2068 // tmppenal = gapz_n1[i] * og_t_fg_h_dg_n2_p[j];
2069 // tmppenal = ( (1.0-gapz1[i])*(1.0-ogcp2g[j]+fgcp2g[j]-digf2[j]) ) * 0.5 * fpenalty; // mada
2070 if( (g=*prept+tmppenal) >= mi )
2072 // fprintf( stderr, "jump i end=%f, %c-%c\n", g-*prept, seq1[0][i-1], seq2[0][j-1] );
2082 fprintf( stderr, "%5.0f?", g );
2084 tmppenal = *gapz_n2_pt1 * fg_t_og_h_dg_n1_p_va;
2085 // tmppenal = gapz_n2[j+1] * fg_t_og_h_dg_n1_p[i];
2086 // tmppenal = ( (1.0-gapz2[j+1])*(1.0-fgcp1g[i]+ogcp1g[i]-digf1[i]) ) * 0.5 * fpenalty; // mada
2087 if( (g=*mjpt+tmppenal) > wm )
2090 *ijppt = +( i - *mpjpt );
2092 tmppenal = *gapz_n2_pt0 * og_t_fg_h_dg_n1_p_va;
2093 // tmppenal = gapz_n2[j] * og_t_fg_h_dg_n1_p[i];
2094 // tmppenal = ( (1.0-gapz2[j])*(1.0-ogcp1g[i]+fgcp1g[i]-digf1[i]) ) * 0.5 * fpenalty; // mada
2095 if( (g=*prept+tmppenal) >= *mjpt )
2101 fprintf( stderr, "%5.0f ", wm );
2105 m[j] += fpenalty_ex;
2117 fg_t_og_h_dg_n2_p_pt++;
2118 og_t_fg_h_dg_n2_p_pt++;
2126 lastverticalw[i] = currentw[lgth2-1];
2129 // fprintf( stderr, "wm = %f\n", wm );
2134 for( j=1; j<lgth2+1; j++ )
2135 currentw[j] -= offset * ( lgth2 - j ) / 2.0;
2136 for( i=1; i<lgth1+1; i++ )
2137 lastverticalw[i] -= offset * ( lgth1 - i / 2.0);
2142 fprintf( stderr, "\n" );
2143 for( i=0; i<icyc; i++ ) fprintf( stderr,"%s\n", seq1[i] );
2144 fprintf( stderr, "#####\n" );
2145 for( j=0; j<jcyc; j++ ) fprintf( stderr,"%s\n", seq2[j] );
2146 fprintf( stderr, "====>" );
2147 for( i=0; i<icyc; i++ ) strcpy( mseq1[i], seq1[i] );
2148 for( j=0; j<jcyc; j++ ) strcpy( mseq2[j], seq2[j] );
2152 Atracking_localhom_gapmap( impmatch, currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc, gapmap1, gapmap2 );
2155 Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
2157 // fprintf( stderr, "### impmatch = %f\n", *impmatch );
2159 resultlen = strlen( mseq1[0] );
2160 if( alloclen < resultlen || resultlen > N )
2162 fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
2163 ErrorExit( "LENGTH OVER!\n" );
2167 for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
2168 for( j=0; j<jcyc; j++ ) strcpy( seq2[j], mseq2[j] );
2170 fprintf( stderr, "\n" );
2171 for( i=0; i<icyc; i++ ) fprintf( stderr, "%s\n", mseq1[i] );
2172 fprintf( stderr, "#####\n" );
2173 for( j=0; j<jcyc; j++ ) fprintf( stderr, "%s\n", mseq2[j] );
2176 // fprintf( stderr, "wm = %f\n", wm );