int main( int ac, char **av ) { int *nlen; static char **name, **seq; double score; extern double score_calc_for_score( int, char ** ); arguments( ac, av ); getnumlen( stdin ); rewind( stdin ); nlen = AllocateIntVec( njob ); name = AllocateCharMtx( njob, B+1 ); seq = AllocateCharMtx( njob, nlenmax+2 ); readData_pointer( stdin, name, nlen, seq ); if( !isaligned( njob, seq ) ) ErrorExit( "Not aligned." ); constants( njob, seq ); score = score_calc_for_score( njob, seq ); if( scoremtx == 0 ) score += offset; fprintf( stdout, "score = %f\n", score ); if ( scoremtx == 0 ) fprintf( stdout, "JTT %dPAM\n", pamN ); else if( scoremtx == 1 ) fprintf( stdout, "Dayhoff( machigai ga aru )\n" ); else if( scoremtx == 2 ) fprintf( stdout, "M-Y\n" ); else if( scoremtx == -1 ) fprintf( stdout, "DNA 1:%d\n", kimuraR ); fprintf( stdout, "gap penalty = %+6.2f, %+6.2f, %+6.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 ); exit( 0 ); }
int main( int argc, char *argv[] ) { static char com[10000]; static int *nlen; int left, right; int res; static char **name, **seq, **nogap; static int **gapmap; static int *order; int i, j; FILE *infp; RNApair ***pairprob; RNApair **alnpairprob; RNApair *pairprobpt; RNApair *pt; int *alnpairnum; float prob; int adpos; 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( !whereismccaskillmea ) whereismccaskillmea = ""; getnumlen( infp ); rewind( infp ); if( dorp != 'd' ) { fprintf( stderr, "nuc only\n" ); exit( 1 ); } seq = AllocateCharMtx( njob, nlenmax*2+1 ); nogap = AllocateCharMtx( njob, nlenmax*2+1 ); gapmap = AllocateIntMtx( njob, nlenmax*2+1 ); order = AllocateIntVec( njob ); name = AllocateCharMtx( njob, B+1 ); nlen = AllocateIntVec( njob ); pairprob = (RNApair ***)calloc( njob, sizeof( RNApair ** ) ); alnpairprob = (RNApair **)calloc( nlenmax, sizeof( RNApair * ) ); alnpairnum = AllocateIntVec( nlenmax ); for( i=0; i<nlenmax; i++ ) alnpairnum[i] = 0; readData_pointer( infp, name, nlen, seq ); fclose( infp ); for( i=0; i<njob; i++ ) { pairprob[i] = (RNApair **)calloc( nlenmax, sizeof( RNApair * ) ); for( j=0; j<nlenmax; j++ ) { pairprob[i][j] = (RNApair *)calloc( 1, sizeof( RNApair ) ); pairprob[i][j][0].bestpos = -1; pairprob[i][j][0].bestscore = -1.0; } strcpy( nogap[i], seq[i] ); order[i] = i; } for( j=0; j<nlenmax; j++ ) { alnpairprob[j] = (RNApair *)calloc( 1, sizeof( RNApair ) ); alnpairprob[j][0].bestpos = -1; alnpairprob[j][0].bestscore = -1.0; } constants( njob, seq ); if( alg == 'G' ) fprintf( stderr, "Running DAFS (Sato et al. 2012; http://www.ncrna.org/).\n" ); else fprintf( stderr, "Running mxscarna with the mccaskill_mea mode.\n" ); #ifdef enablemultithread if( nthread > 0 ) { int jobpos; pthread_t *handle; pthread_mutex_t mutex; thread_arg_t *targ; jobpos = 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].jobpospt = &jobpos; targ[i].gapmap = gapmap; targ[i].nogap = nogap; targ[i].nlenmax = nlenmax; targ[i].pairprob = pairprob; targ[i].mutex = &mutex; // athread( targ ); pthread_create( handle+i, NULL, athread, (void *)(targ+i) ); } for( i=0; i<nthread; i++ ) { pthread_join( handle[i], NULL ); } pthread_mutex_destroy( &mutex ); for( i=0; i<njob; i++ ) { fprintf( stdout, ">%d\n", i ); outmccaskill( stdout, pairprob[i], nlenmax ); } } else #endif { for( i=0; i<njob; i++ ) { fprintf( stderr, "%d / %d\n", i+1, njob ); commongappick_record( 1, nogap+i, gapmap[i] ); infp = fopen( "_mccaskillinorg", "w" ); // fprintf( infp, ">in\n%s\n", nogap[i] ); fprintf( infp, ">in\n" ); write1seq( infp, nogap[i] ); fclose( infp ); system( "tr -d '\\r' < _mccaskillinorg > _mccaskillin" ); // for cygwin, wakaran if( alg == 'G' ) sprintf( com, "env PATH=%s dafs --mafft-out _mccaskillout _mccaskillin > _dum1 2>_dum", whereismccaskillmea ); else sprintf( com, "env PATH=%s mxscarnamod -m -writebpp _mccaskillin > _mccaskillout 2>_dum", whereismccaskillmea ); res = system( com ); if( res ) { fprintf( stderr, "ERROR IN mccaskill_mea\n" ); exit( 1 ); } infp = fopen( "_mccaskillout", "r" ); readrawmccaskill( infp, pairprob[i], nlenmax ); fclose( infp ); fprintf( stdout, ">%d\n", i ); outmccaskill( stdout, pairprob[i], nlenmax ); } } for( i=0; i<njob; i++ ) { for( j=0; j<nlen[i]; j++ ) for( pairprobpt=pairprob[i][j]; pairprobpt->bestpos!=-1; pairprobpt++ ) { left = gapmap[i][j]; right = gapmap[i][pairprobpt->bestpos]; prob = pairprobpt->bestscore; for( pt=alnpairprob[left]; pt->bestpos!=-1; pt++ ) if( pt->bestpos == right ) break; if( pt->bestpos == -1 ) { alnpairprob[left] = (RNApair *)realloc( alnpairprob[left], (alnpairnum[left]+2) * sizeof( RNApair ) ); adpos = alnpairnum[left]; alnpairnum[left]++; alnpairprob[left][adpos].bestscore = 0.0; alnpairprob[left][adpos].bestpos = right; alnpairprob[left][adpos+1].bestscore = -1.0; alnpairprob[left][adpos+1].bestpos = -1; pt = alnpairprob[left]+adpos; } else adpos = pt-alnpairprob[left]; pt->bestscore += prob; if( pt->bestpos != right ) { fprintf( stderr, "okashii!\n" ); exit( 1 ); } // fprintf( stderr, "adding %d-%d, %f\n", left, right, prob ); } } for( i=0; i<njob; i++ ) { for( j=0; j<nlenmax; j++ ) free( pairprob[i][j] ); free( pairprob[i] ); } free( pairprob ); for( j=0; j<nlenmax; j++ ) free( alnpairprob[j] ); free( alnpairprob ); free( alnpairnum ); fprintf( stderr, "%d thread(s)\n", nthread ); return( 0 ); #if 0 fprintf( stdout, "result=\n" ); for( i=0; i<nlenmax; i++ ) for( pairprobpt=alnpairprob[i]; pairprobpt->bestpos!=-1; pairprobpt++ ) { pairprobpt->bestscore /= (float)njob; left = i; right = pairprobpt->bestpos; prob = pairprobpt->bestscore; fprintf( stdout, "%d-%d, %f\n", left, right, prob ); } return( 0 ); #endif }
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; 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[] ) { static int nlen[M]; static char **name, **seq; static char **bseq; static double *eff; int i; char c; int alloclen; FILE *infp; arguments( argc, argv ); if( inputfile ) { infp = fopen( inputfile, "r" ); if( !infp ) { fprintf( stderr, "Cannot open %s\n", inputfile ); exit( 1 ); } } else infp = stdin; if( !pairfile ) { fprintf( stderr, "Usage: %s -p pairfile -i inputfile \n", argv[0] ); exit( 1 ); } getnumlen( infp ); rewind( infp ); 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 ); bseq = AllocateCharMtx( njob, nlenmax*9+1 ); alloclen = nlenmax*9; eff = AllocateDoubleVec( njob ); #if 0 Read( name, nlen, seq ); #else readData_pointer( infp, name, nlen, seq ); #endif fclose( infp ); 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 ); for( i=0; i<njob; i++ ) eff[i] = 1.0; for( i=0; i<njob; i++ ) gappick0( bseq[i], seq[i] ); pairalign( name, nlen, bseq, eff, alloclen ); fprintf( trap_g, "done.\n" ); #if DEBUG fprintf( stderr, "closing trap_g\n" ); #endif fclose( trap_g ); #if IODEBUG fprintf( stderr, "OSHIMAI\n" ); #endif SHOWVERSION; return( 0 ); }
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 ); }