9 static char *whereispairalign;
10 static char *laraparams;
11 static char foldalignopt[1000];
12 static int stdout_align;
13 static int stdout_dist;
14 static int store_localhom;
15 static int store_dist;
17 typedef struct _jobtable
23 #ifdef enablemultithread
24 typedef struct _thread_arg
31 LocalHom **localhomtable;
36 pthread_mutex_t *mutex_counter;
37 pthread_mutex_t *mutex_stdout;
41 static void t2u( char *seq )
45 if ( *seq == 'A' ) *seq = 'a';
46 else if( *seq == 'a' ) *seq = 'a';
47 else if( *seq == 'T' ) *seq = 'u';
48 else if( *seq == 't' ) *seq = 'u';
49 else if( *seq == 'U' ) *seq = 'u';
50 else if( *seq == 'u' ) *seq = 'u';
51 else if( *seq == 'G' ) *seq = 'g';
52 else if( *seq == 'g' ) *seq = 'g';
53 else if( *seq == 'C' ) *seq = 'c';
54 else if( *seq == 'c' ) *seq = 'c';
60 static float recallpairfoldalign( char **mseq1, char **mseq2, int m1, int m2, int *of1pt, int *of2pt, int alloclen )
62 static FILE *fp = NULL;
70 fp = fopen( "_foldalignout", "r" );
73 fprintf( stderr, "Cannot open _foldalignout\n" );
78 aln1 = calloc( alloclen, sizeof( char ) );
79 aln2 = calloc( alloclen, sizeof( char ) );
81 readpairfoldalign( fp, *mseq1, *mseq2, aln1, aln2, m1, m2, &of1tmp, &of2tmp, alloclen );
83 if( strstr( foldalignopt, "-global") )
85 fprintf( stderr, "Calling G__align11\n" );
86 value = G__align11( mseq1, mseq2, alloclen, outgap, outgap );
92 fprintf( stderr, "Calling L__align11\n" );
93 value = L__align11( mseq1, mseq2, alloclen, of1pt, of2pt );
96 // value = (float)naivepairscore11( *mseq1, *mseq2, penalty ); // nennnotame
100 fprintf( stderr, "FOLDALIGN returned no alignment between %d and %d. Sequence alignment is used instead.\n", m1+1, m2+1 );
104 strcpy( *mseq1, aln1 );
105 strcpy( *mseq2, aln2 );
110 // value = naivepairscore11( *mseq1, *mseq2, penalty ); // v6.511 ha kore wo tsukau, global nomi dakara.
112 // fclose( fp ); // saigo dake yatta houga yoi.
114 // fprintf( stderr, "*mseq1 = %s\n", *mseq1 );
115 // fprintf( stderr, "*mseq2 = %s\n", *mseq2 );
124 static void callfoldalign( int nseq, char **mseq )
129 static char com[10000];
131 for( i=0; i<nseq; i++ )
134 fp = fopen( "_foldalignin", "w" );
137 fprintf( stderr, "Cannot open _foldalignin\n" );
140 for( i=0; i<nseq; i++ )
142 fprintf( fp, ">%d\n", i+1 );
143 fprintf( fp, "%s\n", mseq[i] );
147 sprintf( com, "env PATH=%s foldalign210 %s _foldalignin > _foldalignout ", whereispairalign, foldalignopt );
151 fprintf( stderr, "Error in foldalign\n" );
157 static void calllara( int nseq, char **mseq, char *laraarg )
162 static char com[10000];
164 // for( i=0; i<nseq; i++ )
166 fp = fopen( "_larain", "w" );
169 fprintf( stderr, "Cannot open _larain\n" );
172 for( i=0; i<nseq; i++ )
174 fprintf( fp, ">%d\n", i+1 );
175 fprintf( fp, "%s\n", mseq[i] );
180 // fprintf( stderr, "calling LaRA\n" );
181 sprintf( com, "env PATH=%s:/bin:/usr/bin mafft_lara -i _larain -w _laraout -o _lara.params %s", whereispairalign, laraarg );
185 fprintf( stderr, "Error in lara\n" );
190 static float recalllara( char **mseq1, char **mseq2, int alloclen )
192 static FILE *fp = NULL;
198 static char com[10000];
204 fp = fopen( "_laraout", "r" );
207 fprintf( stderr, "Cannot open _laraout\n" );
210 ungap1 = AllocateCharVec( alloclen );
211 ungap2 = AllocateCharVec( alloclen );
212 ori1 = AllocateCharVec( alloclen );
213 ori2 = AllocateCharVec( alloclen );
217 strcpy( ori1, *mseq1 );
218 strcpy( ori2, *mseq2 );
220 fgets( com, 999, fp );
221 myfgets( com, 9999, fp );
222 strcpy( *mseq1, com );
223 myfgets( com, 9999, fp );
224 strcpy( *mseq2, com );
226 gappick0( ungap1, *mseq1 );
227 gappick0( ungap2, *mseq2 );
233 if( strcmp( ungap1, ori1 ) || strcmp( ungap2, ori2 ) )
235 fprintf( stderr, "SEQUENCE CHANGED!!\n" );
236 fprintf( stderr, "*mseq1 = %s\n", *mseq1 );
237 fprintf( stderr, "ungap1 = %s\n", ungap1 );
238 fprintf( stderr, "ori1 = %s\n", ori1 );
239 fprintf( stderr, "*mseq2 = %s\n", *mseq2 );
240 fprintf( stderr, "ungap2 = %s\n", ungap2 );
241 fprintf( stderr, "ori2 = %s\n", ori2 );
245 value = (float)naivepairscore11( *mseq1, *mseq2, penalty );
247 // fclose( fp ); // saigo dake yatta houga yoi.
253 static float callmxscarna_giving_bpp( char **mseq1, char **mseq2, char **bpp1, char **bpp2, int alloclen, int i, int j )
262 dirname = calloc( 100, sizeof( char ) );
263 com = calloc( 1000, sizeof( char ) );
264 sprintf( dirname, "_%d-%d", i, j );
265 sprintf( com, "rm -rf %s", dirname );
267 sprintf( com, "mkdir %s", dirname );
271 sprintf( com, "%s/_bpporg", dirname );
272 fp = fopen( com, "w" );
275 fprintf( stderr, "Cannot write to %s/_bpporg\n", dirname );
278 fprintf( fp, ">a\n" );
280 fprintf( fp, "%s", *bpp1++ );
282 fprintf( fp, ">b\n" );
284 fprintf( fp, "%s", *bpp2++ );
287 sprintf( com, "tr -d '\\r' < %s/_bpporg > %s/_bpp", dirname, dirname );
288 system( com ); // for cygwin, wakaran
293 sprintf( com, "%s/_mxscarnainorg", dirname );
294 fp = fopen( com, "w" );
297 fprintf( stderr, "Cannot open %s/_mxscarnainorg\n", dirname );
300 fprintf( fp, ">1\n" );
301 // fprintf( fp, "%s\n", *mseq1 );
302 write1seq( fp, *mseq1 );
303 fprintf( fp, ">2\n" );
304 // fprintf( fp, "%s\n", *mseq2 );
305 write1seq( fp, *mseq2 );
308 sprintf( com, "tr -d '\\r' < %s/_mxscarnainorg > %s/_mxscarnain", dirname, dirname );
309 system( com ); // for cygwin, wakaran
312 sprintf( com, "cd %s; %s/mxscarnamod -readbpp _mxscarnain > _mxscarnaout 2>_dum", dirname, whereispairalign );
314 sprintf( com, "_mxscarnash%s", dirname );
315 fp = fopen( com, "w" );
316 fprintf( fp, "cd %s\n", dirname );
317 fprintf( fp, "%s/mxscarnamod -readbpp _mxscarnain > _mxscarnaout 2>_dum\n", whereispairalign );
318 fprintf( fp, "exit $tatus\n" );
321 sprintf( com, "tr -d '\\r' < _mxscarnash%s > _mxscarnash%s.unix", dirname, dirname );
322 system( com ); // for cygwin, wakaran
324 sprintf( com, "sh _mxscarnash%s.unix 2>_dum%s", dirname, dirname );
329 fprintf( stderr, "Error in mxscarna\n" );
333 sprintf( com, "%s/_mxscarnaout", dirname );
335 fp = fopen( com, "r" );
338 fprintf( stderr, "Cannot open %s/_mxscarnaout\n", dirname );
342 fgets( com, 999, fp );
343 load1SeqWithoutName_new( fp, *mseq1 );
344 fgets( com, 999, fp );
345 load1SeqWithoutName_new( fp, *mseq2 );
349 // fprintf( stderr, "*mseq1 = %s\n", *mseq1 );
350 // fprintf( stderr, "*mseq2 = %s\n", *mseq2 );
352 value = (float)naivepairscore11( *mseq1, *mseq2, penalty );
355 sprintf( com, "rm -rf %s > /dev/null 2>&1", dirname );
358 fprintf( stderr, "retrying to rmdir\n" );
372 static float callmxscarna_slow( char **mseq1, char **mseq2, int alloclen )
376 static char com[10000];
382 fp = fopen( "_mxscarnain", "w" );
385 fprintf( stderr, "Cannot open _mxscarnain\n" );
388 fprintf( fp, ">1\n" );
389 fprintf( fp, "%s\n", *mseq1 );
390 fprintf( fp, ">2\n" );
391 fprintf( fp, "%s\n", *mseq2 );
394 sprintf( com, "env PATH=%s mxscarnamod _mxscarnain > _mxscarnaout 2>_dum", whereispairalign );
398 fprintf( stderr, "Error in mxscarna\n" );
402 fp = fopen( "_mxscarnaout", "r" );
405 fprintf( stderr, "Cannot open _mxscarnaout\n" );
409 fgets( com, 999, fp );
410 load1SeqWithoutName_new( fp, *mseq1 );
411 fgets( com, 999, fp );
412 load1SeqWithoutName_new( fp, *mseq2 );
416 // fprintf( stderr, "*mseq1 = %s\n", *mseq1 );
417 // fprintf( stderr, "*mseq2 = %s\n", *mseq2 );
419 value = (float)naivepairscore11( *mseq1, *mseq2, penalty );
425 static void readhat4( FILE *fp, char ***bpp )
434 // fprintf( stderr, "reading hat4\n" );
436 // fprintf( stderr, "onechar = %c\n", onechar );
439 fprintf( stderr, "Format error\n" );
442 ungetc( onechar, fp );
443 fgets( oneline, 999, fp );
447 ungetc( onechar, fp );
448 if( onechar == '>' || onechar == EOF )
450 // fprintf( stderr, "Next\n" );
451 *bpp = realloc( *bpp, (bppsize+2) * sizeof( char * ) );
452 (*bpp)[bppsize] = NULL;
455 fgets( oneline, 999, fp );
456 // fprintf( stderr, "oneline=%s\n", oneline );
457 // sscanf( oneline, "%d %d %f", &posi, &posj, &prob );
458 // fprintf( stderr, "%d %d -> %f\n", posi, posj, prob );
459 *bpp = realloc( *bpp, (bppsize+2) * sizeof( char * ) );
460 (*bpp)[bppsize] = calloc( 100, sizeof( char ) );
461 strcpy( (*bpp)[bppsize], oneline );
466 static void preparebpp( int nseq, char ***bpp )
471 fp = fopen( "hat4", "r" );
474 fprintf( stderr, "Cannot open hat4\n" );
477 for( i=0; i<nseq; i++ )
478 readhat4( fp, bpp+i );
482 void arguments( int argc, char *argv[] )
526 ppenalty = NOTSPECIFIED;
527 ppenalty_OP = NOTSPECIFIED;
528 ppenalty_ex = NOTSPECIFIED;
529 ppenalty_EX = NOTSPECIFIED;
530 poffset = NOTSPECIFIED;
531 kimuraR = NOTSPECIFIED;
534 fftWinSize = NOTSPECIFIED;
535 fftThreshold = NOTSPECIFIED;
536 RNAppenalty = NOTSPECIFIED;
537 RNApthr = NOTSPECIFIED;
539 while( --argc > 0 && (*++argv)[0] == '-' )
541 while ( ( c = *++argv[0] ) )
547 fprintf( stderr, "inputfile = %s\n", inputfile );
551 ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
555 ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 );
559 ppenalty_OP = (int)( atof( *++argv ) * 1000 - 0.5 );
563 ppenalty_EX = (int)( atof( *++argv ) * 1000 - 0.5 );
567 poffset = (int)( atof( *++argv ) * 1000 - 0.5 );
571 kimuraR = atoi( *++argv );
572 // fprintf( stderr, "kimuraR = %d\n", kimuraR );
576 nblosum = atoi( *++argv );
578 // fprintf( stderr, "blosum %d\n", nblosum );
582 pamN = atoi( *++argv );
585 fprintf( stderr, "jtt %d\n", pamN );
589 pamN = atoi( *++argv );
592 fprintf( stderr, "TM %d\n", pamN );
596 ppslocal = (int)( atof( *++argv ) * 1000 + 0.5 );
597 pslocal = (int)( 600.0 / 1000.0 * ppslocal + 0.5);
598 // fprintf( stderr, "ppslocal = %d\n", ppslocal );
599 // fprintf( stderr, "pslocal = %d\n", pslocal );
603 whereispairalign = *++argv;
604 fprintf( stderr, "whereispairalign = %s\n", whereispairalign );
608 laraparams = *++argv;
609 fprintf( stderr, "laraparams = %s\n", laraparams );
613 nthread = atoi( *++argv );
614 fprintf( stderr, "nthread = %d\n", nthread );
709 /* Modified 01/08/27, default: user tree */
713 /* modification end. */
715 // foldalignopt = *++argv;
716 strcat( foldalignopt, " " );
717 strcat( foldalignopt, *++argv );
718 fprintf( stderr, "foldalignopt = %s\n", foldalignopt );
722 fftThreshold = atoi( *++argv );
726 fftWinSize = atoi( *++argv );
733 fprintf( stderr, "illegal option %c\n", c );
743 cut = atof( (*argv) );
748 fprintf( stderr, "options: Check source file !\n" );
751 if( tbitr == 1 && outgap == 0 )
753 fprintf( stderr, "conflicting options : o, m or u\n" );
758 int countamino( char *s, int end )
762 if( *s++ != '-' ) val++;
766 #if enablemultithread
767 static void *athread( void *arg )
769 thread_arg_t *targ = (thread_arg_t *)arg;
775 float pscore = 0.0; // by D.Mathog
780 char *indication1, *indication2;
781 char **mseq1, **mseq2;
785 int thread_no = targ->thread_no;
786 int njob = targ->njob;
787 Jobtable *jobpospt = targ->jobpospt;
788 char **name = targ->name;
789 char **seq = targ->seq;
790 LocalHom **localhomtable = targ->localhomtable;
791 double **distancemtx = targ->distancemtx;
792 double *selfscore = targ->selfscore;
793 char ***bpp = targ->bpp;
794 int alloclen = targ->alloclen;
796 // fprintf( stderr, "thread %d start!\n", thread_no );
798 effarr = AllocateDoubleVec( njob );
799 for( i=0; i<njob; i++ ) effarr[i] = 1.0;
800 effarr1 = AllocateDoubleVec( njob );
801 effarr2 = AllocateDoubleVec( njob );
802 indication1 = AllocateCharVec( 150 );
803 indication2 = AllocateCharVec( 150 );
804 pair = AllocateCharMtx( njob, njob );
805 for( i=0; i<njob; i++ ) for( j=0; j<njob; j++ ) pair[i][j] = 0;
806 for( i=0; i<njob; i++ ) pair[i][i] = 1;
807 mseq1 = AllocateCharMtx( njob, 0 );
808 mseq2 = AllocateCharMtx( njob, 0 );
809 aseq = AllocateCharMtx( njob, alloclen+10 );
813 pthread_mutex_lock( targ->mutex_counter );
823 // fprintf( stderr, "thread %d end!\n", thread_no );
824 pthread_mutex_unlock( targ->mutex_counter );
826 if( commonIP ) FreeIntMtx( commonIP );
828 if( commonJP ) FreeIntMtx( commonJP );
830 Falign( NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, 0, NULL );
831 G__align11_noalign( NULL, 0, 0, NULL, NULL, 0 );
832 L__align11( NULL, NULL, 0, NULL, NULL );
833 genL__align11( NULL, NULL, 0, NULL, NULL );
848 pthread_mutex_unlock( targ->mutex_counter );
851 if( j == i+1 || j % 100 == 0 )
853 fprintf( stderr, "% 5d / %d (by thread %3d) \r", i, njob, thread_no );
854 // fprintf( stderr, "% 5d - %5d / %d (thread %d)\n", i, j, njob, thread_no );
858 if( strlen( seq[i] ) == 0 || strlen( seq[j] ) == 0 )
860 if( store_dist ) distancemtx[i][j] = 2.0;
863 pthread_mutex_lock( targ->mutex_stdout );
864 fprintf( stdout, "%d %d d=%.3f\n", i+1, j+1, 2.0 );
865 pthread_mutex_unlock( targ->mutex_stdout );
870 strcpy( aseq[i], seq[i] );
871 strcpy( aseq[j], seq[j] );
872 clus1 = conjuctionfortbfast( pair, i, aseq, mseq1, effarr1, effarr, indication1 );
873 clus2 = conjuctionfortbfast( pair, j, aseq, mseq2, effarr2, effarr, indication2 );
874 // fprintf( stderr, "mseq1 = %s\n", mseq1[0] );
875 // fprintf( stderr, "mseq2 = %s\n", mseq2[0] );
878 fprintf( stderr, "group1 = %.66s", indication1 );
879 fprintf( stderr, "\n" );
880 fprintf( stderr, "group2 = %.66s", indication2 );
881 fprintf( stderr, "\n" );
883 // for( l=0; l<clus1; l++ ) fprintf( stderr, "## STEP-eff for mseq1-%d %f\n", l, effarr1[l] );
887 pscore = Falign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, &intdum, NULL, 0, NULL );
888 // fprintf( stderr, "pscore (fft) = %f\n", pscore );
896 pscore = G__align11_noalign( amino_dis, penalty, penalty_ex, mseq1, mseq2, alloclen );
897 L__align11( mseq1, mseq2, alloclen, &off1, &off2 );
900 pscore = G__align11( mseq1, mseq2, alloclen, outgap, outgap );
904 pscore = G__align11_noalign( amino_dis, penalty, penalty_ex, mseq1, mseq2, alloclen );
905 genL__align11( mseq1, mseq2, alloclen, &off1, &off2 );
908 pscore = G__align11_noalign( amino_dis, penalty, penalty_ex, mseq1, mseq2, alloclen );
912 pscore = callmxscarna_giving_bpp( mseq1, mseq2, bpp[i], bpp[j], alloclen, i, j );
917 pscore = Aalign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen );
921 pscore = genG__align11( mseq1, mseq2, alloclen );
925 pscore = recallpairfoldalign( mseq1, mseq2, i, j, &off1, &off2, alloclen );
929 pscore = recalllara( mseq1, mseq2, alloclen );
933 pscore = MSalign11( mseq1, mseq2, alloclen );
937 ErrorExit( "\n\nERROR IN SOURCE FILE\n\n" );
941 if( alg == 't' || ( mseq1[0][0] != 0 && mseq2[0][0] != 0 ) ) // 't' no jouken ha iranai to omou. if( ( mseq1[0][0] != 0 && mseq2[0][0] != 0 ) )
944 fprintf( stderr, "score = %10.2f (%d,%d)\n", pscore, i, j );
946 if( !store_localhom )
948 else if( alg == 'H' )
949 putlocalhom_ext( mseq1[0], mseq2[0], localhomtable[i]+j, off1, off2, (int)pscore, strlen( mseq1[0] ) );
950 else if( alg != 'S' && alg != 'V' )
952 putlocalhom2( mseq1[0], mseq2[0], localhomtable[i]+j, off1, off2, (int)pscore, strlen( mseq1[0] ) );
955 if( (bunbo=MIN( selfscore[i], selfscore[j] )) == 0.0 || bunbo < pscore )
958 pscore = ( 1.0 - pscore / bunbo ) * 2.0;
968 pthread_mutex_lock( targ->mutex_stdout );
971 fprintf( stdout, "sequence %d - sequence %d, pairwise distance = %10.5f\n", i+1, j+1, pscore );
972 fprintf( stdout, ">%s\n", name[i] );
973 write1seq( stdout, mseq1[0] );
974 fprintf( stdout, ">%s\n", name[j] );
975 write1seq( stdout, mseq2[0] );
976 fprintf( stdout, "\n" );
978 pthread_mutex_unlock( targ->mutex_stdout );
982 pthread_mutex_lock( targ->mutex_stdout );
983 if( j == i+1 ) fprintf( stdout, "%d %d d=%.3f\n", i+1, i+1, 0.0 );
984 fprintf( stdout, "%d %d d=%.3f\n", i+1, j+1, pscore );
985 pthread_mutex_unlock( targ->mutex_stdout );
988 if( store_dist) distancemtx[i][j] = pscore;
993 static void pairalign( char **name, int nlen[M], char **seq, char **aseq, char **mseq1, char **mseq2, double *effarr, int alloclen )
998 float pscore = 0.0; // by D.Mathog
999 static char *indication1, *indication2;
1000 FILE *hat2p, *hat3p;
1001 double **distancemtx;
1006 char *hat2file = "hat2";
1007 LocalHom **localhomtable = NULL, *tmpptr;
1011 char ***bpp = NULL; // mxscarna no toki dake
1013 if( store_localhom )
1015 localhomtable = (LocalHom **)calloc( njob, sizeof( LocalHom *) );
1016 for( i=0; i<njob; i++)
1018 localhomtable[i] = (LocalHom *)calloc( njob, sizeof( LocalHom ) );
1019 for( j=0; j<njob; j++)
1021 localhomtable[i][j].start1 = -1;
1022 localhomtable[i][j].end1 = -1;
1023 localhomtable[i][j].start2 = -1;
1024 localhomtable[i][j].end2 = -1;
1025 localhomtable[i][j].opt = -1.0;
1026 localhomtable[i][j].next = NULL;
1027 localhomtable[i][j].nokori = 0;
1032 if( store_dist ) distancemtx = AllocateDoubleMtx( njob, njob );
1033 else distancemtx = NULL;
1034 selfscore = AllocateDoubleVec( njob );
1035 effarr1 = AllocateDoubleVec( njob );
1036 effarr2 = AllocateDoubleVec( njob );
1037 indication1 = AllocateCharVec( 150 );
1038 indication2 = AllocateCharVec( 150 );
1041 pair = AllocateCharMtx( njob, njob );
1045 fprintf( stderr, "##### fftwinsize = %d, fftthreshold = %d\n", fftWinSize, fftThreshold );
1049 for( i=0; i<njob; i++ )
1050 fprintf( stderr, "TBFAST effarr[%d] = %f\n", i, effarr[i] );
1054 // writePre( njob, name, nlen, aseq, 0 );
1056 for( i=0; i<njob; i++ ) for( j=0; j<njob; j++ ) pair[i][j] = 0;
1057 for( i=0; i<njob; i++ ) pair[i][i] = 1;
1061 fprintf( stderr, "Calling FOLDALIGN with option '%s'\n", foldalignopt );
1062 callfoldalign( njob, seq );
1063 fprintf( stderr, "done.\n" );
1067 fprintf( stderr, "Running LARA (Bauer et al. http://www.planet-lisa.net/)\n" );
1068 calllara( njob, seq, "" );
1069 fprintf( stderr, "done.\n" );
1073 fprintf( stderr, "Running SLARA (Bauer et al. http://www.planet-lisa.net/)\n" );
1074 calllara( njob, seq, "-s" );
1075 fprintf( stderr, "done.\n" );
1079 fprintf( stderr, "Preparing bpp\n" );
1080 // bpp = AllocateCharCub( njob, nlenmax, 0 );
1081 bpp = calloc( njob, sizeof( char ** ) );
1082 preparebpp( njob, bpp );
1083 fprintf( stderr, "done.\n" );
1084 fprintf( stderr, "Running MXSCARNA (Tabei et al. http://www.ncrna.org/software/mxscarna)\n" );
1087 for( i=0; i<njob; i++ )
1090 for( pt=seq[i]; *pt; pt++ )
1091 pscore += amino_dis[(int)*pt][(int)*pt];
1092 selfscore[i] = pscore;
1096 #if enablemultithread
1101 pthread_mutex_t mutex_counter;
1102 pthread_mutex_t mutex_stdout;
1108 targ = calloc( nthread, sizeof( thread_arg_t ) );
1109 handle = calloc( nthread, sizeof( pthread_t ) );
1110 pthread_mutex_init( &mutex_counter, NULL );
1111 pthread_mutex_init( &mutex_stdout, NULL );
1113 for( i=0; i<nthread; i++ )
1115 targ[i].thread_no = i;
1116 targ[i].njob = njob;
1117 targ[i].jobpospt = &jobpos;
1118 targ[i].name = name;
1120 targ[i].localhomtable = localhomtable;
1121 targ[i].distancemtx = distancemtx;
1122 targ[i].selfscore = selfscore;
1124 targ[i].alloclen = alloclen;
1125 targ[i].mutex_counter = &mutex_counter;
1126 targ[i].mutex_stdout = &mutex_stdout;
1128 // athread( (void *)targ );
1129 pthread_create( handle+i, NULL, athread, (void *)(targ+i) );
1130 // pthread_create( handle+i, NULL, bthread, (void *)(targ+i) );
1134 for( i=0; i<nthread; i++ )
1136 pthread_join( handle[i], NULL );
1138 pthread_mutex_destroy( &mutex_counter );
1139 pthread_mutex_destroy( &mutex_stdout );
1147 for( i=0; i<ilim; i++ )
1149 if( stdout_dist) fprintf( stdout, "%d %d d=%.3f\n", i+1, i+1, 0.0 );
1150 fprintf( stderr, "% 5d / %d\r", i, njob );
1152 for( j=i+1; j<njob; j++ )
1155 if( strlen( seq[i] ) == 0 || strlen( seq[j] ) == 0 )
1157 if( store_dist ) distancemtx[i][j] = 2.0;
1158 if( stdout_dist) fprintf( stdout, "%d %d d=%.3f\n", i+1, j+1, 2.0 );
1162 strcpy( aseq[i], seq[i] );
1163 strcpy( aseq[j], seq[j] );
1164 clus1 = conjuctionfortbfast( pair, i, aseq, mseq1, effarr1, effarr, indication1 );
1165 clus2 = conjuctionfortbfast( pair, j, aseq, mseq2, effarr2, effarr, indication2 );
1166 // fprintf( stderr, "mseq1 = %s\n", mseq1[0] );
1167 // fprintf( stderr, "mseq2 = %s\n", mseq2[0] );
1170 fprintf( stderr, "group1 = %.66s", indication1 );
1171 fprintf( stderr, "\n" );
1172 fprintf( stderr, "group2 = %.66s", indication2 );
1173 fprintf( stderr, "\n" );
1175 // for( l=0; l<clus1; l++ ) fprintf( stderr, "## STEP-eff for mseq1-%d %f\n", l, effarr1[l] );
1179 pscore = Falign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, &intdum, NULL, 0, NULL );
1180 // fprintf( stderr, "pscore (fft) = %f\n", pscore );
1188 pscore = Aalign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen );
1192 pscore = G__align11_noalign( amino_dis, penalty, penalty_ex, mseq1, mseq2, alloclen );
1196 pscore = G__align11( mseq1, mseq2, alloclen, outgap, outgap );
1200 pscore = G__align11_noalign( amino_dis, penalty, penalty_ex, mseq1, mseq2, alloclen );
1201 genL__align11( mseq1, mseq2, alloclen, &off1, &off2 );
1204 pscore = genG__align11( mseq1, mseq2, alloclen );
1208 pscore = G__align11_noalign( amino_dis, penalty, penalty_ex, mseq1, mseq2, alloclen );
1209 L__align11( mseq1, mseq2, alloclen, &off1, &off2 );
1212 pscore = recallpairfoldalign( mseq1, mseq2, i, j, &off1, &off2, alloclen );
1216 pscore = recalllara( mseq1, mseq2, alloclen );
1220 pscore = callmxscarna_giving_bpp( mseq1, mseq2, bpp[i], bpp[j], alloclen, i, j );
1224 pscore = MSalign11( mseq1, mseq2, alloclen );
1227 ErrorExit( "ERROR IN SOURCE FILE" );
1231 if( alg == 't' || ( mseq1[0][0] != 0 && mseq2[0][0] != 0 ) ) // 't' no jouken ha iranai to omou. if( ( mseq1[0][0] != 0 && mseq2[0][0] != 0 ) )
1234 fprintf( stderr, "score = %10.2f (%d,%d)\n", pscore, i, j );
1236 if( !store_localhom )
1238 else if( alg == 'H' )
1239 putlocalhom_ext( mseq1[0], mseq2[0], localhomtable[i]+j, off1, off2, (int)pscore, strlen( mseq1[0] ) );
1240 else if( alg != 'S' && alg != 'V' )
1241 putlocalhom2( mseq1[0], mseq2[0], localhomtable[i]+j, off1, off2, (int)pscore, strlen( mseq1[0] ) );
1244 if( (bunbo=MIN( selfscore[i], selfscore[j] )) == 0.0 || bunbo < pscore )
1247 pscore = ( 1.0 - pscore / bunbo ) * 2.0;
1258 fprintf( stdout, "sequence %d - sequence %d, pairwise distance = %10.5f\n", i+1, j+1, pscore );
1259 fprintf( stdout, ">%s\n", name[i] );
1260 write1seq( stdout, mseq1[0] );
1261 fprintf( stdout, ">%s\n", name[j] );
1262 write1seq( stdout, mseq2[0] );
1263 fprintf( stdout, "\n" );
1266 if( stdout_dist ) fprintf( stdout, "%d %d d=%.3f\n", i+1, j+1, pscore );
1267 if( store_dist) distancemtx[i][j] = pscore;
1275 hat2p = fopen( hat2file, "w" );
1276 if( !hat2p ) ErrorExit( "Cannot open hat2." );
1277 WriteHat2_pointer( hat2p, njob, name, distancemtx );
1281 hat3p = fopen( "hat3", "w" );
1282 if( !hat3p ) ErrorExit( "Cannot open hat3." );
1283 if( store_localhom )
1285 fprintf( stderr, "\n\n##### writing hat3\n" );
1287 for( i=0; i<ilim; i++ )
1289 for( j=i+1; j<njob; j++ )
1291 for( tmpptr=localhomtable[i]+j; tmpptr; tmpptr=tmpptr->next )
1293 if( tmpptr->opt == -1.0 ) continue;
1295 // if( alg == 'B' || alg == 'T' )
1296 // fprintf( hat3p, "%d %d %d %7.5f %d %d %d %d %p\n", i, j, tmpptr->overlapaa, 1.0, tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2, (void *)tmpptr->next );
1298 fprintf( hat3p, "%d %d %d %7.5f %d %d %d %d h\n", i, j, tmpptr->overlapaa, tmpptr->opt, tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2 );
1303 fprintf( stderr, "calling FreeLocalHomTable\n" );
1305 FreeLocalHomTable( localhomtable, njob );
1307 fprintf( stderr, "done. FreeLocalHomTable\n" );
1315 for( i=0; i<njob; i++ )
1320 if( *ptpt ) free( *ptpt );
1331 free( indication1 );
1332 free( indication2 );
1333 if( store_dist ) FreeDoubleMtx( distancemtx );
1336 static void WriteOptions( FILE *fp )
1339 if( dorp == 'd' ) fprintf( fp, "DNA\n" );
1342 if ( scoremtx == 0 ) fprintf( fp, "JTT %dPAM\n", pamN );
1343 else if( scoremtx == 1 ) fprintf( fp, "BLOSUM %d\n", nblosum );
1344 else if( scoremtx == 2 ) fprintf( fp, "M-Y\n" );
1346 fprintf( stderr, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
1347 if( use_fft ) fprintf( fp, "FFT on\n" );
1349 fprintf( fp, "tree-base method\n" );
1350 if( tbrweight == 0 ) fprintf( fp, "unweighted\n" );
1351 else if( tbrweight == 3 ) fprintf( fp, "clustalw-like weighting\n" );
1352 if( tbitr || tbweight )
1354 fprintf( fp, "iterate at each step\n" );
1355 if( tbitr && tbrweight == 0 ) fprintf( fp, " unweighted\n" );
1356 if( tbitr && tbrweight == 3 ) fprintf( fp, " reversely weighted\n" );
1357 if( tbweight ) fprintf( fp, " weighted\n" );
1358 fprintf( fp, "\n" );
1361 fprintf( fp, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
1364 fprintf( fp, "Algorithm A\n" );
1365 else if( alg == 'A' )
1366 fprintf( fp, "Algorithm A+\n" );
1367 else if( alg == 'S' )
1368 fprintf( fp, "Apgorithm S\n" );
1370 fprintf( fp, "Unknown algorithm\n" );
1374 fprintf( fp, "FFT on\n" );
1376 fprintf( fp, "Basis : 4 nucleotides\n" );
1380 fprintf( fp, "Basis : Polarity and Volume\n" );
1382 fprintf( fp, "Basis : 20 amino acids\n" );
1384 fprintf( fp, "Threshold of anchors = %d%%\n", fftThreshold );
1385 fprintf( fp, "window size of anchors = %dsites\n", fftWinSize );
1388 fprintf( fp, "FFT off\n" );
1393 int main( int argc, char *argv[] )
1397 char **mseq1, **mseq2;
1406 arguments( argc, argv );
1407 #ifndef enablemultithread
1413 infp = fopen( inputfile, "r" );
1416 fprintf( stderr, "Cannot open %s\n", inputfile );
1428 fprintf( stderr, "At least 2 sequences should be input!\n"
1429 "Only %d sequence found.\n", njob );
1434 fprintf( stderr, "The number of sequences must be < %d\n", M );
1435 fprintf( stderr, "Please try the splittbfast program for such large data.\n" );
1439 alloclen = nlenmax*2;
1440 seq = AllocateCharMtx( njob, alloclen+10 );
1441 aseq = AllocateCharMtx( njob, alloclen+10 );
1442 bseq = AllocateCharMtx( njob, alloclen+10 );
1443 mseq1 = AllocateCharMtx( njob, 0 );
1444 mseq2 = AllocateCharMtx( njob, 0 );
1445 name = AllocateCharMtx( njob, B );
1447 eff = AllocateDoubleVec( njob );
1450 Read( name, nlen, seq );
1452 readData_pointer( infp, name, nlen, seq );
1456 constants( njob, seq );
1459 fprintf( stderr, "params = %d, %d, %d\n", penalty, penalty_ex, offset );
1466 WriteOptions( trap_g );
1468 c = seqcheck( seq );
1471 fprintf( stderr, "Illegal character %c\n", c );
1475 // writePre( njob, name, nlen, seq, 0 );
1477 for( i=0; i<njob; i++ ) eff[i] = 1.0;
1480 for( i=0; i<njob; i++ ) gappick0( bseq[i], seq[i] );
1482 pairalign( name, nlen, bseq, aseq, mseq1, mseq2, eff, alloclen );
1484 fprintf( trap_g, "done.\n" );
1486 fprintf( stderr, "closing trap_g\n" );
1490 // writePre( njob, name, nlen, aseq, !contin );
1492 writeData( stdout, njob, name, nlen, aseq );
1495 fprintf( stderr, "OSHIMAI\n" );
1499 if( stdout_dist && nthread > 1 )
1501 fprintf( stderr, "\nThe order of distances is not identical to that in the input file, because of the parallel calculation. Reorder them by yourself, using sort -n -k 2 | sort -n -k 1 -s\n" );
1503 if( stdout_align && nthread > 1 )
1505 fprintf( stderr, "\nThe order of pairwise alignments is not identical to that in the input file, because of the parallel calculation. Reorder them by yourself.\n" );
1508 FreeCharMtx( aseq );
1509 FreeCharMtx( bseq );
1510 FreeCharMtx( name );