Skip to content

Instantly share code, notes, and snippets.

Created December 15, 2013 00:12
Show Gist options
  • Save anonymous/7966814 to your computer and use it in GitHub Desktop.
Save anonymous/7966814 to your computer and use it in GitHub Desktop.
# nimrod c -d:release fasta.nim
# time ./fasta > /dev/null
# 3.635s
import parseutils
import strutils
proc process(filename: string) =
var gcCount = 0
var totalBaseCount = 0
var input = open(filename)
finally: input.close()
while not input.EndOfFile():
var line = input.readLine()
if not line.startsWith(">"):
for letter in line:
case letter
of 'T', 'A':
totalBaseCount += 1
of 'G', 'C':
gcCount += 1
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