diff --git a/src/block.py b/src/block.py index 738ccdaa4f4019d5d44a3adf6c50fe06c685f3d6..8d03cfc7b2c9d8a28d278b4c33c96c8a5cd513be 100644 --- a/src/block.py +++ b/src/block.py @@ -8,8 +8,11 @@ class Block(Root): self.condition = Condition(origin=self, condition = condition) def initialise(self): - if(self.condition.value not in []): + if(self.condition.value not in self.origin.get_conditions_2_ignore()): return super().initialise() + + def get_conditions_2_ignore(self): + return self.origin.get_conditions_2_ignore() def get_type(self): return "Block" diff --git a/src/main.py b/src/main.py index 6af23f59e68faf05bfc176b442198afc805c6ca9..9b2d0a9b7eb666cc275ae3fc60022a65676c8877 100644 --- a/src/main.py +++ b/src/main.py @@ -21,6 +21,9 @@ class Main(Nextflow_Building_Blocks): #def check_in_channels(self, channel): # return self.root.check_in_channels(channel) + def get_conditions_2_ignore(self): + return self.nextflow_file.get_conditions_2_ignore() + def get_modules_defined(self): return self.nextflow_file.get_modules_defined() @@ -41,9 +44,9 @@ class Main(Nextflow_Building_Blocks): def get_type(self): return "Main" - def get_all_calls(self): + def get_all_calls_in_subworkflow(self): dico = {} - self.root.get_all_calls(calls = dico) + self.root.get_all_calls_in_subworkflow(calls = dico) return list(dico.keys()) @@ -81,4 +84,41 @@ class Main(Nextflow_Building_Blocks): def get_structure(self, dico): self.root.get_structure(dico) return dico - \ No newline at end of file + + def get_most_influential_conditions(self): + most_influential_conditions = {} + all_calls = self.get_all_calls_in_subworkflow() + 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(c.get_first_element_called().get_type()=="Subworkflow"): + #Adding the number of calls from a process at the root of the subworkflow + num = 0 + calls_at_root = c.get_first_element_called().root.get_calls_same_level() + for call_at_root in calls_at_root: + for c_at_root in call_at_root.get_all_calls(): + if(c_at_root.get_first_element_called().get_type()=="Process"): + num +=1 + + most_influential_conditions_in_sub = c.get_first_element_called().get_most_influential_conditions() + #Adding the conditions from inside the subworkflow + for condition in most_influential_conditions_in_sub: + try: + temp = most_influential_conditions[condition] + except: + most_influential_conditions[condition] = 0 + num+=most_influential_conditions_in_sub[condition] + most_influential_conditions[condition]+=most_influential_conditions_in_sub[condition] + #Adding calls from the subworkflow to the conditions + 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]+=num + return most_influential_conditions \ No newline at end of file diff --git a/src/nextflow_file.py b/src/nextflow_file.py index 8a5ab6344edab0311ee68f5f3a00d7f0b3d06c08..d62b04dc1ac6c68003ad09e8172754af06922e1d 100644 --- a/src/nextflow_file.py +++ b/src/nextflow_file.py @@ -43,6 +43,8 @@ class Nextflow_File(Nextflow_Building_Blocks): def get_string_line(self, bit_of_code): return self.code.get_string_line(bit_of_code) + def get_conditions_2_ignore(self): + return self.workflow.get_conditions_2_ignore() #Method that returns the address of the file def get_file_address(self): diff --git a/src/root.py b/src/root.py index c3b1351a546dd766e4b83a9389fcc244aabe2c9c..bd202ced0760582157abd04a3631c1b750e3b0a5 100644 --- a/src/root.py +++ b/src/root.py @@ -28,6 +28,9 @@ class Root(Nextflow_Building_Blocks): def get_blocks(self): return self.blocks + + def get_conditions_2_ignore(self): + return self.origin.get_conditions_2_ignore() def add_element_to_elements_being_called(self, element): self.elements_being_called.append(element) @@ -207,13 +210,13 @@ class Root(Nextflow_Building_Blocks): def get_calls_from_other_blocks_on_same_level(self): return [] - def get_all_calls(self, calls = {}): + def get_all_calls_in_subworkflow(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) + #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 0bfcc8824bda7ecfff2700fb0c8751c2896a9973..280392ce4fc92ac44c2192af31c9542ba48da0ed 100644 --- a/src/workflow.py +++ b/src/workflow.py @@ -68,6 +68,7 @@ class Workflow: self.workflow_directory = '/'.join(file.split('/')[:-1]) self.name = name self.graph = None + self.conditions_2_ignore = [] OG_file = Nextflow_File(file, workflow = self, first_file = True) @@ -89,6 +90,9 @@ class Workflow: with open(self.output_dir / "debug" / "operations_in_call.nf",'w') as file: pass + def get_conditions_2_ignore(self): + return self.conditions_2_ignore + def get_duplicate_status(self): return self.duplicate @@ -116,13 +120,13 @@ class Workflow: self.nextflow_files.append(nextflow_file) self.nextflow_files = list(set(self.nextflow_files)) - def initialise(self): + def initialise(self, conditions_2_ignore = []): """Method that initialises the analysis of the worflow Keyword arguments: """ - + self.conditions_2_ignore = conditions_2_ignore #Right now i'm just gonna do everything in DSL2 #At this point there should only be one nextflow file @@ -182,17 +186,8 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen #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 + most_influential_conditions = self.get_workflow_main().get_most_influential_conditions() #If show values then we replace the the conditions ids with their values if(show_values): most_influential_conditions_values = {} @@ -206,7 +201,6 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen #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.")