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