diff --git a/src/emitted.py b/src/emitted.py index 42e547598f50bb9263d87ce4192ce4a6dc9fd569..ba60636140a32cb40feed04c7d9bbb8674a86668 100644 --- a/src/emitted.py +++ b/src/emitted.py @@ -25,6 +25,12 @@ class Emitted(Channel): old_name = thing_which_emits.get_alias() new_call_name = thing_which_emits.get_alias_and_id() code = re.sub(fr'{re.escape(old_name)} *\.', f'{new_call_name}.', code) + #In the cas of a subworklfow -> we replace the last word of the emit by a rewritten version containing the suborklow's alias (to avoid duplicates) + thing_which_emits = self.emitted_by.get_first_element_called() + if(thing_which_emits.get_type()=="Subworkflow"): + if(code.count('.')==2): + last_word = code.split(".")[-1] + code = code.replace(last_word, f"{last_word}_{thing_which_emits.get_alias()}") return code def get_emitted_by(self): diff --git a/src/subworkflow.py b/src/subworkflow.py index d9c8ff016b55dfcd82538479b9aca39eaf4814ee..7fc58c97cdfcef5b6797fa8c8511f46aec4f56aa 100644 --- a/src/subworkflow.py +++ b/src/subworkflow.py @@ -116,20 +116,56 @@ class Subworkflow(Main): ch = t.get_gives()[0] code_up_to_emit = replace_group1(code_up_to_emit, fr"[^\w]({re.escape(ch.get_code())})[^\w]", f"{ch.get_code()}_{name}") - #Renaming the takes in the emits -> if the takes are given as emits + + + #Renaming the emits so that the name of the subworkflow appears in the param name + #The renaming of the emits outside the subworkflow is done at the emit level (when we simplify the emit) for e in self.emit: - channels_take = [] - for t in self.take: - channels_take.append(t.get_gives()[0]) - re_write_channel = False - for o in e.origins: - if(o in channels_take): - re_write_channel = True - if(re_write_channel): + if(len(e.gives)==1): + ch = e.gives[0] + temp = code_after_emit + code_after_emit = replace_group1(code_after_emit, fr"[^\w]({re.escape(ch.get_code())})[^\w]", f"{ch.get_code()}_{name}") + if(temp==code_after_emit): + raise Exception("This shoudn't happen -> code hasn't been replaced") + else: ch = e.origins[0] + temp = code_after_emit code_after_emit = replace_group1(code_after_emit, fr"[^\w]({re.escape(ch.get_code())})[^\w]", f"{ch.get_code()}_{name}") - - code = code_up_to_emit+code_after_emit + code_up_to_emit+=f"\n{ch.get_code()}_{name} = {ch.get_code()}" + if(temp==code_after_emit): + raise Exception("This shoudn't happen -> code hasn't been replaced") + + + #In the emits replacing the 'ch = ....' by 'ch' and adding 'ch = ....' at the end of the body + to_replace = [] + for match in re.finditer(r"(\w+) *= *.+", code_after_emit): + old, new = match.group(0), match.group(1) + to_replace.append((old, new)) + for r in to_replace: + old, new = r + code_up_to_emit+=f"\n{old}" + temp = code_after_emit + code_after_emit = code_after_emit.replace(old, new) + if(temp==code_after_emit): + raise Exception("This shoudn't happen -> code hasn't been replaced") + + ##Renaming the takes in the emits -> if the takes are given as emits + #for e in self.emit: + # channels_take = [] + # for t in self.take: + # channels_take.append(t.get_gives()[0]) + # re_write_channel = False + # for o in e.origins: + # if(o in channels_take): + # re_write_channel = True + # if(re_write_channel): + # ch = e.origins[0] + # temp = code_after_emit + # code_after_emit = replace_group1(code_after_emit, fr"[^\w]({re.escape(ch.get_code())})[^\w]", f"{ch.get_code()}_{name}") + # if(temp==code_after_emit): + # raise Exception("This shoudn't happen -> code hasn't been replaced") + + code = code_up_to_emit+'\n'+code_after_emit return code diff --git a/src/workflow.py b/src/workflow.py index b7497c73324ab07a11eff786fd0d917d5bb9e8a0..1277eda50783d26b09f664a61b5666115bafff87 100644 --- a/src/workflow.py +++ b/src/workflow.py @@ -1221,7 +1221,7 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen code = code.replace("$OR$", "||") code = self.put_modified_operations_back(code, map_element_dico) code = remove_extra_jumps(format_with_tabs(code)) - code = self.remove_GG_from_code(code) + #code = self.remove_GG_from_code(code) f = open(self.get_output_dir()/ "debug" / "rewritten.nf", "w") f.write(code) f.close()