#include "mltaln.h" #define DEBUG 0 #define DEBUG2 0 #define XXXXXXX 0 #define USE_PENALTY_EX 1 #if 1 static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 ) { char *seq2 = s2[0]; int *intptr; intptr = amino_dis[(int)s1[0][i1]]; while( lgth2-- ) *match++ = intptr[(int)*seq2++]; } #else static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 ) { int j; for( j=0; j -1 ) *fpt2 += scarr[*ipt++] * *fpt++; fpt2++,iptpt++,fptpt++; } } #else for( j=0; j-1; k++ ) match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j]; } #endif } #endif static float Ltracking( float *lasthorizontalw, float *lastverticalw, char **seq1, char **seq2, char **mseq1, char **mseq2, int **ijp, int *off1pt, int *off2pt, int endi, int endj, int localstop ) { int i, j, l, iin, jin, lgth1, lgth2, k, limk; int ifi=0, jfi=0; // by D.Mathog, a guess char gap[] = "-"; lgth1 = strlen( seq1[0] ); lgth2 = strlen( seq2[0] ); #if 0 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 ) { *--mseq1[0] = seq1[0][ifi+l]; *--mseq2[0] = *gap; k++; } l= jin - jfi; while( --l ) { *--mseq1[0] = *gap; *--mseq2[0] = seq2[0][jfi+l]; k++; } if( iin <= 0 || jin <= 0 ) break; *--mseq1[0] = seq1[0][ifi]; *--mseq2[0] = seq2[0][jfi]; if( ijp[ifi][jfi] == localstop ) break; k++; iin = ifi; jin = jfi; } if( ifi == -1 ) *off1pt = 0; else *off1pt = ifi; if( jfi == -1 ) *off2pt = 0; else *off2pt = jfi; // fprintf( stderr, "ifn = %d, jfn = %d\n", ifi, jfi ); return( 0.0 ); } float L__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt ) /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */ { // int k; register int i, j; int lasti, lastj; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */ int lgth1, lgth2; int resultlen; float wm = 0.0; /* int ?????? */ float g; float *currentw, *previousw; #if 1 float *wtmp; int *ijppt; float *mjpt, *prept, *curpt; int *mpjpt; #endif float mi, *m; int **ijp; int mpi, *mp; float *w1, *w2; float *match; float *initverticalw; /* kufuu sureba iranai */ float *lastverticalw; /* kufuu sureba iranai */ char **mseq1; char **mseq2; char **mseq; // int **intwork; // float **floatwork; float maxwm; int endali = 0, endalj = 0; // by D.Mathog, a guess // int endali, endalj; float localthr = -offset; float localthr2 = -offset; // float localthr = 100; // float localthr2 = 100; float fpenalty = (float)penalty; float fpenalty_ex = (float)penalty_ex; int **localIP = NULL; int localAlloc1 = 0, localAlloc2 = 0; int localstop; // 060910 mseq1 = AllocateCharMtx( njob, 0 ); mseq2 = AllocateCharMtx( njob, 0 ); lgth1 = strlen( seq1[0] ); lgth2 = strlen( seq2[0] ); { int ll1, ll2; ll1 = (int)(1.3*lgth1) + 100; ll2 = (int)(1.3*lgth2) + 100; #if DEBUG fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 ); #endif w1 = AllocateFloatVec( ll2+2 ); w2 = 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 ); // floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); // intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); #if DEBUG fprintf( stderr, "succeeded\n" ); #endif } mseq1[0] = mseq[0]; mseq2[0] = mseq[1]; { int ll1, ll2; ll1 = (int)(1.3*lgth1) + 100; ll2 = (int)(1.3*lgth2) + 100; #if DEBUG fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 ); #endif localIP = AllocateIntMtx( ll1+10, ll2+10 ); #if DEBUG fprintf( stderr, "succeeded\n\n" ); #endif localAlloc1 = ll1; localAlloc2 = ll2; } ijp = localIP; #if 0 for( i=0; i", wm ); #endif #if 0 fprintf( stderr, "%5.0f?", g ); #endif if( (g=mi+fpenalty) > wm ) { wm = g; *ijppt = -( j - mpi ); } if( *prept > mi ) { mi = *prept; mpi = j-1; } #if USE_PENALTY_EX mi += fpenalty_ex; #endif #if 0 fprintf( stderr, "%5.0f?", g ); #endif if( (g=*mjpt+fpenalty) > wm ) { wm = g; *ijppt = +( i - *mpjpt ); } if( *prept > *mjpt ) { *mjpt = *prept; *mpjpt = i-1; } #if USE_PENALTY_EX *mjpt += fpenalty_ex; #endif if( maxwm < wm ) { maxwm = wm; endali = i; endalj = j; } #if 1 if( wm < localthr ) { // fprintf( stderr, "stop i=%d, j=%d, curpt=%f\n", i, j, *curpt ); *ijppt = localstop; wm = localthr2; } #endif #if 0 fprintf( stderr, "%5.0f ", *curpt ); #endif #if DEBUG2 fprintf( stderr, "%5.0f ", wm ); // fprintf( stderr, "%c-%c *ijppt = %d, localstop = %d\n", seq1[0][i], seq2[0][j], *ijppt, localstop ); #endif *curpt++ += wm; ijppt++; mjpt++; prept++; mpjpt++; } #if DEBUG2 fprintf( stderr, "\n" ); #endif lastverticalw[i] = currentw[lgth2-1]; } #if 0 fprintf( stderr, "maxwm = %f\n", maxwm ); fprintf( stderr, "endali = %d\n", endali ); fprintf( stderr, "endalj = %d\n", endalj ); #endif if( ijp[endali][endalj] == localstop ) { strcpy( seq1[0], "" ); strcpy( seq2[0], "" ); *off1pt = *off2pt = 0; return( 0.0 ); } Ltracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, ijp, off1pt, off2pt, endali, endalj, localstop ); resultlen = strlen( mseq1[0] ); if( alloclen < resultlen || resultlen > N ) { fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N ); ErrorExit( "LENGTH OVER!\n" ); } strcpy( seq1[0], mseq1[0] ); strcpy( seq2[0], mseq2[0] ); #if 0 fprintf( stderr, "wm=%f\n", wm ); fprintf( stderr, ">\n%s\n", mseq1[0] ); fprintf( stderr, ">\n%s\n", mseq2[0] ); fprintf( stderr, "maxwm = %f\n", maxwm ); fprintf( stderr, " wm = %f\n", wm ); #endif FreeFloatVec( w1 ); FreeFloatVec( w2 ); FreeFloatVec( match ); FreeFloatVec( initverticalw ); FreeFloatVec( lastverticalw ); FreeFloatVec( m ); FreeIntVec( mp ); FreeCharMtx( mseq ); // FreeFloatMtx( floatwork ); // FreeIntMtx( intwork ); FreeIntMtx( localIP ); return( maxwm ); }