Created
December 15, 2013 00:12
-
-
Save anonymous/7966814 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # 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