Commit e751b9a6 authored by Jerome Mariette's avatar Jerome Mariette
Browse files

split all add_* functions to have a clearer api

parent eb5a0de6
......@@ -66,14 +66,27 @@ class Component(object):
outputs[os.path.basename(attribute_value)] = self._webify_workflow_outputs(web_path, attribute_value)
return outputs
def add_input_file(self, name, help, file_format="any", default=None, type="inputfile", required=False,
flag=None, group="default", display_name=None, is_list=False, add_to=None):
if is_list:
if default == None: default = []
new_param = InputFileList(name, help, flag=flag, file_format=file_format, default=default,
type=type, required=required, group=group, display_name=display_name)
def add_input_file(self, name, help, file_format="any", default=None, type="inputfile",
required=False, flag=None, group="default", display_name=None, add_to=None):
new_param = InputFile(name, help, flag=flag, file_format=file_format, default=default,
type=type, required=required, group=group, display_name=display_name)
# if this input should be added to a particular parameter
if add_to:
try:
self.__getattribute__(add_to).add_sub_parameter(new_param)
except: pass
# otherwise, add it to the class itself
else:
new_param = InputFile(name, help, flag=flag, file_format=file_format, default=default,
new_param.component_nameid = self.get_nameid()
if default.__class__.__name__ == "OutputFileList" or default.__class__.__name__ == "OutputFile":
new_param.parent_component_nameid = default.component_nameid
self.params_order.append(name)
self.__setattr__(name, new_param)
def add_input_file_list(self, name, help, file_format="any", default=None, type="inputfile",
required=False, flag=None, group="default", display_name=None, add_to=None):
if default == None: default = []
new_param = InputFileList(name, help, flag=flag, file_format=file_format, default=default,
type=type, required=required, group=group, display_name=display_name)
# if this input should be added to a particular parameter
if add_to:
......@@ -88,14 +101,24 @@ class Component(object):
self.params_order.append(name)
self.__setattr__(name, new_param)
def add_parameter(self, name, help, default=None, type=types.StringType, choices=None, required=False,
flag=None, group="default", display_name=None, is_list=False, add_to=None):
if is_list:
if default == None: default = []
new_param = ParameterList(name, help, flag=flag, default=default, type=type, choices=choices,
required=required, group=group, display_name=display_name)
def add_parameter(self, name, help, default=None, type=types.StringType, choices=None,
required=False, flag=None, group="default", display_name=None, add_to=None):
new_param = Parameter(name, help, flag=flag, default=default, type=type, choices=choices,
required=required, group=group, display_name=display_name)
# if this input should be added to a particular parameter
if add_to:
try:
self.__getattribute__(add_to).add_sub_parameter(new_param)
except: pass
# otherwise, add it to the class itself
else:
new_param = Parameter(name, help, flag=flag, default=default, type=type, choices=choices,
self.params_order.append(name)
self.__setattr__(name, new_param)
def add_parameter_list(self, name, help, default=None, type=types.StringType, choices=None,
required=False, flag=None, group="default", display_name=None, add_to=None):
if default == None: default = []
new_param = ParameterList(name, help, flag=flag, default=default, type=type, choices=choices,
required=required, group=group, display_name=display_name)
# if this input should be added to a particular parameter
if add_to:
......@@ -107,13 +130,24 @@ class Component(object):
self.params_order.append(name)
self.__setattr__(name, new_param)
def add_output_file(self, name, help, file_format="any", pattern='{basename_woext}.out',
basename=None, group="default", display_name=None, is_list=False, add_to=None):
if is_list:
new_param = OutputFileList(name, help, default=self.get_outputs(pattern, basename),
file_format=file_format, group=group, display_name=display_name)
def add_output_file(self, name, help, file_format="any", filename=None, group="default", display_name=None, add_to=None):
filename = os.path.basename(filename)
new_param = OutputFile(name, help, default=os.path.join(self.output_directory, filename),
file_format=file_format, group=group, display_name=display_name)
# if this input should be added to a particular parameter
if add_to:
try:
self.__getattribute__(add_to).add_sub_parameter(new_param)
except: pass
# otherwise, add it to the class itself
else:
new_param = OutputFile(name, help, default=os.path.join(self.output_directory, basename),
new_param.component_nameid = self.get_nameid()
self.params_order.append(name)
self.__setattr__(name, new_param)
def add_output_file_list(self, name, help, file_format="any", pattern='{basename_woext}.out',
items=None, group="default", display_name=None, add_to=None):
new_param = OutputFileList(name, help, default=self.get_outputs(pattern, items),
file_format=file_format, group=group, display_name=display_name)
# if this input should be added to a particular parameter
if add_to:
......@@ -125,7 +159,7 @@ class Component(object):
new_param.component_nameid = self.get_nameid()
self.params_order.append(name)
self.__setattr__(name, new_param)
def _webify_workflow_outputs(self, web_path, path):
work_dir = self.config_reader.get_work_directory()
socket_opt = self.config_reader.get_socket_options()
......
......@@ -104,7 +104,7 @@ class Workflow(threading.Thread):
self.params_order = []
self.define_parameters(self.function)
# add the metadata parameter
self.add_parameter("metadata", "Which metadata should be linked to this workflow", is_list=True)
self.add_parameter_list("metadata", "Which metadata should be linked to this workflow")
# if some args are provided, let's fill the parameters
if args: self._set_parameters(args)
......@@ -116,14 +116,24 @@ class Workflow(threading.Thread):
self.set_stderr()
self._serialize()
def add_input_file(self, name, help, file_format="any", default=None, type="inputfile", required=False,
flag=None, group="default", display_name=None, is_list=False, add_to=None):
if is_list:
if default == None: default = []
new_param = InputFileList(name, help, flag=flag, file_format=file_format, default=default,
type=type, required=required, group=group, display_name=display_name)
def add_input_file(self, name, help, file_format="any", default=None, type="inputfile",
required=False, flag=None, group="default", display_name=None, add_to=None):
new_param = InputFile(name, help, flag=flag, file_format=file_format, default=default,
type=type, required=required, group=group, display_name=display_name)
# if this input should be added to a particular parameter
if add_to:
try:
self.__getattribute__(add_to).add_sub_parameter(new_param)
except: pass
# otherwise, add it to the class itself
else:
new_param = InputFile(name, help, flag=flag, file_format=file_format, default=default,
self.params_order.append(name)
self.__setattr__(name, new_param)
def add_input_file_list(self, name, help, file_format="any", default=None, type="inputfile",
required=False, flag=None, group="default", display_name=None, add_to=None):
if default == None: default = []
new_param = InputFileList(name, help, flag=flag, file_format=file_format, default=default,
type=type, required=required, group=group, display_name=display_name)
# if this input should be added to a particular parameter
if add_to:
......@@ -134,23 +144,35 @@ class Workflow(threading.Thread):
else:
self.params_order.append(name)
self.__setattr__(name, new_param)
def add_multiple_parameter(self, name, help, required=False, flag=None, group="default", display_name=None, is_list=False):
def add_multiple_parameter(self, name, help, required=False, flag=None, group="default", display_name=None):
self.params_order.append(name)
if is_list:
new_param = MultiParameterList(name, help, flag=flag, required=required, group=group, display_name=display_name)
else:
new_param = MultiParameter(name, help, flag=flag, required=required, group=group, display_name=display_name)
new_param = MultiParameter(name, help, flag=flag, required=required, group=group, display_name=display_name)
self.__setattr__(name, new_param)
def add_multiple_parameter_list(self, name, help, required=False, flag=None, group="default", display_name=None):
self.params_order.append(name)
new_param = MultiParameterList(name, help, flag=flag, required=required, group=group, display_name=display_name)
self.__setattr__(name, new_param)
def add_parameter(self, name, help, default=None, type=types.StringType, choices=None, required=False,
flag=None, group="default", display_name=None, is_list=False, add_to=None):
if is_list:
if default == None: default = []
new_param = ParameterList(name, help, flag=flag, default=default, type=type, choices=choices,
required=required, group=group, display_name=display_name)
def add_parameter(self, name, help, default=None, type=types.StringType, choices=None,
required=False, flag=None, group="default", display_name=None, add_to=None):
new_param = Parameter(name, help, flag=flag, default=default, type=type, choices=choices,
required=required, group=group, display_name=display_name)
# if this input should be added to a particular parameter
if add_to:
try:
self.__getattribute__(add_to).add_sub_parameter(new_param)
except: pass
# otherwise, add it to the class itself
else:
new_param = Parameter(name, help, flag=flag, default=default, type=type, choices=choices,
self.params_order.append(name)
self.__setattr__(name, new_param)
def add_parameter_list(self, name, help, default=None, type=types.StringType, choices=None,
required=False, flag=None, group="default", display_name=None, add_to=None):
if default == None: default = []
new_param = ParameterList(name, help, flag=flag, default=default, type=type, choices=choices,
required=required, group=group, display_name=display_name)
# if this input should be added to a particular parameter
if add_to:
......
......@@ -24,9 +24,9 @@ class Alignment (Workflow):
return "Align reads against a reference genome"
def define_parameters(self, function="process"):
self.add_input_file("read_1", "Which read1 files should be used", required=True, is_list=True)
self.add_input_file("read_2", "Which read2 files should be used (if single end, leave empty)", type="localfile", is_list=True)
self.add_input_file("reference_genome", "Which genome should the read being align on", required=True, type="localfile")
self.add_input_file_list("read_1", "Which read1 files should be used", required=True)
self.add_input_file_list("read_2", "Which read2 files should be used (if single end, leave empty)")
self.add_input_file("reference_genome", "Which genome should the read being align on", required=True)
def process(self):
# index the reference genome
......
......@@ -30,23 +30,23 @@ class BWA (Component):
def define_parameters(self, reference_genome, read1, read2=None, algorithm="aln"):
self.add_input_file("reference_genome", "Which reference file should be used", default=reference_genome, required=True)
self.add_input_file("read1", "Which read1 files should be used", file_format=Formats.FASTQ, default=read1, required=True, is_list=True)
self.add_input_file("read2", "Which read2 files should be used", file_format=Formats.FASTQ, default=read2, is_list=True)
self.add_input_file_list("read1", "Which read1 files should be used", file_format=Formats.FASTQ, default=read1, required=True)
self.add_input_file_list("read2", "Which read2 files should be used", file_format=Formats.FASTQ, default=read2)
self.add_parameter("algorithm", "Which algorithm should be used to align the reads", default=algorithm, choices=["aln", "bwasw"])
if algorithm == "aln":
self.add_output_file("sai1", "The BWA sai1 file", pattern='{basename_woext}.sai', basename=self.read1, is_list=True)
self.add_output_file_list("sai1", "The BWA sai1 file", pattern='{basename_woext}.sai', items=self.read1)
else:
self.sai1 = None
if read2:
if algorithm == "aln":
self.add_output_file("sai2", "The BWA sai2 file", pattern='{basename_woext}.sai', basename=self.read2, is_list=True)
self.add_output_file_list("sai2", "The BWA sai2 file", pattern='{basename_woext}.sai', items=self.read2)
else:
self.sai2 = None
self.add_output_file("bam_files", "The BWA bam file", pattern='{basename_woext}.bam', basename=[self.read1, self.read2], file_format=Formats.BAM, is_list=True)
self.add_output_file_list("bam_files", "The BWA bam file", pattern='{basename_woext}.bam', items=[self.read1, self.read2], file_format=Formats.BAM)
else:
self.sai2 = None
self.add_output_file("bam_files", "The BWA bam file", pattern='{basename_woext}.bam', basename=self.read1, file_format=Formats.BAM, is_list=True)
self.add_output_file("stderr", "The BWA stderr file", basename='bwa.stderr')
self.add_output_file_list("bam_files", "The BWA bam file", pattern='{basename_woext}.bam', items=self.read1, file_format=Formats.BAM)
self.add_output_file("stderr", "The BWA stderr file", filename='bwa.stderr')
def process(self):
if self.algorithm=="bwasw":
......
......@@ -45,9 +45,9 @@ class BWAIndex (Component):
def define_parameters(self, input_fasta, algorithm="bwtsw"):
self.add_input_file("input_fasta", "Which fasta file should be indexed", file_format=Formats.FASTA, default=input_fasta, required=True)
self.add_parameter("algorithm", "Which algorithm should be used to index the fasta file", default=algorithm, choices=["bwtsw", "div", "is"])
self.add_output_file("databank", "The indexed databank to use with BWA", basename=os.path.basename(input_fasta))
self.add_output_file("stdout", "The BWAIndex stdout file", basename="bwaindex.stdout")
self.add_output_file("stderr", "The BWAIndex stderr file", basename="bwaindex.stderr")
self.add_output_file("databank", "The indexed databank to use with BWA", filename=os.path.basename(input_fasta))
self.add_output_file("stdout", "The BWAIndex stdout file", filename="bwaindex.stdout")
self.add_output_file("stderr", "The BWAIndex stderr file", filename="bwaindex.stderr")
def process(self):
bwaindex = PythonFunction(bwa_index, cmd_format="{EXE} {ARG} {IN} {OUT}")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment