程序代码:
#include <stdio.h>
int main()
{
unsigned long octamer_count[65536] = { 0 };
////// 1 //////
{
FILE* file = fopen( "result22.txt", "rb" );
if( !file )
{
puts( "cannot open the input file.");
return 1;
}
{
unsigned long octamer;
unsigned long octamer_n = 0;
char c;
for( ; fread(&c,1,1,file)==1; )
{
switch( c )
{
case 'A':
octamer = (octamer*4+0)%65536; ++octamer_n; break;
case 'T':
octamer = (octamer*4+1)%65536; ++octamer_n; break;
case 'C':
octamer = (octamer*4+2)%65536; ++octamer_n; break;
case 'G':
octamer = (octamer*4+3)%65536; ++octamer_n; break;
case '\r':
case '\n':
continue;
default:
puts( "Fuck" );
case 'N':
octamer_n = 0;
continue;
}
if( octamer_n < 8 )
continue;
octamer_n = 8;
++octamer_count[octamer];
}
}
fclose( file );
}
////// 2 //////
{
FILE* fileout = fopen( "result22_ouput.txt", "wt" );
if( !fileout )
{
puts( "cannot open the output file.");
return 2;
}
{
unsigned int i, j;
for( i=0; i<sizeof(octamer_count)/sizeof(octamer_count[0]); ++i )
{
if( octamer_count[i] == 0 )
continue;
for( j=65536/4; j!=0; j/=4 )
fprintf( fileout, "%c", "ATCG"[i/j%4] );
fprintf( fileout, " %u\n", octamer_count[i] );
}
}
fclose( fileout );
}
return 0;
}