6 #define USE_PENALTY_EX 0
13 static void OpeningGapCount( float *ogcp, int clus, char **seq, double *eff )
16 int len = strlen( seq[0] );
19 for( i=0; i<len; i++ ) ogcp[i] = 0.0;
20 for( j=0; j<clus; j++ )
23 for( i=0; i<len; i++ )
26 gc = ( seq[j][i] == '-' );
28 if( !gb * gc ) ogcp[i] += eff[j];
33 for( i=0; i<len; i++ )
37 static void FinalGapCount( float *fgcp, int clus, char **seq, double *eff )
40 int len = strlen( seq[0] );
43 for( i=0; i<len; i++ ) fgcp[i] = 0.0;
44 for( j=0; j<clus; j++ )
46 gc = ( seq[j][0] == '-' );
47 for( i=1; i<len+1; i++ )
50 gc = ( seq[j][i] == '-' );
52 if( gb * !gc ) fgcp[i-1] += eff[j];
57 for( i=0; i<len; i++ )
61 static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
65 float **cpmxpd = floatwork;
66 int **cpmxpdn = intwork;
71 for( j=0; j<lgth2; j++ )
78 cpmxpd[j][count] = cpmx2[j][l];
79 cpmxpdn[j][count] = l;
83 cpmxpdn[j][count] = -1;
92 scarr[l] += n_dis[k][l] * cpmx1[i1][k];
95 #if 0 /* ¤³¤ì¤ò»È¤¦¤È¤
\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
97 float *fpt, **fptpt, *fpt2;
105 ipt=*iptpt,fpt=*fptpt;
107 *fpt2 += scarr[*ipt++] * *fpt++;
108 fpt2++,iptpt++,fptpt++;
112 for( j=0; j<lgth2; j++ )
115 for( k=0; cpmxpdn[j][k]>-1; k++ )
116 match[j] += scarr[cpmxpdn[j][k]] * cpmxpd[j][k];
121 static float Atracking( float *lasthorizontalw, float *lastverticalw,
122 char **seq1, char **seq2,
123 char **mseq1, char **mseq2,
124 float **cpmx1, float **cpmx2,
125 short **ijp, int icyc, int jcyc,
126 int ist, int ien, int jst, int jen )
128 int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, klim;
135 for( i=0; i<lgth1; i++ )
137 fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
142 // fprintf( stderr, "in Atracking, lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
144 for( i=0; i<lgth1+1; i++ )
148 for( j=0; j<lgth2+1; j++ )
150 ijp[0][j] = -( j + 1 );
154 for( i=0; i<icyc; i++ )
156 mseq1[i] += lgth1+lgth2;
159 for( j=0; j<jcyc; j++ )
161 mseq2[j] += lgth1+lgth2;
165 // if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
167 iin = lgth1; jin = lgth2;
169 for( k=0; k<=klim; k++ )
171 if( ijp[iin][jin] < 0 )
173 ifi = iin-1; jfi = jin+ijp[iin][jin];
175 else if( ijp[iin][jin] > 0 )
177 ifi = iin-ijp[iin][jin]; jfi = jin-1;
181 ifi = iin-1; jfi = jin-1;
186 for( i=0; i<icyc; i++ )
187 *--mseq1[i] = seq1[i][ist+ifi+l];
188 for( j=0; j<jcyc; j++ )
195 for( i=0; i<icyc; i++ )
197 for( j=0; j<jcyc; j++ )
198 *--mseq2[j] = seq2[j][jst+jfi+l];
201 if( iin <= 0 || jin <= 0 ) break;
202 for( i=0; i<icyc; i++ )
203 *--mseq1[i] = seq1[i][ist+ifi];
204 for( j=0; j<jcyc; j++ )
205 *--mseq2[j] = seq2[j][jst+jfi];
207 iin = ifi; jin = jfi;
209 // if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
211 // fprintf( stderr, "in Atracking (owari), mseq1 = %s\n", mseq1[0] );
212 // fprintf( stderr, "in Atracking (owari), mseq2 = %s\n", mseq2[0] );
216 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] )
217 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
224 float wm; /* int ?????? */
226 float *currentw, *previousw;
227 float fpenalty = (float)penalty;
228 float fpenalty_ex = (float)penalty_ex;
232 float *mjpt, *prept, *curpt;
239 float *initverticalw; /* kufuu sureba iranai */
240 float *lastverticalw; /* kufuu sureba iranai */
246 float *ogcp1 = gapinfo[0];
247 float *fgcp1 = gapinfo[1];
248 float *ogcp2 = gapinfo[2];
249 float *fgcp2 = gapinfo[3];
250 static char **aseq1 = NULL;
251 static char **aseq2 = NULL;
252 static char **aseq1bk, **aseq2bk;
254 // char ttt1[10000], ttt2[10000];
258 aseq1 = AllocateCharMtx( njob, 0 );
259 aseq2 = AllocateCharMtx( njob, 0 );
265 // strncpy( ttt1, seq1[0]+ist, lgth1 ); ttt1[lgth1] = 0;
266 // strncpy( ttt2, seq2[0]+jst, lgth2 ); ttt2[lgth2] = 0;
268 // fprintf( stderr, "in _tanni ist,ien = %d,%d, lgth1=%d\n", ist, ien, lgth1 );
269 // fprintf( stderr, "in _tanni jst,jen = %d,%d, lgth2=%d\n", jst, jen, lgth2 );
270 // fprintf( stderr, "ttt1 = %s\n", ttt1 );
271 // fprintf( stderr, "ttt2 = %s\n", ttt2 );
274 ll1 = ( (int)(1.3*lgth1) ) + 100;
275 ll2 = ( (int)(1.3*lgth2) ) + 100;
277 aseq1bk = AllocateCharMtx( icyc, lgth1+lgth2+100 );
278 aseq2bk = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
279 for( i=0; i<icyc; i++ ) aseq1[i] = aseq1bk[i];
280 for( i=0; i<jcyc; i++ ) aseq2[i] = aseq2bk[i];
282 w1 = AllocateFloatVec( ll2+2 );
283 w2 = AllocateFloatVec( ll2+2 );
285 initverticalw = AllocateFloatVec( ll1+2 );
286 lastverticalw = AllocateFloatVec( ll1+2 );
288 m = AllocateFloatVec( ll2+2 );
289 mp = AllocateIntVec( ll2+2 );
291 floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 );
292 intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 );
295 shortmtx = AllocateShortMtx( ll1+1, ll2+1 );
302 match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
304 match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
306 for( i=1; i<lgth1+1; i++ )
308 initverticalw[i] += fpenalty * ( ogcp1[0] + fgcp1[i-1] );
310 for( j=1; j<lgth2+1; j++ )
312 currentw[j] += fpenalty * ( ogcp2[0] + fgcp2[j-1] );
315 for( j=1; j<lgth2+1; ++j )
317 m[j] = currentw[j-1] + fpenalty * ogcp1[1]; mp[j] = 0;;
320 lastverticalw[0] = currentw[lgth2-1];
324 for( i=1; i<lasti; i++ )
328 previousw = currentw;
331 previousw[0] = initverticalw[i-1];
333 match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
334 currentw[0] = initverticalw[i];
336 mi = previousw[0] + fpenalty * ogcp2[1];
342 curpt = currentw + 1;
345 for( j=1; j<lastj; j++ )
351 fprintf( stderr, "%5.0f->", wm );
353 g = mi + fpenalty * fgcp2[j-1];
355 fprintf( stderr, "%5.0f?", g );
360 *ijppt = -( j - mpi );
362 g = *prept + fpenalty * ogcp2[j];
372 g = *mjpt + fpenalty * fgcp1[i-1];
374 fprintf( stderr, "%5.0f?", g );
379 *ijppt = +( i - *mpjpt );
381 g = *prept + fpenalty * ogcp1[i];
392 fprintf( stderr, "%5.0f ", wm );
403 lastverticalw[i] = currentw[lgth2-1];
407 Atracking( currentw, lastverticalw, seq1, seq2, aseq1, aseq2, cpmx1+ist, cpmx2+jst, ijp, icyc, jcyc, ist, ien, jst, jen );
409 for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
410 for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
412 // fprintf( stderr, "in _tanni, aseq1 = %s\n", aseq1[0] );
413 // fprintf( stderr, "in _tanni, mseq1 = %s\n", mseq1[0] );
417 FreeFloatVec( initverticalw );
418 FreeFloatVec( lastverticalw );
424 FreeFloatMtx( floatwork );
425 FreeIntMtx( intwork );
427 FreeShortMtx( shortmtx );
429 FreeCharMtx( aseq1bk );
430 FreeCharMtx( aseq2bk );
435 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] )
436 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
440 char **aseq1, **aseq2;
441 int ll1, ll2, l, len;
442 int lasti, lastj, imid, jmid;
444 float wm; /* int ?????? */
446 float *currentw, *previousw;
447 float fpenalty = (float)penalty;
448 float fpenalty_ex = (float)penalty_ex;
455 float *mjpt, *prept, *curpt;
460 float *initverticalw; /* kufuu sureba iranai */
461 float *lastverticalw; /* kufuu sureba iranai */
474 int *jumpdumm; //muda
479 // static char ttt1[50000];
480 // static char ttt2[50000];
488 // fprintf( stderr, "==== MSalign (depth=%d, reccycle=%d), ist=%d, ien=%d, jst=%d, jen=%d\n", depth, reccycle, ist, ien, jst, jen );
489 // strncpy( ttt1, seq1[0]+ist, lgth1 );
490 // strncpy( ttt2, seq2[0]+jst, lgth2 );
491 // fprintf( stderr, "seq1 = %s\n", ttt1 );
492 // fprintf( stderr, "seq2 = %s\n", ttt2 );
495 // fprintf( stderr, "==== jimei\n" );
496 for( i=0; i<icyc; i++ )
498 strncpy( mseq1[i], seq1[i]+ist, lgth1 );
501 for( i=0; i<jcyc; i++ )
504 for( j=0; j<lgth1; j++ )
505 strcat( mseq2[i], "-" );
508 // fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
509 // fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
511 return( (float)offset * lgth1 );
514 aseq1 = AllocateCharMtx( icyc, lgth1+lgth2+100 );
515 aseq2 = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
517 if( lgth1 < DPTANNI )
519 // fprintf( stderr, "==== Going to _tanni\n" );
521 wm = MSalignmm_tanni( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ien, jst, jen, alloclen, aseq1, aseq2, gapinfo );
524 for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
525 for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
527 // fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
528 // fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
530 // fprintf( stderr, "freeing aseq\n" );
531 FreeCharMtx( aseq1 );
532 FreeCharMtx( aseq2 );
536 // fprintf( stderr, "Trying to divide the mtx\n" );
538 ll1 = ( (int)(1.3*lgth1) ) + 100;
539 ll2 = ( (int)(1.3*lgth2) ) + 100;
541 // fprintf( stderr, "ll1,ll2=%d,%d\n", ll1, ll2 );
543 w1 = AllocateFloatVec( ll2+2 );
544 w2 = AllocateFloatVec( ll2+2 );
545 // match = AllocateFloatVec( ll2+2 );
546 midw = AllocateFloatVec( ll2+2 );
547 midm = AllocateFloatVec( ll2+2 );
548 jumpback = AllocateIntVec( ll2+2 );
549 jumpforw = AllocateIntVec( ll2+2 );
550 jumpdumm = AllocateIntVec( ll2+2 );
552 initverticalw = AllocateFloatVec( ll1+2 );
553 lastverticalw = AllocateFloatVec( ll1+2 );
555 m = AllocateFloatVec( ll2+2 );
556 mp = AllocateIntVec( ll2+2 );
557 gaps = AllocateCharVec( MAX( ll1, ll2 ) + 2 );
559 floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 );
560 intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 );
563 fprintf( stderr, "succeeded\n" );
567 WMMTX = AllocateFloatMtx( ll1, ll2 );
568 WMMTX2 = AllocateFloatMtx( ll1, ll2 );
571 shortmtx = AllocateShortMtx( ll1, ll2 );
574 fprintf( stderr, "succeeded\n\n" );
583 match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
585 match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
587 // WMMTX[0][0] = initverticalw[0];
588 for( i=1; i<lgth1+1; i++ )
590 initverticalw[i] += fpenalty;
591 // WMMTX[i][0] = initverticalw[i];
593 for( j=1; j<lgth2+1; j++ )
595 currentw[j] += fpenalty;
596 // WMMTX[0][j] = currentw[j];
599 for( j=1; j<lgth2+1; ++j )
601 m[j] = currentw[j-1];
604 lastverticalw[0] = currentw[lgth2-1];
609 // for( i=1; i<lasti; i++ )
610 for( i=1; i<=imid; i++ )
613 previousw = currentw;
616 previousw[0] = initverticalw[i-1];
618 match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
619 currentw[0] = initverticalw[i];
625 // ijppt = ijp[i] + 1;
628 curpt = currentw + 1;
630 if( i == imid ) jumppt = jumpback+1;
631 else jumppt = jumpdumm+1;
633 for( j=1; j<lastj; j++ )
636 *jumppt = 0; // muda atode saishukai dake matomeru
640 fprintf( stderr, "%5.0f->", wm );
644 fprintf( stderr, "%5.0f?", g );
649 *jumppt = +mpi; // muda atode matomeru
650 // *ijppt = -( j - mpi );
662 // fprintf( stderr, "i,j=%d,%d *mpjpt (f)= %d\n", i, j, *mpjpt );
663 g = *mjpt + fpenalty;
665 fprintf( stderr, "%5.0f?", g );
670 // *ijppt = +( i - *mpjpt );
671 *jumppt = -*mpjpt; // muda atode matomeru
684 fprintf( stderr, "%5.0f ", wm );
688 // WMMTX[i][j] = *curpt;
689 // WMMTX2[i][j] = *mjpt;
691 if( i == imid ) //muda
705 lastverticalw[i] = currentw[lgth2-1];
709 for( j=0; j<lgth2; j++ ) midw[j] = currentw[j];
710 for( j=0; j<lgth2; j++ ) midm[j] = m[j];
714 // for( j=0; j<lgth2; j++ ) midw[j] = WMMTX[imid][j];
715 // for( j=0; j<lgth2; j++ ) midm[j] = WMMTX2[imid][j];
718 for( i=0; i<lgth1; i++ )
720 for( j=0; j<lgth2; j++ )
722 fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
724 fprintf( stderr, "\n" );
726 fprintf( stderr, "\n" );
727 fprintf( stderr, "WMMTX2 = \n" );
728 for( i=0; i<lgth1; i++ )
730 for( j=0; j<lgth2; j++ )
732 fprintf( stderr, "% 10.2f ", WMMTX2[i][j] );
734 fprintf( stderr, "\n" );
736 fprintf( stderr, "\n" );
741 match_calc( initverticalw, cpmx2+jst, cpmx1+ist, lgth2-1, lgth1, floatwork, intwork, 1 );
742 match_calc( currentw, cpmx1+ist, cpmx2+jst, lgth1-1, lgth2, floatwork, intwork, 1 );
744 for( i=0; i<lgth1-1; i++ )
746 initverticalw[i] += fpenalty;
747 // WMMTX[i][lgth2-1] += fpenalty;
749 for( j=0; j<lgth2-1; j++ )
751 currentw[j] += fpenalty;
752 // WMMTX[lgth1-1][j] += fpenalty;
755 for( j=lgth2-1; j>0; --j )
757 m[j-1] = currentw[j];
761 // for( j=0; j<lgth2; j++ ) m[j] = 0.0;
762 // m[lgth2-1] ha irunoka?
764 for( i=lgth1-2; i>=imid; i-- )
765 // for( i=lgth1-2; i>-1; i-- )
768 previousw = currentw;
770 previousw[lgth2-1] = initverticalw[i+1];
771 // match_calc( currentw, seq1, seq2, i, lgth2 );
772 match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
774 currentw[lgth2-1] = initverticalw[i];
776 mi = previousw[lgth2-1];
779 mjpt = m + lgth2 - 2;
780 prept = previousw + lgth2 - 1;
781 curpt = currentw + lgth2 - 2;
782 mpjpt = mp + lgth2 - 2;
783 if( i == imid ) jumppt = jumpforw + lgth2 - 2;
784 else jumppt = jumpdumm + lgth2 - 2;
786 for( j=lgth2-2; j>-1; j-- )
795 *jumppt = +mpi; //muda
809 // fprintf( stderr, "i,j=%d,%d *mpjpt = %d\n", i, j, *mpjpt );
810 g = *mjpt + fpenalty;
814 *jumppt = -*mpjpt; //muda
820 // fprintf( stderr, "mjpt: %f->%f (%d,%d)\n", *mjpt, g, i, j );
829 if( i == imid ) // muda
832 midm[j+1] += *mjpt + fpenalty;
834 // WMMTX[i][j] += wm;
835 // WMMTX2[i][j+1] += *mjpt + fpenalty;
846 // for( j=0; j<lgth2; j++ ) midw[j] += currentw[j];
847 // for( j=0; j<lgth2; j++ ) midm[j] += m[j+1];
848 // for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
849 // for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
852 fprintf( stderr, "WMMTX = \n" );
853 for( i=0; i<lgth1; i++ )
855 fprintf( stderr, "%d ", i );
856 for( j=0; j<lgth2; j++ )
858 fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
860 fprintf( stderr, "\n" );
862 fprintf( stderr, "WMMTX2 = (p = %f)\n", fpenalty );
863 for( i=0; i<lgth1; i++ )
865 fprintf( stderr, "%d ", i );
866 for( j=0; j<lgth2; j++ )
868 fprintf( stderr, "% 10.2f ", WMMTX2[i][j] );
870 fprintf( stderr, "\n" );
873 fprintf( stderr, "midw = \n" );
874 for( j=0; j<lgth2; j++ )
876 fprintf( stderr, "% 10.2f ", midw[j] );
878 fprintf( stderr, "\n" );
879 fprintf( stderr, "midm = \n" );
880 for( j=0; j<lgth2; j++ )
882 fprintf( stderr, "% 10.2f ", midm[j] );
884 fprintf( stderr, "\n" );
885 fprintf( stderr, "jumpback = \n" );
886 for( j=0; j<lgth2; j++ )
888 fprintf( stderr, "% 10d ", jumpback[j] );
890 fprintf( stderr, "\n" );
891 fprintf( stderr, "jumpforw = \n" );
892 for( j=0; j<lgth2; j++ )
894 fprintf( stderr, "% 10d ", jumpforw[j] );
896 fprintf( stderr, "\n" );
899 // Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
902 resultlen = strlen( mseq1[0] );
903 if( alloclen < resultlen || resultlen > N )
905 fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
906 ErrorExit( "LENGTH OVER!\n" );
911 maxwm = -999999999.9;
913 for( j=0; j<lgth2; j++ )
929 fprintf( stderr, "jmid=%d, maxwm = %f\n", jmid, maxwm );
930 fprintf( stderr, "jumpforw[%d] = %d\n", jmid, jumpforw[jmid] );
931 fprintf( stderr, "jumpback[%d] = %d\n", jmid, jumpback[jmid] );
933 if( jumpback[jmid] == 0 )
938 else if( jumpback[jmid] < 0 )
940 jumpi = - jumpback[jmid];
946 jumpj = jumpback[jmid];
949 if( jumpforw[jmid] == 0 )
953 else if( jumpforw[jmid] < 0 )
955 imid = - jumpforw[jmid];
956 fprintf( stderr, "XXXX imid = %d", imid );
960 fprintf( stderr, "OXOXO" );
961 jmid = jumpforw[jmid];
969 fprintf( stderr, "jumpi = %d, imid = %d\n", jumpi, imid );
970 fprintf( stderr, "jumpj = %d, jmid = %d\n", jumpj, jmid );
972 fprintf( stderr, "imid = %d\n", imid );
973 fprintf( stderr, "jmid = %d\n", jmid );
979 // FreeFloatVec( match );
980 FreeFloatVec( initverticalw );
981 FreeFloatVec( lastverticalw );
982 FreeFloatVec( midw );
983 FreeFloatVec( midm );
985 FreeIntVec( jumpback );
986 FreeIntVec( jumpforw );
987 FreeIntVec( jumpdumm );
993 FreeFloatMtx( floatwork );
994 FreeIntMtx( intwork );
996 // FreeShortMtx( shortmtx );
997 // FreeFloatMtx( WMMTX );
998 // FreeFloatMtx( WMMTX2 );
1000 // fprintf( stderr, "==== calling myself (first)\n" );
1002 MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ist+jumpi, jst, jst+jumpj, alloclen, aseq1, aseq2, depth, gapinfo );
1003 for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
1004 for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
1006 // fprintf( stderr, "====(f) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
1007 // fprintf( stderr, "====(f) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
1009 len = strlen( mseq1[0] );
1010 // fprintf( stderr, "len = %d\n", len );
1011 l = jmid - jumpj - 1;
1015 fprintf( stderr, "l=%d\n", l );
1016 for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
1017 for( i=0; i<icyc; i++ )
1019 strcat( mseq1[i], gaps );
1020 mseq1[i][len+l] = 0;
1022 for( j=0; j<jcyc; j++ )
1024 strncat( mseq2[j], seq2[j]+jst+jumpj+1, l );
1025 mseq2[j][len+l] = 0;
1028 l = imid - jumpi - 1;
1031 fprintf( stderr, "l=%d\n", l );
1032 for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
1033 for( i=0; i<icyc; i++ )
1035 strncat( mseq1[i], seq1[i]+ist+jumpi+1, l );
1036 mseq1[i][len+l] = 0;
1038 for( j=0; j<jcyc; j++ )
1040 strcat( mseq2[j], gaps );
1041 mseq2[j][len+l] = 0;
1045 // fprintf( stderr, "after gapfill mseq1[0]=%s\n", mseq1[0] );
1046 // fprintf( stderr, "after gapfill mseq2[0]=%s\n", mseq2[0] );
1048 // fprintf( stderr, "==== calling myself (second)\n" );
1050 MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist+imid, ien, jst+jmid, jen, alloclen, aseq1, aseq2, depth, gapinfo );
1052 for( i=0; i<icyc; i++ ) strcat( mseq1[i], aseq1[i] );
1053 for( i=0; i<jcyc; i++ ) strcat( mseq2[i], aseq2[i] );
1055 // fprintf( stderr, "====(s) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
1056 // fprintf( stderr, "====(s) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
1058 // fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
1059 // fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
1061 FreeCharMtx( aseq1 );
1062 FreeCharMtx( aseq2 );
1069 float MSalignmm( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen )
1070 /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
1076 float wm; /* int ?????? */
1077 static char **mseq1 = NULL;
1078 static char **mseq2 = NULL;
1089 fprintf( stderr, "eff in SA+++align\n" );
1090 for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
1094 mseq1 = AllocateCharMtx( njob, 0 );
1095 mseq2 = AllocateCharMtx( njob, 0 );
1098 lgth1 = strlen( seq1[0] );
1099 lgth2 = strlen( seq2[0] );
1101 ll1 = ( (int)(1.3*lgth1) ) + 100;
1102 ll2 = ( (int)(1.3*lgth2) ) + 100;
1104 mseq = AllocateCharMtx( njob, ll1+ll2 );
1106 ogcp1 = AllocateFloatVec( ll1+2 );
1107 ogcp2 = AllocateFloatVec( ll2+2 );
1108 fgcp1 = AllocateFloatVec( ll1+2 );
1109 fgcp2 = AllocateFloatVec( ll2+2 );
1111 cpmx1 = AllocateFloatMtx( ll1+2, 26 );
1112 cpmx2 = AllocateFloatMtx( ll2+2, 26 );
1114 for( i=0; i<icyc; i++ ) mseq1[i] = mseq[i];
1115 for( j=0; j<jcyc; j++ ) mseq2[j] = mseq[icyc+j];
1117 MScpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
1118 MScpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
1121 OpeningGapCount( ogcp1, icyc, seq1, eff1 );
1122 OpeningGapCount( ogcp2, jcyc, seq2, eff2 );
1123 FinalGapCount( fgcp1, icyc, seq1, eff1 );
1124 FinalGapCount( fgcp2, jcyc, seq2, eff2 );
1126 for( i=0; i<lgth1; i++ )
1128 ogcp1[i] = 0.5 * ( 1.0 - ogcp1[i] );
1129 fgcp1[i] = 0.5 * ( 1.0 - fgcp1[i] );
1131 for( i=0; i<lgth2; i++ )
1133 ogcp2[i] = 0.5 * ( 1.0 - ogcp2[i] );
1134 fgcp2[i] = 0.5 * ( 1.0 - fgcp2[i] );
1144 fprintf( stdout, "in MSalignmm.c\n" );
1145 for( i=0; i<icyc; i++ )
1147 fprintf( stdout, ">%d of GROUP1\n", i );
1148 fprintf( stdout, "%s\n", seq1[i] );
1150 for( i=0; i<jcyc; i++ )
1152 fprintf( stdout, ">%d of GROUP2\n", i );
1153 fprintf( stdout, "%s\n", seq2[i] );
1158 wm = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, 0, lgth1-1, 0, lgth2-1, alloclen, mseq1, mseq2, 0, gapinfo );
1160 for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
1161 for( i=0; i<jcyc; i++ ) strcpy( seq2[i], mseq2[i] );
1164 FreeFloatVec( ogcp1 );
1165 FreeFloatVec( ogcp2 );
1166 FreeFloatVec( fgcp1 );
1167 FreeFloatVec( fgcp2 );
1168 FreeFloatMtx( cpmx1 );
1169 FreeFloatMtx( cpmx2 );
1171 FreeCharMtx( mseq );