Created
May 10, 2013 16:53
-
-
Save samuell/5555709 to your computer and use it in GitHub Desktop.
Same as #5555675. bit with static typing of the ints, for cython.
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 re | |
import string | |
def main(): | |
file = open("Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa","r") | |
cdef int a, t, c, g | |
a = 0 | |
t = 0 | |
g = 0 | |
c = 0 | |
for line in file: | |
if not line.startswith(">"): | |
g += line.count("G") | |
c += line.count("C") | |
a += line.count("A") | |
t += line.count("T") | |
cdef int totalBaseCount = a + t + c + g | |
cdef int gcCount = g + c | |
gcFraction = float(gcCount) / totalBaseCount | |
print( gcFraction * 100 ) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment