Skip to content

Instantly share code, notes, and snippets.

@Dubhead
Created May 23, 2013 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dubhead/5633254 to your computer and use it in GitHub Desktop.
Save Dubhead/5633254 to your computer and use it in GitHub Desktop.
A Python version gets a lot slower when str.count(I) is inhibited.
#!/usr/bin/python
def main():
gcCount = 0
atCount = 0
with open("Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa", "r") as f:
for line in f:
if not line.startswith('>'):
# gcCount += line.count('G') + line.count('C')
# atCount += line.count('A') + line.count('T')
for c in line:
if c == 'G' or c == 'C':
gcCount += 1
elif c == 'A' or c == 'T':
atCount += 1
print(gcCount * 100.0 / (gcCount + atCount))
if __name__ == '__main__':
main()
# eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment