5 static int intcmp( int *str1, int *str2 )
7 while( *str1 != -1 && *str2 != -1 )
8 if( *str1++ != *str2++ ) return( 1 );
9 if( *str1 != *str2 ) return( 1 );
13 char **arguments( int argc, char *argv[] )
39 ppenalty = NOTSPECIFIED;
40 ppenalty_ex = NOTSPECIFIED;
41 poffset = NOTSPECIFIED;
42 kimuraR = NOTSPECIFIED;
44 fftWinSize = NOTSPECIFIED;
45 fftThreshold = NOTSPECIFIED;
50 while( --argc > 0 && (*++argv)[0] == '-' )
52 while ( c = *++argv[0] )
87 fftThreshold = atoi( *++argv );
91 fftWinSize = atoi( *++argv );
98 ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
99 fprintf( stderr, "ppenalty = %d\n", ppenalty );
103 ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 );
104 fprintf( stderr, "ppenalty_ex = %d\n", ppenalty_ex );
108 poffset = (int)( atof( *++argv ) * 1000 - 0.5 );
109 fprintf( stderr, "poffset = %d\n", poffset );
113 kimuraR = atoi( *++argv );
114 fprintf( stderr, "kimuraR = %d\n", kimuraR );
118 nblosum = atoi( *++argv );
120 fprintf( stderr, "blosum %d\n", nblosum );
124 pamN = atoi( *++argv );
127 fprintf( stderr, "jtt %d\n", pamN );
131 pamN = atoi( *++argv );
134 fprintf( stderr, "tm %d\n", pamN );
138 fprintf( stderr, "illegal option %c\n", c );
148 fprintf( stderr, "options: Check source file ! %c ?\n", c );
151 fprintf( stderr, "tbitr = %d, tbrweight = %d, tbweight = %d\n", tbitr, tbrweight, tbweight );
152 // readOtherOptions( &ppid, &fftThreshold, &fftWinSize );
157 static 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 )
164 static char **name1, **name2;
165 double *effarr = eff;
166 double *effarr1 = NULL;
167 double *effarr2 = NULL;
168 static char *indication1, *indication2;
172 fprintf( stderr, "in GroupAlign fftWinSize = %d\n", fftWinSize );
173 fprintf( stderr, "in GroupAlign fftThreshold = %d\n", fftThreshold );
175 if( effarr1 == NULL )
177 name1 = AllocateCharMtx( nseq1, B );
178 name2 = AllocateCharMtx( nseq2, B );
179 indication1 = AllocateCharVec( 150 );
180 indication2 = AllocateCharVec( 150 );
181 effarr1 = AllocateDoubleVec( njob );
182 effarr2 = AllocateDoubleVec( njob );
188 for( i=0; i<njob; i++ ) strcpy( aseq[i], seq[i] );
194 // fprintf( stdout, "nseq1 = %d\n", nseq1 );
198 clus1 = conjuctionforgaln( 0, nseq1, aseq, mseq1, effarr1, effarr, name, name1, indication1 );
199 clus2 = conjuctionforgaln( nseq1, njob, aseq, mseq2, effarr2, effarr, name, name2, indication2 );
201 fprintf( stderr, "before align all\n" );
202 display( aseq, njob );
203 fprintf( stderr, "\n" );
204 fprintf( stderr, "before align 1 %s \n", indication1 );
205 display( mseq1, clus1 );
206 fprintf( stderr, "\n" );
207 fprintf( stderr, "before align 2 %s \n", indication2 );
208 display( mseq2, clus2 );
209 fprintf( stderr, "\n" );
215 pscore = Falign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen );
220 pscore = MSalignmm( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen );
222 pscore = A__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, &dumfl );
227 fprintf( stderr, "after align 1 %s \n", indication1 );
228 display( mseq1, clus1 );
229 fprintf( stderr, "\n" );
230 fprintf( stderr, "after align 2 %s \n", indication2 );
231 display( mseq2, clus2 );
232 fprintf( stderr, "\n" );
235 fprintf( stderr, "group-to-group %s /%s %f\n", indication1, indication2, pscore );
236 if( disp ) display( aseq, njob );
237 fprintf( stderr, "\n" );
240 trap = fopen( "pre", "r+" );
241 if( !trap ) ErrorExit( 1 );
242 WriteGapFill( trap, njob, name, nlen, aseq );
244 fprintf( stdout, "nseq1 = %d\n", nseq1 );
248 static void WriteOptions( FILE *fp )
250 fprintf( fp, "tree-base method\n" );
251 if( tbweight == 0 ) fprintf( fp, "unweighted\n" );
252 else if( tbweight == 3 ) fprintf( fp, "reversely weighted\n" );
253 if ( scoremtx == 0 ) fprintf( fp, "JTT %dPAM\n", pamN );
254 else if( scoremtx == 1 ) fprintf( fp, "Dayhoff( machigai ga aru )\n" );
255 else if( scoremtx == 2 ) fprintf( fp, "M-Y\n" );
256 else if( scoremtx == -1 ) fprintf( fp, "DNA\n" );
259 fprintf( fp, "Gap Penalty = %d, %d\n", penalty, offset );
261 fprintf( fp, "Gap Penalty = %d\n", penalty );
265 int main( int argc, char *argv[] )
269 static char **name, **seq;
270 static char **seq1, **seq2;
271 static char **mseq1, **mseq2;
274 static double **pscore;
283 int nlenmax1, nlenmax2, nseq1, nseq2;
286 argv2 = arguments( argc, argv );
288 fprintf( stderr, "####### in galn\n" );
292 fprintf( stderr, "file1 = %s\n", argv2[0] );
293 fprintf( stderr, "file2 = %s\n", argv2[1] );
295 gp1 = fopen( argv2[0], "r" ); if( !gp1 ) ErrorExit( "cannot open file1" );
296 gp2 = fopen( argv2[1], "r" ); if( !gp2 ) ErrorExit( "cannot open file2" );
299 PreRead( gp1, &nseq1, &nlenmax1 );
300 PreRead( gp2, &nseq2, &nlenmax2 );
303 nseq1 = njob; nlenmax1 = nlenmax;
305 nseq2 = njob; nlenmax2 = nlenmax;
308 njob = nseq1 + nseq2;
309 nlenmax = MAX( nlenmax1, nlenmax2 );
316 fprintf( stderr, "ERROR in main\n" );
320 name = AllocateCharMtx( njob, B );
321 nlen = AllocateIntVec( njob );
322 seq1 = AllocateCharMtx( nseq1, nlenmax*3 );
323 seq2 = AllocateCharMtx( nseq2, nlenmax*3 );
324 seq = AllocateCharMtx( njob, 1 );
325 aseq = AllocateCharMtx( njob, nlenmax*3 );
326 bseq = AllocateCharMtx( njob, nlenmax*3 );
327 mseq1 = AllocateCharMtx( njob, 1 );
328 mseq2 = AllocateCharMtx( njob, 1 );
329 alloclen = nlenmax * 3;
331 topol = AllocateIntCub( njob, 2, njob );
332 len = AllocateDoubleMtx( njob, 2 );
333 pscore = AllocateDoubleMtx( njob, njob );
334 eff = AllocateDoubleVec( njob );
337 njob=nseq2; FRead( gp2, name+nseq1, nlen+nseq1, seq2 );
338 njob=nseq1; FRead( gp1, name, nlen, seq1 );
340 njob=nseq2; readDataforgaln( gp2, name+nseq1, nlen+nseq1, seq2 );
341 njob=nseq1; readDataforgaln( gp1, name, nlen, seq1 );
343 njob = nseq1 + nseq2;
347 commongappick( nseq1, seq1 );
348 commongappick( nseq2, seq2 );
350 for( i=0; i<nseq1; i++ ) seq[i] = seq1[i];
351 for( i=nseq1; i<njob; i++ ) seq[i] = seq2[i-nseq1];
353 Write( stdout, njob, name, nlen, seq );
356 constants( njob, seq );
358 WriteOptions( trap_g );
363 fprintf( stderr, "Illeagal character %c\n", c );
366 for( i=1; i<nseq1; i++ )
368 if( nlen[i] != nlen[0] )
369 ErrorExit( "group1 is not aligned." );
371 for( i=nseq1+1; i<njob; i++ )
373 if( nlen[i] != nlen[nseq1] )
374 ErrorExit( "group2 is not aligned." );
378 for( i=0; i<nseq1-1; i++ )
380 for( j=i+1; j<nseq1; j++ )
381 pscore[i][j] = (double)substitution_hosei( seq[i], seq[j] );
382 for( j=nseq1; j<njob; j++ )
385 for( i=nseq1; i<njob-1; i++ )
387 for( j=i+1; j<njob; j++ )
388 pscore[i][j] = (double)substitution_hosei( seq[i], seq[j] );
393 fprintf( stderr, "Not supported\n" );
396 prep = fopen( "hat2", "r" );
397 if( prep == NULL ) ErrorExit( "Make hat2." );
398 readhat2( prep, njob, name, pscore );
402 fprintf( stderr, "Constructing dendrogram ... " );
403 if( treemethod == 'x' )
404 veryfastsupg( njob, pscore, topol, len );
406 ErrorExit( "Incorrect tree\n" );
407 fprintf( stderr, "done.\n" );
412 counteff_simple( njob, topol, len, eff );
416 for( i=0; i<njob; i++ ) eff[i] = 1.0;
419 GroupAlign( nseq1, nseq2, name, nlen, seq, aseq, mseq1, mseq2, topol, len, eff, alloclen );
422 writePre( njob, name, nlen, aseq, 1 );
424 writeDataforgaln( stdout, njob, name, nlen, aseq );