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 // gc = ( gappat[j] == '-' );
25 for( i=0; i<len; i++ )
28 gc = ( seq[j][i] == '-' );
30 if( !gb * gc ) ogcp[i] += feff;
34 // for( i=0; i<len; i++ )
36 // fprintf( stderr, "ogcp[%d] = %30.20f\n", i, ogcp[i] );
40 static void FinalGapCount( float *fgcp, int clus, char **seq, double *eff, int len )
45 for( i=0; i<len; i++ ) fgcp[i] = 0.0;
46 for( j=0; j<clus; j++ )
49 // gc = ( seq[j][0] == '-' );
51 for( i=1; i<len; i++ )
54 gc = ( seq[j][i] == '-' );
66 // fprintf( stderr, "changed gc=%d, gb=%d\n", gc, gb );
67 if( gb * !gc ) fgcp[i-1] += feff;
70 // fprintf( stderr, "eff[%d] = %30.20f\n", j, eff[j] );
72 // for( i=0; i<len; i++ )
74 // fprintf( stderr, "fgcp[%d] = %30.20f\n", i, fgcp[i] );
78 static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
82 float **cpmxpd = floatwork;
83 int **cpmxpdn = intwork;
88 for( j=0; j<lgth2; j++ )
95 cpmxpd[j][count] = cpmx2[j][l];
96 cpmxpdn[j][count] = l;
100 cpmxpdn[j][count] = -1;
104 for( l=0; l<26; l++ )
107 for( k=0; k<26; k++ )
109 scarr[l] += n_dis[k][l] * cpmx1[i1][k];
112 #if 0 /* ¤³¤ì¤ò»È¤¦¤È¤
\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
114 float *fpt, **fptpt, *fpt2;
122 ipt=*iptpt,fpt=*fptpt;
124 *fpt2 += scarr[*ipt++] * *fpt++;
125 fpt2++,iptpt++,fptpt++;
129 for( j=0; j<lgth2; j++ )
132 for( k=0; cpmxpdn[j][k]>-1; k++ )
133 match[j] += scarr[cpmxpdn[j][k]] * cpmxpd[j][k];
138 static float Atracking(
139 char **seq1, char **seq2,
140 char **mseq1, char **mseq2,
141 short **ijp, int icyc, int jcyc,
142 int ist, int ien, int jst, int jen )
144 int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, klim;
151 for( i=0; i<lgth1; i++ )
153 fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
158 // fprintf( stderr, "in Atracking, lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
160 for( i=0; i<lgth1+1; i++ )
164 for( j=0; j<lgth2+1; j++ )
166 ijp[0][j] = -( j + 1 );
170 for( i=0; i<icyc; i++ )
172 mseq1[i] += lgth1+lgth2;
175 for( j=0; j<jcyc; j++ )
177 mseq2[j] += lgth1+lgth2;
181 // if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
183 iin = lgth1; jin = lgth2;
185 for( k=0; k<=klim; k++ )
187 if( ijp[iin][jin] < 0 )
189 ifi = iin-1; jfi = jin+ijp[iin][jin];
191 else if( ijp[iin][jin] > 0 )
193 ifi = iin-ijp[iin][jin]; jfi = jin-1;
197 ifi = iin-1; jfi = jin-1;
202 for( i=0; i<icyc; i++ )
203 *--mseq1[i] = seq1[i][ist+ifi+l];
204 for( j=0; j<jcyc; j++ )
211 for( i=0; i<icyc; i++ )
213 for( j=0; j<jcyc; j++ )
214 *--mseq2[j] = seq2[j][jst+jfi+l];
217 if( iin <= 0 || jin <= 0 ) break;
218 for( i=0; i<icyc; i++ )
219 *--mseq1[i] = seq1[i][ist+ifi];
220 for( j=0; j<jcyc; j++ )
221 *--mseq2[j] = seq2[j][jst+jfi];
223 iin = ifi; jin = jfi;
225 // if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
227 // fprintf( stderr, "in Atracking (owari), mseq1 = %s\n", mseq1[0] );
228 // fprintf( stderr, "in Atracking (owari), mseq2 = %s\n", mseq2[0] );
232 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 )
233 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
240 float wm; /* int ?????? */
242 float *currentw, *previousw;
243 float fpenalty = (float)penalty;
244 float fpenalty_ex = (float)penalty_ex;
248 float *mjpt, *prept, *curpt;
255 float *initverticalw; /* kufuu sureba iranai */
256 float *lastverticalw; /* kufuu sureba iranai */
268 char **aseq1bk, **aseq2bk;
270 ogcp1 = gapinfo[0] + ist;
271 fgcp1 = gapinfo[1] + ist;
272 ogcp2 = gapinfo[2] + jst;
273 fgcp2 = gapinfo[3] + jst;
276 char ttt1[10000], ttt2[10000];
284 strncpy( ttt1, seq1[0]+ist, lgth1 ); ttt1[lgth1] = 0;
285 strncpy( ttt2, seq2[0]+jst, lgth2 ); ttt2[lgth2] = 0;
287 fprintf( stderr, "in _tanni ist,ien = %d,%d, lgth1=%d\n", ist, ien, lgth1 );
288 fprintf( stderr, "in _tanni jst,jen = %d,%d, lgth2=%d\n", jst, jen, lgth2 );
289 fprintf( stderr, "ttt1 = %s\n", ttt1 );
290 fprintf( stderr, "ttt2 = %s\n", ttt2 );
294 ll1 = ( (int)(1.3*lgth1) ) + 100;
295 ll2 = ( (int)(1.3*lgth2) ) + 100;
297 aseq1 = AllocateCharMtx( icyc, 0 );
298 aseq2 = AllocateCharMtx( jcyc, 0 );
299 aseq1bk = AllocateCharMtx( icyc, lgth1+lgth2+100 );
300 aseq2bk = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
301 for( i=0; i<icyc; i++ ) aseq1[i] = aseq1bk[i];
302 for( i=0; i<jcyc; i++ ) aseq2[i] = aseq2bk[i];
304 w1 = AllocateFloatVec( ll2+2 );
305 w2 = AllocateFloatVec( ll2+2 );
307 initverticalw = AllocateFloatVec( ll1+2 );
308 lastverticalw = AllocateFloatVec( ll1+2 );
310 m = AllocateFloatVec( ll2+2 );
311 mp = AllocateIntVec( ll2+2 );
313 floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 27 );
314 intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 );
317 shortmtx = AllocateShortMtx( ll1+1, ll2+1 );
324 match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
326 match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
328 for( i=1; i<lgth1+1; i++ )
330 initverticalw[i] += fpenalty * ( ogcp1[0] + fgcp1[i-1] );
332 for( j=1; j<lgth2+1; j++ )
334 currentw[j] += fpenalty * ( ogcp2[0] + fgcp2[j-1] );
337 for( j=1; j<lgth2+1; ++j )
339 m[j] = currentw[j-1] + fpenalty * ogcp1[1]; mp[j] = 0;;
342 lastverticalw[0] = currentw[lgth2-1];
347 for( i=1; i<lasti; i++ )
351 previousw = currentw;
354 previousw[0] = initverticalw[i-1];
356 match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
357 currentw[0] = initverticalw[i];
359 mi = previousw[0] + fpenalty * ogcp2[1];
365 curpt = currentw + 1;
368 for( j=1; j<lastj; j++ )
374 fprintf( stderr, "%5.0f->", wm );
376 g = mi + fpenalty * fgcp2[j-1];
378 fprintf( stderr, "%5.0f?", g );
383 *ijppt = -( j - mpi );
385 g = *prept + fpenalty * ogcp2[j];
395 g = *mjpt + fpenalty * fgcp1[i-1];
397 fprintf( stderr, "%5.0f?", g );
402 *ijppt = +( i - *mpjpt );
404 g = *prept + fpenalty * ogcp1[i];
415 fprintf( stderr, "%5.0f ", wm );
426 lastverticalw[i] = currentw[lgth2-1];
429 // fprintf( stderr, "wm = %f\n", wm );
431 Atracking( seq1, seq2, aseq1, aseq2, ijp, icyc, jcyc, ist, ien, jst, jen );
433 for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
434 for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
436 // fprintf( stderr, "in _tanni, aseq1 = %s\n", aseq1[0] );
437 // fprintf( stderr, "in _tanni, mseq1 = %s\n", mseq1[0] );
441 FreeFloatVec( initverticalw );
442 FreeFloatVec( lastverticalw );
448 FreeFloatMtx( floatwork );
449 FreeIntMtx( intwork );
451 FreeShortMtx( shortmtx );
453 FreeCharMtx( aseq1bk );
454 FreeCharMtx( aseq2bk );
463 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 )
464 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
469 char **aseq1, **aseq2;
470 int ll1, ll2, l, len;
471 int lasti, lastj, imid, jmid;
473 float wm; /* int ?????? */
475 float *currentw, *previousw;
476 float fpenalty = (float)penalty;
477 float fpenalty_ex = (float)penalty_ex;
484 float *mjpt, *prept, *curpt;
489 float *initverticalw; /* kufuu sureba iranai */
490 float *lastverticalw; /* kufuu sureba iranai */
508 int *jumpdummi; //muda
509 int *jumpdummj; //muda
518 static char ttt1[50000];
519 static char ttt2[50000];
523 ogcp1 = gapinfo[0] + ist;
524 fgcp1 = gapinfo[1] + ist;
525 ogcp2 = gapinfo[2] + jst;
526 fgcp2 = gapinfo[3] + jst;
537 fprintf( stderr, "==== MSalign (depth=%d, reccycle=%d), ist=%d, ien=%d, jst=%d, jen=%d\n", depth, reccycle, ist, ien, jst, jen );
538 strncpy( ttt1, seq1[0]+ist, lgth1 );
539 strncpy( ttt2, seq2[0]+jst, lgth2 );
542 fprintf( stderr, "seq1 = %s\n", ttt1 );
543 fprintf( stderr, "seq2 = %s\n", ttt2 );
547 fprintf( stderr, "==== jimei\n" );
549 for( i=0; i<icyc; i++ )
551 strncpy( mseq1[i], seq1[i]+ist, lgth1 );
554 for( i=0; i<jcyc; i++ )
557 for( j=0; j<lgth1; j++ )
558 strcat( mseq2[i], "-" );
561 // fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
562 // fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
564 return( (float)offset * lgth1 );
567 aseq1 = AllocateCharMtx( icyc, lgth1+lgth2+100 );
568 aseq2 = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
570 if( lgth1 < DPTANNI || lgth2 < DPTANNI )
572 // fprintf( stderr, "==== Going to _tanni\n" );
574 value = MSalignmm_tanni( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ien, jst, jen, alloclen, aseq1, aseq2, gapinfo );
577 for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
578 for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
580 // fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
581 // fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
583 // fprintf( stderr, "freeing aseq\n" );
584 FreeCharMtx( aseq1 );
585 FreeCharMtx( aseq2 );
587 // fprintf( stderr, "value = %f\n", value );
591 // fprintf( stderr, "Trying to divide the mtx\n" );
593 ll1 = ( (int)(1.3*lgth1) ) + 100;
594 ll2 = ( (int)(1.3*lgth2) ) + 100;
596 // fprintf( stderr, "ll1,ll2=%d,%d\n", ll1, ll2 );
598 w1 = AllocateFloatVec( ll2+2 );
599 w2 = AllocateFloatVec( ll2+2 );
600 // match = AllocateFloatVec( ll2+2 );
601 midw = AllocateFloatVec( ll2+2 );
602 midn = AllocateFloatVec( ll2+2 );
603 midm = AllocateFloatVec( ll2+2 );
604 jumpbacki = AllocateIntVec( ll2+2 );
605 jumpbackj = AllocateIntVec( ll2+2 );
606 jumpforwi = AllocateIntVec( ll2+2 );
607 jumpforwj = AllocateIntVec( ll2+2 );
608 jumpdummi = AllocateIntVec( ll2+2 );
609 jumpdummj = AllocateIntVec( ll2+2 );
611 initverticalw = AllocateFloatVec( ll1+2 );
612 lastverticalw = AllocateFloatVec( ll1+2 );
614 m = AllocateFloatVec( ll2+2 );
615 mp = AllocateIntVec( ll2+2 );
616 gaps = AllocateCharVec( MAX( ll1, ll2 ) + 2 );
618 floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 );
619 intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 );
622 fprintf( stderr, "succeeded\n" );
626 WMMTX = AllocateFloatMtx( ll1, ll2 );
627 WMMTX2 = AllocateFloatMtx( ll1, ll2 );
630 shortmtx = AllocateShortMtx( ll1, ll2 );
633 fprintf( stderr, "succeeded\n\n" );
642 match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
644 match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
646 for( i=1; i<lgth1+1; i++ )
648 initverticalw[i] += fpenalty * ( ogcp1[0] + fgcp1[i-1] );
649 // initverticalw[i] += fpenalty;
651 for( j=1; j<lgth2+1; j++ )
653 currentw[j] += fpenalty * ( ogcp2[0] + fgcp2[j-1] );
654 // currentw[j] += fpenalty;
658 WMMTX[0][0] = initverticalw[0];
659 for( i=1; i<lgth1+1; i++ )
661 WMMTX[i][0] = initverticalw[i];
663 for( j=1; j<lgth2+1; j++ )
665 WMMTX[0][j] = currentw[j];
669 for( j=1; j<lgth2+1; ++j )
671 m[j] = currentw[j-1] + fpenalty * ogcp1[1];
672 // m[j] = currentw[j-1];
676 lastverticalw[0] = currentw[lgth2-1];
680 jumpi = 0; // atode kawaru.
683 for( i=1; i<lasti; i++ )
685 for( i=1; i<=imid; i++ )
689 previousw = currentw;
692 previousw[0] = initverticalw[i-1];
694 match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
695 currentw[0] = initverticalw[i];
698 mi = previousw[0] + fpenalty * ogcp2[1];
699 // mi = previousw[0];
702 // ijppt = ijp[i] + 1;
705 curpt = currentw + 1;
710 for( j=1; j<lastj; j++ )
716 fprintf( stderr, "%5.0f->", wm );
718 g = mi + fpenalty * fgcp2[j-1];
719 // g = mi + fpenalty;
721 fprintf( stderr, "%5.0f?", g );
726 // *ijppt = -( j - mpi );
728 g = *prept + fpenalty * ogcp2[j];
739 g = *mjpt + fpenalty * fgcp1[i-1];
740 // g = *mjpt + fpenalty;
742 fprintf( stderr, "%5.0f?", g );
747 // *ijppt = +( i - *mpjpt );
751 g = *prept + fpenalty * ogcp1[i];
763 fprintf( stderr, "%5.0f ", wm );
768 WMMTX[i][j] = *curpt;
769 WMMTX2[i][j] = *mjpt;
772 if( i == imid ) //muda
774 jumpbackj[j] = *mpjpt; // muda atode matomeru
775 jumpbacki[j] = mpi; // muda atode matomeru
776 // fprintf( stderr, "jumpbackj[%d] in forward dp is %d\n", j, *mpjpt );
777 // fprintf( stderr, "jumpbacki[%d] in forward dp is %d\n", j, mpi );
789 lastverticalw[i] = currentw[lgth2-1];
793 for( j=0; j<lgth2; j++ ) midw[j] = currentw[j];
794 for( j=0; j<lgth2; j++ ) midm[j] = m[j];
798 // for( j=0; j<lgth2; j++ ) midw[j] = WMMTX[imid][j];
799 // for( j=0; j<lgth2; j++ ) midm[j] = WMMTX2[imid][j];
802 for( i=0; i<lgth1; i++ )
804 for( j=0; j<lgth2; j++ )
806 fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
808 fprintf( stderr, "\n" );
810 fprintf( stderr, "\n" );
811 fprintf( stderr, "WMMTX2 = \n" );
812 for( i=0; i<lgth1; i++ )
814 for( j=0; j<lgth2; j++ )
816 fprintf( stderr, "% 10.2f ", WMMTX2[i][j] );
818 fprintf( stderr, "\n" );
820 fprintf( stderr, "\n" );
825 match_calc( initverticalw, cpmx2+jst, cpmx1+ist, lgth2-1, lgth1, floatwork, intwork, 1 );
826 match_calc( currentw, cpmx1+ist, cpmx2+jst, lgth1-1, lgth2, floatwork, intwork, 1 );
828 for( i=0; i<lgth1-1; i++ )
830 initverticalw[i] += fpenalty * ( fgcp1[lgth1-1] + ogcp1[i+1] );
831 // initverticalw[i] += fpenalty;
833 for( j=0; j<lgth2-1; j++ )
835 currentw[j] += fpenalty * ( fgcp2[lgth2-1] + ogcp2[j+1] );
836 // currentw[j] += fpenalty;
840 for( i=0; i<lgth1-1; i++ )
842 WMMTX[i][lgth2-1] += fpenalty * ( fgcp1[lgth1-1] + ogcp1[i+1] );
843 fprintf( stderr, "fgcp1[lgth1-1] + ogcp1[i+1] = %f\n", fgcp1[lgth1-1] + ogcp1[i+1] );
845 for( j=0; j<lgth2-1; j++ )
847 WMMTX[lgth1-1][j] += fpenalty * ( fgcp2[lgth2-1] + ogcp2[j+1] );
848 fprintf( stderr, "fgcp2[lgth2-1] + ogcp2[j+1] = %f\n", fgcp2[lgth2-1] + ogcp2[j+1] );
852 for( j=lgth2-1; j>0; --j )
854 m[j-1] = currentw[j] + fpenalty * fgcp2[lgth2-2];
855 // m[j-1] = currentw[j];
859 // for( j=0; j<lgth2; j++ ) m[j] = 0.0;
860 // m[lgth2-1] ha irunoka?
862 // for( i=lgth1-2; i>=imid; i-- )
863 for( i=lgth1-2; i>-1; i-- )
866 previousw = currentw;
868 previousw[lgth2-1] = initverticalw[i+1];
869 // match_calc( currentw, seq1, seq2, i, lgth2 );
870 match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
872 currentw[lgth2-1] = initverticalw[i];
874 mi = previousw[lgth2-1] + fpenalty * fgcp2[lgth2-2];
875 // mi = previousw[lgth2-1];
878 mjpt = m + lgth2 - 2;
879 prept = previousw + lgth2 - 1;
880 curpt = currentw + lgth2 - 2;
881 mpjpt = mp + lgth2 - 2;
884 for( j=lgth2-2; j>-1; j-- )
890 g = mi + fpenalty * ogcp2[j+1];
891 // g = mi + fpenalty;
898 g = *prept + fpenalty * fgcp2[j];
902 // fprintf( stderr, "i,j=%d,%d - renewed! mpi = %d\n", i, j, j+1 );
911 // fprintf( stderr, "i,j=%d,%d *mpjpt = %d\n", i, j, *mpjpt );
912 g = *mjpt + fpenalty * ogcp1[i+1];
913 // g = *mjpt + fpenalty;
920 // if( i == imid )fprintf( stderr, "i,j=%d,%d \n", i, j );
921 g = *prept + fpenalty * fgcp1[i];
933 if( i == jumpi || i == imid - 1 )
935 jumpforwi[j] = ijpi; //muda
936 jumpforwj[j] = ijpj; //muda
937 // fprintf( stderr, "jumpfori[%d] = %d\n", j, ijpi );
938 // fprintf( stderr, "jumpforj[%d] = %d\n", j, ijpj );
940 if( i == imid ) // muda
943 // midm[j+1] += *mjpt + fpenalty; //??????
944 midm[j+1] += *mjpt; //??????
948 // midn[j] += mi + fpenalty; //????
949 midn[j] += mi; //????
953 // WMMTX2[i][j+1] += *mjpt + fpenalty;
954 WMMTX2[i][j+1] += *mjpt;
967 // if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
968 for( j=2; j<lgth2-1; j++ )
978 // if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
980 for( j=1; j<lgth2; j++ )
987 jumpi = jumpbackj[jmid];
990 // if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
992 for( j=2; j<lgth2; j++ )
1000 jumpj = jumpbacki[jmid];
1002 // if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
1005 if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
1008 fprintf( stderr, "### imid=%d, jmid=%d\n", imid, jmid );
1012 if( midn[jmid-1] > wm )
1015 jumpj = jumpbacki[jmid];
1017 fprintf( stderr, "rejump (n)\n" );
1019 if( midm[jmid] > wm )
1021 jumpi = jumpbackj[jmid];
1024 fprintf( stderr, "rejump (m) jumpi=%d\n", jumpi );
1028 fprintf( stderr, "--> imid=%d, jmid=%d\n", imid, jmid );
1029 fprintf( stderr, "--> jumpi=%d, jumpj=%d\n", jumpi, jumpj );
1031 fprintf( stderr, "imid = %d\n", imid );
1032 fprintf( stderr, "midn = \n" );
1033 for( j=0; j<lgth2; j++ )
1035 fprintf( stderr, "% 7.1f ", midn[j] );
1037 fprintf( stderr, "\n" );
1038 fprintf( stderr, "midw = \n" );
1039 for( j=0; j<lgth2; j++ )
1041 fprintf( stderr, "% 7.1f ", midw[j] );
1043 fprintf( stderr, "\n" );
1044 fprintf( stderr, "midm = \n" );
1045 for( j=0; j<lgth2; j++ )
1047 fprintf( stderr, "% 7.1f ", midm[j] );
1049 fprintf( stderr, "\n" );
1051 // fprintf( stderr, "maxwm = %f\n", maxwm );
1054 if( i == jumpi ) //saki?
1056 // fprintf( stderr, "imid, jumpi = %d,%d\n", imid, jumpi );
1057 // fprintf( stderr, "jmid, jumpj = %d,%d\n", jmid, jumpj );
1058 imid = jumpforwi[jumpj];
1059 jmid = jumpforwj[jumpj];
1060 fprintf( stderr, "imid -> %d\n", imid );
1061 fprintf( stderr, "jmid -> %d\n", jmid );
1068 // fprintf( stderr, "imid = %d, but jumpi = %d\n", imid, jumpi );
1069 // fprintf( stderr, "jmid = %d, but jumpj = %d\n", jmid, jumpj );
1071 // for( j=0; j<lgth2; j++ ) midw[j] += currentw[j];
1072 // for( j=0; j<lgth2; j++ ) midm[j] += m[j+1];
1073 // for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
1074 // for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
1078 fprintf( stderr, "WMMTX = \n" );
1079 for( i=0; i<lgth1; i++ )
1081 fprintf( stderr, "%d ", i );
1082 for( j=0; j<lgth2; j++ )
1084 fprintf( stderr, "% 7.2f ", WMMTX[i][j] );
1086 fprintf( stderr, "\n" );
1088 fprintf( stderr, "WMMTX2 = (p = %f)\n", fpenalty );
1089 for( i=0; i<lgth1; i++ )
1091 fprintf( stderr, "%d ", i );
1092 for( j=0; j<lgth2; j++ )
1094 fprintf( stderr, "% 7.2f ", WMMTX2[i][j] );
1096 fprintf( stderr, "\n" );
1099 fprintf( stderr, "jumpbacki = \n" );
1100 for( j=0; j<lgth2; j++ )
1102 fprintf( stderr, "% 7d ", jumpbacki[j] );
1104 fprintf( stderr, "\n" );
1105 fprintf( stderr, "jumpbackj = \n" );
1106 for( j=0; j<lgth2; j++ )
1108 fprintf( stderr, "% 7d ", jumpbackj[j] );
1110 fprintf( stderr, "\n" );
1111 fprintf( stderr, "jumpforwi = \n" );
1112 for( j=0; j<lgth2; j++ )
1114 fprintf( stderr, "% 7d ", jumpforwi[j] );
1116 fprintf( stderr, "\n" );
1117 fprintf( stderr, "jumpforwj = \n" );
1118 for( j=0; j<lgth2; j++ )
1120 fprintf( stderr, "% 7d ", jumpforwj[j] );
1122 fprintf( stderr, "\n" );
1127 // Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
1130 resultlen = strlen( mseq1[0] );
1131 if( alloclen < resultlen || resultlen > N )
1133 fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
1134 ErrorExit( "LENGTH OVER!\n" );
1141 fprintf( stderr, "jumpi = %d, imid = %d\n", jumpi, imid );
1142 fprintf( stderr, "jumpj = %d, jmid = %d\n", jumpj, jmid );
1144 fprintf( stderr, "imid = %d\n", imid );
1145 fprintf( stderr, "jmid = %d\n", jmid );
1151 FreeFloatVec( initverticalw );
1152 FreeFloatVec( lastverticalw );
1153 FreeFloatVec( midw );
1154 FreeFloatVec( midm );
1155 FreeFloatVec( midn );
1157 FreeIntVec( jumpbacki );
1158 FreeIntVec( jumpbackj );
1159 FreeIntVec( jumpforwi );
1160 FreeIntVec( jumpforwj );
1161 FreeIntVec( jumpdummi );
1162 FreeIntVec( jumpdummj );
1167 FreeFloatMtx( floatwork );
1168 FreeIntMtx( intwork );
1171 FreeFloatMtx( WMMTX );
1172 FreeFloatMtx( WMMTX2 );
1175 // fprintf( stderr, "==== calling myself (first)\n" );
1177 fprintf( stderr, "jumpi = %d\n", jumpi );
1178 value = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ist+jumpi, jst, jst+jumpj, alloclen, aseq1, aseq2, depth, gapinfo );
1179 for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
1180 for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
1182 // fprintf( stderr, "====(f) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
1183 // fprintf( stderr, "====(f) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
1185 len = strlen( mseq1[0] );
1186 // fprintf( stderr, "len = %d\n", len );
1187 l = jmid - jumpj - 1;
1188 // fprintf( stderr, "l=%d\n", l );
1191 for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
1192 for( i=0; i<icyc; i++ )
1194 strcat( mseq1[i], gaps );
1195 mseq1[i][len+l] = 0;
1197 for( j=0; j<jcyc; j++ )
1199 strncat( mseq2[j], seq2[j]+jst+jumpj+1, l );
1200 mseq2[j][len+l] = 0;
1202 fprintf( stderr, "penalizing (2) .. %f(%d), %f(%d)\n", ogcp2[jumpj+1], jumpj+1, fgcp2[jmid-1], jmid-1 );
1203 value += fpenalty * ( ogcp2[jumpj+1] + fgcp2[jmid-1] );
1204 // value += fpenalty;
1206 len = strlen( mseq1[0] );
1207 l = imid - jumpi - 1;
1208 // fprintf( stderr, "l=%d\n", l );
1211 for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
1212 for( i=0; i<icyc; i++ )
1214 strncat( mseq1[i], seq1[i]+ist+jumpi+1, l );
1215 mseq1[i][len+l] = 0;
1217 for( j=0; j<jcyc; j++ )
1219 strcat( mseq2[j], gaps );
1220 mseq2[j][len+l] = 0;
1223 // for( i=0; i<lgth1; i++ ) fprintf( stderr, "ogcp1[%d] = %f\n", i, ogcp1[i] );
1224 // for( i=0; i<lgth1; i++ ) fprintf( stderr, "fgcp1[%d] = %f\n", i, fgcp1[i] );
1227 fprintf( stderr, "penalizing (1) .. ogcp1[%d] = %f, fgcp1[%d] = %f\n", jumpi+1, ogcp1[jumpi+1], imid-1, fgcp1[imid-1] );
1228 value += fpenalty * ( ogcp1[jumpi+1] + fgcp1[imid-1] );
1229 // value += fpenalty;
1232 for( i=0; i<icyc; i++ ) fprintf( stderr, "after gapfill mseq1[%d]=%s\n", i, mseq1[i] );
1233 for( i=0; i<jcyc; i++ ) fprintf( stderr, "after gapfill mseq2[%d]=%s\n", i, mseq2[i] );
1236 // fprintf( stderr, "==== calling myself (second)\n" );
1238 value += MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist+imid, ien, jst+jmid, jen, alloclen, aseq1, aseq2, depth, gapinfo );
1242 if( value - maxwm > 1 || maxwm - value > 1 )
1244 fprintf( stderr, "WARNING value = %f, but maxwm = %f penalty = %f\n", value, maxwm, fpenalty );
1246 for( i=0; i<icyc; i++ )
1248 fprintf( stderr, ">1-%d\n%s\n", i, mseq1[i] );
1249 fprintf( stderr, "%s\n", aseq1[i] );
1251 for( i=0; i<jcyc; i++ )
1253 fprintf( stderr, ">2-%d\n%s\n", i, mseq2[i] );
1254 fprintf( stderr, "%s\n", aseq2[i] );
1262 fprintf( stderr, "value = %.0f, maxwm = %.0f -> ok\n", value, maxwm );
1265 for( i=0; i<icyc; i++ ) strcat( mseq1[i], aseq1[i] );
1266 for( i=0; i<jcyc; i++ ) strcat( mseq2[i], aseq2[i] );
1268 // fprintf( stderr, "====(s) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
1269 // fprintf( stderr, "====(s) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
1272 FreeCharMtx( aseq1 );
1273 FreeCharMtx( aseq2 );
1280 float MSalignmm( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen )
1281 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
1287 float wm; /* int ?????? */
1300 fprintf( stderr, "eff in SA+++align\n" );
1301 for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
1304 lgth1 = strlen( seq1[0] );
1305 lgth2 = strlen( seq2[0] );
1307 ll1 = ( (int)(1.3*lgth1) ) + 100;
1308 ll2 = ( (int)(1.3*lgth2) ) + 100;
1310 mseq1 = AllocateCharMtx( icyc, ll1+ll2 );
1311 mseq2 = AllocateCharMtx( jcyc, ll1+ll2 );
1313 gapinfo = AllocateFloatMtx( 4, 0 );
1314 ogcp1 = AllocateFloatVec( ll1+2 );
1315 ogcp2 = AllocateFloatVec( ll2+2 );
1316 fgcp1 = AllocateFloatVec( ll1+2 );
1317 fgcp2 = AllocateFloatVec( ll2+2 );
1320 cpmx1 = AllocateFloatMtx( ll1+2, 27 );
1321 cpmx2 = AllocateFloatMtx( ll2+2, 27 );
1323 for( i=0; i<icyc; i++ )
1327 for( j=0; j<jcyc; j++ )
1332 MScpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
1333 MScpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
1338 OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1 );
1339 OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2 );
1340 FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1 );
1341 FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2 );
1344 for( i=0; i<lgth1; i++ )
1346 ogcp1[i] = 0.5 * ( 1.0 - ogcp1[i] );
1347 fgcp1[i] = 0.5 * ( 1.0 - fgcp1[i] );
1348 // fprintf( stderr, "fgcp1[%d] = %f\n", i, fgcp1[i] );
1350 for( i=0; i<lgth2; i++ )
1352 ogcp2[i] = 0.5 * ( 1.0 - ogcp2[i] );
1353 fgcp2[i] = 0.5 * ( 1.0 - fgcp2[i] );
1354 // fprintf( stderr, "fgcp2[%d] = %f\n", i, fgcp2[i] );
1357 for( i=0; i<lgth1; i++ )
1362 for( i=0; i<lgth2; i++ )
1376 fprintf( stdout, "in MSalignmm.c\n" );
1377 for( i=0; i<icyc; i++ )
1379 fprintf( stdout, ">%d of GROUP1\n", i );
1380 fprintf( stdout, "%s\n", seq1[i] );
1382 for( i=0; i<jcyc; i++ )
1384 fprintf( stdout, ">%d of GROUP2\n", i );
1385 fprintf( stdout, "%s\n", seq2[i] );
1390 wm = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, 0, lgth1-1, 0, lgth2-1, alloclen, mseq1, mseq2, 0, gapinfo );
1392 // fprintf( stderr, "wm = %f\n", wm );
1394 for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
1395 for( i=0; i<jcyc; i++ ) strcpy( seq2[i], mseq2[i] );
1398 FreeFloatVec( ogcp1 );
1399 FreeFloatVec( ogcp2 );
1400 FreeFloatVec( fgcp1 );
1401 FreeFloatVec( fgcp2 );
1402 FreeFloatMtx( cpmx1 );
1403 FreeFloatMtx( cpmx2 );
1404 free( (void *)gapinfo );
1406 FreeCharMtx( mseq1 );
1407 FreeCharMtx( mseq2 );