From 40ab502bd9c5df11eb620765408b7ee0a0431dff Mon Sep 17 00:00:00 2001 From: George Marchment <georgemarchment@yahoo.fr> Date: Tue, 11 Feb 2025 14:48:38 +0100 Subject: [PATCH] Added start most influential conditions + such a weird bug fixed with 'get_above_executors' -> when using a dictionnary -> some weird things stuff happens in memory (try woorkflow 17) --- src/block.py | 13 +++++++++++-- src/condition.py | 3 +++ src/executor.py | 5 +++++ src/main.py | 5 ++++- src/root.py | 15 +++++++++++++++ src/workflow.py | 35 +++++++++++++++++++++++++++++++++++ 6 files changed, 73 insertions(+), 3 deletions(-) diff --git a/src/block.py b/src/block.py index 7ef7cd7..738ccda 100644 --- a/src/block.py +++ b/src/block.py @@ -13,6 +13,14 @@ class Block(Root): def get_type(self): return "Block" + + #This method returns returns all the conditions above the block + #Basically everything which needs to be true for the block to exist + def get_all_conditions(self, conditions = {}): + conditions[self.condition] = '' + self.origin.get_all_conditions(conditions = conditions) + return conditions + def same_condition(self, block): return self.condition.same_condition(block.condition) @@ -47,7 +55,8 @@ class Block(Root): dico[e] = '' self.origin.get_above_executors_rec(dico) - def get_above_executors(self, dico = {}): + def get_above_executors(self): + dico = {} self.origin.get_above_executors_rec(dico) return list(dico.keys()) @@ -81,7 +90,7 @@ class Block(Root): dico[c] = '' self.origin.get_channels_above_level_rec(dico) - def get_channels_above_level(self, dico = {}): + def get_channels_above_level(self): dico = {} self.origin.get_channels_above_level_rec(dico) return list(dico.keys()) diff --git a/src/condition.py b/src/condition.py index 243cca0..af34ffa 100644 --- a/src/condition.py +++ b/src/condition.py @@ -7,6 +7,9 @@ class Condition: self.value = condition #self.initialise() + def get_value(self): + return self.value + def same_condition(self, condition): return self.value == condition.value diff --git a/src/executor.py b/src/executor.py index 3691147..cda3531 100644 --- a/src/executor.py +++ b/src/executor.py @@ -74,6 +74,11 @@ class Executor(Nextflow_Building_Blocks): return self.origin.get_channels_from_name_other_blocks_on_same_level(name) + def get_block(self): + if(self.origin.get_type() in ['Root', "Block"]): + return self.origin + else: + return self.origin.get_block() #def get_channels(self): diff --git a/src/main.py b/src/main.py index f108590..6af23f5 100644 --- a/src/main.py +++ b/src/main.py @@ -41,7 +41,10 @@ class Main(Nextflow_Building_Blocks): def get_type(self): return "Main" - + def get_all_calls(self): + dico = {} + self.root.get_all_calls(calls = dico) + return list(dico.keys()) def check_includes(self): diff --git a/src/root.py b/src/root.py index 250ec9f..c3b1351 100644 --- a/src/root.py +++ b/src/root.py @@ -32,6 +32,7 @@ class Root(Nextflow_Building_Blocks): def add_element_to_elements_being_called(self, element): self.elements_being_called.append(element) + #Does this on the same level def get_blocks_with_same_conditions(self, searching_block): tab = [] for block in self.blocks: @@ -39,6 +40,11 @@ class Root(Nextflow_Building_Blocks): if(block.same_condition(searching_block)): tab.append(block) return tab + + #This method returns returns all the conditions above the block + #Basically everything which needs to be true for the block to exist + def get_all_conditions(self, conditions = {}): + return conditions ############# @@ -201,6 +207,15 @@ class Root(Nextflow_Building_Blocks): def get_calls_from_other_blocks_on_same_level(self): return [] + def get_all_calls(self, calls = {}): + all_calls = self.get_calls_same_level()+self.get_calls_inside_level() + for call in all_calls: + for c in call.get_all_calls(): + calls[c] = '' + if(c.get_first_element_called().get_type()=="Subworkflow"): + c.get_first_element_called().root.get_all_calls(calls = calls) + + diff --git a/src/workflow.py b/src/workflow.py index cf52871..0bfcc88 100644 --- a/src/workflow.py +++ b/src/workflow.py @@ -176,4 +176,39 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen self.graph.initialise(processes_2_remove = self.processes_2_remove) self.graph.get_specification_graph(render_graphs = render_graphs) + #Returns a dico of number of processes called per each condition + #For example : {condition1: 14, condition2: 10, condition:3} + #14 process calls depend on condition1 + #10 process calls depend on condition2 + #3 process calls depend on condition3 + def get_most_influential_conditions(self, show_values = True): + most_influential_conditions = {} + if(self.get_duplicate_status()): + all_calls = self.get_workflow_main().get_all_calls() + for c in all_calls: + if(c.get_first_element_called().get_type()=="Process"): + for condition in c.get_block().get_all_conditions(conditions = {}): + try: + temp = most_influential_conditions[condition] + except: + most_influential_conditions[condition] = 0 + most_influential_conditions[condition]+=1 + #If show values then we replace the the conditions ids with their values + if(show_values): + most_influential_conditions_values = {} + for condition in most_influential_conditions: + try: + t = most_influential_conditions_values[condition.get_value()] + except: + most_influential_conditions_values[condition.get_value()] = 0 + most_influential_conditions_values[condition.get_value()] += most_influential_conditions[condition] + most_influential_conditions = most_influential_conditions_values + + #Sort the dico + most_influential_conditions = {k: v for k, v in sorted(most_influential_conditions.items(), key=lambda item: item[1], reverse=True)} + + return most_influential_conditions + else: + BioFlowInsightError("Need to activate 'duplicate' mode to use this method.") + -- GitLab