diff --git a/src/block.py b/src/block.py index 7ef7cd739df57a7accfa2d5dad962174c593ef1f..738ccdaa4f4019d5d44a3adf6c50fe06c685f3d6 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 243cca04633c97c2e6e176f338d427d9d0e5453d..af34ffafe2a91b8b7c0b1c3c3700b421a18810a4 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 36911470242ea4a215e36ca901cf57df058dccf9..cda35319befd895b8bdb6e3afb9bce16e36ece90 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 f108590141bf8b9b722c426bdadd2c90b8c78188..6af23f59e68faf05bfc176b442198afc805c6ca9 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 250ec9ff39b8033556da8efa17de71e598204039..c3b1351a546dd766e4b83a9389fcc244aabe2c9c 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 cf52871ccdd4c148fcd076c3f7d8a89277041de6..0bfcc8824bda7ecfff2700fb0c8751c2896a9973 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.") +