Skip to content

Instantly share code, notes, and snippets.

@samuell
Created May 10, 2013 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuell/5555809 to your computer and use it in GitHub Desktop.
Save samuell/5555809 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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