8 void arguments( int argc, char *argv[] )
44 ppenalty = NOTSPECIFIED;
45 ppenalty_ex = NOTSPECIFIED;
46 poffset = NOTSPECIFIED;
47 kimuraR = NOTSPECIFIED;
50 fftWinSize = NOTSPECIFIED;
51 fftThreshold = NOTSPECIFIED;
54 while( --argc > 0 && (*++argv)[0] == '-' )
56 while ( c = *++argv[0] )
62 fprintf( stderr, "inputfile = %s\n", inputfile );
66 ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
67 fprintf( stderr, "ppenalty = %d\n", ppenalty );
71 ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 );
72 fprintf( stderr, "ppenalty_ex = %d\n", ppenalty_ex );
76 poffset = (int)( atof( *++argv ) * 1000 - 0.5 );
77 fprintf( stderr, "poffset = %d\n", poffset );
81 kimuraR = atoi( *++argv );
82 fprintf( stderr, "kimuraR = %d\n", kimuraR );
86 nblosum = atoi( *++argv );
88 fprintf( stderr, "blosum %d\n", nblosum );
92 pamN = atoi( *++argv );
95 fprintf( stderr, "jtt %d\n", pamN );
99 pamN = atoi( *++argv );
102 fprintf( stderr, "tm %d\n", pamN );
106 fastathreshold = atof( *++argv );
108 fprintf( stderr, "weighti = %f\n", fastathreshold );
112 thrinter = atof( *++argv );
113 fprintf( stderr, "thrinter %f\n", thrinter );
175 /* Modified 01/08/27, default: user tree */
179 /* modification end. */
181 fftThreshold = atoi( *++argv );
185 fftWinSize = atoi( *++argv );
192 fprintf( stderr, "illegal option %c\n", c );
202 cut = atof( (*argv) );
207 fprintf( stderr, "options: Check source file !\n" );
210 if( tbitr == 1 && outgap == 0 )
212 fprintf( stderr, "conflicting options : o, m or u\n" );
215 if( alg == 'C' && outgap == 0 )
217 fprintf( stderr, "conflicting options : C, o\n" );
223 void treebase( char name[M][B], int nlen[M], char **seq, char **aseq, char **mseq1, char **mseq2, int ***topol, double *effarr, int alloclen, LocalHom **localhomtable )
228 float pscore, tscore;
229 static char *indication1, *indication2;
231 static char name1[M][B], name2[M][B];
232 static double *effarr1 = NULL;
233 static double *effarr2 = NULL;
234 static LocalHom ***localhomshrink = NULL;
239 if( effarr1 == NULL )
241 effarr1 = AllocateDoubleVec( njob );
242 effarr2 = AllocateDoubleVec( njob );
243 indication1 = AllocateCharVec( 150 );
244 indication2 = AllocateCharVec( 150 );
249 localhomshrink = (LocalHom ***)calloc( njob, sizeof( LocalHom ** ) );
250 for( i=0; i<njob; i++)
251 localhomshrink[i] = (LocalHom **)calloc( njob, sizeof( LocalHom *) );
257 fprintf( stderr, "##### fftwinsize = %d, fftthreshold = %d\n", fftWinSize, fftThreshold );
261 for( i=0; i<njob; i++ )
262 fprintf( stderr, "TBFAST effarr[%d] = %f\n", i, effarr[i] );
265 for( i=0; i<njob; i++ ) strcpy( aseq[i], seq[i] );
268 calcimportance( njob, effarr, aseq, localhomtable );
271 writePre( njob, name, nlen, aseq, 0 );
274 for( l=0; l<njob-1; l++ )
277 clus1 = fastconjuction( topol[l][0], aseq, mseq1, effarr1, effarr, name, name1, indication1 );
278 clus2 = fastconjuction( topol[l][1], aseq, mseq2, effarr2, effarr, name, name2, indication2 );
281 fprintf( trap_g, "\nSTEP-%d\n", l );
282 fprintf( trap_g, "group1 = %s\n", indication1 );
283 fprintf( trap_g, "group2 = %s\n", indication2 );
286 fprintf( stderr, "STEP %d /%d\r", l+1, njob-1 );
288 fprintf( stderr, "STEP %d /%d\n", l+1, njob-1 );
289 fprintf( stderr, "group1 = %.66s", indication1 );
290 if( strlen( indication1 ) > 66 ) fprintf( stderr, "..." );
291 fprintf( stderr, "\n" );
292 fprintf( stderr, "group2 = %.66s", indication2 );
293 if( strlen( indication2 ) > 66 ) fprintf( stderr, "..." );
294 fprintf( stderr, "\n" );
296 // for( i=0; i<clus1; i++ ) fprintf( stderr, "## STEP%d-eff for mseq1-%d %f\n", l+1, i, effarr1[i] );
300 fastshrinklocalhom( topol[l][0], topol[l][1], localhomtable, localhomshrink );
301 // fprintf( stderr, "localhomshrink =\n" );
302 // outlocalhompt( localhomshrink, clus1, clus2 );
303 // weightimportance4( clus1, clus2, effarr1, effarr2, localhomshrink );
304 // fprintf( stderr, "after weight =\n" );
305 // outlocalhompt( localhomshrink, clus1, clus2 );
309 fprintf( stderr, "before align all\n" );
310 display( aseq, njob );
311 fprintf( stderr, "\n" );
312 fprintf( stderr, "before align 1 %s \n", indication1 );
313 display( mseq1, clus1 );
314 fprintf( stderr, "\n" );
315 fprintf( stderr, "before align 2 %s \n", indication2 );
316 display( mseq2, clus2 );
317 fprintf( stderr, "\n" );
320 if( constraint == 2 )
322 imp_match_init_strict( NULL, clus1, clus2, strlen( mseq1[0] ), strlen( mseq2[0] ), mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 );
323 pscore = A__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, localhomshrink, &dumfl );
327 pscore = Falign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen );
334 pscore = Aalign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen );
337 pscore = A__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, &dumfl );
340 if( outgap && ( clus1 == 1 && clus2 != 1 || clus1 != 1 && clus2 == 1 ) )
342 pscore = translate_and_Calign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen );
346 pscore = A__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, &dumfl );
350 ErrorExit( "ERROR IN SOURCE FILE" );
354 fprintf( stderr, "score = %10.2f\n", pscore );
358 fprintf( stderr, "after align 1 %s \n", indication1 );
359 display( mseq1, clus1 );
360 fprintf( stderr, "\n" );
361 fprintf( stderr, "after align 2 %s \n", indication2 );
362 display( mseq2, clus2 );
363 fprintf( stderr, "\n" );
366 writePre( njob, name, nlen, aseq, 0 );
368 if( disp ) display( aseq, njob );
371 fprintf( stderr, "totalscore = %10.2f\n\n", tscore );
375 static void WriteOptions( FILE *fp )
378 if( dorp == 'd' ) fprintf( fp, "DNA\n" );
381 if ( scoremtx == 0 ) fprintf( fp, "JTT %dPAM\n", pamN );
382 else if( scoremtx == 1 ) fprintf( fp, "BLOSUM %d\n", nblosum );
383 else if( scoremtx == 2 ) fprintf( fp, "M-Y\n" );
385 fprintf( stderr, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
386 if( use_fft ) fprintf( fp, "FFT on\n" );
388 fprintf( fp, "tree-base method\n" );
389 if( tbrweight == 0 ) fprintf( fp, "unweighted\n" );
390 else if( tbrweight == 3 ) fprintf( fp, "clustalw-like weighting\n" );
391 if( tbitr || tbweight )
393 fprintf( fp, "iterate at each step\n" );
394 if( tbitr && tbrweight == 0 ) fprintf( fp, " unweighted\n" );
395 if( tbitr && tbrweight == 3 ) fprintf( fp, " reversely weighted\n" );
396 if( tbweight ) fprintf( fp, " weighted\n" );
400 fprintf( fp, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
403 fprintf( fp, "Algorithm A\n" );
404 else if( alg == 'A' )
405 fprintf( fp, "Algorithm A+\n" );
406 else if( alg == 'S' )
407 fprintf( fp, "Apgorithm S\n" );
408 else if( alg == 'C' )
409 fprintf( fp, "Apgorithm A+/C\n" );
411 fprintf( fp, "Unknown algorithm\n" );
413 if( treemethod == 'x' )
414 fprintf( fp, "Tree = UPGMA (3).\n" );
415 else if( treemethod == 's' )
416 fprintf( fp, "Tree = UPGMA (2).\n" );
417 else if( treemethod == 'p' )
418 fprintf( fp, "Tree = UPGMA (1).\n" );
420 fprintf( fp, "Unknown tree.\n" );
424 fprintf( fp, "FFT on\n" );
426 fprintf( fp, "Basis : 4 nucleotides\n" );
430 fprintf( fp, "Basis : Polarity and Volume\n" );
432 fprintf( fp, "Basis : 20 amino acids\n" );
434 fprintf( fp, "Threshold of anchors = %d%%\n", fftThreshold );
435 fprintf( fp, "window size of anchors = %dsites\n", fftWinSize );
438 fprintf( fp, "FFT off\n" );
443 int main( int argc, char *argv[] )
446 static char name[M][B], **seq;
447 static char **mseq1, **mseq2;
450 static double **iscore;
463 LocalHom **localhomtable;
466 arguments( argc, argv );
470 infp = fopen( inputfile, "r" );
473 fprintf( stderr, "Cannot open %s\n", inputfile );
486 fprintf( stderr, "At least 2 sequences should be input!\n"
487 "Only %d sequence found.\n", njob );
491 seq = AllocateCharMtx( njob, nlenmax*9+1 );
492 aseq = AllocateCharMtx( njob, nlenmax*9+1 );
493 bseq = AllocateCharMtx( njob, nlenmax*9+1 );
494 mseq1 = AllocateCharMtx( njob, 0 );
495 mseq2 = AllocateCharMtx( njob, 0 );
496 alloclen = nlenmax*9;
498 topol = AllocateIntCub( njob, 2, njob );
499 len = AllocateDoubleMtx( njob, 2 );
500 iscore = AllocateDoubleMtx( njob, njob );
501 eff = AllocateDoubleVec( njob );
504 localhomtable = (LocalHom **)calloc( njob, sizeof( LocalHom *) );
505 for( i=0; i<njob; i++)
507 localhomtable[i] = (LocalHom *)calloc( njob, sizeof( LocalHom ) );
508 for( j=0; j<njob; j++)
510 localhomtable[i][j].nokori = 0;
511 localhomtable[i][j].start1 = -1;
512 localhomtable[i][j].end1 = -1;
513 localhomtable[i][j].start2 = -1;
514 localhomtable[i][j].end2 = -1;
515 localhomtable[i][j].overlapaa = -1.0;
516 localhomtable[i][j].opt = -1.0;
517 localhomtable[i][j].importance = -1.0;
518 localhomtable[i][j].next = NULL;
519 localhomtable[i][j].extended = -1;
520 localhomtable[i][j].last = localhomtable[i]+j;
524 fprintf( stderr, "Loading 'hat3' ... " );
525 prep = fopen( "hat3", "r" );
526 if( prep == NULL ) ErrorExit( "Make hat3." );
527 readlocalhomtable2( prep, njob, localhomtable );
529 fprintf( stderr, "done.\n" );
532 for( i=0; i<njob; i++ )
533 for( j=0; j<njob; j++ )
534 fprintf( stderr, "[%d][%d].nokori = %d\n", i, j, localhomtable[i][j].nokori );
537 // outlocalhom( localhomtable, njob );
545 Read( name, nlen, seq );
547 readData( infp, name, nlen, seq );
551 constants( njob, seq );
554 fprintf( stderr, "params = %d, %d, %d\n", penalty, penalty_ex, offset );
561 WriteOptions( trap_g );
566 fprintf( stderr, "Illeagal character %c\n", c );
570 writePre( njob, name, nlen, seq, 0 );
574 for( i=1; i<njob; i++ )
576 if( nlen[i] != nlen[0] )
578 fprintf( stderr, "Input pre-aligned seqences or make hat2.\n" );
582 for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ )
585 pscore[i][j] = (double)score_calc1( seq[i], seq[j] );
587 iscore[i][j] = (double)( substitution_hosei( seq[i], seq[j] ) );
592 fprintf( stderr, "Loading 'hat2' ... " );
593 prep = fopen( "hat2", "r" );
594 if( prep == NULL ) ErrorExit( "Make hat2." );
595 readhat2( prep, njob, name, iscore );
597 fprintf( stderr, "done.\n" );
600 prep = fopen( "hat2_check", "w" );
601 WriteHat2( prep, njob, name, pscore );
608 for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ )
609 iscore[j][i] = iscore[i][j];
612 fprintf( stderr, "Constructing dendrogram ... " );
613 if( treemethod == 'x' )
614 veryfastsupg( njob, iscore, topol, len );
615 else if( treemethod == 's' )
616 spg( njob, iscore, topol, len );
617 else if( treemethod == 'p' )
618 upg2( njob, iscore, topol, len );
620 ErrorExit( "Incorrect tree\n" );
621 fprintf( stderr, "done.\n" );
623 orderfp = fopen( "order", "w" );
626 fprintf( stderr, "Cannot open 'order'\n" );
629 for( i=0; (j=topol[njob-2][0][i])!=-1; i++ )
631 fprintf( orderfp, "%d\n", j );
633 for( i=0; (j=topol[njob-2][1][i])!=-1; i++ )
635 fprintf( orderfp, "%d\n", j );
640 // countnode( njob, topol, node0 );
645 utree = 0; counteff( njob, topol, len, eff ); utree = 1;
647 counteff_simple( njob, topol, len, eff );
652 for( i=0; i<njob; i++ ) eff[i] = 1.0;
660 fprintf( stderr, "Extending localhom ... " );
661 extendlocalhom2( njob, localhomtable, iscore );
662 fprintf( stderr, "done.\n" );
664 for( i=0; i<njob-1; i++ )
666 for( j=i+1; j<njob; j++ )
668 if( i == j ) continue;
669 if( localhomtable[i][j]->opt == -1.0 ) continue;
670 for( tmpptr=localhomtable[i]+j; tmpptr; tmpptr=tmpptr->next )
676 // resetlocalhom( njob, localhomtable ); // chuui !!!
678 fprintf( stderr, "##### writing hat4, nlenmax = %d\n", nlenmax );
679 hat3p = fopen( "hat4", "w" );
680 if( !hat3p ) ErrorExit( "Cannot open hat4." );
681 for( i=0; i<njob-1; i++ )
683 for( j=i+1; j<njob; j++ )
685 if( i == j ) continue;
686 for( tmpptr=localhomtable[i]+j; tmpptr; tmpptr=tmpptr->next )
688 fprintf( hat3p, "%d %d %d %6.3f %d %d %d %d %p nokori=%d ext=%d\n", i, j, tmpptr->overlapaa, tmpptr->opt * 5.8 / 600, tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2, tmpptr->next, tmpptr->nokori, tmpptr->extended );
690 if( tmpptr->opt == -1.0 ) continue;
695 fprintf( stderr, "done.\n" );
699 FreeDoubleMtx( len );
700 FreeDoubleMtx( iscore );
702 for( i=0; i<njob; i++ ) gappick0( bseq[i], seq[i] );
704 treebase( name, nlen, bseq, aseq, mseq1, mseq2, topol, eff, alloclen, localhomtable );
710 LocalHom *tmppt1, *tmppt2;
711 for( i=0; i<njob; i++)
713 for( j=0; j<njob; j++)
715 tmppt1 = localhomtable[i]+j;
716 while( tmppt2 = tmppt1->next )
718 free( (void *)tmppt1 );
721 free( (void *)tmppt1 );
723 free( (void *)(localhomtable[i]+j) );
725 free( (void *)localhomtable );
729 fprintf( trap_g, "done.\n" );
732 writePre( njob, name, nlen, aseq, !contin );
734 writeData( stdout, njob, name, nlen, aseq );
737 fprintf( stderr, "OSHIMAI\n" );
740 if( constraint ) FreeLocalHomTable( localhomtable, njob );