Skip to content

Instantly share code, notes, and snippets.

@tbrittoborges
Created February 27, 2018 23:12
Show Gist options
  • Save tbrittoborges/acad3700f40039957b75892df67c4f8e to your computer and use it in GitHub Desktop.
Save tbrittoborges/acad3700f40039957b75892df67c4f8e to your computer and use it in GitHub Desktop.
def read_fasta_from_str(fasta):
"""
:param str fasta: multiple sequences in fasta string
"""
from itertools import groupby
def is_header(line):
return line.startswith(">")
for header, group in groupby(fasta.splitlines(), is_header):
if header:
line = group.next()
id_ = line[1:].split()[1]
else:
sequence = ''.join(line.strip() for line in group)
yield id_, sequence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment