def get_reads(sam,contigs = False, mismatches = False, mm_option = False,sort_sam = True, req_map = False, region = False, sbuffer = False):
tempdir = '<STR_LIT>' % (os.path.abspath(sam).rsplit('<STR_LIT:/>', <NUM_LIT:1>)[<NUM_LIT:0>])<EOL>if sort_sam is True:<EOL><INDENT>mapping = '<STR_LIT>' % (sam.rsplit('<STR_LIT:.>', <NUM_LIT:1>)[<NUM_LIT:0>])<EOL>if sam != '<STR_LIT:->':<EOL><INDENT>if os.path.exists(mapping) is False:<EOL><INDENT>os.system("<STR_LIT>" % (sbuffer, tempdir, mapping, sam))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>mapping = '<STR_LIT>'<EOL>p = Popen("<STR_LIT>"% (sbuffer, tempdir, mapping), stdin = sys.stdin, shell = True)<EOL>p.communicate()<EOL><DEDENT>mapping = open(mapping)<EOL><DEDENT>else:<EOL><INDENT>if sam == '<STR_LIT:->':<EOL><INDENT>mapping = sys.stdin<EOL><DEDENT>else:<EOL><INDENT>mapping = open(sam)<EOL><DEDENT><DEDENT>for read in reads_from_mapping(mapping, contigs, mismatches, mm_option, req_map, region):<EOL><INDENT>yield read<EOL><DEDENT>
get mapped reads (and their pairs) from an unsorted sam file