def sam2fastq(sam, singles = False, force = False):
L, R = None, None<EOL>for line in sam:<EOL><INDENT>if line.startswith('<STR_LIT:@>') is True:<EOL><INDENT>continue<EOL><DEDENT>line = line.strip().split()<EOL>bit = [True if i == '<STR_LIT:1>' else Falsefor i in bin(int(line[<NUM_LIT:1>])).split('<STR_LIT:b>')[<NUM_LIT:1>][::-<NUM_LIT:1>]]<EOL>while len(bit) < <NUM_LIT:8>:<EOL><INDENT>bit.append(False)<EOL><DEDENT>pair, proper, na, nap, rev, mrev, left, right = bit<EOL>if pair is False:<EOL><INDENT>if singles is True:<EOL><INDENT>print_single(line, rev)<EOL><DEDENT>continue<EOL><DEDENT>if rev is True:<EOL><INDENT>seq = rc(['<STR_LIT>', line[<NUM_LIT:9>]])[<NUM_LIT:1>]<EOL>qual = line[<NUM_LIT:10>][::-<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>seq = line[<NUM_LIT:9>]<EOL>qual = line[<NUM_LIT:10>]<EOL><DEDENT>if left is True:<EOL><INDENT>if L is not None and force is False:<EOL><INDENT>print('<STR_LIT>', file = sys.stderr)<EOL>print('<STR_LIT>' % (line[<NUM_LIT:0>]), file = sys.stderr)<EOL>exit()<EOL><DEDENT>if L is not None:<EOL><INDENT>L = None<EOL>continue<EOL><DEDENT>L = ['<STR_LIT>' % line[<NUM_LIT:0>], seq, '<STR_LIT>' % line[<NUM_LIT:0>], qual]<EOL>if R is not None:<EOL><INDENT>yield L<EOL>yield R<EOL>L, R = None, None<EOL><DEDENT><DEDENT>if right is True:<EOL><INDENT>if R is not None and force is False:<EOL><INDENT>print('<STR_LIT>', file = sys.stderr)<EOL>print('<STR_LIT>' % (line[<NUM_LIT:0>]), file = sys.stderr)<EOL>exit()<EOL><DEDENT>if R is not None:<EOL><INDENT>R = None<EOL>continue<EOL><DEDENT>R = ['<STR_LIT>' % line[<NUM_LIT:0>], seq, '<STR_LIT>' % line[<NUM_LIT:0>], qual]<EOL>if L is not None:<EOL><INDENT>yield L<EOL>yield R<EOL>L, R = None, None<EOL><DEDENT><DEDENT><DEDENT>
convert sam to fastq