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