8 int howmanyx( char *s )
15 if( !strchr( "atgcuATGCU", *s ) ) val++;
22 if( !strchr( "ARNDCQEGHILKMFPSTWYV", *s ) ) val++;
28 void arguments( int argc, char *argv[] )
37 while( --argc > 0 && (*++argv)[0] == '-' )
39 while ( (c = *++argv[0]) )
45 fprintf( stderr, "inputfile = %s\n", inputfile );
55 fprintf( stderr, "illegal option %c\n", c );
65 fprintf( stderr, "options: -i\n" );
70 int main( int argc, char *argv[] )
77 char **seq = NULL; // by D.Mathog
79 static char name[M][B];
80 static char name1[M][B];
96 int pid = (int)getpid();
97 LocalHom **localhomtable, *tmpptr;
99 home = getenv( "HOME" );
100 #else /* $HOME wo tsukau to fasta ni watasu hikisuu ga afureru */
103 fastapath = getenv( "FASTA_4_MAFFT" );
105 fastapath = "fasta34";
108 if( home ) fprintf( stderr, "home = %s\n", home );
110 if( !home ) home = "";
111 sprintf( queryfile, "%s/tmp/query-%d", home, pid );
112 sprintf( datafile, "%s/tmp/data-%d", home, pid );
113 sprintf( fastafile, "%s/tmp/fasta-%d", home, pid );
114 sprintf( hat2file, "hat2-%d", pid );
117 arguments( argc, argv );
121 infp = fopen( inputfile, "r" );
124 fprintf( stderr, "Cannot open %s\n", inputfile );
134 PreRead( stdin, &njob, &nlenmax );
150 constants( njob, seq );
154 seq = AllocateCharMtx( njob, nlenmax+1 );
155 seq1 = AllocateCharMtx( 2, nlenmax+1 );
156 mtx = AllocateDoubleMtx( njob, njob );
157 mtx2 = AllocateDoubleMtx( njob, njob );
158 localhomtable = (LocalHom **)calloc( njob, sizeof( LocalHom *) );
159 for( i=0; i<njob; i++)
161 localhomtable[i] = (LocalHom *)calloc( njob, sizeof( LocalHom ) );
162 for( j=0; j<njob; j++)
164 localhomtable[i][j].start1 = -1;
165 localhomtable[i][j].end1 = -1;
166 localhomtable[i][j].start2 = -1;
167 localhomtable[i][j].end2 = -1;
168 localhomtable[i][j].opt = -1.0;
169 localhomtable[i][j].next = NULL;
174 FRead( infp, name, nlen, seq );
176 readData( infp, name, nlen, seq );
180 if( scoremtx == -1 ) ktuple = 6;
183 for( i=0; i<njob; i++ )
185 gappick0( seq1[0], seq[i] );
186 strcpy( seq[i], seq1[0] );
188 for( j=0; j<njob; j++ )
190 sprintf( name1[j], "+==========+%d ", j );
193 hat2p = fopen( datafile, "w" );
194 if( !hat2p ) ErrorExit( "Cannot open datafile." );
195 WriteForFasta( hat2p, njob, name1, nlen1, seq );
198 for( i=0; i<njob; i++ )
200 // fprintf( stderr, "### i = %d\n", i );
201 hat2p = fopen( datafile, "w" );
202 if( !hat2p ) ErrorExit( "Cannot open datafile." );
203 WriteForFasta( hat2p, njob-i, name1+i, nlen1+i, seq+i );
209 hat2p = fopen( queryfile, "w" );
210 if( !hat2p ) ErrorExit( "Cannot open queryfile." );
211 WriteForFasta( hat2p, 1, name1+i, nlen1, seq1 );
216 sprintf( com, "%s %s -z3 -m10 -n -Q -b%d -E%d -d%d %s %s %d > %s", fastapath, swopt, M, M, M, queryfile, datafile, ktuple, fastafile );
218 sprintf( com, "%s %s -z3 -m10 -Q -b%d -E%d -d%d %s %s %d > %s", fastapath, swopt, M, M, M, queryfile, datafile, ktuple, fastafile );
220 if( res ) ErrorExit( "error in fasta" );
224 hat2p = fopen( fastafile, "r" );
226 ErrorExit( "file 'fasta.$$' does not exist\n" );
228 res = ReadFasta34m10_nuc( hat2p, mtx[i], i, name1, localhomtable[i] );
230 res = ReadFasta34m10( hat2p, mtx[i], i, name1, localhomtable[i] );
235 fprintf( stderr, "count (fasta34 -z 3) = %d\n", res );
241 for( j=0; j<njob; j++ ) opt[j] = (int)mtx[0][j];
247 if( i < njob-1 ) for( jj=i; jj<i+5; jj++ )
248 fprintf( stdout, "mtx[%d][%d] = %f\n", i+1, jj+1, mtx[i][jj] );
251 fprintf( stderr, "query : %4d / %5d\r", i+1, njob );
254 for( i=0; i<njob; i++ )
259 for( j=0; j<njob; j++ )
264 for( j=0; j<njob; j++ )
266 // fprintf( stderr, "##### mtx[%d][%d] = %f\n", i, j, mtx[i][j] );
267 mtx2[i][j] = ( max - mtx[MIN(i,j)][MAX(i,j)] ) / max * 2.0;
268 // fprintf( stdout, "max = %f, mtx[%d][%d] = %f -> %f\n", max, i+1, j+1, mtx[i][j], mtx2[i][j] );
272 for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ )
274 // fprintf( stdout, "mtx2[%d][%d] = %f, %f\n", i+1, j+1, mtx2[i][j], mtx2[j][i] );
275 mtx2[i][j] = MIN( mtx2[i][j], mtx2[j][i] );
281 if( i < njob-1 ) for( jj=i+1; jj<njob; jj++ )
282 fprintf( stderr, "mtx2[][] = %f\n", mtx2[i][jj] );
286 for( i=0; i<njob; i++ ) name[i][0] = '=';
290 strcpy( b, name[0] );
291 sprintf( name[0], "=query====lgth=%04d-%04d %.*s", nlen[0], howmanyx( seq[0] ), B-30, b );
293 strins( b, name[0] );
295 for( i=1; i<njob; i++ )
297 strcpy( b, name[i] );
298 sprintf( name[i], "=opt=%04d=lgth=%04d-%04d %.*s", opt[i], nlen[i], howmanyx( seq[i] ), B-30, b );
300 strins( b, name[i] );
305 hat2p = fopen( hat2file, "w" );
306 if( !hat2p ) ErrorExit( "Cannot open hat2." );
307 WriteHat2( hat2p, njob, name, mtx2 );
311 fprintf( stderr, "##### writing hat3\n" );
312 hat3p = fopen( "hat3", "w" );
313 if( !hat3p ) ErrorExit( "Cannot open hat3." );
314 for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ )
316 for( tmpptr=localhomtable[i]+j; tmpptr; tmpptr=tmpptr->next )
318 if( tmpptr->opt == -1.0 ) continue;
319 fprintf( hat3p, "%d %d %d %6.3f %d %d %d %d %p\n", i, j, tmpptr->overlapaa, tmpptr->opt, tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2, (void *)tmpptr->next );
325 sprintf( com, "/bin/rm %s %s %s", queryfile, datafile, fastafile );
329 sprintf( com, ALNDIR "/supgsdl < %s", hat2file );
331 if( res ) ErrorExit( "error in spgsdl" );
334 sprintf( com, "mv %s hat2", hat2file );
336 if( res ) ErrorExit( "error in mv" );