comparison toolfactory/rgToolFactory2.py @ 38:a30536c100bf draft

Updated history outputs
author fubar
date Wed, 12 Aug 2020 01:43:46 -0400
parents ce2b1f8ea68d
children 2cd6555baf44
comparison
equal deleted inserted replaced
37:099047ee7094 38:a30536c100bf
1 #!/usr/bin/env python
1 # rgToolFactory.py 2 # rgToolFactory.py
2 # see https://github.com/fubar2/toolfactory 3 # see https://github.com/fubar2/toolfactory
3 # 4 #
4 # copyright ross lazarus (ross stop lazarus at gmail stop com) May 2012 5 # copyright ross lazarus (ross stop lazarus at gmail stop com) May 2012
5 # 6 #
31 import tempfile 32 import tempfile
32 import time 33 import time
33 34
34 import galaxyxml.tool as gxt 35 import galaxyxml.tool as gxt
35 import galaxyxml.tool.parameters as gxtp 36 import galaxyxml.tool.parameters as gxtp
37
36 import lxml 38 import lxml
37 39
38 foo = lxml.__name__ # fug you, flake8. Say my name! Please accept the PR, Helena!
39
40 progname = os.path.split(sys.argv[0])[1]
41 myversion = "V2.1 July 2020" 40 myversion = "V2.1 July 2020"
42 verbose = True 41 verbose = True
43 debug = True 42 debug = True
44 toolFactoryURL = "https://github.com/fubar2/toolfactory" 43 toolFactoryURL = "https://github.com/fubar2/toolfactory"
45 ourdelim = "~~~" 44 ourdelim = "~~~"
46 45
47 # --input_files="$input_files~~~$CL~~~$input_formats~~~$input_label~~~$input_help" 46 # --input_files="$input_files~~~$CL~~~$input_formats~~~$input_label
47 # ~~~$input_help"
48 IPATHPOS = 0 48 IPATHPOS = 0
49 ICLPOS = 1 49 ICLPOS = 1
50 IFMTPOS = 2 50 IFMTPOS = 2
51 ILABPOS = 3 51 ILABPOS = 3
52 IHELPOS = 4 52 IHELPOS = 4
53 IOCLPOS = 5 53 IOCLPOS = 5
54
54 # --output_files "$otab.history_name~~~$otab.history_format~~~$otab.CL 55 # --output_files "$otab.history_name~~~$otab.history_format~~~$otab.CL
55 ONAMEPOS = 0 56 ONAMEPOS = 0
56 OFMTPOS = 1 57 OFMTPOS = 1
57 OCLPOS = 2 58 OCLPOS = 2
58 OOCLPOS = 3 59 OOCLPOS = 3
59 60
60 # --additional_parameters="$i.param_name~~~$i.param_value~~~$i.param_label~~~$i.param_help~~~$i.param_type~~~$i.CL" 61 # --additional_parameters="$i.param_name~~~$i.param_value~~~
62 # $i.param_label~~~$i.param_help~~~$i.param_type~~~$i.CL~~~i$.param_CLoverride"
61 ANAMEPOS = 0 63 ANAMEPOS = 0
62 AVALPOS = 1 64 AVALPOS = 1
63 ALABPOS = 2 65 ALABPOS = 2
64 AHELPPOS = 3 66 AHELPPOS = 3
65 ATYPEPOS = 4 67 ATYPEPOS = 4
66 ACLPOS = 5 68 ACLPOS = 5
67 AOCLPOS = 6 69 AOVERPOS = 6
68 70 AOCLPOS = 7
71
72
73 foo = len(lxml.__version__)
74 # fug you, flake8. Say my name!
69 75
70 def timenow(): 76 def timenow():
71 """return current time as a string 77 """return current time as a string
72 """ 78 """
73 return time.strftime("%d/%m/%Y %H:%M:%S", time.localtime(time.time())) 79 return time.strftime("%d/%m/%Y %H:%M:%S", time.localtime(time.time()))
106 """ 112 """
107 citations = [c for c in citations_text.split("**ENTRY**") if c.strip()] 113 citations = [c for c in citations_text.split("**ENTRY**") if c.strip()]
108 citation_tuples = [] 114 citation_tuples = []
109 for citation in citations: 115 for citation in citations:
110 if citation.startswith("doi"): 116 if citation.startswith("doi"):
111 citation_tuples.append(("doi", citation[len("doi"):].strip())) 117 citation_tuples.append(("doi", citation[len("doi") :].strip()))
112 else: 118 else:
113 citation_tuples.append(("bibtex", citation[len("bibtex"):].strip())) 119 citation_tuples.append(
120 ("bibtex", citation[len("bibtex") :].strip())
121 )
114 return citation_tuples 122 return citation_tuples
115 123
116 124
117 class ScriptRunner: 125 class ScriptRunner:
118 """Wrapper for an arbitrary script 126 """Wrapper for an arbitrary script
142 "argparse", 150 "argparse",
143 "positional", 151 "positional",
144 ], 'Parameter passing in args.parampass must be "0","positional" or "argparse"' 152 ], 'Parameter passing in args.parampass must be "0","positional" or "argparse"'
145 self.tool_name = re.sub("[^a-zA-Z0-9_]+", "", args.tool_name) 153 self.tool_name = re.sub("[^a-zA-Z0-9_]+", "", args.tool_name)
146 self.tool_id = self.tool_name 154 self.tool_id = self.tool_name
147 self.xmlfile = "%s.xml" % self.tool_name
148 if self.args.interpreter_name: 155 if self.args.interpreter_name:
149 exe = "$runMe" 156 exe = "$runMe"
150 else: 157 else:
151 exe = self.args.exe_package 158 exe = self.args.exe_package
152 assert ( 159 assert (
175 self.clsimple() 182 self.clsimple()
176 else: 183 else:
177 clsuffix = [] 184 clsuffix = []
178 xclsuffix = [] 185 xclsuffix = []
179 for i, p in enumerate(self.infiles): 186 for i, p in enumerate(self.infiles):
180 appendme = [p[IOCLPOS], p[ICLPOS], p[IPATHPOS]] 187 if p[IOCLPOS] == "STDIN":
188 appendme = [
189 p[IOCLPOS],
190 p[ICLPOS],
191 p[IPATHPOS],
192 "< %s" % p[IPATHPOS],
193 ]
194 xappendme = [
195 p[IOCLPOS],
196 p[ICLPOS],
197 p[IPATHPOS],
198 "< $%s" % p[ICLPOS],
199 ]
200 else:
201 appendme = [p[IOCLPOS], p[ICLPOS], p[IPATHPOS], ""]
202 xappendme = [p[IOCLPOS], p[ICLPOS], "$%s" % p[ICLPOS], ""]
181 clsuffix.append(appendme) 203 clsuffix.append(appendme)
182 xclsuffix.append([p[IOCLPOS], p[ICLPOS], "$%s" % p[ICLPOS]]) 204 xclsuffix.append(xappendme)
183 # print('##infile i=%d, appendme=%s' % (i,appendme)) 205 # print('##infile i=%d, appendme=%s' % (i,appendme))
184 for i, p in enumerate(self.outfiles): 206 for i, p in enumerate(self.outfiles):
185 if p[OOCLPOS] == "STDOUT": 207 if p[OOCLPOS] == "STDOUT":
186 self.lastclredirect = [">", p[ONAMEPOS]] 208 self.lastclredirect = [">", p[ONAMEPOS]]
187 self.lastxclredirect = [">", "$%s" % p[OCLPOS]] 209 self.lastxclredirect = [">", "$%s" % p[OCLPOS]]
188 # print('##outfiles i=%d lastclredirect = %s' % (i,self.lastclredirect))
189 else: 210 else:
190 appendme = [p[OOCLPOS], p[OCLPOS], p[ONAMEPOS]] 211 clsuffix.append([p[OOCLPOS], p[OCLPOS], p[ONAMEPOS], ""])
191 clsuffix.append(appendme) 212 xclsuffix.append(
192 xclsuffix.append([p[OOCLPOS], p[OCLPOS], "$%s" % p[ONAMEPOS]]) 213 [p[OOCLPOS], p[OCLPOS], "$%s" % p[ONAMEPOS], ""]
193 # print('##outfiles i=%d' % i,'appendme',appendme) 214 )
194 for p in self.addpar: 215 for p in self.addpar:
195 appendme = [p[AOCLPOS], p[ACLPOS], p[AVALPOS]] 216 clsuffix.append(
196 clsuffix.append(appendme) 217 [p[AOCLPOS], p[ACLPOS], p[AVALPOS], p[AOVERPOS]]
197 xclsuffix.append([p[AOCLPOS], p[ACLPOS], '"$%s"' % p[ANAMEPOS]]) 218 )
198 # print('##adpar %d' % i,'appendme=',appendme) 219 xclsuffix.append(
220 [p[AOCLPOS], p[ACLPOS], '"$%s"' % p[ANAMEPOS], p[AOVERPOS]]
221 )
199 clsuffix.sort() 222 clsuffix.sort()
200 xclsuffix.sort() 223 xclsuffix.sort()
201 self.xclsuffix = xclsuffix 224 self.xclsuffix = xclsuffix
202 self.clsuffix = clsuffix 225 self.clsuffix = clsuffix
203 if self.args.parampass == "positional": 226 if self.args.parampass == "positional":
211 rx = [x.rstrip() for x in rx] 234 rx = [x.rstrip() for x in rx]
212 rxcheck = [x.strip() for x in rx if x.strip() > ""] 235 rxcheck = [x.strip() for x in rx if x.strip() > ""]
213 assert len(rxcheck) > 0, "Supplied script is empty. Cannot run" 236 assert len(rxcheck) > 0, "Supplied script is empty. Cannot run"
214 self.script = "\n".join(rx) 237 self.script = "\n".join(rx)
215 fhandle, self.sfile = tempfile.mkstemp( 238 fhandle, self.sfile = tempfile.mkstemp(
216 prefix=self.tool_name, suffix=".%s" % (self.args.interpreter_name) 239 prefix=self.tool_name, suffix="_%s" % (self.args.interpreter_name)
217 ) 240 )
218 tscript = open(self.sfile, "w") 241 tscript = open(self.sfile, "w")
219 tscript.write(self.script) 242 tscript.write(self.script)
220 tscript.close() 243 tscript.close()
221 self.indentedScript = " %s" % "\n".join([" %s" % html_escape(x) for x in rx]) 244 self.indentedScript = " %s" % "\n".join(
222 self.escapedScript = "%s" % "\n".join([" %s" % html_escape(x) for x in rx]) 245 [" %s" % html_escape(x) for x in rx]
246 )
247 self.escapedScript = "%s" % "\n".join(
248 [" %s" % html_escape(x) for x in rx]
249 )
223 art = "%s.%s" % (self.tool_name, self.args.interpreter_name) 250 art = "%s.%s" % (self.tool_name, self.args.interpreter_name)
224 artifact = open(art, "wb") 251 artifact = open(art, "wb")
225 artifact.write(bytes(self.script, "utf8")) 252 artifact.write(bytes(self.script, "utf8"))
226 artifact.close() 253 artifact.close()
227 aCL(self.args.interpreter_name) 254 aCL(self.args.interpreter_name)
280 aXCL("$%s" % self.outfiles[0][ONAMEPOS]) 307 aXCL("$%s" % self.outfiles[0][ONAMEPOS])
281 308
282 def clpositional(self): 309 def clpositional(self):
283 # inputs in order then params 310 # inputs in order then params
284 aCL = self.cl.append 311 aCL = self.cl.append
285 for (o_v, k, v) in self.clsuffix: 312 for (o_v, k, v, koverride) in self.clsuffix:
286 if " " in v: 313 if " " in v:
287 aCL("%s" % v) 314 aCL("%s" % v)
288 else: 315 else:
289 aCL(v) 316 aCL(v)
290 aXCL = self.xmlcl.append 317 aXCL = self.xmlcl.append
291 for (o_v, k, v) in self.xclsuffix: 318 for (o_v, k, v, koverride) in self.xclsuffix:
292 aXCL(v) 319 aXCL(v)
293 if self.lastxclredirect: 320 if self.lastxclredirect:
294 aXCL(self.lastxclredirect[0]) 321 aXCL(self.lastxclredirect[0])
295 aXCL(self.lastxclredirect[1]) 322 aXCL(self.lastxclredirect[1])
296 323
298 """ argparse style 325 """ argparse style
299 """ 326 """
300 aCL = self.cl.append 327 aCL = self.cl.append
301 aXCL = self.xmlcl.append 328 aXCL = self.xmlcl.append
302 # inputs then params in argparse named form 329 # inputs then params in argparse named form
303 for (o_v, k, v) in self.xclsuffix: 330 for (o_v, k, v, koverride) in self.xclsuffix:
304 if len(k.strip()) == 1: 331 if koverride > "":
332 k = koverride
333 elif len(k.strip()) == 1:
305 k = "-%s" % k 334 k = "-%s" % k
306 else: 335 else:
307 k = "--%s" % k 336 k = "--%s" % k
308 aXCL(k) 337 aXCL(k)
309 aXCL(v) 338 aXCL(v)
310 for (o_v, k, v) in self.clsuffix: 339 for (o_v, k, v, koverride) in self.clsuffix:
311 if len(k.strip()) == 1: 340 if koverride > "":
341 k = koverride
342 elif len(k.strip()) == 1:
312 k = "-%s" % k 343 k = "-%s" % k
313 else: 344 else:
314 k = "--%s" % k 345 k = "--%s" % k
315 aCL(k) 346 aCL(k)
316 aCL(v) 347 aCL(v)
337 aparm.command_line_override = "> $%s" % newcl 368 aparm.command_line_override = "> $%s" % newcl
338 else: 369 else:
339 aparm.positional = int(oldcl) 370 aparm.positional = int(oldcl)
340 aparm.command_line_override = "$%s" % newcl 371 aparm.command_line_override = "$%s" % newcl
341 self.toutputs.append(aparm) 372 self.toutputs.append(aparm)
342 tp = gxtp.TestOutput(name=newcl, value="%s_sample" % newcl, format=newfmt) 373 tp = gxtp.TestOutput(
374 name=newcl, value="%s_sample" % newcl, format=newfmt
375 )
343 self.testparam.append(tp) 376 self.testparam.append(tp)
344 for p in self.infiles: 377 for p in self.infiles:
345 newname = p[ICLPOS] 378 newname = p[ICLPOS]
346 newfmt = p[IFMTPOS] 379 newfmt = p[IFMTPOS]
347 ndash = self.getNdash(newname) 380 ndash = self.getNdash(newname)
361 aninput.positional = self.is_positional 394 aninput.positional = self.is_positional
362 self.tinputs.append(aninput) 395 self.tinputs.append(aninput)
363 tparm = gxtp.TestParam(name=newname, value="%s_sample" % newname) 396 tparm = gxtp.TestParam(name=newname, value="%s_sample" % newname)
364 self.testparam.append(tparm) 397 self.testparam.append(tparm)
365 for p in self.addpar: 398 for p in self.addpar:
366 newname, newval, newlabel, newhelp, newtype, newcl, oldcl = p 399 newname, newval, newlabel, newhelp, newtype, newcl, override, oldcl = p
367 if not len(newlabel) > 0: 400 if not len(newlabel) > 0:
368 newlabel = newname 401 newlabel = newname
369 ndash = self.getNdash(newname) 402 ndash = self.getNdash(newname)
370 if newtype == "text": 403 if newtype == "text":
371 aparm = gxtp.TextParam( 404 aparm = gxtp.TextParam(
432 newfmt = self.outfiles[0][OFMTPOS] 465 newfmt = self.outfiles[0][OFMTPOS]
433 anout = gxtp.OutputData(newname, format=newfmt, num_dashes=0) 466 anout = gxtp.OutputData(newname, format=newfmt, num_dashes=0)
434 anout.command_line_override = "> $%s" % newname 467 anout.command_line_override = "> $%s" % newname
435 anout.positional = self.is_positional 468 anout.positional = self.is_positional
436 self.toutputs.append(anout) 469 self.toutputs.append(anout)
437 tp = gxtp.TestOutput(name=newname, value="%s_sample" % newname, format=newfmt) 470 tp = gxtp.TestOutput(
471 name=newname, value="%s_sample" % newname, format=newfmt
472 )
438 self.testparam.append(tp) 473 self.testparam.append(tp)
439 474
440 def makeXML(self): 475 def makeXML(self):
441 """ 476 """
442 Create a Galaxy xml tool wrapper for the new script 477 Create a Galaxy xml tool wrapper for the new script
443 Uses galaxyhtml 478 Uses galaxyhtml
444 Hmmm. How to get the command line into correct order... 479 Hmmm. How to get the command line into correct order...
445 """ 480 """
446 self.tool.command_line_override = self.xmlcl 481 self.tool.command_line_override = self.xmlcl
447 if self.args.interpreter_name: 482 if self.args.interpreter_name:
448 self.tool.interpreter = self.interp 483 self.tool.interpreter = self.args.interpreter_name
449 if self.args.help_text: 484 if self.args.help_text:
450 helptext = open(self.args.help_text, "r").readlines() 485 helptext = open(self.args.help_text, "r").readlines()
451 helptext = [html_escape(x) for x in helptext] 486 helptext = [html_escape(x) for x in helptext]
452 self.tool.help = "".join([x for x in helptext]) 487 self.tool.help = "".join([x for x in helptext])
453 else: 488 else:
460 requirements = gxtp.Requirements() 495 requirements = gxtp.Requirements()
461 496
462 if self.args.interpreter_name: 497 if self.args.interpreter_name:
463 if self.args.interpreter_name == "python": 498 if self.args.interpreter_name == "python":
464 requirements.append( 499 requirements.append(
465 gxtp.Requirement("package", "python", self.args.interpreter_version) 500 gxtp.Requirement(
501 "package", "python", self.args.interpreter_version
502 )
466 ) 503 )
467 elif self.args.interpreter_name not in ["bash", "sh"]: 504 elif self.args.interpreter_name not in ["bash", "sh"]:
468 requirements.append( 505 requirements.append(
469 gxtp.Requirement( 506 gxtp.Requirement(
470 "package", 507 "package",
474 ) 511 )
475 else: 512 else:
476 if self.args.exe_package and self.args.parampass != "system": 513 if self.args.exe_package and self.args.parampass != "system":
477 requirements.append( 514 requirements.append(
478 gxtp.Requirement( 515 gxtp.Requirement(
479 "package", self.args.exe_package, self.args.exe_package_version 516 "package",
517 self.args.exe_package,
518 self.args.exe_package_version,
480 ) 519 )
481 ) 520 )
482 self.tool.requirements = requirements 521 self.tool.requirements = requirements
483 if self.args.parampass == "0": 522 if self.args.parampass == "0":
484 self.doXMLNoparam() 523 self.doNoXMLparam()
485 else: 524 else:
486 self.doXMLParam() 525 self.doXMLparam()
487 self.tool.outputs = self.toutputs 526 self.tool.outputs = self.toutputs
488 self.tool.inputs = self.tinputs 527 self.tool.inputs = self.tinputs
489 if self.args.runmode not in ["Executable", "system"]: 528 if self.args.runmode not in ["Executable", "system"]:
490 configfiles = gxtp.Configfiles() 529 configfiles = gxtp.Configfiles()
491 configfiles.append(gxtp.Configfile(name="runMe", text=self.script)) 530 configfiles.append(gxtp.Configfile(name="runMe", text=self.script))
503 self.tool.add_comment("Source in git at: %s" % (toolFactoryURL)) 542 self.tool.add_comment("Source in git at: %s" % (toolFactoryURL))
504 self.tool.add_comment( 543 self.tool.add_comment(
505 "Cite: Creating re-usable tools from scripts doi: 10.1093/bioinformatics/bts573" 544 "Cite: Creating re-usable tools from scripts doi: 10.1093/bioinformatics/bts573"
506 ) 545 )
507 exml = self.tool.export() 546 exml = self.tool.export()
508 xf = open(self.xmlfile, "w") 547 xf = open('%s.xml' % self.tool_name, "w")
509 xf.write(exml) 548 xf.write(exml)
510 xf.write("\n") 549 xf.write("\n")
511 xf.close() 550 xf.close()
512 # ready for the tarball 551 # ready for the tarball
513 552
518 NOTE names for test inputs and outputs are munged here so must 557 NOTE names for test inputs and outputs are munged here so must
519 correspond to actual input and output names used on the generated cl 558 correspond to actual input and output names used on the generated cl
520 """ 559 """
521 retval = self.run() 560 retval = self.run()
522 if retval: 561 if retval:
523 sys.stderr.write("## Run failed. Cannot build yet. Please fix and retry") 562 sys.stderr.write(
563 "## Run failed. Cannot build yet. Please fix and retry"
564 )
524 sys.exit(1) 565 sys.exit(1)
525 tdir = "tfout" 566 tdir = "tfout"
526 if not os.path.exists(tdir): 567 if not os.path.exists(tdir):
527 os.mkdir(tdir) 568 os.mkdir(tdir)
528 self.makeXML() 569 self.makeXML()
547 shutil.copyfile(pth, dest) 588 shutil.copyfile(pth, dest)
548 dest = os.path.join(tdir, p[OCLPOS]) 589 dest = os.path.join(tdir, p[OCLPOS])
549 shutil.copyfile(pth, dest) 590 shutil.copyfile(pth, dest)
550 591
551 if os.path.exists(self.tlog) and os.stat(self.tlog).st_size > 0: 592 if os.path.exists(self.tlog) and os.stat(self.tlog).st_size > 0:
552 shutil.copyfile(self.tlog, os.path.join(testdir, "test1_log.txt")) 593 shutil.copyfile(self.tlog, os.path.join(testdir, "test1_log_outfiletxt"))
553 if self.args.runmode not in ["Executable", "system"]: 594 if self.args.runmode not in ["Executable", "system"]:
554 stname = os.path.join(tdir, "%s" % (self.sfile)) 595 stname = os.path.join(tdir, "%s" % (self.sfile))
555 if not os.path.exists(stname): 596 if not os.path.exists(stname):
556 shutil.copyfile(self.sfile, stname) 597 shutil.copyfile(self.sfile, stname)
557 xtname = os.path.join(tdir, self.xmlfile) 598 xreal = '%s.xml' % self.tool_name
558 if not os.path.exists(xtname): 599 xout = os.path.join(tdir,xreal)
559 shutil.copyfile(self.xmlfile, xtname) 600 shutil.copyfile(xreal, xout)
560 tarpath = "toolfactory_%s.tgz" % self.tool_name 601 tarpath = "toolfactory_%s.tgz" % self.tool_name
561 tf = tarfile.open(tarpath, "w:gz") 602 tf = tarfile.open(tarpath, "w:gz")
562 tf.add(name=tdir, arcname=self.tool_name) 603 tf.add(name=tdir, arcname=self.tool_name)
563 tf.close() 604 tf.close()
564 shutil.copyfile(tarpath, self.args.new_tool) 605 shutil.copyfile(tarpath, self.args.new_tool)
606 shutil.copyfile(xreal,"tool_xml.txt")
607 repdir = "TF_run_report_tempdir"
608 if not os.path.exists(repdir):
609 os.mkdir(repdir)
610 repoutnames = [x[OCLPOS] for x in self.outfiles]
611 with os.scandir('.') as outs:
612 for entry in outs:
613 if entry.name.endswith('.tgz') or not entry.is_file():
614 continue
615 if entry.name in repoutnames:
616 shutil.copyfile(entry.name,os.path.join(repdir,entry.name))
617 elif entry.name == "%s.xml" % self.tool_name:
618 shutil.copyfile(entry.name,os.path.join(repdir,"new_tool_xml"))
565 return retval 619 return retval
566 620
567 def run(self): 621 def run(self):
568 """ 622 """
569 Some devteam tools have this defensive stderr read so I'm keeping with the faith 623 Some devteam tools have this defensive stderr read so I'm keeping with the faith
575 scl = " ".join(self.cl) 629 scl = " ".join(self.cl)
576 err = None 630 err = None
577 if self.args.parampass != "0": 631 if self.args.parampass != "0":
578 ste = open(self.elog, "wb") 632 ste = open(self.elog, "wb")
579 if self.lastclredirect: 633 if self.lastclredirect:
580 sto = open(self.lastclredirect[1], "wb") # is name of an output file 634 sto = open(
635 self.lastclredirect[1], "wb"
636 ) # is name of an output file
581 else: 637 else:
582 sto = open(self.tlog, "wb") 638 sto = open(self.tlog, "wb")
583 sto.write( 639 sto.write(
584 bytes( 640 bytes(
585 "## Executing Toolfactory generated command line = %s\n" % scl, 641 "## Executing Toolfactory generated command line = %s\n"
642 % scl,
586 "utf8", 643 "utf8",
587 ) 644 )
588 ) 645 )
589 sto.flush() 646 sto.flush()
590 p = subprocess.run(self.cl, shell=False, stdout=sto, stderr=ste) 647 p = subprocess.run(self.cl, shell=False, stdout=sto, stderr=ste)
652 args = parser.parse_args() 709 args = parser.parse_args()
653 assert not args.bad_user, ( 710 assert not args.bad_user, (
654 'UNAUTHORISED: %s is NOT authorized to use this tool until Galaxy admin adds %s to "admin_users" in the Galaxy configuration file' 711 'UNAUTHORISED: %s is NOT authorized to use this tool until Galaxy admin adds %s to "admin_users" in the Galaxy configuration file'
655 % (args.bad_user, args.bad_user) 712 % (args.bad_user, args.bad_user)
656 ) 713 )
657 assert args.tool_name, "## Tool Factory expects a tool name - eg --tool_name=DESeq" 714 assert (
715 args.tool_name
716 ), "## Tool Factory expects a tool name - eg --tool_name=DESeq"
658 assert ( 717 assert (
659 args.interpreter_name or args.exe_package 718 args.interpreter_name or args.exe_package
660 ), "## Tool Factory wrapper expects an interpreter or an executable package" 719 ), "## Tool Factory wrapper expects an interpreter or an executable package"
661 assert args.exe_package or ( 720 assert args.exe_package or (
662 len(args.script_path) > 0 and os.path.isfile(args.script_path) 721 len(args.script_path) > 0 and os.path.isfile(args.script_path)
663 ), "## Tool Factory wrapper expects a script path - eg --script_path=foo.R if no executable" 722 ), "## Tool Factory wrapper expects a script path - eg --script_path=foo.R if no executable"
664 args.input_files = [x.replace('"', "").replace("'", "") for x in args.input_files] 723 args.input_files = [
724 x.replace('"', "").replace("'", "") for x in args.input_files
725 ]
665 # remove quotes we need to deal with spaces in CL params 726 # remove quotes we need to deal with spaces in CL params
666 for i, x in enumerate(args.additional_parameters): 727 for i, x in enumerate(args.additional_parameters):
667 args.additional_parameters[i] = args.additional_parameters[i].replace('"', "") 728 args.additional_parameters[i] = args.additional_parameters[i].replace(
729 '"', ""
730 )
668 r = ScriptRunner(args) 731 r = ScriptRunner(args)
669 if args.make_Tool: 732 if args.make_Tool:
670 retcode = r.makeTooltar() 733 retcode = r.makeTooltar()
671 else: 734 else:
672 retcode = r.run() 735 retcode = r.run()