Skip to content

Instantly share code, notes, and snippets.

@samuell
Created May 10, 2013 16:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save samuell/5555753 to your computer and use it in GitHub Desktop.
import std.stdio;
import std.string;
import std.algorithm;
import std.regex;
void main() {
File file = File("Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa","r");
int gcCount = 0;
int atCount = 0;
int totalBaseCount = 0;
string line;
char c;
while (!file.eof()) {
line = file.readln();
if (line.length > 0 && !startsWith(line, ">")) {
for(uint i = 0; i < line.length; i++) {
c = line[i];
if (c == 'G' || c == 'C') {
gcCount++;
} else if ( c == 'A' || c == 'T' ) {
atCount++;
}
}
}
}
float gcFraction = ( cast(float)gcCount / cast(float)totalBaseCount );
writeln( gcFraction * 100 );
}
@samuell
Copy link
Author

samuell commented May 10, 2013

Compile flags used:

dmd -ofgc_samuel -O -release -inline gc_samuel.d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment