Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Gerdus Van Zyl's PyPy optimized version, with optimized number of lines. See
def main():
file = open("Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa","rb")
gcCount = 0
atCount = 0
while 1:
lines = file.readlines(1000)
if not lines:
for line in lines:
if line and not line[0] == ">":
atCount += line.count("A") + line.count("T")
gcCount += line.count('G') + line.count("C")
totalBaseCount = gcCount + atCount
gcFraction = float(gcCount) / float(totalBaseCount)
print gcFraction * 100
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment