changeset 31:fd95aaef8818 draft

planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit bc3d484c5cd68ddcf456db2fff489d584aa2034c
author peterjc
date Wed, 10 Feb 2016 09:07:39 -0500
parents b506e3b779fa
children 56b421d59805
files tools/mira4_0/mira4.py tools/mira4_0/mira4_bait.py tools/mira4_0/mira4_convert.py tools/mira4_0/mira4_make_bam.py
diffstat 4 files changed, 40 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/tools/mira4_0/mira4.py	Wed Oct 07 09:08:29 2015 -0400
+++ b/tools/mira4_0/mira4.py	Wed Feb 10 09:07:39 2016 -0500
@@ -14,10 +14,6 @@
 
 WRAPPER_VER = "0.0.4" #Keep in sync with the XML file
 
-def sys_exit(msg, err=1):
-    sys.stderr.write(msg+"\n")
-    sys.exit(err)
-
 
 def get_version(mira_binary):
     """Run MIRA to find its version number"""
@@ -71,22 +67,22 @@
 try:
     mira_path = os.environ["MIRA4"]
 except KeyError:
-    sys_exit("Environment variable $MIRA4 not set")
+    sys.exit("Environment variable $MIRA4 not set")
 mira_binary = os.path.join(mira_path, "mira")
 if not os.path.isfile(mira_binary):
-    sys_exit("Missing mira under $MIRA4, %r\nFolder contained: %s"
+    sys.exit("Missing mira under $MIRA4, %r\nFolder contained: %s"
              % (mira_binary, ", ".join(os.listdir(mira_path))))
 mira_convert = os.path.join(mira_path, "miraconvert")
 if not os.path.isfile(mira_convert):
-    sys_exit("Missing miraconvert under $MIRA4, %r\nFolder contained: %s"
+    sys.exit("Missing miraconvert under $MIRA4, %r\nFolder contained: %s"
              % (mira_convert, ", ".join(os.listdir(mira_path))))
 
 mira_ver = get_version(mira_binary)
 if not mira_ver.strip().startswith("4.0"):
-    sys_exit("This wrapper is for MIRA V4.0, not:\n%s\n%s" % (mira_ver, mira_binary))
+    sys.exit("This wrapper is for MIRA V4.0, not:\n%s\n%s" % (mira_ver, mira_binary))
 mira_convert_ver = get_version(mira_convert)
 if not mira_convert_ver.strip().startswith("4.0"):
-    sys_exit("This wrapper is for MIRA V4.0, not:\n%s\n%s" % (mira_ver, mira_convert))
+    sys.exit("This wrapper is for MIRA V4.0, not:\n%s\n%s" % (mira_ver, mira_convert))
 if options.version:
     print "%s, MIRA wrapper version %s" % (mira_ver, WRAPPER_VER)
     if mira_ver != mira_convert_ver:
@@ -94,9 +90,9 @@
     sys.exit(0)
 
 if not manifest:
-    sys_exit("Manifest is required")
+    sys.exit("Manifest is required")
 elif not os.path.isfile(manifest):
-    sys_exit("Missing input MIRA manifest file: %r" % manifest)
+    sys.exit("Missing input MIRA manifest file: %r" % manifest)
 
 
 try:
@@ -149,14 +145,13 @@
 
 def collect_output(temp, name, handle):
     """Moves files to the output filenames (global variables)."""
-    n3 = (temp, name, name, name)
     f = "%s/%s_assembly/%s_d_results" % (temp, name, name)
     if not os.path.isdir(f):
         log_manifest(manifest)
-        sys_exit("Missing output folder")
+        sys.exit("Missing output folder")
     if not os.listdir(f):
         log_manifest(manifest)
-        sys_exit("Empty output folder")
+        sys.exit("Empty output folder")
     missing = []
 
     old_maf = "%s/%s_out.maf" % (f, name)
@@ -201,7 +196,7 @@
             #Not collecting the MAF file, use original location        
             msg = make_bam(mira_convert, old_maf, ref_fasta, out_bam, handle)
         if msg:
-            sys_exit(msg)
+            sys.exit(msg)
 
 def clean_up(temp, name):
     folder = "%s/%s_assembly" % (temp, name)
@@ -277,8 +272,9 @@
     handle.close()
     clean_up(temp, name)
     log_manifest(manifest)
-    sys_exit("Return error code %i from command:\n%s" % (return_code, cmd),
-             return_code)
+    sys.stderr.write("Return error code %i from command:\n" % return_code)
+    sys.stderr.write(cmd + "\n")
+    sys.exit(eturn_code)
 handle.flush()
 
 if os.path.isfile("MIRA_assembly/MIRA_d_results/ec.log"):
--- a/tools/mira4_0/mira4_bait.py	Wed Oct 07 09:08:29 2015 -0400
+++ b/tools/mira4_0/mira4_bait.py	Wed Feb 10 09:07:39 2016 -0500
@@ -9,10 +9,6 @@
 
 WRAPPER_VER = "0.0.5" #Keep in sync with the XML file
 
-def sys_exit(msg, err=1):
-    sys.stderr.write(msg+"\n")
-    sys.exit(err)
-
 
 def get_version(mira_binary):
     """Run MIRA to find its version number"""
@@ -34,20 +30,20 @@
             if " version " in line:
                 line = line.split()
                 return line[line.index("version")+1].rstrip(")")
-        sys_exit("Could not determine MIRA version:\n%s" % ver)
+        sys.exit("Could not determine MIRA version:\n%s" % ver)
     return ver.split("\n", 1)[0]
 
 try:
     mira_path = os.environ["MIRA4"]
 except KeyError:
-    sys_exit("Environment variable $MIRA4 not set")
+    sys.exit("Environment variable $MIRA4 not set")
 mira_binary = os.path.join(mira_path, "mirabait")
 if not os.path.isfile(mira_binary):
-    sys_exit("Missing mirabait under $MIRA4, %r\nFolder contained: %s"
+    sys.exit("Missing mirabait under $MIRA4, %r\nFolder contained: %s"
              % (mira_binary, ", ".join(os.listdir(mira_path))))
 mira_ver = get_version(mira_binary)
 if not mira_ver.strip().startswith("4.0"):
-    sys_exit("This wrapper is for MIRA V4.0, not:\n%s" % mira_ver)
+    sys.exit("This wrapper is for MIRA V4.0, not:\n%s" % mira_ver)
 if "-v" in sys.argv or "--version" in sys.argv:
     print "%s, MIRA wrapper version %s" % (mira_ver, WRAPPER_VER)
     sys.exit(0)
@@ -60,7 +56,7 @@
 elif format == "mira":
     format = "maf"
 elif format != "fasta":
-    sys_exit("Was not expected format %r" % format)
+    sys.exit("Was not expected format %r" % format)
 
 assert out_file.endswith(".dat")
 out_file_stem = out_file[:-4]
@@ -74,14 +70,14 @@
     #Invert the selection...
     cmd_list.insert(1, "-i")
 else:
-    sys_exit("Output choice should be 'pos' or 'neg', not %r" % output_choice)
+    sys.exit("Output choice should be 'pos' or 'neg', not %r" % output_choice)
 if strand_choice == "both":
     pass
 elif strand_choice == "fwd":
     #Ingore reverse strand...
     cmd_list.insert(1, "-r")
 else:
-    sys_exit("Strand choice should be 'both' or 'fwd', not %r" % strand_choice)
+    sys.exit("Strand choice should be 'both' or 'fwd', not %r" % strand_choice)
 
 cmd = " ".join(cmd_list)
 #print cmd
@@ -103,12 +99,12 @@
 
 if return_code:
     sys.stderr.write(stdout)
-    sys_exit("Return error code %i from command:\n%s" % (return_code, cmd),
+    sys.exit("Return error code %i from command:\n%s" % (return_code, cmd),
              return_code)
 
 #Capture output
 out_tmp = out_file_stem + "." + format
 if not os.path.isfile(out_tmp):
     sys.stderr.write(stdout)
-    sys_exit("Missing output file from mirabait: %s" % out_tmp)
+    sys.exit("Missing output file from mirabait: %s" % out_tmp)
 shutil.move(out_tmp, out_file)
--- a/tools/mira4_0/mira4_convert.py	Wed Oct 07 09:08:29 2015 -0400
+++ b/tools/mira4_0/mira4_convert.py	Wed Feb 10 09:07:39 2016 -0500
@@ -7,8 +7,6 @@
 import sys
 import subprocess
 import shutil
-import time
-import tempfile
 from optparse import OptionParser
 try:
     from io import BytesIO
@@ -21,9 +19,6 @@
 
 WRAPPER_VER = "0.0.7"  # Keep in sync with the XML file
 
-def sys_exit(msg, err=1):
-    sys.stderr.write(msg+"\n")
-    sys.exit(err)
 
 def run(cmd):
     #Avoid using shell=True when we call subprocess to ensure if the Python
@@ -31,16 +26,16 @@
     try:
         child = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     except Exception, err:
-        sys_exit("Error invoking command:\n%s\n\n%s\n" % (" ".join(cmd), err))
+        sys.exit("Error invoking command:\n%s\n\n%s\n" % (" ".join(cmd), err))
     #Use .communicate as can get deadlocks with .wait(),
     stdout, stderr = child.communicate()
     return_code = child.returncode
     if return_code:
         cmd_str = " ".join(cmd)  # doesn't quote spaces etc
         if stderr and stdout:
-            sys_exit("Return code %i from command:\n%s\n\n%s\n\n%s" % (return_code, cmd_str, stdout, stderr))
+            sys.exit("Return code %i from command:\n%s\n\n%s\n\n%s" % (return_code, cmd_str, stdout, stderr))
         else:
-            sys_exit("Return code %i from command:\n%s\n%s" % (return_code, cmd_str, stderr))
+            sys.exit("Return code %i from command:\n%s\n%s" % (return_code, cmd_str, stderr))
 
 def get_version(mira_binary):
     """Run MIRA to find its version number"""
@@ -98,7 +93,7 @@
                   help="Show version and quit")
 options, args = parser.parse_args()
 if args:
-    sys_exit("Expected options (e.g. --input example.maf), not arguments")
+    sys.exit("Expected options (e.g. --input example.maf), not arguments")
 
 input_maf = options.input
 out_maf = options.maf
@@ -110,35 +105,35 @@
 try:
     mira_path = os.environ["MIRA4"]
 except KeyError:
-    sys_exit("Environment variable $MIRA4 not set")
+    sys.exit("Environment variable $MIRA4 not set")
 mira_convert = os.path.join(mira_path, "miraconvert")
 if not os.path.isfile(mira_convert):
-    sys_exit("Missing miraconvert under $MIRA4, %r\nFolder contained: %s"
+    sys.exit("Missing miraconvert under $MIRA4, %r\nFolder contained: %s"
              % (mira_convert, ", ".join(os.listdir(mira_path))))
 
 mira_convert_ver = get_version(mira_convert)
 if not mira_convert_ver.strip().startswith("4.0"):
-    sys_exit("This wrapper is for MIRA V4.0, not:\n%s\n%s" % (mira_convert_ver, mira_convert))
+    sys.exit("This wrapper is for MIRA V4.0, not:\n%s\n%s" % (mira_convert_ver, mira_convert))
 if options.version:
     print("%s, MIRA wrapper version %s" % (mira_convert_ver, WRAPPER_VER))
     sys.exit(0)
 
 if not input_maf:
-    sys_exit("Input MIRA file is required")
+    sys.exit("Input MIRA file is required")
 elif not os.path.isfile(input_maf):
-    sys_exit("Missing input MIRA file: %r" % input_maf)
+    sys.exit("Missing input MIRA file: %r" % input_maf)
 
 if not (out_maf or out_bam or out_fasta or out_ace or out_cstats):
-    sys_exit("No output requested")
+    sys.exit("No output requested")
 
 
 def check_min_int(value, name):
     try:
         i = int(value)
-    except:
-        sys_exit("Bad %s setting, %r" % (name, value))
+    except ValueError:
+        sys.exit("Bad %s setting, %r" % (name, value))
     if i < 0:
-        sys_exit("Negative %s setting, %r" % (name, value))
+        sys.exit("Negative %s setting, %r" % (name, value))
     return i
 
 min_length = check_min_int(options.min_length, "minimum length")
@@ -176,7 +171,7 @@
 
 def collect(old, new):
     if not os.path.isfile(old):
-        sys_exit("Missing expected output file %s" % old)
+        sys.exit("Missing expected output file %s" % old)
     shutil.move(old, new)
 
 if out_maf:
@@ -190,12 +185,12 @@
         #Might the output be filtered down to zero contigs?
         old = os.path.join(temp, "converted.fasta")
         if not os.path.isfile(old):
-            sys_exit("Missing expected output FASTA file")
+            sys.exit("Missing expected output FASTA file")
         elif os.path.getsize(old) == 0:
             print("Warning - no contigs (harsh filters?)")
             collect(old, out_fasta)
         else:
-            sys_exit("Missing expected output FASTA file (only generic file present)")
+            sys.exit("Missing expected output FASTA file (only generic file present)")
 if out_ace:
     collect(os.path.join(temp, "converted.maf"), out_ace)
 if out_cstats:
@@ -207,7 +202,7 @@
     if not os.path.isfile(old):
         old = os.path.join(temp, "converted.sam")
     if not os.path.isfile(old):
-        sys_exit("Missing expected intermediate file %s" % old)
+        sys.exit("Missing expected intermediate file %s" % old)
     h = BytesIO()
     msg = depad(out_fasta, old, out_bam, h)
     if msg:
--- a/tools/mira4_0/mira4_make_bam.py	Wed Oct 07 09:08:29 2015 -0400
+++ b/tools/mira4_0/mira4_make_bam.py	Wed Feb 10 09:07:39 2016 -0500
@@ -7,10 +7,6 @@
 import subprocess
 import tempfile
 
-def sys_exit(msg, err=1):
-    sys.stderr.write(msg+"\n")
-    sys.exit(err)
-
 def run(cmd, log_handle):
     try:
         child = subprocess.Popen(cmd, shell=True,
@@ -89,4 +85,4 @@
     mira_convert, maf_file, fasta_file, bam_file = sys.argv[1:]
     msg = make_bam(mira_convert, maf_file, fasta_file, bam_file, sys.stdout)
     if msg:
-        sys_exit(msg)
+        sys.exit(msg)