10 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;
55 while( --argc > 0 && (*++argv)[0] == '-' )
57 while ( ( c = *++argv[0] ) )
62 ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
63 fprintf( stderr, "ppenalty = %d\n", ppenalty );
67 ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 );
68 fprintf( stderr, "ppenalty_ex = %d\n", ppenalty_ex );
72 poffset = (int)( atof( *++argv ) * 1000 - 0.5 );
73 fprintf( stderr, "poffset = %d\n", poffset );
77 kimuraR = atoi( *++argv );
78 fprintf( stderr, "kimuraR = %d\n", kimuraR );
82 nblosum = atoi( *++argv );
84 fprintf( stderr, "blosum %d\n", nblosum );
88 pamN = atoi( *++argv );
90 fprintf( stderr, "jtt %d\n", pamN );
94 fastathreshold = atof( *++argv );
96 fprintf( stderr, "weighti = %f\n", fastathreshold );
100 corethr = atof( *++argv );
101 fprintf( stderr, "corethr = %f\n", corethr );
164 /* Modified 01/08/27, default: user tree */
168 /* modification end. */
170 fftThreshold = atoi( *++argv );
174 fftWinSize = atoi( *++argv );
181 fprintf( stderr, "illegal option %c\n", c );
191 cut = atof( (*argv) );
196 fprintf( stderr, "options: Check source file !\n" );
199 if( tbitr == 1 && outgap == 0 )
201 fprintf( stderr, "conflicting options : o, m or u\n" );
204 if( alg == 'C' && outgap == 0 )
206 fprintf( stderr, "conflicting options : C, o\n" );
213 static void WriteOptions( FILE *fp )
216 if( dorp == 'd' ) fprintf( fp, "DNA\n" );
219 if ( scoremtx == 0 ) fprintf( fp, "JTT %dPAM\n", pamN );
220 else if( scoremtx == 1 ) fprintf( fp, "BLOSUM %d\n", nblosum );
221 else if( scoremtx == 2 ) fprintf( fp, "M-Y\n" );
223 fprintf( stderr, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
224 if( use_fft ) fprintf( fp, "FFT on\n" );
226 fprintf( fp, "tree-base method\n" );
227 if( tbrweight == 0 ) fprintf( fp, "unweighted\n" );
228 else if( tbrweight == 3 ) fprintf( fp, "clustalw-like weighting\n" );
229 if( tbitr || tbweight )
231 fprintf( fp, "iterate at each step\n" );
232 if( tbitr && tbrweight == 0 ) fprintf( fp, " unweighted\n" );
233 if( tbitr && tbrweight == 3 ) fprintf( fp, " reversely weighted\n" );
234 if( tbweight ) fprintf( fp, " weighted\n" );
238 fprintf( fp, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
241 fprintf( fp, "Algorithm A\n" );
242 else if( alg == 'A' )
243 fprintf( fp, "Algorithm A+\n" );
244 else if( alg == 'S' )
245 fprintf( fp, "Apgorithm S\n" );
246 else if( alg == 'C' )
247 fprintf( fp, "Apgorithm A+/C\n" );
249 fprintf( fp, "Unknown algorithm\n" );
251 if( treemethod == 'x' )
252 fprintf( fp, "Tree = UPGMA (3).\n" );
253 else if( treemethod == 's' )
254 fprintf( fp, "Tree = UPGMA (2).\n" );
255 else if( treemethod == 'p' )
256 fprintf( fp, "Tree = UPGMA (1).\n" );
258 fprintf( fp, "Unknown tree.\n" );
262 fprintf( fp, "FFT on\n" );
264 fprintf( fp, "Basis : 4 nucleotides\n" );
268 fprintf( fp, "Basis : Polarity and Volume\n" );
270 fprintf( fp, "Basis : 20 amino acids\n" );
272 fprintf( fp, "Threshold of anchors = %d%%\n", fftThreshold );
273 fprintf( fp, "window size of anchors = %dsites\n", fftWinSize );
276 fprintf( fp, "FFT off\n" );
281 int main( int argc, char *argv[] )
284 static char name[M][B], **seq;
286 static double **pscore;
288 static double **node0, **node1;
290 static double *avgap;
292 int i, j, m, goffset;
297 int corestart, coreend;
303 arguments( argc, argv );
310 fprintf( stderr, "At least 2 sequences should be input!\n"
311 "Only %d sequence found.\n", njob );
315 seq = AllocateCharMtx( njob, nlenmax*9+1 );
316 oseq = AllocateCharMtx( njob, nlenmax*9+1 );
317 alloclen = nlenmax*9;
319 topol = AllocateIntCub( njob, 2, njob );
320 len = AllocateDoubleMtx( njob, 2 );
321 pscore = AllocateDoubleMtx( njob, njob );
322 eff = AllocateDoubleVec( njob );
323 node0 = AllocateDoubleMtx( njob, njob );
324 node1 = AllocateDoubleMtx( njob, njob );
325 gapc = AllocateDoubleVec( alloclen );
326 avgap = AllocateDoubleVec( alloclen );
329 Read( name, nlen, seq );
331 readData( stdin, name, nlen, seq );
334 constants( njob, seq );
337 fprintf( stderr, "params = %d, %d, %d\n", penalty, penalty_ex, offset );
344 WriteOptions( trap_g );
349 fprintf( stderr, "Illeagal character %c\n", c );
353 writePre( njob, name, nlen, seq, 0 );
357 for( i=1; i<njob; i++ )
359 if( nlen[i] != nlen[0] )
361 fprintf( stderr, "Input pre-aligned seqences or make hat2.\n" );
365 for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ )
368 pscore[i][j] = (double)score_calc1( seq[i], seq[j] );
370 pscore[i][j] = (double)substitution_hosei( seq[i], seq[j] );
375 fprintf( stderr, "Loading 'hat2' ... " );
376 prep = fopen( "hat2", "r" );
377 if( prep == NULL ) ErrorExit( "Make hat2." );
378 readhat2( prep, njob, name, pscore );
380 fprintf( stderr, "done.\n" );
383 prep = fopen( "hat2_check", "w" );
384 WriteHat2( prep, njob, name, pscore );
390 fprintf( stderr, "Constructing dendrogram ... " );
391 if( treemethod == 'x' )
392 supg( njob, pscore, topol, len );
393 else if( treemethod == 's' )
394 spg( njob, pscore, topol, len );
395 else if( treemethod == 'p' )
396 upg2( njob, pscore, topol, len );
398 ErrorExit( "Incorrect tree\n" );
399 fprintf( stderr, "done.\n" );
401 countnode( njob, topol, node0 );
406 utree = 0; counteff( njob, topol, len, eff ); utree = 1;
408 counteff_simple( njob, topol, len, eff );
413 for( i=0; i<njob; i++ ) eff[i] = 1.0;
417 for( i=0; i<nlenmax; i++ )
420 for( j=0; j<njob; j++ )
422 if( seq[j][i] == '-' ) gapc[i] += eff[j];
427 winsize = fftWinSize;
430 corestart = coreend = -1;
431 for( i=0; i<winsize; i++ )
435 for( i=winsize; i<nlenmax; i++ )
438 avgap[m] = tmpavgap / winsize;
439 // fprintf( stdout, "%d %f %f\n", m, avgap[m], gapc[i] );
440 if( avgap[m] < corethr )
442 if( corestart == -1 )
443 corestart = i - winsize;
444 // fprintf( stdout, "ok, gapmin = %f, corestart = %d, coreend = %d\n", gapmin, corestart, coreend );
445 if( avgap[m] < gapmin )
451 tmpavgap -= gapc[i-winsize];
454 if( corestart == -1 || coreend == -1 )
460 for( i=0; i<njob; i++ )
464 while( m-- ) *pt++ = '-';
465 for( j=corestart; j<=coreend; j++ )
468 while( m-- ) *pt++ = '-';
471 ot = oseq[i]+winsize-1;
472 pt = seq[i]+corestart-1;
473 if( coreext ) m = winsize;
475 while( m && --pt > seq[i] )
482 ot = oseq[i]+winsize+coreend-corestart+1;
484 if( coreext ) m = winsize;
486 while( m && *(++pt) )
494 fprintf( stdout, ">%s\n", name[i] );
495 fprintf( stdout, "%s\n", oseq[i] );