12 void arguments( int argc, char *argv[] )
22 while( --argc > 0 && (*++argv)[0] == '-' )
24 while ( ( c = *++argv[0] ) )
30 fprintf( stderr, "inputfile = %s\n", inputfile );
43 fprintf( stderr, "illegal option %c\n", c );
53 fprintf( stderr, "options: -i\n" );
58 void seq_grp_nuc( int *grp, char *seq )
63 tmp = amino_grp[(int)*seq++];
67 fprintf( stderr, "WARNING : Unknown character %c\n", *(seq-1) );
72 void seq_grp( int *grp, char *seq )
77 tmp = amino_grp[(int)*seq++];
81 fprintf( stderr, "WARNING : Unknown character %c\n", *(seq-1) );
86 void makecompositiontable_p( short *table, int *pointt )
90 while( ( point = *pointt++ ) != END_OF_VEC )
94 int commonsextet_p( short *table, int *pointt )
99 static short *memo = NULL;
100 static int *ct = NULL;
105 memo = (short *)calloc( tsize, sizeof( short ) );
106 if( !memo ) ErrorExit( "Cannot allocate memo\n" );
107 ct = (int *)calloc( MIN( maxl, tsize)+1, sizeof( int ) );
108 if( !ct ) ErrorExit( "Cannot allocate memo\n" );
112 while( ( point = *pointt++ ) != END_OF_VEC )
115 if( tmp < table[point] )
117 if( tmp == 0 ) *cp++ = point;
118 // fprintf( stderr, "cp - ct = %d (tsize = %d)\n", cp - ct, tsize );
123 while( *cp != END_OF_VEC )
129 void makepointtable_nuc( int *pointt, int *n )
143 while( *n != END_OF_VEC )
145 point -= *p++ * 1024;
150 *pointt = END_OF_VEC;
153 void makepointtable( int *pointt, int *n )
160 point += *n++ * 1296;
167 while( *n != END_OF_VEC )
169 point -= *p++ * 7776;
174 *pointt = END_OF_VEC;
177 int main( int argc, char **argv )
185 static char name[M][B];
189 double score, score0;
190 static short *table1;
193 arguments( argc, argv );
197 infp = fopen( inputfile, "r" );
200 fprintf( stderr, "Cannot open %s\n", inputfile );
208 PreRead( stdin, &njob, &nlenmax );
215 fprintf( stderr, "At least 2 sequences should be input!\n"
216 "Only %d sequence found.\n", njob );
220 tmpseq = AllocateCharVec( nlenmax+1 );
221 seq = AllocateCharMtx( njob, nlenmax+1 );
222 grpseq = AllocateIntVec( nlenmax+1 );
223 pointt = AllocateIntMtx( njob, nlenmax+1 );
224 mtx = AllocateDoubleMtx( njob, njob );
225 mtx2 = AllocateDoubleMtx( njob, njob );
229 FRead( infp, name, nlen, seq );
231 readData( infp, name, nlen, seq );
236 constants( njob, seq );
238 if( dorp == 'd' ) tsize = (int)pow( 4, 6 );
239 else tsize = (int)pow( 6, 6 );
242 for( i=0; i<njob; i++ )
244 gappick0( tmpseq, seq[i] );
245 nlen[i] = strlen( tmpseq );
248 fprintf( stderr, "Seq %d, too short, %d characters\n", i+1, nlen[i] );
251 if( nlen[i] > maxl ) maxl = nlen[i];
252 if( dorp == 'd' ) /* nuc */
254 seq_grp_nuc( grpseq, tmpseq );
255 makepointtable_nuc( pointt[i], grpseq );
259 seq_grp( grpseq, tmpseq );
260 makepointtable( pointt[i], grpseq );
263 for( i=0; i<njob; i++ )
265 table1 = (short *)calloc( tsize, sizeof( short ) );
266 if( !table1 ) ErrorExit( "Cannot allocate table1\n" );
269 fprintf( stderr, "%4d / %4d\r", i+1, njob );
271 makecompositiontable_p( table1, pointt[i] );
273 for( j=i; j<njob; j++ )
275 score = (double)commonsextet_p( table1, pointt[j] );
280 for( i=0; i<njob; i++ )
283 for( j=0; j<njob; j++ )
284 mtx2[i][j] = ( score0 - mtx[MIN(i,j)][MAX(i,j)] ) / score0 * 3.0;
286 for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ )
290 jscore = mtx[i][j] / ( MIN( strlen( seq[i] ), strlen( seq[j] ) ) - 2 );
291 fprintf( stdout, "jscore = %f\n", jscore );
293 fprintf( stdout, "mtx2[%d][%d] = %f, mtx2[%d][%d] = %f\n", i, j, mtx2[i][j], j, i, mtx2[j][i] );
295 mtx2[i][j] = MIN( mtx2[i][j], mtx2[j][i] );
297 fprintf( stdout, "sonokekka mtx2[%d][%d] %f\n", i, j, mtx2[i][j] );
303 for( i=0; i<njob; i++ )
305 sprintf( b, "=lgth = %04d", nlen[i] );
306 strins( b, name[i] );
310 fp = fopen( "hat2", "w" );
311 if( !fp ) ErrorExit( "Cannot open hat2." );
312 WriteHat2( fp, njob, name, mtx2 );
315 fprintf( stderr, "\n" );