diff --git a/src/call.py b/src/call.py index 079cb9e67054c0f652e830e0d909e9755fc75188..53bb68015bbb2413a558c8abe88b92f31a58d329 100644 --- a/src/call.py +++ b/src/call.py @@ -1,6 +1,7 @@ import re import json import copy +import time from .code_ import Code @@ -37,6 +38,29 @@ class Call(Executor): else: return self.code.get_code() + + def simplify_code(self, new_name = ""): + code = self.get_code() + if(new_name!=""): + code = f"{new_name} = {code}" + tag_to_add = "//AREA TO ADD PARAMS" + code = f"{tag_to_add}\n{code}" + index = 1 + for param in self.parameters: + #Case the param is a call + if(param.get_type()=="Call"): + param_new_name = f"{self.get_first_element_called().get_name()}_param_{index}" + code = code.replace(param.get_code(), param_new_name) + new_bit = param.simplify_code(new_name = param_new_name) + code = code.replace(tag_to_add, f"{tag_to_add}\n{new_bit}") + + #Case the param is an operation + #TODO + index+=1 + return code.replace(tag_to_add, "").strip() + + + def get_type(self): return "Call" @@ -377,17 +401,14 @@ class Call(Executor): subworkflow = self.get_subworkflow_from_name(tab_call[0]) fun = self.get_function_from_name(tab_call[0]) if(process!=None and subworkflow==None and fun==None): - #If the lements need to duplicated -> then we need to duplicate it + #If the elements need to duplicated -> then we need to duplicate it temp = process if(self.get_duplicate_status()): - print(process.get_number_times_called()) if(process.get_number_times_called()>0): - print("here") temp = copy.deepcopy(process) temp.set_alias(f"{process.get_name()}_{process.get_number_times_called()}") self.first_element_called = temp temp.incremente_number_times_called() - print(process.get_name(), process.call) if(process==None and subworkflow!=None and fun==None): self.first_element_called = subworkflow if(process==None and subworkflow==None and fun!=None): diff --git a/src/main_DSL2.py b/src/main_DSL2.py index c396134bbf7a0e5e3ce3558d5101bd9676d30283..cc4a188df1d1f1bf1ae7c4e895cf963c234a40b7 100644 --- a/src/main_DSL2.py +++ b/src/main_DSL2.py @@ -15,6 +15,13 @@ class Main_DSL2(Nextflow_Building_Blocks): self.initialised = False self.conditions=None + def get_all_executors(self): + tab = [] + tab+=self.get_executors() + for sub in self.get_subworkflows_called(): + tab+=sub.get_executors() + return tab + def get_channels(self): return self.channels diff --git a/src/nextflow_file.py b/src/nextflow_file.py index 0b3e1b788d40643e902a4a3ad7a2b296fcdb4c5d..3a3054d5e713e91e777fd3d7ae326112fd1b5e43 100644 --- a/src/nextflow_file.py +++ b/src/nextflow_file.py @@ -133,6 +133,9 @@ class Nextflow_File(Nextflow_Building_Blocks): self.all_includes = [] self.added_2_rocrate = False + def get_all_executors(self): + return self.main.get_all_executors() + def extract_metadata(self): #When the start=="" it means it's the first analysis diff --git a/src/workflow.py b/src/workflow.py index 51437685d283d30102ff3153a82547ea9180a346..0a0013f1b9d293c5fb3efb826b8e44190c9d3984 100644 --- a/src/workflow.py +++ b/src/workflow.py @@ -97,6 +97,9 @@ class Workflow: def set_DSL(self, DSL): self.DSL = DSL + def get_all_executors(self): + return list(set(self.nextflow_file.get_all_executors())) + def get_is_a_git_repo(self): return is_git_directory(path = self.get_repo_adress()) @@ -734,6 +737,16 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen "subworkflow_section":subworkflow_section} return code, ankers + + def simplify_workflow_code(self): + code, ankers = self.write_workflow_into_one_file() + for exe in self.get_all_executors(): + #print(exe.get_code(), exe.get_type()) + if(exe.get_type()=="Call"): + print(exe.simplify_code()) + print() + + #Conert workflow to user_view only makes sense when the option duplicate is activated -> otherwise is doesn't make sense + it makes the analysis way more complicated def convert_workflow_2_user_view(self, relevant_processes = []):