diff --git a/src/constant.py b/src/constant.py index 76ee6a62047ed825fa3618ff8728fd4a8ed29ef3..8f0885a560bc378d1b4fcbff96ce67b1e7098e56 100644 --- a/src/constant.py +++ b/src/constant.py @@ -123,7 +123,8 @@ END_PIPE_OPERATOR = r"\s*(\s*\|\s*\w+)+" # PROCESS #-------------------------- -FILE = r'file +(\w+) *\n|file +\( *(\w+) *\) *\n' +FILE = r'file +(\w+) *\n|file *\( *(\w+) *\) *\n' +PATH = r'path +(\w+) *\n|path *\( *(\w+) *\) *\n' FROM = r' from ([^\n]+)\n' INPUT = r"\n\s*input *:" INTO = r'into +([\w, ]+)' diff --git a/src/emitted.py b/src/emitted.py index 75ad5ac33df11031eb6a0157b6f2b5fa77f9e3d0..b29a0fa8fdf37fc2179a178720eea6927b7cbcea 100644 --- a/src/emitted.py +++ b/src/emitted.py @@ -16,6 +16,9 @@ class Emitted(Channel): self.source.append(emitted_by) self.emits = None #->this is the channel it's emits -> in the case of a subworkflow + def get_all_conditions(self): + return self.origin.get_all_conditions() + def simplify_code(self): code = self.get_code(get_OG=True) thing_which_emits = self.emitted_by.get_first_element_called() diff --git a/src/operation.py b/src/operation.py index 5f81ec7d12ce4f85b6ff2b138471c292b9d95281..28e984bc4250a2fbf40186f66e1ccc922080822e 100644 --- a/src/operation.py +++ b/src/operation.py @@ -912,15 +912,47 @@ class Operation(Executor): # return f"{head}\noperation_{operation_id}_{index} = {lines[-1]}" to_add = [] + dico_origin_2_replace = {} for o in self.origins: + try: + tmp = dico_origin_2_replace[o.get_code(get_OG=True)] + except: + dico_origin_2_replace[o.get_code(get_OG=True)] = [] if(o.get_type()=="Call"): #If it's not a function -> then we rewrite it if(o.get_first_element_called().get_type()!="Function"): to_add.append(add_origin_equals(o, index)) - code = code.replace(o.get_code(get_OG=True), f"operation_{operation_id}_{index}") + dico_origin_2_replace[o.get_code(get_OG=True)].append(f"operation_{operation_id}_{index}") elif(o.get_type()=="Emitted"): - code = code.replace(o.get_code(get_OG=True), o.simplify_code()) + dico_origin_2_replace[o.get_code(get_OG=True)].append(o) index += 1 + + temporary_index = 1 + for origin in dico_origin_2_replace: + if(len(dico_origin_2_replace[origin])<=1): + for val in dico_origin_2_replace[origin]: + if(type(val)==str): + code = code.replace(origin, val) + else: + code = code.replace(origin, val.simplify_code()) + #Case there are mutiple origins then: + else: + #TODO -> fix this problem if you have the courage to -> see at what extend it is used + raise BioFlowInsightError("TODO (update): The output of a emit is ambiguous -> there are multiple instance where it exits") + #print(dico_origin_2_replace) + #for e in dico_origin_2_replace[origin]: + # print(e.get_all_conditions()) + temporary_index+=1 + + #for o in self.origins: + # if(o.get_type()=="Call"): + # #If it's not a function -> then we rewrite it + # if(o.get_first_element_called().get_type()!="Function"): + # to_add.append(add_origin_equals(o, index)) + # code = code.replace(o.get_code(get_OG=True), f"operation_{operation_id}_{index}") + # elif(o.get_type()=="Emitted"): + # code = code.replace(o.get_code(get_OG=True), o.simplify_code()) + # index += 1 to_add.reverse() for c in to_add: diff --git a/src/process.py b/src/process.py index 40316241ea669199454a94afd61677960e5ab7dc..ec693ed614f6de064641db7568d4a42c040aec6c 100644 --- a/src/process.py +++ b/src/process.py @@ -259,16 +259,17 @@ class Process(Nextflow_Building_Blocks): for line in code.split("\n"): #Case there is a single channel as an input -> doesn't use from to import channel -> uses file (see https://github.com/nextflow-io/nextflow/blob/45ceadbdba90b0b7a42a542a9fc241fb04e3719d/docs/process.rst) - pattern = constant.FILE - for match in re.finditer(pattern, line+"\n"): - #In the first case it's "file ch" in the second "file (ch)" - try: - extracted = match.group(1).strip() - except: - extracted = match.group(2).strip() + patterns = [constant.FILE, constant.PATH] + for pattern in patterns: + for match in re.finditer(pattern, line+"\n"): + #In the first case it's "file ch" in the second "file (ch)" + try: + extracted = match.group(1).strip() + except: + extracted = match.group(2).strip() - add_channel(extracted) - self.raw_input_names.append(extracted) + add_channel(extracted) + self.raw_input_names.append(extracted) #Case there are multiple channels as input (e.g. channel1.mix(channel2)) diff --git a/src/workflow.py b/src/workflow.py index 49da4393ed0d3698a6d70bcc798640eda8bbcd77..cd71ce95ad994daa7beb4d0d8bf375b261348942 100644 --- a/src/workflow.py +++ b/src/workflow.py @@ -528,7 +528,11 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen def rewrite_and_initialise(self, code, processes_2_remove, render_graphs): temp_process_dependency_graph = self.graph.get_process_dependency_graph() - temp_spec_graph = self.graph.full_dico + temp_spec_graph = self.graph.full_dico + + #Remove the "_GG_\d+" + #code = re.sub(r"_GG_\d+", "", code) + #Write new code in temporary file temp_file = self.get_output_dir()/f"temp_{str(self)[-7:-2]}.nf" with open(temp_file, "w") as file: