Skip to content
Snippets Groups Projects
Commit 773221c7 authored by George Marchment's avatar George Marchment
Browse files

I've renamed the takes of a subworkflow when simplifying them -> so that the...

I've renamed the takes of a subworkflow when simplifying them -> so that the same name isn't deplicated (it created some problems in workflows with the same input channels) + i tried to add the id to channels -> it doesn't work (so it's in a comment)
parent 056e6ec9
No related branches found
No related tags found
No related merge requests found
Pipeline #14492 failed with stage
in 1 minute and 53 seconds
...@@ -101,5 +101,9 @@ class Channel(Nextflow_Building_Blocks): ...@@ -101,5 +101,9 @@ class Channel(Nextflow_Building_Blocks):
for source in self.get_source(): for source in self.get_source():
dico["edges"].append({'A':str(source), 'B':str(B), "label":self.get_name()}) dico["edges"].append({'A':str(source), 'B':str(B), "label":self.get_name()})
def simplify_code(self, return_tab):
code = self.get_code(get_OG=True)
code = code.replace(code, f"{code}_{id(self)}")
return code
...@@ -969,6 +969,11 @@ class Operation(Executor): ...@@ -969,6 +969,11 @@ class Operation(Executor):
dico_origin_2_replace[OG_code].append(f"operation_{operation_id}_{index}") dico_origin_2_replace[OG_code].append(f"operation_{operation_id}_{index}")
elif(o.get_type()=="Emitted"): elif(o.get_type()=="Emitted"):
dico_origin_2_replace[OG_code].append(o) dico_origin_2_replace[OG_code].append(o)
elif(o.get_type()=="Channel"):
#dico_origin_2_replace[OG_code].append(o)
None
else:
raise Exception("This shoudn't happen")
index += 1 index += 1
temporary_index = 1 temporary_index = 1
...@@ -985,36 +990,80 @@ class Operation(Executor): ...@@ -985,36 +990,80 @@ class Operation(Executor):
raise Exception("This souldn't happen") raise Exception("This souldn't happen")
#Case there are mutiple origins then: #Case there are mutiple origins then:
else: else:
temporary_channel = f"temporary_val_{id(self)}_{temporary_index}"
types = []
for e in dico_origin_2_replace[origin]:
types.append(e.get_type())
if(set(types)=={"Emitted"}):
#Case the multiple origins are emits
#For example
#if(){
# p1(ch1)
#} else {
# p1(ch2)
#}
#val = p1.out -> when wanting to rewrite this operation
calls = {}
for e in dico_origin_2_replace[origin]:
try:
temp = calls[e.emitted_by]
except:
calls[e.emitted_by] = []
calls[e.emitted_by].append(e.simplify_code(return_tab = False))
for c in calls:
#This is just one value
if(len(c.get_all_conditions())>1):
raise Exception("This shoudn't happen")
conditions = c.get_all_conditions()
if(conditions!=[]):
for condition in conditions:
new_body+=f"if({condition.get_value().strip()}) {{\n{temporary_channel} = {calls[c][0]}\n}}\n"
else:
values = set(calls[c])
if(len(values)>1):
raise Exception("This souldn't happen")
for val in values:
new_body+=f"\n{temporary_channel} = {val}"
#Case the multiple origins are channels
#For example #For example
#if(){ #if(){
# p1(ch1) # a = ...
#} else { #} else {
# p1(ch2) # a = ...
#} #}
#val = p1.out -> when wanting to rewrite this operation #b = a -> when wanting to rewrite this operation
calls = {} if(set(types)=={"Channel"}):
temporary_channel = f"temporary_val_{id(self)}_{temporary_index}" None
for e in dico_origin_2_replace[origin]: #operations = {}
#for c in dico_origin_2_replace[origin]:
try: # for source in c.get_source():
temp = calls[e.emitted_by] # try:
except: # temp = operations[source]
calls[e.emitted_by] = [] # except:
calls[e.emitted_by].append(e.simplify_code(return_tab = False)) # operations[source] = []
for c in calls: # operations[source].append(c.simplify_code(return_tab = False))
#This is just one value #for o in operations:
if(len(c.get_all_conditions())>1): # #Turning into one condition
raise Exception("This shoudn't happen") # conditions = []
conditions = c.get_all_conditions() # for condition in o.get_all_conditions():
if(conditions!=[]): # conditions.append(condition.get_value().strip())
for condition in conditions: # if(conditions!=[]):
new_body+=f"if({condition.get_value().strip()}) {{\n{temporary_channel} = {calls[c][0]}\n}}\n" # new_body+=f"if({' && '.join(conditions)}) {{\n{temporary_channel} = {operations[o][0]}\n}}\n"
else: # else:
values = set(calls[c]) # values = set(operations[o])
if(len(values)>1): # if(len(values)>1):
raise Exception("This souldn't happen") # raise Exception("This souldn't happen")
for val in values: # for val in values:
new_body+=f"\n{temporary_channel} = {val}" # new_body+=f"\n{temporary_channel} = {val}"
else:
raise Exception("This shoudn't happen")
#new_body+=temporary_channel #new_body+=temporary_channel
temp = code temp = code
code = code.replace(origin, temporary_channel) code = code.replace(origin, temporary_channel)
......
...@@ -5,7 +5,7 @@ import copy ...@@ -5,7 +5,7 @@ import copy
from .root import Root from .root import Root
from .main import Main from .main import Main
from .bioflowinsighterror import BioFlowInsightError from .bioflowinsighterror import BioFlowInsightError
from .outils import remove_jumps_inbetween_parentheses, get_dico_from_tab_from_id, check_if_element_in_tab_rocrate from .outils import remove_jumps_inbetween_parentheses, replace_group1, get_dico_from_tab_from_id, check_if_element_in_tab_rocrate
...@@ -99,10 +99,18 @@ class Subworkflow(Main): ...@@ -99,10 +99,18 @@ class Subworkflow(Main):
def simplify_code(self): def simplify_code(self):
code = super().simplify_code() code = super().simplify_code()
for o in self.emit: for o in self.emit:
code = code.replace(o.get_code(get_OG = True), o.simplify_code(return_tab = False), 1) code = code.replace(o.get_code(get_OG = True), o.simplify_code(return_tab = False), 1)
return code
#Renaming the takes in the subworkflow
name = self.get_alias()
for t in self.take:
if(len(t.get_gives())!=1):
raise Exception("This shoudn't happen")
ch = t.get_gives()[0]
code = replace_group1(code, fr"[^\w]({re.escape(ch.get_code())})[^\w]", f"{ch.get_code()}_{name}")
return code
def set_alias(self, alias): def set_alias(self, alias):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment