8 #define USE_PENALTY_EX 0
9 #define FASTMATCHCALC 1
12 static int impalloclen = 0;
13 static float **impmtx = NULL;
14 float part_imp_match_out_scQ( int i1, int j1 )
16 // fprintf( stderr, "impalloclen = %d\n", impalloclen );
17 // fprintf( stderr, "i1,j1=%d,%d -> impmtx=%f\n", i1, j1, impmtx[i1][j1] );
18 return( impmtx[i1][j1] );
20 if( i1 == l1 || j1 == l2 ) return( 0.0 );
21 return( impmtx[i1+start1][j1+start2] );
24 static void part_imp_match_out_vead_gapmapQ( float *imp, int i1, int lgth2, int start2, int *gapmap2 )
28 int *gapmappt = gapmap2;
30 *pt++ += impmtx[i1][start2+*gapmappt++];
33 for( j=0; j<lgth2; j++ )
35 imp[j] += impmtx[i1][start2+gapmap2[j]];
40 static void part_imp_match_out_vead_tate_gapmapQ( float *imp, int j1, int lgth1, int start1, int *gapmap1 )
44 int *gapmappt = gapmap1;
46 *pt++ = impmtx[start1+*gapmappt++][j1];
49 for( i=0; i<lgth1; i++ )
51 imp[i] += impmtx[start1+gapmap1[i]][j1];
56 void part_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 )
58 int i, j, k1, k2, tmpint, start1, start2, end1, end2;
63 if( impalloclen <= lgth1 + 2 || impalloclen <= lgth2 + 2 )
65 if( impmtx ) FreeFloatMtx( impmtx );
66 impalloclen = MAX( lgth1, lgth2 ) + 2;
67 impmtx = AllocateFloatMtx( impalloclen+100, impalloclen+100 );
72 fprintf( stderr, "eff1 in _init_strict = \n" );
73 for( i=0; i<clus1; i++ )
74 fprintf( stderr, "eff1[] = %f\n", eff1[i] );
75 for( i=0; i<clus2; i++ )
76 fprintf( stderr, "eff2[] = %f\n", eff2[i] );
79 for( i=0; i<lgth1; i++ ) for( j=0; j<lgth2; j++ )
81 effijx = 1.0 * fastathreshold;
82 for( i=0; i<clus1; i++ )
84 for( j=0; j<clus2; j++ )
86 effij = eff1[i] * eff2[j] * effijx;
87 tmpptr = localhom[i][j];
90 // fprintf( stderr, "start1 = %d\n", tmpptr->start1 );
91 // fprintf( stderr, "end1 = %d\n", tmpptr->end1 );
92 // fprintf( stderr, "i = %d, seq1 = \n%s\n", i, seq1[i] );
93 // fprintf( stderr, "j = %d, seq2 = \n%s\n", j, seq2[j] );
98 if( *pt++ != '-' ) tmpint++;
99 if( tmpint == tmpptr->start1 ) break;
101 start1 = (int)( pt - seq1[i] ) - 1;
103 if( tmpptr->start1 == tmpptr->end1 ) end1 = start1;
109 if( tmpint == tmpptr->end1 ) break;
110 if( *pt++ != '-' ) tmpint++;
112 end1 = (int)( pt - seq1[i] ) - 1;
116 // fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] );
117 if( *pt++ != '-' ) tmpint++;
118 if( tmpint == tmpptr->end1 ) break;
120 end1 = (int)( pt - seq1[i] ) - 1;
128 if( *pt++ != '-' ) tmpint++;
129 if( tmpint == tmpptr->start2 ) break;
131 start2 = (int)( pt - seq2[j] ) - 1;
132 if( tmpptr->start2 == tmpptr->end2 ) end2 = start2;
138 if( tmpint == tmpptr->end2 ) break;
139 if( *pt++ != '-' ) tmpint++;
141 end2 = (int)( pt - seq2[j] ) - 1;
145 if( *pt++ != '-' ) tmpint++;
146 if( tmpint == tmpptr->end2 ) break;
148 end2 = (int)( pt - seq2[j] ) - 1;
151 // 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] );
152 // fprintf( stderr, "step 0\n" );
153 if( end1 - start1 != end2 - start2 )
155 // fprintf( stderr, "CHUUI!!, start1 = %d, end1 = %d, start2 = %d, end2 = %d\n", start1, end1, start2, end2 );
158 k1 = start1; k2 = start2;
161 while( *pt1 && *pt2 )
163 if( *pt1 != '-' && *pt2 != '-' )
165 // ½Å¤ß¤òÆó½Å¤Ë¤«¤±¤Ê¤¤¤è¤¦¤ËÃðդ·¤Æ²¼¤µ¤¤¡£
166 // impmtx[k1][k2] += tmpptr->wimportance * fastathreshold;
167 // impmtx[k1][k2] += tmpptr->importance * effij;
168 impmtx[k1][k2] += tmpptr->fimportance * effij;
169 // fprintf( stderr, "k1=%d, k2=%d, impalloclen=%d\n", k1, k2, impalloclen );
170 // fprintf( stderr, "mark, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
174 else if( *pt1 != '-' && *pt2 == '-' )
176 // fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
179 else if( *pt1 == '-' && *pt2 != '-' )
181 // fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
184 else if( *pt1 == '-' && *pt2 == '-' )
186 // fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
190 if( k1 > end1 || k2 > end2 ) break;
192 tmpptr = tmpptr->next;
197 fprintf( stderr, "impmtx = \n" );
198 for( k2=0; k2<lgth2; k2++ )
199 fprintf( stderr, "%6.3f ", (double)k2 );
200 fprintf( stderr, "\n" );
201 for( k1=0; k1<lgth1; k1++ )
203 fprintf( stderr, "%d", k1 );
204 for( k2=0; k2<lgth2; k2++ )
205 fprintf( stderr, "%2.1f ", impmtx[k1][k2] );
206 fprintf( stderr, "\n" );
213 void part_imp_rnaQ( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***grouprna1, RNApair ***grouprna2, int *gapmap1, int *gapmap2, RNApair *additionalpair )
215 foldrna( nseq1, nseq2, seq1, seq2, eff1, eff2, grouprna1, grouprna2, impmtx, gapmap1, gapmap2, additionalpair );
219 void part_imp_match_initQ( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom )
221 int dif, i, j, k1, k2, tmpint, start1, start2, end1, end2;
222 static int impalloclen = 0;
224 static char *nocount1 = NULL;
225 static char *nocount2 = NULL;
227 if( impalloclen < lgth1 || impalloclen < lgth2 )
229 if( impmtx ) FreeFloatMtx( impmtx );
230 if( nocount1 ) free( nocount1 );
231 if( nocount2 ) free( nocount2 );
232 impalloclen = MAX( lgth1, lgth2 ) + 2;
233 impmtx = AllocateFloatMtx( impalloclen, impalloclen );
234 nocount1 = AllocateCharVec( impalloclen );
235 nocount2 = AllocateCharVec( impalloclen );
239 for( i=0; i<lgth1; i++ )
241 for( j=0; j<clus1; j++ )
242 if( seq1[j][i] == '-' ) break;
243 if( j != clus1 ) nocount1[i] = 1;
244 else nocount1[i] = 0;
246 for( i=0; i<lgth2; i++ )
248 for( j=0; j<clus2; j++ )
249 if( seq2[j][i] == '-' ) break;
250 if( j != clus2 ) nocount2[i] = 1;
251 else nocount2[i] = 0;
255 fprintf( stderr, "nocount2 =\n" );
256 for( i = 0; i<impalloclen; i++ )
258 fprintf( stderr, "nocount2[%d] = %d (%c)\n", i, nocount2[i], seq2[0][i] );
262 for( i=0; i<lgth1; i++ ) for( j=0; j<lgth2; j++ )
264 for( i=0; i<clus1; i++ )
266 fprintf( stderr, "i = %d, seq1 = %s\n", i, seq1[i] );
267 for( j=0; j<clus2; j++ )
269 fprintf( stderr, "start1 = %d\n", localhom[i][j]->start1 );
270 fprintf( stderr, "end1 = %d\n", localhom[i][j]->end1 );
271 fprintf( stderr, "j = %d, seq2 = %s\n", j, seq2[j] );
276 if( *pt++ != '-' ) tmpint++;
277 if( tmpint == localhom[i][j]->start1 ) break;
279 start1 = pt - seq1[i] - 1;
283 // fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, localhom[i][j].end1, pt-seq1[i] );
284 if( *pt++ != '-' ) tmpint++;
285 if( tmpint == localhom[i][j]->end1 ) break;
287 end1 = pt - seq1[i] - 1;
293 if( *pt++ != '-' ) tmpint++;
294 if( tmpint == localhom[i][j]->start2 ) break;
296 start2 = pt - seq2[j] - 1;
299 if( *pt++ != '-' ) tmpint++;
300 if( tmpint == localhom[i][j]->end2 ) break;
302 end2 = pt - seq2[j] - 1;
303 // fprintf( stderr, "start1 = %d, end1 = %d, start2 = %d, end2 = %d\n", start1, end1, start2, end2 );
306 fprintf( stderr, "step 0\n" );
307 while( k1 <= end1 && k2 <= end2 )
310 if( !nocount1[k1] && !nocount2[k2] )
311 impmtx[k1][k2] += localhom[i][j].wimportance * eff1[i] * eff2[j];
314 if( !nocount1[k1] && !nocount2[k2] )
315 impmtx[k1][k2] += localhom[i][j]->wimportance * eff1[i] * eff2[j];
320 dif = ( end1 - start1 ) - ( end2 - start2 );
321 fprintf( stderr, "dif = %d\n", dif );
326 fprintf( stderr, "dif = %d\n", dif );
329 while( k1 <= end1 && k2 <= end2 )
331 if( 0 <= k2 && start2 <= k2 && !nocount1[k1] && !nocount2[k2] )
332 impmtx[k1][k2] = localhom[i][j]->wimportance * eff1[i] * eff2[j];
346 if( k1 >= 0 && k1 >= start1 && !nocount1[k1] && !nocount2[k2] )
347 impmtx[k1][k2] = localhom[i][j]->wimportance * eff1[i] * eff2[j];
356 fprintf( stderr, "impmtx = \n" );
357 for( k2=0; k2<lgth2; k2++ )
358 fprintf( stderr, "%6.3f ", (double)k2 );
359 fprintf( stderr, "\n" );
360 for( k1=0; k1<lgth1; k1++ )
362 fprintf( stderr, "%d", k1 );
363 for( k2=0; k2<lgth2; k2++ )
364 fprintf( stderr, "%6.3f ", impmtx[k1][k2] );
365 fprintf( stderr, "\n" );
371 static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
376 float **cpmxpd = floatwork;
377 int **cpmxpdn = intwork;
378 float *matchpt, *cpmxpdpt, **cpmxpdptpt;
379 int *cpmxpdnpt, **cpmxpdnptpt;
383 for( j=0; j<lgth2; j++ )
386 for( l=0; l<26; l++ )
390 cpmxpd[j][count] = cpmx2[l][j];
391 cpmxpdn[j][count] = l;
395 cpmxpdn[j][count] = -1;
400 for( l=0; l<26; l++ )
403 for( j=0; j<26; j++ )
404 // scarr[l] += n_dis[j][l] * cpmx1[j][i1];
405 scarr[l] += n_dis_consweight_multi[j][l] * cpmx1[j][i1];
408 cpmxpdnptpt = cpmxpdn;
413 cpmxpdnpt = *cpmxpdnptpt++;
414 cpmxpdpt = *cpmxpdptpt++;
415 while( *cpmxpdnpt>-1 )
416 *matchpt += scarr[*cpmxpdnpt++] * *cpmxpdpt++;
423 float **cpmxpd = floatwork;
424 int **cpmxpdn = intwork;
429 for( j=0; j<lgth2; j++ )
432 for( l=0; l<26; l++ )
436 cpmxpd[count][j] = cpmx2[l][j];
437 cpmxpdn[count][j] = l;
441 cpmxpdn[count][j] = -1;
444 for( l=0; l<26; l++ )
447 for( k=0; k<26; k++ )
448 // scarr[l] += n_dis[k][l] * cpmx1[k][i1];
449 scarr[l] += n_dis_consweight_multi[k][l] * cpmx1[k][i1];
451 for( j=0; j<lgth2; j++ )
454 for( k=0; cpmxpdn[k][j]>-1; k++ )
455 match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j];
460 static void Atracking_localhom( float *impwmpt, float *lasthorizontalw, float *lastverticalw,
461 char **seq1, char **seq2,
462 char **mseq1, char **mseq2,
463 float **cpmx1, float **cpmx2,
464 int **ijp, int icyc, int jcyc,
465 int start1, int end1, int start2, int end2,
466 int *gapmap1, int *gapmap2 )
468 int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k;
471 lgth1 = strlen( seq1[0] );
472 lgth2 = strlen( seq2[0] );
475 for( i=0; i<lgth1; i++ )
477 fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
485 wm = lastverticalw[0];
486 for( i=0; i<lgth1; i++ )
488 if( lastverticalw[i] >= wm )
490 wm = lastverticalw[i];
491 iin = i; jin = lgth2-1;
492 ijp[lgth1][lgth2] = +( lgth1 - i );
495 for( j=0; j<lgth2; j++ )
497 if( lasthorizontalw[j] >= wm )
499 wm = lasthorizontalw[j];
500 iin = lgth1-1; jin = j;
501 ijp[lgth1][lgth2] = -( lgth2 - j );
506 for( i=0; i<lgth1+1; i++ )
510 for( j=0; j<lgth2+1; j++ )
512 ijp[0][j] = -( j + 1 );
515 for( i=0; i<icyc; i++ )
517 mseq1[i] += lgth1+lgth2;
520 for( j=0; j<jcyc; j++ )
522 mseq2[j] += lgth1+lgth2;
525 iin = lgth1; jin = lgth2;
527 for( k=0; k<=lgth1+lgth2; k++ )
529 if( ijp[iin][jin] < 0 )
531 ifi = iin-1; jfi = jin+ijp[iin][jin];
533 else if( ijp[iin][jin] > 0 )
535 ifi = iin-ijp[iin][jin]; jfi = jin-1;
539 ifi = iin-1; jfi = jin-1;
544 for( i=0; i<icyc; i++ )
545 *--mseq1[i] = seq1[i][ifi+l];
546 for( j=0; j<jcyc; j++ )
553 for( i=0; i<icyc; i++ )
555 for( j=0; j<jcyc; j++ )
556 *--mseq2[j] = seq2[j][jfi+l];
559 if( iin != lgth1 && jin != lgth2 ) // ??
561 *impwmpt += part_imp_match_out_scQ( gapmap1[iin]+start1, gapmap2[jin]+start2 );
562 // fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] );
564 if( iin <= 0 || jin <= 0 ) break;
565 for( i=0; i<icyc; i++ )
566 *--mseq1[i] = seq1[i][ifi];
567 for( j=0; j<jcyc; j++ )
568 *--mseq2[j] = seq2[j][jfi];
570 iin = ifi; jin = jfi;
573 static float Atracking( float *lasthorizontalw, float *lastverticalw,
574 char **seq1, char **seq2,
575 char **mseq1, char **mseq2,
576 float **cpmx1, float **cpmx2,
577 int **ijp, int icyc, int jcyc )
579 int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, lastk;
582 lgth1 = strlen( seq1[0] );
583 lgth2 = strlen( seq2[0] );
586 for( i=0; i<lgth1; i++ )
588 fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
596 wm = lastverticalw[0];
597 for( i=0; i<lgth1; i++ )
599 if( lastverticalw[i] >= wm )
601 wm = lastverticalw[i];
602 iin = i; jin = lgth2-1;
603 ijp[lgth1][lgth2] = +( lgth1 - i );
606 for( j=0; j<lgth2; j++ )
608 if( lasthorizontalw[j] >= wm )
610 wm = lasthorizontalw[j];
611 iin = lgth1-1; jin = j;
612 ijp[lgth1][lgth2] = -( lgth2 - j );
617 for( i=0; i<lgth1+1; i++ )
621 for( j=0; j<lgth2+1; j++ )
623 ijp[0][j] = -( j + 1 );
626 for( i=0; i<icyc; i++ )
628 mseq1[i] += lgth1+lgth2;
631 for( j=0; j<jcyc; j++ )
633 mseq2[j] += lgth1+lgth2;
636 iin = lgth1; jin = lgth2;
638 for( k=0; k<=lastk; k++ )
640 if( ijp[iin][jin] < 0 )
642 ifi = iin-1; jfi = jin+ijp[iin][jin];
644 else if( ijp[iin][jin] > 0 )
646 ifi = iin-ijp[iin][jin]; jfi = jin-1;
650 ifi = iin-1; jfi = jin-1;
655 for( i=0; i<icyc; i++ )
656 *--mseq1[i] = seq1[i][ifi+l];
657 for( j=0; j<jcyc; j++ )
664 for( i=0; i<icyc; i++ )
666 for( j=0; j<jcyc; j++ )
667 *--mseq2[j] = seq2[j][jfi+l];
670 if( iin <= 0 || jin <= 0 ) break;
671 for( i=0; i<icyc; i++ )
672 *--mseq1[i] = seq1[i][ifi];
673 for( j=0; j<jcyc; j++ )
674 *--mseq2[j] = seq2[j][jfi];
676 iin = ifi; jin = jfi;
681 float partQ__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, int start1, int end1, int start2, int end2, int *gapmap1, int *gapmap2, char *sgap1, char *sgap2, char *egap1, char *egap2 )
682 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
686 int lasti, lastj; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
689 float wm = 0.0; /* int ?????? */
691 float *currentw, *previousw;
695 float *mjpt, *prept, *curpt;
701 static float *w1, *w2;
703 static float *initverticalw; /* kufuu sureba iranai */
704 static float *lastverticalw; /* kufuu sureba iranai */
716 static float *ogcp1g;
717 static float *ogcp2g;
718 static float *fgcp1g;
719 static float *fgcp2g;
720 static float *og_h_dg_n1_p;
721 static float *og_h_dg_n2_p;
722 static float *fg_h_dg_n1_p;
723 static float *fg_h_dg_n2_p;
724 static float *og_t_fg_h_dg_n1_p;
725 static float *og_t_fg_h_dg_n2_p;
726 static float *fg_t_og_h_dg_n1_p;
727 static float *fg_t_og_h_dg_n2_p;
728 static float *gapz_n1;
729 static float *gapz_n2;
730 static float **cpmx1;
731 static float **cpmx2;
732 static int **intwork;
733 static float **floatwork;
734 static int orlgth1 = 0, orlgth2 = 0;
735 float fpenalty = (float)penalty;
737 float fpenalty_ex = (float)penalty_ex;
740 float *fg_t_og_h_dg_n2_p_pt;
741 float *og_t_fg_h_dg_n2_p_pt;
742 float *og_h_dg_n2_p_pt;
743 float *fg_h_dg_n2_p_pt;
748 float fg_t_og_h_dg_n1_p_va;
749 float og_t_fg_h_dg_n1_p_va;
750 float og_h_dg_n1_p_va;
751 float fg_h_dg_n1_p_va;
760 fprintf( stderr, "eff in SA+++align\n" );
761 for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
765 mseq1 = AllocateCharMtx( njob, 0 );
766 mseq2 = AllocateCharMtx( njob, 0 );
770 lgth1 = strlen( seq1[0] );
771 lgth2 = strlen( seq2[0] );
773 if( lgth1 > orlgth1 || lgth2 > orlgth2 )
777 if( orlgth1 > 0 && orlgth2 > 0 )
781 FreeFloatVec( match );
782 FreeFloatVec( initverticalw );
783 FreeFloatVec( lastverticalw );
790 FreeFloatVec( digf1 );
791 FreeFloatVec( digf2 );
792 FreeFloatVec( diaf1 );
793 FreeFloatVec( diaf2 );
794 FreeFloatVec( gapz1 );
795 FreeFloatVec( gapz2 );
796 FreeFloatVec( gapf1 );
797 FreeFloatVec( gapf2 );
798 FreeFloatVec( ogcp1g );
799 FreeFloatVec( ogcp2g );
800 FreeFloatVec( fgcp1g );
801 FreeFloatVec( fgcp2g );
802 FreeFloatVec( og_h_dg_n1_p );
803 FreeFloatVec( og_h_dg_n2_p );
804 FreeFloatVec( fg_h_dg_n1_p );
805 FreeFloatVec( fg_h_dg_n2_p );
806 FreeFloatVec( og_t_fg_h_dg_n1_p );
807 FreeFloatVec( og_t_fg_h_dg_n2_p );
808 FreeFloatVec( fg_t_og_h_dg_n1_p );
809 FreeFloatVec( fg_t_og_h_dg_n2_p );
810 FreeFloatVec( gapz_n1 );
811 FreeFloatVec( gapz_n2 );
813 FreeFloatMtx( cpmx1 );
814 FreeFloatMtx( cpmx2 );
816 FreeFloatMtx( floatwork );
817 FreeIntMtx( intwork );
820 ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
821 ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
824 fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
827 w1 = AllocateFloatVec( ll2+2 );
828 w2 = AllocateFloatVec( ll2+2 );
829 match = AllocateFloatVec( ll2+2 );
831 initverticalw = AllocateFloatVec( ll1+2 );
832 lastverticalw = AllocateFloatVec( ll1+2 );
834 m = AllocateFloatVec( ll2+2 );
835 mp = AllocateIntVec( ll2+2 );
837 mseq = AllocateCharMtx( njob, ll1+ll2 );
839 digf1 = AllocateFloatVec( ll1+2 );
840 digf2 = AllocateFloatVec( ll2+2 );
841 diaf1 = AllocateFloatVec( ll1+2 );
842 diaf2 = AllocateFloatVec( ll2+2 );
843 gapz1 = AllocateFloatVec( ll1+2 );
844 gapz2 = AllocateFloatVec( ll2+2 );
845 gapf1 = AllocateFloatVec( ll1+2 );
846 gapf2 = AllocateFloatVec( ll2+2 );
847 ogcp1g = AllocateFloatVec( ll1+2 );
848 ogcp2g = AllocateFloatVec( ll2+2 );
849 fgcp1g = AllocateFloatVec( ll1+2 );
850 fgcp2g = AllocateFloatVec( ll2+2 );
851 og_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
852 og_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
853 fg_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
854 fg_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
855 og_t_fg_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
856 og_t_fg_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
857 fg_t_og_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
858 fg_t_og_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
859 gapz_n1 = AllocateFloatVec( ll1+2 );
860 gapz_n2 = AllocateFloatVec( ll2+2 );
862 cpmx1 = AllocateFloatMtx( 26, ll1+2 );
863 cpmx2 = AllocateFloatMtx( 26, ll2+2 );
866 floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 );
867 intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 );
869 floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 );
870 intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 );
874 fprintf( stderr, "succeeded\n" );
882 for( i=0; i<icyc; i++ ) mseq1[i] = mseq[i];
883 for( j=0; j<jcyc; j++ ) mseq2[j] = mseq[icyc+j];
886 if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
890 if( commonAlloc1 && commonAlloc2 )
892 FreeIntMtx( commonIP );
895 ll1 = MAX( orlgth1, commonAlloc1 );
896 ll2 = MAX( orlgth2, commonAlloc2 );
899 fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
902 commonIP = AllocateIntMtx( ll1+10, ll2+10 );
905 fprintf( stderr, "succeeded\n\n" );
913 cpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
914 cpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
918 new_OpeningGapCount_zure( ogcp1g, icyc, seq1, eff1, lgth1, sgap1, egap1 );
919 new_OpeningGapCount_zure( ogcp2g, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
920 new_FinalGapCount_zure( fgcp1g, icyc, seq1, eff1, lgth1, sgap1, egap1 );
921 new_FinalGapCount_zure( fgcp2g, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
922 getdigapfreq_part( digf1, icyc, seq1, eff1, lgth1, sgap1, egap1 );
923 getdigapfreq_part( digf2, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
924 getdiaminofreq_part( diaf1, icyc, seq1, eff1, lgth1, sgap1, egap1 );
925 getdiaminofreq_part( diaf2, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
926 getgapfreq( gapf1, icyc, seq1, eff1, lgth1 );
927 getgapfreq( gapf2, jcyc, seq2, eff2, lgth2 );
928 getgapfreq_zure_part( gapz1, icyc, seq1, eff1, lgth1, sgap1 );
929 getgapfreq_zure_part( gapz2, jcyc, seq2, eff2, lgth2, sgap1 );
933 st_OpeningGapCount( ogcp1g, icyc, seq1, eff1, lgth1 );
934 st_OpeningGapCount( ogcp2g, jcyc, seq2, eff2, lgth2 );
935 st_FinalGapCount_zure( fgcp1g, icyc, seq1, eff1, lgth1 );
936 st_FinalGapCount_zure( fgcp2g, jcyc, seq2, eff2, lgth2 );
937 getdigapfreq_st( digf1, icyc, seq1, eff1, lgth1 );
938 getdigapfreq_st( digf2, jcyc, seq2, eff2, lgth2 );
939 getdiaminofreq_x( diaf1, icyc, seq1, eff1, lgth1 );
940 getdiaminofreq_x( diaf2, jcyc, seq2, eff2, lgth2 );
941 getgapfreq( gapf1, icyc, seq1, eff1, lgth1 );
942 getgapfreq( gapf2, jcyc, seq2, eff2, lgth2 );
943 getgapfreq_zure( gapz1, icyc, seq1, eff1, lgth1 );
944 getgapfreq_zure( gapz2, jcyc, seq2, eff2, lgth2 );
949 for( i=0; i<lastj; i++ )
951 og_h_dg_n2_p[i] = ( 1.0-ogcp2g[i]-digf2[i] ) * fpenalty * 0.5;
952 fg_h_dg_n2_p[i] = ( 1.0-fgcp2g[i]-digf2[i] ) * fpenalty * 0.5;
953 og_t_fg_h_dg_n2_p[i] = (1.0-ogcp2g[i]+fgcp2g[i]-digf2[i]) * 0.5 * fpenalty;
954 fg_t_og_h_dg_n2_p[i] = (1.0-fgcp2g[i]+ogcp2g[i]-digf2[i]) * 0.5 * fpenalty;
955 gapz_n2[i] = (1.0-gapz2[i]);
958 for( i=0; i<lastj; i++ )
960 og_h_dg_n1_p[i] = ( 1.0-ogcp1g[i]-digf1[i] ) * fpenalty * 0.5;
961 fg_h_dg_n1_p[i] = ( 1.0-fgcp1g[i]-digf1[i] ) * fpenalty * 0.5;
962 og_t_fg_h_dg_n1_p[i] = (1.0-ogcp1g[i]+fgcp1g[i]-digf1[i]) * 0.5 * fpenalty;
963 fg_t_og_h_dg_n1_p[i] = (1.0-fgcp1g[i]+ogcp1g[i]-digf1[i]) * 0.5 * fpenalty;
964 gapz_n1[i] = (1.0-gapz1[i]);
972 match_calc( initverticalw, cpmx2, cpmx1, 0, lgth1, floatwork, intwork, 1 );
974 part_imp_match_out_vead_tate_gapmapQ( initverticalw, gapmap2[0]+start2, lgth1, start1, gapmap1 );
977 match_calc( currentw, cpmx1, cpmx2, 0, lgth2, floatwork, intwork, 1 );
979 part_imp_match_out_vead_gapmapQ( currentw, gapmap1[0]+start1, lgth2, start2, gapmap2 );
982 imp_match_calc( currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 );
990 g += ogcp1g[0] * og_h_dg_n2_p[0];
992 g += ogcp2g[0] * og_h_dg_n1_p[0];
994 g += fgcp1g[0] * fg_h_dg_n2_p[0];
996 g += fgcp2g[0] * fg_h_dg_n1_p[0];
998 initverticalw[0] += g;
1001 for( i=1; i<lgth1+1; i++ )
1003 tmppenal = gapz_n2[0]*og_t_fg_h_dg_n1_p[0];
1004 initverticalw[i] += tmppenal;
1006 tmppenal = gapz_n2[1]*fg_t_og_h_dg_n1_p[i];
1007 initverticalw[i] += tmppenal;
1010 for( j=1; j<lgth2+1; j++ )
1012 tmppenal = gapz_n1[0]*og_t_fg_h_dg_n2_p[0];
1013 currentw[j] += tmppenal;
1015 tmppenal = gapz_n1[1]*fg_t_og_h_dg_n2_p[j];
1016 currentw[j] += tmppenal;
1022 for( j=1; j<lgth2+1; j++ )
1023 currentw[j] -= offset * j / 2.0;
1024 for( i=1; i<lgth1+1; i++ )
1025 initverticalw[i] -= offset * i / 2.0;
1029 m[0] = 0.0; // iranai
1030 for( j=1; j<lgth2+1; ++j )
1033 m[j] = currentw[j-1] + 10000 * fpenalty; //iinoka?
1036 lastverticalw[0] = 0.0; // Falign kara yobaretatoki kounarukanousei ari
1038 lastverticalw[0] = currentw[lgth2-1];
1040 if( outgap ) lasti = lgth1+1; else lasti = lgth1;
1044 fprintf( stderr, "currentw = \n" );
1045 for( i=0; i<lgth1+1; i++ )
1047 fprintf( stderr, "%5.2f ", currentw[i] );
1049 fprintf( stderr, "\n" );
1050 fprintf( stderr, "initverticalw = \n" );
1051 for( i=0; i<lgth2+1; i++ )
1053 fprintf( stderr, "%5.2f ", initverticalw[i] );
1055 fprintf( stderr, "\n" );
1056 fprintf( stderr, "fcgp\n" );
1057 for( i=0; i<lgth1; i++ )
1058 fprintf( stderr, "fgcp1[%d]=%f\n", i, ogcp1[i] );
1059 for( i=0; i<lgth2; i++ )
1060 fprintf( stderr, "fgcp2[%d]=%f\n", i, ogcp2[i] );
1063 for( i=1; i<lasti; i++ )
1066 previousw = currentw;
1069 previousw[0] = initverticalw[i-1];
1071 match_calc( currentw, cpmx1, cpmx2, i, lgth2, floatwork, intwork, 0 );
1073 fprintf( stderr, "\n" );
1074 fprintf( stderr, "i=%d\n", i );
1075 fprintf( stderr, "currentw = \n" );
1076 for( j=0; j<lgth2; j++ )
1078 fprintf( stderr, "%5.2f ", currentw[j] );
1080 fprintf( stderr, "\n" );
1084 // fprintf( stderr, "Calling imp_match_calc (o) lgth = %d, i = %d\n", lgth1, i );
1085 // imp_match_out_vead( currentw, i, lgth2 );
1086 part_imp_match_out_vead_gapmapQ( currentw, gapmap1[i]+start1, lgth2, start2, gapmap2 );
1089 fprintf( stderr, "\n" );
1090 fprintf( stderr, "i=%d\n", i );
1091 fprintf( stderr, "currentw = \n" );
1092 for( j=0; j<lgth2; j++ )
1094 fprintf( stderr, "%5.2f ", currentw[j] );
1096 fprintf( stderr, "\n" );
1098 currentw[0] = initverticalw[i];
1101 mi = previousw[0] + 10000 * fpenalty;
1106 curpt = currentw + 1;
1108 fg_t_og_h_dg_n2_p_pt = fg_t_og_h_dg_n2_p + 1;
1109 og_t_fg_h_dg_n2_p_pt = og_t_fg_h_dg_n2_p + 1;
1110 og_h_dg_n2_p_pt = og_h_dg_n2_p + 1;
1111 fg_h_dg_n2_p_pt = fg_h_dg_n2_p + 1;
1112 gapz_n2_pt0 = gapz_n2 + 1;
1113 gapz_n2_pt1 = gapz_n2 + 2;
1114 fgcp2pt = fgcp2g + 1;
1115 ogcp2pt = ogcp2g + 1;
1117 fg_t_og_h_dg_n1_p_va = fg_t_og_h_dg_n1_p[i];
1118 og_t_fg_h_dg_n1_p_va = og_t_fg_h_dg_n1_p[i];
1119 og_h_dg_n1_p_va = og_h_dg_n1_p[i];
1120 fg_h_dg_n1_p_va = fg_h_dg_n1_p[i];
1121 gapz_n1_va0 = gapz_n1[i];
1122 gapz_n1_va1 = gapz_n1[i+1];
1123 fgcp1va = fgcp1g[i];
1124 ogcp1va = ogcp1g[i];
1126 for( j=1; j<lastj; j++ )
1130 g = ogcp1va * *og_h_dg_n2_p_pt;
1133 g = *ogcp2pt * og_h_dg_n1_p_va;
1136 g = fgcp1va * *fg_h_dg_n2_p_pt;
1139 g = *fgcp2pt * fg_h_dg_n1_p_va;
1146 fprintf( stderr, "%5.0f->", wm );
1148 tmppenal = gapz_n1_va1 * *fg_t_og_h_dg_n2_p_pt;
1150 fprintf( stderr, "%5.0f?", g );
1152 if( (g=mi+tmppenal) > wm )
1155 *ijppt = -( j - mpi );
1158 tmppenal = gapz_n1_va0 * *og_t_fg_h_dg_n2_p_pt;
1159 if( (g=*prept+tmppenal) >= mi )
1168 tmppenal = *gapz_n2_pt1 * fg_t_og_h_dg_n1_p_va;
1170 fprintf( stderr, "%5.0f?", g );
1172 if( (g=*mjpt+tmppenal) > wm )
1175 *ijppt = +( i - *mpjpt );
1178 tmppenal = *gapz_n2_pt0 * og_t_fg_h_dg_n1_p_va;
1179 if( (g=*prept+tmppenal) >= *mjpt )
1185 m[j] += fpenalty_ex;
1189 fprintf( stderr, "%5.0f ", wm );
1196 fg_t_og_h_dg_n2_p_pt++;
1197 og_t_fg_h_dg_n2_p_pt++;
1205 lastverticalw[i] = currentw[lgth2-1];
1211 for( j=1; j<lgth2+1; j++ )
1212 currentw[j] -= offset * ( lgth2 - j ) / 2.0;
1213 for( i=1; i<lgth1+1; i++ )
1214 lastverticalw[i] -= offset * ( lgth1 - i / 2.0);
1219 fprintf( stderr, "\n" );
1220 for( i=0; i<icyc; i++ ) fprintf( stderr,"%s\n", seq1[i] );
1221 fprintf( stderr, "#####\n" );
1222 for( j=0; j<jcyc; j++ ) fprintf( stderr,"%s\n", seq2[j] );
1223 fprintf( stderr, "====>" );
1224 for( i=0; i<icyc; i++ ) strcpy( mseq1[i], seq1[i] );
1225 for( j=0; j<jcyc; j++ ) strcpy( mseq2[j], seq2[j] );
1229 Atracking_localhom( impmatch, currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc, start1, end1, start2, end2, gapmap1, gapmap2 );
1232 Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
1234 // fprintf( stderr, "### impmatch = %f\n", *impmatch );
1236 resultlen = strlen( mseq1[0] );
1237 if( alloclen < resultlen || resultlen > N )
1239 fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
1240 ErrorExit( "LENGTH OVER!\n" );
1244 for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
1245 for( j=0; j<jcyc; j++ ) strcpy( seq2[j], mseq2[j] );
1247 fprintf( stderr, "\n" );
1248 for( i=0; i<icyc; i++ ) fprintf( stderr, "%s\n", mseq1[i] );
1249 fprintf( stderr, "#####\n" );
1250 for( j=0; j<jcyc; j++ ) fprintf( stderr, "%s\n", mseq2[j] );
1253 // fprintf( stderr, "wm = %f\n", wm );