changeset 8:60a9b3f760cc draft

v0.0.17 Used cached URL, python style updates
author peterjc
date Wed, 01 Feb 2017 09:22:21 -0500
parents 5f85301d50bf
children 512530020360
files tools/effectiveT3/README.rst tools/effectiveT3/effectiveT3.py tools/effectiveT3/effectiveT3.xml tools/effectiveT3/tool_dependencies.xml
diffstat 4 files changed, 67 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/tools/effectiveT3/README.rst	Mon Sep 21 05:52:29 2015 -0400
+++ b/tools/effectiveT3/README.rst	Wed Feb 01 09:22:21 2017 -0500
@@ -1,7 +1,7 @@
 Galaxy wrapper for EffectiveT3 v1.0.1
 =====================================
 
-This wrapper is copyright 2011-2015 by Peter Cock, The James Hutton Institute
+This wrapper is copyright 2011-2017 by Peter Cock, The James Hutton Institute
 (formerly SCRI, Scottish Crop Research Institute), UK. All rights reserved.
 See the licence text below.
 
@@ -94,6 +94,8 @@
         - Includes new standard classification model v2.0.2 (Sep 2015)
           as the default entry in ``tool-data/effectiveT3.loc``
         - Catch java exception, e.g. if Java too old for ``TTSS-STD-2.0.1.jar``
+v0.0.17 - Update tool dependency definition to use cached URL.
+        - Minor internal changes to Python script for error reporting & style.
 ======= ======================================================================
 
 
--- a/tools/effectiveT3/effectiveT3.py	Mon Sep 21 05:52:29 2015 -0400
+++ b/tools/effectiveT3/effectiveT3.py	Wed Feb 01 09:22:21 2017 -0500
@@ -16,30 +16,26 @@
 import subprocess
 
 # 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")
+effective_t3_dir = os.environ.get("EFFECTIVET3", "/opt/EffectiveT3/")
+effective_t3_jar = os.path.join(effective_t3_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.16, TTSS_GUI-1.0.1.jar")
+    print("Wrapper v0.0.17, TTSS_GUI-1.0.1.jar")
     sys.exit(0)
 
-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) != 5:
-   sys_exit("Require four arguments: model, threshold, input protein FASTA file & output tabular file")
+    sys.exit("Require four arguments: model, threshold, input protein FASTA file & output tabular file")
 
 model, threshold, fasta_file, tabular_file = sys.argv[1:]
 
 if not os.path.isfile(fasta_file):
-   sys_exit("Input FASTA file not found: %s" % fasta_file)
+    sys.exit("Input FASTA file not found: %s" % fasta_file)
 
 if threshold not in ["selective", "sensitive"] \
-and not threshold.startswith("cutoff="):
-   sys_exit("Threshold should be selective, sensitive, or cutoff=..., not %r" % threshold)
+    and not threshold.startswith("cutoff="):
+    sys.exit("Threshold should be selective, sensitive, or cutoff=..., not %r" % threshold)
+
 
 def clean_tabular(raw_handle, out_handle):
     """Clean up Effective T3 output to make it tabular."""
@@ -48,65 +44,66 @@
     errors = 0
     for line in raw_handle:
         if not line or line.startswith("#") \
-        or line.startswith("Id; Description; Score;"):
+            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:
         try:
-            id_descr, score, effective = line.rstrip("\r\n").rsplit(";",2)
+            id_descr, score, effective = line.rstrip("\r\n").rsplit(";", 2)
             # Cope when there was no FASTA description
             if "; " not in id_descr and id_descr.endswith(";"):
                 id = id_descr[:-1]
                 descr = ""
             else:
-                id, descr = id_descr.split("; ",1)
+                id, descr = id_descr.split("; ", 1)
         except ValueError:
-            sys_exit("Problem parsing line:\n%s\n" % line)
+            sys.exit("Problem parsing line:\n%s\n" % line)
         parts = [s.strip() for s in [id, descr, score, effective]]
         out_handle.write("\t".join(parts) + "\n")
         count += 1
         if float(score) < 0:
-           errors += 1
+            errors += 1
         if effective.lower() == "true":
-           positive += 1
+            positive += 1
     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.
     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 or stderr.startswith("Exception in thread"):
-        cmd_str= " ".join(cmd)  # doesn't quote spaces etc
+        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))
 
 
-if not os.path.isdir(effectiveT3_dir):
-    sys_exit("Effective T3 folder not found: %r" % effectiveT3_dir)
+if not os.path.isdir(effective_t3_dir):
+    sys.exit("Effective T3 folder not found: %r" % effective_t3_dir)
 
-if not os.path.isfile(effectiveT3_jar):
-    sys_exit("Effective T3 JAR file not found: %r" % effectiveT3_jar)
+if not os.path.isfile(effective_t3_jar):
+    sys.exit("Effective T3 JAR file not found: %r" % effective_t3_jar)
 
-if not os.path.isdir(os.path.join(effectiveT3_dir, "module")):
-    sys_exit("Effective T3 module folder not found: %r" % os.path.join(effectiveT3_dir, "module"))
+if not os.path.isdir(os.path.join(effective_t3_dir, "module")):
+    sys.exit("Effective T3 module folder not found: %r" % os.path.join(effective_t3_dir, "module"))
 
-effectiveT3_model = os.path.join(effectiveT3_dir, "module", model)
-if not os.path.isfile(effectiveT3_model):
+effective_t3_model = os.path.join(effective_t3_dir, "module", model)
+if not os.path.isfile(effective_t3_model):
     sys.stderr.write("Contents of %r is %s\n"
-                     % (os.path.join(effectiveT3_dir, "module"),
-                        ", ".join(repr(p) for p in os.listdir(os.path.join(effectiveT3_dir, "module")))))
-    sys.stderr.write("Main JAR was found: %r\n" % effectiveT3_jar)
-    sys_exit("Effective T3 model JAR file not found: %r" % effectiveT3_model)
+                     % (os.path.join(effective_t3_dir, "module"),
+                        ", ".join(repr(p) for p in os.listdir(os.path.join(effective_t3_dir, "module")))))
+    sys.stderr.write("Main JAR was found: %r\n" % effective_t3_jar)
+    sys.exit("Effective T3 model JAR file not found: %r" % effective_t3_model)
 
 # We will have write access whereever the output should be,
 temp_file = os.path.abspath(tabular_file + ".tmp")
@@ -115,7 +112,7 @@
 tabular_file = os.path.abspath(tabular_file)
 fasta_file = os.path.abspath(fasta_file)
 
-cmd = ["java", "-jar", effectiveT3_jar,
+cmd = ["java", "-jar", effective_t3_jar,
        "-f", fasta_file,
        "-m", model,
        "-t", threshold,
@@ -124,14 +121,14 @@
 
 try:
     # Must run from directory above the module subfolder:
-    os.chdir(effectiveT3_dir)
-except:
-    sys_exit("Could not change to Effective T3 folder: %s" % effectiveT3_dir)
+    os.chdir(effective_t3_dir)
+except Exception:
+    sys.exit("Could not change to Effective T3 folder: %s" % effective_t3_dir)
 
 run(cmd)
 
 if not os.path.isfile(temp_file):
-   sys_exit("ERROR - No output file from Effective T3")
+    sys.exit("ERROR - No output file from Effective T3")
 
 out_handle = open(tabular_file, "w")
 out_handle.write("#ID\tDescription\tScore\tEffective\n")
@@ -143,11 +140,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
-   sys_exit("All your sequences gave an error code")
+if count and count == errors:
+    # Galaxy will still  allow them to see the output file
+    sys.exit("All your sequences gave an error code")
--- a/tools/effectiveT3/effectiveT3.xml	Mon Sep 21 05:52:29 2015 -0400
+++ b/tools/effectiveT3/effectiveT3.xml	Wed Feb 01 09:22:21 2017 -0500
@@ -1,4 +1,4 @@
-<tool id="effectiveT3" name="Effective T3" version="0.0.16">
+<tool id="effectiveT3" name="Effective T3" version="0.0.17">
     <description>Find bacterial effectors in protein sequences</description>
     <requirements>
         <requirement type="package" version="1.0.1">effectiveT3</requirement>
--- a/tools/effectiveT3/tool_dependencies.xml	Mon Sep 21 05:52:29 2015 -0400
+++ b/tools/effectiveT3/tool_dependencies.xml	Wed Feb 01 09:22:21 2017 -0500
@@ -3,29 +3,34 @@
     <package name="effectiveT3" version="1.0.1">
         <install version="1.0">
             <actions>
-                <!-- Set environment variable so Python script knows where to look -->
+                <!-- Main JAR file -->
+                <!-- Original URL http://effectors.csb.univie.ac.at/sites/eff/files/others/TTSS_GUI-1.0.1.jar -->
+                <action type="download_file" sha256sum="5a811a86a14dffbc5ae91dc45f40791642b8866266ffd2337b97d4c298129cab" target_filename="TTSS_GUI-1.0.1.jar">https://depot.galaxyproject.org/software/TTSS_GUI/TTSS_GUI_1.0.1_src_all.jar</action>
+                <action type="move_file"><source>TTSS_GUI-1.0.1.jar</source><destination>$INSTALL_DIR</destination></action>
+                <!-- Model specific JAR files -->
+                <action type="make_directory">$INSTALL_DIR/module</action>
+                <!-- Original URL http://effectors.csb.univie.ac.at/sites/eff/files/others/TTSS_ANIMAL-1.0.1.jar -->
+                <action type="download_file" sha256sum="3d9cd8e805387d2dfa855076b3d5f7f97334aa612288075111329fb036c94e34" target_filename="TTSS_ANIMAL-1.0.1.jar">https://depot.galaxyproject.org/software/TTSS_ANIMAL/TTSS_ANIMAL_1.0.1_src_all.jar</action>
+                <action type="move_file"><source>TTSS_ANIMAL-1.0.1.jar</source><destination>$INSTALL_DIR/module/</destination></action>        
+                <!-- Original URL http://effectors.csb.univie.ac.at/sites/eff/files/others/TTSS_PLANT-1.0.1.jar -->
+                <action type="download_file" sha256sum="593f0052ace030c2fa16cf336f3916a21bc2addbaefdfa149b084b1425e42a13" target_filename="TTSS_PLANT-1.0.1.jar">https://depot.galaxyproject.org/software/TTSS_PLANT/TTSS_PLANT_1.0.1_src_all.jar</action>
+                <action type="move_file"><source>TTSS_PLANT-1.0.1.jar</source><destination>$INSTALL_DIR/module/</destination></action>
+                <!-- Original URL http://effectors.csb.univie.ac.at/sites/eff/files/others/TTSS_STD-1.0.1.jar -->
+                <action type="download_file" sha256sum="865809e5ead6d8bb038e854ccaebc7c102b72738ff3557553af9b9ac8e529336" target_filename="TTSS_STD-1.0.1.jar">https://depot.galaxyproject.org/software/TTSS_STD/TTSS_STD_1.0.1_src_all.jar</action>
+                <action type="move_file"><source>TTSS_STD-1.0.1.jar</source><destination>$INSTALL_DIR/module/</destination></action>
+                <!-- Original URL http://effectors.csb.univie.ac.at/sites/eff/files/others/TTSS_STD-2.0.2.jar -->
+                <action type="download_file" sha256sum="860c6e3680fa1f3c6ac2362605205af4cdd9a1caefee59fdbd37d1453c9bad44" target_filename="TTSS_STD-2.0.2.jar">https://depot.galaxyproject.org/software/TTSS_STD/TTSS_STD_2.0.2_src_all.jar</action>
+                <action type="move_file"><source>TTSS_STD-2.0.2.jar</source><destination>$INSTALL_DIR/module/</destination></action>
+                <!-- Make this accessible -->
                 <action type="set_environment">
                     <environment_variable name="EFFECTIVET3" action="set_to">$INSTALL_DIR</environment_variable>
                 </action>
-                <!-- Main JAR file -->
-                <action type="shell_command">wget http://effectors.csb.univie.ac.at/sites/eff/files/others/TTSS_GUI-1.0.1.jar</action>
-                <!-- If using action type download_file will need to move the file,
-                <action type="move_file"><source>TTSS_GUI-1.0.1.jar</source><destination>$INSTALL_DIR/</destination></action>
-                -->
-                <!-- Three model JAR files -->
-                <action type="make_directory">$INSTALL_DIR/module</action>
-                <action type="shell_command">wget http://effectors.csb.univie.ac.at/sites/eff/files/others/TTSS_ANIMAL-1.0.1.jar</action>
-                <action type="move_file"><source>TTSS_ANIMAL-1.0.1.jar</source><destination>$INSTALL_DIR/module/</destination></action>        
-                <action type="shell_command">wget http://effectors.csb.univie.ac.at/sites/eff/files/others/TTSS_PLANT-1.0.1.jar</action>
-                <action type="move_file"><source>TTSS_PLANT-1.0.1.jar</source><destination>$INSTALL_DIR/module/</destination></action>
-                <action type="shell_command">wget http://effectors.csb.univie.ac.at/sites/eff/files/others/TTSS_STD-1.0.1.jar</action>
-                <action type="move_file"><source>TTSS_STD-1.0.1.jar</source><destination>$INSTALL_DIR/module/</destination></action>
-                <action type="shell_command">wget http://effectors.csb.univie.ac.at/sites/eff/files/others/TTSS_STD-2.0.2.jar</action>
-                <action type="move_file"><source>TTSS_STD-2.0.2.jar</source><destination>$INSTALL_DIR/module/</destination></action>
             </actions>
         </install>
         <readme>
 Downloads effectiveT3 v1.0.1 and associated models from http://effectors.org/ aka http://effectors.csb.univie.ac.at/
+
+Sets environment variable $EFFECTIVET3 to the directory containing the main JAR file whose subdirectory module/ holds the model JAR files.
         </readme>
     </package>
 </tool_dependency>