From 3152bdb38eca129e73665e6e065082a26d37dc95 Mon Sep 17 00:00:00 2001 From: George Marchment <georgemarchment@yahoo.fr> Date: Wed, 12 Feb 2025 14:09:46 +0100 Subject: [PATCH] Good version which works on DSL1 --- src/bioflowinsighterror.py | 8 ++-- src/include.py | 10 ++-- src/main.py | 84 +++++++++++++++++++-------------- src/nextflow_building_blocks.py | 2 - src/nextflow_file.py | 3 ++ src/workflow.py | 6 ++- 6 files changed, 65 insertions(+), 48 deletions(-) diff --git a/src/bioflowinsighterror.py b/src/bioflowinsighterror.py index d10e765..3166381 100644 --- a/src/bioflowinsighterror.py +++ b/src/bioflowinsighterror.py @@ -12,10 +12,10 @@ class BioFlowInsightError(Exception): def __init__(self, error, num=None, origin = None): self.origin = origin if(num!=None): - if(origin!=None): - super().__init__(f"[{num}] Error in the file '{self.origin.get_file_address()}': "+error) - else: - super().__init__(f"[{num}] {error}") + #if(origin!=None): + # super().__init__(f"[{num}] Error in the file '{self.origin.get_file_address()}': "+error) + #else: + super().__init__(f"[{num}] {error}") else: super().__init__(f"{error}") diff --git a/src/include.py b/src/include.py index fa11136..e2ee93f 100644 --- a/src/include.py +++ b/src/include.py @@ -38,9 +38,6 @@ class Include(Nextflow_Building_Blocks): def get_duplicate_status(self): return self.nextflow_file_origin.get_duplicate_status() - def get_root_directory(self): - return self.origin.get_root_directory() - #def get_list_name_includes(self): # if(self.get_duplicate_status()): @@ -67,7 +64,8 @@ class Include(Nextflow_Building_Blocks): if(address.split('/')[0] in ["$projectDir", "${projectDir}", "${baseDir}", "$baseDir"]): address = '/'.join(address.split('/')[1:]) - root = self.get_root_directory() + #root = self.get_root_directory() + root = self.nextflow_file_origin.get_root_directory() address = root+'/'+address if(os.path.isfile(address)): found_file = True @@ -79,14 +77,14 @@ class Include(Nextflow_Building_Blocks): found_file = True if(not found_file and os.path.isfile(address[:-3]+"/main.nf")): - self.nextflow_file = Nextflow_File(address[:-3]+"/main.nf", workflow = self.nextflow_file_origin.get_workflow()) + self.nextflow_file = Nextflow_File(address[:-3]+"/main.nf", workflow = self.nextflow_file_origin.get_workflow(), first_file=False) #TODO -> check if the nextflow_file is defined somewhere else? #In the cas the nextflow file is imported multiple times else: if(os.path.isfile(address)): - self.nextflow_file = Nextflow_File(address, workflow = self.nextflow_file_origin.get_workflow()) + self.nextflow_file = Nextflow_File(address, workflow = self.nextflow_file_origin.get_workflow(), first_file=False) else: address = os.path.normpath(address) raise BioFlowInsightError(f"Something went wrong in an include{self.get_string_line(self.get_code())}. No such file: '{address}'.", num = 10,origin=self) diff --git a/src/main.py b/src/main.py index 9167875..1fe16cd 100644 --- a/src/main.py +++ b/src/main.py @@ -85,38 +85,52 @@ class Main(Nextflow_Building_Blocks): 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 + if(self.nextflow_file.get_DSL()=="DSL2"): + 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 + elif(self.nextflow_file.get_DSL()=="DSL1"): + processes = self.get_modules_defined() + for p in processes: + if(p.is_initialised()): + for condition in p.origin.get_all_conditions(conditions = {}): + try: + temp = most_influential_conditions[condition] + except: + most_influential_conditions[condition] = 0 + most_influential_conditions[condition]+=1 + return most_influential_conditions + else: + raise Exception("This shouldn't happen") \ No newline at end of file diff --git a/src/nextflow_building_blocks.py b/src/nextflow_building_blocks.py index 78954c0..4f554df 100644 --- a/src/nextflow_building_blocks.py +++ b/src/nextflow_building_blocks.py @@ -83,8 +83,6 @@ class Nextflow_Building_Blocks: def get_name_file(self): return self.origin.get_name_file() - def get_root_directory(self): - return self.origin.get_root_directory() def get_rocrate_key(self, dico): return f"{self.get_file_address()[len(dico['temp_directory'])+1:]}#{self.get_name()}" diff --git a/src/nextflow_file.py b/src/nextflow_file.py index ba05366..0be98fa 100644 --- a/src/nextflow_file.py +++ b/src/nextflow_file.py @@ -40,6 +40,9 @@ class Nextflow_File(Nextflow_Building_Blocks): #GENERAL #---------------------- + def get_root_directory(self): + return self.workflow.get_root_directory() + def get_string_line(self, bit_of_code): return self.code.get_string_line(bit_of_code) diff --git a/src/workflow.py b/src/workflow.py index 21ddda5..35f48c9 100644 --- a/src/workflow.py +++ b/src/workflow.py @@ -56,7 +56,7 @@ class Workflow: with open(file, 'r') as f: txt= f.read() else: - raise BioFlowInsightError("Multiple Nextflow files found at the root with no 'main.nf' file: I don't know which want to select") + raise BioFlowInsightError("Multiple Nextflow files found at the root with no 'main.nf' file: I don't know which one to select") @@ -90,6 +90,10 @@ class Workflow: with open(self.output_dir / "debug" / "operations_in_call.nf",'w') as file: pass + def get_root_directory(self): + first_file = self.get_first_file() + return '/'.join(str(first_file.get_file_address()).split('/')[:-1])+"/" + def get_conditions_2_ignore(self): return self.conditions_2_ignore -- GitLab