diff tools/effectiveT3/effectiveT3.py @ 5:1ea715da1879 draft

Uploaded v0.0.13, embed citation, relax test for floating point differences
author peterjc
date Tue, 25 Nov 2014 08:28:24 -0500
parents b0b927299aee
children 0f6eb4a75000
line wrap: on
line diff
--- a/tools/effectiveT3/effectiveT3.py	Wed Sep 18 06:11:36 2013 -0400
+++ b/tools/effectiveT3/effectiveT3.py	Tue Nov 25 08:28:24 2014 -0500
@@ -15,13 +15,13 @@
 import os
 import subprocess
 
-#The Galaxy auto-install via tool_dependencies.xml will set this environment variable
+# The Galaxy auto-install via tool_dependencies.xml will set this environment variable
 effectiveT3_dir = os.environ.get("EFFECTIVET3", "/opt/EffectiveT3/")
 effectiveT3_jar = os.path.join(effectiveT3_dir, "TTSS_GUI-1.0.1.jar")
 
 if "-v" in sys.argv or "--version" in sys.argv:
-    #TODO - Get version of the JAR file dynamically?
-    print "Wrapper v0.0.11, TTSS_GUI-1.0.1.jar"
+    # TODO - Get version of the JAR file dynamically?
+    print("Wrapper v0.0.13, TTSS_GUI-1.0.1.jar")
     sys.exit(0)
 
 def stop_err(msg, error_level=1):
@@ -51,12 +51,12 @@
         or line.startswith("Id; Description; Score;"):
             continue
         assert line.count(";") >= 3, repr(line)
-        #Normally there will just be three semi-colons, however the
-        #original FASTA file's ID or description might have had
-        #semi-colons in it as well, hence the following hackery:
+        # Normally there will just be three semi-colons, however the
+        # original FASTA file's ID or description might have had
+        # semi-colons in it as well, hence the following hackery:
         try:
             id_descr, score, effective = line.rstrip("\r\n").rsplit(";",2)
-            #Cope when there was no FASTA description
+            # Cope when there was no FASTA description
             if "; " not in id_descr and id_descr.endswith(";"):
                 id = id_descr[:-1]
                 descr = ""
@@ -74,20 +74,21 @@
     return count, positive, errors
 
 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:
         stop_err("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:
+        cmd_str= " ".join(cmd)  # doesn't quote spaces etc
         if stderr and stdout:
-            stop_err("Return code %i from command:\n%s\n\n%s\n\n%s" % (return_code, err, stdout, stderr))
+            stop_err("Return code %i from command:\n%s\n\n%s\n\n%s" % (return_code, cmd_str, stdout, stderr))
         else:
-            stop_err("Return code %i from command:\n%s\n%s" % (return_code, err, stderr))
+            stop_err("Return code %i from command:\n%s\n%s" % (return_code, cmd_str, stderr))
 
 if not os.path.isdir(effectiveT3_dir):
     stop_err("Effective T3 folder not found: %r" % effectiveT3_dir)
@@ -106,10 +107,10 @@
     sys.stderr.write("Main JAR was found: %r\n" % effectiveT3_jar)
     stop_err("Effective T3 model JAR file not found: %r" % effectiveT3_model)
 
-#We will have write access whereever the output should be,
+# We will have write access whereever the output should be,
 temp_file = os.path.abspath(tabular_file + ".tmp")
 
-#Use absolute paths since will change current directory...
+# Use absolute paths since will change current directory...
 tabular_file = os.path.abspath(tabular_file)
 fasta_file = os.path.abspath(fasta_file)
 
@@ -121,7 +122,7 @@
        "-q"]
 
 try:
-    #Must run from directory above the module subfolder:
+    # Must run from directory above the module subfolder:
     os.chdir(effectiveT3_dir)
 except:
     stop_err("Could not change to Effective T3 folder: %s" % effectiveT3_dir)
@@ -141,11 +142,11 @@
 os.remove(temp_file)
 
 if errors:
-   print "%i sequences, %i positive, %i errors" \
-         % (count, positive, errors)
+   print("%i sequences, %i positive, %i errors"
+         % (count, positive, errors))
 else:
-   print "%i/%i sequences positive" % (positive, count)
+   print("%i/%i sequences positive" % (positive, count))
 
 if count and count==errors:
-   #Galaxy will still  allow them to see the output file
+   # Galaxy will still  allow them to see the output file
    stop_err("All your sequences gave an error code")