Created
September 17, 2014 18:28
-
-
Save otto-schnurr/db2ada9cdc3a1b532e88 to your computer and use it in GitHub Desktop.
A python solution for http://rosalind.info/problems/gc/.
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
#!/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