def sort_sam(sam, sort):
tempdir = '<STR_LIT>' % (os.path.abspath(sam).rsplit('<STR_LIT:/>', <NUM_LIT:1>)[<NUM_LIT:0>])<EOL>if sort 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>return mapping<EOL>
sort sam file