Mercurial > repos > fubar > tool_factory_2
comparison toolfactory/rgToolFactory2.py @ 135:7805fdac70ed draft
Uploaded
author | fubar |
---|---|
date | Tue, 13 Apr 2021 00:34:39 +0000 |
parents | 1f353bee783f |
children | 63d15caea378 |
comparison
equal
deleted
inserted
replaced
134:1f353bee783f | 135:7805fdac70ed |
---|---|
26 import sys | 26 import sys |
27 import tarfile | 27 import tarfile |
28 import tempfile | 28 import tempfile |
29 import time | 29 import time |
30 | 30 |
31 from bioblend import ConnectionError | |
32 from bioblend import toolshed | |
33 | |
31 import galaxyxml.tool as gxt | 34 import galaxyxml.tool as gxt |
32 import galaxyxml.tool.parameters as gxtp | 35 import galaxyxml.tool.parameters as gxtp |
36 | |
33 import lxml | 37 import lxml |
38 | |
34 import yaml | 39 import yaml |
35 from bioblend import ConnectionError | |
36 from bioblend import toolshed | |
37 | 40 |
38 myversion = "V2.2 February 2021" | 41 myversion = "V2.2 February 2021" |
39 verbose = True | 42 verbose = True |
40 debug = True | 43 debug = True |
41 toolFactoryURL = "https://github.com/fubar2/toolfactory" | 44 toolFactoryURL = "https://github.com/fubar2/toolfactory" |
74 """Wrapper for an arbitrary script | 77 """Wrapper for an arbitrary script |
75 uses galaxyxml | 78 uses galaxyxml |
76 | 79 |
77 """ | 80 """ |
78 | 81 |
79 def __init__(self, args=None): | 82 def __init__(self, args=None): # noqa |
80 """ | 83 """ |
81 prepare command line cl for running the tool here | 84 prepare command line cl for running the tool here |
82 and prepare elements needed for galaxyxml tool generation | 85 and prepare elements needed for galaxyxml tool generation |
83 """ | 86 """ |
84 self.ourcwd = os.getcwd() | 87 self.ourcwd = os.getcwd() |
227 | 230 |
228 def prepargp(self): | 231 def prepargp(self): |
229 clsuffix = [] | 232 clsuffix = [] |
230 xclsuffix = [] | 233 xclsuffix = [] |
231 for i, p in enumerate(self.infiles): | 234 for i, p in enumerate(self.infiles): |
235 nam = p["infilename"] | |
232 if p["origCL"].strip().upper() == "STDIN": | 236 if p["origCL"].strip().upper() == "STDIN": |
233 appendme = [ | 237 appendme = [ |
234 p["infilename"], | 238 nam, |
235 p["infilename"], | 239 nam, |
236 "< %s" % p["infilename"], | 240 "< %s" % nam, |
237 ] | 241 ] |
238 xappendme = [ | 242 xappendme = [ |
239 p["infilename"], | 243 nam, |
240 p["infilename"], | 244 nam, |
241 "< $%s" % p["infilename"], | 245 "< $%s" % nam, |
242 ] | 246 ] |
243 else: | 247 else: |
248 rep = p["repeat"] == "1" | |
249 over = "" | |
250 if rep: | |
251 over = f'#for $rep in $R_{nam}:\n--{nam} "$rep.{nam}"\n#end for' | |
244 appendme = [p["CL"], p["CL"], ""] | 252 appendme = [p["CL"], p["CL"], ""] |
245 xappendme = [p["CL"], "$%s" % p["CL"], ""] | 253 xappendme = [p["CL"], "$%s" % p["CL"], over] |
246 clsuffix.append(appendme) | 254 clsuffix.append(appendme) |
247 xclsuffix.append(xappendme) | 255 xclsuffix.append(xappendme) |
248 for i, p in enumerate(self.outfiles): | 256 for i, p in enumerate(self.outfiles): |
249 if p["origCL"].strip().upper() == "STDOUT": | 257 if p["origCL"].strip().upper() == "STDOUT": |
250 self.lastclredirect = [">", p["name"]] | 258 self.lastclredirect = [">", p["name"]] |
254 xclsuffix.append([p["name"], "$%s" % p["name"], ""]) | 262 xclsuffix.append([p["name"], "$%s" % p["name"], ""]) |
255 for p in self.addpar: | 263 for p in self.addpar: |
256 nam = p["name"] | 264 nam = p["name"] |
257 rep = p["repeat"] == "1" | 265 rep = p["repeat"] == "1" |
258 if rep: | 266 if rep: |
259 over = f" #for $rep in $R_{nam}:\n--{nam} $rep.{nam}\n#end for" | 267 over = f'#for $rep in $R_{nam}:\n--{nam} "$rep.{nam}"\n#end for' |
260 else: | 268 else: |
261 over = p["override"] | 269 over = p["override"] |
262 clsuffix.append([p["CL"], nam, over]) | 270 clsuffix.append([p["CL"], nam, over]) |
263 xclsuffix.append([p["CL"], nam, over]) | 271 xclsuffix.append([p["CL"], nam, over]) |
264 for p in self.selpar: | 272 for p in self.selpar: |
421 if len(newname) < 2: | 429 if len(newname) < 2: |
422 ndash = 1 | 430 ndash = 1 |
423 return ndash | 431 return ndash |
424 | 432 |
425 def doXMLparam(self): | 433 def doXMLparam(self): |
426 """flake8 made me do this...""" | 434 """Add all needed elements to tool""" # noqa |
427 for p in self.outfiles: | 435 for p in self.outfiles: |
428 newname = p["name"] | 436 newname = p["name"] |
429 newfmt = p["format"] | 437 newfmt = p["format"] |
430 newcl = p["CL"] | 438 newcl = p["CL"] |
431 test = p["test"] | 439 test = p["test"] |
484 self.testparam.append(tp) | 492 self.testparam.append(tp) |
485 for p in self.infiles: | 493 for p in self.infiles: |
486 newname = p["infilename"] | 494 newname = p["infilename"] |
487 newfmt = p["format"] | 495 newfmt = p["format"] |
488 ndash = self.getNdash(newname) | 496 ndash = self.getNdash(newname) |
489 reps = p.get("repeat", 0) == 1 | 497 reps = p.get("repeat", "0") == "1" |
490 if not len(p["label"]) > 0: | 498 if not len(p["label"]) > 0: |
491 alab = p["CL"] | 499 alab = p["CL"] |
492 else: | 500 else: |
493 alab = p["label"] | 501 alab = p["label"] |
494 aninput = gxtp.DataParam( | 502 aninput = gxtp.DataParam( |
672 anout.positional = self.is_positional | 680 anout.positional = self.is_positional |
673 self.toutputs.append(anout) | 681 self.toutputs.append(anout) |
674 tp = gxtp.TestOutput(name=newname, value="%s_sample" % newname) | 682 tp = gxtp.TestOutput(name=newname, value="%s_sample" % newname) |
675 self.testparam.append(tp) | 683 self.testparam.append(tp) |
676 | 684 |
677 def makeXML(self): | 685 def makeXML(self): # noqa |
678 """ | 686 """ |
679 Create a Galaxy xml tool wrapper for the new script | 687 Create a Galaxy xml tool wrapper for the new script |
680 Uses galaxyhtml | 688 Uses galaxyhtml |
681 Hmmm. How to get the command line into correct order... | 689 Hmmm. How to get the command line into correct order... |
682 """ | 690 """ |
710 ) | 718 ) |
711 scr.append("\n") | 719 scr.append("\n") |
712 safertext = safertext + "\n".join(scr) | 720 safertext = safertext + "\n".join(scr) |
713 self.newtool.help = safertext | 721 self.newtool.help = safertext |
714 self.newtool.version_command = f'echo "{self.args.tool_version}"' | 722 self.newtool.version_command = f'echo "{self.args.tool_version}"' |
723 std = gxtp.Stdios() | |
724 std1 = gxtp.Stdio() | |
725 std.append(std1) | |
726 self.newtool.stdios = std | |
715 requirements = gxtp.Requirements() | 727 requirements = gxtp.Requirements() |
716 if self.args.packages: | 728 if self.args.packages: |
717 for d in self.args.packages.split(","): | 729 for d in self.args.packages.split(","): |
718 ver = "" | 730 ver = "" |
719 d = d.replace("==", ":") | 731 d = d.replace("==", ":") |
723 else: | 735 else: |
724 packg = d | 736 packg = d |
725 requirements.append( | 737 requirements.append( |
726 gxtp.Requirement("package", packg.strip(), ver.strip()) | 738 gxtp.Requirement("package", packg.strip(), ver.strip()) |
727 ) | 739 ) |
728 self.newtool.requirements = requirements | 740 self.newtool.requirements = requirements |
729 if self.args.parampass == "0": | 741 if self.args.parampass == "0": |
730 self.doNoXMLparam() | 742 self.doNoXMLparam() |
731 else: | 743 else: |
732 self.doXMLparam() | 744 self.doXMLparam() |
733 self.newtool.outputs = self.toutputs | 745 self.newtool.outputs = self.toutputs |
1122 if args.make_Tool == "generate": | 1134 if args.make_Tool == "generate": |
1123 r.run() | 1135 r.run() |
1124 r.moveRunOutputs() | 1136 r.moveRunOutputs() |
1125 r.makeToolTar() | 1137 r.makeToolTar() |
1126 else: | 1138 else: |
1127 # r.planemo_test(genoutputs=True) # this fails :( - see PR | |
1128 # r.moveRunOutputs() | |
1129 # r.makeToolTar(report_fail=False) | |
1130 r.planemo_test_once() | 1139 r.planemo_test_once() |
1131 r.moveRunOutputs() | 1140 r.moveRunOutputs() |
1132 r.makeToolTar(report_fail=True) | 1141 r.makeToolTar(report_fail=True) |
1133 if args.make_Tool == "gentestinstall": | 1142 if args.make_Tool == "gentestinstall": |
1134 r.shedLoad() | 1143 r.shedLoad() |