Skip to content
Snippets Groups Projects
Commit 3fb7c24c authored by George Marchment's avatar George Marchment
Browse files

Added functionnality to romve certain conditions + get dico most influential conditions

parent 40ab502b
No related branches found
No related tags found
No related merge requests found
Pipeline #14352 failed with stage
in 2 minutes and 36 seconds
......@@ -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"
......
......@@ -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
......@@ -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):
......
......@@ -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)
......
......@@ -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.")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment