Mercurial > repos > peterjc > effectivet3
annotate tools/effectiveT3/effectiveT3.py @ 32:1129cafdf0ae draft
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
| author | peterjc | 
|---|---|
| date | Wed, 07 Jun 2017 10:51:31 -0400 | 
| parents | 3ef6c246ccac | 
| children | 011cfce866f1 | 
| rev | line source | 
|---|---|
| 2 | 1 #!/usr/bin/env python | 
| 2 """Wrapper for EffectiveT3 v1.0.1 for use in Galaxy. | |
| 3 | |
| 4 This script takes exactly five command line arguments: | |
| 5 * model name (e.g. TTSS_STD-1.0.1.jar) | |
| 6 * threshold (selective or sensitive) | |
| 7 * an input protein FASTA filename | |
| 8 * output tabular filename | |
| 9 | |
| 10 It then calls the standalone Effective T3 v1.0.1 program (not the | |
| 11 webservice), and reformats the semi-colon separated output into | |
| 12 tab separated output for use in Galaxy. | |
| 13 """ | |
| 14 import os | |
| 32 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 15 # We want to be able to use shutil.which, but need Python 3.3+ | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 16 # import shutil | 
| 2 | 17 import subprocess | 
| 25 
69ba0f4e91af
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit 5fb6ee31f33e8e24c1ae5d56c93ac3e0157dad72-dirty
 peterjc parents: 
24diff
changeset | 18 import sys | 
| 2 | 19 | 
| 32 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 20 # The Galaxy auto-install via tool_dependencies.xml will set the | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 21 # environment variable $EFFECTIVET3 pointing at the folder with | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 22 # the JAR file. | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 23 # | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 24 # The BioConda recipe will put a wrapper script on the $PATH, | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 25 # which we can use to find the JAR file. | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 26 # | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 27 # We fall back on /opt/EffectiveT3/ | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 28 # | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 29 effective_t3_jarname = "TTSS_GUI-1.0.1.jar" | 
| 2 | 30 | 
| 31 if "-v" in sys.argv or "--version" in sys.argv: | |
| 15 
17fbf8b8a554
Uploaded v0.0.13, embed citation, relax test for floating point differences
 peterjc parents: 
9diff
changeset | 32 # TODO - Get version of the JAR file dynamically? | 
| 32 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 33 print("Wrapper v0.0.20, for %s" % effective_t3_jarname) | 
| 2 | 34 sys.exit(0) | 
| 35 | |
| 36 if len(sys.argv) != 5: | |
| 23 | 37 sys.exit("Require four arguments: model, threshold, input protein FASTA file & output tabular file") | 
| 2 | 38 | 
| 39 model, threshold, fasta_file, tabular_file = sys.argv[1:] | |
| 40 | |
| 41 if not os.path.isfile(fasta_file): | |
| 23 | 42 sys.exit("Input FASTA file not found: %s" % fasta_file) | 
| 2 | 43 | 
| 24 
a3d660e900b1
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit 7a746d55f0e8456992ee11c49a507285f9f39383-dirty
 peterjc parents: 
23diff
changeset | 44 if threshold not in ["selective", "sensitive"] and not threshold.startswith("cutoff="): | 
| 23 | 45 sys.exit("Threshold should be selective, sensitive, or cutoff=..., not %r" % threshold) | 
| 46 | |
| 2 | 47 | 
| 48 def clean_tabular(raw_handle, out_handle): | |
| 49 """Clean up Effective T3 output to make it tabular.""" | |
| 50 count = 0 | |
| 51 positive = 0 | |
| 52 errors = 0 | |
| 53 for line in raw_handle: | |
| 24 
a3d660e900b1
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit 7a746d55f0e8456992ee11c49a507285f9f39383-dirty
 peterjc parents: 
23diff
changeset | 54 if not line or line.startswith("#") or line.startswith("Id; Description; Score;"): | 
| 2 | 55 continue | 
| 56 assert line.count(";") >= 3, repr(line) | |
| 15 
17fbf8b8a554
Uploaded v0.0.13, embed citation, relax test for floating point differences
 peterjc parents: 
9diff
changeset | 57 # Normally there will just be three semi-colons, however the | 
| 
17fbf8b8a554
Uploaded v0.0.13, embed citation, relax test for floating point differences
 peterjc parents: 
9diff
changeset | 58 # original FASTA file's ID or description might have had | 
| 
17fbf8b8a554
Uploaded v0.0.13, embed citation, relax test for floating point differences
 peterjc parents: 
9diff
changeset | 59 # semi-colons in it as well, hence the following hackery: | 
| 2 | 60 try: | 
| 23 | 61 id_descr, score, effective = line.rstrip("\r\n").rsplit(";", 2) | 
| 15 
17fbf8b8a554
Uploaded v0.0.13, embed citation, relax test for floating point differences
 peterjc parents: 
9diff
changeset | 62 # Cope when there was no FASTA description | 
| 2 | 63 if "; " not in id_descr and id_descr.endswith(";"): | 
| 64 id = id_descr[:-1] | |
| 65 descr = "" | |
| 66 else: | |
| 23 | 67 id, descr = id_descr.split("; ", 1) | 
| 2 | 68 except ValueError: | 
| 23 | 69 sys.exit("Problem parsing line:\n%s\n" % line) | 
| 2 | 70 parts = [s.strip() for s in [id, descr, score, effective]] | 
| 71 out_handle.write("\t".join(parts) + "\n") | |
| 72 count += 1 | |
| 73 if float(score) < 0: | |
| 23 | 74 errors += 1 | 
| 2 | 75 if effective.lower() == "true": | 
| 23 | 76 positive += 1 | 
| 2 | 77 return count, positive, errors | 
| 78 | |
| 23 | 79 | 
| 2 | 80 def run(cmd): | 
| 27 
af14f755c05b
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit 7496128ee9ef800fe780e545d2157da8a4f89d35-dirty
 peterjc parents: 
25diff
changeset | 81 """Run the command line string via subprocess.""" | 
| 15 
17fbf8b8a554
Uploaded v0.0.13, embed citation, relax test for floating point differences
 peterjc parents: 
9diff
changeset | 82 # Avoid using shell=True when we call subprocess to ensure if the Python | 
| 
17fbf8b8a554
Uploaded v0.0.13, embed citation, relax test for floating point differences
 peterjc parents: 
9diff
changeset | 83 # script is killed, so too is the child process. | 
| 2 | 84 try: | 
| 31 
3ef6c246ccac
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit 79bbb921cb5aa953f0323accd6c8c293c6e486cf-dirty
 peterjc parents: 
30diff
changeset | 85 child = subprocess.Popen(cmd, universal_newlines=True, | 
| 
3ef6c246ccac
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit 79bbb921cb5aa953f0323accd6c8c293c6e486cf-dirty
 peterjc parents: 
30diff
changeset | 86 stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 
| 29 
35c358aa7801
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit 37d5b47ec23e2cbaa453cc660bb1fcbb10dd34ee-dirty
 peterjc parents: 
27diff
changeset | 87 except Exception as err: | 
| 23 | 88 sys.exit("Error invoking command:\n%s\n\n%s\n" % (" ".join(cmd), err)) | 
| 15 
17fbf8b8a554
Uploaded v0.0.13, embed citation, relax test for floating point differences
 peterjc parents: 
9diff
changeset | 89 # Use .communicate as can get deadlocks with .wait(), | 
| 2 | 90 stdout, stderr = child.communicate() | 
| 91 return_code = child.returncode | |
| 18 | 92 if return_code or stderr.startswith("Exception in thread"): | 
| 23 | 93 cmd_str = " ".join(cmd) # doesn't quote spaces etc | 
| 2 | 94 if stderr and stdout: | 
| 23 | 95 sys.exit("Return code %i from command:\n%s\n\n%s\n\n%s" % (return_code, cmd_str, stdout, stderr)) | 
| 2 | 96 else: | 
| 23 | 97 sys.exit("Return code %i from command:\n%s\n%s" % (return_code, cmd_str, stderr)) | 
| 2 | 98 | 
| 18 | 99 | 
| 32 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 100 try: | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 101 from shutil import which | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 102 except ImportError: | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 103 # Likely running on Python 2, use backport: | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 104 def which(cmd, mode=os.F_OK | os.X_OK, path=None): | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 105 """Given a command, mode, and a PATH string, return the path which | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 106 conforms to the given mode on the PATH, or None if there is no such | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 107 file. | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 108 `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 109 of os.environ.get("PATH"), or can be overridden with a custom search | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 110 path. | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 111 """ | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 112 | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 113 # Check that a given file can be accessed with the correct mode. | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 114 # Additionally check that `file` is not a directory, as on Windows | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 115 # directories pass the os.access check. | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 116 def _access_check(fn, mode): | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 117 return (os.path.exists(fn) and os.access(fn, mode) and | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 118 not os.path.isdir(fn)) | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 119 | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 120 # Short circuit. If we're given a full path which matches the mode | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 121 # and it exists, we're done here. | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 122 if _access_check(cmd, mode): | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 123 return cmd | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 124 | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 125 path = (path or os.environ.get("PATH", os.defpath)).split(os.pathsep) | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 126 | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 127 if sys.platform == "win32": | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 128 # The current directory takes precedence on Windows. | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 129 if os.curdir not in path: | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 130 path.insert(0, os.curdir) | 
| 2 | 131 | 
| 32 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 132 # PATHEXT is necessary to check on Windows. | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 133 pathext = os.environ.get("PATHEXT", "").split(os.pathsep) | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 134 # See if the given file matches any of the expected path extensions. | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 135 # This will allow us to short circuit when given "python.exe". | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 136 matches = [cmd for ext in pathext if cmd.lower().endswith(ext.lower())] | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 137 # If it does match, only test that one, otherwise we have to try | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 138 # others. | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 139 files = [cmd] if matches else [cmd + ext.lower() for ext in pathext] | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 140 else: | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 141 # On other platforms you don't have things like PATHEXT to tell you | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 142 # what file suffixes are executable, so just pass on cmd as-is. | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 143 files = [cmd] | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 144 | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 145 seen = set() | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 146 for dir in path: | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 147 dir = os.path.normcase(dir) | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 148 if dir not in seen: | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 149 seen.add(dir) | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 150 for thefile in files: | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 151 name = os.path.join(dir, thefile) | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 152 if _access_check(name, mode): | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 153 return name | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 154 return None | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 155 | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 156 | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 157 # Try in order the following to find the JAR file: | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 158 # - Location of any wrapper script, e.g. from BioConda installation | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 159 # - The $EFFECTIVET3 env var, e.g. old-style Galaxy tool installation | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 160 # - The /opt/EffectiveT3/ folder. | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 161 effective_t3_jar = None | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 162 effective_t3_dir = None | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 163 dirs = ["/opt/EffectiveT3/"] | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 164 if "EFFECTIVET3" in os.environ: | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 165 dirs.insert(0, os.environ.get("EFFECTIVET3")) | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 166 if which("effectivet3"): | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 167 # Assuming this is a BioConda installed wrapper for effective T3, | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 168 # this will get the directory of the wrapper script which is where | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 169 # the JAR file will be: | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 170 dirs.insert(0, os.path.split(os.path.realpath(which("effectivet3")))[0]) | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 171 for effective_t3_dir in dirs: | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 172 effective_t3_jar = os.path.join(effective_t3_dir, effective_t3_jarname) | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 173 if os.path.isfile(effective_t3_jar): | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 174 # Good | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 175 break | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 176 effective_t3_jar = None | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 177 if not effective_t3_dir or not effective_t3_jar: | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 178 sys.exit("Effective T3 JAR file %r not found in %r" % (effective_t3_jarname, dirs)) | 
| 2 | 179 | 
| 23 | 180 if not os.path.isdir(os.path.join(effective_t3_dir, "module")): | 
| 181 sys.exit("Effective T3 module folder not found: %r" % os.path.join(effective_t3_dir, "module")) | |
| 9 
b863c4bec840
Uploaded v0.0.11, take 10, debug output if module folder missing
 peterjc parents: 
8diff
changeset | 182 | 
| 23 | 183 effective_t3_model = os.path.join(effective_t3_dir, "module", model) | 
| 184 if not os.path.isfile(effective_t3_model): | |
| 8 
4a0aa59062f7
Uploaded v0.0.11, take 9, debug output if can't find model
 peterjc parents: 
2diff
changeset | 185 sys.stderr.write("Contents of %r is %s\n" | 
| 23 | 186 % (os.path.join(effective_t3_dir, "module"), | 
| 187 ", ".join(repr(p) for p in os.listdir(os.path.join(effective_t3_dir, "module"))))) | |
| 188 sys.stderr.write("Main JAR was found: %r\n" % effective_t3_jar) | |
| 189 sys.exit("Effective T3 model JAR file not found: %r" % effective_t3_model) | |
| 2 | 190 | 
| 30 
007e86eff414
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit 7ea917a606c9226a0c902504f963577c8986d4a5-dirty
 peterjc parents: 
29diff
changeset | 191 # We will have write access wherever the output should be, | 
| 32 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 192 if tabular_file == "/dev/stdout": | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 193 temp_file = os.path.abspath("effectivet3_tabular_output.tmp") | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 194 else: | 
| 
1129cafdf0ae
planemo upload for repository https://github.com/peterjc/pico_galaxy/tree/master/tools/effectiveT3 commit b557cc18c85dcc5147b80c71f99c16a7015e12b2-dirty
 peterjc parents: 
31diff
changeset | 195 temp_file = os.path.abspath(tabular_file + ".tmp") | 
| 2 | 196 | 
| 15 
17fbf8b8a554
Uploaded v0.0.13, embed citation, relax test for floating point differences
 peterjc parents: 
9diff
changeset | 197 # Use absolute paths since will change current directory... | 
| 2 | 198 tabular_file = os.path.abspath(tabular_file) | 
| 199 fasta_file = os.path.abspath(fasta_file) | |
| 200 | |
| 23 | 201 cmd = ["java", "-jar", effective_t3_jar, | 
| 2 | 202 "-f", fasta_file, | 
| 203 "-m", model, | |
| 204 "-t", threshold, | |
| 205 "-o", temp_file, | |
| 206 "-q"] | |
| 207 | |
| 208 try: | |
| 15 
17fbf8b8a554
Uploaded v0.0.13, embed citation, relax test for floating point differences
 peterjc parents: 
9diff
changeset | 209 # Must run from directory above the module subfolder: | 
| 23 | 210 os.chdir(effective_t3_dir) | 
| 211 except Exception: | |
| 212 sys.exit("Could not change to Effective T3 folder: %s" % effective_t3_dir) | |
| 2 | 213 | 
| 214 run(cmd) | |
| 215 | |
| 216 if not os.path.isfile(temp_file): | |
| 23 | 217 sys.exit("ERROR - No output file from Effective T3") | 
| 2 | 218 | 
| 219 out_handle = open(tabular_file, "w") | |
| 220 out_handle.write("#ID\tDescription\tScore\tEffective\n") | |
| 221 data_handle = open(temp_file) | |
| 222 count, positive, errors = clean_tabular(data_handle, out_handle) | |
| 223 data_handle.close() | |
| 224 out_handle.close() | |
| 225 | |
| 226 os.remove(temp_file) | |
| 227 | |
| 228 if errors: | |
| 23 | 229 print("%i sequences, %i positive, %i errors" | 
| 230 % (count, positive, errors)) | |
| 2 | 231 else: | 
| 23 | 232 print("%i/%i sequences positive" % (positive, count)) | 
| 2 | 233 | 
| 23 | 234 if count and count == errors: | 
| 235 # Galaxy will still allow them to see the output file | |
| 236 sys.exit("All your sequences gave an error code") | 
