#include "mltaln.h" #include "dp.h" #define DEBUG 0 static void match_calc( double *match, double **cpmx1, double **cpmx2, int i1, int lgth2, double **doublework, int **intwork, int initialize ) { int j, k, l; // double scarr[26]; double **cpmxpd = doublework; int **cpmxpdn = intwork; int count = 0; double *scarr; scarr = calloc( nalphabets, sizeof( double ) ); if( initialize ) { for( j=0; j -1; k++ ) match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j]; } free( scarr ); } static double Atracking( double *lasthorizontalw, double *lastverticalw, char **seq1, char **seq2, char **mseq1, char **mseq2, double **cpmx1, double **cpmx2, int **ijp, int icyc, int jcyc ) { int i, j, k, l, iin, jin, ifi, jfi, lgth1, lgth2; // char gap[] = "-"; char *gap; double wm; gap = newgapstr; lgth1 = strlen( seq1[0] ); lgth2 = strlen( seq2[0] ); #if DEBUG for( i=0; i= wm ) { wm = lastverticalw[i]; iin = i; jin = lgth2-1; ijp[lgth1][lgth2] = +( lgth1 - i ); } } for( j=0; j= wm ) { wm = lasthorizontalw[j]; iin = lgth1-1; jin = j; ijp[lgth1][lgth2] = -( lgth2 - j ); } } } for( i=0; i 0 ) { ifi = iin-ijp[iin][jin]; jfi = jin-1; } else { ifi = iin-1; jfi = jin-1; } l = iin - ifi; while( --l ) { for( i=0; i lgth1, outgap == 1 -> lgth1+1 */ int lgth1, lgth2; int resultlen; double wm = 0.0; /* int ?????? */ double g; double x; static TLS double mi, *m; static TLS int **ijp; static TLS int mpi, *mp; static TLS double *currentw; static TLS double *previousw; static TLS double *match; static TLS double *initverticalw; /* kufuu sureba iranai */ static TLS double *lastverticalw; /* kufuu sureba iranai */ static TLS char **mseq1; static TLS char **mseq2; static TLS char **mseq; static TLS double **cpmx1; static TLS double **cpmx2; static TLS int **intwork; static TLS double **doublework; static TLS int orlgth1 = 0, orlgth2 = 0; #if DEBUG fprintf( stderr, "eff in SA+++align\n" ); for( i=0; i orlgth1 || lgth2 > orlgth2 ) { int ll1, ll2; if( orlgth1 > 0 && orlgth2 > 0 ) { FreeFloatVec( currentw ); FreeFloatVec( previousw ); FreeFloatVec( match ); FreeFloatVec( initverticalw ); FreeFloatVec( lastverticalw ); FreeFloatVec( m ); FreeIntVec( mp ); FreeCharMtx( mseq ); FreeFloatMtx( cpmx1 ); FreeFloatMtx( cpmx2 ); FreeFloatMtx( doublework ); FreeIntMtx( intwork ); } ll1 = MAX( (int)(1.1*lgth1), orlgth1 ) + 100; ll2 = MAX( (int)(1.1*lgth2), orlgth2 ) + 100; fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 ); currentw = AllocateFloatVec( ll2+2 ); previousw = AllocateFloatVec( ll2+2 ); match = AllocateFloatVec( ll2+2 ); initverticalw = AllocateFloatVec( ll1+2 ); lastverticalw = AllocateFloatVec( ll1+2 ); m = AllocateFloatVec( ll2+2 ); mp = AllocateIntVec( ll2+2 ); mseq = AllocateCharMtx( njob, ll1+ll2 ); cpmx1 = AllocateFloatMtx( nalphabets, ll1+2 ); cpmx2 = AllocateFloatMtx( nalphabets, ll2+2 ); doublework = AllocateFloatMtx( nalphabets, MAX( ll1, ll2 )+2 ); intwork = AllocateIntMtx( nalphabets, MAX( ll1, ll2 )+2 ); fprintf( stderr, "succeeded\n" ); orlgth1 = ll1; orlgth2 = ll2; } for( i=0; i commonAlloc1 || orlgth2 > commonAlloc2 ) { int ll1, ll2; if( commonAlloc1 && commonAlloc2 ) { FreeIntMtx( commonIP ); } ll1 = MAX( orlgth1, commonAlloc1 ); ll2 = MAX( orlgth2, commonAlloc2 ); fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 ); commonIP = AllocateIntMtx( ll1+10, ll2+10 ); fprintf( stderr, "succeeded\n\n" ); commonAlloc1 = ll1; commonAlloc2 = ll2; } ijp = commonIP; cpmx_calc( seq1, cpmx1, eff1, strlen( seq1[0] ), icyc ); cpmx_calc( seq2, cpmx2, eff2, strlen( seq2[0] ), jcyc ); match_calc( initverticalw, cpmx2, cpmx1, 0, lgth1, doublework, intwork, 1 ); match_calc( currentw, cpmx1, cpmx2, 0, lgth2, doublework, intwork, 1 ); if( outgap == 1 ) { for( i=1; i wm ) { wm = x; ijp[i][j] = -( j - mpi ); } g = penalty * 0.5; x = previousw[j-1] + g; if( mi <= x ) { mi = x; mpi = j-1; } g = penalty * 0.5; x = m[j] + g; if( x > wm ) { wm = x; ijp[i][j] = +( i - mp[j] ); } g = penalty * 0.5; x = previousw[j-1] + g; if( m[j] <= x ) { m[j] = x; mp[j] = i-1; } currentw[j] += wm; } lastverticalw[i] = currentw[lgth2-1]; } /* fprintf( stderr, "\n" ); for( i=0; i" ); for( i=0; i N ) { fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N ); ErrorExit( "LENGTH OVER!\n" ); } for( i=0; i