Commit 475b6466 authored by Penom Nom's avatar Penom Nom
Browse files

Split the current NG6Workflow into two class

- One will handle a workflow without run (BasicNG6Workflow)
- the other will handle runs ( NG6Workflow)
parent 435b6fa0
......@@ -33,40 +33,25 @@ from ng6.run import Run
def adminlogin(login):
t3mysql = t3MySQLdb()
try:
t3mysql.get_user_id(login)
t3mysql.get_user_id(login)
return login
except:
raise argparse.ArgumentTypeError("Login '" + login + "' does not exists! Please provide a valid login!")
class NG6Workflow (Workflow):
"""
"""
def __init__(self, args={}, id=None, function= "process", parameters_section="parameters", add_run_params=True):
class BasicNG6Workflow (Workflow):
def __init__(self, args={}, id=None, function= "process", parameters_section="parameters"):
Workflow.__init__(self, args, id, function, parameters_section)
self._required_parameters = [Parameter("admin_login", "Who is the project administrator", "--admin-login", required=True, type=adminlogin, display_name="Admin login")]
# admin login is required for all workflow
self.add_run_params = add_run_params
self.parameters.extend(self._add_required_parameters())
self.parameters.extend(self._required_parameters)
self.args = self._extend_and_format_args(self.parameters, args)
def _add_required_parameters(self):
orequired = []
orequired.append(Parameter("admin_login", "Who is the project administrator", "--admin-login", required=True, type=adminlogin, display_name="Admin login"))
# add run parameters
if self.add_run_params:
orequired.append(Parameter("project_id", "The project id the run belongs to", "--project-id", required=True, type=int, group="Run information"))
orequired.append(Parameter("run_name", "Give a name to your run", "--name", required=True, group="Run information", display_name="Name"))
orequired.append(Parameter("run_description", "Give a description to your run", "--description", required=True, group="Run information", display_name="Description"))
orequired.append(Parameter("run_date", "When were the data produced","--date", required=True, type=date, group="Run information", display_name="Date"))
orequired.append(Parameter("data_nature", "Are Sequences cDNA, genomique, RNA, ...", "--data-nature", required=True, group="Run information", display_name="Data nature"))
orequired.append(Parameter("sequencer", "Which sequencer produced the data", "--sequencer", required=True, group="Run information", display_name="Sequencer"))
orequired.append(Parameter("species", "Which species has been sequenced", "--species", required=True, group="Run information", display_name="Species"))
orequired.append(Parameter("run_type", "What type of data is it (1 lane, 1 region)", "--type", required=True, group="Run information", display_name="Type"))
return orequired
def get_parameters_per_groups(self, parameters_section="parameters"):
name, description, parameters = self._get_from_config(parameters_section)
parameters.extend(self._add_required_parameters())
parameters.extend(self._required_parameters)
pgparameters, parameters_order = {}, []
for param in parameters:
if param.group not in parameters_order: parameters_order.append(param.group)
......@@ -75,53 +60,8 @@ class NG6Workflow (Workflow):
else:
pgparameters[param.group] = [param]
return [pgparameters, parameters_order]
def pre_process(self):
self.project = None
self.runobj = None
# if starting from an existing project
if self.args.has_key("project_id") and self.args["project_id"] is not None:
self.project = Project.get_from_id(self.args["project_id"])
self.metadata.append("project_id="+str(self.args["project_id"]))
# if user is not allowed to add data on project (is not admin)
if self.project is not None and not self.project.is_admin(self.args["admin_login"]):
sys.stderr.write( "The user login '" + self.args["admin_login"] + "' is not allowed to add data on project '" + self.project.name + "'.\n" )
sys.exit()
# if starting from a brand new project
elif self.args.has_key("project_name") and self.args.has_key("project_description") and self.args.has_key("admin_login"):
self.project = Project(self.args["project_name"], self.args["project_description"], self.args["admin_login"])
self.metadata.append("project_id="+str(self.project.id))
# if starting from an existing run
if self.args.has_key("run_id") and self.args["run_id"] is not None:
if self.project is None :
project = Project.get_from_run_id(self.args["run_id"])
# if user is not allowed to add data on project (is not admin)
if not project.is_admin(self.args["admin_login"]):
sys.stderr.write( "The user login '" + self.args["admin_login"] + "' is not allowed to add data on project '" + project.name + "'." )
sys.exit()
self.runobj = Run.get_from_id(self.args["run_id"])
self.metadata.append("run_id="+str(self.args["run_id"]))
# if starting from a brand new run
elif self.args.has_key("run_date") and self.args.has_key("run_name") and self.args.has_key("species") and self.args.has_key("data_nature") \
and self.args.has_key("run_type") and self.args.has_key("run_description") and self.args.has_key("sequencer") and self.args.has_key("project_id"):
# build the run
self.runobj = Run(self.args["run_name"], self.args["run_date"], self.args["species"], self.args["data_nature"],
self.args["run_type"], self.args["run_description"], self.args["sequencer"])
self.runobj.admin_login=self.args["admin_login"]
# then add the run to the project
self.project.add_run(self.runobj)
# if it's a run with some index, let's write down description
if self.args.has_key("sample") and self.args["sample"]:
try:
samples = {}
for sample in self.args["sample"]:
samples[sample["sample_name"]] = sample["sample_description"]
self.runobj.add_mids_description(samples)
except: pass
self.metadata.append("run_id="+str(self.runobj.id))
def add_component(self, component_name, args=[], kwargs={}, component_prefix="default", parent=None, addto="run"):
# first build and check if this component is OK
if self.comp_pckg.has_key(component_name):
......@@ -176,6 +116,55 @@ class NG6Workflow (Workflow):
return cmpt_object
else:
raise ImportError(component_name + " component cannot be loaded, available components are: {0}".format(", ".join(self.comp_pckg.keys())))
class NG6Workflow (BasicNG6Workflow):
def __init__(self, args={}, id=None, function= "process", parameters_section="parameters"):
BasicNG6Workflow.__init__(self, args, id, function, parameters_section)
self._required_parameters.extend(self._add_required_parameters())
self.parameters.extend(self._required_parameters)
self.args = self._extend_and_format_args(self.parameters, args)
def _add_required_parameters(self):
orequired = []
orequired.append(Parameter("project_id", "The project id the run belongs to", "--project-id", required=True, type=int, group="Run information"))
orequired.append(Parameter("run_name", "Give a name to your run", "--name", required=True, group="Run information", display_name="Name"))
orequired.append(Parameter("run_description", "Give a description to your run", "--description", required=True, group="Run information", display_name="Description"))
orequired.append(Parameter("run_date", "When were the data produced","--date", required=True, type=date, group="Run information", display_name="Date"))
orequired.append(Parameter("data_nature", "Are Sequences cDNA, genomique, RNA, ...", "--data-nature", required=True, group="Run information", display_name="Data nature"))
orequired.append(Parameter("sequencer", "Which sequencer produced the data", "--sequencer", required=True, group="Run information", display_name="Sequencer"))
orequired.append(Parameter("species", "Which species has been sequenced", "--species", required=True, group="Run information", display_name="Species"))
orequired.append(Parameter("run_type", "What type of data is it (1 lane, 1 region)", "--type", required=True, group="Run information", display_name="Type"))
return orequired
def pre_process(self):
self.project = None
self.runobj = None
# start from an existing project
self.project = Project.get_from_id(self.args["project_id"])
self.metadata.append("project_id="+str(self.args["project_id"]))
# if user is not allowed to add data on project (is not admin)
if self.project is not None and not self.project.is_admin(self.args["admin_login"]):
sys.stderr.write( "The user login '" + self.args["admin_login"] + "' is not allowed to add data on project '" + self.project.name + "'.\n" )
sys.exit()
# build the run
self.runobj = Run(self.args["run_name"], self.args["run_date"], self.args["species"], self.args["data_nature"],
self.args["run_type"], self.args["run_description"], self.args["sequencer"])
self.runobj.admin_login=self.args["admin_login"]
# then add the run to the project
self.project.add_run(self.runobj)
# if it's a run with some index, let's write down description
if self.args.has_key("sample") and self.args["sample"]:
try:
samples = {}
for sample in self.args["sample"]:
samples[sample["sample_name"]] = sample["sample_description"]
self.runobj.add_mids_description(samples)
except: pass
self.metadata.append("run_id="+str(self.runobj.id))
def post_process(self):
# once everything done, sync directories
......@@ -183,4 +172,3 @@ class NG6Workflow (Workflow):
self.runobj.sync()
elif self.project:
self.project.sync()
......@@ -18,13 +18,11 @@
import os
import sys
from ng6.ng6workflow import NG6Workflow
from ng6.ng6workflow import BasicNG6Workflow
from ng6.project import Project
from ng6.run import Run
class AddAnalysis (NG6Workflow):
def __init__(self, args={}, id=None, function= "process", parameters_section="parameters"):
NG6Workflow.__init__(self, args, id, function, parameters_section, add_run_params=False)
class AddAnalysis (BasicNG6Workflow):
def process(self):
"""
......@@ -37,16 +35,24 @@ class AddAnalysis (NG6Workflow):
files_to_save.append(file)
else:
sys.exit("error: %s file does not exists\n" % (file))
# Check if user provided a project or a run
if self.project and self.runobj:
sys.stderr.write("An analysis should be added to a run OR a project not both of them!\n")
sys.exit()
elif self.project is None and self.runobj is None :
# Check if user provided a project or a run
if self.args["project_id"] :
self.project = Project.get_from_id(self.args["project_id"])
self.metadata.append("project_id="+str(self.args["project_id"]))
# if user is not allowed to add data on project (is not admin)
if self.project is not None and not self.project.is_admin(self.args["admin_login"]):
sys.stderr.write( "The user login '" + self.args["admin_login"] + "' is not allowed to add data on project '" + self.project.name + "'.\n" )
sys.exit()
elif self.args["run_id"] :
self.runobj = Run.get_from_id(self.args["run_id"])
self.metadata.append("run_id="+str(self.args["run_id"]))
else :
sys.stderr.write("One of run_id or project_id parameter is required!\n")
sys.exit()
addto = "project" if self.project else "run"
addto = "run"
if self.project: addto = "project"
basicanalysis = self.add_component("BasicAnalyse", [files_to_save, self.args["analysis_name"],
self.args["analysis_description"], self.args["analysis_software"], self.args["analysis_software_options"],
self.args["analysis_software_version"], self.args["compression"], self.args["delete"],
......
......@@ -61,11 +61,13 @@ project_id.name = project_id
project_id.flag = --project-id
project_id.help = The project id the analysis belongs to
project_id.type = int
project_id.exclude = run_id
run_id.name = run_id
run_id.flag = --run-id
run_id.help = The run id the run belongs to
run_id.type = int
run_id.exclude = project_id
analysis_name.name = analysis_name
analysis_name.flag = --analysis-name
......
......@@ -15,16 +15,14 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from ng6.ng6workflow import NG6Workflow
from ng6.ng6workflow import BasicNG6Workflow
from ng6.project import Project
class AddProject (NG6Workflow):
def __init__(self, args={}, id=None, function= "process", parameters_section="parameters"):
NG6Workflow.__init__(self, args, id, function, parameters_section, add_run_params=False)
class AddProject (BasicNG6Workflow):
def process(self):
"""
Run the workflow
"""
pass
project = Project(self.args["project_name"], self.args["project_description"], self.args["admin_login"])
self.metadata.append("project_id="+str(project.id))
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