comparison toolfactory/rgToolFactory2.py @ 62:881bd8c81ac9 draft

Uploaded
author fubar
date Mon, 26 Oct 2020 02:51:54 +0000
parents d21517a36db8
children b3254219d4fb
comparison
equal deleted inserted replaced
61:dc923f16e6ff 62:881bd8c81ac9
1 #!/usr/bin/env python
2 # rgToolFactory.py 1 # rgToolFactory.py
3 # see https://github.com/fubar2/toolfactory 2 # see https://github.com/fubar2/toolfactory
4 # 3 #
5 # copyright ross lazarus (ross stop lazarus at gmail stop com) May 2012 4 # copyright ross lazarus (ross stop lazarus at gmail stop com) May 2012
6 # 5 #
323 322
324 def clsimple(self): 323 def clsimple(self):
325 """ no parameters - uses < and > for i/o 324 """ no parameters - uses < and > for i/o
326 """ 325 """
327 aCL = self.cl.append 326 aCL = self.cl.append
328 aCL("<")
329 aCL(self.infiles[0][IPATHPOS])
330 aCL(">")
331 aCL(self.outfiles[0][OCLPOS])
332 aXCL = self.xmlcl.append 327 aXCL = self.xmlcl.append
333 aXCL("<") 328
334 aXCL("$%s" % self.infiles[0][ICLPOS]) 329 if len(self.infiles) > 0:
335 aXCL(">") 330 aCL("<")
336 aXCL("$%s" % self.outfiles[0][ONAMEPOS]) 331 aCL(self.infiles[0][IPATHPOS])
332 aXCL("<")
333 aXCL("$%s" % self.infiles[0][ICLPOS])
334 if len(self.outfiles) > 0:
335 aCL(">")
336 aCL(self.outfiles[0][OCLPOS])
337 aXCL(">")
338 aXCL("$%s" % self.outfiles[0][ONAMEPOS])
337 339
338 def clpositional(self): 340 def clpositional(self):
339 # inputs in order then params 341 # inputs in order then params
340 aCL = self.cl.append 342 aCL = self.cl.append
341 for (o_v, k, v, koverride) in self.clsuffix: 343 for (o_v, k, v, koverride) in self.clsuffix:
480 self.tparm = gxtp.TestParam(newname, value=newval) 482 self.tparm = gxtp.TestParam(newname, value=newval)
481 self.testparam.append(tparm) 483 self.testparam.append(tparm)
482 484
483 def doNoXMLparam(self): 485 def doNoXMLparam(self):
484 """filter style package - stdin to stdout""" 486 """filter style package - stdin to stdout"""
485 alab = self.infiles[0][ILABPOS] 487 if len(self.infiles) > 0:
486 if len(alab) == 0: 488 alab = self.infiles[0][ILABPOS]
487 alab = self.infiles[0][ICLPOS] 489 if len(alab) == 0:
488 max1s = ( 490 alab = self.infiles[0][ICLPOS]
489 "Maximum one input if parampass is 0 but multiple input files supplied - %s" 491 max1s = (
490 % str(self.infiles) 492 "Maximum one input if parampass is 0 but multiple input files supplied - %s"
491 ) 493 % str(self.infiles)
492 assert len(self.infiles) == 1, max1s 494 )
493 newname = self.infiles[0][ICLPOS] 495 assert len(self.infiles) == 1, max1s
494 aninput = gxtp.DataParam( 496 newname = self.infiles[0][ICLPOS]
495 newname, 497 aninput = gxtp.DataParam(
496 optional=False, 498 newname,
497 label=alab, 499 optional=False,
498 help=self.infiles[0][IHELPOS], 500 label=alab,
499 format=self.infiles[0][IFMTPOS], 501 help=self.infiles[0][IHELPOS],
500 multiple=False, 502 format=self.infiles[0][IFMTPOS],
501 num_dashes=0, 503 multiple=False,
502 ) 504 num_dashes=0,
503 aninput.command_line_override = "< $%s" % newname 505 )
504 aninput.positional = self.is_positional 506 aninput.command_line_override = "< $%s" % newname
505 self.tinputs.append(aninput) 507 aninput.positional = self.is_positional
506 tp = gxtp.TestParam(name=newname, value="%s_sample" % newname) 508 self.tinputs.append(aninput)
507 self.testparam.append(tp) 509 tp = gxtp.TestParam(name=newname, value="%s_sample" % newname)
508 newname = self.outfiles[0][OCLPOS] 510 self.testparam.append(tp)
509 newfmt = self.outfiles[0][OFMTPOS] 511 if len(self.outfiles > 0):
510 anout = gxtp.OutputData(newname, format=newfmt, num_dashes=0) 512 newname = self.outfiles[0][OCLPOS]
511 anout.command_line_override = "> $%s" % newname 513 newfmt = self.outfiles[0][OFMTPOS]
512 anout.positional = self.is_positional 514 anout = gxtp.OutputData(newname, format=newfmt, num_dashes=0)
513 self.toutputs.append(anout) 515 anout.command_line_override = "> $%s" % newname
514 tp = gxtp.TestOutput(name=newname, value="%s_sample" % newname, format=newfmt) 516 anout.positional = self.is_positional
515 self.testparam.append(tp) 517 self.toutputs.append(anout)
518 tp = gxtp.TestOutput(name=newname, value="%s_sample" % newname, format=newfmt)
519 self.testparam.append(tp)
516 520
517 def makeXML(self): 521 def makeXML(self):
518 """ 522 """
519 Create a Galaxy xml tool wrapper for the new script 523 Create a Galaxy xml tool wrapper for the new script
520 Uses galaxyhtml 524 Uses galaxyhtml
527 if self.args.help_text: 531 if self.args.help_text:
528 helptext = open(self.args.help_text, "r").readlines() 532 helptext = open(self.args.help_text, "r").readlines()
529 safertext = [html_escape(x) for x in helptext] 533 safertext = [html_escape(x) for x in helptext]
530 if self.args.script_path: 534 if self.args.script_path:
531 scrpt = self.script.split('\n') 535 scrpt = self.script.split('\n')
532 scrpt.append("```\n") 536 scrpt.insert(0,"```\n")
533 if len(scrpt) > 300: 537 if len(scrpt) > 300:
534 safertext = safertext + scrpt[:100] + ['>500 lines - stuff deleted','......'] + scrpt[-100:] 538 safertext = safertext + scrpt[:100] + ['>500 lines - stuff deleted','......'] + scrpt[-100:]
535 else: 539 else:
536 safertext = safertext + scrpt 540 safertext = safertext + scrpt
537 safertext.append("\n```") 541 safertext.append("\n```")
538 self.newtool.help = "".join([x for x in safertext]) 542 self.newtool.help = "\n".join([x for x in safertext])
539 else: 543 else:
540 self.newtool.help = ( 544 self.newtool.help = (
541 "Please ask the tool author (%s) for help \ 545 "Please ask the tool author (%s) for help \
542 as none was supplied at tool generation\n" 546 as none was supplied at tool generation\n"
543 % (self.args.user_email) 547 % (self.args.user_email)
625 p = subprocess.run(self.cl, shell=False, stdout=sto, stderr=ste) 629 p = subprocess.run(self.cl, shell=False, stdout=sto, stderr=ste)
626 sto.close() 630 sto.close()
627 ste.close() 631 ste.close()
628 retval = p.returncode 632 retval = p.returncode
629 else: # work around special case - stdin and write to stdout 633 else: # work around special case - stdin and write to stdout
630 sti = open(self.infiles[0][IPATHPOS], "rb") 634 if len(self.infiles) > 0:
631 sto = open(self.outfiles[0][ONAMEPOS], "wb") 635 sti = open(self.infiles[0][IPATHPOS], "rb")
636 else:
637 sti = sys.stdin
638 if len(self.outfiles) > 0:
639 sto = open(self.outfiles[0][ONAMEPOS], "wb")
640 else:
641 sto = sys.stdout
632 p = subprocess.run(self.cl, shell=False, stdout=sto, stdin=sti) 642 p = subprocess.run(self.cl, shell=False, stdout=sto, stdin=sti)
633 retval = p.returncode 643 retval = p.returncode
634 sto.close() 644 sto.close()
635 sti.close() 645 sti.close()
636 if os.path.isfile(self.tlog) and os.stat(self.tlog).st_size == 0: 646 if os.path.isfile(self.tlog) and os.stat(self.tlog).st_size == 0:
693 tout = open(self.tlog, "w") 703 tout = open(self.tlog, "w")
694 if genoutputs: 704 if genoutputs:
695 cll = [ 705 cll = [
696 "planemo", 706 "planemo",
697 "test", 707 "test",
698 "--skip_venv",
699 "--galaxy_root", 708 "--galaxy_root",
700 self.args.galaxy_root, 709 self.args.galaxy_root,
701 "--update_test_data", 710 "--update_test_data",
702 xreal, 711 xreal,
703 ] 712 ]
704 else: 713 else:
705 cll = ["planemo", "test", "--galaxy_root", 714 cll = ["planemo", "test", "--galaxy_root",
706 self.args.galaxy_root, "--skip_venv", 715 self.args.galaxy_root,
707 xreal,] 716 xreal,]
708 p = subprocess.run( 717 p = subprocess.run(
709 cll, shell=False, cwd=self.tooloutdir, stderr=tout, stdout=tout 718 cll, shell=False, cwd=self.tooloutdir, stderr=tout, stdout=tout
710 ) 719 )
711 if genoutputs: 720 if genoutputs: