diff tools/mira4/mira4.py @ 20:aeb3e35f8236 draft

Uploaded v0.0.4 preview, made MAF and BAM output optional
author peterjc
date Tue, 10 Jun 2014 10:11:58 -0400
parents 8487d70e82aa
children 4abe8d59a438
line wrap: on
line diff
--- a/tools/mira4/mira4.py	Wed May 21 06:56:06 2014 -0400
+++ b/tools/mira4/mira4.py	Tue Jun 10 10:11:58 2014 -0400
@@ -7,11 +7,12 @@
 import shutil
 import time
 import tempfile
+from optparse import OptionParser
 
 #Do we need any PYTHONPATH magic?
 from mira4_make_bam import make_bam
 
-WRAPPER_VER = "0.0.1" #Keep in sync with the XML file
+WRAPPER_VER = "0.0.4" #Keep in sync with the XML file
 
 def stop_err(msg, err=1):
     sys.stderr.write(msg+"\n")
@@ -34,6 +35,35 @@
     del child
     return ver.split("\n", 1)[0].strip()
 
+#Parse Command Line
+usage = """Galaxy MIRA4 wrapper script v%s - use as follows:
+
+$ python mira4.py ...
+
+This will run the MIRA binary and collect its output files as directed.
+""" % WRAPPER_VER
+parser = OptionParser(usage=usage)
+parser.add_option("-m", "--manifest", dest="manifest",
+                  default=None, metavar="FILE",
+                  help="MIRA manifest filename")
+parser.add_option("--maf", dest="maf",
+                  default="-", metavar="FILE",
+                  help="MIRA MAF output filename")
+parser.add_option("--bam", dest="bam",
+                  default="-", metavar="FILE",
+                  help="Unpadded BAM output filename")
+parser.add_option("--fasta", dest="fasta",
+                  default="-", metavar="FILE",
+                  help="Unpadded FASTA output filename")
+parser.add_option("--log", dest="log",
+                  default="-", metavar="FILE",
+                  help="MIRA logging output filename")
+options, args = parser.parse_args()
+manifest = options.manifest
+out_maf = options.maf
+out_bam = options.bam
+out_fasta = options.fasta
+out_log = options.log
 
 try:
     mira_path = os.environ["MIRA4"]
@@ -60,6 +90,11 @@
         print "WARNING: miraconvert %s" % mira_convert_ver
     sys.exit(0)
 
+if not manifest:
+    stop_err("Manifest is required")
+elif not os.path.isfile(manifest):
+    stop_err("Missing input MIRA manifest file: %r" % manifest)
+
 
 try:
     threads = int(os.environ.get("GALAXY_SLOTS", "1"))
@@ -143,6 +178,8 @@
                      (old_fasta, out_fasta)]:
         if not os.path.isfile(old):
             missing = True
+        elif not new or new == "-":
+            handle.write("Ignoring %s\n" % old)
         else:
             handle.write("Capturing %s\n" % old)
             shutil.move(old, new)
@@ -154,9 +191,10 @@
 
     #For mapping mode, probably most people would expect a BAM file
     #using the reference FASTA file...
-    msg = make_bam(mira_convert, out_maf, ref_fasta, out_bam, handle)
-    if msg:
-        stop_err(msg)
+    if out_bam and out_bam != "-":
+        msg = make_bam(mira_convert, out_maf, ref_fasta, out_bam, handle)
+        if msg:
+            stop_err(msg)
 
 def clean_up(temp, name):
     folder = "%s/%s_assembly" % (temp, name)
@@ -167,14 +205,12 @@
 #Currently Galaxy puts us somewhere safe like:
 #/opt/galaxy-dist/database/job_working_directory/846/
 temp = "."
-#name, out_fasta, out_qual, out_ace, out_caf, out_wig, out_log = sys.argv[1:8]
+
 name = "MIRA"
-manifest, out_maf, out_bam, out_fasta, out_log = sys.argv[1:]
 
 override_temp(manifest)
 
 start_time = time.time()
-#cmd_list =sys.argv[8:]
 cmd_list = [mira_binary, "-t", str(threads), manifest]
 cmd = " ".join(cmd_list)
 
@@ -192,7 +228,10 @@
 #print os.path.abspath(".")
 #print cmd
 
-handle = open(out_log, "w")
+if out_log and out_log != "-":
+    handle = open(out_log, "w")
+else:
+    handle = open(os.devnull, "w")
 handle.write("======================== MIRA manifest (instructions) ========================\n")
 m = open(manifest, "rU")
 for line in m: