diff --git a/src/call.py b/src/call.py index ebe16efc5f75a29591377a3b97a00dfbf087e91e..592912314f451cd1c8052a650372611669637846 100644 --- a/src/call.py +++ b/src/call.py @@ -64,7 +64,7 @@ class Call(Executor): return self.code.get_code() - def simplify_code(self, new_name = ""): + def simplify_code(self, return_tab, new_name = ""): if(self.get_first_element_called().get_type()=="Function"): return self.get_code() else: @@ -113,18 +113,26 @@ class Call(Executor): if(temp==code): raise Exception("This souldn't happen") #code = code.replace(param.get_code(get_OG=True), param_new_name) - simplified_param = param.simplify_code() - lines = simplified_param.split('\n') - if(len(lines)==1): - new_bit = f"{param_new_name} = {lines[0]}" - else: - #If there is no '=' -> it means it's a single emit or channel - if(lines[-1].strip().find('=')==-1): - #if(re.fullmatch(r"\w+", lines[-1].strip())): - head = '\n'.join(lines[:-1]) - new_bit = f"{head}\n{param_new_name} = {lines[-1]}" - else: - new_bit = f"{param_new_name} = {simplified_param}" + params, last_operation= param.simplify_code(return_tab = True) + new_bit = "" + for p in params: + new_bit+=f"{p}\n" + new_bit+=f'{param_new_name} = {last_operation}' + #lines = simplified_param.split('\n') + #if(len(lines)==1): + # new_bit = f"{param_new_name} = {lines[0]}" + #else: + # #If there is no '=' -> it means it's a single emit or channel + # print(param.get_code(get_OG=True, replace_calls = False)) + # print(lines) + # print("-", lines[-1].strip()) + # print() + # if(lines[-1].strip().find('=')==-1): + # #if(re.fullmatch(r"\w+", lines[-1].strip())): + # head = '\n'.join(lines[:-1]) + # new_bit = f"{head}\n{param_new_name} = {lines[-1]}" + # else: + # new_bit = f"{param_new_name} = {simplified_param}" temp = code code = code.replace(tag_to_add, f"{tag_to_add}\n{new_bit}") if(temp==code): diff --git a/src/constant.py b/src/constant.py index 6993cdd25a23673e677bb46eb4cbcc0f0b9a3362..b46c2b52089f483310df095565d04a545517c9e5 100644 --- a/src/constant.py +++ b/src/constant.py @@ -109,7 +109,7 @@ DOUBLE_DOT_TUPLE = r"\(\s*\w+\s*(,\s*\w+\s*)+\)\s*=\s*([^\?\n]+)\s*\?([^\n]+)" END_OPERATOR = r' *(\(|{)' ILLEGAL_CHARCTER_BEFORE_POTENTIAL_CHANNELS = r"\w|\'|\"|\." ILLEGAL_CHARCTER_AFTER_POTENTIAL_CHANNELS = r"\w" -MERGE_OPERATIONS = r'\.\s*((merge|mix|concat|spread|join|phase|cross|combine|fromList|collect|fromPath|value|from|map|map_modified|fromFilePairs)\s*(\(|\{))'#I've added map to this list cause channels can appear in map can concatenating channels -> it's a strange way of doing it +MERGE_OPERATIONS = r'\.\s*((merge|mix|concat|spread|join|phase|cross|combine|fromList|collect|fromPath|value|from|fromFilePairs)\s*(\(|\{))'#I've added map to this list cause channels can appear in map can concatenating channels -> it's a strange way of doing it OPERATOR_IN_PIPE = r"\w+ *{[^}]*}|\w+ *\([^\)]*\)|\w+" SET_OPERATORS = ["choice", "separate", "tap", "into", "set"] TUPLE_EQUALS = r'\( *\w+( *, *\w+)+ *\) *=\s*(\w+)\s*\.' diff --git a/src/main.py b/src/main.py index 44f7654c93743f961eb56cd277308745650838e6..6101b3c6d635baf73edd40980977fbe2f89a90a9 100644 --- a/src/main.py +++ b/src/main.py @@ -55,7 +55,7 @@ class Main(Nextflow_Building_Blocks): for exe in sorted_executor_2_length: if(exe.get_type()=="Call" or exe.get_type()=="Operation"): old = exe.get_code(get_OG = True, remove_emit_and_take = True, replace_calls = False) - new = exe.simplify_code() + new = exe.simplify_code(return_tab = False) if(new!=old): temp = code code = code.replace(old, new, 1) diff --git a/src/operation.py b/src/operation.py index ebc158aba074b4a72718378f0a0e7f5d51034c29..4de0c436ebaf93922ed1b9eb8f3faccc831d8e61 100644 --- a/src/operation.py +++ b/src/operation.py @@ -713,7 +713,7 @@ class Operation(Executor): raise Exception("This souldn't happen") #Remove "e:" and "t:" for the subworkklfow inputs and outputs - if(remove_emit_and_take and code[:6] in ["e: ", "t: "] and self.get_artificial_status()): + if(remove_emit_and_take and code[:3] in ["e: ", "t: "] and self.get_artificial_status()): #print("-", code) code = code[3:] code = code.strip() @@ -938,7 +938,7 @@ class Operation(Executor): return operation_2_DSL2(code, self) #Method that rewrites operations to simplify it -> decompose it into multiple line -> to be able to manipulate the calls in a easier way - def simplify_code(self): + def simplify_code(self, return_tab): code = self.get_code(replace_calls =False, clean_pipe=True, remove_emit_and_take=True) #code = self.get_code(get_OG=True) index = 1 @@ -1022,11 +1022,15 @@ class Operation(Executor): raise Exception("This souldn't happen") temporary_index+=1 to_add.append(new_body) - to_add.reverse() - for c in to_add: - code = f"{c}\n{code}" - return code + if(return_tab): + last_operation = code + return to_add, last_operation + else: + for c in to_add: + code = f"{c}\n{code}" + return code + diff --git a/src/subworkflow.py b/src/subworkflow.py index b107bb34a71128cc334c8444915b3ed1e6258ba0..82883dc1fc7913836afbc64f86069a077d60bd6f 100644 --- a/src/subworkflow.py +++ b/src/subworkflow.py @@ -100,7 +100,7 @@ class Subworkflow(Main): def simplify_code(self): code = super().simplify_code() for o in self.emit: - code = code.replace(o.get_code(get_OG = True), o.simplify_code(), 1) + code = code.replace(o.get_code(get_OG = True), o.simplify_code(return_tab = False), 1) return code