def readfq(fp):
last = None  <EOL>while True:  <EOL><INDENT>if not last:  <EOL><INDENT>for l in fp:  <EOL><INDENT>if l[<NUM_LIT:0>] in '<STR_LIT>':  <EOL><INDENT>last = l[:-<NUM_LIT:1>]  <EOL>break<EOL><DEDENT><DEDENT><DEDENT>if not last:<EOL><INDENT>break<EOL><DEDENT>name, seqs, last = last[<NUM_LIT:1>:].partition("<STR_LIT:U+0020>")[<NUM_LIT:0>], [], None<EOL>for l in fp:  <EOL><INDENT>if l[<NUM_LIT:0>] in '<STR_LIT>':<EOL><INDENT>last = l[:-<NUM_LIT:1>]<EOL>break<EOL><DEDENT>seqs.append(l[:-<NUM_LIT:1>])<EOL><DEDENT>if not last or last[<NUM_LIT:0>] != '<STR_LIT:+>':  <EOL><INDENT>yield name, '<STR_LIT>'.join(seqs), None  <EOL>if not last:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:  <EOL><INDENT>seq, leng, seqs = '<STR_LIT>'.join(seqs), <NUM_LIT:0>, []<EOL>for l in fp:  <EOL><INDENT>seqs.append(l[:-<NUM_LIT:1>])<EOL>leng += len(l) - <NUM_LIT:1><EOL>if leng >= len(seq):  <EOL><INDENT>last = None<EOL>yield name, seq, '<STR_LIT>'.join(seqs)  <EOL>break<EOL><DEDENT><DEDENT>if last:  <EOL><INDENT>yield name, seq, None  <EOL>break<EOL><DEDENT><DEDENT><DEDENT>
Generator function adapted from https://github.com/lh3/readfq.