Skip to content

Instantly share code, notes, and snippets.

@NVolcz
Last active December 17, 2015 06:08
Show Gist options
  • Save NVolcz/5562749 to your computer and use it in GitHub Desktop.
Save NVolcz/5562749 to your computer and use it in GitHub Desktop.
import std.stdio;
import std.string;
import std.algorithm;
import std.regex;
import std.traits;
int gcCount = 0;
int totalBaseCount = 0;
void main() {
File file = File("Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa","r");
string line = "";
file.byLine(KeepTerminator.yes).reduce!countGc;
//map!(a => calcGc(a));
//calcGc();
//while (!file.eof()) {
// line = chomp(file.readln());
// if (!startsWith(line, ">")) {
// gcCount = countchars(line, "[GC]");
// totalBaseCount += countchars(line, "[GCTA]");
// }
//}
//float gcFraction = ( cast(float)gcCount / totalBaseCount );
//writeln( gcFraction * 100 );
}
auto calcGc(T)(T line) {
if (!startsWith(line, ">")) {
gcCount = countchars(line, "[GC]");
totalBaseCount += countchars(line, "[GCTA]");
}
//writeln(line);
//writeln(typeid(typeof(line)));
return line;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment