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