6 #define USE_PENALTY_EX 0
14 static void OpeningGapCount( float *ogcp, int clus, char **seq, double *eff )
17 int len = strlen( seq[0] );
20 for( i=0; i<len; i++ ) ogcp[i] = 0.0;
21 for( j=0; j<clus; j++ )
24 for( i=0; i<len; i++ )
27 gc = ( seq[j][i] == '-' );
29 if( !gb * gc ) ogcp[i] += eff[j];
34 for( i=0; i<len; i++ )
38 static void FinalGapCount( float *fgcp, int clus, char **seq, double *eff )
41 int len = strlen( seq[0] );
44 for( i=0; i<len; i++ ) fgcp[i] = 0.0;
45 for( j=0; j<clus; j++ )
47 gc = ( seq[j][0] == '-' );
48 for( i=1; i<len+1; i++ )
51 gc = ( seq[j][i] == '-' );
53 if( gb * !gc ) fgcp[i-1] += eff[j];
58 for( i=0; i<len; i++ )
62 static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
66 float **cpmxpd = floatwork;
67 int **cpmxpdn = intwork;
72 for( j=0; j<lgth2; j++ )
79 cpmxpd[j][count] = cpmx2[j][l];
80 cpmxpdn[j][count] = l;
84 cpmxpdn[j][count] = -1;
93 scarr[l] += n_dis[k][l] * cpmx1[i1][k];
96 #if 0 /* ¤³¤ì¤ò»È¤¦¤È¤
\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
98 float *fpt, **fptpt, *fpt2;
106 ipt=*iptpt,fpt=*fptpt;
108 *fpt2 += scarr[*ipt++] * *fpt++;
109 fpt2++,iptpt++,fptpt++;
113 for( j=0; j<lgth2; j++ )
116 for( k=0; cpmxpdn[j][k]>-1; k++ )
117 match[j] += scarr[cpmxpdn[j][k]] * cpmxpd[j][k];
122 static float Atracking( float *lasthorizontalw, float *lastverticalw,
123 char **seq1, char **seq2,
124 char **mseq1, char **mseq2,
125 float **cpmx1, float **cpmx2,
126 short **ijp, int icyc, int jcyc,
127 int ist, int ien, int jst, int jen )
129 int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, klim;
136 for( i=0; i<lgth1; i++ )
138 fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
143 // fprintf( stderr, "in Atracking, lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
145 for( i=0; i<lgth1+1; i++ )
149 for( j=0; j<lgth2+1; j++ )
151 ijp[0][j] = -( j + 1 );
155 for( i=0; i<icyc; i++ )
157 mseq1[i] += lgth1+lgth2;
160 for( j=0; j<jcyc; j++ )
162 mseq2[j] += lgth1+lgth2;
166 // if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
168 iin = lgth1; jin = lgth2;
170 for( k=0; k<=klim; k++ )
172 if( ijp[iin][jin] < 0 )
174 ifi = iin-1; jfi = jin+ijp[iin][jin];
176 else if( ijp[iin][jin] > 0 )
178 ifi = iin-ijp[iin][jin]; jfi = jin-1;
182 ifi = iin-1; jfi = jin-1;
187 for( i=0; i<icyc; i++ )
188 *--mseq1[i] = seq1[i][ist+ifi+l];
189 for( j=0; j<jcyc; j++ )
196 for( i=0; i<icyc; i++ )
198 for( j=0; j<jcyc; j++ )
199 *--mseq2[j] = seq2[j][jst+jfi+l];
202 if( iin <= 0 || jin <= 0 ) break;
203 for( i=0; i<icyc; i++ )
204 *--mseq1[i] = seq1[i][ist+ifi];
205 for( j=0; j<jcyc; j++ )
206 *--mseq2[j] = seq2[j][jst+jfi];
208 iin = ifi; jin = jfi;
210 // if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
212 // fprintf( stderr, "in Atracking (owari), mseq1 = %s\n", mseq1[0] );
213 // fprintf( stderr, "in Atracking (owari), mseq2 = %s\n", mseq2[0] );
217 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[4] )
218 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
225 float wm; /* int ?????? */
227 float *currentw, *previousw;
228 float fpenalty = (float)penalty;
229 float fpenalty_ex = (float)penalty_ex;
233 float *mjpt, *prept, *curpt;
240 float *initverticalw; /* kufuu sureba iranai */
241 float *lastverticalw; /* kufuu sureba iranai */
247 float *ogcp1 = gapinfo[0];
248 float *fgcp1 = gapinfo[1];
249 float *ogcp2 = gapinfo[2];
250 float *fgcp2 = gapinfo[3];
251 static char **aseq1 = NULL;
252 static char **aseq2 = NULL;
253 static char **aseq1bk, **aseq2bk;
255 // char ttt1[10000], ttt2[10000];
259 aseq1 = AllocateCharMtx( njob, 0 );
260 aseq2 = AllocateCharMtx( njob, 0 );
266 // strncpy( ttt1, seq1[0]+ist, lgth1 ); ttt1[lgth1] = 0;
267 // strncpy( ttt2, seq2[0]+jst, lgth2 ); ttt2[lgth2] = 0;
269 // fprintf( stderr, "in _tanni ist,ien = %d,%d, lgth1=%d\n", ist, ien, lgth1 );
270 // fprintf( stderr, "in _tanni jst,jen = %d,%d, lgth2=%d\n", jst, jen, lgth2 );
271 // fprintf( stderr, "ttt1 = %s\n", ttt1 );
272 // fprintf( stderr, "ttt2 = %s\n", ttt2 );
275 ll1 = ( (int)(1.3*lgth1) ) + 100;
276 ll2 = ( (int)(1.3*lgth2) ) + 100;
278 aseq1bk = AllocateCharMtx( icyc, lgth1+lgth2+100 );
279 aseq2bk = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
280 for( i=0; i<icyc; i++ ) aseq1[i] = aseq1bk[i];
281 for( i=0; i<jcyc; i++ ) aseq2[i] = aseq2bk[i];
283 w1 = AllocateFloatVec( ll2+2 );
284 w2 = AllocateFloatVec( ll2+2 );
286 initverticalw = AllocateFloatVec( ll1+2 );
287 lastverticalw = AllocateFloatVec( ll1+2 );
289 m = AllocateFloatVec( ll2+2 );
290 mp = AllocateIntVec( ll2+2 );
292 floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 );
293 intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 );
296 shortmtx = AllocateShortMtx( ll1+1, ll2+1 );
303 match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
305 match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
307 for( i=1; i<lgth1+1; i++ )
309 initverticalw[i] += fpenalty * ( ogcp1[0] + fgcp1[i-1] );
311 for( j=1; j<lgth2+1; j++ )
313 currentw[j] += fpenalty * ( ogcp2[0] + fgcp2[j-1] );
316 for( j=1; j<lgth2+1; ++j )
318 m[j] = currentw[j-1] + fpenalty * ogcp1[1]; mp[j] = 0;;
321 lastverticalw[0] = currentw[lgth2-1];
325 for( i=1; i<lasti; i++ )
329 previousw = currentw;
332 previousw[0] = initverticalw[i-1];
334 match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
335 currentw[0] = initverticalw[i];
337 mi = previousw[0] + fpenalty * ogcp2[1];
343 curpt = currentw + 1;
346 for( j=1; j<lastj; j++ )
352 fprintf( stderr, "%5.0f->", wm );
354 g = mi + fpenalty * fgcp2[j-1];
356 fprintf( stderr, "%5.0f?", g );
361 *ijppt = -( j - mpi );
363 g = *prept + fpenalty * ogcp2[j];
373 g = *mjpt + fpenalty * fgcp1[i-1];
375 fprintf( stderr, "%5.0f?", g );
380 *ijppt = +( i - *mpjpt );
382 g = *prept + fpenalty * ogcp1[i];
393 fprintf( stderr, "%5.0f ", wm );
404 lastverticalw[i] = currentw[lgth2-1];
408 Atracking( currentw, lastverticalw, seq1, seq2, aseq1, aseq2, cpmx1+ist, cpmx2+jst, ijp, icyc, jcyc, ist, ien, jst, jen );
410 for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
411 for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
413 // fprintf( stderr, "in _tanni, aseq1 = %s\n", aseq1[0] );
414 // fprintf( stderr, "in _tanni, mseq1 = %s\n", mseq1[0] );
418 FreeFloatVec( initverticalw );
419 FreeFloatVec( lastverticalw );
425 FreeFloatMtx( floatwork );
426 FreeIntMtx( intwork );
428 FreeShortMtx( shortmtx );
430 FreeCharMtx( aseq1bk );
431 FreeCharMtx( aseq2bk );
436 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[4] )
437 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
441 char **aseq1, **aseq2;
442 int ll1, ll2, l, len;
443 int lasti, lastj, imid, jmid;
445 float wm; /* int ?????? */
447 float *currentw, *previousw;
448 float fpenalty = (float)penalty;
449 float fpenalty_ex = (float)penalty_ex;
456 float *mjpt, *prept, *curpt;
461 float *initverticalw; /* kufuu sureba iranai */
462 float *lastverticalw; /* kufuu sureba iranai */
480 int *jumpdummi; //muda
481 int *jumpdummj; //muda
485 // float *ogcp1 = gapinfo[0];
486 // float *fgcp1 = gapinfo[1];
487 // float *ogcp2 = gapinfo[2];
488 // float *fgcp2 = gapinfo[3];
489 // static char ttt1[50000];
490 // static char ttt2[50000];
498 // fprintf( stderr, "==== MSalign (depth=%d, reccycle=%d), ist=%d, ien=%d, jst=%d, jen=%d\n", depth, reccycle, ist, ien, jst, jen );
499 // strncpy( ttt1, seq1[0]+ist, lgth1 );
500 // strncpy( ttt2, seq2[0]+jst, lgth2 );
503 // fprintf( stderr, "seq1 = %s\n", ttt1 );
504 // fprintf( stderr, "seq2 = %s\n", ttt2 );
507 fprintf( stderr, "==== jimei\n" );
508 for( i=0; i<icyc; i++ )
510 strncpy( mseq1[i], seq1[i]+ist, lgth1 );
513 for( i=0; i<jcyc; i++ )
516 for( j=0; j<lgth1; j++ )
517 strcat( mseq2[i], "-" );
520 // fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
521 // fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
523 return( (float)offset * lgth1 );
526 aseq1 = AllocateCharMtx( icyc, lgth1+lgth2+100 );
527 aseq2 = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
529 if( lgth1 < DPTANNI || lgth2 < DPTANNI )
531 // fprintf( stderr, "==== Going to _tanni\n" );
533 wm = MSalignmm_tanni( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ien, jst, jen, alloclen, aseq1, aseq2, gapinfo );
536 for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
537 for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
539 // fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
540 // fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
542 // fprintf( stderr, "freeing aseq\n" );
543 FreeCharMtx( aseq1 );
544 FreeCharMtx( aseq2 );
548 // fprintf( stderr, "Trying to divide the mtx\n" );
550 ll1 = ( (int)(1.3*lgth1) ) + 100;
551 ll2 = ( (int)(1.3*lgth2) ) + 100;
553 // fprintf( stderr, "ll1,ll2=%d,%d\n", ll1, ll2 );
555 w1 = AllocateFloatVec( ll2+2 );
556 w2 = AllocateFloatVec( ll2+2 );
557 // match = AllocateFloatVec( ll2+2 );
558 midw = AllocateFloatVec( ll2+2 );
559 midn = AllocateFloatVec( ll2+2 );
560 midm = AllocateFloatVec( ll2+2 );
561 jumpbacki = AllocateIntVec( ll2+2 );
562 jumpbackj = AllocateIntVec( ll2+2 );
563 jumpforwi = AllocateIntVec( ll2+2 );
564 jumpforwj = AllocateIntVec( ll2+2 );
565 jumpdummi = AllocateIntVec( ll2+2 );
566 jumpdummj = AllocateIntVec( ll2+2 );
568 initverticalw = AllocateFloatVec( ll1+2 );
569 lastverticalw = AllocateFloatVec( ll1+2 );
571 m = AllocateFloatVec( ll2+2 );
572 mp = AllocateIntVec( ll2+2 );
573 gaps = AllocateCharVec( MAX( ll1, ll2 ) + 2 );
575 floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 );
576 intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 );
579 fprintf( stderr, "succeeded\n" );
583 WMMTX = AllocateFloatMtx( ll1, ll2 );
584 WMMTX2 = AllocateFloatMtx( ll1, ll2 );
587 shortmtx = AllocateShortMtx( ll1, ll2 );
590 fprintf( stderr, "succeeded\n\n" );
599 match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
601 match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
603 for( i=1; i<lgth1+1; i++ )
605 // initverticalw[i] += fpenalty * ( ogcp1[0] + fgcp1[i-1] );
606 initverticalw[i] += fpenalty;
608 for( j=1; j<lgth2+1; j++ )
610 // currentw[j] += fpenalty * ( ogcp2[0] + fgcp2[j-1] );
611 currentw[j] += fpenalty;
615 WMMTX[0][0] = initverticalw[0];
616 for( i=1; i<lgth1+1; i++ )
618 WMMTX[i][0] = initverticalw[i];
620 for( j=1; j<lgth2+1; j++ )
622 WMMTX[0][j] = currentw[j];
626 for( j=1; j<lgth2+1; ++j )
628 // m[j] = currentw[j-1] + fpenalty * ogcp1[1];
629 m[j] = currentw[j-1];
633 lastverticalw[0] = currentw[lgth2-1];
637 jumpi = 0; // atode kawaru.
639 // for( i=1; i<lasti; i++ )
640 for( i=1; i<=imid; i++ )
643 previousw = currentw;
646 previousw[0] = initverticalw[i-1];
648 match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
649 currentw[0] = initverticalw[i];
652 // mi = previousw[0] + fpenalty * ogcp2[1];
656 // ijppt = ijp[i] + 1;
659 curpt = currentw + 1;
664 for( j=1; j<lastj; j++ )
671 fprintf( stderr, "%5.0f->", wm );
675 fprintf( stderr, "%5.0f?", g );
680 // *ijppt = -( j - mpi );
682 // g = *prept + fpenalty * ogcp2[j];
693 // g = *mjpt + fpenalty * fgcp1[i-1];
694 g = *mjpt + fpenalty;
696 fprintf( stderr, "%5.0f?", g );
701 // *ijppt = +( i - *mpjpt );
705 // g = *prept + fpenalty * ogcp1[i];
717 fprintf( stderr, "%5.0f ", wm );
722 WMMTX[i][j] = *curpt;
723 WMMTX2[i][j] = *mjpt;
726 if( i == imid ) //muda
728 jumpbackj[j] = *mpjpt; // muda atode matomeru
729 jumpbacki[j] = mpi; // muda atode matomeru
730 // fprintf( stderr, "jumpbackj[%d] in forward dp is %d\n", j, *mpjpt );
731 // fprintf( stderr, "jumpbacki[%d] in forward dp is %d\n", j, mpi );
743 lastverticalw[i] = currentw[lgth2-1];
747 for( j=0; j<lgth2; j++ ) midw[j] = currentw[j];
748 for( j=0; j<lgth2; j++ ) midm[j] = m[j];
752 // for( j=0; j<lgth2; j++ ) midw[j] = WMMTX[imid][j];
753 // for( j=0; j<lgth2; j++ ) midm[j] = WMMTX2[imid][j];
756 for( i=0; i<lgth1; i++ )
758 for( j=0; j<lgth2; j++ )
760 fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
762 fprintf( stderr, "\n" );
764 fprintf( stderr, "\n" );
765 fprintf( stderr, "WMMTX2 = \n" );
766 for( i=0; i<lgth1; i++ )
768 for( j=0; j<lgth2; j++ )
770 fprintf( stderr, "% 10.2f ", WMMTX2[i][j] );
772 fprintf( stderr, "\n" );
774 fprintf( stderr, "\n" );
779 match_calc( initverticalw, cpmx2+jst, cpmx1+ist, lgth2-1, lgth1, floatwork, intwork, 1 );
780 match_calc( currentw, cpmx1+ist, cpmx2+jst, lgth1-1, lgth2, floatwork, intwork, 1 );
782 for( i=0; i<lgth1-1; i++ )
784 // initverticalw[i] += fpenalty * ( fgcp1[lgth1-1] + ogcp1[i+1] );
785 initverticalw[i] += fpenalty;
787 for( j=0; j<lgth2-1; j++ )
789 // currentw[j] += fpenalty * ( fgcp2[lgth1-1] + ogcp2[j+1] );
790 currentw[j] += fpenalty;
794 for( i=0; i<lgth1-1; i++ )
796 WMMTX[i][lgth2-1] += fpenalty;
798 for( j=0; j<lgth2-1; j++ )
800 WMMTX[lgth1-1][j] += fpenalty;
804 for( j=lgth2-1; j>0; --j )
806 // m[j-1] = currentw[j] + fpenalty * fgcp2[lgth2-2];
807 m[j-1] = currentw[j];
811 // for( j=0; j<lgth2; j++ ) m[j] = 0.0;
812 // m[lgth2-1] ha irunoka?
814 // for( i=lgth1-2; i>=imid; i-- )
815 for( i=lgth1-2; i>-1; i-- )
818 previousw = currentw;
820 previousw[lgth2-1] = initverticalw[i+1];
821 // match_calc( currentw, seq1, seq2, i, lgth2 );
822 match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
824 currentw[lgth2-1] = initverticalw[i];
826 // mi = previousw[lgth2-1] + fpenalty * fgcp2[lgth2-2];
827 mi = previousw[lgth2-1];
830 mjpt = m + lgth2 - 2;
831 prept = previousw + lgth2 - 1;
832 curpt = currentw + lgth2 - 2;
833 mpjpt = mp + lgth2 - 2;
836 for( j=lgth2-2; j>-1; j-- )
842 // g = mi + fpenalty * ogcp2[j+1];
850 // g = *prept + fpenalty + fgcp2[j];
854 // fprintf( stderr, "i,j=%d,%d - renewed! mpi = %d\n", i, j, j+1 );
863 // fprintf( stderr, "i,j=%d,%d *mpjpt = %d\n", i, j, *mpjpt );
864 // g = *mjpt + fpenalty * ogcp1[i+1];
865 g = *mjpt + fpenalty;
872 // if( i == imid )fprintf( stderr, "i,j=%d,%d \n", i, j );
873 // g = *prept + fpenalty * fgcp1[i];
885 if( i == jumpi || i == imid - 1 )
887 jumpforwi[j] = ijpi; //muda
888 jumpforwj[j] = ijpj; //muda
889 // fprintf( stderr, "jumpfori[%d] = %d\n", j, ijpi );
890 // fprintf( stderr, "jumpforj[%d] = %d\n", j, ijpj );
892 if( i == imid ) // muda
895 midm[j+1] += *mjpt + fpenalty; //??????
899 midn[j] += mi + fpenalty; //????
903 WMMTX2[i][j+1] += *mjpt + fpenalty;
917 for( j=2; j<lgth2; j++ )
932 // fprintf( stderr, "imid=%d, jmid=%d\n", imid, jmid );
938 if( midm[jmid] > wm )
940 jumpi = jumpbackj[jmid];
943 if( midn[jmid-1] >= wm )
946 jumpj = jumpbacki[jmid];
949 fprintf( stderr, "imid = %d\n", imid );
950 fprintf( stderr, "midn = \n" );
951 for( j=0; j<lgth2; j++ )
953 fprintf( stderr, "% 10.2f ", midn[j] );
955 fprintf( stderr, "\n" );
956 fprintf( stderr, "midw = \n" );
957 for( j=0; j<lgth2; j++ )
959 fprintf( stderr, "% 10.2f ", midw[j] );
961 fprintf( stderr, "\n" );
962 fprintf( stderr, "midm = \n" );
963 for( j=0; j<lgth2; j++ )
965 fprintf( stderr, "% 10.2f ", midm[j] );
967 fprintf( stderr, "\n" );
970 if( i == jumpi ) //saki?
972 // fprintf( stderr, "imid, jumpi = %d,%d\n", imid, jumpi );
973 // fprintf( stderr, "jmid, jumpj = %d,%d\n", jmid, jumpj );
974 imid = jumpforwi[jumpj];
975 jmid = jumpforwj[jumpj];
976 // fprintf( stderr, "imid -> %d\n", imid );
977 // fprintf( stderr, "jmid -> %d\n", jmid );
981 // fprintf( stderr, "imid = %d, but jumpi = %d\n", imid, jumpi );
982 // fprintf( stderr, "jmid = %d, but jumpj = %d\n", jmid, jumpj );
984 // for( j=0; j<lgth2; j++ ) midw[j] += currentw[j];
985 // for( j=0; j<lgth2; j++ ) midm[j] += m[j+1];
986 // for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
987 // for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
991 fprintf( stderr, "WMMTX = \n" );
992 for( i=0; i<lgth1; i++ )
994 fprintf( stderr, "%d ", i );
995 for( j=0; j<lgth2; j++ )
997 fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
999 fprintf( stderr, "\n" );
1001 fprintf( stderr, "WMMTX2 = (p = %f)\n", fpenalty );
1002 for( i=0; i<lgth1; i++ )
1004 fprintf( stderr, "%d ", i );
1005 for( j=0; j<lgth2; j++ )
1007 fprintf( stderr, "% 10.2f ", WMMTX2[i][j] );
1009 fprintf( stderr, "\n" );
1012 fprintf( stderr, "jumpbacki = \n" );
1013 for( j=0; j<lgth2; j++ )
1015 fprintf( stderr, "% 10d ", jumpbacki[j] );
1017 fprintf( stderr, "\n" );
1018 fprintf( stderr, "jumpbackj = \n" );
1019 for( j=0; j<lgth2; j++ )
1021 fprintf( stderr, "% 10d ", jumpbackj[j] );
1023 fprintf( stderr, "\n" );
1024 fprintf( stderr, "jumpforwi = \n" );
1025 for( j=0; j<lgth2; j++ )
1027 fprintf( stderr, "% 10d ", jumpforwi[j] );
1029 fprintf( stderr, "\n" );
1030 fprintf( stderr, "jumpforwj = \n" );
1031 for( j=0; j<lgth2; j++ )
1033 fprintf( stderr, "% 10d ", jumpforwj[j] );
1035 fprintf( stderr, "\n" );
1040 // Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
1043 resultlen = strlen( mseq1[0] );
1044 if( alloclen < resultlen || resultlen > N )
1046 fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
1047 ErrorExit( "LENGTH OVER!\n" );
1054 fprintf( stderr, "jumpi = %d, imid = %d\n", jumpi, imid );
1055 fprintf( stderr, "jumpj = %d, jmid = %d\n", jumpj, jmid );
1057 fprintf( stderr, "imid = %d\n", imid );
1058 fprintf( stderr, "jmid = %d\n", jmid );
1064 FreeFloatVec( initverticalw );
1065 FreeFloatVec( lastverticalw );
1066 FreeFloatVec( midw );
1067 FreeFloatVec( midm );
1068 FreeFloatVec( midn );
1070 FreeIntVec( jumpbacki );
1071 FreeIntVec( jumpbackj );
1072 FreeIntVec( jumpforwi );
1073 FreeIntVec( jumpforwj );
1074 FreeIntVec( jumpdummi );
1075 FreeIntVec( jumpdummj );
1080 FreeFloatMtx( floatwork );
1081 FreeIntMtx( intwork );
1084 FreeFloatMtx( WMMTX );
1085 FreeFloatMtx( WMMTX2 );
1088 // fprintf( stderr, "==== calling myself (first)\n" );
1090 MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ist+jumpi, jst, jst+jumpj, alloclen, aseq1, aseq2, depth, gapinfo );
1091 for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
1092 for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
1094 // fprintf( stderr, "====(f) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
1095 // fprintf( stderr, "====(f) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
1097 len = strlen( mseq1[0] );
1098 // fprintf( stderr, "len = %d\n", len );
1099 l = jmid - jumpj - 1;
1100 // fprintf( stderr, "l=%d\n", l );
1103 for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
1104 for( i=0; i<icyc; i++ )
1106 strcat( mseq1[i], gaps );
1107 mseq1[i][len+l] = 0;
1109 for( j=0; j<jcyc; j++ )
1111 strncat( mseq2[j], seq2[j]+jst+jumpj+1, l );
1112 mseq2[j][len+l] = 0;
1115 len = strlen( mseq1[0] );
1116 l = imid - jumpi - 1;
1117 // fprintf( stderr, "l=%d\n", l );
1120 for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
1121 for( i=0; i<icyc; i++ )
1123 strncat( mseq1[i], seq1[i]+ist+jumpi+1, l );
1124 mseq1[i][len+l] = 0;
1126 for( j=0; j<jcyc; j++ )
1128 strcat( mseq2[j], gaps );
1129 mseq2[j][len+l] = 0;
1133 fprintf( stderr, "after gapfill mseq1[0]=%s\n", mseq1[0] );
1134 fprintf( stderr, "after gapfill mseq2[0]=%s\n", mseq2[0] );
1137 // fprintf( stderr, "==== calling myself (second)\n" );
1139 MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist+imid, ien, jst+jmid, jen, alloclen, aseq1, aseq2, depth, gapinfo );
1141 for( i=0; i<icyc; i++ ) strcat( mseq1[i], aseq1[i] );
1142 for( i=0; i<jcyc; i++ ) strcat( mseq2[i], aseq2[i] );
1144 // fprintf( stderr, "====(s) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
1145 // fprintf( stderr, "====(s) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
1147 // fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
1148 // fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
1151 FreeCharMtx( aseq1 );
1152 FreeCharMtx( aseq2 );
1159 float MSalignmm( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen )
1160 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
1166 float wm; /* int ?????? */
1167 static char **mseq1 = NULL;
1168 static char **mseq2 = NULL;
1179 fprintf( stderr, "eff in SA+++align\n" );
1180 for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
1184 mseq1 = AllocateCharMtx( njob, 0 );
1185 mseq2 = AllocateCharMtx( njob, 0 );
1188 lgth1 = strlen( seq1[0] );
1189 lgth2 = strlen( seq2[0] );
1191 ll1 = ( (int)(1.3*lgth1) ) + 100;
1192 ll2 = ( (int)(1.3*lgth2) ) + 100;
1194 mseq = AllocateCharMtx( njob, ll1+ll2 );
1196 ogcp1 = AllocateFloatVec( ll1+2 );
1197 ogcp2 = AllocateFloatVec( ll2+2 );
1198 fgcp1 = AllocateFloatVec( ll1+2 );
1199 fgcp2 = AllocateFloatVec( ll2+2 );
1201 cpmx1 = AllocateFloatMtx( ll1+2, 26 );
1202 cpmx2 = AllocateFloatMtx( ll2+2, 26 );
1204 for( i=0; i<icyc; i++ ) mseq1[i] = mseq[i];
1205 for( j=0; j<jcyc; j++ ) mseq2[j] = mseq[icyc+j];
1207 MScpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
1208 MScpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
1211 OpeningGapCount( ogcp1, icyc, seq1, eff1 );
1212 OpeningGapCount( ogcp2, jcyc, seq2, eff2 );
1213 FinalGapCount( fgcp1, icyc, seq1, eff1 );
1214 FinalGapCount( fgcp2, jcyc, seq2, eff2 );
1216 for( i=0; i<lgth1; i++ )
1218 ogcp1[i] = 0.5 * ( 1.0 - ogcp1[i] );
1219 fgcp1[i] = 0.5 * ( 1.0 - fgcp1[i] );
1221 for( i=0; i<lgth2; i++ )
1223 ogcp2[i] = 0.5 * ( 1.0 - ogcp2[i] );
1224 fgcp2[i] = 0.5 * ( 1.0 - fgcp2[i] );
1234 fprintf( stdout, "in MSalignmm.c\n" );
1235 for( i=0; i<icyc; i++ )
1237 fprintf( stdout, ">%d of GROUP1\n", i );
1238 fprintf( stdout, "%s\n", seq1[i] );
1240 for( i=0; i<jcyc; i++ )
1242 fprintf( stdout, ">%d of GROUP2\n", i );
1243 fprintf( stdout, "%s\n", seq2[i] );
1248 wm = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, 0, lgth1-1, 0, lgth2-1, alloclen, mseq1, mseq2, 0, gapinfo );
1250 for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
1251 for( i=0; i<jcyc; i++ ) strcpy( seq2[i], mseq2[i] );
1254 FreeFloatVec( ogcp1 );
1255 FreeFloatVec( ogcp2 );
1256 FreeFloatVec( fgcp1 );
1257 FreeFloatVec( fgcp2 );
1258 FreeFloatMtx( cpmx1 );
1259 FreeFloatMtx( cpmx2 );
1261 FreeCharMtx( mseq );