Created
October 4, 2012 16:08
-
-
Save benjeffery/3834641 to your computer and use it in GitHub Desktop.
Iterate over a fasta with a single sequence in
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
@contextlib.contextmanager | |
def fasta_sequence(file): | |
with open(file, 'r') as f: | |
f.next() #loose the header row | |
def generator(): | |
for line in f: | |
for char in line.strip(): | |
yield char | |
yield generator() | |
use like: | |
with fasta_sequence(file) as seq: | |
for base in seq: | |
print base |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment