Create a gist now

Instantly share code, notes, and snippets.

Thomas Hume's C code. See http://saml.rilspace.org/node/248
#include <stdio.h>
#include <assert.h>
int main() {
FILE * inputFile = fopen( "Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa", "rb" );
size_t gcCount = 0;
size_t atCount = 0;
for ( char c; (c = fgetc_unlocked( inputFile )) != EOF; ) {
if ( c == '>' ) {
while ( (c = fgetc_unlocked( inputFile )) != '\n' )
;
} else {
do {
switch ( c ) {
case 'A':
case 'T':
atCount++;
break;
case 'G':
case 'C':
gcCount++;
break;
default:
break;
}
} while ( (c = fgetc_unlocked( inputFile )) != '\n' );
}
}
int totalBaseCount = atCount + gcCount;
printf( "%f\n", ((float)gcCount / (float)totalBaseCount ) * 100 );
return 0;
}
@samuell
Owner
samuell commented May 10, 2013

Compile flags used:

gcc -ogc_c_th -std=gnu99 -O3 gc_th.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment