#include "mltaln.h" #if 0 static FILE *fftfp; #endif static TLS int n20or4or2; #define KEIKA 0 #define RND 0 #define DEBUG 0 #if RND // by D.Mathog static void generateRndSeq( char *seq, int len ) { while( len-- ) #if 1 *seq++ = (int)( rnd() * n20or4or2 ); #else *seq++ = (int)1; #endif } #endif static void vec_init( Fukusosuu *result, int nlen ) { while( nlen-- ) { result->R = result->I = 0.0; result++; } } #if 0 // by D.Mathog static void vec_init2( Fukusosuu **result, char *seq, double eff, int st, int ed ) { int i; for( i=st; i= 0 ) result->R += incr * score[n]; #if 0 fprintf( stderr, "n=%d, score=%f, inc=%f R=%f\n",n, score[n], incr * score[n], result->R ); #endif } } static void seq_vec_3( Fukusosuu **result, double incr, char *seq ) { int i; int n; for( i=0; *seq; i++ ) { n = amino_n[(int)*seq++]; if( n < n20or4or2 && n >= 0 ) result[n][i].R += incr; } } static void seq_vec_5( Fukusosuu *result, double *score1, double *score2, double incr, char *seq ) { int n; for( ; *seq; result++ ) { n = amino_n[(int)*seq++]; if( n > 20 ) continue; result->R += incr * score1[n]; result->I += incr * score2[n]; #if 0 fprintf( stderr, "n=%d, score=%f, inc=%f R=%f\n",n, score[n], incr * score[n], result->R ); #endif } } static void seq_vec_4( Fukusosuu *result, double incr, char *seq ) { char s; for( ; *seq; result++ ) { s = *seq++; if( s == 'a' ) result->R += incr; else if( s == 't' ) result->R -= incr; else if( s == 'g' ) result->I += incr; else if( s == 'c' ) result->I -= incr; } } #if 0 // by D.Mathog static void seq_vec( Fukusosuu *result, char query, double incr, char *seq ) { #if 0 int bk = nlen; #endif while( *seq ) { if( *seq++ == query ) result->R += incr; result++; #if 0 fprintf( stderr, "i = %d result->R = %f\n", bk-nlen, (result-1)->R ); #endif } } static int checkRepeat( int num, int *cutpos ) { int tmp, buf; buf = *cutpos; while( num-- ) { if( ( tmp = *cutpos++ ) < buf ) return( 1 ); buf = tmp; } return( 0 ); } static int segcmp( void *ptr1, void *ptr2 ) { int diff; Segment **seg1 = (Segment **)ptr1; Segment **seg2 = (Segment **)ptr2; #if 0 return( (*seg1)->center - (*seg2)->center ); #else diff = (*seg1)->center - (*seg2)->center; if( diff ) return( diff ); diff = (*seg1)->start - (*seg2)->start; if( diff ) return( diff ); diff = (*seg1)->end - (*seg2)->end; if( diff ) return( diff ); fprintf( stderr, "USE STABLE SORT !!\n" ); exit( 1 ); return( 0 ); #endif } #endif static void mymergesort( int first, int last, Segment **seg ) { int middle; static TLS int i, j, k, p; static TLS int allo = 0; static TLS Segment **work = NULL; if( seg == NULL ) { if( work ) free( work ); work = NULL; allo = 0; return; } if( last > allo ) { allo = last; if( work ) free( work ); work = (Segment **)calloc( allo / 2 + 1, sizeof( Segment *) ); } if( first < last ) { middle = ( first + last ) / 2; mymergesort( first, middle, seg ); mymergesort( middle+1, last, seg ); p = 0; for( i=first; i<=middle; i++ ) work[p++] = seg[i]; i = middle + 1; j = 0; k = first; while( i <= last && j < p ) { if( work[j]->center <= seg[i]->center ) seg[k++] = work[j++]; else seg[k++] = seg[i++]; } while( j < p ) seg[k++] = work[j++]; } } double Fgetlag( double **n_dynamicmtx, char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int alloclen ) { int i, j, k, l, m; int nlen, nlen2, nlen4; static TLS int crossscoresize = 0; static TLS char **tmpseq1 = NULL; static TLS char **tmpseq2 = NULL; static TLS char **tmpptr1 = NULL; static TLS char **tmpptr2 = NULL; static TLS char **tmpres1 = NULL; static TLS char **tmpres2 = NULL; static TLS char **result1 = NULL; static TLS char **result2 = NULL; #if RND static TLS char **rndseq1 = NULL; static TLS char **rndseq2 = NULL; #endif static TLS Fukusosuu **seqVector1 = NULL; static TLS Fukusosuu **seqVector2 = NULL; static TLS Fukusosuu **naiseki = NULL; static TLS Fukusosuu *naisekiNoWa = NULL; static TLS double *soukan = NULL; static TLS double **crossscore = NULL; int nlentmp; static TLS int *kouho = NULL; static TLS Segment *segment = NULL; static TLS Segment *segment1 = NULL; static TLS Segment *segment2 = NULL; static TLS Segment **sortedseg1 = NULL; static TLS Segment **sortedseg2 = NULL; static TLS int *cut1 = NULL; static TLS int *cut2 = NULL; static TLS int localalloclen = 0; int lag; int tmpint; int count, count0; int len1, len2; int totallen; double dumdb = 0.0; int headgp, tailgp; len1 = strlen( seq1[0] ); len2 = strlen( seq2[0] ); nlentmp = MAX( len1, len2 ); nlen = 1; while( nlentmp >= nlen ) nlen <<= 1; #if 0 fprintf( stderr, "### nlen = %d\n", nlen ); #endif nlen2 = nlen/2; nlen4 = nlen2 / 2; #if DEBUG fprintf( stderr, "len1 = %d, len2 = %d\n", len1, len2 ); fprintf( stderr, "nlentmp = %d, nlen = %d\n", nlentmp, nlen ); #endif if( !localalloclen ) { kouho = AllocateIntVec( NKOUHO ); cut1 = AllocateIntVec( MAXSEG ); cut2 = AllocateIntVec( MAXSEG ); tmpptr1 = AllocateCharMtx( njob, 0 ); tmpptr2 = AllocateCharMtx( njob, 0 ); result1 = AllocateCharMtx( njob, alloclen ); result2 = AllocateCharMtx( njob, alloclen ); tmpres1 = AllocateCharMtx( njob, alloclen ); tmpres2 = AllocateCharMtx( njob, alloclen ); // crossscore = AllocateDoubleMtx( MAXSEG, MAXSEG ); segment = (Segment *)calloc( MAXSEG, sizeof( Segment ) ); segment1 = (Segment *)calloc( MAXSEG, sizeof( Segment ) ); segment2 = (Segment *)calloc( MAXSEG, sizeof( Segment ) ); sortedseg1 = (Segment **)calloc( MAXSEG, sizeof( Segment * ) ); sortedseg2 = (Segment **)calloc( MAXSEG, sizeof( Segment * ) ); if( !( segment && segment1 && segment2 && sortedseg1 && sortedseg2 ) ) ErrorExit( "Allocation error\n" ); if ( scoremtx == -1 ) n20or4or2 = 4; else if( fftscore == 1 ) n20or4or2 = 2; else n20or4or2 = 20; } if( localalloclen < nlen ) { if( localalloclen ) { #if 1 FreeFukusosuuMtx ( seqVector1 ); FreeFukusosuuMtx ( seqVector2 ); FreeFukusosuuVec( naisekiNoWa ); FreeFukusosuuMtx( naiseki ); FreeDoubleVec( soukan ); FreeCharMtx( tmpseq1 ); FreeCharMtx( tmpseq2 ); #endif #if RND FreeCharMtx( rndseq1 ); FreeCharMtx( rndseq2 ); #endif } tmpseq1 = AllocateCharMtx( njob, nlen ); tmpseq2 = AllocateCharMtx( njob, nlen ); naisekiNoWa = AllocateFukusosuuVec( nlen ); naiseki = AllocateFukusosuuMtx( n20or4or2, nlen ); seqVector1 = AllocateFukusosuuMtx( n20or4or2+1, nlen+1 ); seqVector2 = AllocateFukusosuuMtx( n20or4or2+1, nlen+1 ); soukan = AllocateDoubleVec( nlen+1 ); #if RND rndseq1 = AllocateCharMtx( njob, nlen ); rndseq2 = AllocateCharMtx( njob, nlen ); for( i=0; i /dev/tty" ); #endif if( fftkeika ) fprintf( stderr, " FFT ... " ); for( j=0; j /dev/tty" ); #endif for( j=0; j /dev/tty" ); #endif for( j=0; j /dev/tty" ); #endif for( k=0; k /dev/tty " ); #endif fft( -nlen, naisekiNoWa, 0 ); for( m=0; m<=nlen2; m++ ) soukan[m] = naisekiNoWa[nlen2-m].R; for( m=nlen2+1; m /dev/tty" ); #if 0 fftfp = fopen( "list.plot", "w" ); fprintf( fftfp, "plot 'frt'\n pause +1" ); fclose( fftfp ); system( "/usr/bin/gnuplot list.plot" ); #endif #endif getKouho( kouho, NKOUHO, soukan, nlen ); #if 0 for( i=0; iCandidate No.%d lag = %d\n", k+1, lag ); fprintf( fftfp, "%s\n", tmpptr1[0] ); fprintf( fftfp, ">Candidate No.%d lag = %d\n", k+1, lag ); fprintf( fftfp, "%s\n", tmpptr2[0] ); fprintf( fftfp, ">\n", k+1, lag ); fclose( fftfp ); #endif tmpint = alignableReagion( clus1, clus2, tmpptr1, tmpptr2, eff1, eff2, segment+count ); if( count+tmpint > MAXSEG -3 ) ErrorExit( "TOO MANY SEGMENTS.\n" ); if( tmpint == 0 ) break; // 060430 iinoka ? while( tmpint-- > 0 ) { if( lag > 0 ) { segment1[count].start = segment[count].start ; segment1[count].end = segment[count].end ; segment1[count].center = segment[count].center; segment1[count].score = segment[count].score; segment2[count].start = segment[count].start + lag; segment2[count].end = segment[count].end + lag; segment2[count].center = segment[count].center + lag; segment2[count].score = segment[count].score ; } else { segment1[count].start = segment[count].start - lag; segment1[count].end = segment[count].end - lag; segment1[count].center = segment[count].center - lag; segment1[count].score = segment[count].score ; segment2[count].start = segment[count].start ; segment2[count].end = segment[count].end ; segment2[count].center = segment[count].center; segment2[count].score = segment[count].score ; } #if 0 fprintf( stderr, "Goukaku=%dko\n", tmpint ); fprintf( stderr, "in 1 %d\n", segment1[count].center ); fprintf( stderr, "in 2 %d\n", segment2[count].center ); #endif segment1[count].pair = &segment2[count]; segment2[count].pair = &segment1[count]; count++; #if 0 fprintf( stderr, "count=%d\n", count ); #endif } } #if 1 fprintf( stderr, "done. (%d anchors)\r", count ); #endif if( !count && fftNoAnchStop ) ErrorExit( "Cannot detect anchor!" ); #if 0 fprintf( stdout, "RESULT before sort:\n" ); for( l=0; lnumber = i; for( i=0; inumber = i; if( crossscoresize < count+2 ) { crossscoresize = count+2; fprintf( stderr, "####################################################################################################################################allocating crossscore, size = %d\n", crossscoresize ); if( crossscore ) FreeDoubleMtx( crossscore ); crossscore = AllocateDoubleMtx( crossscoresize, crossscoresize ); } for( i=0; inumber+1] = segment1[i].score; cut1[i+1] = sortedseg1[i]->center; cut2[i+1] = sortedseg2[i]->center; } #if DEBUG fprintf( stderr, "AFTER SORT\n" ); for( i=0; i count ) { fprintf( stderr, "REPEAT!? \n" ); if( fftRepeatStop ) exit( 1 ); } #if KEIKA else fprintf( stderr, "done\n" ); fprintf( stderr, "done. (%d anchors)\n", count ); #endif } #if 0 fftfp = fopen( "fft", "a" ); fprintf( fftfp, "RESULT after sort:\n" ); for( l=0; l alloclen ) ErrorExit( "LENGTH OVER in Falign\n " ); for( j=0; j= nlen ) nlen <<= 1; #if 0 fprintf( stderr, "### nlen = %d\n", nlen ); #endif nlen2 = nlen/2; nlen4 = nlen2 / 2; #if DEBUG fprintf( stderr, "len1 = %d, len2 = %d\n", len1, len2 ); fprintf( stderr, "nlentmp = %d, nlen = %d\n", nlentmp, nlen ); #endif if( prevalloclen != alloclen ) // Falign_noudp mo kaeru { if( prevalloclen ) { FreeCharMtx( result1 ); FreeCharMtx( result2 ); FreeCharMtx( tmpres1 ); FreeCharMtx( tmpres2 ); } // fprintf( stderr, "\n\n\nreallocating ...\n" ); result1 = AllocateCharMtx( njob, alloclen ); result2 = AllocateCharMtx( njob, alloclen ); tmpres1 = AllocateCharMtx( njob, alloclen ); tmpres2 = AllocateCharMtx( njob, alloclen ); prevalloclen = alloclen; } if( !localalloclen ) { sgap1 = AllocateCharVec( njob ); egap1 = AllocateCharVec( njob ); sgap2 = AllocateCharVec( njob ); egap2 = AllocateCharVec( njob ); kouho = AllocateIntVec( NKOUHO ); cut1 = AllocateIntVec( MAXSEG ); cut2 = AllocateIntVec( MAXSEG ); tmpptr1 = AllocateCharMtx( njob, 0 ); tmpptr2 = AllocateCharMtx( njob, 0 ); // crossscore = AllocateDoubleMtx( MAXSEG, MAXSEG ); segment = (Segment *)calloc( MAXSEG, sizeof( Segment ) ); segment1 = (Segment *)calloc( MAXSEG, sizeof( Segment ) ); segment2 = (Segment *)calloc( MAXSEG, sizeof( Segment ) ); sortedseg1 = (Segment **)calloc( MAXSEG, sizeof( Segment * ) ); sortedseg2 = (Segment **)calloc( MAXSEG, sizeof( Segment * ) ); if( !( segment && segment1 && segment2 && sortedseg1 && sortedseg2 ) ) ErrorExit( "Allocation error\n" ); if ( scoremtx == -1 ) n20or4or2 = 1; else if( fftscore ) n20or4or2 = 1; else n20or4or2 = 20; } if( localalloclen < nlen ) { if( localalloclen ) { #if 1 if( !kobetsubunkatsu ) { FreeFukusosuuMtx ( seqVector1 ); FreeFukusosuuMtx ( seqVector2 ); FreeFukusosuuVec( naisekiNoWa ); FreeFukusosuuMtx( naiseki ); FreeDoubleVec( soukan ); } FreeCharMtx( tmpseq1 ); FreeCharMtx( tmpseq2 ); #endif #if RND FreeCharMtx( rndseq1 ); FreeCharMtx( rndseq2 ); #endif } tmpseq1 = AllocateCharMtx( njob, nlen ); tmpseq2 = AllocateCharMtx( njob, nlen ); if( !kobetsubunkatsu ) { naisekiNoWa = AllocateFukusosuuVec( nlen ); naiseki = AllocateFukusosuuMtx( n20or4or2, nlen ); seqVector1 = AllocateFukusosuuMtx( n20or4or2+1, nlen+1 ); seqVector2 = AllocateFukusosuuMtx( n20or4or2+1, nlen+1 ); soukan = AllocateDoubleVec( nlen+1 ); } #if RND rndseq1 = AllocateCharMtx( njob, nlen ); rndseq2 = AllocateCharMtx( njob, nlen ); for( i=0; i /dev/tty" ); #endif if( !kobetsubunkatsu ) { if( fftkeika ) fprintf( stderr, " FFT ... " ); for( j=0; j /dev/tty" ); #endif for( j=0; j /dev/tty" ); #endif for( j=0; j /dev/tty" ); #endif for( k=0; k /dev/tty " ); #endif fft( -nlen, naisekiNoWa, 0 ); for( m=0; m<=nlen2; m++ ) soukan[m] = naisekiNoWa[nlen2-m].R; for( m=nlen2+1; mCandidate No.%d lag = %d\n", k+1, lag ); fprintf( fftfp, "%s\n", tmpptr1[0] ); fprintf( fftfp, ">Candidate No.%d lag = %d\n", k+1, lag ); fprintf( fftfp, "%s\n", tmpptr2[0] ); fprintf( fftfp, ">\n", k+1, lag ); fclose( fftfp ); #endif // fprintf( stderr, "lag = %d\n", lag ); tmpint = alignableReagion( clus1, clus2, tmpptr1, tmpptr2, eff1, eff2, segment+count ); // if( lag == -50 ) exit( 1 ); if( count+tmpint > MAXSEG -3 ) ErrorExit( "TOO MANY SEGMENTS.\n" ); if( tmpint == 0 ) break; // 060430 iinoka ? while( tmpint-- > 0 ) { #if 0 if( segment[count].end - segment[count].start < fftWinSize ) { count++; continue; } #endif if( lag > 0 ) { segment1[count].start = segment[count].start ; segment1[count].end = segment[count].end ; segment1[count].center = segment[count].center; segment1[count].score = segment[count].score; segment2[count].start = segment[count].start + lag; segment2[count].end = segment[count].end + lag; segment2[count].center = segment[count].center + lag; segment2[count].score = segment[count].score ; } else { segment1[count].start = segment[count].start - lag; segment1[count].end = segment[count].end - lag; segment1[count].center = segment[count].center - lag; segment1[count].score = segment[count].score ; segment2[count].start = segment[count].start ; segment2[count].end = segment[count].end ; segment2[count].center = segment[count].center; segment2[count].score = segment[count].score ; } #if 0 fprintf( stderr, "in 1 %d\n", segment1[count].center ); fprintf( stderr, "in 2 %d\n", segment2[count].center ); #endif segment1[count].pair = &segment2[count]; segment2[count].pair = &segment1[count]; count++; } } #if 0 if( !kobetsubunkatsu && fftkeika ) fprintf( stderr, "%d anchors found\r", count ); #endif if( !count && fftNoAnchStop ) ErrorExit( "Cannot detect anchor!" ); #if 0 fprintf( stderr, "RESULT before sort:\n" ); for( l=0; lnumber = i; for( i=0; inumber = i; if( kobetsubunkatsu ) { for( i=0; icenter; cut2[i+1] = sortedseg2[i]->center; } cut1[0] = 0; cut2[0] = 0; cut1[count+1] = len1; cut2[count+1] = len2; count += 2; } else { if( crossscoresize < count+2 ) { crossscoresize = count+2; #if 1 if( fftkeika ) fprintf( stderr, "######allocating crossscore, size = %d\n", crossscoresize ); #endif if( crossscore ) FreeDoubleMtx( crossscore ); crossscore = AllocateDoubleMtx( crossscoresize, crossscoresize ); } for( i=0; inumber+1] = segment1[i].score; cut1[i+1] = sortedseg1[i]->center; cut2[i+1] = sortedseg2[i]->center; } #if 0 fprintf( stderr, "AFTER SORT\n" ); for( i=0; i count ) { #if 0 fprintf( stderr, "\7 REPEAT!? \n" ); #else fprintf( stderr, "REPEAT!? \n" ); #endif if( fftRepeatStop ) exit( 1 ); } #if KEIKA else fprintf( stderr, "done\n" ); #endif } } #if 0 fftfp = fopen( "fft", "a" ); fprintf( fftfp, "RESULT after sort:\n" ); for( l=0; l%d of GROUP1\n", j ); fprintf( stdout, "%s\n", tmpres1[j] ); } for( j=0; j%d of GROUP2\n", j ); fprintf( stdout, "%s\n", tmpres2[j] ); } fflush( stdout ); #endif switch( alg ) { case( 'a' ): totalscore += Aalign( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen ); break; case( 'M' ): if( scoringmatrices ) // called by tditeration.c totalscore += MSalignmm_variousdist( NULL, scoringmatrices, NULL, tmpres1, tmpres2, eff1, eff2, eff1s, eff2s, clus1, clus2, alloclen, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres, headgp, tailgp ); else totalscore += MSalignmm( n_dynamicmtx, tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres, headgp, tailgp ); // totalscore += MSalignmm( n_dis_consweight_multi, tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres, headgp, tailgp ); break; case( 'd' ): if( clus1 == 1 && clus2 == 1 ) { totalscore += G__align11( n_dynamicmtx, tmpres1, tmpres2, alloclen, headgp, tailgp ); } else { if( scoringmatrices ) // called by tditeration.c { totalscore += D__align_variousdist( whichmtx, scoringmatrices, NULL, tmpres1, tmpres2, eff1, eff2, eff1s, eff2s, clus1, clus2, alloclen, NULL, &dumdb, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres, headgp, tailgp ); } else totalscore += D__align( n_dynamicmtx, tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, &dumdb, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres, headgp, tailgp ); } break; case( 'A' ): if( clus1 == 1 && clus2 == 1 ) { totalscore += G__align11( n_dynamicmtx, tmpres1, tmpres2, alloclen, headgp, tailgp ); } else { if( scoringmatrices ) // called by tditeration.c { totalscore += A__align_variousdist( whichmtx, scoringmatrices, NULL, tmpres1, tmpres2, eff1, eff2, eff1s, eff2s, clus1, clus2, alloclen, NULL, &dumdb, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres, headgp, tailgp ); } else totalscore += A__align( n_dynamicmtx, tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, &dumdb, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres, headgp, tailgp ); } break; default: fprintf( stderr, "alg = %c\n", alg ); ErrorExit( "ERROR IN SOURCE FILE Falign.c" ); break; } #ifdef enablemultithread if( chudanres && *chudanres ) { // fprintf( stderr, "\n\n## CHUUDAN!!! at Falign_localhom\n" ); return( -1.0 ); } #endif nlen = strlen( tmpres1[0] ); if( totallen + nlen > alloclen ) { fprintf( stderr, "totallen=%d + nlen=%d > alloclen = %d\n", totallen, nlen, alloclen ); ErrorExit( "LENGTH OVER in Falign\n " ); } for( j=0; j= nlen ) nlen <<= 1; #if 0 fprintf( stderr, "### nlen = %d\n", nlen ); #endif nlen2 = nlen/2; nlen4 = nlen2 / 2; #if 0 fprintf( stderr, "len1 = %d, len2 = %d\n", len1, len2 ); fprintf( stderr, "nlentmp = %d, nlen = %d\n", nlentmp, nlen ); #endif if( prevalloclen != alloclen ) // Falign_noudp mo kaeru { if( prevalloclen ) { FreeCharMtx( result1 ); FreeCharMtx( result2 ); FreeCharMtx( tmpres1 ); FreeCharMtx( tmpres2 ); } // fprintf( stderr, "\n\n\nreallocating ...\n" ); result1 = AllocateCharMtx( njob, alloclen ); result2 = AllocateCharMtx( njob, alloclen ); tmpres1 = AllocateCharMtx( njob, alloclen ); tmpres2 = AllocateCharMtx( njob, alloclen ); prevalloclen = alloclen; } if( !localalloclen ) { sgap1 = AllocateCharVec( njob ); egap1 = AllocateCharVec( njob ); sgap2 = AllocateCharVec( njob ); egap2 = AllocateCharVec( njob ); kouho = AllocateIntVec( NKOUHO_LONG ); cut1 = AllocateIntVec( MAXSEG ); cut2 = AllocateIntVec( MAXSEG ); tmpptr1 = AllocateCharMtx( njob, 0 ); tmpptr2 = AllocateCharMtx( njob, 0 ); segment = (Segment *)calloc( MAXSEG, sizeof( Segment ) ); segment1 = (Segment *)calloc( MAXSEG, sizeof( Segment ) ); segment2 = (Segment *)calloc( MAXSEG, sizeof( Segment ) ); sortedseg1 = (Segment **)calloc( MAXSEG, sizeof( Segment * ) ); sortedseg2 = (Segment **)calloc( MAXSEG, sizeof( Segment * ) ); if( !( segment && segment1 && segment2 && sortedseg1 && sortedseg2 ) ) ErrorExit( "Allocation error\n" ); if ( scoremtx == -1 ) n20or4or2 = 1; else if( fftscore ) n20or4or2 = 1; else n20or4or2 = 20; } if( localalloclen < nlen ) { if( localalloclen ) { #if 1 if( !kobetsubunkatsu ) { FreeFukusosuuMtx ( seqVector1 ); FreeFukusosuuMtx ( seqVector2 ); FreeFukusosuuVec( naisekiNoWa ); FreeFukusosuuMtx( naiseki ); FreeDoubleVec( soukan ); } FreeCharMtx( tmpseq1 ); FreeCharMtx( tmpseq2 ); #endif #if RND FreeCharMtx( rndseq1 ); FreeCharMtx( rndseq2 ); #endif } tmpseq1 = AllocateCharMtx( njob, nlen ); tmpseq2 = AllocateCharMtx( njob, nlen ); if( !kobetsubunkatsu ) { naisekiNoWa = AllocateFukusosuuVec( nlen ); naiseki = AllocateFukusosuuMtx( n20or4or2, nlen ); seqVector1 = AllocateFukusosuuMtx( n20or4or2, nlen+1 ); seqVector2 = AllocateFukusosuuMtx( n20or4or2, nlen+1 ); soukan = AllocateDoubleVec( nlen+1 ); } #if RND rndseq1 = AllocateCharMtx( njob, nlen ); rndseq2 = AllocateCharMtx( njob, nlen ); for( i=0; i /dev/tty" ); #endif if( !kobetsubunkatsu ) { fprintf( stderr, " FFT ... " ); for( j=0; j /dev/tty" ); #endif for( j=0; j /dev/tty" ); #endif for( j=0; j /dev/tty" ); #endif for( k=0; k /dev/tty " ); #endif fft( -nlen, naisekiNoWa, 0 ); for( m=0; m<=nlen2; m++ ) soukan[m] = naisekiNoWa[nlen2-m].R; for( m=nlen2+1; mCandidate No.%d lag = %d\n", k+1, lag ); fprintf( fftfp, "%s\n", tmpptr1[0] ); fprintf( fftfp, ">Candidate No.%d lag = %d\n", k+1, lag ); fprintf( fftfp, "%s\n", tmpptr2[0] ); fprintf( fftfp, ">\n", k+1, lag ); fclose( fftfp ); #endif // fprintf( stderr, "lag = %d\n", lag ); tmpint = alignableReagion( clus1, clus2, tmpptr1, tmpptr2, eff1, eff2, segment+count ); // fprintf( stderr, "lag = %d, %d found\n", lag, tmpint ); // if( lag == -50 ) exit( 1 ); if( count+tmpint > MAXSEG -3 ) ErrorExit( "TOO MANY SEGMENTS.\n" ); // fprintf( stderr, "##### k=%d / %d\n", k, maxk ); // if( tmpint == 0 ) break; // 060430 iinoka ? // 090530 yameta while( tmpint-- > 0 ) { #if 0 if( segment[count].end - segment[count].start < fftWinSize ) { count++; continue; } #endif if( lag > 0 ) { segment1[count].start = segment[count].start ; segment1[count].end = segment[count].end ; segment1[count].center = segment[count].center; segment1[count].score = segment[count].score; segment2[count].start = segment[count].start + lag; segment2[count].end = segment[count].end + lag; segment2[count].center = segment[count].center + lag; segment2[count].score = segment[count].score ; } else { segment1[count].start = segment[count].start - lag; segment1[count].end = segment[count].end - lag; segment1[count].center = segment[count].center - lag; segment1[count].score = segment[count].score ; segment2[count].start = segment[count].start ; segment2[count].end = segment[count].end ; segment2[count].center = segment[count].center; segment2[count].score = segment[count].score ; } #if 0 fprintf( stderr, "##### k=%d / %d\n", k, maxk ); fprintf( stderr, "anchor %d, score = %f\n", count, segment1[count].score ); fprintf( stderr, "in 1 %d\n", segment1[count].center ); fprintf( stderr, "in 2 %d\n", segment2[count].center ); #endif segment1[count].pair = &segment2[count]; segment2[count].pair = &segment1[count]; count++; #if 0 fprintf( stderr, "count=%d\n", count ); #endif } } #if 1 if( !kobetsubunkatsu ) fprintf( stderr, "done. (%d anchors) ", count ); #endif if( !count && fftNoAnchStop ) ErrorExit( "Cannot detect anchor!" ); #if 0 fprintf( stderr, "RESULT before sort:\n" ); for( l=0; lnumber = i; for( i=0; inumber = i; if( kobetsubunkatsu ) { for( i=0; icenter; cut2[i+1] = sortedseg2[i]->center; } cut1[0] = 0; cut2[0] = 0; cut1[count+1] = len1; cut2[count+1] = len2; count += 2; } else { if( count < 5000 ) { if( crossscoresize < count+2 ) { crossscoresize = count+2; #if 1 if( fftkeika ) fprintf( stderr, "######allocating crossscore, size = %d\n", crossscoresize ); #endif if( crossscore ) FreeDoubleMtx( crossscore ); crossscore = AllocateDoubleMtx( crossscoresize, crossscoresize ); } for( i=0; inumber+1] = segment1[i].score; cut1[i+1] = sortedseg1[i]->center; cut2[i+1] = sortedseg2[i]->center; } #if 0 fprintf( stderr, "AFTER SORT\n" ); for( i=0; i count ) { #if 0 fprintf( stderr, "\7 REPEAT!? \n" ); #else fprintf( stderr, "REPEAT!? \n" ); #endif if( fftRepeatStop ) exit( 1 ); } #if KEIKA else fprintf( stderr, "done\n" ); #endif } } else { fprintf( stderr, "\nMany anchors were found. The upper-level DP is skipped.\n\n" ); cut1[0] = 0; cut2[0] = 0; count0 = 0; for( i=0; icenter, sortedseg1[i]->pair->center ); if( sortedseg1[i]->center > cut1[count0] && sortedseg1[i]->pair->center > cut2[count0] ) { count0++; cut1[count0] = sortedseg1[i]->center; cut2[count0] = sortedseg1[i]->pair->center; } else { if( i && sortedseg1[i]->score > sortedseg1[i-1]->score ) { if( sortedseg1[i]->center > cut1[count0-1] && sortedseg1[i]->pair->center > cut2[count0-1] ) { cut1[count0] = sortedseg1[i]->center; cut2[count0] = sortedseg1[i]->pair->center; } else { // count0--; } } } } // if( count-count0 ) // fprintf( stderr, "%d anchors unused\n", count-count0 ); cut1[count0+1] = len1; cut2[count0+1] = len2; count = count0 + 2; count0 = count; } } // exit( 0 ); #if 0 fftfp = fopen( "fft", "a" ); fprintf( fftfp, "RESULT after sort:\n" ); for( l=0; l%d of GROUP1\n", j ); fprintf( stdout, "%s\n", tmpres1[j] ); } for( j=0; j%d of GROUP2\n", j ); fprintf( stdout, "%s\n", tmpres2[j] ); } fflush( stdout ); #endif switch( alg ) { case( 'M' ): if( scoringmatrices ) // called by tditeration.c totalscore += MSalignmm_variousdist( NULL, scoringmatrices, NULL, tmpres1, tmpres2, eff1, eff2, eff1s, eff2s, clus1, clus2, alloclen, sgap1, sgap2, egap1, egap2, NULL, 0, NULL, headgp, tailgp ); else totalscore += MSalignmm( n_dynamicmtx, tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, sgap1, sgap2, egap1, egap2, NULL, 0, NULL, headgp, tailgp ); break; default: fprintf( stderr, "alg = %c\n", alg ); ErrorExit( "ERROR IN SOURCE FILE Falign.c" ); break; } nlen = strlen( tmpres1[0] ); if( totallen + nlen > alloclen ) { fprintf( stderr, "totallen=%d + nlen=%d > alloclen = %d\n", totallen, nlen, alloclen ); ErrorExit( "LENGTH OVER in Falign\n " ); } for( j=0; j