int main() { int i, j; char **seq; static char name[M][B]; static int nlen[M]; double **mtx; FILE *fp; int res; scoremtx = NOTSPECIFIED; #if 0 PreRead( stdin, &njob, &nlenmax ); #else getnumlen( stdin ); #endif rewind( stdin ); seq = AllocateCharMtx( njob, nlenmax+1 ); mtx = AllocateDoubleMtx( njob, njob ); #if 0 FRead( stdin, name, nlen, seq ); #else readData( stdin, name, nlen, seq ); #endif for( i=0; i<njob-1; i++ ) { fprintf( stderr, "%4d/%4d\r", i+1, njob ); for( j=i+1; j<njob; j++ ) mtx[i][j] = (double)substitution_score( seq[i], seq[j] ); } #if TEST for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ ) fprintf( stdout, "i=%d, j=%d, mtx[][] = %f\n", i, j, mtx[i][j] ); #endif fp = fopen( "hat2", "w" ); WriteHat2( fp, njob, name, mtx ); fclose( fp ); exit( 0 ); /* res = system( ALNDIR "/spgsdl < hat2" ); if( res ) exit( 1 ); else exit( 0 ); */ }
int main( int argc, char *argv[] ) { static int nlen[M]; static char **name, **seq; int i, j, alloclen, c; double **mtx; double *self; double tmpdouble; FILE *fp; arguments( argc, argv ); getnumlen( stdin ); rewind( stdin ); if( njob < 2 ) { fprintf( stderr, "At least 2 sequences should be input!\n" "Only %d sequence found.\n", njob ); exit( 1 ); } name = AllocateCharMtx( njob, B+1 ); seq = AllocateCharMtx( njob, nlenmax*9+1 ); mtx = AllocateDoubleMtx( njob, njob ); self = AllocateDoubleVec( njob ); alloclen = nlenmax*9; readData_pointer( stdin, name, nlen, seq ); constants( njob, seq ); c = seqcheck( seq ); if( c ) { fprintf( stderr, "Illeagal character %c\n", c ); exit( 1 ); } for( i=0; i<njob; i++ ) { self[i] = (double)substitution_nid( seq[i], seq[i] ); // fprintf( stdout, "self[%d] = %f\n", i, self[i] ); } for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ ) { tmpdouble = (double)substitution_score( seq[i], seq[j] ); // fprintf( stdout, "tmpdouble = %f\n", tmpdouble ); mtx[i][j] = ( 1.0 - tmpdouble / MIN( self[i], self[j] ) ); if( mtx[i][j] < 0.95 ) mtx[i][j] = - log( 1.0 - mtx[i][j] ); else mtx[i][j] = 3.0; } #if TEST for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ ) fprintf( stdout, "i=%d, j=%d, mtx[][] = %f\n", i, j, mtx[i][j] ); #endif fp = fopen( "hat2", "w" ); WriteHat2_pointer( fp, njob, name, mtx ); fclose( fp ); exit( 0 ); return( 0 ); }
int main( int argc, char **argv ) { int i, j; FILE *fp, *infp; char **seq; int *grpseq; char *tmpseq; int **pointt; static char name[M][B]; static int nlen[M]; double **mtx; double **mtx2; double score, score0; static short *table1; char b[B]; arguments( argc, argv ); if( inputfile ) { infp = fopen( inputfile, "r" ); if( !infp ) { fprintf( stderr, "Cannot open %s\n", inputfile ); exit( 1 ); } } else infp = stdin; #if 0 PreRead( stdin, &njob, &nlenmax ); #else getnumlen( infp ); #endif rewind( infp ); if( njob < 2 ) { fprintf( stderr, "At least 2 sequences should be input!\n" "Only %d sequence found.\n", njob ); exit( 1 ); } tmpseq = AllocateCharVec( nlenmax+1 ); seq = AllocateCharMtx( njob, nlenmax+1 ); grpseq = AllocateIntVec( nlenmax+1 ); pointt = AllocateIntMtx( njob, nlenmax+1 ); mtx = AllocateDoubleMtx( njob, njob ); mtx2 = AllocateDoubleMtx( njob, njob ); pamN = NOTSPECIFIED; #if 0 FRead( infp, name, nlen, seq ); #else readData( infp, name, nlen, seq ); #endif fclose( infp ); constants( njob, seq ); if( dorp == 'd' ) tsize = (int)pow( 4, 6 ); else tsize = (int)pow( 6, 6 ); maxl = 0; for( i=0; i<njob; i++ ) { gappick0( tmpseq, seq[i] ); nlen[i] = strlen( tmpseq ); if( nlen[i] < 6 ) { fprintf( stderr, "Seq %d, too short, %d characters\n", i+1, nlen[i] ); exit( 1 ); } if( nlen[i] > maxl ) maxl = nlen[i]; if( dorp == 'd' ) /* nuc */ { seq_grp_nuc( grpseq, tmpseq ); makepointtable_nuc( pointt[i], grpseq ); } else /* amino */ { seq_grp( grpseq, tmpseq ); makepointtable( pointt[i], grpseq ); } } for( i=0; i<njob; i++ ) { table1 = (short *)calloc( tsize, sizeof( short ) ); if( !table1 ) ErrorExit( "Cannot allocate table1\n" ); if( i % 10 == 0 ) { fprintf( stderr, "%4d / %4d\r", i+1, njob ); } makecompositiontable_p( table1, pointt[i] ); for( j=i; j<njob; j++ ) { score = (double)commonsextet_p( table1, pointt[j] ); mtx[i][j] = score; } free( table1 ); } for( i=0; i<njob; i++ ) { score0 = mtx[i][i]; for( j=0; j<njob; j++ ) mtx2[i][j] = ( score0 - mtx[MIN(i,j)][MAX(i,j)] ) / score0 * 3.0; } for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ ) { #if TEST double jscore; jscore = mtx[i][j] / ( MIN( strlen( seq[i] ), strlen( seq[j] ) ) - 2 ); fprintf( stdout, "jscore = %f\n", jscore ); fprintf( stdout, "mtx2[%d][%d] = %f, mtx2[%d][%d] = %f\n", i, j, mtx2[i][j], j, i, mtx2[j][i] ); #endif mtx2[i][j] = MIN( mtx2[i][j], mtx2[j][i] ); #if TEST fprintf( stdout, "sonokekka mtx2[%d][%d] %f\n", i, j, mtx2[i][j] ); #endif } if( disopt ) { for( i=0; i<njob; i++ ) { sprintf( b, "=lgth = %04d", nlen[i] ); strins( b, name[i] ); } } fp = fopen( "hat2", "w" ); if( !fp ) ErrorExit( "Cannot open hat2." ); WriteHat2( fp, njob, name, mtx2 ); fclose( fp ); fprintf( stderr, "\n" ); SHOWVERSION; exit( 0 ); }
void blockAlign2( int *cut1, int *cut2, Segment **seg1, Segment **seg2, double **ocrossscore, int *ncut ) { int i, j, k, shift, cur1, cur2, count, klim; static TLS int crossscoresize = 0; static TLS int *result1 = NULL; static TLS int *result2 = NULL; static TLS int *ocut1 = NULL; static TLS int *ocut2 = NULL; double maximum; static TLS double **crossscore = NULL; static TLS int **track = NULL; static TLS double maxj, maxi; static TLS int pointj, pointi; if( cut1 == NULL) { if( result1 ) { if( result1 ) free( result1 ); result1 = NULL; if( result2 ) free( result2 ); result2 = NULL; if( ocut1 ) free( ocut1 ); ocut1 = NULL; if( ocut2 ) free( ocut2 ); ocut2 = NULL; if( track ) FreeIntMtx( track ); track = NULL; if( crossscore ) FreeDoubleMtx( crossscore ); crossscore = NULL; } crossscoresize = 0; return; } if( result1 == NULL ) { result1 = AllocateIntVec( MAXSEG ); result2 = AllocateIntVec( MAXSEG ); ocut1 = AllocateIntVec( MAXSEG ); ocut2 = AllocateIntVec( MAXSEG ); } if( crossscoresize < *ncut+2 ) { crossscoresize = *ncut+2; if( fftkeika ) fprintf( stderr, "allocating crossscore and track, size = %d\n", crossscoresize ); if( track ) FreeIntMtx( track ); if( crossscore ) FreeDoubleMtx( crossscore ); track = AllocateIntMtx( crossscoresize, crossscoresize ); crossscore = AllocateDoubleMtx( crossscoresize, crossscoresize ); } #if 0 for( i=0; i<*ncut-2; i++ ) fprintf( stderr, "%d.start = %d, score = %f\n", i, seg1[i]->start, seg1[i]->score ); for( i=0; i<*ncut; i++ ) fprintf( stderr, "i=%d, cut1 = %d, cut2 = %d\n", i, cut1[i], cut2[i] ); for( i=0; i<*ncut; i++ ) { for( j=0; j<*ncut; j++ ) fprintf( stderr, "%#4.0f ", ocrossscore[i][j] ); fprintf( stderr, "\n" ); } #endif for( i=0; i<*ncut; i++ ) for( j=0; j<*ncut; j++ ) /* mudadanaa */ crossscore[i][j] = ocrossscore[i][j]; for( i=0; i<*ncut; i++ ) { ocut1[i] = cut1[i]; ocut2[i] = cut2[i]; } for( i=1; i<*ncut; i++ ) { #if 0 fprintf( stderr, "### i=%d/%d\n", i,*ncut ); #endif for( j=1; j<*ncut; j++ ) { pointi = 0; maxi = 0.0; klim = j-2; for( k=0; k<klim; k++ ) { /* fprintf( stderr, "k=%d, i=%d\n", k, i ); */ if( k && k<*ncut-1 && j<*ncut-1 && !permit( seg1[k-1], seg1[j-1] ) ) continue; if( crossscore[i-1][k] > maxj ) { pointi = k; maxi = crossscore[i-1][k]; } } pointj = 0; maxj = 0.0; klim = i-2; for( k=0; k<klim; k++ ) { if( k && k<*ncut-1 && i<*ncut-1 && !permit( seg2[k-1], seg2[i-1] ) ) continue; if( crossscore[k][j-1] > maxj ) { pointj = k; maxj = crossscore[k][j-1]; } } maxi += penalty; maxj += penalty; maximum = crossscore[i-1][j-1]; track[i][j] = 0; if( maximum < maxi ) { maximum = maxi ; track[i][j] = j - pointi; } if( maximum < maxj ) { maximum = maxj ; track[i][j] = pointj - i; } crossscore[i][j] += maximum; } } #if 0 for( i=0; i<*ncut; i++ ) { for( j=0; j<*ncut; j++ ) fprintf( stderr, "%3d ", track[i][j] ); fprintf( stderr, "\n" ); } #endif result1[MAXSEG-1] = *ncut-1; result2[MAXSEG-1] = *ncut-1; for( i=MAXSEG-1; i>=1; i-- ) { cur1 = result1[i]; cur2 = result2[i]; if( cur1 == 0 || cur2 == 0 ) break; shift = track[cur1][cur2]; if( shift == 0 ) { result1[i-1] = cur1 - 1; result2[i-1] = cur2 - 1; continue; } else if( shift > 0 ) { result1[i-1] = cur1 - 1; result2[i-1] = cur2 - shift; } else if( shift < 0 ) { result1[i-1] = cur1 + shift; result2[i-1] = cur2 - 1; } } count = 0; for( j=i; j<MAXSEG; j++ ) { if( ocrossscore[result1[j]][result2[j]] == 0.0 ) continue; if( result1[j] == result1[j-1] || result2[j] == result2[j-1] ) if( ocrossscore[result1[j]][result2[j]] > ocrossscore[result1[j-1]][result2[j-1]] ) count--; cut1[count] = ocut1[result1[j]]; cut2[count] = ocut2[result2[j]]; count++; } *ncut = count; #if 0 for( i=0; i<*ncut; i++ ) fprintf( stderr, "i=%d, cut1 = %d, cut2 = %d\n", i, cut1[i], cut2[i] ); #endif }
void blockAlign3( int *cut1, int *cut2, Segment **seg1, Segment **seg2, double **ocrossscore, int *ncut ) // memory complexity = O(n^3), time complexity = O(n^2) { int i, j, shift, cur1, cur2, count; static TLS int crossscoresize = 0; static TLS int jumpposi, *jumppos; static TLS double jumpscorei, *jumpscore; static TLS int *result1 = NULL; static TLS int *result2 = NULL; static TLS int *ocut1 = NULL; static TLS int *ocut2 = NULL; double maximum; static TLS double **crossscore = NULL; static TLS int **track = NULL; if( result1 == NULL ) { result1 = AllocateIntVec( MAXSEG ); result2 = AllocateIntVec( MAXSEG ); ocut1 = AllocateIntVec( MAXSEG ); ocut2 = AllocateIntVec( MAXSEG ); } if( crossscoresize < *ncut+2 ) { crossscoresize = *ncut+2; if( fftkeika ) fprintf( stderr, "allocating crossscore and track, size = %d\n", crossscoresize ); if( track ) FreeIntMtx( track ); if( crossscore ) FreeDoubleMtx( crossscore ); if( jumppos ) FreeIntVec( jumppos ); if( jumpscore ) FreeDoubleVec( jumpscore ); track = AllocateIntMtx( crossscoresize, crossscoresize ); crossscore = AllocateDoubleMtx( crossscoresize, crossscoresize ); jumppos = AllocateIntVec( crossscoresize ); jumpscore = AllocateDoubleVec( crossscoresize ); } #if 0 for( i=0; i<*ncut-2; i++ ) fprintf( stderr, "%d.start = %d, score = %f\n", i, seg1[i]->start, seg1[i]->score ); for( i=0; i<*ncut; i++ ) fprintf( stderr, "i=%d, cut1 = %d, cut2 = %d\n", i, cut1[i], cut2[i] ); for( i=0; i<*ncut; i++ ) { for( j=0; j<*ncut; j++ ) fprintf( stderr, "%#4.0f ", ocrossscore[i][j] ); fprintf( stderr, "\n" ); } #endif for( i=0; i<*ncut; i++ ) for( j=0; j<*ncut; j++ ) /* mudadanaa */ crossscore[i][j] = ocrossscore[i][j]; for( i=0; i<*ncut; i++ ) { ocut1[i] = cut1[i]; ocut2[i] = cut2[i]; } for( j=0; j<*ncut; j++ ) { jumpscore[j] = -999.999; jumppos[j] = -1; } for( i=1; i<*ncut; i++ ) { jumpscorei = -999.999; jumpposi = -1; for( j=1; j<*ncut; j++ ) { #if 1 fprintf( stderr, "in blockalign3, ### i=%d, j=%d\n", i, j ); #endif #if 0 for( k=0; k<j-2; k++ ) { /* fprintf( stderr, "k=%d, i=%d\n", k, i ); */ if( k && k<*ncut-1 && j<*ncut-1 && !permit( seg1[k-1], seg1[j-1] ) ) continue; if( crossscore[i-1][k] > maxj ) { pointi = k; maxi = crossscore[i-1][k]; } } pointj = 0; maxj = 0.0; for( k=0; k<i-2; k++ ) { if( k && k<*ncut-1 && i<*ncut-1 && !permit( seg2[k-1], seg2[i-1] ) ) continue; if( crossscore[k][j-1] > maxj ) { pointj = k; maxj = crossscore[k][j-1]; } } maxi += penalty; maxj += penalty; #endif maximum = crossscore[i-1][j-1]; track[i][j] = 0; if( maximum < jumpscorei && permit( seg1[jumpposi], seg1[i] ) ) { maximum = jumpscorei; track[i][j] = j - jumpposi; } if( maximum < jumpscore[j] && permit( seg2[jumppos[j]], seg2[j] ) ) { maximum = jumpscore[j]; track[i][j] = jumpscore[j] - i; } crossscore[i][j] += maximum; if( jumpscorei < crossscore[i-1][j] ) { jumpscorei = crossscore[i-1][j]; jumpposi = j; } if( jumpscore[j] < crossscore[i][j-1] ) { jumpscore[j] = crossscore[i][j-1]; jumppos[j] = i; } } } #if 0 for( i=0; i<*ncut; i++ ) { for( j=0; j<*ncut; j++ ) fprintf( stderr, "%3d ", track[i][j] ); fprintf( stderr, "\n" ); } #endif result1[MAXSEG-1] = *ncut-1; result2[MAXSEG-1] = *ncut-1; for( i=MAXSEG-1; i>=1; i-- ) { cur1 = result1[i]; cur2 = result2[i]; if( cur1 == 0 || cur2 == 0 ) break; shift = track[cur1][cur2]; if( shift == 0 ) { result1[i-1] = cur1 - 1; result2[i-1] = cur2 - 1; continue; } else if( shift > 0 ) { result1[i-1] = cur1 - 1; result2[i-1] = cur2 - shift; } else if( shift < 0 ) { result1[i-1] = cur1 + shift; result2[i-1] = cur2 - 1; } } count = 0; for( j=i; j<MAXSEG; j++ ) { if( ocrossscore[result1[j]][result2[j]] == 0.0 ) continue; if( result1[j] == result1[j-1] || result2[j] == result2[j-1] ) if( ocrossscore[result1[j]][result2[j]] > ocrossscore[result1[j-1]][result2[j-1]] ) count--; cut1[count] = ocut1[result1[j]]; cut2[count] = ocut2[result2[j]]; count++; } *ncut = count; #if 0 for( i=0; i<*ncut; i++ ) fprintf( stderr, "i=%d, cut1 = %d, cut2 = %d\n", i, cut1[i], cut2[i] ); #endif }
static void pairalign( char name[M][B], int nlen[M], char **seq, char **aseq, char **mseq1, char **mseq2, double *effarr, int alloclen ) { int i, j, ilim; int clus1, clus2; int off1, off2; float pscore = 0.0; // by D.Mathog static char *indication1, *indication2; FILE *hat2p, *hat3p; static double **distancemtx; static double *effarr1 = NULL; static double *effarr2 = NULL; char *pt; char *hat2file = "hat2"; LocalHom **localhomtable, *tmpptr; static char **pair; int intdum; double bunbo; localhomtable = (LocalHom **)calloc( njob, sizeof( LocalHom *) ); for( i=0; i<njob; i++) { localhomtable[i] = (LocalHom *)calloc( njob, sizeof( LocalHom ) ); for( j=0; j<njob; j++) { localhomtable[i][j].start1 = -1; localhomtable[i][j].end1 = -1; localhomtable[i][j].start2 = -1; localhomtable[i][j].end2 = -1; localhomtable[i][j].opt = -1.0; localhomtable[i][j].next = NULL; localhomtable[i][j].nokori = 0; } } if( effarr1 == NULL ) { distancemtx = AllocateDoubleMtx( njob, njob ); effarr1 = AllocateDoubleVec( njob ); effarr2 = AllocateDoubleVec( njob ); indication1 = AllocateCharVec( 150 ); indication2 = AllocateCharVec( 150 ); #if 0 #else pair = AllocateCharMtx( njob, njob ); #endif } #if 0 fprintf( stderr, "##### fftwinsize = %d, fftthreshold = %d\n", fftWinSize, fftThreshold ); #endif #if 0 for( i=0; i<njob; i++ ) fprintf( stderr, "TBFAST effarr[%d] = %f\n", i, effarr[i] ); #endif // writePre( njob, name, nlen, aseq, 0 ); for( i=0; i<njob; i++ ) for( j=0; j<njob; j++ ) pair[i][j] = 0; for( i=0; i<njob; i++ ) pair[i][i] = 1; if( alg == 'H' ) { fprintf( stderr, "Calling FOLDALIGN with option '%s'\n", foldalignopt ); callfoldalign( njob, seq ); fprintf( stderr, "done.\n" ); } if( alg == 'B' ) { fprintf( stderr, "Calling LARA\n" ); calllara( njob, seq, "" ); fprintf( stderr, "done.\n" ); } if( alg == 'T' ) { fprintf( stderr, "Calling SLARA\n" ); calllara( njob, seq, "-s" ); fprintf( stderr, "done.\n" ); } ilim = njob - 1; for( i=0; i<ilim; i++ ) { fprintf( stderr, "% 5d / %d\r", i, njob ); for( j=i+1; j<njob; j++ ) { if( strlen( seq[i] ) == 0 || strlen( seq[j] ) == 0 ) { distancemtx[i][j] = pscore; continue; } strcpy( aseq[i], seq[i] ); strcpy( aseq[j], seq[j] ); clus1 = conjuctionfortbfast( pair, i, aseq, mseq1, effarr1, effarr, indication1 ); clus2 = conjuctionfortbfast( pair, j, aseq, mseq2, effarr2, effarr, indication2 ); // fprintf( stderr, "mseq1 = %s\n", mseq1[0] ); // fprintf( stderr, "mseq2 = %s\n", mseq2[0] ); #if 0 fprintf( stderr, "group1 = %.66s", indication1 ); fprintf( stderr, "\n" ); fprintf( stderr, "group2 = %.66s", indication2 ); fprintf( stderr, "\n" ); #endif // for( l=0; l<clus1; l++ ) fprintf( stderr, "## STEP-eff for mseq1-%d %f\n", l, effarr1[l] ); #if 1 if( use_fft ) { pscore = Falign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, &intdum, NULL, 0, NULL ); off1 = off2 = 0; } else #endif { switch( alg ) { case( 'a' ): pscore = Aalign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen ); off1 = off2 = 0; break; case( 'A' ): pscore = G__align11( mseq1, mseq2, alloclen, NULL, 0, NULL ); off1 = off2 = 0; break; #if 0 case( 'V' ): pscore = VAalign11( mseq1, mseq2, alloclen, &off1, &off2, localhomtable[i]+j ); fprintf( stderr, "i,j = %d,%d, score = %f\n", i,j, pscore ); break; case( 'S' ): fprintf( stderr, "aligning %d-%d\n", i, j ); pscore = suboptalign11( mseq1, mseq2, alloclen, &off1, &off2, localhomtable[i]+j ); fprintf( stderr, "i,j = %d,%d, score = %f\n", i,j, pscore ); break; #endif case( 'N' ): pscore = genL__align11( mseq1, mseq2, alloclen, &off1, &off2 ); // fprintf( stderr, "pscore = %f\n", pscore ); break; case( 'L' ): pscore = L__align11( mseq1, mseq2, alloclen, &off1, &off2 ); // fprintf( stderr, "pscore (1) = %f\n", pscore ); // pscore = (float)naivepairscore11( *mseq1, *mseq2, penalty ); // nennnotame // fprintf( stderr, "pscore (2) = %f\n\n", pscore ); break; case( 'H' ): pscore = recallpairfoldalign( mseq1, mseq2, i, j, &off1, &off2, alloclen ); break; case( 'B' ): case( 'T' ): pscore = recalllara( mseq1, mseq2, alloclen ); off1 = off2 = 0; // fprintf( stderr, "lara, pscore = %f\n", pscore ); break; case( 's' ): pscore = callmxscarna( mseq1, mseq2, alloclen ); off1 = off2 = 0; // fprintf( stderr, "scarna, pscore = %f\n", pscore ); break; case( 'M' ): // pscore = MSalign11( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, NULL, NULL, NULL ); pscore = MSalign11( mseq1, mseq2, alloclen ); // fprintf( stderr, "pscore = %f\n", pscore ); break; ErrorExit( "ERROR IN SOURCE FILE" ); } } distancemtx[i][j] = pscore; #if SCOREOUT fprintf( stderr, "score = %10.2f (%d,%d)\n", pscore, i, j ); #endif // fprintf( stderr, "pslocal = %d\n", pslocal ); // offset = makelocal( *mseq1, *mseq2, pslocal ); #if 0 fprintf( stderr, "off1 = %d, off2 = %d\n", off1, off2 ); fprintf( stderr, ">%d\n%s\n>%d\n%s\n>\n", i, mseq1[0], j, mseq2[0] ); #endif // putlocalhom2( mseq1[0], mseq2[0], localhomtable[i]+j, countamino( *mseq1, off1 ), countamino( *mseq2, off2 ), pscore, strlen( mseq1[0] ) ); // fprintf( stderr, "pscore = %f\n", pscore ); if( alg == 'H' ) // if( alg == 'H' || alg == 's' || alg == 'B' ) // next version putlocalhom_ext( mseq1[0], mseq2[0], localhomtable[i]+j, off1, off2, (int)pscore, strlen( mseq1[0] ) ); else if( alg != 'S' && alg != 'V' ) putlocalhom2( mseq1[0], mseq2[0], localhomtable[i]+j, off1, off2, (int)pscore, strlen( mseq1[0] ) ); } } for( i=0; i<njob; i++ ) { pscore = 0.0; for( pt=seq[i]; *pt; pt++ ) pscore += amino_dis[(int)*pt][(int)*pt]; distancemtx[i][i] = pscore; } ilim = njob-1; for( i=0; i<ilim; i++ ) { for( j=i+1; j<njob; j++ ) { bunbo = MIN( distancemtx[i][i], distancemtx[j][j] ); if( bunbo == 0.0 ) distancemtx[i][j] = 2.0; else distancemtx[i][j] = ( 1.0 - distancemtx[i][j] / bunbo ) * 2.0; } } hat2p = fopen( hat2file, "w" ); if( !hat2p ) ErrorExit( "Cannot open hat2." ); WriteHat2( hat2p, njob, name, distancemtx ); fclose( hat2p ); fprintf( stderr, "##### writing hat3\n" ); hat3p = fopen( "hat3", "w" ); if( !hat3p ) ErrorExit( "Cannot open hat3." ); ilim = njob-1; for( i=0; i<ilim; i++ ) { for( j=i+1; j<njob; j++ ) { for( tmpptr=localhomtable[i]+j; tmpptr; tmpptr=tmpptr->next ) { if( tmpptr->opt == -1.0 ) continue; fprintf( hat3p, "%d %d %d %7.5f %d %d %d %d %p\n", i, j, tmpptr->overlapaa, tmpptr->opt, tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2, (void *)tmpptr->next ); } } } fclose( hat3p ); #if DEBUG fprintf( stderr, "calling FreeLocalHomTable\n" ); #endif FreeLocalHomTable( localhomtable, njob ); #if DEBUG fprintf( stderr, "done. FreeLocalHomTable\n" ); #endif }
int main( int argc, char **argv ) { int i, j; char **seq; static char **name; static int nlen[M]; float *selfscore; double **mtx; FILE *fp; FILE *infp; float ssi, ssj, bunbo; arguments( argc, argv ); #ifndef enablemultithread nthread = 0; #endif if( inputfile ) { infp = fopen( inputfile, "r" ); if( !infp ) { fprintf( stderr, "Cannot open %s\n", inputfile ); exit( 1 ); } } else infp = stdin; #if 0 PreRead( stdin, &njob, &nlenmax ); #else getnumlen( infp ); #endif rewind( infp ); seq = AllocateCharMtx( njob, nlenmax+1 ); name = AllocateCharMtx( njob, B+1 ); mtx = AllocateDoubleMtx( njob, njob ); selfscore = AllocateFloatVec( njob ); #if 0 FRead( stdin, name, nlen, seq ); #else readData_pointer( infp, name, nlen, seq ); #endif fclose( infp ); constants( njob, seq ); #if 0 for( i=0; i<njob-1; i++ ) { fprintf( stderr, "%4d/%4d\r", i+1, njob ); for( j=i+1; j<njob; j++ ) mtx[i][j] = (double)substitution_hosei( seq[i], seq[j] ); // fprintf( stderr, "i=%d,j=%d, l=%d &&& %f\n", i, j, nlen[0], mtx[i][j] ); } #else // 061003 for( i=0; i<njob; i++ ) { selfscore[i] = (float)naivepairscore11( seq[i], seq[i], penalty ); } #ifdef enablemultithread if( nthread > 0 ) { thread_arg_t *targ; Jobtable jobpos; pthread_t *handle; pthread_mutex_t mutex; jobpos.i = 0; jobpos.j = 0; targ = calloc( nthread, sizeof( thread_arg_t ) ); handle = calloc( nthread, sizeof( pthread_t ) ); pthread_mutex_init( &mutex, NULL ); for( i=0; i<nthread; i++ ) { targ[i].thread_no = i; targ[i].njob = njob; targ[i].selfscore = selfscore; targ[i].mtx = mtx; targ[i].seq = seq; targ[i].jobpospt = &jobpos; targ[i].mutex = &mutex; pthread_create( handle+i, NULL, athread, (void *)(targ+i) ); } for( i=0; i<nthread; i++ ) { pthread_join( handle[i], NULL ); } pthread_mutex_destroy( &mutex ); } else #endif { for( i=0; i<njob-1; i++ ) { ssi = selfscore[i]; fprintf( stderr, "%4d/%4d\r", i+1, njob ); for( j=i+1; j<njob; j++ ) { ssj = selfscore[j]; bunbo = MIN( ssi, ssj ); if( bunbo == 0.0 ) mtx[i][j] = 1.0; else mtx[i][j] = 1.0 - (double)naivepairscore11( seq[i], seq[j], penalty ) / bunbo; // mtx[i][j] = 1.0 - (double)naivepairscore11( seq[i], seq[j], penalty ) / MIN( selfscore[i], selfscore[j] ); // fprintf( stderr, "i=%d,j=%d, l=%d### %f, score = %d\n", i, j, nlen[0], mtx[i][j], naivepairscore11( seq[i], seq[j], penalty ) ); } } } #endif #if TEST for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ ) fprintf( stdout, "i=%d, j=%d, mtx[][] = %f\n", i, j, mtx[i][j] ); #endif fp = fopen( "hat2", "w" ); WriteHat2_pointer( fp, njob, name, mtx ); fclose( fp ); #if 0 if( treeout ) { int ***topol; double **len; topol = AllocateIntCub( njob, 2, njob ); len = AllocateDoubleMtx( njob, njob ); veryfastsupg_double_outtree( njob, mtx, topol, len ); } #endif SHOWVERSION; exit( 0 ); /* res = system( ALNDIR "/spgsdl < hat2" ); if( res ) exit( 1 ); else exit( 0 ); */ }
int main( int argc, char *argv[] ) { char **argv2; static int *nlen; static char **name, **seq; static char **seq1, **seq2; static char **mseq1, **mseq2; static char **aseq; static char **bseq; static double **pscore; static double *eff; int i, j, len1, len2; static int ***topol; static double **len; FILE *gp1, *gp2; char c; int nlenmax1, nlenmax2, nseq1, nseq2; int alloclen; argv2 = arguments( argc, argv ); fprintf( stderr, "####### in galn\n" ); initFiles(); fprintf( stderr, "file1 = %s\n", argv2[0] ); fprintf( stderr, "file2 = %s\n", argv2[1] ); gp1 = fopen( argv2[0], "r" ); if( !gp1 ) ErrorExit( "cannot open file1" ); gp2 = fopen( argv2[1], "r" ); if( !gp2 ) ErrorExit( "cannot open file2" ); #if 0 PreRead( gp1, &nseq1, &nlenmax1 ); PreRead( gp2, &nseq2, &nlenmax2 ); #else getnumlen( gp1 ); nseq1 = njob; nlenmax1 = nlenmax; getnumlen( gp2 ); nseq2 = njob; nlenmax2 = nlenmax; #endif njob = nseq1 + nseq2; nlenmax = MAX( nlenmax1, nlenmax2 ); rewind( gp1 ); rewind( gp2 ); name = AllocateCharMtx( njob, B ); nlen = AllocateIntVec( njob ); seq1 = AllocateCharMtx( nseq1, nlenmax*3 ); seq2 = AllocateCharMtx( nseq2, nlenmax*3 ); seq = AllocateCharMtx( njob, 1 ); aseq = AllocateCharMtx( njob, nlenmax*3 ); bseq = AllocateCharMtx( njob, nlenmax*3 ); mseq1 = AllocateCharMtx( njob, 1 ); mseq2 = AllocateCharMtx( njob, 1 ); alloclen = nlenmax * 3; topol = AllocateIntCub( njob, 2, njob ); len = AllocateDoubleMtx( njob, 2 ); pscore = AllocateDoubleMtx( njob, njob ); eff = AllocateDoubleVec( njob ); #if 0 njob=nseq2; FRead( gp2, name+nseq1, nlen+nseq1, seq2 ); njob=nseq1; FRead( gp1, name, nlen, seq1 ); #else njob=nseq2; readDataforgaln( gp2, name+nseq1, nlen+nseq1, seq2 ); njob=nseq1; readDataforgaln( gp1, name, nlen, seq1 ); #endif njob = nseq1 + nseq2; #if 0 // CHUUI commongappick( nseq1, seq1 ); commongappick( nseq2, seq2 ); #endif for( i=0; i<nseq1; i++ ) seq[i] = seq1[i]; for( i=nseq1; i<njob; i++ ) seq[i] = seq2[i-nseq1]; /* Write( stdout, njob, name, nlen, seq ); */ constants( njob, seq ); WriteOptions( trap_g ); c = seqcheck( seq ); if( c ) { fprintf( stderr, "Illeagal character %c\n", c ); exit( 1 ); } for( i=1; i<nseq1; i++ ) { if( nlen[i] != nlen[0] ) ErrorExit( "group1 is not aligned." ); } for( i=nseq1+1; i<njob; i++ ) { if( nlen[i] != nlen[nseq1] ) ErrorExit( "group2 is not aligned." ); } if( tbutree == 0 ) { for( i=0; i<nseq1; i++ ) { for( j=i+1; j<nseq1; j++ ) { pscore[i][j] = (double)substitution_hosei( seq[i], seq[j] ); // fprintf( stderr, "%d-%d, %5.1f \n", i, j, pscore[i][j] ); } for( j=nseq1; j<njob; j++ ) { pscore[i][j] = 3.0; // fprintf( stderr, "%d-%d, %5.1f \n", i, j, pscore[i][j] ); } } for( i=nseq1; i<njob-1; i++ ) { for( j=i+1; j<njob; j++ ) { pscore[i][j] = (double)substitution_hosei( seq[i], seq[j] ); // fprintf( stderr, "%d-%d, %5.1f \n", i, j, pscore[i][j] ); } } // fprintf( stderr, "\n" ); } else { fprintf( stderr, "Not supported\n" ); exit( 1 ); #if 0 prep = fopen( "hat2", "r" ); if( prep == NULL ) ErrorExit( "Make hat2." ); readhat2( prep, njob, name, pscore ); fclose( prep ); #endif } fprintf( stderr, "Constructing dendrogram ... " ); if( treemethod == 'x' ) veryfastsupg( njob, pscore, topol, len ); else ErrorExit( "Incorrect tree\n" ); fprintf( stderr, "done.\n" ); if( tbrweight ) { weight = 3; counteff_simple( njob, topol, len, eff ); // for( i=0; i<njob; i++ ) fprintf( stderr, "eff[%d] = %f\n", i, eff[i] ); } else { for( i=0; i<njob; i++ ) eff[i] = 1.0; } len1 = strlen( seq[0] ); len2 = strlen( seq[nseq1] ); if( len1 > 30000 || len2 > 30000 ) { fprintf( stderr, "\nlen1=%d, len2=%d, Switching to the memsave mode.\n", len1, len2 ); alg = 'M'; } GroupAlign( nseq1, nseq2, name, nlen, seq, aseq, mseq1, mseq2, topol, len, eff, alloclen ); #if 0 writePre( njob, name, nlen, aseq, 1 ); #else writeDataforgaln( stdout, njob, name, nlen, aseq ); #endif SHOWVERSION; return( 0 ); }
void constants( int nseq, char **seq ) { int i, j, x; // double tmp; if( dorp == 'd' ) /* DNA */ { int k, m; double average; double **pamx = AllocateDoubleMtx( 11,11 ); double **pam1 = AllocateDoubleMtx( 4, 4 ); double *freq = AllocateDoubleVec( 4 ); scoremtx = -1; if( RNAppenalty == NOTSPECIFIED ) RNAppenalty = DEFAULTRNAGOP_N; if( RNAppenalty_ex == NOTSPECIFIED ) RNAppenalty_ex = DEFAULTRNAGEP_N; if( ppenalty == NOTSPECIFIED ) ppenalty = DEFAULTGOP_N; if( ppenalty_OP == NOTSPECIFIED ) ppenalty_OP = DEFAULTGOP_N; if( ppenalty_ex == NOTSPECIFIED ) ppenalty_ex = DEFAULTGEP_N; if( ppenalty_EX == NOTSPECIFIED ) ppenalty_EX = DEFAULTGEP_N; if( poffset == NOTSPECIFIED ) poffset = DEFAULTOFS_N; if( RNApthr == NOTSPECIFIED ) RNApthr = DEFAULTRNATHR_N; if( pamN == NOTSPECIFIED ) pamN = DEFAULTPAMN; if( kimuraR == NOTSPECIFIED ) kimuraR = 2; RNApenalty = (int)( 3 * 600.0 / 1000.0 * RNAppenalty + 0.5 ); RNApenalty_ex = (int)( 3 * 600.0 / 1000.0 * RNAppenalty_ex + 0.5 ); // fprintf( stderr, "DEFAULTRNAGOP_N = %d\n", DEFAULTRNAGOP_N ); // fprintf( stderr, "RNAppenalty = %d\n", RNAppenalty ); // fprintf( stderr, "RNApenalty = %d\n", RNApenalty ); RNAthr = (int)( 3 * 600.0 / 1000.0 * RNApthr + 0.5 ); penalty = (int)( 3 * 600.0 / 1000.0 * ppenalty + 0.5); penalty_OP = (int)( 3 * 600.0 / 1000.0 * ppenalty_OP + 0.5); penalty_ex = (int)( 3 * 600.0 / 1000.0 * ppenalty_ex + 0.5); penalty_EX = (int)( 3 * 600.0 / 1000.0 * ppenalty_EX + 0.5); offset = (int)( 3 * 600.0 / 1000.0 * poffset + 0.5); offsetFFT = (int)( 3 * 600.0 / 1000.0 * (-0) + 0.5); offsetLN = (int)( 3 * 600.0 / 1000.0 * 100 + 0.5); penaltyLN = (int)( 3 * 600.0 / 1000.0 * -2000 + 0.5); penalty_exLN = (int)( 3 * 600.0 / 1000.0 * -100 + 0.5); sprintf( modelname, "%s%d (%d), %6.3f (%6.3f), %6.3f (%6.3f)", rnakozo?"RNA":"DNA", pamN, kimuraR, -(double)ppenalty*0.001, -(double)ppenalty*0.003, -(double)poffset*0.001, -(double)poffset*0.003 ); if( kimuraR == 9999 ) { for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) pamx[i][j] = (double)locn_disn[i][j]; #if NORMALIZE1 average = 0.0; for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) average += pamx[i][j]; average /= 16.0; if( disp ) fprintf( stderr, "average = %f\n", average ); for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) pamx[i][j] -= average; for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) pamx[i][j] *= 600.0 / average; for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) pamx[i][j] -= offset; #endif } else { double f = 0.99; double s = (double)kimuraR / ( 2 + kimuraR ) * 0.01; double v = (double)1 / ( 2 + kimuraR ) * 0.01; pam1[0][0] = f; pam1[0][1] = s; pam1[0][2] = v; pam1[0][3] = v; pam1[1][0] = s; pam1[1][1] = f; pam1[1][2] = v; pam1[1][3] = v; pam1[2][0] = v; pam1[2][1] = v; pam1[2][2] = f; pam1[2][3] = s; pam1[3][0] = v; pam1[3][1] = v; pam1[3][2] = s; pam1[3][3] = f; fprintf( stderr, "generating %dPAM scoring matrix for nucleotides ... ", pamN ); if( disp ) { fprintf( stderr, " TPM \n" ); for( i=0; i<4; i++ ) { for( j=0; j<4; j++ ) fprintf( stderr, "%+#6.10f", pam1[i][j] ); fprintf( stderr, "\n" ); } fprintf( stderr, "\n" ); } MtxuntDouble( pamx, 4 ); for( x=0; x < pamN; x++ ) MtxmltDouble( pamx, pam1, 4 ); for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) pamx[i][j] /= 1.0 / 4.0; for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) { if( pamx[i][j] == 0.0 ) { fprintf( stderr, "WARNING: pamx[i][j] = 0.0 ?\n" ); pamx[i][j] = 0.00001; /* by J. Thompson */ } pamx[i][j] = log10( pamx[i][j] ) * 1000.0; } if( disp ) { fprintf( stderr, " after log\n" ); for( i=0; i<4; i++ ) { for( j=0; j<4; j++ ) fprintf( stderr, "%+#6.10f", pamx[i][j] ); fprintf( stderr, "\n" ); } fprintf( stderr, "\n" ); } // ????? for( i=0; i<26; i++ ) amino[i] = locaminon[i]; for( i=0; i<0x80; i++ ) amino_n[i] = -1; for( i=0; i<26; i++ ) amino_n[(int)amino[i]] = i; if( fmodel == 1 ) calcfreq_nuc( nseq, seq, freq ); else { freq[0] = 0.25; freq[1] = 0.25; freq[2] = 0.25; freq[3] = 0.25; } // fprintf( stderr, "a, freq[0] = %f\n", freq[0] ); // fprintf( stderr, "g, freq[1] = %f\n", freq[1] ); // fprintf( stderr, "c, freq[2] = %f\n", freq[2] ); // fprintf( stderr, "t, freq[3] = %f\n", freq[3] ); average = 0.0; for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) average += pamx[i][j] * freq[i] * freq[j]; for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) pamx[i][j] -= average; average = 0.0; for( i=0; i<4; i++ ) average += pamx[i][i] * 1.0 / 4.0; for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) pamx[i][j] *= 600.0 / average; for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) pamx[i][j] -= offset; /* extending gap cost */ for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) pamx[i][j] = shishagonyuu( pamx[i][j] ); if( disp ) { fprintf( stderr, " after shishagonyuu\n" ); for( i=0; i<4; i++ ) { for( j=0; j<4; j++ ) fprintf( stderr, "%+#6.10f", pamx[i][j] ); fprintf( stderr, "\n" ); } fprintf( stderr, "\n" ); } fprintf( stderr, "done\n" ); } for( i=0; i<5; i++ ) { pamx[4][i] = pamx[3][i]; pamx[i][4] = pamx[i][3]; } for( i=5; i<10; i++ ) for( j=5; j<10; j++ ) { pamx[i][j] = pamx[i-5][j-5]; } if( disp ) { fprintf( stderr, " before dis\n" ); for( i=0; i<4; i++ ) { for( j=0; j<4; j++ ) fprintf( stderr, "%+#6.10f", pamx[i][j] ); fprintf( stderr, "\n" ); } fprintf( stderr, "\n" ); } if( disp ) { fprintf( stderr, " score matrix \n" ); for( i=0; i<4; i++ ) { for( j=0; j<4; j++ ) fprintf( stderr, "%+#6.10f", pamx[i][j] ); fprintf( stderr, "\n" ); } fprintf( stderr, "\n" ); } for( i=0; i<26; i++ ) amino[i] = locaminon[i]; for( i=0; i<26; i++ ) amino_grp[(int)amino[i]] = locgrpn[i]; for( i=0; i<26; i++ ) for( j=0; j<26; j++ ) n_dis[i][j] = 0; for( i=0; i<10; i++ ) for( j=0; j<10; j++ ) n_dis[i][j] = shishagonyuu( pamx[i][j] ); if( disp ) { fprintf( stderr, " score matrix \n" ); for( i=0; i<26; i++ ) { for( j=0; j<26; j++ ) fprintf( stderr, "%+6d", n_dis[i][j] ); fprintf( stderr, "\n" ); } fprintf( stderr, "\n" ); } // RIBOSUM #if 1 average = 0.0; for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) average += ribosum4[i][j] * freq[i] * freq[j]; for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) ribosum4[i][j] -= average; average = 0.0; for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) for( k=0; k<4; k++ ) for( m=0; m<4; m++ ) { // if( i%4==0&&j%4==3 || i%4==3&&j%4==0 || i%4==1&&j%4==2 || i%4==2&&j%4==1 || i%4==1&&j%4==3 || i%4==3&&j%4==1 ) // if( k%4==0&&m%4==3 || k%4==3&&m%4==0 || k%4==1&&m%4==2 || k%4==2&&m%4==1 || k%4==1&&m%4==3 || k%4==3&&m%4==1 ) average += ribosum16[i*4+j][k*4+m] * freq[i] * freq[j] * freq[k] * freq[m]; } for( i=0; i<16; i++ ) for( j=0; j<16; j++ ) ribosum16[i][j] -= average; average = 0.0; for( i=0; i<4; i++ ) average += ribosum4[i][i] * freq[i]; for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) ribosum4[i][j] *= 600.0 / average; average = 0.0; average += ribosum16[0*4+3][0*4+3] * freq[0] * freq[3]; // AU average += ribosum16[3*4+0][3*4+0] * freq[3] * freq[0]; // UA average += ribosum16[1*4+2][1*4+2] * freq[1] * freq[2]; // CG average += ribosum16[2*4+1][2*4+1] * freq[2] * freq[1]; // GC average += ribosum16[1*4+3][1*4+3] * freq[1] * freq[3]; // GU average += ribosum16[3*4+1][3*4+1] * freq[3] * freq[1]; // UG for( i=0; i<16; i++ ) for( j=0; j<16; j++ ) ribosum16[i][j] *= 600.0 / average; #if 1 for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) ribosum4[i][j] -= offset; /* extending gap cost ?????*/ for( i=0; i<16; i++ ) for( j=0; j<16; j++ ) ribosum16[i][j] -= offset; /* extending gap cost ?????*/ #endif for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) ribosum4[i][j] = shishagonyuu( ribosum4[i][j] ); for( i=0; i<16; i++ ) for( j=0; j<16; j++ ) ribosum16[i][j] = shishagonyuu( ribosum16[i][j] ); if( disp ) { fprintf( stderr, "ribosum after shishagonyuu\n" ); for( i=0; i<4; i++ ) { for( j=0; j<4; j++ ) fprintf( stderr, "%+#6.10f", ribosum4[i][j] ); fprintf( stderr, "\n" ); } fprintf( stderr, "\n" ); fprintf( stderr, "ribosum16 after shishagonyuu\n" ); for( i=0; i<16; i++ ) { for( j=0; j<16; j++ ) fprintf( stderr, "%+#7.0f", ribosum16[i][j] ); fprintf( stderr, "\n" ); } fprintf( stderr, "\n" ); } fprintf( stderr, "done\n" ); #if 1 for( i=0; i<37; i++ ) for( j=0; j<37; j++ ) ribosumdis[i][j] = 0.0; //iru for( m=0; m<9; m++ ) for( i=0; i<4; i++ ) // loop for( k=0; k<9; k++ ) for( j=0; j<4; j++ ) ribosumdis[m*4+i][k*4+j] = ribosum4[i][j]; // loop-loop // for( k=0; k<9; k++ ) for( j=0; j<4; j++ ) ribosumdis[m*4+i][k*4+j] = n_dis[i][j]; // loop-loop for( i=0; i<16; i++ ) for( j=0; j<16; j++ ) ribosumdis[i+4][j+4] = ribosum16[i][j]; // stem5-stem5 for( i=0; i<16; i++ ) for( j=0; j<16; j++ ) ribosumdis[i+20][j+20] = ribosum16[i][j]; // stem5-stem5 #else // do not use ribosum for( i=0; i<37; i++ ) for( j=0; j<37; j++ ) ribosumdis[i][j] = 0.0; //iru for( m=0; m<9; m++ ) for( i=0; i<4; i++ ) // loop for( k=0; k<9; k++ ) for( j=0; j<4; j++ ) ribosumdis[m*4+i][k*4+j] = n_dis[i][j]; // loop-loop #endif if( disp ) { fprintf( stderr, "ribosumdis\n" ); for( i=0; i<37; i++ ) { for( j=0; j<37; j++ ) fprintf( stderr, "%+5d", ribosumdis[i][j] ); fprintf( stderr, "\n" ); } fprintf( stderr, "\n" ); } fprintf( stderr, "done\n" ); #endif FreeDoubleMtx( pam1 ); FreeDoubleMtx( pamx ); free( freq ); } else if( dorp == 'p' && scoremtx == 1 ) /* Blosum */ { double *freq; double *freq1; double *datafreq; double average; // double tmp; double **n_distmp; n_distmp = AllocateDoubleMtx( 20, 20 ); datafreq = AllocateDoubleVec( 20 ); freq = AllocateDoubleVec( 20 ); if( ppenalty == NOTSPECIFIED ) ppenalty = DEFAULTGOP_B; if( ppenalty_OP == NOTSPECIFIED ) ppenalty_OP = DEFAULTGOP_B; if( ppenalty_ex == NOTSPECIFIED ) ppenalty_ex = DEFAULTGEP_B; if( ppenalty_EX == NOTSPECIFIED ) ppenalty_EX = DEFAULTGEP_B; if( poffset == NOTSPECIFIED ) poffset = DEFAULTOFS_B; if( pamN == NOTSPECIFIED ) pamN = 0; if( kimuraR == NOTSPECIFIED ) kimuraR = 1; penalty = (int)( 600.0 / 1000.0 * ppenalty + 0.5 ); penalty_OP = (int)( 600.0 / 1000.0 * ppenalty_OP + 0.5 ); penalty_ex = (int)( 600.0 / 1000.0 * ppenalty_ex + 0.5 ); penalty_EX = (int)( 600.0 / 1000.0 * ppenalty_EX + 0.5 ); offset = (int)( 600.0 / 1000.0 * poffset + 0.5 ); offsetFFT = (int)( 600.0 / 1000.0 * (-0) + 0.5); offsetLN = (int)( 600.0 / 1000.0 * 100 + 0.5); penaltyLN = (int)( 600.0 / 1000.0 * -2000 + 0.5); penalty_exLN = (int)( 600.0 / 1000.0 * -100 + 0.5); BLOSUMmtx( nblosum, n_distmp, freq, amino, amino_grp ); if( nblosum == -1 ) sprintf( modelname, "User-defined, %6.3f, %+6.3f, %+6.3f", -(double)ppenalty/1000, -(double)poffset/1000, -(double)ppenalty_ex/1000 ); else sprintf( modelname, "BLOSUM%d, %6.3f, %+6.3f, %+6.3f", nblosum, -(double)ppenalty/1000, -(double)poffset/1000, -(double)ppenalty_ex/1000 ); #if 0 for( i=0; i<26; i++ ) amino[i] = locaminod[i]; for( i=0; i<26; i++ ) amino_grp[(int)amino[i]] = locgrpd[i]; for( i=0; i<0x80; i++ ) amino_n[i] = 0; for( i=0; i<26; i++ ) amino_n[(int)amino[i]] = i; #endif for( i=0; i<0x80; i++ )amino_n[i] = -1; for( i=0; i<26; i++) amino_n[(int)amino[i]] = i; if( fmodel == 1 ) { calcfreq( nseq, seq, datafreq ); freq1 = datafreq; } else freq1 = freq; #if TEST fprintf( stderr, "raw scoreing matrix : \n" ); for( i=0; i<20; i++ ) { for( j=0; j<20; j++ ) { fprintf( stdout, "%6.2f", n_distmp[i][j] ); } fprintf( stdout, "\n" ); } #endif if( fmodel == -1 ) average = 0.0; else { for( i=0; i<20; i++ ) #if TEST fprintf( stdout, "freq[%c] = %f, datafreq[%c] = %f, freq1[] = %f\n", amino[i], freq[i], amino[i], datafreq[i], freq1[i] ); #endif average = 0.0; for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) average += n_distmp[i][j] * freq1[i] * freq1[j]; } #if TEST fprintf( stdout, "####### average2 = %f\n", average ); #endif for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) n_distmp[i][j] -= average; #if TEST fprintf( stdout, "average2 = %f\n", average ); fprintf( stdout, "after average substruction : \n" ); for( i=0; i<20; i++ ) { for( j=0; j<20; j++ ) { fprintf( stdout, "%6.2f", n_distmp[i][j] ); } fprintf( stdout, "\n" ); } #endif average = 0.0; for( i=0; i<20; i++ ) average += n_distmp[i][i] * freq1[i]; #if TEST fprintf( stdout, "####### average1 = %f\n", average ); #endif for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) n_distmp[i][j] *= 600.0 / average; #if TEST fprintf( stdout, "after average division : \n" ); for( i=0; i<20; i++ ) { for( j=0; j<=i; j++ ) { fprintf( stdout, "%7.1f", n_distmp[i][j] ); } fprintf( stdout, "\n" ); } #endif for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) n_distmp[i][j] -= offset; #if TEST fprintf( stdout, "after offset substruction (offset = %d): \n", offset ); for( i=0; i<20; i++ ) { for( j=0; j<=i; j++ ) { fprintf( stdout, "%7.1f", n_distmp[i][j] ); } fprintf( stdout, "\n" ); } #endif #if 0 /* 注意 !!!!!!!!!! */ penalty -= offset; #endif for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) n_distmp[i][j] = shishagonyuu( n_distmp[i][j] ); if( disp ) { fprintf( stdout, " scoring matrix \n" ); for( i=0; i<20; i++ ) { fprintf( stdout, "%c ", amino[i] ); for( j=0; j<20; j++ ) fprintf( stdout, "%5.0f", n_distmp[i][j] ); fprintf( stdout, "\n" ); } fprintf( stdout, " " ); for( i=0; i<20; i++ ) fprintf( stdout, " %c", amino[i] ); average = 0.0; for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) average += n_distmp[i][j] * freq1[i] * freq1[j]; fprintf( stdout, "average = %f\n", average ); average = 0.0; for( i=0; i<20; i++ ) average += n_distmp[i][i] * freq1[i]; fprintf( stdout, "itch average = %f\n", average ); fprintf( stderr, "parameters: %d, %d, %d\n", penalty, penalty_ex, offset ); exit( 1 ); } for( i=0; i<26; i++ ) for( j=0; j<26; j++ ) n_dis[i][j] = 0; for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) n_dis[i][j] = (int)n_distmp[i][j]; FreeDoubleMtx( n_distmp ); FreeDoubleVec( datafreq ); FreeDoubleVec( freq ); fprintf( stderr, "done.\n" ); } else if( dorp == 'p' && scoremtx == 2 ) /* Miyata-Yasunaga */ { fprintf( stderr, "Not supported\n" ); exit( 1 ); for( i=0; i<26; i++ ) for( j=0; j<26; j++ ) n_dis[i][j] = locn_dism[i][j]; for( i=0; i<26; i++ ) if( i != 24 ) n_dis[i][24] = n_dis[24][i] = exgpm; n_dis[24][24] = 0; if( ppenalty == NOTSPECIFIED ) ppenalty = locpenaltym; if( poffset == NOTSPECIFIED ) poffset = -20; if( pamN == NOTSPECIFIED ) pamN = 0; if( kimuraR == NOTSPECIFIED ) kimuraR = 1; penalty = ppenalty; offset = poffset; sprintf( modelname, "Miyata-Yasunaga, %6.3f, %6.3f", -(double)ppenalty/1000, -(double)poffset/1000 ); for( i=0; i<26; i++ ) amino[i] = locaminom[i]; for( i=0; i<26; i++ ) amino_grp[(int)amino[i]] = locgrpm[i]; #if DEBUG fprintf( stdout, "scoreing matrix : \n" ); for( i=0; i<26; i++ ) { for( j=0; j<26; j++ ) { fprintf( stdout, "%#5d", n_dis[i][j] ); } fprintf( stdout, "\n" ); } #endif } else /* JTT */ { double **rsr; double **pam1; double **pamx; double *freq; double *freq1; double *mutab; double *datafreq; double average; double tmp; double delta; rsr = AllocateDoubleMtx( 20, 20 ); pam1 = AllocateDoubleMtx( 20, 20 ); pamx = AllocateDoubleMtx( 20, 20 ); freq = AllocateDoubleVec( 20 ); mutab = AllocateDoubleVec( 20 ); datafreq = AllocateDoubleVec( 20 ); if( ppenalty == NOTSPECIFIED ) ppenalty = DEFAULTGOP_J; if( ppenalty_OP == NOTSPECIFIED ) ppenalty_OP = DEFAULTGOP_J; if( ppenalty_ex == NOTSPECIFIED ) ppenalty_ex = DEFAULTGEP_J; if( ppenalty_EX == NOTSPECIFIED ) ppenalty_EX = DEFAULTGEP_J; if( poffset == NOTSPECIFIED ) poffset = DEFAULTOFS_J; if( pamN == NOTSPECIFIED ) pamN = DEFAULTPAMN; if( kimuraR == NOTSPECIFIED ) kimuraR = 1; penalty = (int)( 600.0 / 1000.0 * ppenalty + 0.5 ); penalty_OP = (int)( 600.0 / 1000.0 * ppenalty_OP + 0.5 ); penalty_ex = (int)( 600.0 / 1000.0 * ppenalty_ex + 0.5 ); penalty_EX = (int)( 600.0 / 1000.0 * ppenalty_EX + 0.5 ); offset = (int)( 600.0 / 1000.0 * poffset + 0.5 ); offsetFFT = (int)( 600.0 / 1000.0 * (-0) + 0.5 ); offsetLN = (int)( 600.0 / 1000.0 * 100 + 0.5); penaltyLN = (int)( 600.0 / 1000.0 * -2000 + 0.5); penalty_exLN = (int)( 600.0 / 1000.0 * -100 + 0.5); sprintf( modelname, "%s %dPAM, %6.3f, %6.3f", (TMorJTT==TM)?"Transmembrane":"JTT", pamN, -(double)ppenalty/1000, -(double)poffset/1000 ); JTTmtx( rsr, freq, amino, amino_grp, (int)(TMorJTT==TM) ); #if TEST fprintf( stdout, "rsr = \n" ); for( i=0; i<20; i++ ) { for( j=0; j<20; j++ ) { fprintf( stdout, "%9.2f ", rsr[i][j] ); } fprintf( stdout, "\n" ); } #endif for( i=0; i<0x80; i++ ) amino_n[i] = -1; for( i=0; i<26; i++ ) amino_n[(int)amino[i]] = i; if( fmodel == 1 ) { calcfreq( nseq, seq, datafreq ); freq1 = datafreq; } else freq1 = freq; fprintf( stderr, "generating %dPAM %s scoring matrix for amino acids ... ", pamN, (TMorJTT==TM)?"Transmembrane":"JTT" ); tmp = 0.0; for( i=0; i<20; i++ ) { mutab[i] = 0.0; for( j=0; j<20; j++ ) mutab[i] += rsr[i][j] * freq[j]; tmp += mutab[i] * freq[i]; } #if TEST fprintf( stdout, "mutability = \n" ); for( i=0; i<20; i++ ) fprintf( stdout, "%5.3f\n", mutab[i] ); fprintf( stdout, "tmp = %f\n", tmp ); #endif delta = 0.01 / tmp; for( i=0; i<20; i++ ) { for( j=0; j<20; j++ ) { if( i != j ) pam1[i][j] = delta * rsr[i][j] * freq[i]; else pam1[i][j] = 1.0 - delta * mutab[i]; } } if( disp ) { fprintf( stdout, "pam1 = \n" ); for( i=0; i<20; i++ ) { for( j=0; j<20; j++ ) { fprintf( stdout, "%9.6f ", pam1[i][j] ); } fprintf( stdout, "\n" ); } } MtxuntDouble( pamx, 20 ); for( x=0; x < pamN; x++ ) MtxmltDouble( pamx, pam1, 20 ); for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) pamx[i][j] /= freq[j]; for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) { if( pamx[i][j] == 0.0 ) { fprintf( stderr, "WARNING: pamx[%d][%d] = 0.0?\n", i, j ); pamx[i][j] = 0.00001; /* by J. Thompson */ } pamx[i][j] = log10( pamx[i][j] ) * 1000.0; } #if TEST fprintf( stdout, "raw scoring matrix : \n" ); for( i=0; i<20; i++ ) { for( j=0; j<20; j++ ) { fprintf( stdout, "%5.0f", pamx[i][j] ); } fprintf( stdout, "\n" ); } average = tmp = 0.0; for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) { average += pamx[i][j] * freq1[i] * freq1[j]; tmp += freq1[i] * freq1[j]; } average /= tmp; fprintf( stdout, "Zenbu average = %f, tmp = %f \n", average, tmp ); average = tmp = 0.0; for( i=0; i<20; i++ ) for( j=i; j<20; j++ ) { average += pamx[i][j] * freq1[i] * freq1[j]; tmp += freq1[i] * freq1[j]; } average /= tmp; fprintf( stdout, "Zenbu average2 = %f, tmp = %f \n", average, tmp ); average = tmp = 0.0; for( i=0; i<20; i++ ) { average += pamx[i][i] * freq1[i]; tmp += freq1[i]; } average /= tmp; fprintf( stdout, "Itch average = %f, tmp = %f \n", average, tmp ); #endif #if NORMALIZE1 if( fmodel == -1 ) average = 0.0; else { #if TEST for( i=0; i<20; i++ ) fprintf( stdout, "freq[%c] = %f, datafreq[%c] = %f, freq1[] = %f\n", amino[i], freq[i], amino[i], datafreq[i], freq1[i] ); #endif average = 0.0; for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) average += pamx[i][j] * freq1[i] * freq1[j]; } #if TEST fprintf( stdout, "####### average2 = %f\n", average ); #endif for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) pamx[i][j] -= average; #if TEST fprintf( stdout, "average2 = %f\n", average ); fprintf( stdout, "after average substruction : \n" ); for( i=0; i<20; i++ ) { for( j=0; j<20; j++ ) { fprintf( stdout, "%5.0f", pamx[i][j] ); } fprintf( stdout, "\n" ); } #endif average = 0.0; for( i=0; i<20; i++ ) average += pamx[i][i] * freq1[i]; #if TEST fprintf( stdout, "####### average1 = %f\n", average ); #endif for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) pamx[i][j] *= 600.0 / average; #if TEST fprintf( stdout, "after average division : \n" ); for( i=0; i<20; i++ ) { for( j=0; j<=i; j++ ) { fprintf( stdout, "%5.0f", pamx[i][j] ); } fprintf( stdout, "\n" ); } #endif for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) pamx[i][j] -= offset; #if TEST fprintf( stdout, "after offset substruction (offset = %d): \n", offset ); for( i=0; i<20; i++ ) { for( j=0; j<=i; j++ ) { fprintf( stdout, "%5.0f", pamx[i][j] ); } fprintf( stdout, "\n" ); } #endif #if 0 /* 注意 !!!!!!!!!! */ penalty -= offset; #endif for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) pamx[i][j] = shishagonyuu( pamx[i][j] ); #else average = 0.0; for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) average += pamx[i][j]; average /= 400.0; for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) { pamx[i][j] -= average; pamx[i][j] = shishagonyuu( pamx[i][j] ); } #endif if( disp ) { fprintf( stdout, " scoring matrix \n" ); for( i=0; i<20; i++ ) { fprintf( stdout, "%c ", amino[i] ); for( j=0; j<20; j++ ) fprintf( stdout, "%5.0f", pamx[i][j] ); fprintf( stdout, "\n" ); } fprintf( stdout, " " ); for( i=0; i<20; i++ ) fprintf( stdout, " %c", amino[i] ); average = 0.0; for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) average += pamx[i][j] * freq1[i] * freq1[j]; fprintf( stdout, "average = %f\n", average ); average = 0.0; for( i=0; i<20; i++ ) average += pamx[i][i] * freq1[i]; fprintf( stdout, "itch average = %f\n", average ); fprintf( stderr, "parameters: %d, %d, %d\n", penalty, penalty_ex, offset ); exit( 1 ); } for( i=0; i<26; i++ ) for( j=0; j<26; j++ ) n_dis[i][j] = 0; for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) n_dis[i][j] = (int)pamx[i][j]; fprintf( stderr, "done.\n" ); FreeDoubleMtx( rsr ); FreeDoubleMtx( pam1 ); FreeDoubleMtx( pamx ); FreeDoubleVec( freq ); FreeDoubleVec( mutab ); FreeDoubleVec( datafreq ); } fprintf( stderr, "scoremtx = %d\n", scoremtx ); #if DEBUG fprintf( stderr, "scoremtx = %d\n", scoremtx ); fprintf( stderr, "amino[] = %s\n", amino ); #endif for( i=0; i<0x80; i++ )amino_n[i] = -1; for( i=0; i<26; i++) amino_n[(int)amino[i]] = i; for( i=0; i<0x80; i++ ) for( j=0; j<0x80; j++ ) amino_dis[i][j] = 0; for( i=0; i<0x80; i++ ) for( j=0; j<0x80; j++ ) amino_disLN[i][j] = 0; for( i=0; i<0x80; i++ ) for( j=0; j<0x80; j++ ) amino_dis_consweight_multi[i][j] = 0.0; for( i=0; i<26; i++) for( j=0; j<26; j++ ) { amino_dis[(int)amino[i]][(int)amino[j]] = n_dis[i][j]; n_dis_consweight_multi[i][j] = (float)n_dis[i][j] * consweight_multi; amino_dis_consweight_multi[(int)amino[i]][(int)amino[j]] = (double)n_dis[i][j] * consweight_multi; } if( dorp == 'd' ) /* DNA */ { for( i=0; i<5; i++) for( j=0; j<5; j++ ) amino_disLN[(int)amino[i]][(int)amino[j]] = n_dis[i][j] + offset - offsetLN; for( i=5; i<10; i++) for( j=5; j<10; j++ ) amino_disLN[(int)amino[i]][(int)amino[j]] = n_dis[i][j] + offset - offsetLN; for( i=0; i<5; i++) for( j=0; j<5; j++ ) n_disFFT[i][j] = n_dis[i][j] + offset - offsetFFT; for( i=5; i<10; i++) for( j=5; j<10; j++ ) n_disFFT[i][j] = n_dis[i][j] + offset - offsetFFT; } else // protein { for( i=0; i<20; i++) for( j=0; j<20; j++ ) amino_disLN[(int)amino[i]][(int)amino[j]] = n_dis[i][j] + offset - offsetLN; for( i=0; i<20; i++) for( j=0; j<20; j++ ) n_disFFT[i][j] = n_dis[i][j] + offset - offsetFFT; } #if 0 fprintf( stderr, "amino_dis (offset = %d): \n", offset ); for( i=0; i<20; i++ ) { for( j=0; j<20; j++ ) { fprintf( stderr, "%5d", amino_dis[(int)amino[i]][(int)amino[j]] ); } fprintf( stderr, "\n" ); } fprintf( stderr, "amino_disLN (offsetLN = %d): \n", offsetLN ); for( i=0; i<20; i++ ) { for( j=0; j<20; j++ ) { fprintf( stderr, "%5d", amino_disLN[(int)amino[i]][(int)amino[j]] ); } fprintf( stderr, "\n" ); } fprintf( stderr, "n_dis (offset = %d): \n", offset ); for( i=0; i<26; i++ ) { for( j=0; j<26; j++ ) { fprintf( stderr, "%5d", n_dis[i][j] ); } fprintf( stderr, "\n" ); } fprintf( stderr, "n_disFFT (offsetFFT = %d): \n", offsetFFT ); for( i=0; i<26; i++ ) { for( j=0; j<26; j++ ) { fprintf( stderr, "%5d", n_disFFT[i][j] ); } fprintf( stderr, "\n" ); } exit( 1 ); #endif ppid = 0; if( fftThreshold == NOTSPECIFIED ) { fftThreshold = FFT_THRESHOLD; } if( fftWinSize == NOTSPECIFIED ) { if( dorp == 'd' ) fftWinSize = FFT_WINSIZE_D; else fftWinSize = FFT_WINSIZE_P; } if( fftscore ) { double av, sd; for( i=0; i<20; i++ ) polarity[i] = polarity_[i]; for( av=0.0, i=0; i<20; i++ ) av += polarity[i]; av /= 20.0; for( sd=0.0, i=0; i<20; i++ ) sd += ( polarity[i]-av ) * ( polarity[i]-av ); sd /= 20.0; sd = sqrt( sd ); for( i=0; i<20; i++ ) polarity[i] -= av; for( i=0; i<20; i++ ) polarity[i] /= sd; for( i=0; i<20; i++ ) volume[i] = volume_[i]; for( av=0.0, i=0; i<20; i++ ) av += volume[i]; av /= 20.0; for( sd=0.0, i=0; i<20; i++ ) sd += ( volume[i]-av ) * ( volume[i]-av ); sd /= 20.0; sd = sqrt( sd ); for( i=0; i<20; i++ ) volume[i] -= av; for( i=0; i<20; i++ ) volume[i] /= sd; #if 0 for( i=0; i<20; i++ ) fprintf( stdout, "amino=%c, pol = %f<-%f, vol = %f<-%f\n", amino[i], polarity[i], polarity_[i], volume[i], volume_[i] ); for( i=0; i<20; i++ ) fprintf( stdout, "%c %+5.3f %+5.3f\n", amino[i], volume[i], polarity[i] ); #endif } }
static void pairalign( char name[M][B], int nlen[M], char **seq, char **aseq, char **mseq1, char **mseq2, double *equiv, double *effarr, char **strfiles, char **chainids, int alloclen ) { int i, j, ilim; int clus1, clus2; int off1, off2; float pscore = 0.0; // by D.Mathog static char *indication1, *indication2; FILE *hat2p, *hat3p; static double **distancemtx; static double *effarr1 = NULL; static double *effarr2 = NULL; char *pt; char *hat2file = "hat2"; LocalHom **localhomtable, *tmpptr; static char **pair; // int intdum; double bunbo; char **checkseq; localhomtable = (LocalHom **)calloc( njob, sizeof( LocalHom *) ); for( i=0; i<njob; i++) { localhomtable[i] = (LocalHom *)calloc( njob, sizeof( LocalHom ) ); for( j=0; j<njob; j++) { localhomtable[i][j].start1 = -1; localhomtable[i][j].end1 = -1; localhomtable[i][j].start2 = -1; localhomtable[i][j].end2 = -1; localhomtable[i][j].opt = -1.0; localhomtable[i][j].next = NULL; localhomtable[i][j].nokori = 0; } } if( effarr1 == NULL ) { distancemtx = AllocateDoubleMtx( njob, njob ); effarr1 = AllocateDoubleVec( njob ); effarr2 = AllocateDoubleVec( njob ); indication1 = AllocateCharVec( 150 ); indication2 = AllocateCharVec( 150 ); checkseq = AllocateCharMtx( njob, alloclen ); #if 0 #else pair = AllocateCharMtx( njob, njob ); #endif } #if 0 fprintf( stderr, "##### fftwinsize = %d, fftthreshold = %d\n", fftWinSize, fftThreshold ); #endif #if 0 for( i=0; i<njob; i++ ) fprintf( stderr, "TBFAST effarr[%d] = %f\n", i, effarr[i] ); #endif // writePre( njob, name, nlen, aseq, 0 ); for( i=0; i<njob; i++ ) for( j=0; j<njob; j++ ) pair[i][j] = 0; for( i=0; i<njob; i++ ) pair[i][i] = 1; for( i=0; i<njob; i++ ) { strcpy( checkseq[i], seq[i] ); // fprintf( stderr, "checkseq[%d] = %s\n", i, checkseq[i] ); } ilim = njob - 1; for( i=0; i<ilim; i++ ) { fprintf( stderr, "% 5d / %d\r", i, njob ); for( j=i+1; j<njob; j++ ) { #if 0 if( strlen( seq[i] ) == 0 || strlen( seq[j] ) == 0 ) { distancemtx[i][j] = pscore; continue; } #endif strcpy( aseq[i], seq[i] ); strcpy( aseq[j], seq[j] ); clus1 = conjuctionfortbfast( pair, i, aseq, mseq1, effarr1, effarr, indication1 ); clus2 = conjuctionfortbfast( pair, j, aseq, mseq2, effarr2, effarr, indication2 ); // fprintf( stderr, "mseq1 = %s\n", mseq1[0] ); // fprintf( stderr, "mseq2 = %s\n", mseq2[0] ); #if 0 fprintf( stderr, "group1 = %.66s", indication1 ); fprintf( stderr, "\n" ); fprintf( stderr, "group2 = %.66s", indication2 ); fprintf( stderr, "\n" ); #endif // for( l=0; l<clus1; l++ ) fprintf( stderr, "## STEP-eff for mseq1-%d %f\n", l, effarr1[l] ); #if 1 { switch( alg ) { case( 'T' ): fprintf( stderr, " Calling tmalign %d-%d/%d \r", i+1, j+1, njob ); pscore = calltmalign( mseq1, mseq2, equiv, strfiles[i], chainids[i], strfiles[j], chainids[j], alloclen ); off1 = off2 = 0; break; case( 'R' ): fprintf( stderr, " Calling PDP_ASH.pl %d-%d/%d \r", i+1, j+1, njob ); pscore = callrash( i, j, mseq1, mseq2, equiv, strfiles[i], chainids[i], strfiles[j], chainids[j], alloclen ); off1 = off2 = 0; break; ErrorExit( "ERROR IN SOURCE FILE" ); } } #endif distancemtx[i][j] = pscore; #if SCOREOUT fprintf( stderr, "score = %10.2f (%d,%d)\n", pscore, i, j ); #endif putlocalhom_str( mseq1[0], mseq2[0], equiv, scale, localhomtable[i]+j, off1, off2, (int)pscore, strlen( mseq1[0] ) ); #if 1 if( alreadyoutput[i] == 0 ) { alreadyoutput[i] = 1; gappick0( seq[i], mseq1[0] ); fprintf( stdout, ">%d_%s-%s\n%s\n", i+1, strfiles[i], chainids[i], seq[i] ); strcpy( checkseq[i], seq[i] ); } else { gappick0( seq[i], mseq1[0] ); fprintf( stderr, "checking seq%d\n", i ); // fprintf( stderr, " seq=%s\n", seq[i] ); // fprintf( stderr, "checkseq=%s\n", checkseq[i] ); if( strcmp( checkseq[i], seq[i] ) ) { fprintf( stderr, "\n\nWARNING: Sequence changed!!\n" ); fprintf( stderr, "i=%d\n", i ); fprintf( stderr, " seq=%s\n", seq[i] ); fprintf( stderr, "checkseq=%s\n", checkseq[i] ); exit( 1 ); } } if( alreadyoutput[j] == 0 ) { alreadyoutput[j] = 1; gappick0( seq[j], mseq2[0] ); fprintf( stdout, ">%d_%s-%s\n%s\n", j+1, strfiles[j], chainids[j], seq[j] ); strcpy( checkseq[j], seq[j] ); } else { gappick0( seq[j], mseq2[0] ); fprintf( stderr, "checking seq%d\n", j ); if( strcmp( checkseq[j], seq[j] ) ) { fprintf( stderr, "\n\nWARNING: Sequence changed!!\n" ); fprintf( stderr, "j=%d\n", j ); fprintf( stderr, " seq=%s\n", seq[j] ); fprintf( stderr, "checkseq=%s\n", checkseq[j] ); exit( 1 ); } } #endif } } for( i=0; i<njob; i++ ) { pscore = 0.0; for( pt=seq[i]; *pt; pt++ ) pscore += amino_dis[(int)*pt][(int)*pt]; distancemtx[i][i] = pscore; } ilim = njob-1; for( i=0; i<ilim; i++ ) { for( j=i+1; j<njob; j++ ) { bunbo = MIN( distancemtx[i][i], distancemtx[j][j] ); if( bunbo == 0.0 ) distancemtx[i][j] = 2.0; else distancemtx[i][j] = ( 1.0 - distancemtx[i][j] / bunbo ) * 2.0; } } hat2p = fopen( hat2file, "w" ); if( !hat2p ) ErrorExit( "Cannot open hat2." ); WriteHat2( hat2p, njob, name, distancemtx ); fclose( hat2p ); fprintf( stderr, "##### writing hat3\n" ); hat3p = fopen( "hat3", "w" ); if( !hat3p ) ErrorExit( "Cannot open hat3." ); ilim = njob-1; for( i=0; i<ilim; i++ ) { for( j=i+1; j<njob; j++ ) { for( tmpptr=localhomtable[i]+j; tmpptr; tmpptr=tmpptr->next ) { if( tmpptr->opt == -1.0 ) continue; fprintf( hat3p, "%d %d %d %7.5f %d %d %d %d k\n", i, j, tmpptr->overlapaa, tmpptr->opt, tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2 ); } } } fclose( hat3p ); #if DEBUG fprintf( stderr, "calling FreeLocalHomTable\n" ); #endif FreeLocalHomTable( localhomtable, njob ); #if DEBUG fprintf( stderr, "done. FreeLocalHomTable\n" ); #endif }
float L__align11_noalign( double **n_dynamicmtx, char **seq1, char **seq2 ) // warp mitaiou { // int k; 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 static TLS float mi, *m; // static TLS int **ijp; // static TLS int mpi, *mp; static TLS float *w1, *w2; static TLS float *match; static TLS float *initverticalw; /* kufuu sureba iranai */ static TLS float *lastverticalw; /* kufuu sureba iranai */ // static TLS char **mseq1; // static TLS char **mseq2; // static TLS char **mseq; // static TLS int **intwork; // static TLS float **floatwork; static TLS int orlgth1 = 0, orlgth2 = 0; static TLS double **amino_dynamicmtx = NULL; // ?? 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; if( seq1 == NULL ) { if( orlgth1 > 0 && orlgth2 > 0 ) { orlgth1 = 0; orlgth2 = 0; // free( mseq1 ); // free( mseq2 ); FreeFloatVec( w1 ); FreeFloatVec( w2 ); FreeFloatVec( match ); FreeFloatVec( initverticalw ); FreeFloatVec( lastverticalw ); FreeFloatVec( m ); // FreeIntVec( mp ); // FreeCharMtx( mseq ); if( amino_dynamicmtx ) FreeDoubleMtx( amino_dynamicmtx ); amino_dynamicmtx = NULL; } return( 0.0 ); } // if( orlgth1 == 0 ) // { // mseq1 = AllocateCharMtx( njob, 0 ); // mseq2 = AllocateCharMtx( njob, 0 ); // } lgth1 = strlen( seq1[0] ); lgth2 = strlen( seq2[0] ); if( lgth1 > orlgth1 || lgth2 > orlgth2 ) { int ll1, ll2; if( orlgth1 > 0 && orlgth2 > 0 ) { FreeFloatVec( w1 ); FreeFloatVec( w2 ); FreeFloatVec( match ); FreeFloatVec( initverticalw ); FreeFloatVec( lastverticalw ); FreeFloatVec( m ); // FreeIntVec( mp ); // FreeCharMtx( mseq ); // FreeFloatMtx( floatwork ); // FreeIntMtx( intwork ); if( amino_dynamicmtx ) FreeDoubleMtx( amino_dynamicmtx ); amino_dynamicmtx = NULL; } ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100; ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 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( nalphabets, MAX( ll1, ll2 )+2 ); // intwork = AllocateIntMtx( nalphabets, MAX( ll1, ll2 )+2 ); #if DEBUG fprintf( stderr, "succeeded\n" ); #endif amino_dynamicmtx = AllocateDoubleMtx( 0x80, 0x80 ); orlgth1 = ll1 - 100; orlgth2 = ll2 - 100; } for( i=0; i<nalphabets; i++) for( j=0; j<nalphabets; j++ ) amino_dynamicmtx[(int)amino[i]][(int)amino[j]] = (double)n_dynamicmtx[i][j]; // mseq1[0] = mseq[0]; // mseq2[0] = mseq[1]; // if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 ) // { // int ll1, ll2; // // if( commonAlloc1 && commonAlloc2 ) // { // FreeIntMtx( commonIP ); // } // // ll1 = MAX( orlgth1, commonAlloc1 ); // ll2 = MAX( orlgth2, commonAlloc2 ); #if DEBUG // fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 ); #endif // commonIP = AllocateIntMtx( ll1+10, ll2+10 ); #if DEBUG // fprintf( stderr, "succeeded\n\n" ); #endif // commonAlloc1 = ll1; // commonAlloc2 = ll2; // } // ijp = commonIP; #if 0 for( i=0; i<lgth1; i++ ) fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] ); #endif currentw = w1; previousw = w2; match_calc_mtx( amino_dynamicmtx, initverticalw, seq2, seq1, 0, lgth1 ); match_calc_mtx( amino_dynamicmtx, currentw, seq1, seq2, 0, lgth2 ); lasti = lgth2+1; for( j=1; j<lasti; ++j ) { m[j] = currentw[j-1]; // mp[j] = 0; #if 0 if( m[j] < localthr ) m[j] = localthr2; #endif } lastverticalw[0] = currentw[lgth2-1]; lasti = lgth1+1; #if 0 fprintf( stderr, "currentw = \n" ); for( i=0; i<lgth1+1; i++ ) { fprintf( stderr, "%5.2f ", currentw[i] ); } fprintf( stderr, "\n" ); fprintf( stderr, "initverticalw = \n" ); for( i=0; i<lgth2+1; i++ ) { fprintf( stderr, "%5.2f ", initverticalw[i] ); } fprintf( stderr, "\n" ); #endif #if DEBUG2 fprintf( stderr, "\n" ); fprintf( stderr, " " ); for( j=0; j<lgth2; j++ ) fprintf( stderr, "%c ", seq2[0][j] ); fprintf( stderr, "\n" ); #endif localstop = lgth1+lgth2+1; maxwm = -999999999.9; #if DEBUG2 fprintf( stderr, "\n" ); fprintf( stderr, "%c ", seq1[0][0] ); for( j=0; j<lgth2+1; j++ ) fprintf( stderr, "%5.0f ", currentw[j] ); fprintf( stderr, "\n" ); #endif for( i=1; i<lasti; i++ ) { wtmp = previousw; previousw = currentw; currentw = wtmp; previousw[0] = initverticalw[i-1]; match_calc_mtx( amino_dynamicmtx, currentw, seq1, seq2, i, lgth2 ); #if DEBUG2 fprintf( stderr, "%c ", seq1[0][i] ); fprintf( stderr, "%5.0f ", currentw[0] ); #endif #if XXXXXXX fprintf( stderr, "\n" ); fprintf( stderr, "i=%d\n", i ); fprintf( stderr, "currentw = \n" ); for( j=0; j<lgth2; j++ ) { fprintf( stderr, "%5.2f ", currentw[j] ); } fprintf( stderr, "\n" ); #endif #if XXXXXXX fprintf( stderr, "\n" ); fprintf( stderr, "i=%d\n", i ); fprintf( stderr, "currentw = \n" ); for( j=0; j<lgth2; j++ ) { fprintf( stderr, "%5.2f ", currentw[j] ); } fprintf( stderr, "\n" ); #endif currentw[0] = initverticalw[i]; mi = previousw[0]; // mpi = 0; #if 0 if( mi < localthr ) mi = localthr2; #endif // ijppt = ijp[i] + 1; mjpt = m + 1; prept = previousw; curpt = currentw + 1; // mpjpt = mp + 1; lastj = lgth2+1; for( j=1; j<lastj; j++ ) { wm = *prept; // *ijppt = 0; #if 0 fprintf( stderr, "%5.0f->", 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 0 // IRUKAMO!!!! if( ijp[endali][endalj] == localstop ) { strcpy( seq1[0], "" ); strcpy( seq2[0], "" ); *off1pt = *off2pt = 0; fprintf( stderr, "maxwm <- 0.0 \n" ); return( 0.0 ); } #else if( maxwm < localthr ) { fprintf( stderr, "maxwm <- 0.0 \n" ); return( 0.0 ); } #endif // Ltracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, ijp, off1pt, off2pt, endali, endalj ); // 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 return( maxwm ); }
float L__align11( double **n_dynamicmtx, float scoreoffset, 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; 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 static TLS float mi, *m; static TLS int **ijp; static TLS int mpi, *mp; static TLS float *w1, *w2; static TLS float *match; static TLS float *initverticalw; /* kufuu sureba iranai */ static TLS float *lastverticalw; /* kufuu sureba iranai */ static TLS char **mseq1; static TLS char **mseq2; static TLS char **mseq; // static TLS int **intwork; // static TLS float **floatwork; static TLS int orlgth1 = 0, orlgth2 = 0; static TLS double **amino_dynamicmtx = NULL; // ?? float maxwm; int endali = 0, endalj = 0; // by D.Mathog, a guess // int endali, endalj; float localthr = -offset + scoreoffset * 600; // 2013/12/13 float localthr2 = -offset + scoreoffset * 600; // 2013/12/13 // float localthr = -offset; // float localthr2 = -offset; float fpenalty = (float)penalty; float fpenalty_ex = (float)penalty_ex; float fpenalty_shift = (float)penalty_shift; float fpenalty_tmp; // atode kesu int *warpis = NULL; int *warpjs = NULL; int *warpi = NULL; int *warpj = NULL; int *prevwarpi = NULL; int *prevwarpj = NULL; float *wmrecords = NULL; float *prevwmrecords = NULL; int warpn = 0; int warpbase; float curm = 0.0; float *wmrecordspt, *wmrecords1pt, *prevwmrecordspt; int *warpipt, *warpjpt; if( seq1 == NULL ) { if( orlgth1 > 0 && orlgth2 > 0 ) { orlgth1 = 0; orlgth2 = 0; free( mseq1 ); free( mseq2 ); FreeFloatVec( w1 ); FreeFloatVec( w2 ); FreeFloatVec( match ); FreeFloatVec( initverticalw ); FreeFloatVec( lastverticalw ); FreeFloatVec( m ); FreeIntVec( mp ); FreeCharMtx( mseq ); if( amino_dynamicmtx ) FreeDoubleMtx( amino_dynamicmtx ); amino_dynamicmtx = NULL; } return( 0.0 ); } if( orlgth1 == 0 ) { mseq1 = AllocateCharMtx( njob, 0 ); mseq2 = AllocateCharMtx( njob, 0 ); } lgth1 = strlen( seq1[0] ); lgth2 = strlen( seq2[0] ); warpbase = lgth1 + lgth2; warpis = NULL; warpjs = NULL; warpn = 0; if( trywarp ) { wmrecords = AllocateFloatVec( lgth2+1 ); warpi = AllocateIntVec( lgth2+1 ); warpj = AllocateIntVec( lgth2+1 ); prevwmrecords = AllocateFloatVec( lgth2+1 ); prevwarpi = AllocateIntVec( lgth2+1 ); prevwarpj = AllocateIntVec( lgth2+1 ); for( i=0; i<lgth2+1; i++ ) prevwmrecords[i] = 0.0; for( i=0; i<lgth2+1; i++ ) wmrecords[i] = 0.0; for( i=0; i<lgth2+1; i++ ) prevwarpi[i] = -warpbase; for( i=0; i<lgth2+1; i++ ) prevwarpj[i] = -warpbase; for( i=0; i<lgth2+1; i++ ) warpi[i] = -warpbase; for( i=0; i<lgth2+1; i++ ) warpj[i] = -warpbase; } if( lgth1 > orlgth1 || lgth2 > orlgth2 ) { int ll1, ll2; if( orlgth1 > 0 && orlgth2 > 0 ) { FreeFloatVec( w1 ); FreeFloatVec( w2 ); FreeFloatVec( match ); FreeFloatVec( initverticalw ); FreeFloatVec( lastverticalw ); FreeFloatVec( m ); FreeIntVec( mp ); FreeCharMtx( mseq ); if( amino_dynamicmtx ) FreeDoubleMtx( amino_dynamicmtx ); amino_dynamicmtx = NULL; // FreeFloatMtx( floatwork ); // FreeIntMtx( intwork ); } ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100; ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 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( nalphabets, MAX( ll1, ll2 )+2 ); // intwork = AllocateIntMtx( nalphabets, MAX( ll1, ll2 )+2 ); #if DEBUG fprintf( stderr, "succeeded\n" ); #endif amino_dynamicmtx = AllocateDoubleMtx( 0x80, 0x80 ); orlgth1 = ll1 - 100; orlgth2 = ll2 - 100; } for( i=0; i<nalphabets; i++) for( j=0; j<nalphabets; j++ ) amino_dynamicmtx[(int)amino[i]][(int)amino[j]] = (double)n_dynamicmtx[i][j]; mseq1[0] = mseq[0]; mseq2[0] = mseq[1]; if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 ) { int ll1, ll2; if( commonAlloc1 && commonAlloc2 ) { FreeIntMtx( commonIP ); } ll1 = MAX( orlgth1, commonAlloc1 ); ll2 = MAX( orlgth2, commonAlloc2 ); #if DEBUG fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 ); #endif commonIP = AllocateIntMtx( ll1+10, ll2+10 ); #if DEBUG fprintf( stderr, "succeeded\n\n" ); #endif commonAlloc1 = ll1; commonAlloc2 = ll2; } ijp = commonIP; #if 0 for( i=0; i<lgth1; i++ ) fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] ); #endif currentw = w1; previousw = w2; match_calc_mtx( amino_dynamicmtx, initverticalw, seq2, seq1, 0, lgth1 ); match_calc_mtx( amino_dynamicmtx, currentw, seq1, seq2, 0, lgth2 ); lasti = lgth2+1; for( j=1; j<lasti; ++j ) { m[j] = currentw[j-1]; mp[j] = 0; #if 0 if( m[j] < localthr ) m[j] = localthr2; #endif } lastverticalw[0] = currentw[lgth2-1]; lasti = lgth1+1; #if 0 fprintf( stderr, "currentw = \n" ); for( i=0; i<lgth1+1; i++ ) { fprintf( stderr, "%5.2f ", currentw[i] ); } fprintf( stderr, "\n" ); fprintf( stderr, "initverticalw = \n" ); for( i=0; i<lgth2+1; i++ ) { fprintf( stderr, "%5.2f ", initverticalw[i] ); } fprintf( stderr, "\n" ); #endif #if DEBUG2 fprintf( stderr, "\n" ); fprintf( stderr, " " ); for( j=0; j<lgth2; j++ ) fprintf( stderr, "%c ", seq2[0][j] ); fprintf( stderr, "\n" ); #endif localstop = lgth1+lgth2+1; maxwm = -999999999.9; #if DEBUG2 fprintf( stderr, "\n" ); fprintf( stderr, "%c ", seq1[0][0] ); for( j=0; j<lgth2+1; j++ ) fprintf( stderr, "%5.0f ", currentw[j] ); fprintf( stderr, "\n" ); #endif for( i=1; i<lasti; i++ ) { wtmp = previousw; previousw = currentw; currentw = wtmp; previousw[0] = initverticalw[i-1]; match_calc_mtx( amino_dynamicmtx, currentw, seq1, seq2, i, lgth2 ); #if DEBUG2 fprintf( stderr, "%c ", seq1[0][i] ); fprintf( stderr, "%5.0f ", currentw[0] ); #endif #if XXXXXXX fprintf( stderr, "\n" ); fprintf( stderr, "i=%d\n", i ); fprintf( stderr, "currentw = \n" ); for( j=0; j<lgth2; j++ ) { fprintf( stderr, "%5.2f ", currentw[j] ); } fprintf( stderr, "\n" ); #endif #if XXXXXXX fprintf( stderr, "\n" ); fprintf( stderr, "i=%d\n", i ); fprintf( stderr, "currentw = \n" ); for( j=0; j<lgth2; j++ ) { fprintf( stderr, "%5.2f ", currentw[j] ); } fprintf( stderr, "\n" ); #endif currentw[0] = initverticalw[i]; mi = previousw[0]; mpi = 0; #if 0 if( mi < localthr ) mi = localthr2; #endif ijppt = ijp[i] + 1; mjpt = m + 1; prept = previousw; curpt = currentw + 1; mpjpt = mp + 1; lastj = lgth2+1; if( trywarp ) { prevwmrecordspt = prevwmrecords; wmrecordspt = wmrecords+1; wmrecords1pt = wmrecords; warpipt = warpi + 1; warpjpt = warpj + 1; } for( j=1; j<lastj; j++ ) { wm = *prept; *ijppt = 0; #if 0 fprintf( stderr, "%5.0f->", 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, localthr = %f\n", i, j, *curpt, localthr ); *ijppt = localstop; wm = localthr2; } #endif #if 0 fprintf( stderr, "%5.0f ", *curpt ); #endif #if 0 fprintf( stderr, "wm (%d,%d) = %5.0f\n", i, j, wm ); // fprintf( stderr, "%c-%c *ijppt = %d, localstop = %d\n", seq1[0][i], seq2[0][j], *ijppt, localstop ); #endif if( trywarp ) { fpenalty_tmp = fpenalty_shift + fpenalty_ex * ( i - prevwarpi[j-1] + j - prevwarpj[j-1] ); // fprintf( stderr, "fpenalty_shift = %f\n", fpenalty_tmp ); // fprintf( stderr, "\n\n\nwarp to %c-%c (%d-%d) from %c-%c (%d-%d) ? prevwmrecords[%d] = %f + %f <- wm = %f\n", seq1[0][prevwarpi[j-1]], seq2[0][prevwarpj[j-1]], prevwarpi[j-1], prevwarpj[j-1], seq1[0][i], seq2[0][j], i, j, j, prevwmrecords[j-1], fpenalty_tmp, wm ); // if( (g=prevwmrecords[j-1] + fpenalty_shift )> wm ) if( ( g=*prevwmrecordspt++ + fpenalty_tmp )> wm ) // naka ha osokute kamawanai { // fprintf( stderr, "Yes! Warp!! from %d-%d (%c-%c) to %d-%d (%c-%c) fpenalty_tmp = %f! warpn = %d\n", i, j, seq1[0][i], seq2[0][j-1], prevwarpi[j-1], prevwarpj[j-1],seq1[0][prevwarpi[j-1]], seq2[0][prevwarpj[j-1]], fpenalty_tmp, warpn ); if( warpn && prevwarpi[j-1] == warpis[warpn-1] && prevwarpj[j-1] == warpjs[warpn-1] ) { *ijppt = warpbase + warpn - 1; } else { *ijppt = warpbase + warpn; warpis = realloc( warpis, sizeof(int) * ( warpn+1 ) ); warpjs = realloc( warpjs, sizeof(int) * ( warpn+1 ) ); warpis[warpn] = prevwarpi[j-1]; warpjs[warpn] = prevwarpj[j-1]; warpn++; } wm = g; } else { } curm = *curpt + wm; // fprintf( stderr, "###### curm = %f at %c-%c, i=%d, j=%d\n", curm, seq1[0][i], seq2[0][j], i, j ); // fprintf( stderr, "copy from i, j-1? %f > %f?\n", wmrecords[j-1], curm ); // if( wmrecords[j-1] > wmrecords[j] ) if( *wmrecords1pt > *wmrecordspt ) { // fprintf( stderr, "yes\n" ); // wmrecords[j] = wmrecords[j-1]; *wmrecordspt = *wmrecords1pt; // warpi[j] = warpi[j-1]; // warpj[j] = warpj[j-1]; *warpipt = *(warpipt-1); *warpjpt = *(warpjpt-1); // fprintf( stderr, "warpi[j]=%d, warpj[j]=%d wmrecords[j] = %f\n", warpi[j], warpj[j], wmrecords[j] ); } // else // { // fprintf( stderr, "no\n" ); // } // fprintf( stderr, " curm = %f at %c-%c\n", curm, seq1[0][i], seq2[0][j] ); // fprintf( stderr, " wmrecords[%d] = %f\n", j, wmrecords[j] ); // fprintf( stderr, "replace?\n" ); // if( curm > wmrecords[j] ) if( curm > *wmrecordspt ) { // fprintf( stderr, "yes at %d-%d (%c-%c), replaced warp: warpi[j]=%d, warpj[j]=%d warpn=%d, wmrecords[j] = %f -> %f\n", i, j, seq1[0][i], seq2[0][j], i, j, warpn, wmrecords[j], curm ); // wmrecords[j] = curm; *wmrecordspt = curm; // warpi[j] = i; // warpj[j] = j; *warpipt = i; *warpjpt = j; } // else // { // fprintf( stderr, "No! warpi[j]=%d, warpj[j]=%d wmrecords[j] = %f\n", warpi[j], warpj[j], wmrecords[j] ); // } // fprintf( stderr, "%d-%d (%c-%c) curm = %5.0f, wmrecords[j]=%f\n", i, j, seq1[0][i], seq2[0][j], curm, wmrecords[j] ); wmrecordspt++; wmrecords1pt++; warpipt++; warpjpt++; } *curpt++ += wm; ijppt++; mjpt++; prept++; mpjpt++; } #if DEBUG2 fprintf( stderr, "\n" ); #endif lastverticalw[i] = currentw[lgth2-1]; if( trywarp ) { fltncpy( prevwmrecords, wmrecords, lastj ); intncpy( prevwarpi, warpi, lastj ); intncpy( prevwarpj, warpj, lastj ); } } // fprintf( stderr, "\nwm = %f\n", wm ); if( trywarp ) { // if( warpn ) fprintf( stderr, "warpn = %d\n", warpn ); free( wmrecords ); free( prevwmrecords ); free( warpi ); free( warpj ); free( prevwarpi ); free( prevwarpj ); } #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; fprintf( stderr, "maxwm <- 0.0 \n" ); return( 0.0 ); } Ltracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, ijp, off1pt, off2pt, endali, endalj, warpis, warpjs, warpbase ); if( warpis ) free( warpis ); if( warpjs ) free( warpjs ); 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 return( maxwm ); }
int main( int argc, char *argv[] ) { static int nlen[M]; static char **name, **seq; static char **oseq; static double **pscore; static double *eff; static double **node0, **node1; static double *gapc; static double *avgap; double tmpavgap; int i, j, m, goffset; static int ***topol; static double **len; FILE *prep; char c; int corestart, coreend; int alloclen; int winsize; char *pt, *ot; double gapmin; arguments( argc, argv ); getnumlen( stdin ); rewind( stdin ); if( njob < 2 ) { fprintf( stderr, "At least 2 sequences should be input!\n" "Only %d sequence found.\n", njob ); exit( 1 ); } seq = AllocateCharMtx( njob, nlenmax*9+1 ); name = AllocateCharMtx( njob, B+1 ); oseq = AllocateCharMtx( njob, nlenmax*9+1 ); alloclen = nlenmax*9; topol = AllocateIntCub( njob, 2, njob ); len = AllocateDoubleMtx( njob, 2 ); pscore = AllocateDoubleMtx( njob, njob ); eff = AllocateDoubleVec( njob ); node0 = AllocateDoubleMtx( njob, njob ); node1 = AllocateDoubleMtx( njob, njob ); gapc = AllocateDoubleVec( alloclen ); avgap = AllocateDoubleVec( alloclen ); #if 0 Read( name, nlen, seq ); #else readData_pointer( stdin, name, nlen, seq ); #endif constants( njob, seq ); #if 0 fprintf( stderr, "params = %d, %d, %d\n", penalty, penalty_ex, offset ); #endif initSignalSM(); initFiles(); WriteOptions( trap_g ); c = seqcheck( seq ); if( c ) { fprintf( stderr, "Illeagal character %c\n", c ); exit( 1 ); } writePre( njob, name, nlen, seq, 0 ); if( tbutree == 0 ) { for( i=1; i<njob; i++ ) { if( nlen[i] != nlen[0] ) { fprintf( stderr, "Input pre-aligned seqences or make hat2.\n" ); exit( 1 ); } } for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ ) { /* pscore[i][j] = (double)score_calc1( seq[i], seq[j] ); */ pscore[i][j] = (double)substitution_hosei( seq[i], seq[j] ); } } else { fprintf( stderr, "Loading 'hat2' ... " ); prep = fopen( "hat2", "r" ); if( prep == NULL ) ErrorExit( "Make hat2." ); readhat2_pointer( prep, njob, name, pscore ); fclose( prep ); fprintf( stderr, "done.\n" ); #if 0 prep = fopen( "hat2_check", "w" ); WriteHat2( prep, njob, name, pscore ); fclose( prep ); #endif } fprintf( stderr, "Constructing dendrogram ... " ); if( treemethod == 'x' ) supg( njob, pscore, topol, len ); else if( treemethod == 's' ) spg( njob, pscore, topol, len ); else if( treemethod == 'p' ) upg2( njob, pscore, topol, len ); else ErrorExit( "Incorrect tree\n" ); fprintf( stderr, "done.\n" ); countnode( njob, topol, node0 ); if( tbrweight ) { weight = 3; #if 0 utree = 0; counteff( njob, topol, len, eff ); utree = 1; #else counteff_simple( njob, topol, len, eff ); #endif } else { for( i=0; i<njob; i++ ) eff[i] = 1.0; } for( i=0; i<nlenmax; i++ ) { gapc[i] = 0.0; for( j=0; j<njob; j++ ) { if( seq[j][i] == '-' ) gapc[i] += eff[j]; } } gapmin = 1.0; winsize = fftWinSize; goffset = winsize/2; tmpavgap = 0.0; corestart = coreend = -1; for( i=0; i<winsize; i++ ) { tmpavgap += gapc[i]; } for( i=winsize; i<nlenmax; i++ ) { m = i - goffset; avgap[m] = tmpavgap / winsize; // fprintf( stdout, "%d %f %f\n", m, avgap[m], gapc[i] ); if( avgap[m] < corethr ) { if( corestart == -1 ) corestart = i - winsize; // fprintf( stdout, "ok, gapmin = %f, corestart = %d, coreend = %d\n", gapmin, corestart, coreend ); if( avgap[m] < gapmin ) { gapmin = avgap[m]; } coreend = i; } tmpavgap -= gapc[i-winsize]; tmpavgap += gapc[i]; } if( corestart == -1 || coreend == -1 ) { corestart = 0; coreend = nlenmax-1; } for( i=0; i<njob; i++ ) { pt = oseq[i]; m = winsize; while( m-- ) *pt++ = '-'; for( j=corestart; j<=coreend; j++ ) *pt++ = seq[i][j]; m = winsize; while( m-- ) *pt++ = '-'; *pt = 0; ot = oseq[i]+winsize-1; pt = seq[i]+corestart-1; if( coreext ) m = winsize; else m = 0; while( m && --pt > seq[i] ) if( *pt != '-' ) { *ot-- = *pt; m--; } ot = oseq[i]+winsize+coreend-corestart+1; pt = seq[i]+coreend; if( coreext ) m = winsize; else m = 0; while( m && *(++pt) ) { if( *pt != '-' ) { *ot++ = *pt; m--; } } fprintf( stdout, ">%s\n", name[i] ); fprintf( stdout, "%s\n", oseq[i] ); } exit( 1 ); SHOWVERSION; return( 0 ); }
float Falign_localhom( char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int alloclen, LocalHom ***localhom, float *totalimpmatch, int *gapmap1, int *gapmap2, int *chudanpt, int chudanref, int *chudanres ) { // tditeration.c deha alloclen ha huhen nanode // prevalloclen ha iranai. int i, j, k, l, m, maxk; 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 char *sgap1, *egap1, *sgap2, *egap2; static TLS int localalloclen = 0; int lag; int tmpint; int count, count0; int len1, len2; int totallen; float totalscore; float impmatch; extern Fukusosuu *AllocateFukusosuuVec(); extern Fukusosuu **AllocateFukusosuuMtx(); if( seq1 == NULL ) { if( result1 ) { // fprintf( stderr, "Freeing localarrays in Falign\n" ); localalloclen = 0; mymergesort( 0, 0, NULL ); alignableReagion( 0, 0, NULL, NULL, NULL, NULL, NULL ); fft( 0, NULL, 1 ); A__align( NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0 ); G__align11( NULL, NULL, 0, 0, 0 ); partA__align( NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL ); blockAlign2( NULL, NULL, NULL, NULL, NULL, NULL ); if( crossscore ) FreeDoubleMtx( crossscore ); FreeCharMtx( result1 ); FreeCharMtx( result2 ); FreeCharMtx( tmpres1 ); FreeCharMtx( tmpres2 ); FreeCharMtx( tmpseq1 ); FreeCharMtx( tmpseq2 ); free( sgap1 ); free( egap1 ); free( sgap2 ); free( egap2 ); free( kouho ); free( cut1 ); free( cut2 ); free( tmpptr1 ); free( tmpptr2 ); free( segment ); free( segment1 ); free( segment2 ); free( sortedseg1 ); free( sortedseg2 ); if( !kobetsubunkatsu ) { FreeFukusosuuMtx ( seqVector1 ); FreeFukusosuuMtx ( seqVector2 ); FreeFukusosuuVec( naisekiNoWa ); FreeFukusosuuMtx( naiseki ); FreeDoubleVec( soukan ); } } else { // fprintf( stderr, "Did not allocate localarrays in Falign\n" ); } return( 0.0 ); } 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 ) { 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 ); 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 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<njob; i++ ) { generateRndSeq( rndseq1[i], nlen ); generateRndSeq( rndseq2[i], nlen ); } #endif localalloclen = nlen; } for( j=0; j<clus1; j++ ) strcpy( tmpseq1[j], seq1[j] ); for( j=0; j<clus2; j++ ) strcpy( tmpseq2[j], seq2[j] ); #if 0 fftfp = fopen( "input_of_Falign", "w" ); fprintf( fftfp, "nlen = %d\n", nlen ); fprintf( fftfp, "seq1: ( %d sequences ) \n", clus1 ); for( i=0; i<clus1; i++ ) fprintf( fftfp, "%s\n", seq1[i] ); fprintf( fftfp, "seq2: ( %d sequences ) \n", clus2 ); for( i=0; i<clus2; i++ ) fprintf( fftfp, "%s\n", seq2[i] ); fclose( fftfp ); system( "less input_of_Falign < /dev/tty > /dev/tty" ); #endif if( !kobetsubunkatsu ) { fprintf( stderr, "FFT ... " ); for( j=0; j<n20or4or2; j++ ) vec_init( seqVector1[j], nlen ); if( fftscore && scoremtx != -1 ) { for( i=0; i<clus1; i++ ) { seq_vec_2( seqVector1[0], polarity, eff1[i], tmpseq1[i] ); seq_vec_2( seqVector1[1], volume, eff1[i], tmpseq1[i] ); } } else { #if 0 for( i=0; i<clus1; i++ ) for( j=0; j<n20or4or2; j++ ) seq_vec( seqVector1[j], amino[j], eff1[i], tmpseq1[i] ); #else for( i=0; i<clus1; i++ ) seq_vec_3( seqVector1, eff1[i], tmpseq1[i] ); #endif } #if RND for( i=0; i<clus1; i++ ) { vec_init2( seqVector1, rndseq1[i], eff1[i], len1, nlen ); } #endif #if 0 fftfp = fopen( "seqVec", "w" ); fprintf( fftfp, "before transform\n" ); for( k=0; k<n20or4or2; k++ ) { fprintf( fftfp, "nlen=%d\n", nlen ); fprintf( fftfp, "%c\n", amino[k] ); for( l=0; l<nlen; l++ ) fprintf( fftfp, "%f %f\n", seqVector1[k][l].R, seqVector1[k][l].I ); } fclose( fftfp ); system( "less seqVec < /dev/tty > /dev/tty" ); #endif for( j=0; j<n20or4or2; j++ ) vec_init( seqVector2[j], nlen ); if( fftscore && scoremtx != -1 ) { for( i=0; i<clus2; i++ ) { seq_vec_2( seqVector2[0], polarity, eff2[i], tmpseq2[i] ); seq_vec_2( seqVector2[1], volume, eff2[i], tmpseq2[i] ); } } else { #if 0 for( i=0; i<clus2; i++ ) for( j=0; j<n20or4or2; j++ ) seq_vec( seqVector2[j], amino[j], eff2[i], tmpseq2[i] ); #else for( i=0; i<clus2; i++ ) seq_vec_3( seqVector2, eff2[i], tmpseq2[i] ); #endif } #if RND for( i=0; i<clus2; i++ ) { vec_init2( seqVector2, rndseq2[i], eff2[i], len2, nlen ); } #endif #if 0 fftfp = fopen( "seqVec2", "w" ); fprintf( fftfp, "before fft\n" ); for( k=0; k<n20or4or2; k++ ) { fprintf( fftfp, "%c\n", amino[k] ); for( l=0; l<nlen; l++ ) fprintf( fftfp, "%f %f\n", seqVector2[k][l].R, seqVector2[k][l].I ); } fclose( fftfp ); system( "less seqVec2 < /dev/tty > /dev/tty" ); #endif for( j=0; j<n20or4or2; j++ ) { fft( nlen, seqVector2[j], (j==0) ); fft( nlen, seqVector1[j], 0 ); } #if 0 fftfp = fopen( "seqVec2", "w" ); fprintf( fftfp, "#after fft\n" ); for( k=0; k<n20or4or2; k++ ) { fprintf( fftfp, "#%c\n", amino[k] ); for( l=0; l<nlen; l++ ) fprintf( fftfp, "%f %f\n", seqVector2[k][l].R, seqVector2[k][l].I ); } fclose( fftfp ); system( "less seqVec2 < /dev/tty > /dev/tty" ); #endif for( k=0; k<n20or4or2; k++ ) { for( l=0; l<nlen; l++ ) calcNaiseki( naiseki[k]+l, seqVector1[k]+l, seqVector2[k]+l ); } for( l=0; l<nlen; l++ ) { naisekiNoWa[l].R = 0.0; naisekiNoWa[l].I = 0.0; for( k=0; k<n20or4or2; k++ ) { naisekiNoWa[l].R += naiseki[k][l].R; naisekiNoWa[l].I += naiseki[k][l].I; } } #if 0 fftfp = fopen( "naisekiNoWa", "w" ); fprintf( fftfp, "#Before fft\n" ); for( l=0; l<nlen; l++ ) fprintf( fftfp, "%d %f %f\n", l, naisekiNoWa[l].R, naisekiNoWa[l].I ); fclose( fftfp ); system( "less naisekiNoWa < /dev/tty > /dev/tty " ); #endif fft( -nlen, naisekiNoWa, 0 ); for( m=0; m<=nlen2; m++ ) soukan[m] = naisekiNoWa[nlen2-m].R; for( m=nlen2+1; m<nlen; m++ ) soukan[m] = naisekiNoWa[nlen+nlen2-m].R; #if 0 fftfp = fopen( "naisekiNoWa", "w" ); fprintf( fftfp, "#After fft\n" ); for( l=0; l<nlen; l++ ) fprintf( fftfp, "%d %f\n", l, naisekiNoWa[l].R ); fclose( fftfp ); fftfp = fopen( "list.plot", "w" ); fprintf( fftfp, "plot 'naisekiNoWa'\npause -1" ); fclose( fftfp ); system( "/usr/bin/gnuplot list.plot &" ); #endif #if 0 fprintf( stderr, "frt write start\n" ); fftfp = fopen( "frt", "w" ); for( l=0; l<nlen; l++ ) fprintf( fftfp, "%d %f\n", l-nlen2, soukan[l] ); fclose( fftfp ); system( "less frt < /dev/tty > /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; i<NKOUHO; i++ ) { fprintf( stderr, "kouho[%d] = %d\n", i, kouho[i] ); } #endif } #if KEIKA fprintf( stderr, "Searching anchors ... " ); #endif count = 0; #define CAND 0 #if CAND fftfp = fopen( "cand", "w" ); fclose( fftfp ); #endif if( kobetsubunkatsu ) { maxk = 1; kouho[0] = 0; } else { maxk = NKOUHO; } for( k=0; k<maxk; k++ ) { lag = kouho[k]; zurasu2( lag, clus1, clus2, seq1, seq2, tmpptr1, tmpptr2 ); #if CAND fftfp = fopen( "cand", "a" ); fprintf( fftfp, "Candidate No.%d lag = %d\n", k+1, lag ); fprintf( fftfp, "%s\n", tmpptr1[0] ); fprintf( fftfp, "%s\n", tmpptr2[0] ); fclose( fftfp ); #endif tmpint = alignableReagion( clus1, clus2, tmpptr1, tmpptr2, eff1, eff2, segment+count ); if( count+tmpint > MAXSEG -3 ) ErrorExit( "TOO MANY SEGMENTS.\n" ); 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 fftfp = fopen( "cand", "a" ); fprintf( fftfp, "Goukaku=%dko\n", tmpint ); fprintf( fftfp, "in 1 %d\n", segment1[count].center ); fprintf( fftfp, "in 2 %d\n", segment2[count].center ); fclose( fftfp ); #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, "%d segments found\n", count ); #endif if( !count && fftNoAnchStop ) ErrorExit( "Cannot detect anchor!" ); #if 0 fftfp = fopen( "fft", "a" ); fprintf( fftfp, "RESULT before sort:\n" ); for( l=0; l<count; l++ ) { fprintf( fftfp, "cut[%d]=%d, ", l, segment1[l].center ); fprintf( fftfp, "%d score = %f\n", segment2[l].center, segment1[l].score ); } fclose( fftfp ); #endif #if KEIKA fprintf( stderr, "Aligning anchors ... " ); #endif for( i=0; i<count; i++ ) { sortedseg1[i] = &segment1[i]; sortedseg2[i] = &segment2[i]; } #if 0 tmpsort( count, sortedseg1 ); tmpsort( count, sortedseg2 ); qsort( sortedseg1, count, sizeof( Segment * ), segcmp ); qsort( sortedseg2, count, sizeof( Segment * ), segcmp ); #else mymergesort( 0, count-1, sortedseg1 ); mymergesort( 0, count-1, sortedseg2 ); #endif for( i=0; i<count; i++ ) sortedseg1[i]->number = i; for( i=0; i<count; i++ ) sortedseg2[i]->number = i; if( kobetsubunkatsu ) { for( i=0; i<count; i++ ) { cut1[i+1] = sortedseg1[i]->center; 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 fprintf( stderr, "######allocating crossscore, size = %d\n", crossscoresize ); #endif if( crossscore ) FreeDoubleMtx( crossscore ); crossscore = AllocateDoubleMtx( crossscoresize, crossscoresize ); } for( i=0; i<count+2; i++ ) for( j=0; j<count+2; j++ ) crossscore[i][j] = 0.0; for( i=0; i<count; i++ ) { crossscore[segment1[i].number+1][segment1[i].pair->number+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; i++ ) fprintf( stderr, "%d, %d\n", segment1[i].start, segment2[i].start ); #endif crossscore[0][0] = 10000000.0; cut1[0] = 0; cut2[0] = 0; crossscore[count+1][count+1] = 10000000.0; cut1[count+1] = len1; cut2[count+1] = len2; count += 2; count0 = count; blockAlign2( cut1, cut2, sortedseg1, sortedseg2, crossscore, &count ); if( count0 > 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<count; l++ ) { fprintf( fftfp, "cut[%d]=%d, ", l, segment1[l].center ); fprintf( fftfp, "%d\n", segment2[l].center ); } fclose( fftfp ); #endif #if 0 fftfp = fopen( "fft", "a" ); fprintf( fftfp, "RESULT after sort:\n" ); for( l=0; l<count; l++ ) { fprintf( fftfp, "cut : %d %d\n", cut1[l], cut2[l] ); } fclose( fftfp ); #endif #if KEIKA fprintf( trap_g, "Devided to %d segments\n", count-1 ); fprintf( trap_g, "%d %d forg\n", MIN( clus1, clus2 ), count-1 ); #endif totallen = 0; for( j=0; j<clus1; j++ ) result1[j][0] = 0; for( j=0; j<clus2; j++ ) result2[j][0] = 0; totalscore = 0.0; *totalimpmatch = 0.0; for( i=0; i<count-1; i++ ) { #if DEBUG fprintf( stderr, "DP %03d / %03d %4d to ", i+1, count-1, totallen ); #else #if KEIKA fprintf( stderr, "DP %03d / %03d\r", i+1, count-1 ); #endif #endif if( cut1[i] ) { getkyokaigap( sgap1, seq1, cut1[i]-1, clus1 ); getkyokaigap( sgap2, seq2, cut2[i]-1, clus2 ); } else { for( j=0; j<clus1; j++ ) sgap1[j] = 'o'; for( j=0; j<clus2; j++ ) sgap2[j] = 'o'; } if( cut1[i+1] != len1 ) { getkyokaigap( egap1, seq1, cut1[i+1], clus1 ); getkyokaigap( egap2, seq2, cut2[i+1], clus2 ); } else { for( j=0; j<clus1; j++ ) egap1[j] = 'o'; for( j=0; j<clus2; j++ ) egap2[j] = 'o'; } for( j=0; j<clus1; j++ ) { strncpy( tmpres1[j], seq1[j]+cut1[i], cut1[i+1]-cut1[i] ); tmpres1[j][cut1[i+1]-cut1[i]] = 0; } if( kobetsubunkatsu ) commongappick_record( clus1, tmpres1, gapmap1 ); for( j=0; j<clus2; j++ ) { strncpy( tmpres2[j], seq2[j]+cut2[i], cut2[i+1]-cut2[i] ); tmpres2[j][cut2[i+1]-cut2[i]] = 0; } if( kobetsubunkatsu ) commongappick_record( clus2, tmpres2, gapmap2 ); #if 0 fprintf( stderr, "count = %d\n", count ); fprintf( stderr, "### reg1 = %d-%d\n", cut1[i], cut1[i+1]-1 ); fprintf( stderr, "### reg2 = %d-%d\n", cut2[i], cut2[i+1]-1 ); #endif switch( alg ) { case( 'a' ): totalscore += Aalign( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen ); break; case( 'Q' ): totalscore += partQ__align( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, localhom, &impmatch, cut1[i], cut1[i+1]-1, cut2[i], cut2[i+1]-1, gapmap1, gapmap2, sgap1, sgap2, egap1, egap2 ); *totalimpmatch += impmatch; // fprintf( stderr, "*totalimpmatch in Falign_localhom = %f\n", *totalimpmatch ); break; case( 'A' ): totalscore += partA__align( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, localhom, &impmatch, cut1[i], cut1[i+1]-1, cut2[i], cut2[i+1]-1, gapmap1, gapmap2, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres ); *totalimpmatch += impmatch; // fprintf( stderr, "*totalimpmatch in Falign_localhom = %f\n", *totalimpmatch ); 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<clus1; j++ ) strcat( result1[j], tmpres1[j] ); for( j=0; j<clus2; j++ ) strcat( result2[j], tmpres2[j] ); totallen += nlen; #if 0 fprintf( stderr, "%4d\r", totallen ); fprintf( stderr, "\n\n" ); for( j=0; j<clus1; j++ ) { fprintf( stderr, "%s\n", tmpres1[j] ); } fprintf( stderr, "-------\n" ); for( j=0; j<clus2; j++ ) { fprintf( stderr, "%s\n", tmpres2[j] ); } #endif } #if KEIKA fprintf( stderr, "DP ... done \n" ); #endif for( j=0; j<clus1; j++ ) strcpy( seq1[j], result1[j] ); for( j=0; j<clus2; j++ ) strcpy( seq2[j], result2[j] ); #if 0 for( j=0; j<clus1; j++ ) { fprintf( stderr, "%s\n", result1[j] ); } fprintf( stderr, "- - - - - - - - - - -\n" ); for( j=0; j<clus2; j++ ) { fprintf( stderr, "%s\n", result2[j] ); } #endif return( totalscore ); }