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

first step to make Parameter looks good

parent 8110b41f
......@@ -154,7 +154,7 @@ class JFlowServer (object):
wf_instances = self.wfmanager.get_available_workflows()
for instance in wf_instances:
parameters, parameters_per_groups, groups = [], {}, ["default"]
for param in instance.parameters:
for param in instance.get_parameters():
# if it's a multiple action change the action by the name
if param.action == jflow.parameter.MiltipleAction:
action = "MiltipleAction"
......
......@@ -168,29 +168,29 @@ class MiltipleAppendAction(argparse.Action):
final_values.append((param, final_hash[param]))
items.append(final_values)
setattr(namespace, self.dest, items)
class Parameter(object):
"""
"""
class AbstractParameter(object):
def __init__(self, name, help, flag, default=None, type=types.StringType, choices=None,
required=False, action="store", sub_parameters=[], group="default", display_name=None):
def __init__(self, name, help, default=None, type=types.StringType, choices=None, required=False,
flag=None, action="store", sub_parameters=None, group="default", display_name=None):
self.name = name
self.flag = flag
self.help = help
self.action = action
self.nargs = None
self.sub_parameters = sub_parameters
if sub_parameters:
self.sub_parameters = sub_parameters
else: self.sub_parameters = []
self.group = group
if display_name == None:
self.display_name = name
if flag == None:
self.flag = "--"+name.replace("_", "-")
else: self.flag = flag
if display_name == None:
self.display_name = name.replace("_", " ").title()
else: self.display_name = display_name
self.required = str(required).lower() in ("yes", "y", "true", "t", "1")
self.choices = choices
if self.choices:
self.choices = choices.split("|")
if len(self.sub_parameters) > 0:
self.nargs = "+"
......@@ -239,7 +239,7 @@ class Parameter(object):
self.default = {}
for param in self.sub_parameters:
self.default[param.name] = param.default
def export_to_argparse(self):
if self.type == types.BooleanType and str(self.default).lower() in ("false", "f", "0"):
return {"help": self.help, "required": self.required, "dest": self.name,
......@@ -259,6 +259,98 @@ class Parameter(object):
def get_type(self):
return self.type.__name__
def __str__(self):
return self.name + ": " + str(self.flag) + " | " + self.help + " (default=" + \
str(self.default) + ", required=" + str(self.required) + ", flag=" + self.flag + ")"
class AbstractFile(object):
def __init__(self, file_format="any"):
self.file_format = file_format
self.parent_component_nameid = None
class MultiParameter(dict, AbstractParameter):
def __init__(self, name, help, required=False, flag=None, group="default", display_name=None):
AbstractParameter.__init__(self, name, help, required=required, flag=flag, group=group, display_name=display_name)
return dict.__init__(self, {})
class MultiParameterList(list, AbstractParameter):
def __init__(self, name, help, required=False, flag=None, group="default", display_name=None):
AbstractParameter.__init__(self, name, help, required=required, flag=flag, group=group, display_name=display_name)
return list.__init__(self, [])
class Parameter(str, AbstractParameter):
def __new__(self, name, help, default="", type=types.StringType, choices=None, required=False,
flag=None, sub_parameters=None, group="default", display_name=None):
return str.__new__(self, default)
def __init__(self, name, help, default="", type=types.StringType, choices=None, required=False,
flag=None, sub_parameters=None, group="default", display_name=None):
AbstractParameter.__init__(self, name, help, flag=flag, type=type, choices=choices, required=required,
action="store", sub_parameters=sub_parameters, group=group, display_name=display_name)
class InputFile(Parameter, AbstractFile):
def __new__(self, name, help, file_format="any", default="", type=types.StringType, choices=None,
required=False, flag=None, group="default", display_name=None):
return str.__new__(self, default)
def __init__(self, name, help, file_format="any", default="", type=types.StringType, choices=None,
required=False, flag=None, group="default", display_name=None):
AbstractFile.__init__(self, file_format)
Parameter.__init__(self, name, help, flag=flag, type=type, choices=choices,
required=required, group=group, display_name=display_name)
class OutputFile(Parameter, AbstractFile):
def __new__(self, name, help, file_format="any", default="", type=types.StringType, choices=None,
required=False, flag=None, group="default", display_name=None):
return str.__new__(self, default)
def __init__(self, name, help, file_format="any", default="", type=types.StringType, choices=None,
required=False, flag=None, group="default", display_name=None):
AbstractFile.__init__(self, file_format)
Parameter.__init__(self, name, help, flag=flag, type=type, choices=choices,
required=required, group=group, display_name=display_name)
class ParameterList(list, AbstractParameter):
def __init__(self, name, help, default=[], type=types.StringType, choices=None, required=False,
flag=None, sub_parameters=None, group="default", display_name=None):
AbstractParameter.__init__(self, name, help, flag=flag, type=type, choices=choices, required=required,
action="append", sub_parameters=sub_parameters, group=group, display_name=display_name)
if default.__class__.__name__ == "str":
return list.__init__(self, [default])
elif default.__class__.__name__ == "list":
return list.__init__(self, default)
class InputFileList(ParameterList, AbstractFile):
def __init__(self, name, help, file_format="any", default=[], type=types.StringType, choices=None,
required=False, flag=None, group="default", display_name=None):
AbstractFile.__init__(self, file_format)
ParameterList.__init__(self, name, help, flag=flag, type=type, choices=choices,
required=required, group=group, display_name=display_name)
if default.__class__.__name__ == "str":
return list.__init__(self, [default])
elif default.__class__.__name__ == "list":
return list.__init__(self, default)
class OutputFileList(ParameterList, AbstractFile):
def __init__(self, name, help, file_format="any", default=[], type=types.StringType,
choices=None, required=False, flag=None, group="default", display_name=None):
AbstractFile.__init__(self, file_format)
ParameterList.__init__(self, name, help, flag=flag, type=type, choices=choices,
required=required, group=group, display_name=display_name)
if default.__class__.__name__ == "str":
return list.__init__(self, [default])
elif default.__class__.__name__ == "list":
return list.__init__(self, default)
This diff is collapsed.
......@@ -16,15 +16,37 @@
#
from jflow.workflow import Workflow
from jflow.parameter import InputFileList, InputFile
class Alignment (Workflow):
def get_name(self):
return "alignment"
def get_description(self):
return "align reads against a reference genome"
def define_parameters(self, parameters_section=None):
self.add_input_file("read_1", "Which read1 files should be used", required=True, type="localfile", 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_multiple_parameter("test", "toto est dnas le gazon")
self.add_input_file("toto", "Whices should be used", required=True, is_list=True, add_to="test")
self.add_input_file("tot", "Whould be used", is_list=True, add_to="test")
# prochaine etape:
# - tester les types multiples
# - Ajouter les types InputFile, InputFileList, OutputFile, OutputFileList
# - trouver une methode pour ordonner les parameters (self.add_parameter ...)
def process(self):
"""
Run the workflow
"""
print ">>>>>>>>>>>>>>>>>>>> ", self.reference_genome
print ">>>>>>>>>>>>>>>>>>>> ", self.read_1
print ">>>>>>>>>>>>>>>>>>>> ", self.read_2
# index the reference genome
bwaindex = self.add_component("BWAIndex", [self.args["reference_genome"]])
#bwaindex = self.add_component("BWAIndex", [self.args["reference_genome"]])
# align reads against indexed genome
bwa = self.add_component("BWA", [bwaindex.databank, self.args["read_1"], self.args["read_2"]])
\ No newline at end of file
#bwa = self.add_component("BWA", [bwaindex.databank, self.args["read_1"], self.args["read_2"]])
\ No newline at end of file
#
# Copyright (C) 2012 INRA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
[global]
name = alignment
description = align reads against a reference genome
#
# Parameter section
# param.name: the parameter display name
# .flag: the command line flag to use the argument
# .help: a brief description of what the parameter does
# .default [None]: the value produced if the parameter is not provided
# .type [str]: the parameter type that should be tested, this can be:
# str|int|date|inputfile|urlfile|localfile|browsefile|bool|... all types
# defined in the types.py package)
# .choices [None]: a container of the allowable values for the parameter
# .required [False]: whether or not the command-line option may be omitted
# .action [store]: the basic type of action to be taken (store|append)
# .group [None]: gathers arguments into groups when displaying help messages / forms
# .exclude [None]: will make sure that there is only one arguments provided
#
[parameters]
read_1.name = Read 1
read_1.flag = --read-1
read_1.help = Which read1 files should be used
read_1.required = True
read_1.type = localfile
read_1.action = append
read_2.name = Read 2
read_2.flag = --read-2
read_2.help = Which read2 files should be used (if single end, leave empty)
read_2.type = localfile
read_2.action = append
reference_genome.name = Reference genome
reference_genome.flag = --reference-genome
reference_genome.help = Which genome should the read being align on
reference_genome.type = localfile
reference_genome.required = True
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