6 #define USE_PENALTY_EX 0
14 static void OpeningGapCount( float *ogcp, int clus, char **seq, double *eff, int len )
19 for( i=0; i<len; i++ ) ogcp[i] = 0.0;
20 for( j=0; j<clus; j++ )
24 for( i=0; i<len; i++ )
27 gc = ( seq[j][i] == '-' );
29 if( !gb * gc ) ogcp[i] += feff;
34 // for( i=0; i<len; i++ )
36 // fprintf( stderr, "ogcp[%d] = %30.20f\n", i, ogcp[i] );
37 // ogcp[i] /= totaleff;
41 static void FinalGapCount( float *fgcp, int clus, char **seq, double *eff, int len )
46 for( i=0; i<len+1; i++ ) fgcp[i] = 0.0;
47 for( j=0; j<clus; j++ )
50 gc = ( seq[j][0] == '-' );
51 for( i=1; i<len+1; i++ )
54 gc = ( seq[j][i] == '-' );
56 if( gb * !gc ) fgcp[i-1] += feff;
59 // totaleff += eff[j];
60 // fprintf( stderr, "eff[%d] = %30.20f\n", j, eff[j] );
62 // for( i=0; i<len; i++ )
64 // fgcp[i] /= totaleff;
65 // fprintf( stderr, "fgcp[%d] = %30.20f\n", i, fgcp[i] );
69 static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
73 float **cpmxpd = floatwork;
74 int **cpmxpdn = intwork;
79 for( j=0; j<lgth2; j++ )
86 cpmxpd[j][count] = cpmx2[j][l];
87 cpmxpdn[j][count] = l;
91 cpmxpdn[j][count] = -1;
100 scarr[l] += n_dis[k][l] * cpmx1[i1][k];
103 #if 0 /* ¤³¤ì¤ò»È¤¦¤È¤
\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
105 float *fpt, **fptpt, *fpt2;
113 ipt=*iptpt,fpt=*fptpt;
115 *fpt2 += scarr[*ipt++] * *fpt++;
116 fpt2++,iptpt++,fptpt++;
120 for( j=0; j<lgth2; j++ )
123 for( k=0; cpmxpdn[j][k]>-1; k++ )
124 match[j] += scarr[cpmxpdn[j][k]] * cpmxpd[j][k];
129 static float Atracking(
130 char **seq1, char **seq2,
131 char **mseq1, char **mseq2,
132 short **ijp, int icyc, int jcyc,
133 int ist, int ien, int jst, int jen )
135 int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, klim;
142 for( i=0; i<lgth1; i++ )
144 fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
149 // fprintf( stderr, "in Atracking, lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
151 for( i=0; i<lgth1+1; i++ )
155 for( j=0; j<lgth2+1; j++ )
157 ijp[0][j] = -( j + 1 );
161 for( i=0; i<icyc; i++ )
163 mseq1[i] += lgth1+lgth2;
166 for( j=0; j<jcyc; j++ )
168 mseq2[j] += lgth1+lgth2;
172 // if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
174 iin = lgth1; jin = lgth2;
176 for( k=0; k<=klim; k++ )
178 if( ijp[iin][jin] < 0 )
180 ifi = iin-1; jfi = jin+ijp[iin][jin];
182 else if( ijp[iin][jin] > 0 )
184 ifi = iin-ijp[iin][jin]; jfi = jin-1;
188 ifi = iin-1; jfi = jin-1;
193 for( i=0; i<icyc; i++ )
194 *--mseq1[i] = seq1[i][ist+ifi+l];
195 for( j=0; j<jcyc; j++ )
202 for( i=0; i<icyc; i++ )
204 for( j=0; j<jcyc; j++ )
205 *--mseq2[j] = seq2[j][jst+jfi+l];
208 if( iin <= 0 || jin <= 0 ) break;
209 for( i=0; i<icyc; i++ )
210 *--mseq1[i] = seq1[i][ist+ifi];
211 for( j=0; j<jcyc; j++ )
212 *--mseq2[j] = seq2[j][jst+jfi];
214 iin = ifi; jin = jfi;
216 // if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
218 // fprintf( stderr, "in Atracking (owari), mseq1 = %s\n", mseq1[0] );
219 // fprintf( stderr, "in Atracking (owari), mseq2 = %s\n", mseq2[0] );
223 static float MSalignmm_tanni( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, char **mseq1, char **mseq2, float **gapinfo )
224 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
231 float wm; /* int ?????? */
233 float *currentw, *previousw;
234 float fpenalty = (float)penalty;
235 float fpenalty_ex = (float)penalty_ex;
239 float *mjpt, *prept, *curpt;
246 float *initverticalw; /* kufuu sureba iranai */
247 float *lastverticalw; /* kufuu sureba iranai */
259 char **aseq1bk, **aseq2bk;
261 ogcp1 = gapinfo[0] + ist;
262 fgcp1 = gapinfo[1] + ist;
263 ogcp2 = gapinfo[2] + jst;
264 fgcp2 = gapinfo[3] + jst;
266 // char ttt1[10000], ttt2[10000];
272 // strncpy( ttt1, seq1[0]+ist, lgth1 ); ttt1[lgth1] = 0;
273 // strncpy( ttt2, seq2[0]+jst, lgth2 ); ttt2[lgth2] = 0;
275 // fprintf( stderr, "in _tanni ist,ien = %d,%d, lgth1=%d\n", ist, ien, lgth1 );
276 // fprintf( stderr, "in _tanni jst,jen = %d,%d, lgth2=%d\n", jst, jen, lgth2 );
277 // fprintf( stderr, "ttt1 = %s\n", ttt1 );
278 // fprintf( stderr, "ttt2 = %s\n", ttt2 );
281 ll1 = ( (int)(1.3*lgth1) ) + 100;
282 ll2 = ( (int)(1.3*lgth2) ) + 100;
284 aseq1 = AllocateCharMtx( icyc, 0 );
285 aseq2 = AllocateCharMtx( jcyc, 0 );
286 aseq1bk = AllocateCharMtx( icyc, lgth1+lgth2+100 );
287 aseq2bk = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
288 for( i=0; i<icyc; i++ ) aseq1[i] = aseq1bk[i];
289 for( i=0; i<jcyc; i++ ) aseq2[i] = aseq2bk[i];
291 w1 = AllocateFloatVec( ll2+2 );
292 w2 = AllocateFloatVec( ll2+2 );
294 initverticalw = AllocateFloatVec( ll1+2 );
295 lastverticalw = AllocateFloatVec( ll1+2 );
297 m = AllocateFloatVec( ll2+2 );
298 mp = AllocateIntVec( ll2+2 );
300 floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 27 );
301 intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 );
304 shortmtx = AllocateShortMtx( ll1+1, ll2+1 );
311 match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
313 match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
315 for( i=1; i<lgth1+1; i++ )
317 initverticalw[i] += fpenalty * ( ogcp1[0] + fgcp1[i-1] );
319 for( j=1; j<lgth2+1; j++ )
321 currentw[j] += fpenalty * ( ogcp2[0] + fgcp2[j-1] );
324 for( j=1; j<lgth2+1; ++j )
326 m[j] = currentw[j-1] + fpenalty * ogcp1[1]; mp[j] = 0;;
329 lastverticalw[0] = currentw[lgth2-1];
333 for( i=1; i<lasti; i++ )
337 previousw = currentw;
340 previousw[0] = initverticalw[i-1];
342 match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
343 currentw[0] = initverticalw[i];
345 mi = previousw[0] + fpenalty * ogcp2[1];
351 curpt = currentw + 1;
354 for( j=1; j<lastj; j++ )
360 fprintf( stderr, "%5.0f->", wm );
362 g = mi + fpenalty * fgcp2[j-1];
364 fprintf( stderr, "%5.0f?", g );
369 *ijppt = -( j - mpi );
371 g = *prept + fpenalty * ogcp2[j];
381 g = *mjpt + fpenalty * fgcp1[i-1];
383 fprintf( stderr, "%5.0f?", g );
388 *ijppt = +( i - *mpjpt );
390 g = *prept + fpenalty * ogcp1[i];
401 fprintf( stderr, "%5.0f ", wm );
412 lastverticalw[i] = currentw[lgth2-1];
415 // fprintf( stderr, "wm = %f\n", wm );
417 Atracking( seq1, seq2, aseq1, aseq2, ijp, icyc, jcyc, ist, ien, jst, jen );
419 for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
420 for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
422 // fprintf( stderr, "in _tanni, aseq1 = %s\n", aseq1[0] );
423 // fprintf( stderr, "in _tanni, mseq1 = %s\n", mseq1[0] );
427 FreeFloatVec( initverticalw );
428 FreeFloatVec( lastverticalw );
434 FreeFloatMtx( floatwork );
435 FreeIntMtx( intwork );
437 FreeShortMtx( shortmtx );
439 FreeCharMtx( aseq1bk );
440 FreeCharMtx( aseq2bk );
448 static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, char **mseq1, char **mseq2, int depth, float **gapinfo )
449 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
453 char **aseq1, **aseq2;
454 int ll1, ll2, l, len;
455 int lasti, lastj, imid, jmid;
457 float wm; /* int ?????? */
459 float *currentw, *previousw;
460 float fpenalty = (float)penalty;
461 float fpenalty_ex = (float)penalty_ex;
468 float *mjpt, *prept, *curpt;
473 float *initverticalw; /* kufuu sureba iranai */
474 float *lastverticalw; /* kufuu sureba iranai */
492 int *jumpdummi; //muda
493 int *jumpdummj; //muda
497 // float *ogcp1 = gapinfo[0];
498 // float *fgcp1 = gapinfo[1];
499 // float *ogcp2 = gapinfo[2];
500 // float *fgcp2 = gapinfo[3];
501 // static char ttt1[50000];
502 // static char ttt2[50000];
510 // fprintf( stderr, "==== MSalign (depth=%d, reccycle=%d), ist=%d, ien=%d, jst=%d, jen=%d\n", depth, reccycle, ist, ien, jst, jen );
511 // strncpy( ttt1, seq1[0]+ist, lgth1 );
512 // strncpy( ttt2, seq2[0]+jst, lgth2 );
515 // fprintf( stderr, "seq1 = %s\n", ttt1 );
516 // fprintf( stderr, "seq2 = %s\n", ttt2 );
519 fprintf( stderr, "==== jimei\n" );
520 for( i=0; i<icyc; i++ )
522 strncpy( mseq1[i], seq1[i]+ist, lgth1 );
525 for( i=0; i<jcyc; i++ )
528 for( j=0; j<lgth1; j++ )
529 strcat( mseq2[i], "-" );
532 // fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
533 // fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
535 return( (float)offset * lgth1 );
538 aseq1 = AllocateCharMtx( icyc, lgth1+lgth2+100 );
539 aseq2 = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
541 if( lgth1 < DPTANNI || lgth2 < DPTANNI )
543 // fprintf( stderr, "==== Going to _tanni\n" );
545 wm = MSalignmm_tanni( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ien, jst, jen, alloclen, aseq1, aseq2, gapinfo );
548 for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
549 for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
551 // fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
552 // fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
554 // fprintf( stderr, "freeing aseq\n" );
555 FreeCharMtx( aseq1 );
556 FreeCharMtx( aseq2 );
560 // fprintf( stderr, "Trying to divide the mtx\n" );
562 ll1 = ( (int)(1.3*lgth1) ) + 100;
563 ll2 = ( (int)(1.3*lgth2) ) + 100;
565 // fprintf( stderr, "ll1,ll2=%d,%d\n", ll1, ll2 );
567 w1 = AllocateFloatVec( ll2+2 );
568 w2 = AllocateFloatVec( ll2+2 );
569 // match = AllocateFloatVec( ll2+2 );
570 midw = AllocateFloatVec( ll2+2 );
571 midn = AllocateFloatVec( ll2+2 );
572 midm = AllocateFloatVec( ll2+2 );
573 jumpbacki = AllocateIntVec( ll2+2 );
574 jumpbackj = AllocateIntVec( ll2+2 );
575 jumpforwi = AllocateIntVec( ll2+2 );
576 jumpforwj = AllocateIntVec( ll2+2 );
577 jumpdummi = AllocateIntVec( ll2+2 );
578 jumpdummj = AllocateIntVec( ll2+2 );
580 initverticalw = AllocateFloatVec( ll1+2 );
581 lastverticalw = AllocateFloatVec( ll1+2 );
583 m = AllocateFloatVec( ll2+2 );
584 mp = AllocateIntVec( ll2+2 );
585 gaps = AllocateCharVec( MAX( ll1, ll2 ) + 2 );
587 floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 );
588 intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 );
591 fprintf( stderr, "succeeded\n" );
595 WMMTX = AllocateFloatMtx( ll1, ll2 );
596 WMMTX2 = AllocateFloatMtx( ll1, ll2 );
599 shortmtx = AllocateShortMtx( ll1, ll2 );
602 fprintf( stderr, "succeeded\n\n" );
611 match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
613 match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
615 for( i=1; i<lgth1+1; i++ )
617 // initverticalw[i] += fpenalty * ( ogcp1[0] + fgcp1[i-1] );
618 initverticalw[i] += fpenalty;
620 for( j=1; j<lgth2+1; j++ )
622 // currentw[j] += fpenalty * ( ogcp2[0] + fgcp2[j-1] );
623 currentw[j] += fpenalty;
627 WMMTX[0][0] = initverticalw[0];
628 for( i=1; i<lgth1+1; i++ )
630 WMMTX[i][0] = initverticalw[i];
632 for( j=1; j<lgth2+1; j++ )
634 WMMTX[0][j] = currentw[j];
638 for( j=1; j<lgth2+1; ++j )
640 // m[j] = currentw[j-1] + fpenalty * ogcp1[1];
641 m[j] = currentw[j-1];
645 lastverticalw[0] = currentw[lgth2-1];
649 jumpi = 0; // atode kawaru.
651 // for( i=1; i<lasti; i++ )
652 for( i=1; i<=imid; i++ )
655 previousw = currentw;
658 previousw[0] = initverticalw[i-1];
660 match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
661 currentw[0] = initverticalw[i];
664 // mi = previousw[0] + fpenalty * ogcp2[1];
668 // ijppt = ijp[i] + 1;
671 curpt = currentw + 1;
676 for( j=1; j<lastj; j++ )
683 fprintf( stderr, "%5.0f->", wm );
687 fprintf( stderr, "%5.0f?", g );
692 // *ijppt = -( j - mpi );
694 // g = *prept + fpenalty * ogcp2[j];
705 // g = *mjpt + fpenalty * fgcp1[i-1];
706 g = *mjpt + fpenalty;
708 fprintf( stderr, "%5.0f?", g );
713 // *ijppt = +( i - *mpjpt );
717 // g = *prept + fpenalty * ogcp1[i];
729 fprintf( stderr, "%5.0f ", wm );
734 WMMTX[i][j] = *curpt;
735 WMMTX2[i][j] = *mjpt;
738 if( i == imid ) //muda
740 jumpbackj[j] = *mpjpt; // muda atode matomeru
741 jumpbacki[j] = mpi; // muda atode matomeru
742 // fprintf( stderr, "jumpbackj[%d] in forward dp is %d\n", j, *mpjpt );
743 // fprintf( stderr, "jumpbacki[%d] in forward dp is %d\n", j, mpi );
755 lastverticalw[i] = currentw[lgth2-1];
759 for( j=0; j<lgth2; j++ ) midw[j] = currentw[j];
760 for( j=0; j<lgth2; j++ ) midm[j] = m[j];
764 // for( j=0; j<lgth2; j++ ) midw[j] = WMMTX[imid][j];
765 // for( j=0; j<lgth2; j++ ) midm[j] = WMMTX2[imid][j];
768 for( i=0; i<lgth1; i++ )
770 for( j=0; j<lgth2; j++ )
772 fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
774 fprintf( stderr, "\n" );
776 fprintf( stderr, "\n" );
777 fprintf( stderr, "WMMTX2 = \n" );
778 for( i=0; i<lgth1; i++ )
780 for( j=0; j<lgth2; j++ )
782 fprintf( stderr, "% 10.2f ", WMMTX2[i][j] );
784 fprintf( stderr, "\n" );
786 fprintf( stderr, "\n" );
791 match_calc( initverticalw, cpmx2+jst, cpmx1+ist, lgth2-1, lgth1, floatwork, intwork, 1 );
792 match_calc( currentw, cpmx1+ist, cpmx2+jst, lgth1-1, lgth2, floatwork, intwork, 1 );
794 for( i=0; i<lgth1-1; i++ )
796 // initverticalw[i] += fpenalty * ( fgcp1[lgth1-1] + ogcp1[i+1] );
797 initverticalw[i] += fpenalty;
799 for( j=0; j<lgth2-1; j++ )
801 // currentw[j] += fpenalty * ( fgcp2[lgth1-1] + ogcp2[j+1] );
802 currentw[j] += fpenalty;
806 for( i=0; i<lgth1-1; i++ )
808 WMMTX[i][lgth2-1] += fpenalty;
810 for( j=0; j<lgth2-1; j++ )
812 WMMTX[lgth1-1][j] += fpenalty;
816 for( j=lgth2-1; j>0; --j )
818 // m[j-1] = currentw[j] + fpenalty * fgcp2[lgth2-2];
819 m[j-1] = currentw[j];
823 // for( j=0; j<lgth2; j++ ) m[j] = 0.0;
824 // m[lgth2-1] ha irunoka?
826 // for( i=lgth1-2; i>=imid; i-- )
827 for( i=lgth1-2; i>-1; i-- )
830 previousw = currentw;
832 previousw[lgth2-1] = initverticalw[i+1];
833 // match_calc( currentw, seq1, seq2, i, lgth2 );
834 match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
836 currentw[lgth2-1] = initverticalw[i];
838 // mi = previousw[lgth2-1] + fpenalty * fgcp2[lgth2-2];
839 mi = previousw[lgth2-1];
842 mjpt = m + lgth2 - 2;
843 prept = previousw + lgth2 - 1;
844 curpt = currentw + lgth2 - 2;
845 mpjpt = mp + lgth2 - 2;
848 for( j=lgth2-2; j>-1; j-- )
854 // g = mi + fpenalty * ogcp2[j+1];
862 // g = *prept + fpenalty + fgcp2[j];
866 // fprintf( stderr, "i,j=%d,%d - renewed! mpi = %d\n", i, j, j+1 );
875 // fprintf( stderr, "i,j=%d,%d *mpjpt = %d\n", i, j, *mpjpt );
876 // g = *mjpt + fpenalty * ogcp1[i+1];
877 g = *mjpt + fpenalty;
884 // if( i == imid )fprintf( stderr, "i,j=%d,%d \n", i, j );
885 // g = *prept + fpenalty * fgcp1[i];
897 if( i == jumpi || i == imid - 1 )
899 jumpforwi[j] = ijpi; //muda
900 jumpforwj[j] = ijpj; //muda
901 // fprintf( stderr, "jumpfori[%d] = %d\n", j, ijpi );
902 // fprintf( stderr, "jumpforj[%d] = %d\n", j, ijpj );
904 if( i == imid ) // muda
907 midm[j+1] += *mjpt + fpenalty; //??????
911 midn[j] += mi + fpenalty; //????
915 WMMTX2[i][j+1] += *mjpt + fpenalty;
929 for( j=2; j<lgth2; j++ )
944 // fprintf( stderr, "imid=%d, jmid=%d\n", imid, jmid );
950 if( midm[jmid] > wm )
952 jumpi = jumpbackj[jmid];
955 if( midn[jmid-1] >= wm )
958 jumpj = jumpbacki[jmid];
961 fprintf( stderr, "imid = %d\n", imid );
962 fprintf( stderr, "midn = \n" );
963 for( j=0; j<lgth2; j++ )
965 fprintf( stderr, "% 10.2f ", midn[j] );
967 fprintf( stderr, "\n" );
968 fprintf( stderr, "midw = \n" );
969 for( j=0; j<lgth2; j++ )
971 fprintf( stderr, "% 10.2f ", midw[j] );
973 fprintf( stderr, "\n" );
974 fprintf( stderr, "midm = \n" );
975 for( j=0; j<lgth2; j++ )
977 fprintf( stderr, "% 10.2f ", midm[j] );
979 fprintf( stderr, "\n" );
982 if( i == jumpi ) //saki?
984 // fprintf( stderr, "imid, jumpi = %d,%d\n", imid, jumpi );
985 // fprintf( stderr, "jmid, jumpj = %d,%d\n", jmid, jumpj );
986 imid = jumpforwi[jumpj];
987 jmid = jumpforwj[jumpj];
988 // fprintf( stderr, "imid -> %d\n", imid );
989 // fprintf( stderr, "jmid -> %d\n", jmid );
993 // fprintf( stderr, "imid = %d, but jumpi = %d\n", imid, jumpi );
994 // fprintf( stderr, "jmid = %d, but jumpj = %d\n", jmid, jumpj );
996 // for( j=0; j<lgth2; j++ ) midw[j] += currentw[j];
997 // for( j=0; j<lgth2; j++ ) midm[j] += m[j+1];
998 // for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
999 // for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
1003 fprintf( stderr, "WMMTX = \n" );
1004 for( i=0; i<lgth1; i++ )
1006 fprintf( stderr, "%d ", i );
1007 for( j=0; j<lgth2; j++ )
1009 fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
1011 fprintf( stderr, "\n" );
1013 fprintf( stderr, "WMMTX2 = (p = %f)\n", fpenalty );
1014 for( i=0; i<lgth1; i++ )
1016 fprintf( stderr, "%d ", i );
1017 for( j=0; j<lgth2; j++ )
1019 fprintf( stderr, "% 10.2f ", WMMTX2[i][j] );
1021 fprintf( stderr, "\n" );
1024 fprintf( stderr, "jumpbacki = \n" );
1025 for( j=0; j<lgth2; j++ )
1027 fprintf( stderr, "% 10d ", jumpbacki[j] );
1029 fprintf( stderr, "\n" );
1030 fprintf( stderr, "jumpbackj = \n" );
1031 for( j=0; j<lgth2; j++ )
1033 fprintf( stderr, "% 10d ", jumpbackj[j] );
1035 fprintf( stderr, "\n" );
1036 fprintf( stderr, "jumpforwi = \n" );
1037 for( j=0; j<lgth2; j++ )
1039 fprintf( stderr, "% 10d ", jumpforwi[j] );
1041 fprintf( stderr, "\n" );
1042 fprintf( stderr, "jumpforwj = \n" );
1043 for( j=0; j<lgth2; j++ )
1045 fprintf( stderr, "% 10d ", jumpforwj[j] );
1047 fprintf( stderr, "\n" );
1052 // Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
1055 resultlen = strlen( mseq1[0] );
1056 if( alloclen < resultlen || resultlen > N )
1058 fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
1059 ErrorExit( "LENGTH OVER!\n" );
1066 fprintf( stderr, "jumpi = %d, imid = %d\n", jumpi, imid );
1067 fprintf( stderr, "jumpj = %d, jmid = %d\n", jumpj, jmid );
1069 fprintf( stderr, "imid = %d\n", imid );
1070 fprintf( stderr, "jmid = %d\n", jmid );
1076 FreeFloatVec( initverticalw );
1077 FreeFloatVec( lastverticalw );
1078 FreeFloatVec( midw );
1079 FreeFloatVec( midm );
1080 FreeFloatVec( midn );
1082 FreeIntVec( jumpbacki );
1083 FreeIntVec( jumpbackj );
1084 FreeIntVec( jumpforwi );
1085 FreeIntVec( jumpforwj );
1086 FreeIntVec( jumpdummi );
1087 FreeIntVec( jumpdummj );
1092 FreeFloatMtx( floatwork );
1093 FreeIntMtx( intwork );
1096 FreeFloatMtx( WMMTX );
1097 FreeFloatMtx( WMMTX2 );
1100 // fprintf( stderr, "==== calling myself (first)\n" );
1102 MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ist+jumpi, jst, jst+jumpj, alloclen, aseq1, aseq2, depth, gapinfo );
1103 for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
1104 for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
1106 // fprintf( stderr, "====(f) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
1107 // fprintf( stderr, "====(f) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
1109 len = strlen( mseq1[0] );
1110 // fprintf( stderr, "len = %d\n", len );
1111 l = jmid - jumpj - 1;
1112 // fprintf( stderr, "l=%d\n", l );
1115 for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
1116 for( i=0; i<icyc; i++ )
1118 strcat( mseq1[i], gaps );
1119 mseq1[i][len+l] = 0;
1121 for( j=0; j<jcyc; j++ )
1123 strncat( mseq2[j], seq2[j]+jst+jumpj+1, l );
1124 mseq2[j][len+l] = 0;
1127 len = strlen( mseq1[0] );
1128 l = imid - jumpi - 1;
1129 // fprintf( stderr, "l=%d\n", l );
1132 for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
1133 for( i=0; i<icyc; i++ )
1135 strncat( mseq1[i], seq1[i]+ist+jumpi+1, l );
1136 mseq1[i][len+l] = 0;
1138 for( j=0; j<jcyc; j++ )
1140 strcat( mseq2[j], gaps );
1141 mseq2[j][len+l] = 0;
1145 fprintf( stderr, "after gapfill mseq1[0]=%s\n", mseq1[0] );
1146 fprintf( stderr, "after gapfill mseq2[0]=%s\n", mseq2[0] );
1149 // fprintf( stderr, "==== calling myself (second)\n" );
1151 MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist+imid, ien, jst+jmid, jen, alloclen, aseq1, aseq2, depth, gapinfo );
1153 for( i=0; i<icyc; i++ ) strcat( mseq1[i], aseq1[i] );
1154 for( i=0; i<jcyc; i++ ) strcat( mseq2[i], aseq2[i] );
1156 // fprintf( stderr, "====(s) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
1157 // fprintf( stderr, "====(s) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
1159 // fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
1160 // fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
1163 FreeCharMtx( aseq1 );
1164 FreeCharMtx( aseq2 );
1171 float MSalignmm( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen )
1172 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
1178 float wm; /* int ?????? */
1191 fprintf( stderr, "eff in SA+++align\n" );
1192 for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
1195 lgth1 = strlen( seq1[0] );
1196 lgth2 = strlen( seq2[0] );
1198 ll1 = ( (int)(1.3*lgth1) ) + 100;
1199 ll2 = ( (int)(1.3*lgth2) ) + 100;
1201 mseq1 = AllocateCharMtx( icyc, ll1+ll2 );
1202 mseq2 = AllocateCharMtx( jcyc, ll1+ll2 );
1204 gapinfo = AllocateFloatMtx( 4, 0 );
1205 ogcp1 = AllocateFloatVec( ll1+2 );
1206 ogcp2 = AllocateFloatVec( ll2+2 );
1207 fgcp1 = AllocateFloatVec( ll1+2 );
1208 fgcp2 = AllocateFloatVec( ll2+2 );
1210 cpmx1 = AllocateFloatMtx( ll1+2, 27 );
1211 cpmx2 = AllocateFloatMtx( ll2+2, 27 );
1213 for( i=0; i<icyc; i++ )
1217 for( j=0; j<jcyc; j++ )
1222 MScpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
1223 MScpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
1227 OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1 );
1228 OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2 );
1229 FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1 );
1230 FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2 );
1233 for( i=0; i<lgth1; i++ )
1235 ogcp1[i] = 0.5 * ( 1.0 - ogcp1[i] );
1236 fgcp1[i] = 0.5 * ( 1.0 - fgcp1[i] );
1238 for( i=0; i<lgth2; i++ )
1240 ogcp2[i] = 0.5 * ( 1.0 - ogcp2[i] );
1241 fgcp2[i] = 0.5 * ( 1.0 - fgcp2[i] );
1244 for( i=0; i<lgth1; i++ )
1249 for( i=0; i<lgth2; i++ )
1263 fprintf( stdout, "in MSalignmm.c\n" );
1264 for( i=0; i<icyc; i++ )
1266 fprintf( stdout, ">%d of GROUP1\n", i );
1267 fprintf( stdout, "%s\n", seq1[i] );
1269 for( i=0; i<jcyc; i++ )
1271 fprintf( stdout, ">%d of GROUP2\n", i );
1272 fprintf( stdout, "%s\n", seq2[i] );
1277 wm = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, 0, lgth1-1, 0, lgth2-1, alloclen, mseq1, mseq2, 0, gapinfo );
1279 for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
1280 for( i=0; i<jcyc; i++ ) strcpy( seq2[i], mseq2[i] );
1283 FreeFloatVec( ogcp1 );
1284 FreeFloatVec( ogcp2 );
1285 FreeFloatVec( fgcp1 );
1286 FreeFloatVec( fgcp2 );
1287 FreeFloatMtx( cpmx1 );
1288 FreeFloatMtx( cpmx2 );
1289 free( (void *)gapinfo );
1291 FreeCharMtx( mseq1 );
1292 FreeCharMtx( mseq2 );