0
|
1 import sys, os, subprocess
|
|
2
|
|
3 TRINITY_BASE_DIR = ""
|
|
4 if os.environ.has_key('TRINITY_HOME'):
|
|
5 TRINITY_BASE_DIR = os.environ['TRINITY_HOME'];
|
|
6 elif hasattr(os, 'symlink'): # symlink was implemented to always return false when it was not implemented in earlier versions of python.
|
|
7 # 2017-09-26
|
|
8 # Cicada Dennis added looking for the location of the Trinity program using the Unix "which" utility.
|
|
9 # I tried using "command -v Trinity" but for some reason, I was getting a OS permission error with that.
|
|
10 # I also found distutils.spawn.find_executable() which might work, but already implemented the below.
|
|
11 try:
|
|
12 pipe1 = subprocess.Popen(["which", "Trinity"], stdout=subprocess.PIPE)
|
|
13 except:
|
|
14 msg = "You must set the environmental variable TRINITY_HOME to the base installation directory of Trinity before running {:s}.\n".format(sys.argv[0])
|
|
15 sys.stderr.write(msg)
|
|
16 # t, v, tb = sys.exc_info()
|
|
17 # raise t, v, tb
|
|
18 # For some reason the above was giving a syntax error.
|
|
19 # A simple raise should reraise the existing exception.
|
|
20 raise
|
|
21 else:
|
|
22 TrinityPath, err_info = pipe1.communicate()
|
|
23 # FIX - probably should be checking err_info for errors...
|
|
24 # Determine the TRINITY_BASE_DIR from output1.
|
|
25 # If TrinityPath is a link, we need to dereference the link.
|
|
26 TrinityPath = TrinityPath.rstrip() # Need to strip off a newline.
|
|
27 # print "Trinity that was found is: {:s}".format(repr(TrinityPath))
|
|
28 # print os.path.islink(TrinityPath)
|
|
29 TrinityPath = os.path.abspath(TrinityPath)
|
|
30 # msg = "The Absolute Trinity path that was found is: {:s}".format(TrinityPath)
|
|
31 # print msg
|
|
32 # print os.path.islink(TrinityPath)
|
|
33 while os.path.islink(TrinityPath):
|
|
34 # print "That path is a link."
|
|
35 TrinityPath = os.path.join(os.path.dirname(TrinityPath),os.readlink(TrinityPath))
|
|
36 # print "The new path is: {:s}".format(TrinityPath)
|
|
37 # Take off the last part of the path (which is the Trinity command)
|
|
38 TRINITY_BASE_DIR = "/".join(TrinityPath.split("/")[0:-1])
|
|
39 else:
|
|
40 sys.stderr.write("Either set TRINITY_HOME to the trinity base directory, " + \
|
|
41 "or ensure that directory is in the PATH before running.")
|
|
42 sys.exit(1)
|
|
43
|
|
44 usage= "usage: " + " $counts_matrix" + " $dispersion"
|
|
45
|
|
46 if len(sys.argv)<2:
|
|
47 print "Require at least two parameters, " + usage
|
|
48 else:
|
|
49 print "All good- command going ahead"
|
|
50 print " "
|
|
51
|
|
52 def run_command(cmd):
|
|
53 # 2017-10-02
|
|
54 # Cicada Dennis put the subprocess command in a try/except statement.
|
|
55 # Errors were going undetected the way it was written previously.
|
|
56 print "Running command:\n\t" + cmd
|
|
57 try:
|
|
58 pipe = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
|
59 cmd_stdout, cmd_stderr = pipe.communicate()
|
|
60 except:
|
|
61 msg = "ERROR while running command:\n\t" + cmd
|
|
62 sys.stderr.write(msg)
|
|
63 raise
|
|
64
|
|
65 sys.stdout.write(cmd_stdout)
|
|
66 ret = pipe.returncode
|
|
67 if ret:
|
|
68 print "command died: " + str(ret)
|
|
69 sys.stderr.write(cmd_stderr)
|
|
70 sys.exit(ret)
|
|
71 else:
|
|
72 # Any error output is written to stdout instead of stderr, since no error has occurred.
|
|
73 sys.stderr.write(cmd_stderr)
|
|
74 return
|
|
75
|
|
76 print ""
|
|
77
|
|
78 countmatrix= "counts_matrix"
|
|
79
|
|
80 cmd= "cp " + sys.argv[1] + " " + countmatrix
|
|
81 run_command(cmd)
|
|
82
|
|
83 cmd= TRINITY_BASE_DIR + "/Analysis/DifferentialExpression/run_DE_analysis.pl "+ " --matrix "+ countmatrix + " --method edgeR " + " --output edgeR_results "+ " --dispersion " + sys.argv[2] + " --tar_gz_outdir"
|
|
84
|
|
85 run_command(cmd)
|
|
86
|
|
87 sys.exit(0)
|