Initial Nimrod implementation of the file reading/scanning problem at 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 strutils | |
proc process(filename: string) = | |
var | |
input: TFile | |
lineBuf = newString(100) | |
gcCount = 0 | |
totalBaseCount = 0 | |
input = open(filename) | |
finally: input.close() | |
while input.readLine(lineBuf): | |
if lineBuf[0] != '>': | |
for letter in lineBuf: | |
case letter | |
of 'A': | |
totalBaseCount += 1 | |
of 'C': | |
gcCount += 1 | |
totalBaseCount += 1 | |
of 'G': | |
gcCount += 1 | |
totalBaseCount += 1 | |
of 'T': | |
totalBaseCount += 1 | |
else: | |
nil | |
let gcFraction = gcCount / totalBaseCount | |
echo formatFloat(gcFraction * 100, ffDecimal, 4) | |
when isMainModule: | |
process("Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For comparison, the best of three time mesurements on my machine were: