10 void arguments( int argc, char *argv[] )
20 while( --argc > 0 && (*++argv)[0] == '-' )
22 while ( ( c = *++argv[0] ) )
28 fprintf( stderr, "inputfile = %s\n", inputfile );
41 fprintf( stderr, "illegal option %c\n", c );
51 fprintf( stderr, "options: -i\n" );
56 void seq_grp_nuc( int *grp, char *seq )
61 tmp = amino_grp[(int)*seq++];
65 fprintf( stderr, "WARNING : Unknown character %c\n", *(seq-1) );
70 void seq_grp( int *grp, char *seq )
75 tmp = amino_grp[(int)*seq++];
79 fprintf( stderr, "WARNING : Unknown character %c\n", *(seq-1) );
84 void makecompositiontable_p( short *table, int *pointt )
88 while( ( point = *pointt++ ) != END_OF_VEC )
92 static int localcommonsextet_p( short *table, int *pointt )
97 static short *memo = NULL;
98 static int *ct = NULL;
103 memo = (short *)calloc( tsize, sizeof( short ) );
104 if( !memo ) ErrorExit( "Cannot allocate memo\n" );
105 ct = (int *)calloc( MIN( maxl, tsize)+1, sizeof( int ) );
106 if( !ct ) ErrorExit( "Cannot allocate memo\n" );
110 while( ( point = *pointt++ ) != END_OF_VEC )
113 if( tmp < table[point] )
115 if( tmp == 0 ) *cp++ = point;
116 // fprintf( stderr, "cp - ct = %d (tsize = %d)\n", cp - ct, tsize );
121 while( *cp != END_OF_VEC )
127 void makepointtable_nuc( int *pointt, int *n )
141 while( *n != END_OF_VEC )
143 point -= *p++ * 1024;
148 *pointt = END_OF_VEC;
151 void makepointtable( int *pointt, int *n )
158 point += *n++ * 1296;
165 while( *n != END_OF_VEC )
167 point -= *p++ * 7776;
172 *pointt = END_OF_VEC;
175 int main( int argc, char **argv )
187 double score, score0;
188 static short *table1;
191 arguments( argc, argv );
195 infp = fopen( inputfile, "r" );
198 fprintf( stderr, "Cannot open %s\n", inputfile );
206 PreRead( stdin, &njob, &nlenmax );
213 fprintf( stderr, "At least 2 sequences should be input!\n"
214 "Only %d sequence found.\n", njob );
218 name = AllocateCharMtx( njob, B+1 );
219 tmpseq = AllocateCharVec( nlenmax+1 );
220 seq = AllocateCharMtx( njob, nlenmax+1 );
221 grpseq = AllocateIntVec( nlenmax+1 );
222 pointt = AllocateIntMtx( njob, nlenmax+1 );
223 mtx = AllocateDoubleMtx( njob, njob );
224 mtx2 = AllocateDoubleMtx( njob, njob );
228 FRead( infp, name, nlen, seq );
230 readData_pointer( infp, name, nlen, seq );
235 constants( njob, seq );
237 if( dorp == 'd' ) tsize = (int)pow( 4, 6 );
238 else tsize = (int)pow( 6, 6 );
241 for( i=0; i<njob; i++ )
243 gappick0( tmpseq, seq[i] );
244 nlen[i] = strlen( tmpseq );
247 fprintf( stderr, "Seq %d, too short, %d characters\n", i+1, nlen[i] );
250 if( nlen[i] > maxl ) maxl = nlen[i];
251 if( dorp == 'd' ) /* nuc */
253 seq_grp_nuc( grpseq, tmpseq );
254 makepointtable_nuc( pointt[i], grpseq );
258 seq_grp( grpseq, tmpseq );
259 makepointtable( pointt[i], grpseq );
262 for( i=0; i<njob; i++ )
264 table1 = (short *)calloc( tsize, sizeof( short ) );
265 if( !table1 ) ErrorExit( "Cannot allocate table1\n" );
268 fprintf( stderr, "%4d / %4d\r", i+1, njob );
270 makecompositiontable_p( table1, pointt[i] );
272 for( j=i; j<njob; j++ )
274 score = (double)localcommonsextet_p( table1, pointt[j] );
279 for( i=0; i<njob; i++ )
282 for( j=0; j<njob; j++ )
283 mtx2[i][j] = ( score0 - mtx[MIN(i,j)][MAX(i,j)] ) / score0 * 3.0;
285 for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ )
289 jscore = mtx[i][j] / ( MIN( strlen( seq[i] ), strlen( seq[j] ) ) - 2 );
290 fprintf( stdout, "jscore = %f\n", jscore );
292 fprintf( stdout, "mtx2[%d][%d] = %f, mtx2[%d][%d] = %f\n", i, j, mtx2[i][j], j, i, mtx2[j][i] );
294 mtx2[i][j] = MIN( mtx2[i][j], mtx2[j][i] );
296 fprintf( stdout, "sonokekka mtx2[%d][%d] %f\n", i, j, mtx2[i][j] );
302 for( i=0; i<njob; i++ )
304 sprintf( b, "=lgth = %04d", nlen[i] );
305 strins( b, name[i] );
309 fp = fopen( "hat2", "w" );
310 if( !fp ) ErrorExit( "Cannot open hat2." );
311 WriteHat2_pointer( fp, njob, name, mtx2 );
314 fprintf( stderr, "\n" );