diff tools/mira4_0/mira4_convert.py @ 32:56b421d59805 draft

planemo upload for repository https://github.com/peterjc/galaxy_mira/tree/master/tools/mira4_0 commit fd979d17340cde155de176604744831d9597c6b6
author peterjc
date Thu, 18 May 2017 13:36:08 -0400
parents fd95aaef8818
children 0785a6537f3e
line wrap: on
line diff
--- a/tools/mira4_0/mira4_convert.py	Wed Feb 10 09:07:39 2016 -0500
+++ b/tools/mira4_0/mira4_convert.py	Thu May 18 13:36:08 2017 -0400
@@ -3,31 +3,36 @@
 
 This focuses on the miraconvert binary.
 """
+
+from __future__ import print_function
+
 import os
-import sys
+import shutil
 import subprocess
-import shutil
+import sys
+
 from optparse import OptionParser
+
 try:
     from io import BytesIO
 except ImportError:
-    #Should we worry about Python 2.5 or older?
+    # Should we worry about Python 2.5 or older?
     from StringIO import StringIO as BytesIO
 
-#Do we need any PYTHONPATH magic?
+# Do we need any PYTHONPATH magic?
 from mira4_make_bam import depad
 
-WRAPPER_VER = "0.0.7"  # Keep in sync with the XML file
+WRAPPER_VER = "0.0.10"  # Keep in sync with the XML file
 
 
 def run(cmd):
-    #Avoid using shell=True when we call subprocess to ensure if the Python
-    #script is killed, so too is the child process.
+    # Avoid using shell=True when we call subprocess to ensure if the Python
+    # script is killed, so too is the child process.
     try:
         child = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-    except Exception, err:
+    except Exception as err:
         sys.exit("Error invoking command:\n%s\n\n%s\n" % (" ".join(cmd), err))
-    #Use .communicate as can get deadlocks with .wait(),
+    # Use .communicate as can get deadlocks with .wait(),
     stdout, stderr = child.communicate()
     return_code = child.returncode
     if return_code:
@@ -37,6 +42,7 @@
         else:
             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"""
     # At the commend line I would use: mira -v | head -n 1
@@ -46,14 +52,15 @@
         child = subprocess.Popen(cmd,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.STDOUT)
-    except Exception, err:
+    except Exception as err:
         sys.stderr.write("Error invoking command:\n%s\n\n%s\n" % (" ".join(cmd), err))
         sys.exit(1)
     ver, tmp = child.communicate()
     del child
     return ver.split("\n", 1)[0].strip()
 
-#Parse Command Line
+
+# Parse Command Line
 usage = """Galaxy MIRA4 wrapper script v%s - use as follows:
 
 $ python mira4_convert.py ...
@@ -136,13 +143,14 @@
         sys.exit("Negative %s setting, %r" % (name, value))
     return i
 
+
 min_length = check_min_int(options.min_length, "minimum length")
 min_cover = check_min_int(options.min_cover, "minimum cover")
 min_reads = check_min_int(options.min_reads, "minimum reads")
 
-#TODO - Run MIRA in /tmp or a configurable directory?
-#Currently Galaxy puts us somewhere safe like:
-#/opt/galaxy-dist/database/job_working_directory/846/
+# TODO - Run MIRA in /tmp or a configurable directory?
+# Currently Galaxy puts us somewhere safe like:
+# /opt/galaxy-dist/database/job_working_directory/846/
 temp = "."
 
 
@@ -159,7 +167,7 @@
 if out_bam:
     cmd_list.append("samnbb")
     if not out_fasta:
-        #Need this for samtools depad
+        # Need this for samtools depad
         out_fasta = os.path.join(temp, "depadded.fasta")
 if out_fasta:
     cmd_list.append("fasta")
@@ -169,20 +177,22 @@
     cmd_list.append("cstats")
 run(cmd_list)
 
+
 def collect(old, new):
     if not os.path.isfile(old):
         sys.exit("Missing expected output file %s" % old)
     shutil.move(old, new)
 
+
 if out_maf:
     collect(os.path.join(temp, "converted.maf"), out_maf)
 if out_fasta:
-    #Can we look at the MAF file to see if there are multiple strains?
+    # Can we look at the MAF file to see if there are multiple strains?
     old = os.path.join(temp, "converted_AllStrains.unpadded.fasta")
     if os.path.isfile(old):
         collect(old, out_fasta)
     else:
-        #Might the output be filtered down to zero contigs?
+        # 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")
@@ -212,7 +222,7 @@
         sys.exit(1)
     h.close()
     if out_fasta == os.path.join(temp, "depadded.fasta"):
-        #Not asked for by Galaxy, no longer needed
+        # Not asked for by Galaxy, no longer needed
         os.remove(out_fasta)
 
 if min_length or min_cover or min_reads: