changeset 3:70b3058d39d9 draft

Adding more debugging statements.
author trinity_ctat
date Mon, 02 Oct 2017 14:36:31 -0400
parents 93f07220f08c
children bfd09008aae7
files EdgeR_differentialExpression_wrapper.py
diffstat 1 files changed, 22 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/EdgeR_differentialExpression_wrapper.py	Fri Sep 29 14:12:02 2017 -0400
+++ b/EdgeR_differentialExpression_wrapper.py	Mon Oct 02 14:36:31 2017 -0400
@@ -37,7 +37,8 @@
         # Take off the last part of the path (which is the Trinity command)
         TRINITY_BASE_DIR = "/".join(TrinityPath.split("/")[0:-1])
 else:
-    sys.stderr.write("Either set TRINITY_HOME to the trinity base directory, or ensure that directory is in the PATH before running.")
+    sys.stderr.write("Either set TRINITY_HOME to the trinity base directory, " + \
+        "or ensure that directory is in the PATH before running.")
     sys.exit(1)
 
 usage= "usage: " + " $counts_matrix" + " $dispersion"
@@ -49,17 +50,30 @@
 print " "
 
 def run_command(cmd):
-    print "The command used: " + cmd
-    pipe=subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE)
-    pipe.wait()
-    ret= pipe.returncode
+    # 2017-10-02
+    # Cicada Dennis put the subprocess command in a try/except statement.
+    # Errors were going undetected the way it was written previously.
+    print "Running command:\n\t" + cmd
+    try:
+        pipe = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
+        cmd_stdout, cmd_stderr = pipe.communicate()
+    except:
+        msg = "ERROR while running command:\n\t" + cmd
+        sys.stderr.write(msg)
+        raise
+    
+    sys.stdout.write(cmd_stdout)
+    ret = pipe.returncode
     if ret:
         print "command died: " + str(ret)
-        print pipe.stderr.readlines()
-        sys.exit(1)
+        sys.stderr.write(cmd_stderr)
+        sys.exit(ret)
     else:
+        # Any error output is written to stdout instead of stderr, since no error has occurred.
+        sys.stderr.write(cmd_stderr) 
         return
-print " "
+
+print ""
 
 countmatrix= "counts_matrix"
 
@@ -67,7 +81,6 @@
 run_command(cmd)
 
 cmd= TRINITY_BASE_DIR + "/Analysis/DifferentialExpression/run_DE_analysis.pl "+ " --matrix "+ countmatrix + " --method edgeR " + " --output edgeR_results "+ " --dispersion " + sys.argv[2] + " --tar_gz_outdir"
-
 run_command(cmd)
 
 sys.exit(0)