Created
February 27, 2018 23:12
-
-
Save tbrittoborges/acad3700f40039957b75892df67c4f8e to your computer and use it in GitHub Desktop.
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
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