Last active
December 17, 2015 06:08
-
-
Save NVolcz/5562749 to your computer and use it in GitHub Desktop.
Componentified version of http://saml.rilspace.org/calculating-gc-content-in-python-and-d-how-to-get-10x-speedup-in-d
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
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