From df4699c792923b0482ebbb352f97fec2abb41d25 Mon Sep 17 00:00:00 2001 From: George Marchment <georgemarchment@yahoo.fr> Date: Thu, 20 Mar 2025 10:47:04 +0100 Subject: [PATCH] Updated the rewrite of the calls + added filter to catch when an executor appears twice (throws error) --- src/call.py | 10 +++++++--- src/main.py | 8 ++++++-- src/operation.py | 2 +- src/workflow.py | 3 ++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/call.py b/src/call.py index a07dc6c..0e647eb 100644 --- a/src/call.py +++ b/src/call.py @@ -103,12 +103,16 @@ class Call(Executor): if(temp==code): raise Exception("This souldn't happen") #code = code.replace(param.get_code(get_OG=True), param_new_name) - lines = param.simplify_code().split('\n') + simplified_param = param.simplify_code() + lines = simplified_param.split('\n') if(len(lines)==1): new_bit = f"{param_new_name} = {lines[0]}" else: - head = '\n'.join(lines[:-1]) - new_bit = f"{head}\n{param_new_name} = {lines[-1]}" + if(re.fullmatch(r"\w+", lines[-1].strip())): + head = '\n'.join(lines[:-1]) + new_bit = f"{head}\n{param_new_name} = {lines[-1]}" + else: + new_bit = f"{param_new_name} = {simplified_param}" temp = code code = code.replace(tag_to_add, f"{tag_to_add}\n{new_bit}") if(temp==code): diff --git a/src/main.py b/src/main.py index 63a052a..44f7654 100644 --- a/src/main.py +++ b/src/main.py @@ -15,10 +15,14 @@ class Main(Nextflow_Building_Blocks): self.initialised = False self.root = None - def get_order_execution_executors(self, dico): + def get_order_execution_executors(self, dico, seen): executors = self.get_all_executors_in_subworkflow() pos = {} for e in executors: + code = e.get_code(get_OG = True) + if(code in seen): + raise BioFlowInsightError(f'Executor "{code}" appears twice in the workflow in the exact same way. BioFlow-Insight cannot rewrite the workflow then, try slighly changing how one of the executors is defined') + seen[code] = '' pos[e] = e.get_position_in_main(e) #TODO add sort here pos = {k: v for k, v in sorted(pos.items(), key=lambda item: item[1])} @@ -26,7 +30,7 @@ class Main(Nextflow_Building_Blocks): if(e.get_type()=="Call"): if(e.get_first_element_called().get_type()=="Subworkflow"): dico[e] = {} - e.get_first_element_called().get_order_execution_executors(dico[e]) + e.get_first_element_called().get_order_execution_executors(dico[e], seen) else: dico[e.get_first_element_called()] = pos[e] else: diff --git a/src/operation.py b/src/operation.py index f58c833..ebc158a 100644 --- a/src/operation.py +++ b/src/operation.py @@ -753,9 +753,9 @@ class Operation(Executor): to_call.append(m.get_alias()) pattern_call = constant.BEGINNING_CALL searching = True - text = " "+self.get_code(clean_pipe = clean_pipe) while(searching): searching= False + text = " "+self.get_code(clean_pipe = clean_pipe, replace_calls = False) for c in self.calls: temp = text text = text.replace(self.calls[c].get_code(), "") diff --git a/src/workflow.py b/src/workflow.py index 1826ab7..09be46e 100644 --- a/src/workflow.py +++ b/src/workflow.py @@ -420,7 +420,8 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen #Method that returns the order of execution for each executor def get_order_execution_executors(self): dico = {} - dico = self.get_workflow_main().get_order_execution_executors(dico) + seen = {} + dico = self.get_workflow_main().get_order_execution_executors(dico, seen) tab = [] def explore_dico(dico): if(type(dico)!=dict): -- GitLab