8 #define USE_PENALTY_EX 0
9 #define FASTMATCHCALC 1
12 static void st_OpeningGapCount( float *ogcp, int clus, char **seq, double *eff, int len )
17 for( i=0; i<len; i++ ) ogcp[i] = 0.0;
18 for( j=0; j<clus; j++ )
22 for( i=0; i<len; i++ )
25 gc = ( seq[j][i] == '-' );
27 if( !gb * gc ) ogcp[i] += feff;
33 static void st_FinalGapCount( float *fgcp, int clus, char **seq, double *eff, int len )
38 for( i=0; i<len; i++ ) fgcp[i] = 0.0;
39 for( j=0; j<clus; j++ )
42 gc = ( seq[j][0] == '-' );
43 for( i=1; i<len+1; i++ )
46 gc = ( seq[j][i] == '-' );
48 if( gb * !gc ) fgcp[i-1] += feff;
59 static TLS int impalloclen = 0;
60 static TLS float **impmtx = NULL;
61 float part_imp_match_out_sc( int i1, int j1 )
63 // fprintf( stderr, "impalloclen = %d\n", impalloclen );
64 // fprintf( stderr, "i1,j1=%d,%d -> impmtx=%f\n", i1, j1, impmtx[i1][j1] );
65 return( impmtx[i1][j1] );
67 if( i1 == l1 || j1 == l2 ) return( 0.0 );
68 return( impmtx[i1+start1][j1+start2] );
71 static void part_imp_match_out_vead_gapmap( float *imp, int i1, int lgth2, int start2, int *gapmap2 )
75 int *gapmappt = gapmap2;
77 *pt++ += impmtx[i1][start2+*gapmappt++];
80 for( j=0; j<lgth2; j++ )
82 imp[j] += impmtx[i1][start2+gapmap2[j]];
87 static void part_imp_match_out_vead_tate_gapmap( float *imp, int j1, int lgth1, int start1, int *gapmap1 )
91 int *gapmappt = gapmap1;
93 *pt++ = impmtx[start1+*gapmappt++][j1];
96 for( i=0; i<lgth1; i++ )
98 imp[i] += impmtx[start1+gapmap1[i]][j1];
103 void part_imp_match_init_strict( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, double *eff1_kozo, double *eff2_kozo, LocalHom ***localhom, int forscore )
105 int i, j, k1, k2, tmpint, start1, start2, end1, end2;
106 double effij, effijx, effij_kozo;
107 char *pt, *pt1, *pt2;
112 if( impmtx ) FreeFloatMtx( impmtx );
117 if( impalloclen <= lgth1 + 2 || impalloclen <= lgth2 + 2 )
119 if( impmtx ) FreeFloatMtx( impmtx );
120 impalloclen = MAX( lgth1, lgth2 ) + 2;
121 impmtx = AllocateFloatMtx( impalloclen+100, impalloclen+100 );
126 fprintf( stderr, "eff1 in _init_strict = \n" );
127 for( i=0; i<clus1; i++ )
128 fprintf( stderr, "eff1[] = %f\n", eff1[i] );
129 for( i=0; i<clus2; i++ )
130 fprintf( stderr, "eff2[] = %f\n", eff2[i] );
133 for( i=0; i<lgth1; i++ ) for( j=0; j<lgth2; j++ )
135 effijx = 1.0 * fastathreshold;
136 for( i=0; i<clus1; i++ )
138 for( j=0; j<clus2; j++ )
140 effij = eff1[i] * eff2[j] * effijx;
141 effij_kozo = eff1_kozo[i] * eff2_kozo[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 = (int)( pt - seq1[i] ) - 1;
158 if( tmpptr->start1 == tmpptr->end1 ) end1 = start1;
164 if( tmpint == tmpptr->end1 ) break;
165 if( *pt++ != '-' ) tmpint++;
167 end1 = (int)( pt - seq1[i] ) - 1;
171 // fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] );
172 if( *pt++ != '-' ) tmpint++;
173 if( tmpint == tmpptr->end1 ) break;
175 end1 = (int)( pt - seq1[i] ) - 1;
183 if( *pt++ != '-' ) tmpint++;
184 if( tmpint == tmpptr->start2 ) break;
186 start2 = (int)( pt - seq2[j] ) - 1;
187 if( tmpptr->start2 == tmpptr->end2 ) end2 = start2;
193 if( tmpint == tmpptr->end2 ) break;
194 if( *pt++ != '-' ) tmpint++;
196 end2 = (int)( pt - seq2[j] ) - 1;
200 if( *pt++ != '-' ) tmpint++;
201 if( tmpint == tmpptr->end2 ) break;
203 end2 = (int)( pt - seq2[j] ) - 1;
206 // 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] );
207 // fprintf( stderr, "step 0\n" );
208 if( end1 - start1 != end2 - start2 )
210 // fprintf( stderr, "CHUUI!!, start1 = %d, end1 = %d, start2 = %d, end2 = %d\n", start1, end1, start2, end2 );
213 k1 = start1; k2 = start2;
216 while( *pt1 && *pt2 )
218 if( *pt1 != '-' && *pt2 != '-' )
220 // ½Å¤ß¤òÆó½Å¤Ë¤«¤±¤Ê¤¤¤è¤¦¤ËÃðդ·¤Æ²¼¤µ¤¤¡£
221 // impmtx[k1][k2] += tmpptr->wimportance * fastathreshold;
222 // impmtx[k1][k2] += tmpptr->importance * effij;
223 // impmtx[k1][k2] += tmpptr->fimportance * effij;
224 if( tmpptr->korh == 'k' )
225 impmtx[k1][k2] += tmpptr->fimportance * effij_kozo;
227 impmtx[k1][k2] += tmpptr->fimportance * effij;
228 // fprintf( stderr, "k1=%d, k2=%d, impalloclen=%d\n", k1, k2, impalloclen );
229 // fprintf( stderr, "mark, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
233 else if( *pt1 != '-' && *pt2 == '-' )
235 // fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
238 else if( *pt1 == '-' && *pt2 != '-' )
240 // fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
243 else if( *pt1 == '-' && *pt2 == '-' )
245 // fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
249 if( k1 > end1 || k2 > end2 ) break;
251 tmpptr = tmpptr->next;
256 fprintf( stderr, "impmtx = \n" );
257 for( k2=0; k2<lgth2; k2++ )
258 fprintf( stderr, "%6.3f ", (double)k2 );
259 fprintf( stderr, "\n" );
260 for( k1=0; k1<lgth1; k1++ )
262 fprintf( stderr, "%d", k1 );
263 for( k2=0; k2<lgth2; k2++ )
264 fprintf( stderr, "%2.1f ", impmtx[k1][k2] );
265 fprintf( stderr, "\n" );
272 void part_imp_rna( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***grouprna1, RNApair ***grouprna2, int *gapmap1, int *gapmap2, RNApair *additionalpair )
274 foldrna( nseq1, nseq2, seq1, seq2, eff1, eff2, grouprna1, grouprna2, impmtx, gapmap1, gapmap2, additionalpair );
278 void part_imp_match_init( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom )
280 int dif, i, j, k1, k2, tmpint, start1, start2, end1, end2;
281 static TLS int impalloclen = 0;
283 static TLS char *nocount1 = NULL;
284 static TLS char *nocount2 = NULL;
286 if( impalloclen < lgth1 || impalloclen < lgth2 )
288 if( impmtx ) FreeFloatMtx( impmtx );
289 if( nocount1 ) free( nocount1 );
290 if( nocount2 ) free( nocount2 );
291 impalloclen = MAX( lgth1, lgth2 ) + 2;
292 impmtx = AllocateFloatMtx( impalloclen, impalloclen );
293 nocount1 = AllocateCharVec( impalloclen );
294 nocount2 = AllocateCharVec( impalloclen );
298 for( i=0; i<lgth1; i++ )
300 for( j=0; j<clus1; j++ )
301 if( seq1[j][i] == '-' ) break;
302 if( j != clus1 ) nocount1[i] = 1;
303 else nocount1[i] = 0;
305 for( i=0; i<lgth2; i++ )
307 for( j=0; j<clus2; j++ )
308 if( seq2[j][i] == '-' ) break;
309 if( j != clus2 ) nocount2[i] = 1;
310 else nocount2[i] = 0;
314 fprintf( stderr, "nocount2 =\n" );
315 for( i = 0; i<impalloclen; i++ )
317 fprintf( stderr, "nocount2[%d] = %d (%c)\n", i, nocount2[i], seq2[0][i] );
321 for( i=0; i<lgth1; i++ ) for( j=0; j<lgth2; j++ )
323 for( i=0; i<clus1; i++ )
325 fprintf( stderr, "i = %d, seq1 = %s\n", i, seq1[i] );
326 for( j=0; j<clus2; j++ )
328 fprintf( stderr, "start1 = %d\n", localhom[i][j]->start1 );
329 fprintf( stderr, "end1 = %d\n", localhom[i][j]->end1 );
330 fprintf( stderr, "j = %d, seq2 = %s\n", j, seq2[j] );
335 if( *pt++ != '-' ) tmpint++;
336 if( tmpint == localhom[i][j]->start1 ) break;
338 start1 = pt - seq1[i] - 1;
342 // fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, localhom[i][j].end1, pt-seq1[i] );
343 if( *pt++ != '-' ) tmpint++;
344 if( tmpint == localhom[i][j]->end1 ) break;
346 end1 = pt - seq1[i] - 1;
352 if( *pt++ != '-' ) tmpint++;
353 if( tmpint == localhom[i][j]->start2 ) break;
355 start2 = pt - seq2[j] - 1;
358 if( *pt++ != '-' ) tmpint++;
359 if( tmpint == localhom[i][j]->end2 ) break;
361 end2 = pt - seq2[j] - 1;
362 // fprintf( stderr, "start1 = %d, end1 = %d, start2 = %d, end2 = %d\n", start1, end1, start2, end2 );
365 fprintf( stderr, "step 0\n" );
366 while( k1 <= end1 && k2 <= end2 )
369 if( !nocount1[k1] && !nocount2[k2] )
370 impmtx[k1][k2] += localhom[i][j].wimportance * eff1[i] * eff2[j];
373 if( !nocount1[k1] && !nocount2[k2] )
374 impmtx[k1][k2] += localhom[i][j]->wimportance * eff1[i] * eff2[j];
379 dif = ( end1 - start1 ) - ( end2 - start2 );
380 fprintf( stderr, "dif = %d\n", dif );
385 fprintf( stderr, "dif = %d\n", dif );
388 while( k1 <= end1 && k2 <= end2 )
390 if( 0 <= k2 && start2 <= k2 && !nocount1[k1] && !nocount2[k2] )
391 impmtx[k1][k2] = localhom[i][j]->wimportance * eff1[i] * eff2[j];
405 if( k1 >= 0 && k1 >= start1 && !nocount1[k1] && !nocount2[k2] )
406 impmtx[k1][k2] = localhom[i][j]->wimportance * eff1[i] * eff2[j];
415 fprintf( stderr, "impmtx = \n" );
416 for( k2=0; k2<lgth2; k2++ )
417 fprintf( stderr, "%6.3f ", (double)k2 );
418 fprintf( stderr, "\n" );
419 for( k1=0; k1<lgth1; k1++ )
421 fprintf( stderr, "%d", k1 );
422 for( k2=0; k2<lgth2; k2++ )
423 fprintf( stderr, "%6.3f ", impmtx[k1][k2] );
424 fprintf( stderr, "\n" );
430 static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
435 float **cpmxpd = floatwork;
436 int **cpmxpdn = intwork;
437 float *matchpt, *cpmxpdpt, **cpmxpdptpt;
438 int *cpmxpdnpt, **cpmxpdnptpt;
442 for( j=0; j<lgth2; j++ )
445 for( l=0; l<26; l++ )
449 cpmxpd[j][count] = cpmx2[l][j];
450 cpmxpdn[j][count] = l;
454 cpmxpdn[j][count] = -1;
459 for( l=0; l<26; l++ )
462 for( j=0; j<26; j++ )
463 scarr[l] += n_dis_consweight_multi[j][l] * cpmx1[j][i1];
464 // scarr[l] += n_dis[j][l] * cpmx1[j][i1];
467 cpmxpdnptpt = cpmxpdn;
472 cpmxpdnpt = *cpmxpdnptpt++;
473 cpmxpdpt = *cpmxpdptpt++;
474 while( *cpmxpdnpt>-1 )
475 *matchpt += scarr[*cpmxpdnpt++] * *cpmxpdpt++;
482 float **cpmxpd = floatwork;
483 int **cpmxpdn = intwork;
488 for( j=0; j<lgth2; j++ )
491 for( l=0; l<26; l++ )
495 cpmxpd[count][j] = cpmx2[l][j];
496 cpmxpdn[count][j] = l;
500 cpmxpdn[count][j] = -1;
503 for( l=0; l<26; l++ )
506 for( k=0; k<26; k++ )
507 scarr[l] += n_dis_consweight_multi[k][l] * cpmx1[k][i1];
508 // scarr[l] += n_dis[k][l] * cpmx1[k][i1];
510 for( j=0; j<lgth2; j++ )
513 for( k=0; cpmxpdn[k][j]>-1; k++ )
514 match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j];
519 static void Atracking_localhom( float *impwmpt, float *lasthorizontalw, float *lastverticalw,
520 char **seq1, char **seq2,
521 char **mseq1, char **mseq2,
522 float **cpmx1, float **cpmx2,
523 int **ijp, int icyc, int jcyc,
524 int start1, int end1, int start2, int end2,
525 int *gapmap1, int *gapmap2 )
527 int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k;
532 lgth1 = strlen( seq1[0] );
533 lgth2 = strlen( seq2[0] );
536 for( i=0; i<lgth1; i++ )
538 fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
546 wm = lastverticalw[0];
547 for( i=0; i<lgth1; i++ )
549 if( lastverticalw[i] >= wm )
551 wm = lastverticalw[i];
552 iin = i; jin = lgth2-1;
553 ijp[lgth1][lgth2] = +( lgth1 - i );
556 for( j=0; j<lgth2; j++ )
558 if( lasthorizontalw[j] >= wm )
560 wm = lasthorizontalw[j];
561 iin = lgth1-1; jin = j;
562 ijp[lgth1][lgth2] = -( lgth2 - j );
567 for( i=0; i<lgth1+1; i++ )
571 for( j=0; j<lgth2+1; j++ )
573 ijp[0][j] = -( j + 1 );
576 for( i=0; i<icyc; i++ )
578 mseq1[i] += lgth1+lgth2;
581 for( j=0; j<jcyc; j++ )
583 mseq2[j] += lgth1+lgth2;
586 iin = lgth1; jin = lgth2;
588 for( k=0; k<=lgth1+lgth2; k++ )
590 if( ijp[iin][jin] < 0 )
592 ifi = iin-1; jfi = jin+ijp[iin][jin];
594 else if( ijp[iin][jin] > 0 )
596 ifi = iin-ijp[iin][jin]; jfi = jin-1;
600 ifi = iin-1; jfi = jin-1;
605 for( i=0; i<icyc; i++ )
606 *--mseq1[i] = seq1[i][ifi+l];
607 for( j=0; j<jcyc; j++ )
614 for( i=0; i<icyc; i++ )
616 for( j=0; j<jcyc; j++ )
617 *--mseq2[j] = seq2[j][jfi+l];
620 if( iin != lgth1 && jin != lgth2 ) // ??
622 *impwmpt += part_imp_match_out_sc( gapmap1[iin]+start1, gapmap2[jin]+start2 );
623 // fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] );
625 if( iin <= 0 || jin <= 0 ) break;
626 for( i=0; i<icyc; i++ )
627 *--mseq1[i] = seq1[i][ifi];
628 for( j=0; j<jcyc; j++ )
629 *--mseq2[j] = seq2[j][jfi];
631 iin = ifi; jin = jfi;
634 static float Atracking( float *lasthorizontalw, float *lastverticalw,
635 char **seq1, char **seq2,
636 char **mseq1, char **mseq2,
637 float **cpmx1, float **cpmx2,
638 int **ijp, int icyc, int jcyc )
640 int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, lastk;
645 lgth1 = strlen( seq1[0] );
646 lgth2 = strlen( seq2[0] );
649 for( i=0; i<lgth1; i++ )
651 fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
659 wm = lastverticalw[0];
660 for( i=0; i<lgth1; i++ )
662 if( lastverticalw[i] >= wm )
664 wm = lastverticalw[i];
665 iin = i; jin = lgth2-1;
666 ijp[lgth1][lgth2] = +( lgth1 - i );
669 for( j=0; j<lgth2; j++ )
671 if( lasthorizontalw[j] >= wm )
673 wm = lasthorizontalw[j];
674 iin = lgth1-1; jin = j;
675 ijp[lgth1][lgth2] = -( lgth2 - j );
680 for( i=0; i<lgth1+1; i++ )
684 for( j=0; j<lgth2+1; j++ )
686 ijp[0][j] = -( j + 1 );
689 for( i=0; i<icyc; i++ )
691 mseq1[i] += lgth1+lgth2;
694 for( j=0; j<jcyc; j++ )
696 mseq2[j] += lgth1+lgth2;
699 iin = lgth1; jin = lgth2;
701 for( k=0; k<=lastk; k++ )
703 if( ijp[iin][jin] < 0 )
705 ifi = iin-1; jfi = jin+ijp[iin][jin];
707 else if( ijp[iin][jin] > 0 )
709 ifi = iin-ijp[iin][jin]; jfi = jin-1;
713 ifi = iin-1; jfi = jin-1;
718 for( i=0; i<icyc; i++ )
719 *--mseq1[i] = seq1[i][ifi+l];
720 for( j=0; j<jcyc; j++ )
727 for( i=0; i<icyc; i++ )
729 for( j=0; j<jcyc; j++ )
730 *--mseq2[j] = seq2[j][jfi+l];
733 if( iin <= 0 || jin <= 0 ) break;
734 for( i=0; i<icyc; i++ )
735 *--mseq1[i] = seq1[i][ifi];
736 for( j=0; j<jcyc; j++ )
737 *--mseq2[j] = seq2[j][jfi];
739 iin = ifi; jin = jfi;
744 float partA__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, int *chudanpt, int chudanref, int *chudanres )
745 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
749 int lasti, lastj; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
752 float wm = 0.0; /* int ?????? */
754 float *currentw, *previousw;
758 float *mjpt, *prept, *curpt;
761 static TLS float mi, *m;
762 static TLS int **ijp;
763 static TLS int mpi, *mp;
764 static TLS float *w1, *w2;
765 static TLS float *match;
766 static TLS float *initverticalw; /* kufuu sureba iranai */
767 static TLS float *lastverticalw; /* kufuu sureba iranai */
768 static TLS char **mseq1;
769 static TLS char **mseq2;
770 static TLS char **mseq;
771 static TLS float *ogcp1;
772 static TLS float *ogcp2;
773 static TLS float *fgcp1;
774 static TLS float *fgcp2;
775 static TLS float **cpmx1;
776 static TLS float **cpmx2;
777 static TLS int **intwork;
778 static TLS float **floatwork;
779 static TLS int orlgth1 = 0, orlgth2 = 0;
780 float fpenalty = (float)penalty;
782 float fpenalty_ex = (float)penalty_ex;
794 // fprintf( stderr, "## Freeing local arrays in A__align\n" );
798 part_imp_match_init_strict( NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0 );
804 FreeFloatVec( match );
805 FreeFloatVec( initverticalw );
806 FreeFloatVec( lastverticalw );
813 FreeFloatVec( ogcp1 );
814 FreeFloatVec( ogcp2 );
815 FreeFloatVec( fgcp1 );
816 FreeFloatVec( fgcp2 );
819 FreeFloatMtx( cpmx1 );
820 FreeFloatMtx( cpmx2 );
822 FreeFloatMtx( floatwork );
823 FreeIntMtx( intwork );
828 // fprintf( stderr, "## Not allocated\n" );
833 lgth1 = strlen( seq1[0] );
834 lgth2 = strlen( seq2[0] );
836 if( lgth1 == 0 ) fprintf( stderr, "WARNING: lgth1=0 in partA__align\n" );
837 if( lgth2 == 0 ) fprintf( stderr, "WARNING: lgth2=0 in partA__align\n" );
839 if( lgth1 == 0 && lgth2 == 0 )
844 for( i=0; i<icyc; i++ )
848 while( j ) seq1[i][--j] = '-';
849 // fprintf( stderr, "seq1[i] = %s\n", seq1[i] );
856 for( i=0; i<jcyc; i++ )
860 while( j ) seq2[i][--j] = '-';
861 // fprintf( stderr, "seq2[i] = %s\n", seq2[i] );
868 fprintf( stderr, "eff in SA+++align\n" );
869 for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
873 mseq1 = AllocateCharMtx( njob, 0 );
874 mseq2 = AllocateCharMtx( njob, 0 );
880 if( lgth1 > orlgth1 || lgth2 > orlgth2 )
884 if( orlgth1 > 0 && orlgth2 > 0 )
888 FreeFloatVec( match );
889 FreeFloatVec( initverticalw );
890 FreeFloatVec( lastverticalw );
897 FreeFloatVec( ogcp1 );
898 FreeFloatVec( ogcp2 );
899 FreeFloatVec( fgcp1 );
900 FreeFloatVec( fgcp2 );
903 FreeFloatMtx( cpmx1 );
904 FreeFloatMtx( cpmx2 );
906 FreeFloatMtx( floatwork );
907 FreeIntMtx( intwork );
910 ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
911 ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
914 fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
917 w1 = AllocateFloatVec( ll2+2 );
918 w2 = AllocateFloatVec( ll2+2 );
919 match = AllocateFloatVec( ll2+2 );
921 initverticalw = AllocateFloatVec( ll1+2 );
922 lastverticalw = AllocateFloatVec( ll1+2 );
924 m = AllocateFloatVec( ll2+2 );
925 mp = AllocateIntVec( ll2+2 );
927 mseq = AllocateCharMtx( njob, ll1+ll2 );
929 ogcp1 = AllocateFloatVec( ll1+2 );
930 ogcp2 = AllocateFloatVec( ll2+2 );
931 fgcp1 = AllocateFloatVec( ll1+2 );
932 fgcp2 = AllocateFloatVec( ll2+2 );
934 cpmx1 = AllocateFloatMtx( 26, ll1+2 );
935 cpmx2 = AllocateFloatMtx( 26, ll2+2 );
938 floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 );
939 intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 );
941 floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 );
942 intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 );
946 fprintf( stderr, "succeeded\n" );
954 for( i=0; i<icyc; i++ ) mseq1[i] = mseq[i];
955 for( j=0; j<jcyc; j++ ) mseq2[j] = mseq[icyc+j];
958 if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
962 if( commonAlloc1 && commonAlloc2 )
964 FreeIntMtx( commonIP );
967 ll1 = MAX( orlgth1, commonAlloc1 );
968 ll2 = MAX( orlgth2, commonAlloc2 );
971 fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
974 commonIP = AllocateIntMtx( ll1+10, ll2+10 );
977 fprintf( stderr, "succeeded\n\n" );
985 cpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
986 cpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
990 new_OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1, sgap1 );
991 new_OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2, sgap2 );
992 new_FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1, egap1 );
993 new_FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2, egap2 );
997 st_OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1 );
998 st_OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2 );
999 st_FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1 );
1000 st_FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2 );
1003 for( i=0; i<lgth1; i++ )
1005 ogcp1[i] = 0.5 * ( 1.0 - ogcp1[i] ) * fpenalty;
1006 fgcp1[i] = 0.5 * ( 1.0 - fgcp1[i] ) * fpenalty;
1008 for( i=0; i<lgth2; i++ )
1010 ogcp2[i] = 0.5 * ( 1.0 - ogcp2[i] ) * fpenalty;
1011 fgcp2[i] = 0.5 * ( 1.0 - fgcp2[i] ) * fpenalty;
1014 for( i=0; i<lgth1; i++ )
1015 fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
1022 match_calc( initverticalw, cpmx2, cpmx1, 0, lgth1, floatwork, intwork, 1 );
1024 part_imp_match_out_vead_tate_gapmap( initverticalw, gapmap2[0]+start2, lgth1, start1, gapmap1 );
1027 match_calc( currentw, cpmx1, cpmx2, 0, lgth2, floatwork, intwork, 1 );
1029 part_imp_match_out_vead_gapmap( currentw, gapmap1[0]+start1, lgth2, start2, gapmap2 );
1030 #if 0 // -> tbfast.c
1032 imp_match_calc( currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 );
1038 for( i=1; i<lgth1+1; i++ )
1040 initverticalw[i] += ( ogcp1[0] + fgcp1[i-1] ) ;
1042 for( j=1; j<lgth2+1; j++ )
1044 currentw[j] += ( ogcp2[0] + fgcp2[j-1] ) ;
1050 for( j=1; j<lgth2+1; j++ )
1051 currentw[j] -= offset * j / 2.0;
1052 for( i=1; i<lgth1+1; i++ )
1053 initverticalw[i] -= offset * i / 2.0;
1057 for( j=1; j<lgth2+1; ++j )
1059 m[j] = currentw[j-1] + ogcp1[1]; mp[j] = 0;
1062 lastverticalw[0] = currentw[lgth2-1];
1064 if( outgap ) lasti = lgth1+1; else lasti = lgth1;
1068 fprintf( stderr, "currentw = \n" );
1069 for( i=0; i<lgth1+1; i++ )
1071 fprintf( stderr, "%5.2f ", currentw[i] );
1073 fprintf( stderr, "\n" );
1074 fprintf( stderr, "initverticalw = \n" );
1075 for( i=0; i<lgth2+1; i++ )
1077 fprintf( stderr, "%5.2f ", initverticalw[i] );
1079 fprintf( stderr, "\n" );
1080 fprintf( stderr, "fcgp\n" );
1081 for( i=0; i<lgth1; i++ )
1082 fprintf( stderr, "fgcp1[%d]=%f\n", i, ogcp1[i] );
1083 for( i=0; i<lgth2; i++ )
1084 fprintf( stderr, "fgcp2[%d]=%f\n", i, ogcp2[i] );
1087 for( i=1; i<lasti; i++ )
1090 #ifdef enablemultithread
1091 // fprintf( stderr, "chudan = %d, %d\n", *chudanpt, chudanref );
1092 if( chudanpt && *chudanpt != chudanref )
1094 // fprintf( stderr, "\n\n## CHUUDAN!!! i\n" );
1101 previousw = currentw;
1104 previousw[0] = initverticalw[i-1];
1106 match_calc( currentw, cpmx1, cpmx2, i, lgth2, floatwork, intwork, 0 );
1108 fprintf( stderr, "\n" );
1109 fprintf( stderr, "i=%d\n", i );
1110 fprintf( stderr, "currentw = \n" );
1111 for( j=0; j<lgth2; j++ )
1113 fprintf( stderr, "%5.2f ", currentw[j] );
1115 fprintf( stderr, "\n" );
1119 // fprintf( stderr, "Calling imp_match_calc (o) lgth = %d, i = %d\n", lgth1, i );
1120 // imp_match_out_vead( currentw, i, lgth2 );
1121 part_imp_match_out_vead_gapmap( currentw, gapmap1[i]+start1, lgth2, start2, gapmap2 );
1124 fprintf( stderr, "\n" );
1125 fprintf( stderr, "i=%d\n", i );
1126 fprintf( stderr, "currentw = \n" );
1127 for( j=0; j<lgth2; j++ )
1129 fprintf( stderr, "%5.2f ", currentw[j] );
1131 fprintf( stderr, "\n" );
1133 currentw[0] = initverticalw[i];
1136 mi = previousw[0] + ogcp2[1]; mpi = 0;
1141 curpt = currentw + 1;
1145 fgcp1va = fgcp1[i-1];
1147 for( j=1; j<lastj; j++ )
1149 #ifdef xxxenablemultithread
1150 // fprintf( stderr, "chudan = %d, %d\n", *chudanpt, chudanref );
1151 if( chudanpt && *chudanpt != chudanref )
1153 // fprintf( stderr, "\n\n## CHUUDAN!!! j\n" );
1162 fprintf( stderr, "%5.0f->", wm );
1166 fprintf( stderr, "%5.0f?", g );
1171 *ijppt = -( j - mpi );
1173 g = *prept + *ogcp2pt;
1183 g = *mjpt + fgcp1va;
1185 fprintf( stderr, "%5.0f?", g );
1190 *ijppt = +( i - *mpjpt );
1192 g = *prept + ogcp1va;
1199 m[j] += fpenalty_ex;
1203 fprintf( stderr, "%5.0f ", wm );
1214 lastverticalw[i] = currentw[lgth2-1];
1221 for( j=1; j<lgth2+1; j++ )
1222 currentw[j] -= offset * ( lgth2 - j ) / 2.0;
1223 for( i=1; i<lgth1+1; i++ )
1224 lastverticalw[i] -= offset * ( lgth1 - i / 2.0);
1229 fprintf( stderr, "\n" );
1230 for( i=0; i<icyc; i++ ) fprintf( stderr,"%s\n", seq1[i] );
1231 fprintf( stderr, "#####\n" );
1232 for( j=0; j<jcyc; j++ ) fprintf( stderr,"%s\n", seq2[j] );
1233 fprintf( stderr, "====>" );
1234 for( i=0; i<icyc; i++ ) strcpy( mseq1[i], seq1[i] );
1235 for( j=0; j<jcyc; j++ ) strcpy( mseq2[j], seq2[j] );
1239 Atracking_localhom( impmatch, currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc, start1, end1, start2, end2, gapmap1, gapmap2 );
1242 Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
1244 // fprintf( stderr, "### impmatch = %f\n", *impmatch );
1246 resultlen = strlen( mseq1[0] );
1247 if( alloclen < resultlen || resultlen > N )
1249 fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
1250 ErrorExit( "LENGTH OVER!\n" );
1254 for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
1255 for( j=0; j<jcyc; j++ ) strcpy( seq2[j], mseq2[j] );
1257 fprintf( stderr, "\n" );
1258 for( i=0; i<icyc; i++ ) fprintf( stderr, "%s\n", mseq1[i] );
1259 fprintf( stderr, "#####\n" );
1260 for( j=0; j<jcyc; j++ ) fprintf( stderr, "%s\n", mseq2[j] );