7 #define USE_PENALTY_EX 0
13 static int reccycle = 0;
16 static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
20 float **cpmxpd = floatwork;
21 int **cpmxpdn = intwork;
30 for( j=0; j<lgth2; j++ )
37 cpmxpd[j][count] = cpmx2[j][l];
38 cpmxpdn[j][count] = l;
42 cpmxpdn[j][count] = -1;
51 scarr[l] += n_dis[k][l] * cpmx1[i1][k];
54 #if 0 /* ¤³¤ì¤ò»È¤¦¤È¤
\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
56 float *fpt, **fptpt, *fpt2;
64 ipt=*iptpt,fpt=*fptpt;
66 *fpt2 += scarr[*ipt++] * *fpt++;
67 fpt2++,iptpt++,fptpt++;
70 for( j=0; j<lgth2; j++ )
73 for( k=0; cpmxpdn[j][k]>-1; k++ )
74 match[j] += scarr[cpmxpdn[j][k]] * cpmxpd[j][k];
83 for( k=0; (cpkd=(*cpmxpdnpt)[k])>-1; k++ )
84 *matchpt += scarr[cpkd] * (*cpmxpdpt)[k];
92 static float Atracking(
93 char **seq1, char **seq2,
94 char **mseq1, char **mseq2,
95 int **ijp, int icyc, int jcyc,
96 int ist, int ien, int jst, int jen )
98 int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, klim;
99 char *gaptable1, *gt1bk;
100 char *gaptable2, *gt2bk;
104 gt1bk = AllocateCharVec( lgth1+lgth2+1 );
105 gt2bk = AllocateCharVec( lgth1+lgth2+1 );
108 for( i=0; i<lgth1; i++ )
110 fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
115 // fprintf( stderr, "in Atracking, lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
117 for( i=0; i<lgth1+1; i++ )
121 for( j=0; j<lgth2+1; j++ )
123 ijp[0][j] = -( j + 1 );
127 gaptable1 = gt1bk + lgth1+lgth2;
129 gaptable2 = gt2bk + lgth1+lgth2;
132 // if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
134 iin = lgth1; jin = lgth2;
136 for( k=0; k<=klim; k++ )
138 if( ijp[iin][jin] < 0 )
140 ifi = iin-1; jfi = jin+ijp[iin][jin];
142 else if( ijp[iin][jin] > 0 )
144 ifi = iin-ijp[iin][jin]; jfi = jin-1;
148 ifi = iin-1; jfi = jin-1;
164 if( iin <= 0 || jin <= 0 ) break;
168 iin = ifi; jin = jfi;
172 for( i=0; i<icyc; i++ ) gapireru( mseq1[i], seq1[i]+ist, gaptable1 );
173 for( j=0; j<jcyc; j++ ) gapireru( mseq2[j], seq2[j]+jst, gaptable2 );
178 // fprintf( stderr, "in Atracking (owari), mseq1 = %s\n", mseq1[0] );
179 // fprintf( stderr, "in Atracking (owari), mseq2 = %s\n", mseq2[0] );
183 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 )
184 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
190 float wm = 0.0; /* int ?????? */
192 float *currentw, *previousw;
194 float fpenalty_ex = (float)penalty_ex;
199 float *mjpt, *prept, *curpt;
206 float *initverticalw; /* kufuu sureba iranai */
207 float *lastverticalw; /* kufuu sureba iranai */
218 // char **aseq1bk, **aseq2bk;
220 ogcp1 = gapinfo[0] + ist;
221 fgcp1 = gapinfo[1] + ist;
222 ogcp2 = gapinfo[2] + jst;
223 fgcp2 = gapinfo[3] + jst;
226 char ttt1[10000], ttt2[10000];
234 strncpy( ttt1, seq1[0]+ist, lgth1 ); ttt1[lgth1] = 0;
235 strncpy( ttt2, seq2[0]+jst, lgth2 ); ttt2[lgth2] = 0;
237 fprintf( stderr, "in _tanni ist,ien = %d,%d, lgth1=%d\n", ist, ien, lgth1 );
238 fprintf( stderr, "in _tanni jst,jen = %d,%d, lgth2=%d\n", jst, jen, lgth2 );
239 fprintf( stderr, "ttt1 = %s\n", ttt1 );
240 fprintf( stderr, "ttt2 = %s\n", ttt2 );
244 ll1 = ( (int)(lgth1) ) + 100;
245 ll2 = ( (int)(lgth2) ) + 100;
247 // aseq1 = AllocateCharMtx( icyc, 0 );
248 // aseq2 = AllocateCharMtx( jcyc, 0 );
249 // aseq1bk = AllocateCharMtx( icyc, lgth1+lgth2+100 );
250 // aseq2bk = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
251 // for( i=0; i<icyc; i++ ) aseq1[i] = aseq1bk[i];
252 // for( i=0; i<jcyc; i++ ) aseq2[i] = aseq2bk[i];
254 w1 = AllocateFloatVec( ll2+2 );
255 w2 = AllocateFloatVec( ll2+2 );
257 initverticalw = AllocateFloatVec( ll1+2 );
258 lastverticalw = AllocateFloatVec( ll1+2 );
260 m = AllocateFloatVec( ll2+2 );
261 mp = AllocateIntVec( ll2+2 );
263 floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 27 );
264 intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 );
267 intmtx = AllocateIntMtx( ll1+1, ll2+1 );
274 match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
276 match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
278 for( i=1; i<lgth1+1; i++ )
280 initverticalw[i] += ( ogcp1[0] + fgcp1[i-1] );
282 for( j=1; j<lgth2+1; j++ )
284 currentw[j] += ( ogcp2[0] + fgcp2[j-1] );
287 for( j=1; j<lgth2+1; ++j )
289 m[j] = currentw[j-1] + ogcp1[1]; mp[j] = 0;;
292 lastverticalw[0] = currentw[lgth2-1];
297 for( i=1; i<lasti; i++ )
301 previousw = currentw;
304 previousw[0] = initverticalw[i-1];
306 match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
307 currentw[0] = initverticalw[i];
309 mi = previousw[0] + ogcp2[1];
315 curpt = currentw + 1;
318 for( j=1; j<lastj; j++ )
324 fprintf( stderr, "%5.0f->", wm );
328 fprintf( stderr, "%5.0f?", g );
333 *ijppt = -( j - mpi );
335 g = *prept + ogcp2[j];
345 g = *mjpt + fgcp1[i-1];
347 fprintf( stderr, "%5.0f?", g );
352 *ijppt = +( i - *mpjpt );
354 g = *prept + ogcp1[i];
365 fprintf( stderr, "%5.0f ", wm );
376 lastverticalw[i] = currentw[lgth2-1];
379 // fprintf( stderr, "wm = %f\n", wm );
381 Atracking( seq1, seq2, mseq1, mseq2, ijp, icyc, jcyc, ist, ien, jst, jen );
383 // for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
384 // for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
386 // fprintf( stderr, "in _tanni, aseq1 = %s\n", aseq1[0] );
387 // fprintf( stderr, "in _tanni, mseq1 = %s\n", mseq1[0] );
391 FreeFloatVec( initverticalw );
392 FreeFloatVec( lastverticalw );
398 FreeFloatMtx( floatwork );
399 FreeIntMtx( intwork );
401 FreeIntMtx( intmtx );
403 // FreeCharMtx( aseq1bk );
404 // FreeCharMtx( aseq2bk );
413 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 )
414 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
420 char **aseq1, **aseq2;
421 int ll1, ll2, l, len;
422 int lasti, lastj, imid;
423 int jmid = 0; // by D.Mathog, a guess
424 float wm = 0.0; /* int ?????? */
426 float *currentw, *previousw;
428 float fpenalty_ex = (float)penalty_ex;
436 float *mjpt, *prept, *curpt;
441 float *initverticalw; /* kufuu sureba iranai */
442 float *lastverticalw; /* kufuu sureba iranai */
459 int *jumpdummi; //muda
460 int *jumpdummj = NULL; // by D.Mathog, a guess
461 int jumpi, jumpj = 0; // by D.Mathog, a guess
471 static char ttt1[50000];
472 static char ttt2[50000];
475 ogcp1 = gapinfo[0] + ist;
476 fgcp1 = gapinfo[1] + ist;
477 ogcp2 = gapinfo[2] + jst;
478 fgcp2 = gapinfo[3] + jst;
487 // fprintf( stderr, "\nWARNING: lgth1 = %d\n", lgth1 );
489 // fprintf( stderr, "\nWARNING: lgth2 = %d\n", lgth2 );
493 fprintf( stderr, "==== MSalign (depth=%d, reccycle=%d), ist=%d, ien=%d, jst=%d, jen=%d\n", depth, reccycle, ist, ien, jst, jen );
494 strncpy( ttt1, seq1[0]+ist, lgth1 );
495 strncpy( ttt2, seq2[0]+jst, lgth2 );
498 fprintf( stderr, "seq1 = %s\n", ttt1 );
499 fprintf( stderr, "seq2 = %s\n", ttt2 );
501 if( lgth2 <= 0 ) // lgth1 <= 0 ha?
503 // fprintf( stderr, "\n\n==== jimei\n\n" );
505 for( i=0; i<icyc; i++ )
507 strncpy( mseq1[i], seq1[i]+ist, lgth1 );
510 for( i=0; i<jcyc; i++ )
513 for( j=0; j<lgth1; j++ )
514 strcat( mseq2[i], "-" );
517 // fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
518 // fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
524 aseq1 = AllocateCharMtx( icyc, 0 );
525 aseq2 = AllocateCharMtx( jcyc, 0 );
526 for( i=0; i<icyc; i++ ) aseq1[i] = mseq1[i];
527 for( i=0; i<jcyc; i++ ) aseq2[i] = mseq2[i];
529 aseq1 = AllocateCharMtx( icyc, lgth1+lgth2+100 );
530 aseq2 = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
533 // if( lgth1 < DPTANNI && lgth2 < DPTANNI ) // & dato lgth ==1 no kanousei ga arunode yokunai
534 // if( lgth1 < DPTANNI ) // kore mo lgth2 ga mijikasugiru kanousei ari
535 if( lgth1 < DPTANNI || lgth2 < DPTANNI ) // zettai ni anzen ka?
537 // fprintf( stderr, "==== Going to _tanni\n" );
539 value = MSalignmm_tanni( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ien, jst, jen, alloclen, aseq1, aseq2, gapinfo );
546 for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
547 for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
549 FreeCharMtx( aseq1 );
550 FreeCharMtx( aseq2 );
553 // fprintf( stderr, "value = %f\n", value );
557 // fprintf( stderr, "Trying to divide the mtx\n" );
559 ll1 = ( (int)(lgth1) ) + 100;
560 ll2 = ( (int)(lgth2) ) + 100;
562 // fprintf( stderr, "ll1,ll2=%d,%d\n", ll1, ll2 );
564 w1 = AllocateFloatVec( ll2+2 );
565 w2 = AllocateFloatVec( ll2+2 );
566 // match = AllocateFloatVec( ll2+2 );
567 midw = AllocateFloatVec( ll2+2 );
568 midn = AllocateFloatVec( ll2+2 );
569 midm = AllocateFloatVec( ll2+2 );
570 jumpbacki = AllocateIntVec( ll2+2 );
571 jumpbackj = AllocateIntVec( ll2+2 );
572 jumpforwi = AllocateIntVec( ll2+2 );
573 jumpforwj = AllocateIntVec( ll2+2 );
574 jumpdummi = AllocateIntVec( ll2+2 );
575 jumpdummj = AllocateIntVec( ll2+2 );
577 initverticalw = AllocateFloatVec( ll1+2 );
578 lastverticalw = AllocateFloatVec( ll1+2 );
580 m = AllocateFloatVec( ll2+2 );
581 mp = AllocateIntVec( ll2+2 );
582 gaps = AllocateCharVec( MAX( ll1, ll2 ) + 2 );
584 floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 );
585 intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 );
588 fprintf( stderr, "succeeded\n" );
592 WMMTX = AllocateFloatMtx( ll1, ll2 );
593 WMMTX2 = AllocateFloatMtx( ll1, ll2 );
596 shortmtx = AllocateShortMtx( ll1, ll2 );
599 fprintf( stderr, "succeeded\n\n" );
608 match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
610 match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
612 for( i=1; i<lgth1+1; i++ )
614 initverticalw[i] += ( ogcp1[0] + fgcp1[i-1] );
616 for( j=1; j<lgth2+1; j++ )
618 currentw[j] += ( ogcp2[0] + fgcp2[j-1] );
622 WMMTX[0][0] = initverticalw[0];
623 for( i=1; i<lgth1+1; i++ )
625 WMMTX[i][0] = initverticalw[i];
627 for( j=1; j<lgth2+1; j++ )
629 WMMTX[0][j] = currentw[j];
634 for( j=1; j<lgth2+1; ++j )
636 m[j] = currentw[j-1] + ogcp1[1];
637 // m[j] = currentw[j-1];
641 lastverticalw[0] = currentw[lgth2-1];
645 jumpi = 0; // atode kawaru.
648 for( i=1; i<lasti; i++ )
650 for( i=1; i<=imid; i++ )
654 previousw = currentw;
657 previousw[0] = initverticalw[i-1];
659 match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
660 currentw[0] = initverticalw[i];
666 if( i == imid ) midm[0] = m[0];
668 mi = previousw[0] + ogcp2[1];
669 // mi = previousw[0];
673 // ijppt = ijp[i] + 1;
676 curpt = currentw + 1;
681 for( j=1; j<lastj; j++ )
687 fprintf( stderr, "%5.0f->", wm );
690 // g = mi + fpenalty;
692 fprintf( stderr, "%5.0f?", g );
697 // *ijppt = -( j - mpi );
699 g = *prept + ogcp2[j];
710 g = *mjpt + fgcp1[i-1];
711 // g = *mjpt + fpenalty;
713 fprintf( stderr, "%5.0f?", g );
718 // *ijppt = +( i - *mpjpt );
722 g = *prept + ogcp1[i];
734 fprintf( stderr, "%5.0f ", wm );
739 WMMTX[i][j] = *curpt;
740 WMMTX2[i][j] = *mjpt;
743 if( i == imid ) //muda
745 jumpbackj[j] = *mpjpt; // muda atode matomeru
746 jumpbacki[j] = mpi; // muda atode matomeru
747 // fprintf( stderr, "jumpbackj[%d] in forward dp is %d\n", j, *mpjpt );
748 // fprintf( stderr, "jumpbacki[%d] in forward dp is %d\n", j, mpi );
754 // fprintf( stderr, "m[%d] = %f\n", j, m[j] );
761 lastverticalw[i] = currentw[lgth2-1];
764 WMMTX2[i][lgth2] = m[lgth2-1];
770 for( j=0; j<lgth2; j++ ) midw[j] = currentw[j];
771 for( j=0; j<lgth2; j++ ) midm[j] = m[j];
775 // for( j=0; j<lgth2; j++ ) midw[j] = WMMTX[imid][j];
776 // for( j=0; j<lgth2; j++ ) midm[j] = WMMTX2[imid][j];
779 for( i=0; i<lgth1; i++ )
781 for( j=0; j<lgth2; j++ )
783 fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
785 fprintf( stderr, "\n" );
787 fprintf( stderr, "\n" );
788 fprintf( stderr, "WMMTX2 = \n" );
789 for( i=0; i<lgth1; i++ )
791 for( j=0; j<lgth2; j++ )
793 fprintf( stderr, "% 10.2f ", WMMTX2[i][j] );
795 fprintf( stderr, "\n" );
797 fprintf( stderr, "\n" );
802 match_calc( initverticalw, cpmx2+jst, cpmx1+ist, lgth2-1, lgth1, floatwork, intwork, 1 );
803 match_calc( currentw, cpmx1+ist, cpmx2+jst, lgth1-1, lgth2, floatwork, intwork, 1 );
805 for( i=0; i<lgth1-1; i++ )
807 initverticalw[i] += ( fgcp1[lgth1-1] + ogcp1[i+1] );
808 // initverticalw[i] += fpenalty;
810 for( j=0; j<lgth2-1; j++ )
812 currentw[j] += ( fgcp2[lgth2-1] + ogcp2[j+1] );
813 // currentw[j] += fpenalty;
817 for( i=0; i<lgth1-1; i++ )
819 WMMTX[i][lgth2-1] += ( fgcp1[lgth1-1] + ogcp1[i+1] );
820 fprintf( stderr, "fgcp1[lgth1-1] + ogcp1[i+1] = %f\n", fgcp1[lgth1-1] + ogcp1[i+1] );
822 for( j=0; j<lgth2-1; j++ )
824 WMMTX[lgth1-1][j] += ( fgcp2[lgth2-1] + ogcp2[j+1] );
825 fprintf( stderr, "fgcp2[lgth2-1] + ogcp2[j+1] = %f\n", fgcp2[lgth2-1] + ogcp2[j+1] );
834 for( j=lgth2-1; j>0; --j )
836 m[j-1] = currentw[j] + fgcp2[lgth2-2];
837 // m[j-1] = currentw[j];
841 // for( j=0; j<lgth2; j++ ) m[j] = 0.0;
842 // m[lgth2-1] ha irunoka?
845 // for( i=lgth1-2; i>=imid; i-- )
848 for( i=lgth1-2; i>-1; i-- )
851 previousw = currentw;
853 previousw[lgth2-1] = initverticalw[i+1];
854 // match_calc( currentw, seq1, seq2, i, lgth2 );
855 match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
857 currentw[lgth2-1] = initverticalw[i];
859 // m[lgth2] = fgcp1[i];
860 // WMMTX2[i][lgth2] += m[lgth2];
861 // fprintf( stderr, "m[] = %f\n", m[lgth2] );
863 mi = previousw[lgth2-1] + fgcp2[lgth2-2];
864 // mi = previousw[lgth2-1];
867 mjpt = m + lgth2 - 2;
868 prept = previousw + lgth2 - 1;
869 curpt = currentw + lgth2 - 2;
870 mpjpt = mp + lgth2 - 2;
873 for( j=lgth2-2; j>-1; j-- )
880 // g = mi + fpenalty;
888 g = *prept + fgcp2[j];
892 // fprintf( stderr, "i,j=%d,%d - renewed! mpi = %d\n", i, j, j+1 );
901 // fprintf( stderr, "i,j=%d,%d *mpjpt = %d\n", i, j, *mpjpt );
902 g = *mjpt + ogcp1[i+1];
903 // g = *mjpt + fpenalty;
911 // if( i == imid )fprintf( stderr, "i,j=%d,%d \n", i, j );
912 g = *prept + fgcp1[i];
924 if( i == jumpi || i == imid - 1 )
926 jumpforwi[j] = ijpi; //muda
927 jumpforwj[j] = ijpj; //muda
928 // fprintf( stderr, "jumpfori[%d] = %d\n", j, ijpi );
929 // fprintf( stderr, "jumpforj[%d] = %d\n", j, ijpj );
931 if( i == imid ) // muda
934 // midm[j+1] += *mjpt + fpenalty; //??????
935 midm[j+1] += *mjpt; //??????
939 // midn[j] += mi + fpenalty; //????
940 midn[j] += mi; //????
944 // WMMTX2[i][j+1] += *mjpt + fpenalty;
945 WMMTX2[i][j+1] += *mjpt;
954 // fprintf( stderr, "adding *mjpt (=%f) to WMMTX2[%d][%d]\n", *mjpt, i, j+1 );
955 g = *prept + fgcp1[i];
962 WMMTX2[i][j+1] += firstm;
964 if( i == imid ) midm[j+1] += firstm;
970 // if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
971 for( j=2; j<lgth2-1; j++ )
979 // if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
981 for( j=0; j<lgth2+1; j++ )
989 // if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
992 // if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
995 // fprintf( stderr, "### imid=%d, jmid=%d\n", imid, jmid );
999 if( jmid > 0 && midn[jmid-1] > wm ) //060413
1002 jumpj = jumpbacki[jmid];
1004 // fprintf( stderr, "rejump (n)\n" );
1006 if( midm[jmid] > wm )
1008 jumpi = jumpbackj[jmid];
1011 // fprintf( stderr, "rejump (m) jumpi=%d\n", jumpi );
1015 // fprintf( stderr, "--> imid=%d, jmid=%d\n", imid, jmid );
1016 // fprintf( stderr, "--> jumpi=%d, jumpj=%d\n", jumpi, jumpj );
1018 fprintf( stderr, "imid = %d\n", imid );
1019 fprintf( stderr, "midn = \n" );
1020 for( j=0; j<lgth2; j++ )
1022 fprintf( stderr, "% 7.1f ", midn[j] );
1024 fprintf( stderr, "\n" );
1025 fprintf( stderr, "midw = \n" );
1026 for( j=0; j<lgth2; j++ )
1028 fprintf( stderr, "% 7.1f ", midw[j] );
1030 fprintf( stderr, "\n" );
1031 fprintf( stderr, "midm = \n" );
1032 for( j=0; j<lgth2; j++ )
1034 fprintf( stderr, "% 7.1f ", midm[j] );
1036 fprintf( stderr, "\n" );
1038 // fprintf( stderr, "maxwm = %f\n", maxwm );
1040 if( i == jumpi ) //saki?
1042 // fprintf( stderr, "imid, jumpi = %d,%d\n", imid, jumpi );
1043 // fprintf( stderr, "jmid, jumpj = %d,%d\n", jmid, jumpj );
1046 // fprintf( stderr, "CHUI2!\n" );
1047 jumpj = 0; jmid = 1;
1048 jumpi = firstmp - 1;
1053 else if( jmid == lgth2 )
1055 fprintf( stderr, "CHUI1!\n" );
1057 imid=jumpforwi[0]; jmid=lgth2-1;
1060 else if( jmid >= lgth2 )
1062 // fprintf( stderr, "CHUI1!\n" );
1063 jumpi=imid-1; jmid=lgth2;
1069 imid = jumpforwi[jumpj];
1070 jmid = jumpforwj[jumpj];
1073 fprintf( stderr, "jumpi -> %d\n", jumpi );
1074 fprintf( stderr, "jumpj -> %d\n", jumpj );
1075 fprintf( stderr, "imid -> %d\n", imid );
1076 fprintf( stderr, "jmid -> %d\n", jmid );
1088 imid=lgth1-1; jmid=lgth2-1;
1092 // fprintf( stderr, "imid = %d, but jumpi = %d\n", imid, jumpi );
1093 // fprintf( stderr, "jmid = %d, but jumpj = %d\n", jmid, jumpj );
1095 // for( j=0; j<lgth2; j++ ) midw[j] += currentw[j];
1096 // for( j=0; j<lgth2; j++ ) midm[j] += m[j+1];
1097 // for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
1098 // for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
1102 fprintf( stderr, "WMMTX = \n" );
1103 for( i=0; i<lgth1; i++ )
1105 fprintf( stderr, "%d ", i );
1106 for( j=0; j<lgth2; j++ )
1108 fprintf( stderr, "% 7.2f ", WMMTX[i][j] );
1110 fprintf( stderr, "\n" );
1112 // fprintf( stderr, "WMMTX2 = (p = %f)\n", fpenalty );
1113 for( i=0; i<lgth1; i++ )
1115 fprintf( stderr, "%d ", i );
1116 for( j=0; j<lgth2+1; j++ )
1118 fprintf( stderr, "% 7.2f ", WMMTX2[i][j] );
1120 fprintf( stderr, "\n" );
1123 fprintf( stderr, "jumpbacki = \n" );
1124 for( j=0; j<lgth2; j++ )
1126 fprintf( stderr, "% 7d ", jumpbacki[j] );
1128 fprintf( stderr, "\n" );
1129 fprintf( stderr, "jumpbackj = \n" );
1130 for( j=0; j<lgth2; j++ )
1132 fprintf( stderr, "% 7d ", jumpbackj[j] );
1134 fprintf( stderr, "\n" );
1135 fprintf( stderr, "jumpforwi = \n" );
1136 for( j=0; j<lgth2; j++ )
1138 fprintf( stderr, "% 7d ", jumpforwi[j] );
1140 fprintf( stderr, "\n" );
1141 fprintf( stderr, "jumpforwj = \n" );
1142 for( j=0; j<lgth2; j++ )
1144 fprintf( stderr, "% 7d ", jumpforwj[j] );
1146 fprintf( stderr, "\n" );
1152 // Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
1155 resultlen = strlen( mseq1[0] );
1156 if( alloclen < resultlen || resultlen > N )
1158 fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
1159 ErrorExit( "LENGTH OVER!\n" );
1166 fprintf( stderr, "jumpi = %d, imid = %d\n", jumpi, imid );
1167 fprintf( stderr, "jumpj = %d, jmid = %d\n", jumpj, jmid );
1169 fprintf( stderr, "imid = %d\n", imid );
1170 fprintf( stderr, "jmid = %d\n", jmid );
1176 FreeFloatVec( initverticalw );
1177 FreeFloatVec( lastverticalw );
1178 FreeFloatVec( midw );
1179 FreeFloatVec( midm );
1180 FreeFloatVec( midn );
1182 FreeIntVec( jumpbacki );
1183 FreeIntVec( jumpbackj );
1184 FreeIntVec( jumpforwi );
1185 FreeIntVec( jumpforwj );
1186 FreeIntVec( jumpdummi );
1187 FreeIntVec( jumpdummj );
1192 FreeFloatMtx( floatwork );
1193 FreeIntMtx( intwork );
1196 FreeFloatMtx( WMMTX );
1197 FreeFloatMtx( WMMTX2 );
1200 // fprintf( stderr, "==== calling myself (first)\n" );
1203 fprintf( stderr, "seq1[0] = %s\n", seq1[0] );
1204 fprintf( stderr, "seq2[0] = %s\n", seq2[0] );
1206 value = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ist+jumpi, jst, jst+jumpj, alloclen, aseq1, aseq2, depth, gapinfo );
1208 fprintf( stderr, "aseq1[0] = %s\n", aseq1[0] );
1209 fprintf( stderr, "aseq2[0] = %s\n", aseq2[0] );
1213 for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
1214 for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
1217 // fprintf( stderr, "====(f) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
1218 // fprintf( stderr, "====(f) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
1220 len = strlen( mseq1[0] );
1221 // fprintf( stderr, "len = %d\n", len );
1222 l = jmid - jumpj - 1;
1223 // fprintf( stderr, "l=%d\n", l );
1226 for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
1227 for( i=0; i<icyc; i++ )
1229 strcat( mseq1[i], gaps );
1230 mseq1[i][len+l] = 0;
1232 for( j=0; j<jcyc; j++ )
1234 strncat( mseq2[j], seq2[j]+jst+jumpj+1, l );
1235 mseq2[j][len+l] = 0;
1237 // fprintf( stderr, "penalizing (2) .. %f(%d), %f(%d)\n", ogcp2[jumpj+1], jumpj+1, fgcp2[jmid-1], jmid-1 );
1238 value += ( ogcp2[jumpj+1] + fgcp2[jmid-1] );
1239 // value += fpenalty;
1241 len = strlen( mseq1[0] );
1242 l = imid - jumpi - 1;
1243 // fprintf( stderr, "l=%d\n", l );
1246 for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
1247 for( i=0; i<icyc; i++ )
1249 strncat( mseq1[i], seq1[i]+ist+jumpi+1, l );
1250 mseq1[i][len+l] = 0;
1252 for( j=0; j<jcyc; j++ )
1254 strcat( mseq2[j], gaps );
1255 mseq2[j][len+l] = 0;
1258 // for( i=0; i<lgth1; i++ ) fprintf( stderr, "ogcp1[%d] = %f\n", i, ogcp1[i] );
1259 // for( i=0; i<lgth1; i++ ) fprintf( stderr, "fgcp1[%d] = %f\n", i, fgcp1[i] );
1262 // fprintf( stderr, "penalizing (1) .. ogcp1[%d] = %f, fgcp1[%d] = %f\n", jumpi+1, ogcp1[jumpi+1], imid-1, fgcp1[imid-1] );
1263 value += ( ogcp1[jumpi+1] + fgcp1[imid-1] );
1264 // value += fpenalty;
1267 for( i=0; i<icyc; i++ ) fprintf( stderr, "after gapfill mseq1[%d]=%s\n", i, mseq1[i] );
1268 for( i=0; i<jcyc; i++ ) fprintf( stderr, "after gapfill mseq2[%d]=%s\n", i, mseq2[i] );
1271 // fprintf( stderr, "==== calling myself (second)\n" );
1274 alnlen = strlen( aseq1[0] );
1275 for( i=0; i<icyc; i++ ) aseq1[i] += alnlen;
1276 for( i=0; i<jcyc; i++ ) aseq2[i] += alnlen;
1280 fprintf( stderr, "seq1[0] = %s\n", seq1[0] );
1281 fprintf( stderr, "seq2[0] = %s\n", seq2[0] );
1283 value += MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist+imid, ien, jst+jmid, jen, alloclen, aseq1, aseq2, depth, gapinfo );
1285 fprintf( stderr, "aseq1[0] = %s\n", aseq1[0] );
1286 fprintf( stderr, "aseq2[0] = %s\n", aseq2[0] );
1292 if( value - maxwm > 1 || maxwm - value > 1 )
1294 fprintf( stderr, "WARNING value = %f, but maxwm = %f\n", value, maxwm );
1295 for( i=0; i<icyc; i++ )
1297 fprintf( stderr, ">1-%d\n%s\n", i, mseq1[i] );
1298 fprintf( stderr, "%s\n", aseq1[i] );
1300 for( i=0; i<jcyc; i++ )
1302 fprintf( stderr, ">2-%d\n%s\n", i, mseq2[i] );
1303 fprintf( stderr, "%s\n", aseq2[i] );
1310 fprintf( stderr, "value = %.0f, maxwm = %.0f -> ok\n", value, maxwm );
1316 for( i=0; i<icyc; i++ ) strcat( mseq1[i], aseq1[i] );
1317 for( i=0; i<jcyc; i++ ) strcat( mseq2[i], aseq2[i] );
1320 // fprintf( stderr, "====(s) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
1321 // fprintf( stderr, "====(s) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
1328 FreeCharMtx( aseq1 );
1329 FreeCharMtx( aseq2 );
1337 float MSalignmm( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, char *sgap1, char *sgap2, char *egap1, char *egap2 )
1338 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
1344 float wm = 0.0; /* int ?????? */
1354 float fpenalty = (float)penalty;
1358 fprintf( stderr, "eff in SA+++align\n" );
1359 for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
1362 nglen1 = seqlen( seq1[0] );
1363 nglen2 = seqlen( seq2[0] );
1365 lgth1 = strlen( seq1[0] );
1366 lgth2 = strlen( seq2[0] );
1368 ll1 = ( (int)(lgth1) ) + 100;
1369 ll2 = ( (int)(lgth2) ) + 100;
1371 mseq1 = AllocateCharMtx( icyc, ll1+ll2 );
1372 mseq2 = AllocateCharMtx( jcyc, ll1+ll2 );
1374 gapinfo = AllocateFloatMtx( 4, 0 );
1375 ogcp1 = AllocateFloatVec( ll1+2 );
1376 ogcp2 = AllocateFloatVec( ll2+2 );
1377 fgcp1 = AllocateFloatVec( ll1+2 );
1378 fgcp2 = AllocateFloatVec( ll2+2 );
1381 cpmx1 = AllocateFloatMtx( ll1+2, 27 );
1382 cpmx2 = AllocateFloatMtx( ll2+2, 27 );
1384 for( i=0; i<icyc; i++ )
1386 if( strlen( seq1[i] ) != lgth1 )
1388 fprintf( stderr, "i = %d / %d\n", i, icyc );
1389 fprintf( stderr, "bug! hairetsu ga kowareta!\n" );
1393 for( j=0; j<jcyc; j++ )
1395 if( strlen( seq2[j] ) != lgth2 )
1397 fprintf( stderr, "j = %d / %d\n", j, jcyc );
1398 fprintf( stderr, "bug! hairetsu ga kowareta!\n" );
1403 MScpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
1404 MScpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
1411 new_OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1, sgap1 );
1412 new_OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2, sgap2 );
1413 new_FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1, egap2 );
1414 new_FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2, egap2 );
1418 st_OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1 );
1419 st_OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2 );
1420 st_FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1 );
1421 st_FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2 );
1425 for( i=0; i<lgth1; i++ )
1427 ogcp1[i] = 0.5 * ( 1.0 - ogcp1[i] ) * fpenalty;
1428 fgcp1[i] = 0.5 * ( 1.0 - fgcp1[i] ) * fpenalty;
1429 // fprintf( stderr, "fgcp1[%d] = %f\n", i, fgcp1[i] );
1431 for( i=0; i<lgth2; i++ )
1433 ogcp2[i] = 0.5 * ( 1.0 - ogcp2[i] ) * fpenalty;
1434 fgcp2[i] = 0.5 * ( 1.0 - fgcp2[i] ) * fpenalty;
1435 // fprintf( stderr, "fgcp2[%d] = %f\n", i, fgcp2[i] );
1438 for( i=0; i<lgth1; i++ )
1440 ogcp1[i] = 0.5 * fpenalty;
1441 fgcp1[i] = 0.5 * fpenalty;
1443 for( i=0; i<lgth2; i++ )
1445 ogcp2[i] = 0.5 * fpenalty;
1446 fgcp2[i] = 0.5 * fpenalty;
1457 fprintf( stdout, "in MSalignmm.c\n" );
1458 for( i=0; i<icyc; i++ )
1460 fprintf( stdout, ">%d of GROUP1\n", i );
1461 fprintf( stdout, "%s\n", seq1[i] );
1463 for( i=0; i<jcyc; i++ )
1465 fprintf( stdout, ">%d of GROUP2\n", i );
1466 fprintf( stdout, "%s\n", seq2[i] );
1471 wm = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, 0, lgth1-1, 0, lgth2-1, alloclen, mseq1, mseq2, 0, gapinfo );
1473 fprintf( stderr, " seq1[0] = %s\n", seq1[0] );
1474 fprintf( stderr, " seq2[0] = %s\n", seq2[0] );
1475 fprintf( stderr, "mseq1[0] = %s\n", mseq1[0] );
1476 fprintf( stderr, "mseq2[0] = %s\n", mseq2[0] );
1479 // fprintf( stderr, "wm = %f\n", wm );
1482 for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
1483 for( i=0; i<jcyc; i++ ) strcpy( seq2[i], mseq2[i] );
1485 if( seqlen( seq1[0] ) != nglen1 )
1487 fprintf( stderr, "bug! hairetsu ga kowareta! (nglen1) seqlen(seq1[0])=%d but nglen1=%d\n", seqlen( seq1[0] ), nglen1 );
1488 fprintf( stderr, "seq1[0] = %s\n", seq1[0] );
1491 if( seqlen( seq2[0] ) != nglen2 )
1493 fprintf( stderr, "bug! hairetsu ga kowareta! (nglen2) seqlen(seq2[0])=%d but nglen2=%d\n", seqlen( seq2[0] ), nglen2 );
1497 FreeFloatVec( ogcp1 );
1498 FreeFloatVec( ogcp2 );
1499 FreeFloatVec( fgcp1 );
1500 FreeFloatVec( fgcp2 );
1501 FreeFloatMtx( cpmx1 );
1502 FreeFloatMtx( cpmx2 );
1503 free( (void *)gapinfo );
1505 FreeCharMtx( mseq1 );
1506 FreeCharMtx( mseq2 );
1508 lgth1 = strlen( seq1[0] );
1509 lgth2 = strlen( seq2[0] );
1510 for( i=0; i<icyc; i++ )
1512 if( strlen( seq1[i] ) != lgth1 )
1514 fprintf( stderr, "i = %d / %d\n", i, icyc );
1515 fprintf( stderr, "hairetsu ga kowareta (end of MSalignmm) !\n" );
1519 for( j=0; j<jcyc; j++ )
1521 if( strlen( seq2[j] ) != lgth2 )
1523 fprintf( stderr, "j = %d / %d\n", j, jcyc );
1524 fprintf( stderr, "hairetsu ga kowareta (end of MSalignmm) !\n" );