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;
473 lgth1 = strlen( seq1[0] );
474 lgth2 = strlen( seq2[0] );
477 for( i=0; i<lgth1; i++ )
479 fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
487 wm = lastverticalw[0];
488 for( i=0; i<lgth1; i++ )
490 if( lastverticalw[i] >= wm )
492 wm = lastverticalw[i];
493 iin = i; jin = lgth2-1;
494 ijp[lgth1][lgth2] = +( lgth1 - i );
497 for( j=0; j<lgth2; j++ )
499 if( lasthorizontalw[j] >= wm )
501 wm = lasthorizontalw[j];
502 iin = lgth1-1; jin = j;
503 ijp[lgth1][lgth2] = -( lgth2 - j );
508 for( i=0; i<lgth1+1; i++ )
512 for( j=0; j<lgth2+1; j++ )
514 ijp[0][j] = -( j + 1 );
517 for( i=0; i<icyc; i++ )
519 mseq1[i] += lgth1+lgth2;
522 for( j=0; j<jcyc; j++ )
524 mseq2[j] += lgth1+lgth2;
527 iin = lgth1; jin = lgth2;
529 for( k=0; k<=lgth1+lgth2; k++ )
531 if( ijp[iin][jin] < 0 )
533 ifi = iin-1; jfi = jin+ijp[iin][jin];
535 else if( ijp[iin][jin] > 0 )
537 ifi = iin-ijp[iin][jin]; jfi = jin-1;
541 ifi = iin-1; jfi = jin-1;
546 for( i=0; i<icyc; i++ )
547 *--mseq1[i] = seq1[i][ifi+l];
548 for( j=0; j<jcyc; j++ )
555 for( i=0; i<icyc; i++ )
557 for( j=0; j<jcyc; j++ )
558 *--mseq2[j] = seq2[j][jfi+l];
561 if( iin != lgth1 && jin != lgth2 ) // ??
563 *impwmpt += part_imp_match_out_scQ( gapmap1[iin]+start1, gapmap2[jin]+start2 );
564 // fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] );
566 if( iin <= 0 || jin <= 0 ) break;
567 for( i=0; i<icyc; i++ )
568 *--mseq1[i] = seq1[i][ifi];
569 for( j=0; j<jcyc; j++ )
570 *--mseq2[j] = seq2[j][jfi];
572 iin = ifi; jin = jfi;
575 static float Atracking( float *lasthorizontalw, float *lastverticalw,
576 char **seq1, char **seq2,
577 char **mseq1, char **mseq2,
578 float **cpmx1, float **cpmx2,
579 int **ijp, int icyc, int jcyc )
581 int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, lastk;
586 lgth1 = strlen( seq1[0] );
587 lgth2 = strlen( seq2[0] );
590 for( i=0; i<lgth1; i++ )
592 fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
600 wm = lastverticalw[0];
601 for( i=0; i<lgth1; i++ )
603 if( lastverticalw[i] >= wm )
605 wm = lastverticalw[i];
606 iin = i; jin = lgth2-1;
607 ijp[lgth1][lgth2] = +( lgth1 - i );
610 for( j=0; j<lgth2; j++ )
612 if( lasthorizontalw[j] >= wm )
614 wm = lasthorizontalw[j];
615 iin = lgth1-1; jin = j;
616 ijp[lgth1][lgth2] = -( lgth2 - j );
621 for( i=0; i<lgth1+1; i++ )
625 for( j=0; j<lgth2+1; j++ )
627 ijp[0][j] = -( j + 1 );
630 for( i=0; i<icyc; i++ )
632 mseq1[i] += lgth1+lgth2;
635 for( j=0; j<jcyc; j++ )
637 mseq2[j] += lgth1+lgth2;
640 iin = lgth1; jin = lgth2;
642 for( k=0; k<=lastk; k++ )
644 if( ijp[iin][jin] < 0 )
646 ifi = iin-1; jfi = jin+ijp[iin][jin];
648 else if( ijp[iin][jin] > 0 )
650 ifi = iin-ijp[iin][jin]; jfi = jin-1;
654 ifi = iin-1; jfi = jin-1;
659 for( i=0; i<icyc; i++ )
660 *--mseq1[i] = seq1[i][ifi+l];
661 for( j=0; j<jcyc; j++ )
668 for( i=0; i<icyc; i++ )
670 for( j=0; j<jcyc; j++ )
671 *--mseq2[j] = seq2[j][jfi+l];
674 if( iin <= 0 || jin <= 0 ) break;
675 for( i=0; i<icyc; i++ )
676 *--mseq1[i] = seq1[i][ifi];
677 for( j=0; j<jcyc; j++ )
678 *--mseq2[j] = seq2[j][jfi];
680 iin = ifi; jin = jfi;
685 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 )
686 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
690 int lasti, lastj; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
693 float wm = 0.0; /* int ?????? */
695 float *currentw, *previousw;
699 float *mjpt, *prept, *curpt;
705 static float *w1, *w2;
707 static float *initverticalw; /* kufuu sureba iranai */
708 static float *lastverticalw; /* kufuu sureba iranai */
720 static float *ogcp1g;
721 static float *ogcp2g;
722 static float *fgcp1g;
723 static float *fgcp2g;
724 static float *og_h_dg_n1_p;
725 static float *og_h_dg_n2_p;
726 static float *fg_h_dg_n1_p;
727 static float *fg_h_dg_n2_p;
728 static float *og_t_fg_h_dg_n1_p;
729 static float *og_t_fg_h_dg_n2_p;
730 static float *fg_t_og_h_dg_n1_p;
731 static float *fg_t_og_h_dg_n2_p;
732 static float *gapz_n1;
733 static float *gapz_n2;
734 static float **cpmx1;
735 static float **cpmx2;
736 static int **intwork;
737 static float **floatwork;
738 static int orlgth1 = 0, orlgth2 = 0;
739 float fpenalty = (float)penalty;
741 float fpenalty_ex = (float)penalty_ex;
744 float *fg_t_og_h_dg_n2_p_pt;
745 float *og_t_fg_h_dg_n2_p_pt;
746 float *og_h_dg_n2_p_pt;
747 float *fg_h_dg_n2_p_pt;
752 float fg_t_og_h_dg_n1_p_va;
753 float og_t_fg_h_dg_n1_p_va;
754 float og_h_dg_n1_p_va;
755 float fg_h_dg_n1_p_va;
764 fprintf( stderr, "eff in SA+++align\n" );
765 for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
769 mseq1 = AllocateCharMtx( njob, 0 );
770 mseq2 = AllocateCharMtx( njob, 0 );
774 lgth1 = strlen( seq1[0] );
775 lgth2 = strlen( seq2[0] );
777 if( lgth1 > orlgth1 || lgth2 > orlgth2 )
781 if( orlgth1 > 0 && orlgth2 > 0 )
785 FreeFloatVec( match );
786 FreeFloatVec( initverticalw );
787 FreeFloatVec( lastverticalw );
794 FreeFloatVec( digf1 );
795 FreeFloatVec( digf2 );
796 FreeFloatVec( diaf1 );
797 FreeFloatVec( diaf2 );
798 FreeFloatVec( gapz1 );
799 FreeFloatVec( gapz2 );
800 FreeFloatVec( gapf1 );
801 FreeFloatVec( gapf2 );
802 FreeFloatVec( ogcp1g );
803 FreeFloatVec( ogcp2g );
804 FreeFloatVec( fgcp1g );
805 FreeFloatVec( fgcp2g );
806 FreeFloatVec( og_h_dg_n1_p );
807 FreeFloatVec( og_h_dg_n2_p );
808 FreeFloatVec( fg_h_dg_n1_p );
809 FreeFloatVec( fg_h_dg_n2_p );
810 FreeFloatVec( og_t_fg_h_dg_n1_p );
811 FreeFloatVec( og_t_fg_h_dg_n2_p );
812 FreeFloatVec( fg_t_og_h_dg_n1_p );
813 FreeFloatVec( fg_t_og_h_dg_n2_p );
814 FreeFloatVec( gapz_n1 );
815 FreeFloatVec( gapz_n2 );
817 FreeFloatMtx( cpmx1 );
818 FreeFloatMtx( cpmx2 );
820 FreeFloatMtx( floatwork );
821 FreeIntMtx( intwork );
824 ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
825 ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
828 fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
831 w1 = AllocateFloatVec( ll2+2 );
832 w2 = AllocateFloatVec( ll2+2 );
833 match = AllocateFloatVec( ll2+2 );
835 initverticalw = AllocateFloatVec( ll1+2 );
836 lastverticalw = AllocateFloatVec( ll1+2 );
838 m = AllocateFloatVec( ll2+2 );
839 mp = AllocateIntVec( ll2+2 );
841 mseq = AllocateCharMtx( njob, ll1+ll2 );
843 digf1 = AllocateFloatVec( ll1+2 );
844 digf2 = AllocateFloatVec( ll2+2 );
845 diaf1 = AllocateFloatVec( ll1+2 );
846 diaf2 = AllocateFloatVec( ll2+2 );
847 gapz1 = AllocateFloatVec( ll1+2 );
848 gapz2 = AllocateFloatVec( ll2+2 );
849 gapf1 = AllocateFloatVec( ll1+2 );
850 gapf2 = AllocateFloatVec( ll2+2 );
851 ogcp1g = AllocateFloatVec( ll1+2 );
852 ogcp2g = AllocateFloatVec( ll2+2 );
853 fgcp1g = AllocateFloatVec( ll1+2 );
854 fgcp2g = AllocateFloatVec( ll2+2 );
855 og_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
856 og_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
857 fg_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
858 fg_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
859 og_t_fg_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
860 og_t_fg_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
861 fg_t_og_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
862 fg_t_og_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
863 gapz_n1 = AllocateFloatVec( ll1+2 );
864 gapz_n2 = AllocateFloatVec( ll2+2 );
866 cpmx1 = AllocateFloatMtx( 26, ll1+2 );
867 cpmx2 = AllocateFloatMtx( 26, ll2+2 );
870 floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 );
871 intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 );
873 floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 );
874 intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 );
878 fprintf( stderr, "succeeded\n" );
886 for( i=0; i<icyc; i++ ) mseq1[i] = mseq[i];
887 for( j=0; j<jcyc; j++ ) mseq2[j] = mseq[icyc+j];
890 if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
894 if( commonAlloc1 && commonAlloc2 )
896 FreeIntMtx( commonIP );
899 ll1 = MAX( orlgth1, commonAlloc1 );
900 ll2 = MAX( orlgth2, commonAlloc2 );
903 fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
906 commonIP = AllocateIntMtx( ll1+10, ll2+10 );
909 fprintf( stderr, "succeeded\n\n" );
917 cpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
918 cpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
922 new_OpeningGapCount_zure( ogcp1g, icyc, seq1, eff1, lgth1, sgap1, egap1 );
923 new_OpeningGapCount_zure( ogcp2g, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
924 new_FinalGapCount_zure( fgcp1g, icyc, seq1, eff1, lgth1, sgap1, egap1 );
925 new_FinalGapCount_zure( fgcp2g, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
926 getdigapfreq_part( digf1, icyc, seq1, eff1, lgth1, sgap1, egap1 );
927 getdigapfreq_part( digf2, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
928 getdiaminofreq_part( diaf1, icyc, seq1, eff1, lgth1, sgap1, egap1 );
929 getdiaminofreq_part( diaf2, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
930 getgapfreq( gapf1, icyc, seq1, eff1, lgth1 );
931 getgapfreq( gapf2, jcyc, seq2, eff2, lgth2 );
932 getgapfreq_zure_part( gapz1, icyc, seq1, eff1, lgth1, sgap1 );
933 getgapfreq_zure_part( gapz2, jcyc, seq2, eff2, lgth2, sgap1 );
937 st_OpeningGapCount( ogcp1g, icyc, seq1, eff1, lgth1 );
938 st_OpeningGapCount( ogcp2g, jcyc, seq2, eff2, lgth2 );
939 st_FinalGapCount_zure( fgcp1g, icyc, seq1, eff1, lgth1 );
940 st_FinalGapCount_zure( fgcp2g, jcyc, seq2, eff2, lgth2 );
941 getdigapfreq_st( digf1, icyc, seq1, eff1, lgth1 );
942 getdigapfreq_st( digf2, jcyc, seq2, eff2, lgth2 );
943 getdiaminofreq_x( diaf1, icyc, seq1, eff1, lgth1 );
944 getdiaminofreq_x( diaf2, jcyc, seq2, eff2, lgth2 );
945 getgapfreq( gapf1, icyc, seq1, eff1, lgth1 );
946 getgapfreq( gapf2, jcyc, seq2, eff2, lgth2 );
947 getgapfreq_zure( gapz1, icyc, seq1, eff1, lgth1 );
948 getgapfreq_zure( gapz2, jcyc, seq2, eff2, lgth2 );
953 for( i=0; i<lastj; i++ )
955 og_h_dg_n2_p[i] = ( 1.0-ogcp2g[i]-digf2[i] ) * fpenalty * 0.5;
956 fg_h_dg_n2_p[i] = ( 1.0-fgcp2g[i]-digf2[i] ) * fpenalty * 0.5;
957 og_t_fg_h_dg_n2_p[i] = (1.0-ogcp2g[i]+fgcp2g[i]-digf2[i]) * 0.5 * fpenalty;
958 fg_t_og_h_dg_n2_p[i] = (1.0-fgcp2g[i]+ogcp2g[i]-digf2[i]) * 0.5 * fpenalty;
959 gapz_n2[i] = (1.0-gapz2[i]);
962 for( i=0; i<lastj; i++ )
964 og_h_dg_n1_p[i] = ( 1.0-ogcp1g[i]-digf1[i] ) * fpenalty * 0.5;
965 fg_h_dg_n1_p[i] = ( 1.0-fgcp1g[i]-digf1[i] ) * fpenalty * 0.5;
966 og_t_fg_h_dg_n1_p[i] = (1.0-ogcp1g[i]+fgcp1g[i]-digf1[i]) * 0.5 * fpenalty;
967 fg_t_og_h_dg_n1_p[i] = (1.0-fgcp1g[i]+ogcp1g[i]-digf1[i]) * 0.5 * fpenalty;
968 gapz_n1[i] = (1.0-gapz1[i]);
976 match_calc( initverticalw, cpmx2, cpmx1, 0, lgth1, floatwork, intwork, 1 );
978 part_imp_match_out_vead_tate_gapmapQ( initverticalw, gapmap2[0]+start2, lgth1, start1, gapmap1 );
981 match_calc( currentw, cpmx1, cpmx2, 0, lgth2, floatwork, intwork, 1 );
983 part_imp_match_out_vead_gapmapQ( currentw, gapmap1[0]+start1, lgth2, start2, gapmap2 );
986 imp_match_calc( currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 );
994 g += ogcp1g[0] * og_h_dg_n2_p[0];
996 g += ogcp2g[0] * og_h_dg_n1_p[0];
998 g += fgcp1g[0] * fg_h_dg_n2_p[0];
1000 g += fgcp2g[0] * fg_h_dg_n1_p[0];
1002 initverticalw[0] += g;
1005 for( i=1; i<lgth1+1; i++ )
1007 tmppenal = gapz_n2[0]*og_t_fg_h_dg_n1_p[0];
1008 initverticalw[i] += tmppenal;
1010 tmppenal = gapz_n2[1]*fg_t_og_h_dg_n1_p[i];
1011 initverticalw[i] += tmppenal;
1014 for( j=1; j<lgth2+1; j++ )
1016 tmppenal = gapz_n1[0]*og_t_fg_h_dg_n2_p[0];
1017 currentw[j] += tmppenal;
1019 tmppenal = gapz_n1[1]*fg_t_og_h_dg_n2_p[j];
1020 currentw[j] += tmppenal;
1026 for( j=1; j<lgth2+1; j++ )
1027 currentw[j] -= offset * j / 2.0;
1028 for( i=1; i<lgth1+1; i++ )
1029 initverticalw[i] -= offset * i / 2.0;
1033 m[0] = 0.0; // iranai
1034 for( j=1; j<lgth2+1; ++j )
1037 m[j] = currentw[j-1] + 10000 * fpenalty; //iinoka?
1040 lastverticalw[0] = 0.0; // Falign kara yobaretatoki kounarukanousei ari
1042 lastverticalw[0] = currentw[lgth2-1];
1044 if( outgap ) lasti = lgth1+1; else lasti = lgth1;
1048 fprintf( stderr, "currentw = \n" );
1049 for( i=0; i<lgth1+1; i++ )
1051 fprintf( stderr, "%5.2f ", currentw[i] );
1053 fprintf( stderr, "\n" );
1054 fprintf( stderr, "initverticalw = \n" );
1055 for( i=0; i<lgth2+1; i++ )
1057 fprintf( stderr, "%5.2f ", initverticalw[i] );
1059 fprintf( stderr, "\n" );
1060 fprintf( stderr, "fcgp\n" );
1061 for( i=0; i<lgth1; i++ )
1062 fprintf( stderr, "fgcp1[%d]=%f\n", i, ogcp1[i] );
1063 for( i=0; i<lgth2; i++ )
1064 fprintf( stderr, "fgcp2[%d]=%f\n", i, ogcp2[i] );
1067 for( i=1; i<lasti; i++ )
1070 previousw = currentw;
1073 previousw[0] = initverticalw[i-1];
1075 match_calc( currentw, cpmx1, cpmx2, i, lgth2, floatwork, intwork, 0 );
1077 fprintf( stderr, "\n" );
1078 fprintf( stderr, "i=%d\n", i );
1079 fprintf( stderr, "currentw = \n" );
1080 for( j=0; j<lgth2; j++ )
1082 fprintf( stderr, "%5.2f ", currentw[j] );
1084 fprintf( stderr, "\n" );
1088 // fprintf( stderr, "Calling imp_match_calc (o) lgth = %d, i = %d\n", lgth1, i );
1089 // imp_match_out_vead( currentw, i, lgth2 );
1090 part_imp_match_out_vead_gapmapQ( currentw, gapmap1[i]+start1, lgth2, start2, gapmap2 );
1093 fprintf( stderr, "\n" );
1094 fprintf( stderr, "i=%d\n", i );
1095 fprintf( stderr, "currentw = \n" );
1096 for( j=0; j<lgth2; j++ )
1098 fprintf( stderr, "%5.2f ", currentw[j] );
1100 fprintf( stderr, "\n" );
1102 currentw[0] = initverticalw[i];
1105 mi = previousw[0] + 10000 * fpenalty;
1110 curpt = currentw + 1;
1112 fg_t_og_h_dg_n2_p_pt = fg_t_og_h_dg_n2_p + 1;
1113 og_t_fg_h_dg_n2_p_pt = og_t_fg_h_dg_n2_p + 1;
1114 og_h_dg_n2_p_pt = og_h_dg_n2_p + 1;
1115 fg_h_dg_n2_p_pt = fg_h_dg_n2_p + 1;
1116 gapz_n2_pt0 = gapz_n2 + 1;
1117 gapz_n2_pt1 = gapz_n2 + 2;
1118 fgcp2pt = fgcp2g + 1;
1119 ogcp2pt = ogcp2g + 1;
1121 fg_t_og_h_dg_n1_p_va = fg_t_og_h_dg_n1_p[i];
1122 og_t_fg_h_dg_n1_p_va = og_t_fg_h_dg_n1_p[i];
1123 og_h_dg_n1_p_va = og_h_dg_n1_p[i];
1124 fg_h_dg_n1_p_va = fg_h_dg_n1_p[i];
1125 gapz_n1_va0 = gapz_n1[i];
1126 gapz_n1_va1 = gapz_n1[i+1];
1127 fgcp1va = fgcp1g[i];
1128 ogcp1va = ogcp1g[i];
1130 for( j=1; j<lastj; j++ )
1134 g = ogcp1va * *og_h_dg_n2_p_pt;
1137 g = *ogcp2pt * og_h_dg_n1_p_va;
1140 g = fgcp1va * *fg_h_dg_n2_p_pt;
1143 g = *fgcp2pt * fg_h_dg_n1_p_va;
1150 fprintf( stderr, "%5.0f->", wm );
1152 tmppenal = gapz_n1_va1 * *fg_t_og_h_dg_n2_p_pt;
1154 fprintf( stderr, "%5.0f?", g );
1156 if( (g=mi+tmppenal) > wm )
1159 *ijppt = -( j - mpi );
1162 tmppenal = gapz_n1_va0 * *og_t_fg_h_dg_n2_p_pt;
1163 if( (g=*prept+tmppenal) >= mi )
1172 tmppenal = *gapz_n2_pt1 * fg_t_og_h_dg_n1_p_va;
1174 fprintf( stderr, "%5.0f?", g );
1176 if( (g=*mjpt+tmppenal) > wm )
1179 *ijppt = +( i - *mpjpt );
1182 tmppenal = *gapz_n2_pt0 * og_t_fg_h_dg_n1_p_va;
1183 if( (g=*prept+tmppenal) >= *mjpt )
1189 m[j] += fpenalty_ex;
1193 fprintf( stderr, "%5.0f ", wm );
1200 fg_t_og_h_dg_n2_p_pt++;
1201 og_t_fg_h_dg_n2_p_pt++;
1209 lastverticalw[i] = currentw[lgth2-1];
1215 for( j=1; j<lgth2+1; j++ )
1216 currentw[j] -= offset * ( lgth2 - j ) / 2.0;
1217 for( i=1; i<lgth1+1; i++ )
1218 lastverticalw[i] -= offset * ( lgth1 - i / 2.0);
1223 fprintf( stderr, "\n" );
1224 for( i=0; i<icyc; i++ ) fprintf( stderr,"%s\n", seq1[i] );
1225 fprintf( stderr, "#####\n" );
1226 for( j=0; j<jcyc; j++ ) fprintf( stderr,"%s\n", seq2[j] );
1227 fprintf( stderr, "====>" );
1228 for( i=0; i<icyc; i++ ) strcpy( mseq1[i], seq1[i] );
1229 for( j=0; j<jcyc; j++ ) strcpy( mseq2[j], seq2[j] );
1233 Atracking_localhom( impmatch, currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc, start1, end1, start2, end2, gapmap1, gapmap2 );
1236 Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
1238 // fprintf( stderr, "### impmatch = %f\n", *impmatch );
1240 resultlen = strlen( mseq1[0] );
1241 if( alloclen < resultlen || resultlen > N )
1243 fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
1244 ErrorExit( "LENGTH OVER!\n" );
1248 for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
1249 for( j=0; j<jcyc; j++ ) strcpy( seq2[j], mseq2[j] );
1251 fprintf( stderr, "\n" );
1252 for( i=0; i<icyc; i++ ) fprintf( stderr, "%s\n", mseq1[i] );
1253 fprintf( stderr, "#####\n" );
1254 for( j=0; j<jcyc; j++ ) fprintf( stderr, "%s\n", mseq2[j] );
1257 // fprintf( stderr, "wm = %f\n", wm );