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, **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 name = AllocateCharMtx( njob, B+1 );
317 oseq = AllocateCharMtx( njob, nlenmax*9+1 );
318 alloclen = nlenmax*9;
320 topol = AllocateIntCub( njob, 2, njob );
321 len = AllocateDoubleMtx( njob, 2 );
322 pscore = AllocateDoubleMtx( njob, njob );
323 eff = AllocateDoubleVec( njob );
324 node0 = AllocateDoubleMtx( njob, njob );
325 node1 = AllocateDoubleMtx( njob, njob );
326 gapc = AllocateDoubleVec( alloclen );
327 avgap = AllocateDoubleVec( alloclen );
330 Read( name, nlen, seq );
332 readData_pointer( stdin, name, nlen, seq );
335 constants( njob, seq );
338 fprintf( stderr, "params = %d, %d, %d\n", penalty, penalty_ex, offset );
345 WriteOptions( trap_g );
350 fprintf( stderr, "Illeagal character %c\n", c );
354 writePre( njob, name, nlen, seq, 0 );
358 for( i=1; i<njob; i++ )
360 if( nlen[i] != nlen[0] )
362 fprintf( stderr, "Input pre-aligned seqences or make hat2.\n" );
366 for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ )
369 pscore[i][j] = (double)score_calc1( seq[i], seq[j] );
371 pscore[i][j] = (double)substitution_hosei( seq[i], seq[j] );
376 fprintf( stderr, "Loading 'hat2' ... " );
377 prep = fopen( "hat2", "r" );
378 if( prep == NULL ) ErrorExit( "Make hat2." );
379 readhat2_pointer( prep, njob, name, pscore );
381 fprintf( stderr, "done.\n" );
384 prep = fopen( "hat2_check", "w" );
385 WriteHat2( prep, njob, name, pscore );
391 fprintf( stderr, "Constructing dendrogram ... " );
392 if( treemethod == 'x' )
393 supg( njob, pscore, topol, len );
394 else if( treemethod == 's' )
395 spg( njob, pscore, topol, len );
396 else if( treemethod == 'p' )
397 upg2( njob, pscore, topol, len );
399 ErrorExit( "Incorrect tree\n" );
400 fprintf( stderr, "done.\n" );
402 countnode( njob, topol, node0 );
407 utree = 0; counteff( njob, topol, len, eff ); utree = 1;
409 counteff_simple( njob, topol, len, eff );
414 for( i=0; i<njob; i++ ) eff[i] = 1.0;
418 for( i=0; i<nlenmax; i++ )
421 for( j=0; j<njob; j++ )
423 if( seq[j][i] == '-' ) gapc[i] += eff[j];
428 winsize = fftWinSize;
431 corestart = coreend = -1;
432 for( i=0; i<winsize; i++ )
436 for( i=winsize; i<nlenmax; i++ )
439 avgap[m] = tmpavgap / winsize;
440 // fprintf( stdout, "%d %f %f\n", m, avgap[m], gapc[i] );
441 if( avgap[m] < corethr )
443 if( corestart == -1 )
444 corestart = i - winsize;
445 // fprintf( stdout, "ok, gapmin = %f, corestart = %d, coreend = %d\n", gapmin, corestart, coreend );
446 if( avgap[m] < gapmin )
452 tmpavgap -= gapc[i-winsize];
455 if( corestart == -1 || coreend == -1 )
461 for( i=0; i<njob; i++ )
465 while( m-- ) *pt++ = '-';
466 for( j=corestart; j<=coreend; j++ )
469 while( m-- ) *pt++ = '-';
472 ot = oseq[i]+winsize-1;
473 pt = seq[i]+corestart-1;
474 if( coreext ) m = winsize;
476 while( m && --pt > seq[i] )
483 ot = oseq[i]+winsize+coreend-corestart+1;
485 if( coreext ) m = winsize;
487 while( m && *(++pt) )
495 fprintf( stdout, ">%s\n", name[i] );
496 fprintf( stdout, "%s\n", oseq[i] );