Skip to content

Instantly share code, notes, and snippets.

@otto-schnurr
Created September 17, 2014 18:28
Show Gist options
  • Save otto-schnurr/db2ada9cdc3a1b532e88 to your computer and use it in GitHub Desktop.
Save otto-schnurr/db2ada9cdc3a1b532e88 to your computer and use it in GitHub Desktop.
A python solution for http://rosalind.info/problems/gc/.
#!/usr/bin/env python
from fileinput import input as data
from itertools import imap
def ifasta(lines):
name, dna = None, ''
for line in imap(str.rstrip, lines):
if line.startswith('>'):
if name:
yield name, dna
name, dna = line[1:], ''
else:
dna += line
if name:
yield name, dna
def gc(dna):
return sum(c=='G' or c=='C' for c in dna) * 100.0 / len(dna)
igcname = ((gc(dna), name) for name, dna in ifasta(data()))
maxgc, maxname = max(igcname)
print maxname
print maxgc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment