#include "mltaln.h" #include "dp.h" #define MEMSAVE 1 #define DEBUG 1 #define USE_PENALTY_EX 1 #define STOREWM 1 static float singleribosumscore( int n1, int n2, char **s1, char **s2, double *eff1, double *eff2, int p1, int p2 ) { float val; int i, j; int code1, code2; val = 0.0; for( i=0; i 3 ) code1 = 36; code2 = amino_n[(int)s2[j][p2]]; if( code2 > 3 ) code2 = 36; // fprintf( stderr, "'l'%c-%c: %f\n", s1[i][p1], s2[j][p2], (float)ribosumdis[code1][code2] ); val += (float)ribosumdis[code1][code2] * eff1[i] * eff2[j]; } return( val ); } static float pairedribosumscore53( int n1, int n2, char **s1, char **s2, double *eff1, double *eff2, int p1, int p2, int c1, int c2 ) { float val; int i, j; int code1o, code1u, code2o, code2u, code1, code2; val = 0.0; for( i=0; i 3 ) code1 = code1o = 36; else if( code1u > 3 ) code1 = 36; else code1 = 4 + code1o * 4 + code1u; code2o = amino_n[(int)s2[j][p2]]; code2u = amino_n[(int)s2[j][c2]]; if( code2o > 3 ) code2 = code1o = 36; else if( code2u > 3 ) code2 = 36; else code2 = 4 + code2o * 4 + code2u; // fprintf( stderr, "%c%c-%c%c: %f\n", s1[i][p1], s1[i][c1], s2[j][p2], s2[j][c2], (float)ribosumdis[code1][code2] ); if( code1 == 36 || code2 == 36 ) val += (float)n_dis[code1o][code2o] * eff1[i] * eff2[j]; else val += (float)ribosumdis[code1][code2] * eff1[i] * eff2[j]; } return( val ); } static float pairedribosumscore35( int n1, int n2, char **s1, char **s2, double *eff1, double *eff2, int p1, int p2, int c1, int c2 ) { float val; int i, j; int code1o, code1u, code2o, code2u, code1, code2; val = 0.0; for( i=0; i 3 ) code1 = code1o = 36; else if( code1u > 3 ) code1 = 36; else code1 = 4 + code1u * 4 + code1o; code2o = amino_n[(int)s2[j][p2]]; code2u = amino_n[(int)s2[j][c2]]; if( code2o > 3 ) code2 = code1o = 36; else if( code2u > 3 ) code2 = 36; else code2 = 4 + code2u * 4 + code2o; // fprintf( stderr, "%c%c-%c%c: %f\n", s1[i][p1], s1[i][c1], s2[j][p2], s2[j][c2], (float)ribosumdis[code1][code2] ); if( code1 == 36 || code2 == 36 ) val += (float)n_dis[code1o][code2o] * eff1[i] * eff2[j]; else val += (float)ribosumdis[code1][code2] * eff1[i] * eff2[j]; } return( val ); } static void mccaskillextract( char **seq, char **nogap, int nseq, RNApair **pairprob, RNApair ***single, int **sgapmap, double *eff ) { int lgth; int nogaplgth; int i, j; int left, right, adpos; float prob; static TLS int *pairnum; RNApair *pt, *pt2; lgth = strlen( seq[0] ); pairnum = calloc( lgth, sizeof( int ) ); for( i=0; ibestpos!=-1; pt++ ) { left = sgapmap[i][j]; right = sgapmap[i][pt->bestpos]; prob = pt->bestscore; for( pt2=pairprob[left]; pt2->bestpos!=-1; pt2++ ) if( pt2->bestpos == right ) break; // fprintf( stderr, "i,j=%d,%d, left=%d, right=%d, pt=%d, pt2->bestpos = %d\n", i, j, left, right, pt-single[i][j], pt2->bestpos ); if( pt2->bestpos == -1 ) { pairprob[left] = (RNApair *)realloc( pairprob[left], (pairnum[left]+2) * sizeof( RNApair ) ); adpos = pairnum[left]; pairnum[left]++; pairprob[left][adpos].bestscore = 0.0; pairprob[left][adpos].bestpos = right; pairprob[left][adpos+1].bestscore = -1.0; pairprob[left][adpos+1].bestpos = -1; pt2 = pairprob[left]+adpos; } else adpos = pt2-pairprob[left]; pt2->bestscore += prob * eff[i]; if( pt2->bestpos != right ) { fprintf( stderr, "okashii!\n" ); exit( 1 ); } // fprintf( stderr, "adding %d-%d, %f\n", left, right, prob ); // fprintf( stderr, "pairprob[0][0].bestpos=%d\n", pairprob[0][0].bestpos ); // fprintf( stderr, "pairprob[0][0].bestscore=%f\n", pairprob[0][0].bestscore ); } } // fprintf( stderr, "before taikakuka\n" ); for( i=0; i -1 ) { // pairprob[i][j].bestscore /= (float)nseq; // fprintf( stderr, "pair of %d = %d (%f) %c:%c\n", i, pairprob[i][j].bestpos, pairprob[i][j].bestscore, seq[0][i], seq[0][pairprob[i][j].bestpos] ); } } #if 0 for( i=0; i %d\n", i, j, right, i ); pairprob[right] = (RNApair *)realloc( pairprob[right], (pairnum[right]+2) * sizeof( RNApair ) ); pairprob[right][pairnum[right]].bestscore = pairprob[i][j].bestscore; pairprob[right][pairnum[right]].bestpos = i; pairnum[right]++; pairprob[right][pairnum[right]].bestscore = -1.0; pairprob[right][pairnum[right]].bestpos = -1; } #endif free( pairnum ); } void rnaalifoldcall( char **seq, int nseq, RNApair **pairprob ) { int lgth; int i; static TLS int *order = NULL; static TLS char **name = NULL; char gett[1000]; FILE *fp; int left, right, dumm; float prob; static TLS int pid; static TLS char fnamein[100]; static TLS char cmd[1000]; static TLS int *pairnum; lgth = strlen( seq[0] ); if( order == NULL ) { pid = (int)getpid(); sprintf( fnamein, "/tmp/_rnaalifoldin.%d", pid ); order = AllocateIntVec( njob ); name = AllocateCharMtx( njob, 10 ); for( i=0; i 50.0 && prob > pairprob[left][0].bestscore ) { pairprob[left][0].bestscore = prob; pairprob[left][0].bestpos = right; #else if( prob > 0.0 ) { pairprob[left] = (RNApair *)realloc( pairprob[left], (pairnum[left]+2) * sizeof( RNApair ) ); pairprob[left][pairnum[left]].bestscore = prob / 100.0; pairprob[left][pairnum[left]].bestpos = right; pairnum[left]++; pairprob[left][pairnum[left]].bestscore = -1.0; pairprob[left][pairnum[left]].bestpos = -1; fprintf( stderr, "%d-%d, %f\n", left, right, prob ); pairprob[right] = (RNApair *)realloc( pairprob[right], (pairnum[right]+2) * sizeof( RNApair ) ); pairprob[right][pairnum[right]].bestscore = prob / 100.0; pairprob[right][pairnum[right]].bestpos = left; pairnum[right]++; pairprob[right][pairnum[right]].bestscore = -1.0; pairprob[right][pairnum[right]].bestpos = -1; fprintf( stderr, "%d-%d, %f\n", left, right, prob ); #endif } } fclose( fp ); sprintf( cmd, "rm -f %s", fnamein ); system( cmd ); for( i=0; i -1 ) { pairprob[right][0].bestpos = i; pairprob[right][0].bestscore = pairprob[i][0].bestscore; } } #if 0 for( i=0; i -1 ) pairprob[i][0].bestscore = 1.0; // atode kesu #endif // fprintf( stderr, "after taikakuka in rnaalifoldcall\n" ); // for( i=0; iori\n%s\n", oseq1[0] ); fprintf( stdout, ">rev\n%s\n", oseq1r[0] ); } #endif /* similarity score */ Lalignmm_hmout( oseq1, oseq2, eff1, eff2, nseq1, nseq2, 10000, NULL, NULL, NULL, NULL, map ); if( 1 ) { if( RNAscoremtx == 'n' ) { for( i=0; ibestpos!=-1; pairpt1++ ) { for( j=0; jbestpos!=-1; pairpt2++ ) { uido = pairpt1->bestpos; ujdo = pairpt2->bestpos; prob = pairpt1->bestscore * pairpt2->bestscore; if( uido > -1 && ujdo > -1 ) { if( uido > i && j > ujdo ) { impmtx2[i][j] += prob * pairedribosumscore53( nseq1, nseq2, oseq1, oseq2, eff1, eff2, i, j, uido, ujdo ) * consweight_multi; tbppmtx[i][j] -= prob; } else if( i < uido && j < ujdo ) { impmtx2[i][j] += prob * pairedribosumscore35( nseq1, nseq2, oseq1, oseq2, eff1, eff2, i, j, uido, ujdo ) * consweight_multi; tbppmtx[i][j] -= prob; } } } } for( i=0; ibestpos!=-1; pairpt1++ ) { // if( pairprob1[i] == NULL ) continue; for( j=0; jbestpos!=-1; pairpt2++ ) { // fprintf( stderr, "i=%d, j=%d, pn1=%d, pn2=%d\n", i, j, pairpt1-pairprob1[i], pairpt2-pairprob2[j] ); // if( pairprob2[j] == NULL ) continue; uido = pairpt1->bestpos; ujdo = pairpt2->bestpos; prob = pairpt1->bestscore * pairpt2->bestscore; // prob = 1.0; // fprintf( stderr, "i=%d->uido=%d, j=%d->ujdo=%d\n", i, uido, j, ujdo ); // fprintf( stderr, "impmtx2[%d][%d] = %f\n", i, j, impmtx2[i][j] ); // if( i < uido && j > ujdo ) continue; // if( i > uido && j < ujdo ) continue; // posdistj = abs( ujdo-j ); // if( uido > -1 && ujdo > -1 ) if( uido > -1 && ujdo > -1 && ( ( i > uido && j > ujdo ) || ( i < uido && j < ujdo ) ) ) { { impmtx2[i][j] += MAX( 0, map[uido][ujdo] ) * consweight_rna * 600 * prob; // osoi } } } } for( i=0; i