INNER CODE UNIT · Python
open_text
steineggerlab/Metabuli · util/simulate_faa_reads.py:9
def open_text(path):
return gzip.open(path, "rt") if str(path).endswith(".gz") else open(path, "r")
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: