From 64ce19e5a966f9af523337ae0816c16c9c550958 Mon Sep 17 00:00:00 2001 From: George Marchment <georgemarchment@yahoo.fr> Date: Sat, 14 Dec 2024 11:11:32 +0100 Subject: [PATCH] add rewrite call --- src/call.py | 29 +++++++++++++++++++++++++---- src/main_DSL2.py | 7 +++++++ src/nextflow_file.py | 3 +++ src/workflow.py | 13 +++++++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/call.py b/src/call.py index 079cb9e..53bb680 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 c396134..cc4a188 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 0b3e1b7..3a3054d 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 5143768..0a0013f 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 = []): -- GitLab