Skip to content

Instantly share code, notes, and snippets.

@benjeffery
Created October 4, 2012 16:08
Show Gist options
  • Save benjeffery/3834641 to your computer and use it in GitHub Desktop.
Save benjeffery/3834641 to your computer and use it in GitHub Desktop.
Iterate over a fasta with a single sequence in
@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