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

first component ok

parent be1a5cf0
......@@ -19,13 +19,14 @@ import os
import sys
import inspect
import tempfile
import types
from jflow.workflows_manager import WorkflowsManager
from jflow.config_reader import JFlowConfigReader
from jflow.dataset import ArrayList
from jflow.utils import which
from jflow.iotypes import DynamicOutput, OutputFile, OutputFileList
from jflow.parameter import *
from jflow.iotypes import DynamicOutput
from weaver.util import parse_string_list
......@@ -35,6 +36,7 @@ class Component(object):
def __init__(self):
self.prefix = "default"
self.params_order = []
self.output_directory = None
self.config_reader = JFlowConfigReader()
self.version = self.get_version()
......@@ -64,6 +66,62 @@ 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)
else:
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:
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)
else:
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:
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)
else:
new_param = OutputFile(name, help, default=os.path.join(self.output_directory, basename),
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:
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()
......
......@@ -70,6 +70,17 @@ def inputfile(file):
else:
return urlfile(file)
class Formats(object):
ANY = "any"
BAM = "bam"
FASTQ = "fastq"
FASTA = "fasta"
SFF = "sff"
QUAL = "qual"
FLOW = "flow"
HTML = "html"
class MultipleParameters(object):
def __init__(self, types, required, choices, excludes, default, actions):
......
......@@ -30,30 +30,10 @@ class Alignment (Workflow):
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_multiple_parameter("test", "toto est dnas le gazon", required=True)
self.add_parameter("toto", "Whices should be used", required=True, is_list=True, add_to="test")
self.add_parameter("tot_2", "Whould be used", type="int", add_to="test")
self.add_parameter("rdate", "date be used", type="date", add_to="test")
self.add_multiple_parameter("unmulti", "unmulti qui fait chier", required=True, is_list=True)
self.add_parameter("a", "Wa", required=True, add_to="unmulti")
self.add_parameter("b", "Wb", type="int", add_to="unmulti")
self.add_parameter("c", "dc", type="date", add_to="unmulti")
#self.add_exclusion_rule("read_1", "read_2")
#self.add_exclusion_rule("toto", "tot_2")
def process(self):
print self.read_1
print self.read_2
print self.reference_genome
print self.test
print self.unmulti
def process(self):
# index the reference genome
#bwaindex = self.add_component("BWAIndex", [self.args["reference_genome"]])
bwaindex = self.add_component("BWAIndex", [self.reference_genome])
# align reads against indexed genome
#bwa = self.add_component("BWA", [bwaindex.databank, self.args["read_1"], self.args["read_2"]])
......
......@@ -19,8 +19,7 @@ import os
from subprocess import Popen, PIPE
from jflow.component import Component
from jflow.iotypes import OutputFile, InputFile, Formats
from jflow.parameter import Formats
from weaver.function import PythonFunction, ShellFunction
......@@ -44,11 +43,11 @@ def bwa_index(exec_path, algorithm, input_fasta, databank, stdout_path, stderr_p
class BWAIndex (Component):
def define_parameters(self, input_fasta, algorithm="bwtsw"):
self.input_fasta = InputFile(input_fasta, Formats.FASTA)
self.algorithm = algorithm
self.databank = OutputFile(os.path.join(self.output_directory, os.path.basename(input_fasta)))
self.stdout = OutputFile(os.path.join(self.output_directory, "bwaindex.stdout"))
self.stderr = OutputFile(os.path.join(self.output_directory, "bwaindex.stderr"))
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")
def process(self):
bwaindex = PythonFunction(bwa_index, cmd_format="{EXE} {ARG} {IN} {OUT}")
......@@ -59,4 +58,3 @@ class BWAIndex (Component):
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate()
return stderr.split()[7]
\ No newline at end of file
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