Skip to content

Instantly share code, notes, and snippets.

@chasemc
Last active August 24, 2023 19:59
Show Gist options
  • Save chasemc/28ef621b985f2cc342903dd43789d145 to your computer and use it in GitHub Desktop.
Save chasemc/28ef621b985f2cc342903dd43789d145 to your computer and use it in GitHub Desktop.
def parse_fasta(filepath: str) -> Generator[str, str]:
seq_id = ""
with open(filepath, "r") as h:
seq_id = ""
seq = ""
for i in h:
if i[0] == ">":
if seq_id:
yield (seq_id, seq)
seq_id = i[1:].strip()
seq = ""
else:
seq += i.strip()
yield (seq_id, seq)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment