X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=binaries%2Fsrc%2Fmafft%2Fcore%2Ftbfast.c;fp=binaries%2Fsrc%2Fmafft%2Fcore%2Ftbfast.c;h=6acce2877ecc5c22c97d6d8eacec4ee5bfdbe755;hb=063b30bb5e8161134ae764742636ab538e10eea7;hp=0000000000000000000000000000000000000000;hpb=6e0ce943f09b5ac30f3eb8dc0f20bc75114669ce;p=jabaws.git diff --git a/binaries/src/mafft/core/tbfast.c b/binaries/src/mafft/core/tbfast.c new file mode 100644 index 0000000..6acce28 --- /dev/null +++ b/binaries/src/mafft/core/tbfast.c @@ -0,0 +1,1880 @@ +#include "mltaln.h" + +#define DEBUG 0 +#define IODEBUG 0 +#define SCOREOUT 0 + +static int nadd; +static int treein; +static int topin; +static int treeout; +static int distout; +static int noalign; + +typedef struct _jobtable +{ + int i; + int j; +} Jobtable; + +#ifdef enablemultithread +typedef struct _distancematrixthread_arg +{ + int njob; + int thread_no; + float *selfscore; + float **iscore; + char **seq; + Jobtable *jobpospt; + pthread_mutex_t *mutex; +} distancematrixthread_arg_t; + +typedef struct _treebasethread_arg +{ + int thread_no; + int *nrunpt; + int njob; + int *nlen; + int *jobpospt; + int ***topol; + Treedep *dep; + char **aseq; + double *effarr; + int *alloclenpt; + LocalHom **localhomtable; + RNApair ***singlerna; + double *effarr_kozo; + int *fftlog; + pthread_mutex_t *mutex; + pthread_cond_t *treecond; +} treebasethread_arg_t; +#endif + +void arguments( int argc, char *argv[] ) +{ + int c; + + nthread = 1; + outnumber = 0; + scoreout = 0; + treein = 0; + topin = 0; + rnaprediction = 'm'; + rnakozo = 0; + nevermemsave = 0; + inputfile = NULL; + addfile = NULL; + addprofile = 1; + fftkeika = 0; + constraint = 0; + nblosum = 62; + fmodel = 0; + calledByXced = 0; + devide = 0; + use_fft = 0; // chuui + force_fft = 0; + fftscore = 1; + fftRepeatStop = 0; + fftNoAnchStop = 0; + weight = 3; + utree = 1; + tbutree = 1; + refine = 0; + check = 1; + cut = 0.0; + disp = 0; + outgap = 1; + alg = 'A'; + mix = 0; + tbitr = 0; + scmtd = 5; + tbweight = 0; + tbrweight = 3; + checkC = 0; + treemethod = 'X'; + contin = 0; + scoremtx = 1; + kobetsubunkatsu = 0; + dorp = NOTSPECIFIED; + ppenalty = NOTSPECIFIED; + ppenalty_ex = NOTSPECIFIED; + poffset = NOTSPECIFIED; + kimuraR = NOTSPECIFIED; + pamN = NOTSPECIFIED; + geta2 = GETA2; + fftWinSize = NOTSPECIFIED; + fftThreshold = NOTSPECIFIED; + RNAppenalty = NOTSPECIFIED; + RNAppenalty_ex = NOTSPECIFIED; + RNApthr = NOTSPECIFIED; + TMorJTT = JTT; + consweight_multi = 1.0; + consweight_rna = 0.0; + + while( --argc > 0 && (*++argv)[0] == '-' ) + { + while ( ( c = *++argv[0] ) ) + { + switch( c ) + { + case 'i': + inputfile = *++argv; + fprintf( stderr, "inputfile = %s\n", inputfile ); + --argc; + goto nextoption; + case 'I': + nadd = atoi( *++argv ); + fprintf( stderr, "nadd = %d\n", nadd ); + --argc; + goto nextoption; + case 'e': + RNApthr = (int)( atof( *++argv ) * 1000 - 0.5 ); + --argc; + goto nextoption; + case 'o': + RNAppenalty = (int)( atof( *++argv ) * 1000 - 0.5 ); + --argc; + goto nextoption; + case 'f': + ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 ); +// fprintf( stderr, "ppenalty = %d\n", ppenalty ); + --argc; + goto nextoption; + case 'g': + ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 ); + fprintf( stderr, "ppenalty_ex = %d\n", ppenalty_ex ); + --argc; + goto nextoption; + case 'h': + poffset = (int)( atof( *++argv ) * 1000 - 0.5 ); +// fprintf( stderr, "poffset = %d\n", poffset ); + --argc; + goto nextoption; + case 'k': + kimuraR = atoi( *++argv ); + fprintf( stderr, "kappa = %d\n", kimuraR ); + --argc; + goto nextoption; + case 'b': + nblosum = atoi( *++argv ); + scoremtx = 1; + fprintf( stderr, "blosum %d / kimura 200\n", nblosum ); + --argc; + goto nextoption; + case 'j': + pamN = atoi( *++argv ); + scoremtx = 0; + TMorJTT = JTT; + fprintf( stderr, "jtt/kimura %d\n", pamN ); + --argc; + goto nextoption; + case 'm': + pamN = atoi( *++argv ); + scoremtx = 0; + TMorJTT = TM; + fprintf( stderr, "tm %d\n", pamN ); + --argc; + goto nextoption; + case 'l': + fastathreshold = atof( *++argv ); + constraint = 2; + --argc; + goto nextoption; + case 'r': + consweight_rna = atof( *++argv ); + rnakozo = 1; + --argc; + goto nextoption; + case 'c': + consweight_multi = atof( *++argv ); + --argc; + goto nextoption; + case 'C': + nthread = atoi( *++argv ); + fprintf( stderr, "nthread = %d\n", nthread ); + --argc; + goto nextoption; + case 'R': + rnaprediction = 'r'; + break; + case 's': + RNAscoremtx = 'r'; + break; +#if 1 + case 'a': + fmodel = 1; + break; +#endif + case 'K': + addprofile = 0; + break; + case 'y': + distout = 1; + break; + case 't': + treeout = 1; + break; + case 'T': + noalign = 1; + break; + case 'D': + dorp = 'd'; + break; + case 'P': + dorp = 'p'; + break; +#if 1 + case 'O': + outgap = 0; + break; +#else + case 'O': + fftNoAnchStop = 1; + break; +#endif + case 'S': + scoreout = 1; + break; +#if 0 + case 'e': + fftscore = 0; + break; + case 'r': + fmodel = -1; + break; + case 'R': + fftRepeatStop = 1; + break; + case 's': + treemethod = 's'; + break; +#endif + case 'X': + treemethod = 'X'; + break; + case 'E': + treemethod = 'E'; + break; + case 'q': + treemethod = 'q'; + break; + case 'n' : + outnumber = 1; + break; +#if 0 + case 'a': + alg = 'a'; + break; +#endif + case 'Q': + alg = 'Q'; + break; + case 'H': + alg = 'H'; + break; + case 'A': + alg = 'A'; + break; + case 'M': + alg = 'M'; + break; + case 'N': + nevermemsave = 1; + break; + case 'B': + break; + case 'F': + use_fft = 1; + break; + case 'G': + force_fft = 1; + use_fft = 1; + break; + case 'U': + treein = 1; + break; + case 'V': + topin = 1; + break; + case 'u': + tbrweight = 0; + weight = 0; + break; + case 'v': + tbrweight = 3; + break; + case 'd': + disp = 1; + break; +/* Modified 01/08/27, default: user tree */ + case 'J': + tbutree = 0; + break; +/* modification end. */ + case 'z': + fftThreshold = atoi( *++argv ); + --argc; + goto nextoption; + case 'w': + fftWinSize = atoi( *++argv ); + --argc; + goto nextoption; + case 'Z': + checkC = 1; + break; + default: + fprintf( stderr, "illegal option %c\n", c ); + argc = 0; + break; + } + } + nextoption: + ; + } + if( argc == 1 ) + { + cut = atof( (*argv) ); + argc--; + } + if( argc != 0 ) + { + fprintf( stderr, "options: Check source file !\n" ); + exit( 1 ); + } + if( tbitr == 1 && outgap == 0 ) + { + fprintf( stderr, "conflicting options : o, m or u\n" ); + exit( 1 ); + } + if( alg == 'C' && outgap == 0 ) + { + fprintf( stderr, "conflicting options : C, o\n" ); + exit( 1 ); + } +} + +#if 0 +static void *distancematrixthread2( void *arg ) +{ + distancematrixthread_arg_t *targ = (distancematrixthread_arg_t *)arg; + int njob = targ->njob; + int thread_no = targ->thread_no; + float *selfscore = targ->selfscore; + float **iscore = targ->iscore; + char **seq = targ->seq; + Jobtable *jobpospt = targ->jobpospt; + + float ssi, ssj, bunbo; + int i, j; + + while( 1 ) + { + pthread_mutex_lock( targ->mutex ); + i = jobpospt->i; + i++; + if( i == njob-1 ) + { + pthread_mutex_unlock( targ->mutex ); + return( NULL ); + } + jobpospt->i = i; + pthread_mutex_unlock( targ->mutex ); + + ssi = selfscore[i]; + if( i % 10 == 0 ) fprintf( stderr, "\r% 5d / %d (thread %4d)", i, njob, thread_no ); + for( j=i+1; jnjob; + int thread_no = targ->thread_no; + float *selfscore = targ->selfscore; + float **iscore = targ->iscore; + char **seq = targ->seq; + Jobtable *jobpospt = targ->jobpospt; + + float ssi, ssj, bunbo; + int i, j; + + while( 1 ) + { + pthread_mutex_lock( targ->mutex ); + j = jobpospt->j; + i = jobpospt->i; + j++; + if( j == njob ) + { + i++; + j = i + 1; + if( i == njob-1 ) + { + pthread_mutex_unlock( targ->mutex ); + return( NULL ); + } + } + jobpospt->j = j; + jobpospt->i = i; + pthread_mutex_unlock( targ->mutex ); + + + if( j==i+1 && i % 10 == 0 ) fprintf( stderr, "\r% 5d / %d (thread %4d)", i, njob, thread_no ); + ssi = selfscore[i]; + ssj = selfscore[j]; + bunbo = MIN( ssi, ssj ); + if( bunbo == 0.0 ) + iscore[i][j-i] = 1.0; + else + iscore[i][j-i] = 1.0 - naivepairscore11( seq[i], seq[j], penalty ) / bunbo; + } +} + +static void *treebasethread( void *arg ) +{ + treebasethread_arg_t *targ = (treebasethread_arg_t *)arg; + int *nrunpt = targ->nrunpt; + int thread_no = targ->thread_no; + int njob = targ->njob; + int *nlen = targ->nlen; + int *jobpospt = targ->jobpospt; + int ***topol = targ->topol; + Treedep *dep = targ->dep; + char **aseq = targ->aseq; + double *effarr = targ->effarr; + int *alloclen = targ->alloclenpt; + LocalHom **localhomtable = targ->localhomtable; + RNApair ***singlerna = targ->singlerna; + double *effarr_kozo = targ->effarr_kozo; + int *fftlog = targ->fftlog; + + char **mseq1, **mseq2; + char **localcopy; + int i, j, l; + int len1, len2; + int clus1, clus2; + float pscore; + char *indication1, *indication2; + double *effarr1 = NULL; + double *effarr2 = NULL; + double *effarr1_kozo = NULL; + double *effarr2_kozo = NULL; + LocalHom ***localhomshrink = NULL; + int m1, m2; + float dumfl = 0.0; + int ffttry; + RNApair ***grouprna1, ***grouprna2; + + + mseq1 = AllocateCharMtx( njob, 0 ); + mseq2 = AllocateCharMtx( njob, 0 ); + localcopy = calloc( njob, sizeof( char * ) ); + + if( rnakozo && rnaprediction == 'm' ) + { + grouprna1 = (RNApair ***)calloc( njob, sizeof( RNApair ** ) ); + grouprna2 = (RNApair ***)calloc( njob, sizeof( RNApair ** ) ); + } + else + { + grouprna1 = grouprna2 = NULL; + } + + effarr1 = AllocateDoubleVec( njob ); + effarr2 = AllocateDoubleVec( njob ); + indication1 = AllocateCharVec( 150 ); + indication2 = AllocateCharVec( 150 ); +#if 0 +#else + if( constraint ) + { + localhomshrink = (LocalHom ***)calloc( njob, sizeof( LocalHom ** ) ); + for( i=0; i main thread + if( constraint ) + calcimportance( njob, effarr, aseq, localhomtable ); +#endif + + +// writePre( njob, name, nlen, aseq, 0 ); + + +// for( l=0; lmutex ); + l = *jobpospt; + if( l == njob-1 ) + { + pthread_mutex_unlock( targ->mutex ); + if( commonIP ) FreeIntMtx( commonIP ); + commonIP = NULL; + Falign( NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, 0, NULL ); + A__align( NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0 ); + free( mseq1 ); + free( mseq2 ); + free( localcopy ); + free( effarr1 ); + free( effarr2 ); + free( effarr1_kozo ); + free( effarr2_kozo ); + free( indication1 ); + free( indication2 ); + if( constraint ) + { + for( i=0; itreecond, targ->mutex ); + } + if( dep[l].child1 != -1 ) + { + while( dep[dep[l].child1].done == 0 ) + pthread_cond_wait( targ->treecond, targ->mutex ); + } +// while( *nrunpt >= nthread ) +// pthread_cond_wait( targ->treecond, targ->mutex ); + (*nrunpt)++; + +// pthread_mutex_unlock( targ->mutex ); + + + m1 = topol[l][0][0]; + m2 = topol[l][1][0]; + +// pthread_mutex_lock( targ->mutex ); + + len1 = strlen( aseq[m1] ); + len2 = strlen( aseq[m2] ); + if( *alloclen <= len1 + len2 ) + { + fprintf( stderr, "\nReallocating (by thread %d) ..", thread_no ); + *alloclen = ( len1 + len2 ) + 1000; + ReallocateCharMtx( aseq, njob, *alloclen + 10 ); + fprintf( stderr, "done. *alloclen = %d\n", *alloclen ); + } + + for( i=0; (j=topol[l][0][i])!=-1; i++ ) + { + localcopy[j] = calloc( *alloclen, sizeof( char ) ); + strcpy( localcopy[j], aseq[j] ); + } + for( i=0; (j=topol[l][1][i])!=-1; i++ ) + { + localcopy[j] = calloc( *alloclen, sizeof( char ) ); + strcpy( localcopy[j], aseq[j] ); + } + + pthread_mutex_unlock( targ->mutex ); + + if( effarr_kozo ) + { + clus1 = fastconjuction_noname_kozo( topol[l][0], localcopy, mseq1, effarr1, effarr, effarr1_kozo, effarr_kozo, indication1 ); + clus2 = fastconjuction_noname_kozo( topol[l][1], localcopy, mseq2, effarr2, effarr, effarr2_kozo, effarr_kozo, indication2 ); + } + else + { + clus1 = fastconjuction_noname( topol[l][0], localcopy, mseq1, effarr1, effarr, indication1 ); + clus2 = fastconjuction_noname( topol[l][1], localcopy, mseq2, effarr2, effarr, indication2 ); + } + + + +#if 1 + fprintf( stderr, "\rSTEP % 5d /%d (thread %4d) ", l+1, njob-1, thread_no ); +#else + fprintf( stderr, "STEP %d /%d (thread %d) \n", l+1, njob-1, thread_no ); + fprintf( stderr, "group1 = %.66s", indication1 ); + if( strlen( indication1 ) > 66 ) fprintf( stderr, "..." ); + fprintf( stderr, ", child1 = %d\n", dep[l].child0 ); + fprintf( stderr, "group2 = %.66s", indication2 ); + if( strlen( indication2 ) > 66 ) fprintf( stderr, "..." ); + fprintf( stderr, ", child2 = %d\n", dep[l].child1 ); + + fprintf( stderr, "Group1's lengths = " ); + for( i=0; i 30000 || len2 > 30000 ) ) ) + { + fprintf( stderr, "\nlen1=%d, len2=%d, Switching to the memsave mode.\n", len1, len2 ); + alg = 'M'; + if( commonIP ) FreeIntMtx( commonIP ); + commonAlloc1 = 0; + commonAlloc2 = 0; + } + + +// if( fftlog[m1] && fftlog[m2] ) ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 ); + if( fftlog[m1] && fftlog[m2] ) ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 && clus1 < 1000 && clus2 < 1000 ); + else ffttry = 0; +// ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 && clus1 < 5000 && clus2 < 5000 ); // v6.708 +// fprintf( stderr, "f=%d, len1/fftlog[m1]=%f, clus1=%d, len2/fftlog[m2]=%f, clus2=%d\n", ffttry, (float)len1/fftlog[m1], clus1, (float)len2/fftlog[m2], clus2 ); +// fprintf( stderr, "f=%d, clus1=%d, fftlog[m1]=%d, clus2=%d, fftlog[m2]=%d\n", ffttry, clus1, fftlog[m1], clus2, fftlog[m2] ); + if( constraint == 2 ) + { + if( alg == 'M' ) + { + fprintf( stderr, "\n\nMemory saving mode is not supported.\n\n" ); + exit( 1 ); + } + fprintf( stderr, "c" ); + if( alg == 'A' ) + { + imp_match_init_strict( NULL, clus1, clus2, strlen( mseq1[0] ), strlen( mseq2[0] ), mseq1, mseq2, effarr1, effarr2, effarr1_kozo, effarr2_kozo, localhomshrink, 1 ); + if( rnakozo ) imp_rna( clus1, clus2, mseq1, mseq2, effarr1, effarr2, grouprna1, grouprna2, NULL, NULL, NULL ); + pscore = A__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, localhomshrink, &dumfl, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap ); + } + else if( alg == 'H' ) + { + imp_match_init_strictH( NULL, clus1, clus2, strlen( mseq1[0] ), strlen( mseq2[0] ), mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 ); + pscore = H__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, localhomshrink, &dumfl, NULL, NULL, NULL, NULL ); + } + else if( alg == 'Q' ) + { + imp_match_init_strictQ( NULL, clus1, clus2, strlen( mseq1[0] ), strlen( mseq2[0] ), mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 ); + if( rnakozo ) imp_rnaQ( clus1, clus2, mseq1, mseq2, effarr1, effarr2, grouprna1, grouprna2, NULL, NULL, NULL ); + pscore = Q__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, localhomshrink, &dumfl, NULL, NULL, NULL, NULL ); + } + else if( alg == 'R' ) + { + imp_match_init_strictR( NULL, clus1, clus2, strlen( mseq1[0] ), strlen( mseq2[0] ), mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 ); + pscore = R__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, localhomshrink, &dumfl, NULL, NULL, NULL, NULL ); + } + } + else if( force_fft || ( use_fft && ffttry ) ) + { + fprintf( stderr, "f" ); + if( alg == 'M' ) + { + fprintf( stderr, "m" ); + pscore = Falign_udpari_long( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, fftlog+m1 ); + } + else + pscore = Falign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, fftlog+m1, NULL, 0, NULL ); + } + else + { + fprintf( stderr, "d" ); + fftlog[m1] = 0; + switch( alg ) + { + case( 'a' ): + pscore = Aalign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen ); + break; + case( 'M' ): + fprintf( stderr, "m" ); + pscore = MSalignmm( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap ); + break; + case( 'A' ): + pscore = A__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap ); + break; + case( 'Q' ): + pscore = Q__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL ); + break; + case( 'R' ): + pscore = R__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL ); + break; + case( 'H' ): + pscore = H__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL ); + break; + default: + ErrorExit( "ERROR IN SOURCE FILE" ); + } + } + + nlen[m1] = 0.5 * ( nlen[m1] + nlen[m2] ); + +#if SCOREOUT + fprintf( stderr, "score = %10.2f\n", pscore ); +#endif + +/* + fprintf( stderr, "after align 1 %s \n", indication1 ); + display( mseq1, clus1 ); + fprintf( stderr, "\n" ); + fprintf( stderr, "after align 2 %s \n", indication2 ); + display( mseq2, clus2 ); + fprintf( stderr, "\n" ); +*/ + +// writePre( njob, name, nlen, localcopy, 0 ); + + if( disp ) display( localcopy, njob ); + + pthread_mutex_lock( targ->mutex ); + dep[l].done = 1; + (*nrunpt)--; + pthread_cond_broadcast( targ->treecond ); + +// pthread_mutex_unlock( targ->mutex ); +// pthread_mutex_lock( targ->mutex ); + + for( i=0; (j=topol[l][0][i])!=-1; i++ ) + strcpy( aseq[j], localcopy[j] ); + for( i=0; (j=topol[l][1][i])!=-1; i++ ) + strcpy( aseq[j], localcopy[j] ); + pthread_mutex_unlock( targ->mutex ); + + for( i=0; (j=topol[l][0][i])!=-1; i++ ) + free( localcopy[j] ); + for( i=0; (j=topol[l][1][i])!=-1; i++ ) + free( localcopy[j] ); + free( topol[l][0] ); + free( topol[l][1] ); + free( topol[l] ); + + } +} +#endif + +void treebase( int *nlen, char **aseq, int nadd, char *mergeoralign, char **mseq1, char **mseq2, int ***topol, double *effarr, int *alloclen, LocalHom **localhomtable, RNApair ***singlerna, double *effarr_kozo ) +{ + int i, l, m; + int len1nocommongap, len2nocommongap; + int len1, len2; + int clus1, clus2; + float pscore, tscore; + static char *indication1, *indication2; + static double *effarr1 = NULL; + static double *effarr2 = NULL; + static double *effarr1_kozo = NULL; + static double *effarr2_kozo = NULL; + static LocalHom ***localhomshrink = NULL; + static int *fftlog; + int m1, m2; + static int *gaplen; + static int *gapmap; + static int *alreadyaligned; + float dumfl = 0.0; + int ffttry; + RNApair ***grouprna1, ***grouprna2; + + if( rnakozo && rnaprediction == 'm' ) + { + grouprna1 = (RNApair ***)calloc( njob, sizeof( RNApair ** ) ); + grouprna2 = (RNApair ***)calloc( njob, sizeof( RNApair ** ) ); + } + else + { + grouprna1 = grouprna2 = NULL; + } + + if( effarr1 == NULL ) + { + fftlog = AllocateIntVec( njob ); + effarr1 = AllocateDoubleVec( njob ); + effarr2 = AllocateDoubleVec( njob ); + indication1 = AllocateCharVec( 150 ); + indication2 = AllocateCharVec( 150 ); + gaplen = AllocateIntVec( *alloclen+10 ); + gapmap = AllocateIntVec( *alloclen+10 ); + alreadyaligned = AllocateIntVec( njob ); +#if 0 +#else + if( constraint ) + { + localhomshrink = (LocalHom ***)calloc( njob, sizeof( LocalHom ** ) ); + for( i=0; i 66 ) fprintf( stderr, "..." ); + fprintf( stderr, "\n" ); + fprintf( stderr, "group2 = %.66s", indication2 ); + if( strlen( indication2 ) > 66 ) fprintf( stderr, "..." ); + fprintf( stderr, "\n" ); +#endif + + + +// for( i=0; i 30000 || len2 > 30000 ) ) ) + { + fprintf( stderr, "\nlen1=%d, len2=%d, Switching to the memsave mode.\n", len1, len2 ); + alg = 'M'; + if( commonIP ) FreeIntMtx( commonIP ); + commonAlloc1 = 0; + commonAlloc2 = 0; + } + + +// if( fftlog[m1] && fftlog[m2] ) ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 ); + if( fftlog[m1] && fftlog[m2] ) ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 && clus1 < 1000 && clus2 < 1000 ); + else ffttry = 0; +// ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 && clus1 < 5000 && clus2 < 5000 ); // v6.708 +// fprintf( stderr, "f=%d, len1/fftlog[m1]=%f, clus1=%d, len2/fftlog[m2]=%f, clus2=%d\n", ffttry, (float)len1/fftlog[m1], clus1, (float)len2/fftlog[m2], clus2 ); +// fprintf( stderr, "f=%d, clus1=%d, fftlog[m1]=%d, clus2=%d, fftlog[m2]=%d\n", ffttry, clus1, fftlog[m1], clus2, fftlog[m2] ); + if( constraint == 2 ) + { + if( alg == 'M' ) + { + fprintf( stderr, "\n\nMemory saving mode is not supported.\n\n" ); + exit( 1 ); + } + fprintf( stderr, "c" ); + if( alg == 'A' ) + { + imp_match_init_strict( NULL, clus1, clus2, strlen( mseq1[0] ), strlen( mseq2[0] ), mseq1, mseq2, effarr1, effarr2, effarr1_kozo, effarr2_kozo, localhomshrink, 1 ); + if( rnakozo ) imp_rna( clus1, clus2, mseq1, mseq2, effarr1, effarr2, grouprna1, grouprna2, NULL, NULL, NULL ); + pscore = A__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, localhomshrink, &dumfl, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap ); + } + else if( alg == 'H' ) + { + imp_match_init_strictH( NULL, clus1, clus2, strlen( mseq1[0] ), strlen( mseq2[0] ), mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 ); + pscore = H__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, localhomshrink, &dumfl, NULL, NULL, NULL, NULL ); + } + else if( alg == 'Q' ) + { + imp_match_init_strictQ( NULL, clus1, clus2, strlen( mseq1[0] ), strlen( mseq2[0] ), mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 ); + if( rnakozo ) imp_rnaQ( clus1, clus2, mseq1, mseq2, effarr1, effarr2, grouprna1, grouprna2, NULL, NULL, NULL ); + pscore = Q__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, localhomshrink, &dumfl, NULL, NULL, NULL, NULL ); + } + else if( alg == 'R' ) + { + imp_match_init_strictR( NULL, clus1, clus2, strlen( mseq1[0] ), strlen( mseq2[0] ), mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 ); + pscore = R__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, localhomshrink, &dumfl, NULL, NULL, NULL, NULL ); + } + } + else if( force_fft || ( use_fft && ffttry ) ) + { + fprintf( stderr, "f" ); + if( alg == 'M' ) + { + fprintf( stderr, "m" ); + pscore = Falign_udpari_long( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, fftlog+m1 ); + } + else + pscore = Falign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, fftlog+m1, NULL, 0, NULL ); + } + else + { + fprintf( stderr, "d" ); + fftlog[m1] = 0; + switch( alg ) + { + case( 'a' ): + pscore = Aalign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen ); + break; + case( 'M' ): + fprintf( stderr, "m" ); + pscore = MSalignmm( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap ); + break; + case( 'A' ): + pscore = A__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap ); + break; + case( 'Q' ): + pscore = Q__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL ); + break; + case( 'R' ): + pscore = R__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL ); + break; + case( 'H' ): + pscore = H__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL ); + break; + default: + ErrorExit( "ERROR IN SOURCE FILE" ); + } + } + + nlen[m1] = 0.5 * ( nlen[m1] + nlen[m2] ); + +#if SCOREOUT + fprintf( stderr, "score = %10.2f\n", pscore ); +#endif + tscore += pscore; +/* + fprintf( stderr, "after align 1 %s \n", indication1 ); + display( mseq1, clus1 ); + fprintf( stderr, "\n" ); + fprintf( stderr, "after align 2 %s \n", indication2 ); + display( mseq2, clus2 ); + fprintf( stderr, "\n" ); +*/ + +// writePre( njob, name, nlen, aseq, 0 ); + + if( disp ) display( aseq, njob ); + + if( mergeoralign[l] == '1' ) // jissainiha nai. atarashii hairetsu ha saigo dakara. + { + adjustgapmap( strlen( mseq2[0] )-len2nocommongap+len2, gapmap, mseq2[0] ); + restorecommongaps( njob, aseq, topol[l][0], topol[l][1], gapmap, *alloclen ); + findnewgaps( clus2, mseq2, gaplen ); + insertnewgaps( njob, alreadyaligned, aseq, topol[l][1], topol[l][0], gaplen, gapmap, *alloclen, alg ); + for( i=0; i-1; i++ ) alreadyaligned[m] = 1; + } + if( mergeoralign[l] == '2' ) + { +// fprintf( stderr, ">mseq1[0] = \n%s\n", mseq1[0] ); +// fprintf( stderr, ">mseq2[0] = \n%s\n", mseq2[0] ); + adjustgapmap( strlen( mseq1[0] )-len1nocommongap+len1, gapmap, mseq1[0] ); + restorecommongaps( njob, aseq, topol[l][0], topol[l][1], gapmap, *alloclen ); + findnewgaps( clus1, mseq1, gaplen ); + insertnewgaps( njob, alreadyaligned, aseq, topol[l][0], topol[l][1], gaplen, gapmap, *alloclen, alg ); + for( i=0; i-1; i++ ) alreadyaligned[m] = 1; + } + + free( topol[l][0] ); + free( topol[l][1] ); + free( topol[l] ); + } +#if SCOREOUT + fprintf( stderr, "totalscore = %10.2f\n\n", tscore ); +#endif +} + +static void WriteOptions( FILE *fp ) +{ + + if( dorp == 'd' ) fprintf( fp, "DNA\n" ); + else + { + if ( scoremtx == 0 ) fprintf( fp, "JTT %dPAM\n", pamN ); + else if( scoremtx == 1 ) fprintf( fp, "BLOSUM %d\n", nblosum ); + else if( scoremtx == 2 ) fprintf( fp, "M-Y\n" ); + } + fprintf( stderr, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 ); + if( use_fft ) fprintf( fp, "FFT on\n" ); + + fprintf( fp, "tree-base method\n" ); + if( tbrweight == 0 ) fprintf( fp, "unweighted\n" ); + else if( tbrweight == 3 ) fprintf( fp, "clustalw-like weighting\n" ); + if( tbitr || tbweight ) + { + fprintf( fp, "iterate at each step\n" ); + if( tbitr && tbrweight == 0 ) fprintf( fp, " unweighted\n" ); + if( tbitr && tbrweight == 3 ) fprintf( fp, " reversely weighted\n" ); + if( tbweight ) fprintf( fp, " weighted\n" ); + fprintf( fp, "\n" ); + } + + fprintf( fp, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 ); + + if( alg == 'a' ) + fprintf( fp, "Algorithm A\n" ); + else if( alg == 'A' ) + fprintf( fp, "Algorithm A+\n" ); + else if( alg == 'C' ) + fprintf( fp, "Apgorithm A+/C\n" ); + else + fprintf( fp, "Unknown algorithm\n" ); + + if( treemethod == 'X' ) + fprintf( fp, "Tree = UPGMA (mix).\n" ); + else if( treemethod == 'E' ) + fprintf( fp, "Tree = UPGMA (average).\n" ); + else if( treemethod == 'q' ) + fprintf( fp, "Tree = Minimum linkage.\n" ); + else + fprintf( fp, "Unknown tree.\n" ); + + if( use_fft ) + { + fprintf( fp, "FFT on\n" ); + if( dorp == 'd' ) + fprintf( fp, "Basis : 4 nucleotides\n" ); + else + { + if( fftscore ) + fprintf( fp, "Basis : Polarity and Volume\n" ); + else + fprintf( fp, "Basis : 20 amino acids\n" ); + } + fprintf( fp, "Threshold of anchors = %d%%\n", fftThreshold ); + fprintf( fp, "window size of anchors = %dsites\n", fftWinSize ); + } + else + fprintf( fp, "FFT off\n" ); + fflush( fp ); +} + + +int main( int argc, char *argv[] ) +{ + static int *nlen; + static float *selfscore; + int nogaplen; + static char **name, **seq; + static char **mseq1, **mseq2; + static char **bseq; + static float **iscore, **iscore_kozo; + static double *eff, *eff_kozo, *eff_kozo_mapped = NULL; + int i, j, ien, ik, jk; + static int ***topol, ***topol_kozo; + static int *addmem; + static Treedep *dep; + static float **len, **len_kozo; + FILE *prep; + FILE *infp; + FILE *orderfp; + FILE *hat2p; + double unweightedspscore; + int alignmentlength; + char *mergeoralign; + int foundthebranch; + + char c; + int alloclen; + LocalHom **localhomtable = NULL; + RNApair ***singlerna; + float ssi, ssj, bunbo; + static char *kozoarivec; + int nkozo; + + 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; + + getnumlen( infp ); + rewind( infp ); + + + nkozo = 0; + + 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+1 ); + mseq1 = AllocateCharMtx( njob, 0 ); + mseq2 = AllocateCharMtx( njob, 0 ); + + name = AllocateCharMtx( njob, B+1 ); + nlen = AllocateIntVec( njob ); + selfscore = AllocateFloatVec( njob ); + + topol = AllocateIntCub( njob, 2, 0 ); + len = AllocateFloatMtx( njob, 2 ); + iscore = AllocateFloatHalfMtx( njob ); + eff = AllocateDoubleVec( njob ); + kozoarivec = AllocateCharVec( njob ); + + mergeoralign = AllocateCharVec( njob ); + + dep = (Treedep *)calloc( njob, sizeof( Treedep ) ); + if( nadd ) addmem = AllocateIntVec( nadd+1 ); + + if( constraint ) + { + localhomtable = (LocalHom **)calloc( njob, sizeof( LocalHom *) ); + for( i=0; i 0 ) + { + distancematrixthread_arg_t *targ; + Jobtable jobpos; + pthread_t *handle; + pthread_mutex_t mutex; + + jobpos.i = 0; + jobpos.j = 0; + + targ = calloc( nthread, sizeof( distancematrixthread_arg_t ) ); + handle = calloc( nthread, sizeof( pthread_t ) ); + pthread_mutex_init( &mutex, NULL ); + + for( i=0; i 0 && nadd == 0 ) + { + treebasethread_arg_t *targ; + int jobpos; + pthread_t *handle; + pthread_mutex_t mutex; + pthread_cond_t treecond; + int *fftlog; + int nrun; + int nthread_yoyu; + + nthread_yoyu = nthread * 1; + nrun = 0; + jobpos = 0; + targ = calloc( nthread_yoyu, sizeof( treebasethread_arg_t ) ); + fftlog = AllocateIntVec( njob ); + handle = calloc( nthread_yoyu, sizeof( pthread_t ) ); + pthread_mutex_init( &mutex, NULL ); + pthread_cond_init( &treecond, NULL ); + + for( i=0; inext ) + { + free( (void *)tmppt1 ); + tmppt1 = tmppt2; + } + free( (void *)tmppt1 ); + } + free( (void *)(localhomtable[i]+j) ); + } + free( (void *)localhomtable ); + } +#endif + + fprintf( trap_g, "done.\n" ); + fclose( trap_g ); + free( mergeoralign ); + + writeData_pointer( prep_g, njob, name, nlen, bseq ); +#if 0 + writeData( stdout, njob, name, nlen, bseq ); + writePre( njob, name, nlen, bseq, !contin ); + writeData_pointer( prep_g, njob, name, nlen, aseq ); +#endif +#if IODEBUG + fprintf( stderr, "OSHIMAI\n" ); +#endif + + if( constraint ) FreeLocalHomTable( localhomtable, njob ); + + SHOWVERSION; + return( 0 ); +}