84
|
1 # replace with shebang for biocontainer
|
48
|
2 # see https://github.com/fubar2/toolfactory
|
|
3 #
|
|
4 # copyright ross lazarus (ross stop lazarus at gmail stop com) May 2012
|
|
5 #
|
|
6 # all rights reserved
|
|
7 # Licensed under the LGPL
|
49
|
8 # suggestions for improvement and bug fixes welcome at
|
|
9 # https://github.com/fubar2/toolfactory
|
48
|
10 #
|
|
11 # July 2020: BCC was fun and I feel like rip van winkle after 5 years.
|
|
12 # Decided to
|
|
13 # 1. Fix the toolfactory so it works - done for simplest case
|
|
14 # 2. Fix planemo so the toolfactory function works
|
|
15 # 3. Rewrite bits using galaxyxml functions where that makes sense - done
|
|
16 #
|
|
17 # removed all the old complications including making the new tool use this same script
|
|
18 # galaxyxml now generates the tool xml https://github.com/hexylena/galaxyxml
|
|
19 # No support for automatic HTML file creation from arbitrary outputs
|
|
20 # essential problem is to create two command lines - one for the tool xml and a different
|
|
21 # one to run the executable with the supplied test data and settings
|
|
22 # Be simpler to write the tool, then run it with planemo and soak up the test outputs.
|
|
23
|
|
24
|
|
25 import argparse
|
76
|
26 import datetime
|
|
27 import json
|
48
|
28 import logging
|
|
29 import os
|
|
30 import re
|
|
31 import shutil
|
|
32 import subprocess
|
|
33 import sys
|
|
34 import tarfile
|
|
35 import tempfile
|
|
36 import time
|
|
37
|
75
|
38
|
63
|
39 from bioblend import toolshed
|
|
40
|
48
|
41 import galaxyxml.tool as gxt
|
|
42 import galaxyxml.tool.parameters as gxtp
|
|
43
|
|
44 import lxml
|
|
45
|
|
46 import yaml
|
|
47
|
|
48 myversion = "V2.1 July 2020"
|
|
49 verbose = True
|
|
50 debug = True
|
|
51 toolFactoryURL = "https://github.com/fubar2/toolfactory"
|
|
52 ourdelim = "~~~"
|
50
|
53 ALOT = 10000000 # srsly. command or test overrides use read() so just in case
|
49
|
54 STDIOXML = """<stdio>
|
|
55 <exit_code range="100:" level="debug" description="shite happens" />
|
|
56 </stdio>"""
|
48
|
57
|
|
58 # --input_files="$input_files~~~$CL~~~$input_formats~~~$input_label
|
|
59 # ~~~$input_help"
|
|
60 IPATHPOS = 0
|
|
61 ICLPOS = 1
|
|
62 IFMTPOS = 2
|
|
63 ILABPOS = 3
|
|
64 IHELPOS = 4
|
|
65 IOCLPOS = 5
|
|
66
|
49
|
67 # --output_files "$otab.history_name~~~$otab.history_format~~~$otab.CL~~~otab.history_test
|
48
|
68 ONAMEPOS = 0
|
|
69 OFMTPOS = 1
|
|
70 OCLPOS = 2
|
49
|
71 OTESTPOS = 3
|
|
72 OOCLPOS = 4
|
|
73
|
48
|
74
|
|
75 # --additional_parameters="$i.param_name~~~$i.param_value~~~
|
|
76 # $i.param_label~~~$i.param_help~~~$i.param_type~~~$i.CL~~~i$.param_CLoverride"
|
|
77 ANAMEPOS = 0
|
|
78 AVALPOS = 1
|
|
79 ALABPOS = 2
|
|
80 AHELPPOS = 3
|
|
81 ATYPEPOS = 4
|
|
82 ACLPOS = 5
|
|
83 AOVERPOS = 6
|
|
84 AOCLPOS = 7
|
|
85
|
|
86
|
|
87 foo = len(lxml.__version__)
|
|
88 # fug you, flake8. Say my name!
|
49
|
89 FAKEEXE = "~~~REMOVE~~~ME~~~"
|
|
90 # need this until a PR/version bump to fix galaxyxml prepending the exe even
|
|
91 # with override.
|
|
92
|
48
|
93
|
|
94 def timenow():
|
75
|
95 """return current time as a string"""
|
48
|
96 return time.strftime("%d/%m/%Y %H:%M:%S", time.localtime(time.time()))
|
|
97
|
|
98
|
|
99 def quote_non_numeric(s):
|
|
100 """return a prequoted string for non-numerics
|
|
101 useful for perl and Rscript parameter passing?
|
|
102 """
|
|
103 try:
|
|
104 _ = float(s)
|
|
105 return s
|
|
106 except ValueError:
|
|
107 return '"%s"' % s
|
|
108
|
|
109
|
|
110 html_escape_table = {"&": "&", ">": ">", "<": "<", "$": r"\$"}
|
|
111
|
|
112
|
|
113 def html_escape(text):
|
|
114 """Produce entities within text."""
|
|
115 return "".join(html_escape_table.get(c, c) for c in text)
|
|
116
|
|
117
|
|
118 def html_unescape(text):
|
|
119 """Revert entities within text. Multiple character targets so use replace"""
|
|
120 t = text.replace("&", "&")
|
|
121 t = t.replace(">", ">")
|
|
122 t = t.replace("<", "<")
|
|
123 t = t.replace("\\$", "$")
|
|
124 return t
|
|
125
|
|
126
|
|
127 def parse_citations(citations_text):
|
75
|
128 """"""
|
48
|
129 citations = [c for c in citations_text.split("**ENTRY**") if c.strip()]
|
|
130 citation_tuples = []
|
|
131 for citation in citations:
|
|
132 if citation.startswith("doi"):
|
|
133 citation_tuples.append(("doi", citation[len("doi") :].strip()))
|
|
134 else:
|
49
|
135 citation_tuples.append(("bibtex", citation[len("bibtex") :].strip()))
|
48
|
136 return citation_tuples
|
|
137
|
|
138
|
|
139 class ScriptRunner:
|
|
140 """Wrapper for an arbitrary script
|
|
141 uses galaxyxml
|
|
142
|
|
143 """
|
|
144
|
|
145 def __init__(self, args=None):
|
|
146 """
|
|
147 prepare command line cl for running the tool here
|
|
148 and prepare elements needed for galaxyxml tool generation
|
|
149 """
|
|
150 self.infiles = [x.split(ourdelim) for x in args.input_files]
|
|
151 self.outfiles = [x.split(ourdelim) for x in args.output_files]
|
|
152 self.addpar = [x.split(ourdelim) for x in args.additional_parameters]
|
|
153 self.args = args
|
|
154 self.cleanuppar()
|
|
155 self.lastclredirect = None
|
|
156 self.lastxclredirect = None
|
|
157 self.cl = []
|
|
158 self.xmlcl = []
|
|
159 self.is_positional = self.args.parampass == "positional"
|
63
|
160 if self.args.sysexe:
|
49
|
161 self.executeme = self.args.sysexe
|
63
|
162 else:
|
|
163 if self.args.packages:
|
|
164 self.executeme = self.args.packages.split(",")[0].split(":")[0]
|
|
165 else:
|
|
166 self.executeme = None
|
48
|
167 aCL = self.cl.append
|
49
|
168 aXCL = self.xmlcl.append
|
48
|
169 assert args.parampass in [
|
|
170 "0",
|
|
171 "argparse",
|
|
172 "positional",
|
49
|
173 ], 'args.parampass must be "0","positional" or "argparse"'
|
48
|
174 self.tool_name = re.sub("[^a-zA-Z0-9_]+", "", args.tool_name)
|
|
175 self.tool_id = self.tool_name
|
50
|
176 self.newtool = gxt.Tool(
|
48
|
177 self.args.tool_name,
|
|
178 self.tool_id,
|
|
179 self.args.tool_version,
|
|
180 self.args.tool_desc,
|
50
|
181 FAKEEXE,
|
48
|
182 )
|
76
|
183 self.newtarpath = "toolfactory_%s.tgz" % self.tool_name
|
48
|
184 self.tooloutdir = "tfout"
|
|
185 self.repdir = "TF_run_report_tempdir"
|
|
186 self.testdir = os.path.join(self.tooloutdir, "test-data")
|
|
187 if not os.path.exists(self.tooloutdir):
|
|
188 os.mkdir(self.tooloutdir)
|
|
189 if not os.path.exists(self.testdir):
|
|
190 os.mkdir(self.testdir) # make tests directory
|
|
191 if not os.path.exists(self.repdir):
|
|
192 os.mkdir(self.repdir)
|
|
193 self.tinputs = gxtp.Inputs()
|
|
194 self.toutputs = gxtp.Outputs()
|
|
195 self.testparam = []
|
49
|
196 if self.args.script_path:
|
|
197 self.prepScript()
|
|
198 if self.args.command_override:
|
|
199 scos = open(self.args.command_override, "r").readlines()
|
|
200 self.command_override = [x.rstrip() for x in scos]
|
|
201 else:
|
|
202 self.command_override = None
|
|
203 if self.args.test_override:
|
|
204 stos = open(self.args.test_override, "r").readlines()
|
|
205 self.test_override = [x.rstrip() for x in stos]
|
|
206 else:
|
|
207 self.test_override = None
|
50
|
208 if self.args.cl_prefix: # DIY CL start
|
49
|
209 clp = self.args.cl_prefix.split(" ")
|
|
210 for c in clp:
|
|
211 aCL(c)
|
|
212 aXCL(c)
|
|
213 else:
|
56
|
214 if self.args.script_path:
|
|
215 aCL(self.executeme)
|
|
216 aCL(self.sfile)
|
|
217 aXCL(self.executeme)
|
|
218 aXCL("$runme")
|
48
|
219 else:
|
56
|
220 aCL(self.executeme) # this little CL will just run
|
|
221 aXCL(self.executeme)
|
50
|
222 self.elog = os.path.join(self.repdir, "%s_error_log.txt" % self.tool_name)
|
|
223 self.tlog = os.path.join(self.repdir, "%s_runner_log.txt" % self.tool_name)
|
48
|
224
|
|
225 if self.args.parampass == "0":
|
|
226 self.clsimple()
|
|
227 else:
|
|
228 clsuffix = []
|
|
229 xclsuffix = []
|
|
230 for i, p in enumerate(self.infiles):
|
|
231 if p[IOCLPOS] == "STDIN":
|
|
232 appendme = [
|
|
233 p[IOCLPOS],
|
|
234 p[ICLPOS],
|
|
235 p[IPATHPOS],
|
|
236 "< %s" % p[IPATHPOS],
|
|
237 ]
|
|
238 xappendme = [
|
|
239 p[IOCLPOS],
|
|
240 p[ICLPOS],
|
|
241 p[IPATHPOS],
|
|
242 "< $%s" % p[ICLPOS],
|
|
243 ]
|
|
244 else:
|
|
245 appendme = [p[IOCLPOS], p[ICLPOS], p[IPATHPOS], ""]
|
|
246 xappendme = [p[IOCLPOS], p[ICLPOS], "$%s" % p[ICLPOS], ""]
|
|
247 clsuffix.append(appendme)
|
|
248 xclsuffix.append(xappendme)
|
|
249 for i, p in enumerate(self.outfiles):
|
|
250 if p[OOCLPOS] == "STDOUT":
|
|
251 self.lastclredirect = [">", p[ONAMEPOS]]
|
|
252 self.lastxclredirect = [">", "$%s" % p[OCLPOS]]
|
|
253 else:
|
|
254 clsuffix.append([p[OOCLPOS], p[OCLPOS], p[ONAMEPOS], ""])
|
49
|
255 xclsuffix.append([p[OOCLPOS], p[OCLPOS], "$%s" % p[ONAMEPOS], ""])
|
48
|
256 for p in self.addpar:
|
49
|
257 clsuffix.append([p[AOCLPOS], p[ACLPOS], p[AVALPOS], p[AOVERPOS]])
|
48
|
258 xclsuffix.append(
|
|
259 [p[AOCLPOS], p[ACLPOS], '"$%s"' % p[ANAMEPOS], p[AOVERPOS]]
|
|
260 )
|
|
261 clsuffix.sort()
|
|
262 xclsuffix.sort()
|
|
263 self.xclsuffix = xclsuffix
|
|
264 self.clsuffix = clsuffix
|
|
265 if self.args.parampass == "positional":
|
|
266 self.clpositional()
|
|
267 else:
|
|
268 self.clargparse()
|
|
269
|
|
270 def prepScript(self):
|
|
271 rx = open(self.args.script_path, "r").readlines()
|
|
272 rx = [x.rstrip() for x in rx]
|
|
273 rxcheck = [x.strip() for x in rx if x.strip() > ""]
|
|
274 assert len(rxcheck) > 0, "Supplied script is empty. Cannot run"
|
|
275 self.script = "\n".join(rx)
|
|
276 fhandle, self.sfile = tempfile.mkstemp(
|
49
|
277 prefix=self.tool_name, suffix="_%s" % (self.executeme)
|
48
|
278 )
|
|
279 tscript = open(self.sfile, "w")
|
|
280 tscript.write(self.script)
|
|
281 tscript.close()
|
49
|
282 self.indentedScript = " %s" % "\n".join([" %s" % html_escape(x) for x in rx])
|
|
283 self.escapedScript = "%s" % "\n".join([" %s" % html_escape(x) for x in rx])
|
|
284 art = "%s.%s" % (self.tool_name, self.executeme)
|
48
|
285 artifact = open(art, "wb")
|
|
286 artifact.write(bytes(self.script, "utf8"))
|
|
287 artifact.close()
|
|
288
|
|
289 def cleanuppar(self):
|
|
290 """ positional parameters are complicated by their numeric ordinal"""
|
|
291 for i, p in enumerate(self.infiles):
|
|
292 if self.args.parampass == "positional":
|
75
|
293 assert p[
|
|
294 ICLPOS
|
|
295 ].isdigit(), "Positional parameters must be ordinal integers - got %s for %s" % (
|
|
296 p[ICLPOS],
|
|
297 p[ILABPOS],
|
48
|
298 )
|
|
299 p.append(p[ICLPOS])
|
|
300 if p[ICLPOS].isdigit() or self.args.parampass == "0":
|
|
301 scl = "input%d" % (i + 1)
|
|
302 p[ICLPOS] = scl
|
|
303 self.infiles[i] = p
|
|
304 for i, p in enumerate(
|
|
305 self.outfiles
|
|
306 ): # trying to automagically gather using extensions
|
|
307 if self.args.parampass == "positional" and p[OCLPOS] != "STDOUT":
|
75
|
308 assert p[
|
|
309 OCLPOS
|
|
310 ].isdigit(), "Positional parameters must be ordinal integers - got %s for %s" % (
|
|
311 p[OCLPOS],
|
|
312 p[ONAMEPOS],
|
48
|
313 )
|
|
314 p.append(p[OCLPOS])
|
|
315 if p[OCLPOS].isdigit() or p[OCLPOS] == "STDOUT":
|
|
316 scl = p[ONAMEPOS]
|
|
317 p[OCLPOS] = scl
|
|
318 self.outfiles[i] = p
|
|
319 for i, p in enumerate(self.addpar):
|
|
320 if self.args.parampass == "positional":
|
75
|
321 assert p[
|
|
322 ACLPOS
|
|
323 ].isdigit(), "Positional parameters must be ordinal integers - got %s for %s" % (
|
|
324 p[ACLPOS],
|
|
325 p[ANAMEPOS],
|
48
|
326 )
|
|
327 p.append(p[ACLPOS])
|
|
328 if p[ACLPOS].isdigit():
|
|
329 scl = "input%s" % p[ACLPOS]
|
|
330 p[ACLPOS] = scl
|
|
331 self.addpar[i] = p
|
|
332
|
|
333 def clsimple(self):
|
75
|
334 """no parameters - uses < and > for i/o"""
|
48
|
335 aCL = self.cl.append
|
|
336 aXCL = self.xmlcl.append
|
62
|
337
|
|
338 if len(self.infiles) > 0:
|
|
339 aCL("<")
|
|
340 aCL(self.infiles[0][IPATHPOS])
|
|
341 aXCL("<")
|
|
342 aXCL("$%s" % self.infiles[0][ICLPOS])
|
|
343 if len(self.outfiles) > 0:
|
|
344 aCL(">")
|
|
345 aCL(self.outfiles[0][OCLPOS])
|
|
346 aXCL(">")
|
|
347 aXCL("$%s" % self.outfiles[0][ONAMEPOS])
|
48
|
348
|
|
349 def clpositional(self):
|
|
350 # inputs in order then params
|
|
351 aCL = self.cl.append
|
|
352 for (o_v, k, v, koverride) in self.clsuffix:
|
|
353 if " " in v:
|
|
354 aCL("%s" % v)
|
|
355 else:
|
|
356 aCL(v)
|
|
357 aXCL = self.xmlcl.append
|
|
358 for (o_v, k, v, koverride) in self.xclsuffix:
|
|
359 aXCL(v)
|
|
360 if self.lastxclredirect:
|
|
361 aXCL(self.lastxclredirect[0])
|
|
362 aXCL(self.lastxclredirect[1])
|
|
363
|
|
364 def clargparse(self):
|
75
|
365 """argparse style"""
|
48
|
366 aCL = self.cl.append
|
|
367 aXCL = self.xmlcl.append
|
|
368 # inputs then params in argparse named form
|
|
369 for (o_v, k, v, koverride) in self.xclsuffix:
|
|
370 if koverride > "":
|
|
371 k = koverride
|
|
372 elif len(k.strip()) == 1:
|
|
373 k = "-%s" % k
|
|
374 else:
|
|
375 k = "--%s" % k
|
|
376 aXCL(k)
|
|
377 aXCL(v)
|
|
378 for (o_v, k, v, koverride) in self.clsuffix:
|
|
379 if koverride > "":
|
|
380 k = koverride
|
|
381 elif len(k.strip()) == 1:
|
|
382 k = "-%s" % k
|
|
383 else:
|
|
384 k = "--%s" % k
|
|
385 aCL(k)
|
|
386 aCL(v)
|
|
387
|
|
388 def getNdash(self, newname):
|
|
389 if self.is_positional:
|
|
390 ndash = 0
|
|
391 else:
|
|
392 ndash = 2
|
|
393 if len(newname) < 2:
|
|
394 ndash = 1
|
|
395 return ndash
|
|
396
|
|
397 def doXMLparam(self):
|
|
398 """flake8 made me do this..."""
|
|
399 for p in self.outfiles:
|
49
|
400 newname, newfmt, newcl, test, oldcl = p
|
48
|
401 ndash = self.getNdash(newcl)
|
|
402 aparm = gxtp.OutputData(newcl, format=newfmt, num_dashes=ndash)
|
|
403 aparm.positional = self.is_positional
|
|
404 if self.is_positional:
|
|
405 if oldcl == "STDOUT":
|
|
406 aparm.positional = 9999999
|
|
407 aparm.command_line_override = "> $%s" % newcl
|
|
408 else:
|
|
409 aparm.positional = int(oldcl)
|
|
410 aparm.command_line_override = "$%s" % newcl
|
|
411 self.toutputs.append(aparm)
|
49
|
412 usetest = None
|
|
413 ld = None
|
50
|
414 if test > "":
|
|
415 if test.startswith("diff"):
|
|
416 usetest = "diff"
|
|
417 if test.split(":")[1].isdigit:
|
|
418 ld = int(test.split(":")[1])
|
49
|
419 else:
|
|
420 usetest = test
|
50
|
421 tp = gxtp.TestOutput(
|
|
422 name=newcl,
|
|
423 value="%s_sample" % newcl,
|
|
424 format=newfmt,
|
|
425 compare=usetest,
|
|
426 lines_diff=ld,
|
|
427 delta=None,
|
|
428 )
|
48
|
429 self.testparam.append(tp)
|
|
430 for p in self.infiles:
|
|
431 newname = p[ICLPOS]
|
|
432 newfmt = p[IFMTPOS]
|
|
433 ndash = self.getNdash(newname)
|
|
434 if not len(p[ILABPOS]) > 0:
|
|
435 alab = p[ICLPOS]
|
|
436 else:
|
|
437 alab = p[ILABPOS]
|
|
438 aninput = gxtp.DataParam(
|
|
439 newname,
|
|
440 optional=False,
|
|
441 label=alab,
|
|
442 help=p[IHELPOS],
|
|
443 format=newfmt,
|
|
444 multiple=False,
|
|
445 num_dashes=ndash,
|
|
446 )
|
|
447 aninput.positional = self.is_positional
|
|
448 self.tinputs.append(aninput)
|
|
449 tparm = gxtp.TestParam(name=newname, value="%s_sample" % newname)
|
|
450 self.testparam.append(tparm)
|
|
451 for p in self.addpar:
|
|
452 newname, newval, newlabel, newhelp, newtype, newcl, override, oldcl = p
|
|
453 if not len(newlabel) > 0:
|
|
454 newlabel = newname
|
|
455 ndash = self.getNdash(newname)
|
|
456 if newtype == "text":
|
|
457 aparm = gxtp.TextParam(
|
|
458 newname,
|
|
459 label=newlabel,
|
|
460 help=newhelp,
|
|
461 value=newval,
|
|
462 num_dashes=ndash,
|
|
463 )
|
|
464 elif newtype == "integer":
|
|
465 aparm = gxtp.IntegerParam(
|
|
466 newname,
|
|
467 label=newname,
|
|
468 help=newhelp,
|
|
469 value=newval,
|
|
470 num_dashes=ndash,
|
|
471 )
|
|
472 elif newtype == "float":
|
|
473 aparm = gxtp.FloatParam(
|
|
474 newname,
|
|
475 label=newname,
|
|
476 help=newhelp,
|
|
477 value=newval,
|
|
478 num_dashes=ndash,
|
|
479 )
|
|
480 else:
|
|
481 raise ValueError(
|
|
482 'Unrecognised parameter type "%s" for\
|
|
483 additional parameter %s in makeXML'
|
|
484 % (newtype, newname)
|
|
485 )
|
|
486 aparm.positional = self.is_positional
|
|
487 if self.is_positional:
|
63
|
488 aparm.positional = int(oldcl)
|
48
|
489 self.tinputs.append(aparm)
|
63
|
490 tparm = gxtp.TestParam(newname, value=newval)
|
48
|
491 self.testparam.append(tparm)
|
|
492
|
|
493 def doNoXMLparam(self):
|
49
|
494 """filter style package - stdin to stdout"""
|
62
|
495 if len(self.infiles) > 0:
|
|
496 alab = self.infiles[0][ILABPOS]
|
|
497 if len(alab) == 0:
|
|
498 alab = self.infiles[0][ICLPOS]
|
|
499 max1s = (
|
|
500 "Maximum one input if parampass is 0 but multiple input files supplied - %s"
|
|
501 % str(self.infiles)
|
|
502 )
|
|
503 assert len(self.infiles) == 1, max1s
|
|
504 newname = self.infiles[0][ICLPOS]
|
|
505 aninput = gxtp.DataParam(
|
|
506 newname,
|
|
507 optional=False,
|
|
508 label=alab,
|
|
509 help=self.infiles[0][IHELPOS],
|
|
510 format=self.infiles[0][IFMTPOS],
|
|
511 multiple=False,
|
|
512 num_dashes=0,
|
|
513 )
|
|
514 aninput.command_line_override = "< $%s" % newname
|
|
515 aninput.positional = self.is_positional
|
|
516 self.tinputs.append(aninput)
|
|
517 tp = gxtp.TestParam(name=newname, value="%s_sample" % newname)
|
|
518 self.testparam.append(tp)
|
63
|
519 if len(self.outfiles) > 0:
|
62
|
520 newname = self.outfiles[0][OCLPOS]
|
|
521 newfmt = self.outfiles[0][OFMTPOS]
|
|
522 anout = gxtp.OutputData(newname, format=newfmt, num_dashes=0)
|
|
523 anout.command_line_override = "> $%s" % newname
|
|
524 anout.positional = self.is_positional
|
|
525 self.toutputs.append(anout)
|
75
|
526 tp = gxtp.TestOutput(
|
|
527 name=newname, value="%s_sample" % newname, format=newfmt
|
|
528 )
|
62
|
529 self.testparam.append(tp)
|
48
|
530
|
|
531 def makeXML(self):
|
|
532 """
|
|
533 Create a Galaxy xml tool wrapper for the new script
|
|
534 Uses galaxyhtml
|
|
535 Hmmm. How to get the command line into correct order...
|
|
536 """
|
49
|
537 if self.command_override:
|
56
|
538 self.newtool.command_override = self.command_override # config file
|
48
|
539 else:
|
56
|
540 self.newtool.command_override = self.xmlcl
|
48
|
541 if self.args.help_text:
|
|
542 helptext = open(self.args.help_text, "r").readlines()
|
50
|
543 safertext = [html_escape(x) for x in helptext]
|
63
|
544 if False and self.args.script_path:
|
75
|
545 scrp = self.script.split("\n")
|
|
546 scrpt = [" %s" % x for x in scrp] # try to stop templating
|
|
547 scrpt.insert(0, "```\n")
|
50
|
548 if len(scrpt) > 300:
|
75
|
549 safertext = (
|
|
550 safertext + scrpt[:100] + \
|
|
551 [">500 lines - stuff deleted", "......"] + scrpt[-100:]
|
|
552 )
|
50
|
553 else:
|
|
554 safertext = safertext + scrpt
|
|
555 safertext.append("\n```")
|
62
|
556 self.newtool.help = "\n".join([x for x in safertext])
|
48
|
557 else:
|
50
|
558 self.newtool.help = (
|
48
|
559 "Please ask the tool author (%s) for help \
|
|
560 as none was supplied at tool generation\n"
|
|
561 % (self.args.user_email)
|
|
562 )
|
50
|
563 self.newtool.version_command = None # do not want
|
48
|
564 requirements = gxtp.Requirements()
|
49
|
565 if self.args.packages:
|
|
566 for d in self.args.packages.split(","):
|
|
567 if ":" in d:
|
|
568 packg, ver = d.split(":")
|
|
569 else:
|
|
570 packg = d
|
|
571 ver = ""
|
50
|
572 requirements.append(
|
|
573 gxtp.Requirement("package", packg.strip(), ver.strip())
|
|
574 )
|
|
575 self.newtool.requirements = requirements
|
48
|
576 if self.args.parampass == "0":
|
|
577 self.doNoXMLparam()
|
|
578 else:
|
|
579 self.doXMLparam()
|
50
|
580 self.newtool.outputs = self.toutputs
|
|
581 self.newtool.inputs = self.tinputs
|
|
582 if self.args.script_path:
|
48
|
583 configfiles = gxtp.Configfiles()
|
49
|
584 configfiles.append(gxtp.Configfile(name="runme", text=self.script))
|
50
|
585 self.newtool.configfiles = configfiles
|
48
|
586 tests = gxtp.Tests()
|
|
587 test_a = gxtp.Test()
|
|
588 for tp in self.testparam:
|
|
589 test_a.append(tp)
|
|
590 tests.append(test_a)
|
50
|
591 self.newtool.tests = tests
|
|
592 self.newtool.add_comment(
|
48
|
593 "Created by %s at %s using the Galaxy Tool Factory."
|
|
594 % (self.args.user_email, timenow())
|
|
595 )
|
50
|
596 self.newtool.add_comment("Source in git at: %s" % (toolFactoryURL))
|
|
597 self.newtool.add_comment(
|
48
|
598 "Cite: Creating re-usable tools from scripts doi: \
|
|
599 10.1093/bioinformatics/bts573"
|
|
600 )
|
50
|
601 exml0 = self.newtool.export()
|
49
|
602 exml = exml0.replace(FAKEEXE, "") # temporary work around until PR accepted
|
50
|
603 if (
|
|
604 self.test_override
|
|
605 ): # cannot do this inside galaxyxml as it expects lxml objects for tests
|
|
606 part1 = exml.split("<tests>")[0]
|
|
607 part2 = exml.split("</tests>")[1]
|
|
608 fixed = "%s\n%s\n%s" % (part1, self.test_override, part2)
|
49
|
609 exml = fixed
|
63
|
610 exml = exml.replace('range="1:"', 'range="1000:"')
|
49
|
611 xf = open("%s.xml" % self.tool_name, "w")
|
48
|
612 xf.write(exml)
|
|
613 xf.write("\n")
|
|
614 xf.close()
|
|
615 # ready for the tarball
|
|
616
|
|
617 def run(self):
|
|
618 """
|
50
|
619 generate test outputs by running a command line
|
56
|
620 won't work if command or test override in play - planemo is the
|
50
|
621 easiest way to generate test outputs for that case so is
|
|
622 automagically selected
|
48
|
623 """
|
|
624 scl = " ".join(self.cl)
|
|
625 err = None
|
|
626 if self.args.parampass != "0":
|
56
|
627 if os.path.exists(self.elog):
|
|
628 ste = open(self.elog, "a")
|
|
629 else:
|
|
630 ste = open(self.elog, "w")
|
48
|
631 if self.lastclredirect:
|
49
|
632 sto = open(self.lastclredirect[1], "wb") # is name of an output file
|
48
|
633 else:
|
56
|
634 if os.path.exists(self.tlog):
|
|
635 sto = open(self.tlog, "a")
|
|
636 else:
|
|
637 sto = open(self.tlog, "w")
|
48
|
638 sto.write(
|
75
|
639 "## Executing Toolfactory generated command line = %s\n" % scl
|
48
|
640 )
|
|
641 sto.flush()
|
|
642 p = subprocess.run(self.cl, shell=False, stdout=sto, stderr=ste)
|
|
643 sto.close()
|
|
644 ste.close()
|
|
645 retval = p.returncode
|
49
|
646 else: # work around special case - stdin and write to stdout
|
62
|
647 if len(self.infiles) > 0:
|
|
648 sti = open(self.infiles[0][IPATHPOS], "rb")
|
|
649 else:
|
63
|
650 sti = sys.stdin
|
62
|
651 if len(self.outfiles) > 0:
|
|
652 sto = open(self.outfiles[0][ONAMEPOS], "wb")
|
|
653 else:
|
|
654 sto = sys.stdout
|
48
|
655 p = subprocess.run(self.cl, shell=False, stdout=sto, stdin=sti)
|
75
|
656 sto.write("## Executing Toolfactory generated command line = %s\n" % scl)
|
48
|
657 retval = p.returncode
|
|
658 sto.close()
|
|
659 sti.close()
|
|
660 if os.path.isfile(self.tlog) and os.stat(self.tlog).st_size == 0:
|
|
661 os.unlink(self.tlog)
|
|
662 if os.path.isfile(self.elog) and os.stat(self.elog).st_size == 0:
|
|
663 os.unlink(self.elog)
|
|
664 if retval != 0 and err: # problem
|
|
665 sys.stderr.write(err)
|
|
666 logging.debug("run done")
|
|
667 return retval
|
|
668
|
63
|
669 def shedLoad(self):
|
48
|
670 """
|
63
|
671 {'deleted': False,
|
|
672 'description': 'Tools for manipulating data',
|
|
673 'id': '175812cd7caaf439',
|
|
674 'model_class': 'Category',
|
|
675 'name': 'Text Manipulation',
|
|
676 'url': '/api/categories/175812cd7caaf439'}]
|
|
677
|
|
678
|
48
|
679 """
|
49
|
680 if os.path.exists(self.tlog):
|
63
|
681 sto = open(self.tlog, "a")
|
48
|
682 else:
|
63
|
683 sto = open(self.tlog, "w")
|
48
|
684
|
75
|
685 ts = toolshed.ToolShedInstance(
|
|
686 url=self.args.toolshed_url, key=self.args.toolshed_api_key, verify=False
|
|
687 )
|
63
|
688 repos = ts.repositories.get_repositories()
|
75
|
689 rnames = [x.get("name", "?") for x in repos]
|
|
690 rids = [x.get("id", "?") for x in repos]
|
80
|
691 sto.write(f"############names={rnames} rids={rids}\n")
|
75
|
692 cat = "ToolFactory generated tools"
|
63
|
693 if self.args.tool_name not in rnames:
|
|
694 tscat = ts.categories.get_categories()
|
75
|
695 cnames = [x.get("name", "?") for x in tscat]
|
|
696 cids = [x.get("id", "?") for x in tscat]
|
63
|
697 catID = None
|
|
698 if cat in cnames:
|
|
699 ci = cnames.index(cat)
|
|
700 catID = cids[ci]
|
75
|
701 res = ts.repositories.create_repository(
|
|
702 name=self.args.tool_name,
|
|
703 synopsis="Synopsis:%s" % self.args.tool_desc,
|
|
704 description=self.args.tool_desc,
|
|
705 type="unrestricted",
|
|
706 remote_repository_url=self.args.toolshed_url,
|
|
707 homepage_url=None,
|
|
708 category_ids=catID,
|
|
709 )
|
|
710 tid = res.get("id", None)
|
80
|
711 sto.write(f"##########create res={res}\n")
|
49
|
712 else:
|
75
|
713 i = rnames.index(self.args.tool_name)
|
|
714 tid = rids[i]
|
|
715 res = ts.repositories.update_repository(
|
|
716 id=tid, tar_ball_path=self.newtarpath, commit_message=None
|
|
717 )
|
80
|
718 sto.write(f"#####update res={res}\n")
|
63
|
719 sto.close()
|
|
720
|
48
|
721 def eph_galaxy_load(self):
|
75
|
722 """load the new tool from the local toolshed after planemo uploads it"""
|
49
|
723 if os.path.exists(self.tlog):
|
50
|
724 tout = open(self.tlog, "a")
|
49
|
725 else:
|
50
|
726 tout = open(self.tlog, "w")
|
49
|
727 cll = [
|
|
728 "shed-tools",
|
|
729 "install",
|
|
730 "-g",
|
|
731 self.args.galaxy_url,
|
|
732 "--latest",
|
|
733 "-a",
|
|
734 self.args.galaxy_api_key,
|
|
735 "--name",
|
|
736 self.args.tool_name,
|
|
737 "--owner",
|
|
738 "fubar",
|
|
739 "--toolshed",
|
|
740 self.args.toolshed_url,
|
75
|
741 "--section_label",
|
63
|
742 "ToolFactory",
|
49
|
743 ]
|
63
|
744 tout.write("running\n%s\n" % " ".join(cll))
|
49
|
745 p = subprocess.run(cll, shell=False, stderr=tout, stdout=tout)
|
75
|
746 tout.write(
|
|
747 "installed %s - got retcode %d\n" % (self.args.tool_name, p.returncode)
|
|
748 )
|
63
|
749 tout.close()
|
|
750 return p.returncode
|
|
751
|
|
752 def planemo_shedload(self):
|
|
753 """
|
|
754 planemo shed_create --shed_target testtoolshed
|
|
755 planemo shed_init --name=<name>
|
|
756 --owner=<shed_username>
|
|
757 --description=<short description>
|
|
758 [--remote_repository_url=<URL to .shed.yml on github>]
|
|
759 [--homepage_url=<Homepage for tool.>]
|
|
760 [--long_description=<long description>]
|
|
761 [--category=<category name>]*
|
66
|
762
|
|
763
|
63
|
764 planemo shed_update --check_diff --shed_target testtoolshed
|
|
765 """
|
|
766 if os.path.exists(self.tlog):
|
|
767 tout = open(self.tlog, "a")
|
48
|
768 else:
|
63
|
769 tout = open(self.tlog, "w")
|
75
|
770 ts = toolshed.ToolShedInstance(
|
|
771 url=self.args.toolshed_url, key=self.args.toolshed_api_key, verify=False
|
|
772 )
|
63
|
773 repos = ts.repositories.get_repositories()
|
75
|
774 rnames = [x.get("name", "?") for x in repos]
|
|
775 rids = [x.get("id", "?") for x in repos]
|
|
776 #cat = "ToolFactory generated tools"
|
63
|
777 if self.args.tool_name not in rnames:
|
75
|
778 cll = [
|
|
779 "planemo",
|
|
780 "shed_create",
|
|
781 "--shed_target",
|
|
782 "local",
|
|
783 "--owner",
|
|
784 "fubar",
|
|
785 "--name",
|
|
786 self.args.tool_name,
|
|
787 "--shed_key",
|
|
788 self.args.toolshed_api_key,
|
|
789 ]
|
63
|
790 try:
|
|
791 p = subprocess.run(
|
|
792 cll, shell=False, cwd=self.tooloutdir, stdout=tout, stderr=tout
|
|
793 )
|
|
794 except:
|
|
795 pass
|
|
796 if p.returncode != 0:
|
80
|
797 tout.write("Repository %s exists\n" % self.args.tool_name)
|
63
|
798 else:
|
80
|
799 tout.write("initiated %s\n" % self.args.tool_name)
|
63
|
800 cll = [
|
|
801 "planemo",
|
|
802 "shed_upload",
|
|
803 "--shed_target",
|
|
804 "local",
|
|
805 "--owner",
|
|
806 "fubar",
|
|
807 "--name",
|
|
808 self.args.tool_name,
|
|
809 "--shed_key",
|
|
810 self.args.toolshed_api_key,
|
|
811 "--tar",
|
|
812 self.newtarpath,
|
|
813 ]
|
|
814 p = subprocess.run(cll, shell=False, stdout=tout, stderr=tout)
|
80
|
815 tout.write("Ran %s got %d\n" % (" ".join(cll), p.returncode))
|
49
|
816 tout.close()
|
48
|
817 return p.returncode
|
|
818
|
76
|
819 def eph_test(self, genoutputs=True):
|
|
820 """problem getting jobid - ephemeris upload is the job before the one we want - but depends on how many inputs
|
|
821 """
|
75
|
822 if os.path.exists(self.tlog):
|
|
823 tout = open(self.tlog, "a")
|
|
824 else:
|
|
825 tout = open(self.tlog, "w")
|
|
826 cll = [
|
|
827 "shed-tools",
|
|
828 "test",
|
|
829 "-g",
|
|
830 self.args.galaxy_url,
|
|
831 "-a",
|
|
832 self.args.galaxy_api_key,
|
|
833 "--name",
|
|
834 self.args.tool_name,
|
|
835 "--owner",
|
|
836 "fubar",
|
|
837 ]
|
76
|
838 if genoutputs:
|
|
839 dummy, tfile = tempfile.mkstemp()
|
|
840 p = subprocess.run(
|
|
841 cll, shell=False, stderr=dummy, stdout=dummy
|
|
842 )
|
|
843
|
|
844 with open('tool_test_output.json','rb') as f:
|
|
845 s = json.loads(f.read())
|
|
846 print('read %s' % s)
|
|
847 cl = s['tests'][0]['data']['job']['command_line'].split()
|
|
848 n = cl.index('--script_path')
|
|
849 jobdir = cl[n+1]
|
|
850 jobdir = jobdir.replace('"','')
|
|
851 jobdir = jobdir.split('/configs')[0]
|
|
852 print('jobdir=%s' % jobdir)
|
|
853
|
|
854 #"/home/ross/galthrow/database/jobs_directory/000/649/configs/tmptfxu51gs\"
|
|
855 src = os.path.join(jobdir,'working',self.newtarpath)
|
|
856 if os.path.exists(src):
|
|
857 dest = os.path.join(self.testdir, self.newtarpath)
|
|
858 shutil.copyfile(src, dest)
|
|
859 else:
|
|
860 tout.write('No toolshed archive found after first ephemeris test - not a good sign')
|
|
861 ephouts = os.path.join(jobdir,'working','tfout','test-data')
|
|
862 with os.scandir(ephouts) as outs:
|
|
863 for entry in outs:
|
|
864 if not entry.is_file():
|
|
865 continue
|
|
866 dest = os.path.join(self.tooloutdir, entry.name)
|
|
867 src = os.path.join(ephouts, entry.name)
|
|
868 shutil.copyfile(src, dest)
|
|
869 else:
|
|
870 p = subprocess.run(
|
|
871 cll, shell=False, stderr=tout, stdout=tout)
|
|
872 tout.write("eph_test Ran %s got %d" % (" ".join(cll), p.returncode))
|
75
|
873 tout.close()
|
|
874 return p.returncode
|
63
|
875
|
83
|
876 def planemo_test_biocontainer(self, genoutputs=True):
|
|
877 """planemo is a requirement so is available for testing but testing in a biocontainer
|
|
878 requires some fiddling to use the hacked galaxy-central .venv
|
|
879
|
|
880 Planemo runs:
|
|
881 python ./scripts/functional_tests.py -v --with-nosehtml --html-report-file
|
|
882 /export/galaxy-central/database/job_working_directory/000/17/working/TF_run_report_tempdir/tacrev_planemo_test_report.html
|
|
883 --with-xunit --xunit-file /tmp/tmpt90p7f9h/xunit.xml --with-structureddata
|
|
884 --structured-data-file
|
|
885 /export/galaxy-central/database/job_working_directory/000/17/working/tfout/tool_test_output.json functional.test_toolbox
|
|
886
|
|
887
|
|
888 for the planemo-biocontainer,
|
|
889 planemo test --conda_dependency_resolution --skip_venv --galaxy_root /galthrow/ rgToolFactory2.xml
|
|
890
|
|
891 """
|
|
892 xreal = "%s.xml" % self.tool_name
|
|
893 tool_test_path = os.path.join(self.repdir,f"{self.tool_name}_planemo_test_report.html")
|
|
894 if os.path.exists(self.tlog):
|
|
895 tout = open(self.tlog, "a")
|
|
896 else:
|
|
897 tout = open(self.tlog, "w")
|
|
898 if genoutputs:
|
|
899 dummy, tfile = tempfile.mkstemp()
|
|
900 cll = [
|
84
|
901 ".","/home/biodocker/galaxy-central/.venv/bin/activate", "&&",
|
83
|
902 "planemo",
|
|
903 "test",
|
|
904 "--test_data", os.path.abspath(self.testdir),
|
|
905 "--test_output", os.path.abspath(tool_test_path),
|
|
906 "--skip_venv",
|
|
907 "--galaxy_root",
|
87
|
908 "/home/biodocker/galaxy-central",
|
83
|
909 "--update_test_data",
|
|
910 os.path.abspath(xreal),
|
|
911 ]
|
|
912 p = subprocess.run(
|
|
913 cll,
|
|
914 shell=False,
|
|
915 cwd=self.tooloutdir,
|
|
916 stderr=dummy,
|
|
917 stdout=dummy,
|
|
918 )
|
|
919
|
|
920 else:
|
|
921 cll = [
|
|
922 ".","/home/biodocker/galaxy-central/.venv/bin/activate","&&",
|
|
923 "planemo",
|
|
924 "test",
|
|
925 "--test_data", os.path.abspath(self.testdir),
|
|
926 "--test_output", os.path.abspath(tool_test_path),
|
|
927 "--skip_venv",
|
|
928 "--galaxy_root",
|
87
|
929 "/home/biodocker/galaxy-central",
|
83
|
930 os.path.abspath(xreal),
|
|
931 ]
|
|
932 p = subprocess.run(
|
|
933 cll, shell=False, cwd=self.tooloutdir, stderr=tout, stdout=tout
|
|
934 )
|
|
935 tout.close()
|
|
936 return p.returncode
|
|
937
|
63
|
938 def planemo_test(self, genoutputs=True):
|
83
|
939 """planemo is a requirement so is available for testing but needs a different call if
|
|
940 in the biocontainer - see above
|
63
|
941 and for generating test outputs if command or test overrides are supplied
|
|
942 test outputs are sent to repdir for display
|
81
|
943 planemo test --engine docker_galaxy --galaxy_root /galaxy-central pyrevpos/pyrevpos.xml
|
|
944
|
|
945 Planemo runs:
|
|
946 python ./scripts/functional_tests.py -v --with-nosehtml --html-report-file
|
|
947 /export/galaxy-central/database/job_working_directory/000/17/working/TF_run_report_tempdir/tacrev_planemo_test_report.html
|
|
948 --with-xunit --xunit-file /tmp/tmpt90p7f9h/xunit.xml --with-structureddata
|
|
949 --structured-data-file
|
|
950 /export/galaxy-central/database/job_working_directory/000/17/working/tfout/tool_test_output.json functional.test_toolbox
|
|
951
|
|
952
|
|
953 for the planemo-biocontainer,
|
|
954 planemo test --conda_dependency_resolution --skip_venv --galaxy_root /galthrow/ rgToolFactory2.xml
|
|
955
|
63
|
956 """
|
|
957 xreal = "%s.xml" % self.tool_name
|
78
|
958 tool_test_path = os.path.join(self.repdir,f"{self.tool_name}_planemo_test_report.html")
|
63
|
959 if os.path.exists(self.tlog):
|
|
960 tout = open(self.tlog, "a")
|
|
961 else:
|
|
962 tout = open(self.tlog, "w")
|
|
963 if genoutputs:
|
75
|
964 dummy, tfile = tempfile.mkstemp()
|
63
|
965 cll = [
|
|
966 "planemo",
|
|
967 "test",
|
78
|
968 "--test_data", os.path.abspath(self.testdir),
|
|
969 "--test_output", os.path.abspath(tool_test_path),
|
81
|
970 "--skip_venv",
|
63
|
971 "--galaxy_root",
|
|
972 self.args.galaxy_root,
|
74
|
973 "--update_test_data",
|
78
|
974 os.path.abspath(xreal),
|
63
|
975 ]
|
|
976 p = subprocess.run(
|
75
|
977 cll,
|
|
978 shell=False,
|
|
979 cwd=self.tooloutdir,
|
80
|
980 stderr=dummy,
|
|
981 stdout=dummy,
|
75
|
982 )
|
80
|
983
|
63
|
984 else:
|
75
|
985 cll = [
|
|
986 "planemo",
|
|
987 "test",
|
80
|
988 "--test_data", os.path.abspath(self.testdir),
|
|
989 "--test_output", os.path.abspath(tool_test_path),
|
81
|
990 "--skip_venv",
|
75
|
991 "--galaxy_root",
|
74
|
992 self.args.galaxy_root,
|
78
|
993 os.path.abspath(xreal),
|
75
|
994 ]
|
63
|
995 p = subprocess.run(
|
75
|
996 cll, shell=False, cwd=self.tooloutdir, stderr=tout, stdout=tout
|
|
997 )
|
63
|
998 tout.close()
|
|
999 return p.returncode
|
|
1000
|
83
|
1001
|
48
|
1002 def writeShedyml(self):
|
75
|
1003 """for planemo"""
|
49
|
1004 yuser = self.args.user_email.split("@")[0]
|
|
1005 yfname = os.path.join(self.tooloutdir, ".shed.yml")
|
|
1006 yamlf = open(yfname, "w")
|
|
1007 odict = {
|
|
1008 "name": self.tool_name,
|
|
1009 "owner": yuser,
|
|
1010 "type": "unrestricted",
|
|
1011 "description": self.args.tool_desc,
|
50
|
1012 "synopsis": self.args.tool_desc,
|
|
1013 "category": "TF Generated Tools",
|
49
|
1014 }
|
48
|
1015 yaml.dump(odict, yamlf, allow_unicode=True)
|
|
1016 yamlf.close()
|
|
1017
|
50
|
1018 def makeTool(self):
|
75
|
1019 """write xmls and input samples into place"""
|
50
|
1020 self.makeXML()
|
|
1021 if self.args.script_path:
|
|
1022 stname = os.path.join(self.tooloutdir, "%s" % (self.sfile))
|
|
1023 if not os.path.exists(stname):
|
|
1024 shutil.copyfile(self.sfile, stname)
|
|
1025 xreal = "%s.xml" % self.tool_name
|
|
1026 xout = os.path.join(self.tooloutdir, xreal)
|
|
1027 shutil.copyfile(xreal, xout)
|
|
1028 for p in self.infiles:
|
|
1029 pth = p[IPATHPOS]
|
|
1030 dest = os.path.join(self.testdir, "%s_sample" % p[ICLPOS])
|
|
1031 shutil.copyfile(pth, dest)
|
49
|
1032
|
50
|
1033 def makeToolTar(self):
|
75
|
1034 """move outputs into test-data and prepare the tarball"""
|
66
|
1035 excludeme = "tool_test_output"
|
75
|
1036
|
66
|
1037 def exclude_function(tarinfo):
|
75
|
1038 filename = tarinfo.name
|
|
1039 return (
|
|
1040 None
|
80
|
1041 if filename.startswith(excludeme)
|
75
|
1042 else tarinfo
|
|
1043 )
|
66
|
1044
|
50
|
1045 for p in self.outfiles:
|
|
1046 src = p[ONAMEPOS]
|
|
1047 if os.path.isfile(src):
|
|
1048 dest = os.path.join(self.testdir, "%s_sample" % src)
|
|
1049 shutil.copyfile(src, dest)
|
|
1050 dest = os.path.join(self.repdir, "%s.%s" % (src, p[OFMTPOS]))
|
|
1051 shutil.copyfile(src, dest)
|
|
1052 else:
|
|
1053 print(
|
|
1054 "### problem - output file %s not found in tooloutdir %s"
|
|
1055 % (src, self.tooloutdir)
|
|
1056 )
|
|
1057 tf = tarfile.open(self.newtarpath, "w:gz")
|
66
|
1058 tf.add(name=self.tooloutdir, arcname=self.tool_name, filter=exclude_function)
|
50
|
1059 tf.close()
|
|
1060 shutil.copyfile(self.newtarpath, self.args.new_tool)
|
|
1061
|
|
1062 def moveRunOutputs(self):
|
75
|
1063 """need to move planemo or run outputs into toolfactory collection"""
|
50
|
1064 with os.scandir(self.tooloutdir) as outs:
|
|
1065 for entry in outs:
|
80
|
1066 if not entry.is_file():
|
|
1067 continue
|
|
1068 if "." in entry.name:
|
|
1069 nayme, ext = os.path.splitext(entry.name)
|
|
1070 if ext in ['.yml','.xml','.json','.yaml']:
|
|
1071 ext = f'{ext}.txt'
|
|
1072 else:
|
|
1073 ext = ".txt"
|
|
1074 ofn = "%s%s" % (entry.name.replace(".", "_"), ext)
|
|
1075 dest = os.path.join(self.repdir, ofn)
|
|
1076 src = os.path.join(self.tooloutdir, entry.name)
|
|
1077 shutil.copyfile(src, dest)
|
|
1078 with os.scandir(self.testdir) as outs:
|
|
1079 for entry in outs:
|
|
1080 if not entry.is_file():
|
50
|
1081 continue
|
|
1082 if "." in entry.name:
|
|
1083 nayme, ext = os.path.splitext(entry.name)
|
|
1084 else:
|
|
1085 ext = ".txt"
|
80
|
1086 newname = f"{entry.name}{ext}"
|
|
1087 dest = os.path.join(self.repdir, newname)
|
|
1088 src = os.path.join(self.testdir, entry.name)
|
50
|
1089 shutil.copyfile(src, dest)
|
|
1090
|
49
|
1091
|
76
|
1092
|
48
|
1093 def main():
|
|
1094 """
|
|
1095 This is a Galaxy wrapper. It expects to be called by a special purpose tool.xml as:
|
49
|
1096 <command interpreter="python">rgBaseScriptWrapper.py --script_path "$scriptPath"
|
|
1097 --tool_name "foo" --interpreter "Rscript"
|
48
|
1098 </command>
|
|
1099 """
|
|
1100 parser = argparse.ArgumentParser()
|
|
1101 a = parser.add_argument
|
49
|
1102 a("--script_path", default=None)
|
|
1103 a("--history_test", default=None)
|
|
1104 a("--cl_prefix", default=None)
|
|
1105 a("--sysexe", default=None)
|
|
1106 a("--packages", default=None)
|
76
|
1107 a("--tool_name", default="newtool")
|
72
|
1108 a("--tool_dir", default=None)
|
48
|
1109 a("--input_files", default=[], action="append")
|
|
1110 a("--output_files", default=[], action="append")
|
|
1111 a("--user_email", default="Unknown")
|
|
1112 a("--bad_user", default=None)
|
49
|
1113 a("--make_Tool", default="runonly")
|
48
|
1114 a("--help_text", default=None)
|
|
1115 a("--tool_desc", default=None)
|
|
1116 a("--tool_version", default=None)
|
|
1117 a("--citations", default=None)
|
49
|
1118 a("--command_override", default=None)
|
|
1119 a("--test_override", default=None)
|
48
|
1120 a("--additional_parameters", action="append", default=[])
|
|
1121 a("--edit_additional_parameters", action="store_true", default=False)
|
|
1122 a("--parampass", default="positional")
|
|
1123 a("--tfout", default="./tfout")
|
|
1124 a("--new_tool", default="new_tool")
|
49
|
1125 a("--galaxy_url", default="http://localhost:8080")
|
75
|
1126 a(
|
76
|
1127 "--toolshed_url", default="http://localhost:9009")
|
|
1128 # make sure this is identical to tool_sheds_conf.xml localhost != 127.0.0.1 so validation fails
|
63
|
1129 a("--toolshed_api_key", default="fakekey")
|
50
|
1130 a("--galaxy_api_key", default="fakekey")
|
|
1131 a("--galaxy_root", default="/galaxy-central")
|
48
|
1132 args = parser.parse_args()
|
|
1133 assert not args.bad_user, (
|
|
1134 'UNAUTHORISED: %s is NOT authorized to use this tool until Galaxy admin adds %s to "admin_users" in the Galaxy configuration file'
|
|
1135 % (args.bad_user, args.bad_user)
|
|
1136 )
|
49
|
1137 assert args.tool_name, "## Tool Factory expects a tool name - eg --tool_name=DESeq"
|
48
|
1138 assert (
|
49
|
1139 args.sysexe or args.packages
|
48
|
1140 ), "## Tool Factory wrapper expects an interpreter or an executable package"
|
49
|
1141 args.input_files = [x.replace('"', "").replace("'", "") for x in args.input_files]
|
48
|
1142 # remove quotes we need to deal with spaces in CL params
|
|
1143 for i, x in enumerate(args.additional_parameters):
|
49
|
1144 args.additional_parameters[i] = args.additional_parameters[i].replace('"', "")
|
48
|
1145 r = ScriptRunner(args)
|
49
|
1146 r.writeShedyml()
|
|
1147 r.makeTool()
|
66
|
1148 if args.make_Tool == "generate":
|
|
1149 retcode = r.run()
|
|
1150 r.moveRunOutputs()
|
|
1151 r.makeToolTar()
|
|
1152 else:
|
|
1153 retcode = r.planemo_test(genoutputs=True) # this fails :( - see PR
|
|
1154 r.moveRunOutputs()
|
|
1155 r.makeToolTar()
|
|
1156 retcode = r.planemo_test(genoutputs=False)
|
|
1157 r.moveRunOutputs()
|
80
|
1158 r.makeToolTar()
|
76
|
1159 print(f"second planemo_test returned {retcode}")
|
66
|
1160 if args.make_Tool == "gentestinstall":
|
80
|
1161 r.shedLoad()
|
66
|
1162 r.eph_galaxy_load()
|
63
|
1163
|
48
|
1164
|
|
1165 if __name__ == "__main__":
|
|
1166 main()
|