INNER CODE UNIT · Python
parse_fasta
steineggerlab/Metabuli · util/simulate_faa_reads.py:13
def parse_fasta(path):
name = None
chunks = []
with open_text(path) as handle:
for line in handle:
line = line.strip()
if not line:
continue
if line.startswith(">"):
if name is not None:
yield name, "".join(chunks)
name = line[1:].split()[0]
chunks = []
else:
chunks.append(line)
if name is not None:
yield name, "".join(chunks)