Skip to content
Snippets Groups Projects
Commit 678ab80b authored by George Marchment's avatar George Marchment
Browse files

Moved the conditions to the outside of the cluster in the case of one...

Moved the conditions to the outside of the cluster in the case of one condition in cluster + added the creation of empty channels
parent 96dddcb8
No related branches found
No related tags found
No related merge requests found
Pipeline #14263 failed with stage
in 2 minutes and 3 seconds
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
from .nextflow_file import Nextflow_File from .nextflow_file import Nextflow_File
from .ro_crate import RO_Crate from .ro_crate import RO_Crate
from . import constant from . import constant
from .outils import is_git_directory, format_with_tabs, replace_thing_by_call, replace_group1, group_together_ifs from .outils import is_git_directory, format_with_tabs, replace_thing_by_call, replace_group1, group_together_ifs, extract_curly
from .outils_graph import flatten_dico, initia_link_dico_rec, get_number_cycles from .outils_graph import flatten_dico, initia_link_dico_rec, get_number_cycles
from .outils_annotate import get_tools_commands_from_user_for_process from .outils_annotate import get_tools_commands_from_user_for_process
from .bioflowinsighterror import BioFlowInsightError from .bioflowinsighterror import BioFlowInsightError
...@@ -933,6 +933,18 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen ...@@ -933,6 +933,18 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
#TODO find a better naming system #TODO find a better naming system
name = f"non_relevant_cluster_{non_relevant_name}" name = f"non_relevant_cluster_{non_relevant_name}"
non_relevant_name+=1 non_relevant_name+=1
#Check that there is a single condtion in the body
body = group_together_ifs(body)
conditions_in_subworkflow = []
end = -1
for match in re.finditer(r"if\s*(\([^\{]+)\{", body):
conditions_in_subworkflow.append(match.group(1).strip())
_, start = match.span(0)
if(len(conditions_in_subworkflow)==1):
end = extract_curly(body, start)
body = body[start: end-1].strip()
#TAKE #TAKE
...@@ -965,38 +977,40 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen ...@@ -965,38 +977,40 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
#Replace names inside subworkflow #Replace names inside subworkflow
subworkflow_code = f"subworkflow {name} {{\n{take}\n{body}\n{emit}\n}}" subworkflow_code = f"subworkflow {name} {{\n{take}\n{body}\n{emit}\n}}"
params = ", ".join(old_param_names)
subworkfow_call = f"{name}({params})"
for i in range(len(new_param_names)): for i in range(len(new_param_names)):
pattern = fr"[\=\,\(] *({re.escape(takes_param[i].get_code())})[\s\,\)]" pattern = fr"[\=\,\(] *({re.escape(takes_param[i].get_code())})[\s\,\)]"
subworkflow_code = replace_group1(subworkflow_code, pattern, new_param_names[i]) subworkflow_code = replace_group1(subworkflow_code, pattern, new_param_names[i])
#subworkflow_code = subworkflow_code.replace(takes_param[i].get_code(), new_param_names[i]) #subworkflow_code = subworkflow_code.replace(takes_param[i].get_code(), new_param_names[i])
#TODO -> added verification of conditions
params = ", ".join(old_param_names)
subworkfow_call_case_true = f"{name}({params})"
subworkfow_call_case_false = ""
for i in range(len(new_output_names)): for i in range(len(new_output_names)):
#In the case of channels, we just add chanel = subworkflow.out[i] #In the case of channels, we just add chanel = subworkflow.out[i]
if(not bool(re.findall("\.\s*out", old_output_names[i]))): if(not bool(re.findall("\.\s*out", old_output_names[i]))):
subworkfow_call+=f"\n{old_output_names[i]} = {new_output_names[i]}" subworkfow_call_case_true+=f"\n{old_output_names[i]} = {new_output_names[i]}"
subworkfow_call_case_false+=f"\n{old_output_names[i]} = Channel.empty()"
#In the case of emitted values we need to replace the code on the outside #In the case of emitted values we need to replace the code on the outside
else: else:
param_out_name= f"{name}_out_{i+1}" param_out_name= f"{name}_out_{i+1}"
subworkfow_call+=f"\n{param_out_name} = {new_output_names[i]}" subworkfow_call_case_true+=f"\n{param_out_name} = {new_output_names[i]}"
subworkfow_call_case_false+=f"\n{param_out_name} = Channel.empty()"
channels_to_replace_outside_of_cluster.append((old_output_names[i], param_out_name)) channels_to_replace_outside_of_cluster.append((old_output_names[i], param_out_name))
#If there was only one single condition in the subworkflow cluster -> then we add it when the call is done
if(len(conditions_in_subworkflow)==1):
subworkfow_call = f"if{conditions_in_subworkflow[0]} {{\n{subworkfow_call_case_true}\n}} else {{\n{subworkfow_call_case_false}\n}}"
None
else:
subworkfow_call = subworkfow_call_case_true
subworkflow_clusters_to_add.append(subworkflow_code) subworkflow_clusters_to_add.append(subworkflow_code)
subworkflow_cluster_calls_to_add.append(subworkfow_call) subworkflow_cluster_calls_to_add.append(subworkfow_call)
index_cluster+=1 index_cluster+=1
subworkflow_code = format_with_tabs(group_together_ifs(subworkflow_code))
#subworkflow_code = format_with_tabs(subworkflow_code)
print(subworkflow_code) print(format_with_tabs(subworkflow_code))
#print(subworkfow_call)
#
#for t in self.get_takes(things_added_in_cluster):
# print("*", t.get_code())
#
#for t in self.get_emits(things_added_in_cluster):
# print("-", t.get_code())
print("-----------") print("-----------")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment