def doNoXMLparam(self): """filter style package - stdin to stdout""" if len(self.infiles) > 0: alab = self.infiles[0]["label"] if len(alab) == 0: alab = self.infiles[0]["infilename"] max1s = ( "Maximum one input if parampass is 0 but multiple input files supplied - %s" % str(self.infiles)) assert len(self.infiles) == 1, max1s newname = self.infiles[0]["infilename"] aninput = gxtp.DataParam( newname, optional=False, label=alab, help=self.infiles[0]["help"], format=self.infiles[0]["format"], multiple=False, num_dashes=0, ) aninput.command_line_override = "< $%s" % newname aninput.positional = True self.tinputs.append(aninput) tp = gxtp.TestParam(name=newname, value="%s_sample" % newname) self.testparam.append(tp) if len(self.outfiles) > 0: newname = self.outfiles[0]["name"] newfmt = self.outfiles[0]["format"] anout = gxtp.OutputData(newname, format=newfmt, num_dashes=0) anout.command_line_override = "> $%s" % newname anout.positional = self.is_positional self.toutputs.append(anout) tp = gxtp.TestOutput(name=newname, value="%s_sample" % newname) self.testparam.append(tp)
def add_input_file(self, input_obj): """ Add an input to the tool (XML: <inputs>). :param input_obj: Input object. :type input_obj: :class:`tooldog.biotool_model.Input` """ LOGGER.debug("Adding input to GalaxyToolGen object...") if not hasattr(self.tool, 'inputs'): self.tool.inputs = gxtp.Inputs() # Build parameter self.input_ct += 1 data_uri = input_obj.data_type.get_edam_id() # Give unique name to the input name = 'INPUT' + str(self.input_ct) # Get all different format for this input list_formats = [] if not input_obj.formats: list_formats.append(self.etog.get_datatype(edam_data=data_uri)) else: for format_obj in input_obj.formats: format_uri = format_obj.get_edam_id() list_formats.append( self.etog.get_datatype(edam_data=data_uri, edam_format=format_uri)) formats = ', '.join(list_formats) # Create the parameter param = gxtp.DataParam(name, label=input_obj.data_type.term, help=input_obj.description, format=formats) # Override the corresponding arguments in the command line param.command_line_override = '--' + name + ' $' + name # Write comment about this param param.node.insert(0, etree.Comment(FIXME)) param.node.insert(0, etree.Comment(PARAM_COMMENT % (self.biotool_id))) # Appends parameter to inputs self.tool.inputs.append(param)
def __gxtp_param_from_type(self, param, flag, label, num_dashes, gxparam_extra_kwargs, default=None): from argparse import FileType """Based on a type, convert to appropriate gxtp class """ if default is None and (param.type in (int, float)): default = 0 if param.choices is not None: choices = {k: k for k in param.choices} gxparam = gxtp.SelectParam(flag, default=default, label=label, num_dashes=num_dashes, options=choices, **gxparam_extra_kwargs) elif param.type == int: gxparam = gxtp.IntegerParam(flag, default, label=label, num_dashes=num_dashes, **gxparam_extra_kwargs) elif param.type == float: gxparam = gxtp.FloatParam(flag, default, label=label, num_dashes=num_dashes, **gxparam_extra_kwargs) elif param.type is None or param.type == str: gxparam = gxtp.TextParam(flag, default=default, label=label, num_dashes=num_dashes, **gxparam_extra_kwargs) elif param.type == locate('file'): gxparam = gxtp.DataParam(flag, label=label, num_dashes=num_dashes, **gxparam_extra_kwargs) elif isinstance(param.type, FileType): if 'w' in param.type._mode: gxparam = gxtp.OutputParameter(flag, format='data', default=default, label=label, num_dashes=num_dashes, **gxparam_extra_kwargs) else: gxparam = gxtp.DataParam(flag, default=default, label=label, num_dashes=num_dashes, **gxparam_extra_kwargs) else: gxparam = None return gxparam
def doXMLparam(self): # noqa """Add all needed elements to tool""" for p in self.outfiles: newname = p["name"] newfmt = p["format"] newcl = p["CL"] test = p["test"] oldcl = p["origCL"] test = test.strip() ndash = self.getNdash(newcl) aparm = gxtp.OutputData(name=newname, format=newfmt, num_dashes=ndash, label=newname) aparm.positional = self.is_positional if self.is_positional: if oldcl.upper() == "STDOUT": aparm.positional = 9999999 aparm.command_line_override = "> $%s" % newname else: aparm.positional = int(oldcl) aparm.command_line_override = "$%s" % newname self.toutputs.append(aparm) ld = None if test.strip() > "": if test.startswith("diff"): c = "diff" ld = 0 if test.split(":")[1].isdigit: ld = int(test.split(":")[1]) tp = gxtp.TestOutput( name=newname, value="%s_sample" % newname, compare=c, lines_diff=ld, ) elif test.startswith("sim_size"): c = "sim_size" tn = test.split(":")[1].strip() if tn > "": if "." in tn: delta = None delta_frac = min(1.0, float(tn)) else: delta = int(tn) delta_frac = None tp = gxtp.TestOutput( name=newname, value="%s_sample" % newname, compare=c, delta=delta, delta_frac=delta_frac, ) else: c = test tp = gxtp.TestOutput( name=newname, value="%s_sample" % newname, compare=c, ) self.testparam.append(tp) for p in self.infiles: newname = p["infilename"] newfmt = p["format"] ndash = self.getNdash(newname) reps = p.get("repeat", "0") == "1" if not len(p["label"]) > 0: alab = p["CL"] else: alab = p["label"] aninput = gxtp.DataParam( newname, optional=False, label=alab, help=p["help"], format=newfmt, multiple=False, num_dashes=ndash, ) aninput.positional = self.is_positional if self.is_positional: if p["origCL"].upper() == "STDIN": aninput.positional = 9999998 aninput.command_line_override = "> $%s" % newname else: aninput.positional = int(p["origCL"]) aninput.command_line_override = "$%s" % newname if reps: repe = gxtp.Repeat(name=f"R_{newname}", title=f"Add as many {alab} as needed") repe.append(aninput) self.tinputs.append(repe) tparm = gxtp.TestRepeat(name=f"R_{newname}") tparm2 = gxtp.TestParam(newname, value="%s_sample" % newname) tparm.append(tparm2) self.testparam.append(tparm) else: self.tinputs.append(aninput) tparm = gxtp.TestParam(newname, value="%s_sample" % newname) self.testparam.append(tparm) for p in self.addpar: newname = p["name"] newval = p["value"] newlabel = p["label"] newhelp = p["help"] newtype = p["type"] newcl = p["CL"] oldcl = p["origCL"] reps = p["repeat"] == "1" if not len(newlabel) > 0: newlabel = newname ndash = self.getNdash(newname) if newtype == "text": aparm = gxtp.TextParam( newname, label=newlabel, help=newhelp, value=newval, num_dashes=ndash, ) elif newtype == "integer": aparm = gxtp.IntegerParam( newname, label=newlabel, help=newhelp, value=newval, num_dashes=ndash, ) elif newtype == "float": aparm = gxtp.FloatParam( newname, label=newlabel, help=newhelp, value=newval, num_dashes=ndash, ) elif newtype == "boolean": aparm = gxtp.BooleanParam( newname, label=newlabel, help=newhelp, value=newval, num_dashes=ndash, ) else: raise ValueError('Unrecognised parameter type "%s" for\ additional parameter %s in makeXML' % (newtype, newname)) aparm.positional = self.is_positional if self.is_positional: aparm.positional = int(oldcl) if reps: repe = gxtp.Repeat(name=f"R_{newname}", title=f"Add as many {newlabel} as needed") repe.append(aparm) self.tinputs.append(repe) tparm = gxtp.TestRepeat(name=f"R_{newname}") tparm2 = gxtp.TestParam(newname, value=newval) tparm.append(tparm2) self.testparam.append(tparm) else: self.tinputs.append(aparm) tparm = gxtp.TestParam(newname, value=newval) self.testparam.append(tparm) for p in self.selpar: newname = p["name"] newval = p["value"] newlabel = p["label"] newhelp = p["help"] newtype = p["type"] newcl = p["CL"] if not len(newlabel) > 0: newlabel = newname ndash = self.getNdash(newname) if newtype == "selecttext": newtext = p["texts"] aparm = gxtp.SelectParam( newname, label=newlabel, help=newhelp, num_dashes=ndash, ) for i in range(len(newval)): anopt = gxtp.SelectOption( value=newval[i], text=newtext[i], ) aparm.append(anopt) aparm.positional = self.is_positional if self.is_positional: aparm.positional = int(newcl) self.tinputs.append(aparm) tparm = gxtp.TestParam(newname, value=newval) self.testparam.append(tparm) else: raise ValueError('Unrecognised parameter type "%s" for\ selecttext parameter %s in makeXML' % (newtype, newname)) for p in self.collections: newkind = p["kind"] newname = p["name"] newlabel = p["label"] newdisc = p["discover"] collect = gxtp.OutputCollection(newname, label=newlabel, type=newkind) disc = gxtp.DiscoverDatasets(pattern=newdisc, directory=f"{newname}", visible="false") collect.append(disc) self.toutputs.append(collect) try: tparm = gxtp.TestOutputCollection( newname) # broken until PR merged. self.testparam.append(tparm) except Exception: print( "#### WARNING: Galaxyxml version does not have the PR merged yet - tests for collections must be over-ridden until then!" )
def doXMLparam(self): """flake8 made me do this...""" for p in self.outfiles: newname = p["name"] newfmt = p["format"] newcl = p["CL"] test = p["test"] oldcl = p["origCL"] test = test.strip() ndash = self.getNdash(newcl) aparm = gxtp.OutputData(name=newname, format=newfmt, num_dashes=ndash, label=newname) aparm.positional = self.is_positional if self.is_positional: if oldcl.upper() == "STDOUT": aparm.positional = 9999999 aparm.command_line_override = "> $%s" % newname else: aparm.positional = int(oldcl) aparm.command_line_override = "$%s" % newname self.toutputs.append(aparm) ld = None if test.strip() > "": if test.startswith("diff"): c = "diff" ld = 0 if test.split(":")[1].isdigit: ld = int(test.split(":")[1]) tp = gxtp.TestOutput( name=newname, value="%s_sample" % newname, compare=c, lines_diff=ld, ) elif test.startswith("sim_size"): c = "sim_size" tn = test.split(":")[1].strip() if tn > "": if "." in tn: delta = None delta_frac = min(1.0, float(tn)) else: delta = int(tn) delta_frac = None tp = gxtp.TestOutput( name=newname, value="%s_sample" % newname, compare=c, delta=delta, delta_frac=delta_frac, ) else: c = test tp = gxtp.TestOutput( name=newname, value="%s_sample" % newname, compare=c, ) self.testparam.append(tp) for p in self.infiles: newname = p["infilename"] newfmt = p["format"] ndash = self.getNdash(newname) if not len(p["label"]) > 0: alab = p["CL"] else: alab = p["label"] aninput = gxtp.DataParam( newname, optional=False, label=alab, help=p["help"], format=newfmt, multiple=False, num_dashes=ndash, ) aninput.positional = self.is_positional if self.is_positional: if p["origCL"].upper() == "STDIN": aparm.positional = 9999998 aparm.command_line_override = "> $%s" % newname else: aparm.positional = int(p["origCL"]) aparm.command_line_override = "$%s" % newname self.tinputs.append(aninput) tparm = gxtp.TestParam(name=newname, value="%s_sample" % newname) self.testparam.append(tparm) for p in self.addpar: newname = p["name"] newval = p["value"] newlabel = p["label"] newhelp = p["help"] newtype = p["type"] newcl = p["CL"] oldcl = p["origCL"] if not len(newlabel) > 0: newlabel = newname ndash = self.getNdash(newname) if newtype == "text": aparm = gxtp.TextParam( newname, label=newlabel, help=newhelp, value=newval, num_dashes=ndash, ) elif newtype == "integer": aparm = gxtp.IntegerParam( newname, label=newname, help=newhelp, value=newval, num_dashes=ndash, ) elif newtype == "float": aparm = gxtp.FloatParam( newname, label=newname, help=newhelp, value=newval, num_dashes=ndash, ) elif newtype == "boolean": aparm = gxtp.BooleanParam( newname, label=newname, help=newhelp, value=newval, num_dashes=ndash, ) else: raise ValueError('Unrecognised parameter type "%s" for\ additional parameter %s in makeXML' % (newtype, newname)) aparm.positional = self.is_positional if self.is_positional: aparm.positional = int(oldcl) self.tinputs.append(aparm) tparm = gxtp.TestParam(newname, value=newval) self.testparam.append(tparm) for p in self.selpar: newname = p["name"] newval = p["value"] newlabel = p["label"] newhelp = p["help"] newtype = p["type"] newcl = p["CL"] if not len(newlabel) > 0: newlabel = newname ndash = self.getNdash(newname) if newtype == "selecttext": newtext = p["texts"] aparm = gxtp.SelectParam( newname, label=newlabel, help=newhelp, num_dashes=ndash, ) for i in range(len(newval)): anopt = gxtp.SelectOption( value=newval[i], text=newtext[i], ) aparm.append(anopt) aparm.positional = self.is_positional if self.is_positional: aparm.positional = int(newcl) self.tinputs.append(aparm) tparm = gxtp.TestParam(newname, value=newval) self.testparam.append(tparm) else: raise ValueError('Unrecognised parameter type "%s" for\ selecttext parameter %s in makeXML' % (newtype, newname)) for p in self.collections: newkind = p["kind"] newname = p["name"] newlabel = p["label"] newdisc = p["discover"] collect = gxtp.OutputCollection(newname, label=newlabel, type=newkind) disc = gxtp.DiscoverDatasets(pattern=newdisc, directory=f"{newname}", visible="false") collect.append(disc) self.toutputs.append(collect) tparm = gxtp.TestOutput(newname, ftype="pdf") self.testparam.append(tparm)