Commit 9159630d authored by mmassaviol's avatar mmassaviol
Browse files

Add expand in inputs when needed

parent 42d6bb9f
......@@ -15,9 +15,41 @@ dirpath = tempfile.mkdtemp()
DEFAULT_PATH_OUTPUT = "./"
DEFAULT_PATH_INPUT = "./workflows/"
# Return True when {sample} is in inputs files
def wildcard_in_inputs(rule_name, tool_yaml):
found = False
for command in tool_yaml["commands"]:
if command["name"] == rule_name:
found = True
for inputt in command["inputs"]:
if "file" in inputt:
if "{sample}" in inputt["file"]:
return True
if inputt["type"] == "reads":
return True
if found: # command found but no wildcard
return False
else:
exit("Command "+rule_name+" not found")
# Return True when {sample} is in outputs files
def wildcard_in_outputs(rule_name, tool_yaml):
found = False
for command in tool_yaml["commands"]:
if command["name"] == rule_name:
found = True
for output in command["outputs"]:
if "file" in output:
if "{sample}" in output["file"]:
return True
if found: # command found but no wildcard
return False
else:
exit("Command "+rule_name+" not found")
def generate(name, path_yaml = "", path_input = DEFAULT_PATH_INPUT, path_output = DEFAULT_PATH_OUTPUT):
result = "# File generate with generate_workflow_snakefile.py\n\n"
result = "# File generated with generate_workflow_snakefile.py\n\n"
yaml = None
......@@ -63,8 +95,22 @@ def generate(name, path_yaml = "", path_input = DEFAULT_PATH_INPUT, path_output
if command["name"] == step["rule_name"]:
RULE_YAML = command
inputs_list_from_command = [inputt["name"] for inputt in RULE_YAML["inputs"]] # Liste des inputs dans la commande du yaml de l'outil
inputs_list_from_yaml = list() # Liste des inputs dans le steps_in du yaml du workflow
# wildcards in inputs and outputs
wildcard_in = wildcard_in_inputs(step["rule_name"],TOOL_YAML)
wildcard_out = wildcard_in_outputs(step["rule_name"],TOOL_YAML)
# wildcard in inputs but not in outputs => expand on inputs
if wildcard_in and not wildcard_out:
expand_begin = "expand("
expand_end = ",sample=SAMPLES)"
else:
expand_begin = ""
expand_end = ""
# Liste des inputs dans la commande du yaml de l'outil
#inputs_list_from_command = [inputt["name"] for inputt in RULE_YAML["inputs"]]
# Liste des inputs dans le steps_in du yaml du workflow
inputs_list_from_yaml = list()
result += "def " + step["step_name"] + "__" + step["rule_name"] + "_inputs():\n"
result += "\tinputs = dict()\n"
......@@ -87,15 +133,15 @@ def generate(name, path_yaml = "", path_input = DEFAULT_PATH_INPUT, path_output
if param["input_name"] not in inputs_list_from_yaml:
result += "\tinputs[\"" + param["input_name"] + "\"] = list()\n"
if "raw_" in param["origin_command"] :
result += "\tinputs[\"" + param["input_name"] + "\"].append(" + param["origin_command"]+"[\""+param["origin_name"]+"\"])\n"
result += "\tinputs[\"" + param["input_name"] + "\"].append(" + expand_begin + param["origin_command"] + "[\"" + param["origin_name"] + "\"]" + expand_end + ")\n"
else:
result += "\tinputs[\"" + param["input_name"] + "\"].append(rules." + param["origin_step"] + "__" + param["origin_command"] + ".output." + param["origin_name"] + ")\n"
result += "\tinputs[\"" + param["input_name"] + "\"].append(" + expand_begin + "rules." + param["origin_step"] + "__" + param["origin_command"] + ".output." + param["origin_name"] + expand_end + ")\n"
# inputs classiques
else:
if "raw_" in param["origin_command"] :
result += "\tinputs[\"" + param["input_name"] + "\"] = " + param["origin_command"]+"[\""+param["origin_name"]+"\"]\n"
result += "\tinputs[\"" + param["input_name"] + "\"] = " + expand_begin + param["origin_command"] + "[\"" + param["origin_name"] + "\"] " + expand_end + "\n"
else:
result += "\tinputs[\"" + param["input_name"] + "\"] = rules." + param["origin_step"] + "__" + param["origin_command"] + ".output." + param["origin_name"] + "\n"
result += "\tinputs[\"" + param["input_name"] + "\"] = " + expand_begin + "rules." + param["origin_step"] + "__" + param["origin_command"] + ".output." + param["origin_name"] + expand_end + "\n"
inputs_list_from_yaml.append(param["input_name"]) # input traités (ou vu une fois si de type liste)
......@@ -131,17 +177,8 @@ def generate(name, path_yaml = "", path_input = DEFAULT_PATH_INPUT, path_output
if ("step_name" in step) and ("rule_name" in step):
# Check in tool yaml if {sample} in output files to add expand
tool_yaml = read_yaml(path_input+"/tools/"+step["tool_name"]+"/"+step["tool_name"]+".yaml")
need_expand = False
need_expand = wildcard_in_outputs(step["rule_name"],tool_yaml)
for command in tool_yaml["commands"]:
if command["name"] == step["rule_name"]:
for output in command["outputs"]:
if "file" in output:
if "{sample}" in output["file"]:
need_expand = True
else:
# TODO return error
continue
if need_expand:
expand_start = "expand("
expand_end = ", sample=SAMPLES)"
......
Supports Markdown
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