annotate tools/effectiveT3/effectiveT3.py @ 11:ed8c1babc166 draft default tip

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