From dde31389a0482406980cf2e6faa160e07b0782a8 Mon Sep 17 00:00:00 2001 From: George Marchment <georgemarchment@yahoo.fr> Date: Tue, 18 Mar 2025 15:27:00 +0100 Subject: [PATCH] First workflow (EpiDiverse/snp) works A to Z by rewritting and then running --- src/nextflow_file.py | 20 ++++++++++++++++++++ src/workflow.py | 31 ++++++++++++++++++------------- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/nextflow_file.py b/src/nextflow_file.py index ebdf62d..9329ac8 100644 --- a/src/nextflow_file.py +++ b/src/nextflow_file.py @@ -273,6 +273,26 @@ class Nextflow_File(Nextflow_Building_Blocks): modules+=list(include.defines.values()) return modules + def get_calls_made_outside_of_main(self): + #Code without processes + code = self.get_code() + for proecess in self.processes: + code = code.replace(proecess.get_code(), "") + for sub in self.subworkflows: + code = code.replace(sub.get_code(), "") + for fun in self.functions: + code = code.replace(fun.get_code(), "") + if(self.first_file and self.main!=None): + code = code.replace(self.main.get_code(), "") + for include in self.includes: + code = code.replace(include.get_code(), "") + + from .root import Root + self.root = Root(code=code, origin= self, modules_defined=self.get_modules_defined(), subworkflow_inputs = []) + self.root.initialise() + calls = {} + self.root.get_all_calls_in_subworkflow(calls=calls) + return list(calls.keys()) #---------------------- #INITIALISE diff --git a/src/workflow.py b/src/workflow.py index 277b1c7..1826ab7 100644 --- a/src/workflow.py +++ b/src/workflow.py @@ -461,21 +461,18 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen ankers = function_section+ "\n"*3 + process_section+ "\n"*3 + subworkflow_section - to_replace = [] - for match in re.finditer(constant.FULL_INLCUDE_2, code): - to_replace.append(match.group(0)) + - if(to_replace==[]): - pos_start = 0 - start_code_pattern = r"\#\!\s*\/usr\/bin\/env\s+nextflow" - for match in re.finditer(start_code_pattern, code): - pos_start = match.span(0)[1]+1 - code = code[:pos_start]+ankers+code[pos_start:] - else: - for r in to_replace: - code = code.replace(r, ankers) - ankers = "" + #Place ankers + pos_start = 0 + start_code_pattern = r"\#\!\s*\/usr\/bin\/env\s+nextflow" + for match in re.finditer(start_code_pattern, code): + pos_start = match.span(0)[1]+1 + code = code[:pos_start]+ankers+code[pos_start:] + #Remove the includes + for match in re.finditer(constant.FULL_INLCUDE_2, code): + code = re.sub(fr"{re.escape(match.group(0))}.*", "", code) processes, subworkflows, functions = [], [], [] for c in self.get_workflow_main().get_all_calls_in_workflow(): @@ -488,6 +485,14 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen functions.append(ele) else: raise Exception("This shoudn't happen") + + #Get calls to functions made outside of themain which might have been imported -> so we need to add them + for c in self.get_first_file().get_calls_made_outside_of_main(): + ele = c.get_first_element_called() + if(ele.get_type()=="Function"): + functions.append(ele) + else: + raise Exception("This shoudn't happen -> either a call to a process or subworkflow outside of main or subworkflow") #Simplifying main code = code.replace(self.get_workflow_main().get_code(get_OG = True), self.get_workflow_main().simplify_code()) -- GitLab