annotate toolfactory/test-data/input1_sample @ 1:0183cad9d13b draft

planemo upload
author fubar
date Thu, 22 Feb 2024 10:48:01 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1 #!/usr/bin/env python
0183cad9d13b planemo upload
fubar
parents:
diff changeset
2 # rgToolFactory.py
0183cad9d13b planemo upload
fubar
parents:
diff changeset
3 # see https://github.com/fubar2/toolfactory
0183cad9d13b planemo upload
fubar
parents:
diff changeset
4 #
0183cad9d13b planemo upload
fubar
parents:
diff changeset
5 # copyright ross lazarus (ross stop lazarus at gmail stop com) May 2012
0183cad9d13b planemo upload
fubar
parents:
diff changeset
6 #
0183cad9d13b planemo upload
fubar
parents:
diff changeset
7 # all rights reserved
0183cad9d13b planemo upload
fubar
parents:
diff changeset
8 # Licensed under the LGPL
0183cad9d13b planemo upload
fubar
parents:
diff changeset
9 # suggestions for improvement and bug fixes welcome at https://github.com/fubar2/toolfactory
0183cad9d13b planemo upload
fubar
parents:
diff changeset
10 #
0183cad9d13b planemo upload
fubar
parents:
diff changeset
11 # July 2020: BCC was fun and I feel like rip van winkle after 5 years.
0183cad9d13b planemo upload
fubar
parents:
diff changeset
12 # Decided to
0183cad9d13b planemo upload
fubar
parents:
diff changeset
13 # 1. Fix the toolfactory so it works - done for simplest case
0183cad9d13b planemo upload
fubar
parents:
diff changeset
14 # 2. Fix planemo so the toolfactory function works
0183cad9d13b planemo upload
fubar
parents:
diff changeset
15 # 3. Rewrite bits using galaxyxml functions where that makes sense - done
0183cad9d13b planemo upload
fubar
parents:
diff changeset
16 #
0183cad9d13b planemo upload
fubar
parents:
diff changeset
17 # removed all the old complications including making the new tool use this same script
0183cad9d13b planemo upload
fubar
parents:
diff changeset
18 # galaxyxml now generates the tool xml https://github.com/hexylena/galaxyxml
0183cad9d13b planemo upload
fubar
parents:
diff changeset
19 # No support for automatic HTML file creation from arbitrary outputs
0183cad9d13b planemo upload
fubar
parents:
diff changeset
20 # TODO: add option to run that code as a post execution hook
0183cad9d13b planemo upload
fubar
parents:
diff changeset
21 # TODO: add additional history input parameters - currently only one
0183cad9d13b planemo upload
fubar
parents:
diff changeset
22
0183cad9d13b planemo upload
fubar
parents:
diff changeset
23
0183cad9d13b planemo upload
fubar
parents:
diff changeset
24 import argparse
0183cad9d13b planemo upload
fubar
parents:
diff changeset
25 import logging
0183cad9d13b planemo upload
fubar
parents:
diff changeset
26 import os
0183cad9d13b planemo upload
fubar
parents:
diff changeset
27 import re
0183cad9d13b planemo upload
fubar
parents:
diff changeset
28 import shutil
0183cad9d13b planemo upload
fubar
parents:
diff changeset
29 import subprocess
0183cad9d13b planemo upload
fubar
parents:
diff changeset
30 import sys
0183cad9d13b planemo upload
fubar
parents:
diff changeset
31 import tarfile
0183cad9d13b planemo upload
fubar
parents:
diff changeset
32 import tempfile
0183cad9d13b planemo upload
fubar
parents:
diff changeset
33 import time
0183cad9d13b planemo upload
fubar
parents:
diff changeset
34
0183cad9d13b planemo upload
fubar
parents:
diff changeset
35 import galaxyxml.tool as gxt
0183cad9d13b planemo upload
fubar
parents:
diff changeset
36 import galaxyxml.tool.parameters as gxtp
0183cad9d13b planemo upload
fubar
parents:
diff changeset
37
0183cad9d13b planemo upload
fubar
parents:
diff changeset
38 import lxml
0183cad9d13b planemo upload
fubar
parents:
diff changeset
39
0183cad9d13b planemo upload
fubar
parents:
diff changeset
40 myversion = "V2.1 July 2020"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
41 verbose = True
0183cad9d13b planemo upload
fubar
parents:
diff changeset
42 debug = True
0183cad9d13b planemo upload
fubar
parents:
diff changeset
43 toolFactoryURL = "https://github.com/fubar2/toolfactory"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
44 ourdelim = "~~~"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
45
0183cad9d13b planemo upload
fubar
parents:
diff changeset
46 # --input_files="$input_files~~~$CL~~~$input_formats~~~$input_label
0183cad9d13b planemo upload
fubar
parents:
diff changeset
47 # ~~~$input_help"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
48 IPATHPOS = 0
0183cad9d13b planemo upload
fubar
parents:
diff changeset
49 ICLPOS = 1
0183cad9d13b planemo upload
fubar
parents:
diff changeset
50 IFMTPOS = 2
0183cad9d13b planemo upload
fubar
parents:
diff changeset
51 ILABPOS = 3
0183cad9d13b planemo upload
fubar
parents:
diff changeset
52 IHELPOS = 4
0183cad9d13b planemo upload
fubar
parents:
diff changeset
53 IOCLPOS = 5
0183cad9d13b planemo upload
fubar
parents:
diff changeset
54
0183cad9d13b planemo upload
fubar
parents:
diff changeset
55 # --output_files "$otab.history_name~~~$otab.history_format~~~$otab.CL
0183cad9d13b planemo upload
fubar
parents:
diff changeset
56 ONAMEPOS = 0
0183cad9d13b planemo upload
fubar
parents:
diff changeset
57 OFMTPOS = 1
0183cad9d13b planemo upload
fubar
parents:
diff changeset
58 OCLPOS = 2
0183cad9d13b planemo upload
fubar
parents:
diff changeset
59 OOCLPOS = 3
0183cad9d13b planemo upload
fubar
parents:
diff changeset
60
0183cad9d13b planemo upload
fubar
parents:
diff changeset
61 # --additional_parameters="$i.param_name~~~$i.param_value~~~
0183cad9d13b planemo upload
fubar
parents:
diff changeset
62 # $i.param_label~~~$i.param_help~~~$i.param_type~~~$i.CL~~~i$.param_CLoverride"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
63 ANAMEPOS = 0
0183cad9d13b planemo upload
fubar
parents:
diff changeset
64 AVALPOS = 1
0183cad9d13b planemo upload
fubar
parents:
diff changeset
65 ALABPOS = 2
0183cad9d13b planemo upload
fubar
parents:
diff changeset
66 AHELPPOS = 3
0183cad9d13b planemo upload
fubar
parents:
diff changeset
67 ATYPEPOS = 4
0183cad9d13b planemo upload
fubar
parents:
diff changeset
68 ACLPOS = 5
0183cad9d13b planemo upload
fubar
parents:
diff changeset
69 AOVERPOS = 6
0183cad9d13b planemo upload
fubar
parents:
diff changeset
70 AOCLPOS = 7
0183cad9d13b planemo upload
fubar
parents:
diff changeset
71
0183cad9d13b planemo upload
fubar
parents:
diff changeset
72
0183cad9d13b planemo upload
fubar
parents:
diff changeset
73 foo = len(lxml.__version__)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
74 # fug you, flake8. Say my name!
0183cad9d13b planemo upload
fubar
parents:
diff changeset
75
0183cad9d13b planemo upload
fubar
parents:
diff changeset
76 def timenow():
0183cad9d13b planemo upload
fubar
parents:
diff changeset
77 """return current time as a string
0183cad9d13b planemo upload
fubar
parents:
diff changeset
78 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
79 return time.strftime("%d/%m/%Y %H:%M:%S", time.localtime(time.time()))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
80
0183cad9d13b planemo upload
fubar
parents:
diff changeset
81
0183cad9d13b planemo upload
fubar
parents:
diff changeset
82 def quote_non_numeric(s):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
83 """return a prequoted string for non-numerics
0183cad9d13b planemo upload
fubar
parents:
diff changeset
84 useful for perl and Rscript parameter passing?
0183cad9d13b planemo upload
fubar
parents:
diff changeset
85 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
86 try:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
87 _ = float(s)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
88 return s
0183cad9d13b planemo upload
fubar
parents:
diff changeset
89 except ValueError:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
90 return '"%s"' % s
0183cad9d13b planemo upload
fubar
parents:
diff changeset
91
0183cad9d13b planemo upload
fubar
parents:
diff changeset
92
0183cad9d13b planemo upload
fubar
parents:
diff changeset
93 html_escape_table = {"&": "&amp;", ">": "&gt;", "<": "&lt;", "$": r"\$"}
0183cad9d13b planemo upload
fubar
parents:
diff changeset
94
0183cad9d13b planemo upload
fubar
parents:
diff changeset
95
0183cad9d13b planemo upload
fubar
parents:
diff changeset
96 def html_escape(text):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
97 """Produce entities within text."""
0183cad9d13b planemo upload
fubar
parents:
diff changeset
98 return "".join(html_escape_table.get(c, c) for c in text)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
99
0183cad9d13b planemo upload
fubar
parents:
diff changeset
100
0183cad9d13b planemo upload
fubar
parents:
diff changeset
101 def html_unescape(text):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
102 """Revert entities within text. Multiple character targets so use replace"""
0183cad9d13b planemo upload
fubar
parents:
diff changeset
103 t = text.replace("&amp;", "&")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
104 t = t.replace("&gt;", ">")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
105 t = t.replace("&lt;", "<")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
106 t = t.replace("\\$", "$")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
107 return t
0183cad9d13b planemo upload
fubar
parents:
diff changeset
108
0183cad9d13b planemo upload
fubar
parents:
diff changeset
109
0183cad9d13b planemo upload
fubar
parents:
diff changeset
110 def parse_citations(citations_text):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
111 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
112 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
113 citations = [c for c in citations_text.split("**ENTRY**") if c.strip()]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
114 citation_tuples = []
0183cad9d13b planemo upload
fubar
parents:
diff changeset
115 for citation in citations:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
116 if citation.startswith("doi"):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
117 citation_tuples.append(("doi", citation[len("doi") :].strip()))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
118 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
119 citation_tuples.append(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
120 ("bibtex", citation[len("bibtex") :].strip())
0183cad9d13b planemo upload
fubar
parents:
diff changeset
121 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
122 return citation_tuples
0183cad9d13b planemo upload
fubar
parents:
diff changeset
123
0183cad9d13b planemo upload
fubar
parents:
diff changeset
124
0183cad9d13b planemo upload
fubar
parents:
diff changeset
125 class ScriptRunner:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
126 """Wrapper for an arbitrary script
0183cad9d13b planemo upload
fubar
parents:
diff changeset
127 uses galaxyxml
0183cad9d13b planemo upload
fubar
parents:
diff changeset
128
0183cad9d13b planemo upload
fubar
parents:
diff changeset
129 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
130
0183cad9d13b planemo upload
fubar
parents:
diff changeset
131 def __init__(self, args=None):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
132 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
133 prepare command line cl for running the tool here
0183cad9d13b planemo upload
fubar
parents:
diff changeset
134 and prepare elements needed for galaxyxml tool generation
0183cad9d13b planemo upload
fubar
parents:
diff changeset
135 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
136
0183cad9d13b planemo upload
fubar
parents:
diff changeset
137 self.infiles = [x.split(ourdelim) for x in args.input_files]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
138 self.outfiles = [x.split(ourdelim) for x in args.output_files]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
139 self.addpar = [x.split(ourdelim) for x in args.additional_parameters]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
140 self.args = args
0183cad9d13b planemo upload
fubar
parents:
diff changeset
141 self.cleanuppar()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
142 self.lastclredirect = None
0183cad9d13b planemo upload
fubar
parents:
diff changeset
143 self.lastxclredirect = None
0183cad9d13b planemo upload
fubar
parents:
diff changeset
144 self.cl = []
0183cad9d13b planemo upload
fubar
parents:
diff changeset
145 self.xmlcl = []
0183cad9d13b planemo upload
fubar
parents:
diff changeset
146 self.is_positional = self.args.parampass == "positional"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
147 aCL = self.cl.append
0183cad9d13b planemo upload
fubar
parents:
diff changeset
148 assert args.parampass in [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
149 "0",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
150 "argparse",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
151 "positional",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
152 ], 'Parameter passing in args.parampass must be "0","positional" or "argparse"'
0183cad9d13b planemo upload
fubar
parents:
diff changeset
153 self.tool_name = re.sub("[^a-zA-Z0-9_]+", "", args.tool_name)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
154 self.tool_id = self.tool_name
0183cad9d13b planemo upload
fubar
parents:
diff changeset
155 if self.args.interpreter_name:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
156 exe = "$runMe"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
157 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
158 exe = self.args.exe_package
0183cad9d13b planemo upload
fubar
parents:
diff changeset
159 assert (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
160 exe is not None
0183cad9d13b planemo upload
fubar
parents:
diff changeset
161 ), "No interpeter or executable passed in - nothing to run so cannot build"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
162 self.tool = gxt.Tool(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
163 self.args.tool_name,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
164 self.tool_id,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
165 self.args.tool_version,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
166 self.args.tool_desc,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
167 exe,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
168 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
169 self.tinputs = gxtp.Inputs()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
170 self.toutputs = gxtp.Outputs()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
171 self.testparam = []
0183cad9d13b planemo upload
fubar
parents:
diff changeset
172 if (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
173 self.args.runmode == "Executable" or self.args.runmode == "system"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
174 ): # binary - no need
0183cad9d13b planemo upload
fubar
parents:
diff changeset
175 aCL(self.args.exe_package) # this little CL will just run
0183cad9d13b planemo upload
fubar
parents:
diff changeset
176 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
177 self.prepScript()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
178 self.elog = "%s_error_log.txt" % self.tool_name
0183cad9d13b planemo upload
fubar
parents:
diff changeset
179 self.tlog = "%s_runner_log.txt" % self.tool_name
0183cad9d13b planemo upload
fubar
parents:
diff changeset
180
0183cad9d13b planemo upload
fubar
parents:
diff changeset
181 if self.args.parampass == "0":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
182 self.clsimple()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
183 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
184 clsuffix = []
0183cad9d13b planemo upload
fubar
parents:
diff changeset
185 xclsuffix = []
0183cad9d13b planemo upload
fubar
parents:
diff changeset
186 for i, p in enumerate(self.infiles):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
187 if p[IOCLPOS] == "STDIN":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
188 appendme = [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
189 p[IOCLPOS],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
190 p[ICLPOS],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
191 p[IPATHPOS],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
192 "< %s" % p[IPATHPOS],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
193 ]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
194 xappendme = [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
195 p[IOCLPOS],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
196 p[ICLPOS],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
197 p[IPATHPOS],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
198 "< $%s" % p[ICLPOS],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
199 ]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
200 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
201 appendme = [p[IOCLPOS], p[ICLPOS], p[IPATHPOS], ""]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
202 xappendme = [p[IOCLPOS], p[ICLPOS], "$%s" % p[ICLPOS], ""]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
203 clsuffix.append(appendme)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
204 xclsuffix.append(xappendme)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
205 # print('##infile i=%d, appendme=%s' % (i,appendme))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
206 for i, p in enumerate(self.outfiles):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
207 if p[OOCLPOS] == "STDOUT":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
208 self.lastclredirect = [">", p[ONAMEPOS]]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
209 self.lastxclredirect = [">", "$%s" % p[OCLPOS]]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
210 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
211 clsuffix.append([p[OOCLPOS], p[OCLPOS], p[ONAMEPOS], ""])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
212 xclsuffix.append(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
213 [p[OOCLPOS], p[OCLPOS], "$%s" % p[ONAMEPOS], ""]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
214 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
215 for p in self.addpar:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
216 clsuffix.append(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
217 [p[AOCLPOS], p[ACLPOS], p[AVALPOS], p[AOVERPOS]]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
218 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
219 xclsuffix.append(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
220 [p[AOCLPOS], p[ACLPOS], '"$%s"' % p[ANAMEPOS], p[AOVERPOS]]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
221 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
222 clsuffix.sort()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
223 xclsuffix.sort()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
224 self.xclsuffix = xclsuffix
0183cad9d13b planemo upload
fubar
parents:
diff changeset
225 self.clsuffix = clsuffix
0183cad9d13b planemo upload
fubar
parents:
diff changeset
226 if self.args.parampass == "positional":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
227 self.clpositional()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
228 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
229 self.clargparse()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
230
0183cad9d13b planemo upload
fubar
parents:
diff changeset
231 def prepScript(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
232 aCL = self.cl.append
0183cad9d13b planemo upload
fubar
parents:
diff changeset
233 rx = open(self.args.script_path, "r").readlines()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
234 rx = [x.rstrip() for x in rx]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
235 rxcheck = [x.strip() for x in rx if x.strip() > ""]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
236 assert len(rxcheck) > 0, "Supplied script is empty. Cannot run"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
237 self.script = "\n".join(rx)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
238 fhandle, self.sfile = tempfile.mkstemp(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
239 prefix=self.tool_name, suffix="_%s" % (self.args.interpreter_name)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
240 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
241 tscript = open(self.sfile, "w")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
242 tscript.write(self.script)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
243 tscript.close()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
244 self.indentedScript = " %s" % "\n".join(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
245 [" %s" % html_escape(x) for x in rx]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
246 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
247 self.escapedScript = "%s" % "\n".join(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
248 [" %s" % html_escape(x) for x in rx]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
249 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
250 art = "%s.%s" % (self.tool_name, self.args.interpreter_name)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
251 artifact = open(art, "wb")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
252 artifact.write(bytes(self.script, "utf8"))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
253 artifact.close()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
254 aCL(self.args.interpreter_name)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
255 aCL(self.sfile)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
256
0183cad9d13b planemo upload
fubar
parents:
diff changeset
257 def cleanuppar(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
258 """ positional parameters are complicated by their numeric ordinal"""
0183cad9d13b planemo upload
fubar
parents:
diff changeset
259 for i, p in enumerate(self.infiles):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
260 if self.args.parampass == "positional":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
261 assert p[ICLPOS].isdigit(), (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
262 "Positional parameters must be ordinal integers - got %s for %s"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
263 % (p[ICLPOS], p[ILABPOS])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
264 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
265 p.append(p[ICLPOS])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
266 if p[ICLPOS].isdigit() or self.args.parampass == "0":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
267 scl = "input%d" % (i + 1)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
268 p[ICLPOS] = scl
0183cad9d13b planemo upload
fubar
parents:
diff changeset
269 self.infiles[i] = p
0183cad9d13b planemo upload
fubar
parents:
diff changeset
270 for i, p in enumerate(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
271 self.outfiles
0183cad9d13b planemo upload
fubar
parents:
diff changeset
272 ): # trying to automagically gather using extensions
0183cad9d13b planemo upload
fubar
parents:
diff changeset
273 if self.args.parampass == "positional" and p[OCLPOS] != "STDOUT":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
274 assert p[OCLPOS].isdigit(), (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
275 "Positional parameters must be ordinal integers - got %s for %s"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
276 % (p[OCLPOS], p[ONAMEPOS])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
277 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
278 p.append(p[OCLPOS])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
279 if p[OCLPOS].isdigit() or p[OCLPOS] == "STDOUT":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
280 scl = p[ONAMEPOS]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
281 p[OCLPOS] = scl
0183cad9d13b planemo upload
fubar
parents:
diff changeset
282 self.outfiles[i] = p
0183cad9d13b planemo upload
fubar
parents:
diff changeset
283 for i, p in enumerate(self.addpar):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
284 if self.args.parampass == "positional":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
285 assert p[ACLPOS].isdigit(), (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
286 "Positional parameters must be ordinal integers - got %s for %s"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
287 % (p[ACLPOS], p[ANAMEPOS])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
288 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
289 p.append(p[ACLPOS])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
290 if p[ACLPOS].isdigit():
0183cad9d13b planemo upload
fubar
parents:
diff changeset
291 scl = "input%s" % p[ACLPOS]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
292 p[ACLPOS] = scl
0183cad9d13b planemo upload
fubar
parents:
diff changeset
293 self.addpar[i] = p
0183cad9d13b planemo upload
fubar
parents:
diff changeset
294
0183cad9d13b planemo upload
fubar
parents:
diff changeset
295 def clsimple(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
296 """ no parameters - uses < and > for i/o
0183cad9d13b planemo upload
fubar
parents:
diff changeset
297 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
298 aCL = self.cl.append
0183cad9d13b planemo upload
fubar
parents:
diff changeset
299 aCL("<")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
300 aCL(self.infiles[0][IPATHPOS])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
301 aCL(">")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
302 aCL(self.outfiles[0][OCLPOS])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
303 aXCL = self.xmlcl.append
0183cad9d13b planemo upload
fubar
parents:
diff changeset
304 aXCL("<")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
305 aXCL("$%s" % self.infiles[0][ICLPOS])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
306 aXCL(">")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
307 aXCL("$%s" % self.outfiles[0][ONAMEPOS])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
308
0183cad9d13b planemo upload
fubar
parents:
diff changeset
309 def clpositional(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
310 # inputs in order then params
0183cad9d13b planemo upload
fubar
parents:
diff changeset
311 aCL = self.cl.append
0183cad9d13b planemo upload
fubar
parents:
diff changeset
312 for (o_v, k, v, koverride) in self.clsuffix:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
313 if " " in v:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
314 aCL("%s" % v)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
315 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
316 aCL(v)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
317 aXCL = self.xmlcl.append
0183cad9d13b planemo upload
fubar
parents:
diff changeset
318 for (o_v, k, v, koverride) in self.xclsuffix:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
319 aXCL(v)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
320 if self.lastxclredirect:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
321 aXCL(self.lastxclredirect[0])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
322 aXCL(self.lastxclredirect[1])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
323
0183cad9d13b planemo upload
fubar
parents:
diff changeset
324 def clargparse(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
325 """ argparse style
0183cad9d13b planemo upload
fubar
parents:
diff changeset
326 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
327 aCL = self.cl.append
0183cad9d13b planemo upload
fubar
parents:
diff changeset
328 aXCL = self.xmlcl.append
0183cad9d13b planemo upload
fubar
parents:
diff changeset
329 # inputs then params in argparse named form
0183cad9d13b planemo upload
fubar
parents:
diff changeset
330 for (o_v, k, v, koverride) in self.xclsuffix:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
331 if koverride > "":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
332 k = koverride
0183cad9d13b planemo upload
fubar
parents:
diff changeset
333 elif len(k.strip()) == 1:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
334 k = "-%s" % k
0183cad9d13b planemo upload
fubar
parents:
diff changeset
335 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
336 k = "--%s" % k
0183cad9d13b planemo upload
fubar
parents:
diff changeset
337 aXCL(k)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
338 aXCL(v)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
339 for (o_v, k, v, koverride) in self.clsuffix:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
340 if koverride > "":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
341 k = koverride
0183cad9d13b planemo upload
fubar
parents:
diff changeset
342 elif len(k.strip()) == 1:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
343 k = "-%s" % k
0183cad9d13b planemo upload
fubar
parents:
diff changeset
344 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
345 k = "--%s" % k
0183cad9d13b planemo upload
fubar
parents:
diff changeset
346 aCL(k)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
347 aCL(v)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
348
0183cad9d13b planemo upload
fubar
parents:
diff changeset
349 def getNdash(self, newname):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
350 if self.is_positional:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
351 ndash = 0
0183cad9d13b planemo upload
fubar
parents:
diff changeset
352 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
353 ndash = 2
0183cad9d13b planemo upload
fubar
parents:
diff changeset
354 if len(newname) < 2:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
355 ndash = 1
0183cad9d13b planemo upload
fubar
parents:
diff changeset
356 return ndash
0183cad9d13b planemo upload
fubar
parents:
diff changeset
357
0183cad9d13b planemo upload
fubar
parents:
diff changeset
358 def doXMLparam(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
359 """flake8 made me do this..."""
0183cad9d13b planemo upload
fubar
parents:
diff changeset
360 for p in self.outfiles:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
361 newname, newfmt, newcl, oldcl = p
0183cad9d13b planemo upload
fubar
parents:
diff changeset
362 ndash = self.getNdash(newcl)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
363 aparm = gxtp.OutputData(newcl, format=newfmt, num_dashes=ndash)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
364 aparm.positional = self.is_positional
0183cad9d13b planemo upload
fubar
parents:
diff changeset
365 if self.is_positional:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
366 if oldcl == "STDOUT":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
367 aparm.positional = 9999999
0183cad9d13b planemo upload
fubar
parents:
diff changeset
368 aparm.command_line_override = "> $%s" % newcl
0183cad9d13b planemo upload
fubar
parents:
diff changeset
369 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
370 aparm.positional = int(oldcl)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
371 aparm.command_line_override = "$%s" % newcl
0183cad9d13b planemo upload
fubar
parents:
diff changeset
372 self.toutputs.append(aparm)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
373 tp = gxtp.TestOutput(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
374 name=newcl, value="%s_sample" % newcl, format=newfmt
0183cad9d13b planemo upload
fubar
parents:
diff changeset
375 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
376 self.testparam.append(tp)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
377 for p in self.infiles:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
378 newname = p[ICLPOS]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
379 newfmt = p[IFMTPOS]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
380 ndash = self.getNdash(newname)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
381 if not len(p[ILABPOS]) > 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
382 alab = p[ICLPOS]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
383 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
384 alab = p[ILABPOS]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
385 aninput = gxtp.DataParam(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
386 newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
387 optional=False,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
388 label=alab,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
389 help=p[IHELPOS],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
390 format=newfmt,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
391 multiple=False,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
392 num_dashes=ndash,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
393 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
394 aninput.positional = self.is_positional
0183cad9d13b planemo upload
fubar
parents:
diff changeset
395 self.tinputs.append(aninput)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
396 tparm = gxtp.TestParam(name=newname, value="%s_sample" % newname)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
397 self.testparam.append(tparm)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
398 for p in self.addpar:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
399 newname, newval, newlabel, newhelp, newtype, newcl, override, oldcl = p
0183cad9d13b planemo upload
fubar
parents:
diff changeset
400 if not len(newlabel) > 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
401 newlabel = newname
0183cad9d13b planemo upload
fubar
parents:
diff changeset
402 ndash = self.getNdash(newname)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
403 if newtype == "text":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
404 aparm = gxtp.TextParam(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
405 newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
406 label=newlabel,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
407 help=newhelp,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
408 value=newval,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
409 num_dashes=ndash,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
410 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
411 elif newtype == "integer":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
412 aparm = gxtp.IntegerParam(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
413 newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
414 label=newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
415 help=newhelp,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
416 value=newval,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
417 num_dashes=ndash,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
418 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
419 elif newtype == "float":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
420 aparm = gxtp.FloatParam(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
421 newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
422 label=newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
423 help=newhelp,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
424 value=newval,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
425 num_dashes=ndash,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
426 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
427 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
428 raise ValueError(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
429 'Unrecognised parameter type "%s" for\
0183cad9d13b planemo upload
fubar
parents:
diff changeset
430 additional parameter %s in makeXML'
0183cad9d13b planemo upload
fubar
parents:
diff changeset
431 % (newtype, newname)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
432 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
433 aparm.positional = self.is_positional
0183cad9d13b planemo upload
fubar
parents:
diff changeset
434 if self.is_positional:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
435 aninput.positional = int(oldcl)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
436 self.tinputs.append(aparm)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
437 self.tparm = gxtp.TestParam(newname, value=newval)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
438 self.testparam.append(tparm)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
439
0183cad9d13b planemo upload
fubar
parents:
diff changeset
440 def doNoXMLparam(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
441 alab = self.infiles[0][ILABPOS]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
442 if len(alab) == 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
443 alab = self.infiles[0][ICLPOS]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
444 max1s = (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
445 "Maximum one input if parampass is 0 - more than one input files supplied - %s"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
446 % str(self.infiles)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
447 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
448 assert len(self.infiles) == 1, max1s
0183cad9d13b planemo upload
fubar
parents:
diff changeset
449 newname = self.infiles[0][ICLPOS]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
450 aninput = gxtp.DataParam(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
451 newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
452 optional=False,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
453 label=alab,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
454 help=self.infiles[0][IHELPOS],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
455 format=self.infiles[0][IFMTPOS],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
456 multiple=False,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
457 num_dashes=0,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
458 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
459 aninput.command_line_override = "< $%s" % newname
0183cad9d13b planemo upload
fubar
parents:
diff changeset
460 aninput.positional = self.is_positional
0183cad9d13b planemo upload
fubar
parents:
diff changeset
461 self.tinputs.append(aninput)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
462 tp = gxtp.TestParam(name=newname, value="%s_sample" % newname)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
463 self.testparam.append(tp)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
464 newname = self.outfiles[0][OCLPOS]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
465 newfmt = self.outfiles[0][OFMTPOS]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
466 anout = gxtp.OutputData(newname, format=newfmt, num_dashes=0)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
467 anout.command_line_override = "> $%s" % newname
0183cad9d13b planemo upload
fubar
parents:
diff changeset
468 anout.positional = self.is_positional
0183cad9d13b planemo upload
fubar
parents:
diff changeset
469 self.toutputs.append(anout)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
470 tp = gxtp.TestOutput(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
471 name=newname, value="%s_sample" % newname, format=newfmt
0183cad9d13b planemo upload
fubar
parents:
diff changeset
472 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
473 self.testparam.append(tp)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
474
0183cad9d13b planemo upload
fubar
parents:
diff changeset
475 def makeXML(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
476 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
477 Create a Galaxy xml tool wrapper for the new script
0183cad9d13b planemo upload
fubar
parents:
diff changeset
478 Uses galaxyhtml
0183cad9d13b planemo upload
fubar
parents:
diff changeset
479 Hmmm. How to get the command line into correct order...
0183cad9d13b planemo upload
fubar
parents:
diff changeset
480 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
481 self.tool.command_line_override = self.xmlcl
0183cad9d13b planemo upload
fubar
parents:
diff changeset
482 if self.args.interpreter_name:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
483 self.tool.interpreter = self.args.interpreter_name
0183cad9d13b planemo upload
fubar
parents:
diff changeset
484 if self.args.help_text:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
485 helptext = open(self.args.help_text, "r").readlines()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
486 helptext = [html_escape(x) for x in helptext]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
487 self.tool.help = "".join([x for x in helptext])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
488 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
489 self.tool.help = (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
490 "Please ask the tool author (%s) for help \
0183cad9d13b planemo upload
fubar
parents:
diff changeset
491 as none was supplied at tool generation\n"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
492 % (self.args.user_email)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
493 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
494 self.tool.version_command = None # do not want
0183cad9d13b planemo upload
fubar
parents:
diff changeset
495 requirements = gxtp.Requirements()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
496
0183cad9d13b planemo upload
fubar
parents:
diff changeset
497 if self.args.interpreter_name:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
498 if self.args.interpreter_name == "python":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
499 requirements.append(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
500 gxtp.Requirement(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
501 "package", "python", self.args.interpreter_version
0183cad9d13b planemo upload
fubar
parents:
diff changeset
502 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
503 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
504 elif self.args.interpreter_name not in ["bash", "sh"]:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
505 requirements.append(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
506 gxtp.Requirement(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
507 "package",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
508 self.args.interpreter_name,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
509 self.args.interpreter_version,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
510 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
511 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
512 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
513 if self.args.exe_package and self.args.parampass != "system":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
514 requirements.append(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
515 gxtp.Requirement(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
516 "package",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
517 self.args.exe_package,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
518 self.args.exe_package_version,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
519 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
520 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
521 self.tool.requirements = requirements
0183cad9d13b planemo upload
fubar
parents:
diff changeset
522 if self.args.parampass == "0":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
523 self.doNoXMLparam()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
524 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
525 self.doXMLparam()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
526 self.tool.outputs = self.toutputs
0183cad9d13b planemo upload
fubar
parents:
diff changeset
527 self.tool.inputs = self.tinputs
0183cad9d13b planemo upload
fubar
parents:
diff changeset
528 if self.args.runmode not in ["Executable", "system"]:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
529 configfiles = gxtp.Configfiles()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
530 configfiles.append(gxtp.Configfile(name="runMe", text=self.script))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
531 self.tool.configfiles = configfiles
0183cad9d13b planemo upload
fubar
parents:
diff changeset
532 tests = gxtp.Tests()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
533 test_a = gxtp.Test()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
534 for tp in self.testparam:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
535 test_a.append(tp)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
536 tests.append(test_a)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
537 self.tool.tests = tests
0183cad9d13b planemo upload
fubar
parents:
diff changeset
538 self.tool.add_comment(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
539 "Created by %s at %s using the Galaxy Tool Factory."
0183cad9d13b planemo upload
fubar
parents:
diff changeset
540 % (self.args.user_email, timenow())
0183cad9d13b planemo upload
fubar
parents:
diff changeset
541 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
542 self.tool.add_comment("Source in git at: %s" % (toolFactoryURL))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
543 self.tool.add_comment(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
544 "Cite: Creating re-usable tools from scripts doi: 10.1093/bioinformatics/bts573"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
545 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
546 exml = self.tool.export()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
547 xf = open('%s.xml' % self.tool_name, "w")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
548 xf.write(exml)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
549 xf.write("\n")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
550 xf.close()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
551 # ready for the tarball
0183cad9d13b planemo upload
fubar
parents:
diff changeset
552
0183cad9d13b planemo upload
fubar
parents:
diff changeset
553 def makeTooltar(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
554 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
555 a tool is a gz tarball with eg
0183cad9d13b planemo upload
fubar
parents:
diff changeset
556 /toolname/tool.xml /toolname/tool.py /toolname/test-data/test1_in.foo ...
0183cad9d13b planemo upload
fubar
parents:
diff changeset
557 NOTE names for test inputs and outputs are munged here so must
0183cad9d13b planemo upload
fubar
parents:
diff changeset
558 correspond to actual input and output names used on the generated cl
0183cad9d13b planemo upload
fubar
parents:
diff changeset
559 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
560 retval = self.run()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
561 if retval:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
562 sys.stderr.write(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
563 "## Run failed. Cannot build yet. Please fix and retry"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
564 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
565 sys.exit(1)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
566 tdir = "tfout"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
567 if not os.path.exists(tdir):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
568 os.mkdir(tdir)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
569 self.makeXML()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
570 testdir = os.path.join(tdir, "test-data")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
571 if not os.path.exists(testdir):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
572 os.mkdir(testdir) # make tests directory
0183cad9d13b planemo upload
fubar
parents:
diff changeset
573 for p in self.infiles:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
574 pth = p[IPATHPOS]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
575 dest = os.path.join(testdir, "%s_sample" % p[ICLPOS])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
576 shutil.copyfile(pth, dest)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
577 for p in self.outfiles:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
578 pth = p[OCLPOS]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
579 if p[OOCLPOS] == "STDOUT" or self.args.parampass == "0":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
580 pth = p[ONAMEPOS]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
581 dest = os.path.join(testdir, "%s_sample" % p[ONAMEPOS])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
582 shutil.copyfile(pth, dest)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
583 dest = os.path.join(tdir, p[ONAMEPOS])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
584 shutil.copyfile(pth, dest)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
585 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
586 pth = p[OCLPOS]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
587 dest = os.path.join(testdir, "%s_sample" % p[OCLPOS])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
588 shutil.copyfile(pth, dest)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
589 dest = os.path.join(tdir, p[OCLPOS])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
590 shutil.copyfile(pth, dest)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
591
0183cad9d13b planemo upload
fubar
parents:
diff changeset
592 if os.path.exists(self.tlog) and os.stat(self.tlog).st_size > 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
593 shutil.copyfile(self.tlog, os.path.join(testdir, "test1_log_outfiletxt"))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
594 if self.args.runmode not in ["Executable", "system"]:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
595 stname = os.path.join(tdir, "%s" % (self.sfile))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
596 if not os.path.exists(stname):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
597 shutil.copyfile(self.sfile, stname)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
598 xreal = '%s.xml' % self.tool_name
0183cad9d13b planemo upload
fubar
parents:
diff changeset
599 xout = os.path.join(tdir,xreal)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
600 shutil.copyfile(xreal, xout)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
601 tarpath = "toolfactory_%s.tgz" % self.tool_name
0183cad9d13b planemo upload
fubar
parents:
diff changeset
602 tf = tarfile.open(tarpath, "w:gz")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
603 tf.add(name=tdir, arcname=self.tool_name)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
604 tf.close()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
605 shutil.copyfile(tarpath, self.args.new_tool)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
606 shutil.copyfile(xreal,"tool_xml.txt")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
607 repdir = "TF_run_report_tempdir"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
608 if not os.path.exists(repdir):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
609 os.mkdir(repdir)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
610 repoutnames = [x[OCLPOS] for x in self.outfiles]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
611 with os.scandir('.') as outs:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
612 for entry in outs:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
613 if entry.name.endswith('.tgz') or not entry.is_file():
0183cad9d13b planemo upload
fubar
parents:
diff changeset
614 continue
0183cad9d13b planemo upload
fubar
parents:
diff changeset
615 if entry.name in repoutnames:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
616 shutil.copyfile(entry.name,os.path.join(repdir,entry.name))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
617 elif entry.name == "%s.xml" % self.tool_name:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
618 shutil.copyfile(entry.name,os.path.join(repdir,"new_tool_xml"))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
619 return retval
0183cad9d13b planemo upload
fubar
parents:
diff changeset
620
0183cad9d13b planemo upload
fubar
parents:
diff changeset
621 def run(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
622 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
623 Some devteam tools have this defensive stderr read so I'm keeping with the faith
0183cad9d13b planemo upload
fubar
parents:
diff changeset
624 Feel free to update.
0183cad9d13b planemo upload
fubar
parents:
diff changeset
625 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
626 s = "run cl=%s" % str(self.cl)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
627
0183cad9d13b planemo upload
fubar
parents:
diff changeset
628 logging.debug(s)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
629 scl = " ".join(self.cl)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
630 err = None
0183cad9d13b planemo upload
fubar
parents:
diff changeset
631 if self.args.parampass != "0":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
632 ste = open(self.elog, "wb")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
633 if self.lastclredirect:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
634 sto = open(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
635 self.lastclredirect[1], "wb"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
636 ) # is name of an output file
0183cad9d13b planemo upload
fubar
parents:
diff changeset
637 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
638 sto = open(self.tlog, "wb")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
639 sto.write(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
640 bytes(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
641 "## Executing Toolfactory generated command line = %s\n"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
642 % scl,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
643 "utf8",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
644 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
645 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
646 sto.flush()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
647 p = subprocess.run(self.cl, shell=False, stdout=sto, stderr=ste)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
648 sto.close()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
649 ste.close()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
650 tmp_stderr = open(self.elog, "rb")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
651 err = ""
0183cad9d13b planemo upload
fubar
parents:
diff changeset
652 buffsize = 1048576
0183cad9d13b planemo upload
fubar
parents:
diff changeset
653 try:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
654 while True:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
655 err += str(tmp_stderr.read(buffsize))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
656 if not err or len(err) % buffsize != 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
657 break
0183cad9d13b planemo upload
fubar
parents:
diff changeset
658 except OverflowError:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
659 pass
0183cad9d13b planemo upload
fubar
parents:
diff changeset
660 tmp_stderr.close()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
661 retval = p.returncode
0183cad9d13b planemo upload
fubar
parents:
diff changeset
662 else: # work around special case of simple scripts that take stdin and write to stdout
0183cad9d13b planemo upload
fubar
parents:
diff changeset
663 sti = open(self.infiles[0][IPATHPOS], "rb")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
664 sto = open(self.outfiles[0][ONAMEPOS], "wb")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
665 # must use shell to redirect
0183cad9d13b planemo upload
fubar
parents:
diff changeset
666 p = subprocess.run(self.cl, shell=False, stdout=sto, stdin=sti)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
667 retval = p.returncode
0183cad9d13b planemo upload
fubar
parents:
diff changeset
668 sto.close()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
669 sti.close()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
670 if os.path.isfile(self.tlog) and os.stat(self.tlog).st_size == 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
671 os.unlink(self.tlog)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
672 if os.path.isfile(self.elog) and os.stat(self.elog).st_size == 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
673 os.unlink(self.elog)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
674 if p.returncode != 0 and err: # problem
0183cad9d13b planemo upload
fubar
parents:
diff changeset
675 sys.stderr.write(err)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
676 logging.debug("run done")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
677 return retval
0183cad9d13b planemo upload
fubar
parents:
diff changeset
678
0183cad9d13b planemo upload
fubar
parents:
diff changeset
679
0183cad9d13b planemo upload
fubar
parents:
diff changeset
680 def main():
0183cad9d13b planemo upload
fubar
parents:
diff changeset
681 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
682 This is a Galaxy wrapper. It expects to be called by a special purpose tool.xml as:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
683 <command interpreter="python">rgBaseScriptWrapper.py --script_path "$scriptPath" --tool_name "foo" --interpreter "Rscript"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
684 </command>
0183cad9d13b planemo upload
fubar
parents:
diff changeset
685 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
686 parser = argparse.ArgumentParser()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
687 a = parser.add_argument
0183cad9d13b planemo upload
fubar
parents:
diff changeset
688 a("--script_path", default="")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
689 a("--tool_name", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
690 a("--interpreter_name", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
691 a("--interpreter_version", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
692 a("--exe_package", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
693 a("--exe_package_version", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
694 a("--input_files", default=[], action="append")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
695 a("--output_files", default=[], action="append")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
696 a("--user_email", default="Unknown")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
697 a("--bad_user", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
698 a("--make_Tool", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
699 a("--help_text", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
700 a("--tool_desc", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
701 a("--tool_version", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
702 a("--citations", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
703 a("--additional_parameters", action="append", default=[])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
704 a("--edit_additional_parameters", action="store_true", default=False)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
705 a("--parampass", default="positional")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
706 a("--tfout", default="./tfout")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
707 a("--new_tool", default="new_tool")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
708 a("--runmode", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
709 args = parser.parse_args()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
710 assert not args.bad_user, (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
711 'UNAUTHORISED: %s is NOT authorized to use this tool until Galaxy admin adds %s to "admin_users" in the Galaxy configuration file'
0183cad9d13b planemo upload
fubar
parents:
diff changeset
712 % (args.bad_user, args.bad_user)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
713 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
714 assert (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
715 args.tool_name
0183cad9d13b planemo upload
fubar
parents:
diff changeset
716 ), "## Tool Factory expects a tool name - eg --tool_name=DESeq"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
717 assert (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
718 args.interpreter_name or args.exe_package
0183cad9d13b planemo upload
fubar
parents:
diff changeset
719 ), "## Tool Factory wrapper expects an interpreter or an executable package"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
720 assert args.exe_package or (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
721 len(args.script_path) > 0 and os.path.isfile(args.script_path)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
722 ), "## Tool Factory wrapper expects a script path - eg --script_path=foo.R if no executable"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
723 args.input_files = [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
724 x.replace('"', "").replace("'", "") for x in args.input_files
0183cad9d13b planemo upload
fubar
parents:
diff changeset
725 ]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
726 # remove quotes we need to deal with spaces in CL params
0183cad9d13b planemo upload
fubar
parents:
diff changeset
727 for i, x in enumerate(args.additional_parameters):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
728 args.additional_parameters[i] = args.additional_parameters[i].replace(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
729 '"', ""
0183cad9d13b planemo upload
fubar
parents:
diff changeset
730 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
731 r = ScriptRunner(args)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
732 if args.make_Tool:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
733 retcode = r.makeTooltar()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
734 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
735 retcode = r.run()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
736 if retcode:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
737 sys.exit(retcode) # indicate failure to job runner
0183cad9d13b planemo upload
fubar
parents:
diff changeset
738
0183cad9d13b planemo upload
fubar
parents:
diff changeset
739
0183cad9d13b planemo upload
fubar
parents:
diff changeset
740 if __name__ == "__main__":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
741 main()