Mercurial > repos > trinity_ctat > edger_differential_expression
comparison EdgeR_differentialExpression_wrapper.py @ 0:023628c034b6 draft
Adding EdgeR differential expression.
| author | trinity_ctat |
|---|---|
| date | Fri, 29 Sep 2017 13:42:30 -0400 |
| parents | |
| children | 70b3058d39d9 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:023628c034b6 |
|---|---|
| 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, or ensure that directory is in the PATH before running.") | |
| 41 sys.exit(1) | |
| 42 | |
| 43 usage= "usage: " + " $counts_matrix" + " $dispersion" | |
| 44 | |
| 45 if len(sys.argv)<2: | |
| 46 print "Require at least two parameters, " + usage | |
| 47 else: | |
| 48 print "All good- command going ahead" | |
| 49 print " " | |
| 50 | |
| 51 def run_command(cmd): | |
| 52 print "The command used: " + cmd | |
| 53 pipe=subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE) | |
| 54 pipe.wait() | |
| 55 ret= pipe.returncode | |
| 56 if ret: | |
| 57 print "command died: " + str(ret) | |
| 58 print pipe.stderr.readlines() | |
| 59 sys.exit(1) | |
| 60 else: | |
| 61 return | |
| 62 print " " | |
| 63 | |
| 64 countmatrix= "counts_matrix" | |
| 65 | |
| 66 cmd= "cp " + sys.argv[1] + " " + countmatrix | |
| 67 run_command(cmd) | |
| 68 | |
| 69 cmd= TRINITY_BASE_DIR + "/Analysis/DifferentialExpression/run_DE_analysis.pl "+ " --matrix "+ countmatrix + " --method edgeR " + " --output edgeR_results "+ " --dispersion " + sys.argv[2] + " --tar_gz_outdir" | |
| 70 | |
| 71 run_command(cmd) | |
| 72 | |
| 73 sys.exit(0) |
