Thomas Hume's C code. See http://saml.rilspace.org/node/248
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compile flags used: