Mercurial > repos > peterjc > samtools_idxstats
diff tools/samtools_idxstats/samtools_idxstats.py @ 2:71afa65f444a draft default tip
v0.0.5 Internal changes to command line handling
author | peterjc |
---|---|
date | Tue, 16 May 2017 09:24:18 -0400 |
parents | 8945bad80f4a |
children |
line wrap: on
line diff
--- a/tools/samtools_idxstats/samtools_idxstats.py Wed May 13 10:35:50 2015 -0400 +++ b/tools/samtools_idxstats/samtools_idxstats.py Tue May 16 09:24:18 2017 -0400 @@ -10,35 +10,30 @@ runs "samtools idxstats" and captures the output to the desired tabular file. """ -import sys + import os -import subprocess +import sys import tempfile if "-v" in sys.argv or "--version" in sys.argv: - #Galaxy seems to invert the order of the two lines + # Galaxy seems to invert the order of the two lines print "(Galaxy wrapper v0.0.2)" cmd = "samtools 2>&1 | grep -i ^Version" sys.exit(os.system(cmd)) -def sys_exit(msg, error_level=1): - """Print error message to stdout and quit with given error level.""" - sys.stderr.write("%s\n" % msg) - sys.exit(error_level) - if len(sys.argv) != 4: - sys_exit("Require three arguments: BAM, BAI, tabular filenames") + sys.exit("Require three arguments: BAM, BAI, tabular filenames") bam_filename, bai_filename, tabular_filename = sys.argv[1:] if not os.path.isfile(bam_filename): - sys_exit("Input BAM file not found: %s" % bam_filename) + sys.exit("Input BAM file not found: %s" % bam_filename) if not os.path.isfile(bai_filename): if bai_filename == "None": - sys_exit("Error: Galaxy did not index your BAM file") - sys_exit("Input BAI file not found: %s" % bai_filename) + sys.exit("Error: Galaxy did not index your BAM file") + sys.exit("Input BAI file not found: %s" % bai_filename) -#Assign sensible names with real extensions, and setup symlinks: +# Assign sensible names with real extensions, and setup symlinks: tmp_dir = tempfile.mkdtemp() bam_file = os.path.join(tmp_dir, "temp.bam") bai_file = os.path.join(tmp_dir, "temp.bam.bai") @@ -48,14 +43,14 @@ assert os.path.isfile(bai_file), bai_file assert os.path.isfile(bam_file + ".bai"), bam_file -#Run samtools idxstats: +# Run samtools idxstats: cmd = 'samtools idxstats "%s" > "%s"' % (bam_file, tabular_filename) return_code = os.system(cmd) -#Remove the temp symlinks: +# Remove the temp symlinks: os.remove(bam_file) os.remove(bai_file) os.rmdir(tmp_dir) if return_code: - sys_exit("Return code %i from command:\n%s" % (return_code, cmd)) + sys.exit("Return code %i from command:\n%s" % (return_code, cmd))