Skip to content

Instantly share code, notes, and snippets.

@samuell
Last active March 6, 2019 18:35
  • 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/5589994 to your computer and use it in GitHub Desktop.
import std.stdio;
import std.string;
import std.algorithm;
void main() {
File file = File("Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa","r");
int countat[256];
int countgc[256];
countat['A'] = 1;
countat['T'] = 1;
countgc['G'] = 1;
countgc['C'] = 1;
int at = 0;
int gc = 0;
char[] line;
while(file.readln(line)){
if (!startsWith(line, '>')) {
foreach (char c; line) {
at += countat[c];
gc += countgc[c];
}
}
}
float gcFraction = ( cast(float)gc / cast(float)(at+gc) );
writeln( gcFraction * 100 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment