diff tools/effectiveT3/effectiveT3.py @ 6:0f6eb4a75000 draft

v0.0.15 internal changes; v0.0.14 fixed error handling
author peterjc
date Wed, 05 Aug 2015 11:04:42 -0400
parents 1ea715da1879
children 5f85301d50bf
line wrap: on
line diff
--- a/tools/effectiveT3/effectiveT3.py	Tue Nov 25 08:28:24 2014 -0500
+++ b/tools/effectiveT3/effectiveT3.py	Wed Aug 05 11:04:42 2015 -0400
@@ -21,25 +21,25 @@
 
 if "-v" in sys.argv or "--version" in sys.argv:
     # TODO - Get version of the JAR file dynamically?
-    print("Wrapper v0.0.13, TTSS_GUI-1.0.1.jar")
+    print("Wrapper v0.0.14, TTSS_GUI-1.0.1.jar")
     sys.exit(0)
 
-def stop_err(msg, error_level=1):
+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:
-   stop_err("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):
-   stop_err("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="):
-   stop_err("Threshold should be selective, sensitive, or cutoff=..., not %r" % threshold)
+   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."""
@@ -63,7 +63,7 @@
             else:
                 id, descr = id_descr.split("; ",1)
         except ValueError:
-            stop_err("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
@@ -79,25 +79,25 @@
     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))
+        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:
-            stop_err("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:
-            stop_err("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):
-    stop_err("Effective T3 folder not found: %r" % effectiveT3_dir)
+    sys_exit("Effective T3 folder not found: %r" % effectiveT3_dir)
 
 if not os.path.isfile(effectiveT3_jar):
-    stop_err("Effective T3 JAR file not found: %r" % effectiveT3_jar)
+    sys_exit("Effective T3 JAR file not found: %r" % effectiveT3_jar)
 
 if not os.path.isdir(os.path.join(effectiveT3_dir, "module")):
-    stop_err("Effective T3 module folder not found: %r" % os.path.join(effectiveT3_dir, "module"))
+    sys_exit("Effective T3 module folder not found: %r" % os.path.join(effectiveT3_dir, "module"))
 
 effectiveT3_model = os.path.join(effectiveT3_dir, "module", model)
 if not os.path.isfile(effectiveT3_model):
@@ -105,7 +105,7 @@
                      % (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)
-    stop_err("Effective T3 model JAR file not found: %r" % effectiveT3_model)
+    sys_exit("Effective T3 model JAR file not found: %r" % effectiveT3_model)
 
 # We will have write access whereever the output should be,
 temp_file = os.path.abspath(tabular_file + ".tmp")
@@ -125,12 +125,12 @@
     # 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)
+    sys_exit("Could not change to Effective T3 folder: %s" % effectiveT3_dir)
 
 run(cmd)
 
 if not os.path.isfile(temp_file):
-   stop_err("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")
@@ -149,4 +149,4 @@
 
 if count and count==errors:
    # Galaxy will still  allow them to see the output file
-   stop_err("All your sequences gave an error code")
+   sys_exit("All your sequences gave an error code")