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

update to DSL1 to DSL2: add val around variables in tuple

parent 678ab80b
No related branches found
No related tags found
No related merge requests found
Pipeline #14264 failed with stage
in 2 minutes and 17 seconds
...@@ -1053,7 +1053,32 @@ def process_2_DSL2(code): ...@@ -1053,7 +1053,32 @@ def process_2_DSL2(code):
code = re.sub(r'file( | *\()', replace_file_by_path, code) code = re.sub(r'file( | *\()', replace_file_by_path, code)
code = re.sub(r'set( | *\()', replace_set_by_tuple, code) code = re.sub(r'set( | *\()', replace_set_by_tuple, code)
return code return add_vals_when_necessary(code)
#Function that adds vals around variables in a tuple
def add_vals_when_necessary(line):
starts_with_tuple = False
code_to_replace = ""
for match in re.finditer(r"tuple\s*\((.+)\)", line):
starts_with_tuple = True
code_to_replace = match.group(1)
if(not starts_with_tuple):
for match in re.finditer(r"tuple\s*(.+)", line):
starts_with_tuple = True
code_to_replace = match.group(1)
if(starts_with_tuple):
code_to_replace = re.split(r'\,\s*emit\s*\:', code_to_replace)[0]
#Adding val to cases where it's just the variable
line_split = code_to_replace.split(',')
for y in range(len(line_split)) :
param = line_split[y]
if(bool(re.fullmatch('\w+', param.strip()))):
line_split[y] = f"val({param.strip()})"
temp = ", ".join(line_split)
line = line.replace(code_to_replace, temp)
return line
def operation_2_DSL2(code, origin): def operation_2_DSL2(code, origin):
......
...@@ -558,15 +558,20 @@ class Process(Nextflow_Building_Blocks): ...@@ -558,15 +558,20 @@ class Process(Nextflow_Building_Blocks):
code = process_2_DSL2(code) code = process_2_DSL2(code)
lines = [] lines = []
for line in code.split("\n"): for line in code.split("\n"):
lines.append(line.split(" from ")[0]) temp = process_2_DSL2(line.split(" from ")[0])
lines.append(temp)
code = "\n".join(lines) code = "\n".join(lines)
return code return code
def convert_output_code_to_DSL2(self): def convert_output_code_to_DSL2(self):
code = self.output_code code = self.output_code
code = process_2_DSL2(code) lines = []
code = code.replace(" into ", ", emit: ") for line in code.split("\n"):
code = code.replace(" mode flatten", "") line = line.replace(" into ", ", emit: ")
line = line.replace(" mode flatten", "")
line = process_2_DSL2(line)
lines.append(line)
code = "\n".join(lines)
return code return code
#This method is to detect which are the channels which need to be flattened #This method is to detect which are the channels which need to be flattened
......
...@@ -856,7 +856,7 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen ...@@ -856,7 +856,7 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
processes_added = [] processes_added = []
things_added_in_cluster = [] things_added_in_cluster = []
if(len(elements)>1): if(len(elements)>1):
name, body, take, emit = "", "main:\n", "", "" name, body, take, emit = "", "", "", ""
first_element = True first_element = True
for ele in elements: for ele in elements:
...@@ -976,9 +976,9 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen ...@@ -976,9 +976,9 @@ 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"workflow {name} {{\n{take}\nmain:\n{body}\n{emit}\n}}"
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])
...@@ -1011,7 +1011,7 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen ...@@ -1011,7 +1011,7 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
print(format_with_tabs(subworkflow_code)) print(format_with_tabs(subworkflow_code))
print("-----------") print("//-----------")
#TODO -> rmoving the conditions which are problematic #TODO -> rmoving the conditions which are problematic
......
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