8 #include <sys/resource.h>
13 getrusage(RUSAGE_SELF, &t);
15 return tv.tv_sec + (double)tv.tv_usec*1e-6;
20 int intcmp( int *str1, int *str2 )
22 while( *str1 != -1 && *str2 != -1 )
23 if( *str1++ != *str2++ ) return( 1 );
24 if( *str1 != *str2 ) return( 1 );
28 char **arguments( int argc, char *argv[] )
37 use_fft = 0; // CHUUI!! atode modosu
55 ppenalty = NOTSPECIFIED;
56 ppenalty_ex = NOTSPECIFIED;
57 poffset = NOTSPECIFIED;
58 kimuraR = NOTSPECIFIED;
60 fftWinSize = NOTSPECIFIED;
61 fftThreshold = NOTSPECIFIED;
66 while( --argc > 0 && (*++argv)[0] == '-' )
68 while ( ( c = *++argv[0] ) )
109 fftThreshold = atoi( *++argv );
113 fftWinSize = atoi( *++argv );
120 ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
121 fprintf( stderr, "ppenalty = %d\n", ppenalty );
125 ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 );
126 fprintf( stderr, "ppenalty_ex = %d\n", ppenalty_ex );
130 poffset = (int)( atof( *++argv ) * 1000 - 0.5 );
131 fprintf( stderr, "poffset = %d\n", poffset );
135 kimuraR = atoi( *++argv );
136 fprintf( stderr, "kimuraR = %d\n", kimuraR );
140 nblosum = atoi( *++argv );
142 fprintf( stderr, "blosum %d\n", nblosum );
146 pamN = atoi( *++argv );
149 fprintf( stderr, "jtt %d\n", pamN );
153 pamN = atoi( *++argv );
156 fprintf( stderr, "tm %d\n", pamN );
160 fprintf( stderr, "illegal option %c\n", c );
170 fprintf( stderr, "options: Check source file ! %c ?\n", c );
173 fprintf( stderr, "tbitr = %d, tbrweight = %d, tbweight = %d\n", tbitr, tbrweight, tbweight );
174 // readOtherOptions( &ppid, &fftThreshold, &fftWinSize );
179 void GroupAlign( int nseq1, int nseq2, char **name, int *nlen, char **seq, char **aseq, char **mseq1, char **mseq2, int ***topol, double **len, double *eff, int alloclen )
185 static char **name1, **name2;
186 double *effarr = eff;
187 double *effarr1 = NULL;
188 double *effarr2 = NULL;
189 static char *indication1, *indication2;
197 // fprintf( stderr, "in GroupAlign fftWinSize = %d\n", fftWinSize );
198 // fprintf( stderr, "in GroupAlign fftThreshold = %d\n", fftThreshold );
200 if( effarr1 == NULL )
202 name1 = AllocateCharMtx( nseq1, B );
203 name2 = AllocateCharMtx( nseq2, B );
204 indication1 = AllocateCharVec( 150 );
205 indication2 = AllocateCharVec( 150 );
206 effarr1 = AllocateDoubleVec( njob );
207 effarr2 = AllocateDoubleVec( njob );
213 for( i=0; i<njob; i++ ) strcpy( aseq[i], seq[i] );
219 // fprintf( stdout, "nseq1 = %d\n", nseq1 );
223 clus1 = conjuctionforgaln( 0, nseq1, aseq, mseq1, effarr1, effarr, name, name1, indication1 );
224 clus2 = conjuctionforgaln( nseq1, njob, aseq, mseq2, effarr2, effarr, name, name2, indication2 );
226 fprintf( stderr, "before align all\n" );
227 display( aseq, njob );
228 fprintf( stderr, "\n" );
229 fprintf( stderr, "before align 1 %s \n", indication1 );
230 display( mseq1, clus1 );
231 fprintf( stderr, "\n" );
232 fprintf( stderr, "before align 2 %s \n", indication2 );
233 display( mseq2, clus2 );
234 fprintf( stderr, "\n" );
238 fprintf( stderr, "before realignment, score = %f\n", naiveQpairscore( nseq1, nseq2, mseq1, mseq2, effarr1, effarr2, penalty ) );
239 else if( alg == 'H' )
240 fprintf( stderr, "before realignment, score = %f\n", naivepairscore( nseq1, nseq2, mseq1, mseq2, effarr1, effarr2, penalty ) );
242 commongappick( nseq1, mseq1 );
243 commongappick( nseq2, mseq2 );
247 time1 = getrusage_sec();
248 fprintf( stderr, "entering Falign\n" );
253 pscore = Falign_udpari_long( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, &intdum );
255 pscore = Falign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, &intdum );
260 pscore = MSalignmm( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, NULL, NULL, NULL );
261 else if( alg == 'H' )
262 pscore = H__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL );
263 else if( alg == 'Q' )
264 pscore = Q__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL );
266 pscore = A__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL );
269 time2 = getrusage_sec();
270 fprintf( stdout, "### %d - %d, %f\n", clus1, clus2, time2-time1 );
275 fprintf( stderr, "before realignment, score = %f\n", naivepairscore( nseq1, nseq2, mseq1, mseq2, effarr1, effarr2, penalty ) );
276 else if( alg == 'Q' )
277 fprintf( stderr, "after realignment, score = %f\n", naiveQpairscore( nseq1, nseq2, mseq1, mseq2, effarr1, effarr2, penalty ) );
281 fprintf( stderr, "after align 1 %s \n", indication1 );
282 display( mseq1, clus1 );
283 fprintf( stderr, "\n" );
284 fprintf( stderr, "after align 2 %s \n", indication2 );
285 display( mseq2, clus2 );
286 fprintf( stderr, "\n" );
289 fprintf( stderr, "group-to-group %s /%s %f\n", indication1, indication2, pscore );
290 if( disp ) display( aseq, njob );
291 fprintf( stderr, "\n" );
294 trap = fopen( "pre", "r+" );
295 if( !trap ) ErrorExit( 1 );
296 WriteGapFill( trap, njob, name, nlen, aseq );
298 fprintf( stdout, "nseq1 = %d\n", nseq1 );
302 static void WriteOptions( FILE *fp )
304 fprintf( fp, "tree-base method\n" );
305 if( tbweight == 0 ) fprintf( fp, "unweighted\n" );
306 else if( tbweight == 3 ) fprintf( fp, "reversely weighted\n" );
307 if ( scoremtx == 0 ) fprintf( fp, "JTT %dPAM\n", pamN );
308 else if( scoremtx == 1 ) fprintf( fp, "Dayhoff( machigai ga aru )\n" );
309 else if( scoremtx == 2 ) fprintf( fp, "M-Y\n" );
310 else if( scoremtx == -1 ) fprintf( fp, "DNA\n" );
313 fprintf( fp, "Gap Penalty = %d, %d\n", penalty, offset );
315 fprintf( fp, "Gap Penalty = %d\n", penalty );
319 int main( int argc, char *argv[] )
323 static char **name, **seq;
324 static char **seq1, **seq2;
325 static char **mseq1, **mseq2;
328 static double **pscore;
330 int i, j, len1, len2;
335 int nlenmax1, nlenmax2, nseq1, nseq2;
338 argv2 = arguments( argc, argv );
340 fprintf( stderr, "####### in galn\n" );
344 fprintf( stderr, "file1 = %s\n", argv2[0] );
345 fprintf( stderr, "file2 = %s\n", argv2[1] );
347 gp1 = fopen( argv2[0], "r" ); if( !gp1 ) ErrorExit( "cannot open file1" );
348 gp2 = fopen( argv2[1], "r" ); if( !gp2 ) ErrorExit( "cannot open file2" );
351 PreRead( gp1, &nseq1, &nlenmax1 );
352 PreRead( gp2, &nseq2, &nlenmax2 );
355 nseq1 = njob; nlenmax1 = nlenmax;
357 nseq2 = njob; nlenmax2 = nlenmax;
360 njob = nseq1 + nseq2;
361 nlenmax = MAX( nlenmax1, nlenmax2 );
367 name = AllocateCharMtx( njob, B );
368 nlen = AllocateIntVec( njob );
369 seq1 = AllocateCharMtx( nseq1, nlenmax*3 );
370 seq2 = AllocateCharMtx( nseq2, nlenmax*3 );
371 seq = AllocateCharMtx( njob, 1 );
372 aseq = AllocateCharMtx( njob, nlenmax*3 );
373 bseq = AllocateCharMtx( njob, nlenmax*3 );
374 mseq1 = AllocateCharMtx( njob, 1 );
375 mseq2 = AllocateCharMtx( njob, 1 );
376 alloclen = nlenmax * 3;
378 topol = AllocateIntCub( njob, 2, njob );
379 len = AllocateDoubleMtx( njob, 2 );
380 pscore = AllocateDoubleMtx( njob, njob );
381 eff = AllocateDoubleVec( njob );
384 njob=nseq2; FRead( gp2, name+nseq1, nlen+nseq1, seq2 );
385 njob=nseq1; FRead( gp1, name, nlen, seq1 );
387 njob=nseq2; readDataforgaln( gp2, name+nseq1, nlen+nseq1, seq2 );
388 njob=nseq1; readDataforgaln( gp1, name, nlen, seq1 );
390 njob = nseq1 + nseq2;
394 commongappick( nseq1, seq1 );
395 commongappick( nseq2, seq2 );
398 for( i=0; i<nseq1; i++ ) seq[i] = seq1[i];
399 for( i=nseq1; i<njob; i++ ) seq[i] = seq2[i-nseq1];
401 Write( stdout, njob, name, nlen, seq );
404 constants( njob, seq );
406 WriteOptions( trap_g );
411 fprintf( stderr, "Illeagal character %c\n", c );
414 for( i=1; i<nseq1; i++ )
416 if( nlen[i] != nlen[0] )
417 ErrorExit( "group1 is not aligned." );
419 for( i=nseq1+1; i<njob; i++ )
421 if( nlen[i] != nlen[nseq1] )
422 ErrorExit( "group2 is not aligned." );
426 for( i=0; i<nseq1; i++ )
428 for( j=i+1; j<nseq1; j++ )
430 pscore[i][j] = (double)substitution_hosei( seq[i], seq[j] );
431 // fprintf( stderr, "%d-%d, %5.1f \n", i, j, pscore[i][j] );
433 for( j=nseq1; j<njob; j++ )
436 // fprintf( stderr, "%d-%d, %5.1f \n", i, j, pscore[i][j] );
439 for( i=nseq1; i<njob-1; i++ )
441 for( j=i+1; j<njob; j++ )
443 pscore[i][j] = (double)substitution_hosei( seq[i], seq[j] );
444 // fprintf( stderr, "%d-%d, %5.1f \n", i, j, pscore[i][j] );
447 // fprintf( stderr, "\n" );
453 fprintf( stderr, "Not supported\n" );
456 prep = fopen( "hat2", "r" );
457 if( prep == NULL ) ErrorExit( "Make hat2." );
458 readhat2( prep, njob, name, pscore );
462 fprintf( stderr, "Constructing dendrogram ... " );
463 if( treemethod == 'x' )
464 veryfastsupg( njob, pscore, topol, len );
466 ErrorExit( "Incorrect tree\n" );
467 fprintf( stderr, "done.\n" );
472 counteff_simple( njob, topol, len, eff );
473 // for( i=0; i<njob; i++ ) fprintf( stderr, "eff[%d] = %f\n", i, eff[i] );
477 for( i=0; i<njob; i++ ) eff[i] = 1.0;
480 len1 = strlen( seq[0] );
481 len2 = strlen( seq[nseq1] );
482 if( len1 > 10000 || len2 > 10000 )
484 fprintf( stderr, "\nlen1=%d, len2=%d, Switching to the memsave mode.\n", len1, len2 );
491 GroupAlign( nseq1, nseq2, name, nlen, seq, aseq, mseq1, mseq2, topol, len, eff, alloclen );
494 writePre( njob, name, nlen, aseq, 1 );
496 writeDataforgaln( stdout, njob, name, nlen, aseq );