diff --git a/src/subworkflow.py b/src/subworkflow.py index e8e1a4b2c764fd8528556257cfa152a40ac8768e..7bff264c2e2ddfdd338c59c0935f10bea33fa374 100644 --- a/src/subworkflow.py +++ b/src/subworkflow.py @@ -18,9 +18,12 @@ class Subworkflow(Main): self.printed_name = self.name #These are the different parts of of a subworkflow -> work corresponds to the main self.take = [] + self.take_code = "" self.takes_channels = [] self.work = None + self.main_code = "" self.emit = [] + self.emit_code = "" self.call = [] #These are probably to remove @@ -31,6 +34,8 @@ class Subworkflow(Main): self.called_by = []#List of calls self.number_times_copied = 0 + self.elements_in_order = True + def copy(self): sub = copy.copy(self) sub.alias = self.name @@ -100,6 +105,21 @@ class Subworkflow(Main): def simplify_code(self): code = super().simplify_code() + #Putting the take, main and emit in that order, if needs be + if(not self.elements_in_order): + w = copy.deepcopy(self) + temp_take, temp_work, temp_emit = w.take, w.work, w.emit + w.code = Code(code, origin=w, initialise=False) + w.initialise_parts() + w.take, w.work, w.emit = temp_take, temp_work, temp_emit + code = re.sub(r"take *:\s+"+re.escape(w.take_code), "//anker", code) + code = re.sub(r"main *:\s+"+re.escape(w.main_code), "//anker", code) + code = re.sub(r"emit *:\s+"+re.escape(w.emit_code), "//anker", code) + new_body = f"take:\n\t\t{w.take_code}\n\n\tmain:\n\t\t{w.main_code}\n\n\temit:\n\t\t{w.emit_code}\n\n" + code = code.replace("//anker", new_body, 1) + code = code.replace("//anker", "") + + for o in self.emit: code = code.replace(o.get_code(get_OG = True), o.simplify_code(return_tab = False), 1) @@ -206,7 +226,7 @@ class Subworkflow(Main): def get_work(self): return self.work.get_code() - #TODO -> when return the code of a subworkflow -> i return evrything (not just the work) -> check if that is correct + #Method which initiliases the different parts of a workflow (take/main/emit) def initialise_parts(self): code = self.get_code() @@ -241,6 +261,7 @@ class Subworkflow(Main): self.take = Code(code[take_pos[1]:emit_pos[0]].strip(), origin = self, initialise=False) self.emit = Code(code[emit_pos[1]:main_pos[0]].strip(), origin = self, initialise=False) self.work = Code(code[main_pos[1]:code.rfind('}')].strip(), origin = self, initialise=False) + self.elements_in_order = False else: raise Exception('You need to add a case') #Case nothing is there @@ -275,8 +296,15 @@ class Subworkflow(Main): self.emit = Code(code[emit_pos[1]:code.rfind('}')].strip(), origin = self, initialise=False) firt_curly = code.find("{") self.work = Code(code[firt_curly+1:emit_pos[0]].strip(), origin = self, initialise=False) + self.elements_in_order else: raise Exception("Not possible!") + if(self.take!=[]): + self.take_code = self.take.get_code() + if(self.work!=None): + self.main_code = self.work.get_code() + if(self.emit!=[]): + self.emit_code = self.emit.get_code() def get_channel_from_name_takes(self, name): for c in self.takes_channels: