diff --git a/src/call.py b/src/call.py index 1f8bd77478bbd6a0aaf1559bd3eb1cff2e7a7de8..d89713eef48812e0ee552ce8ef14035b512ff2f0 100644 --- a/src/call.py +++ b/src/call.py @@ -328,34 +328,39 @@ class Call(Executor): #If they are not -> we check that the right number isn't implied else: #TODO this needs to be checked - #num_inputs = 0 - #for p in self.parameters: - # if(p.get_type()=="Call"): - # num_inputs+= p.get_nb_outputs() - # elif(p.get_type()=="Emitted"): - # emitted = p - # if(emitted.get_emitted_by().get_type()=="Subworkflow"): - # if(emitted.get_emits()==None): - # num_inputs+= emitted.get_emitted_by().get_nb_emit() - # else: - # num_inputs+=1 - # elif(emitted.get_emitted_by().get_type()=="Process"): - # if(emitted.get_emits()==None): - # num_inputs+= emitted.get_emitted_by().get_nb_outputs() - # else: - # num_inputs+=1 - # else: - # raise Exception("This shoudn't happen") - # else: - # #Cause in case channel, operation or emit, it is only one channel given - # num_inputs+=1 - #if(num_inputs==process.get_nb_inputs()): - # for p in self.parameters: - # add_parameter(p) - # - #else: - # raise BioFlowInsightError(f"Not the same number of parameters given as input for the process '{process.get_alias()}'{self.get_string_line(self.get_code(get_OG=True))}.", num=2, origin=self) - raise BioFlowInsightError(f"Not the same number of parameters given as input for the process '{process.get_alias()}'{self.get_string_line(self.get_code(get_OG=True))}.", type=2, origin=self) + num_inputs = 0 + for p in self.parameters: + if(p.get_type()=="Call"): + num_inputs+= p.get_nb_outputs() + elif(p.get_type()=="Emitted"): + emitted = p + #TODO -> check if this code is ever entered + print(emitted.get_code(), emitted.emits) + print(emitted.get_emitted_by().get_first_element_called()) + print(emitted.get_emits()) + print(emitted.get_emitted_by().get_nb_outputs()) + if(emitted.get_emitted_by().get_type()=="Subworkflow"): + if(emitted.get_emits()==None): + num_inputs+= emitted.get_emitted_by().get_nb_emit() + else: + num_inputs+=1 + elif(emitted.get_emitted_by().get_type()=="Process"): + if(emitted.get_emits()==None): + num_inputs+= emitted.get_emitted_by().get_nb_outputs() + else: + num_inputs+=1 + else: + raise Exception("This shoudn't happen") + else: + #Cause in case channel, operation or emit, it is only one channel given + num_inputs+=1 + if(num_inputs==process.get_nb_inputs()): + for p in self.parameters: + add_parameter(p) + + else: + raise BioFlowInsightError(f"Not the same number of parameters given as input for the process '{process.get_alias()}'{self.get_string_line(self.get_code(get_OG=True))}.", num=2, origin=self) + #raise BioFlowInsightError(f"Not the same number of parameters given as input for the process '{process.get_alias()}'{self.get_string_line(self.get_code(get_OG=True))}.", type=2, origin=self) elif(self.get_first_element_called().get_type()=="Subworkflow"): sub = self.get_first_element_called() diff --git a/src/emitted.py b/src/emitted.py index e452b381bde58adacb0854721d1e109b4741fecc..bed4c40eeaeeeb5eb085c8771cd8ac8c2ce636ad 100644 --- a/src/emitted.py +++ b/src/emitted.py @@ -44,47 +44,59 @@ class Emitted(Channel): def set_emits_decimal(self, decimal): thing_which_emits = self.emitted_by.get_first_element_called() - self.emits = thing_which_emits.get_emit()[decimal] + if(thing_which_emits.get_type()=="Subworkflow"): + self.emits = thing_which_emits.get_emit()[decimal] + elif(thing_which_emits.get_type()=="Process"):#Case it's a process + self.emits =thing_which_emits + else: + raise Exception("This shoudn't happen!") def set_emits_name(self, name): thing_which_emits = self.emitted_by.get_first_element_called() - emitted = thing_which_emits.get_emit() - for o in emitted: - code = o.get_code() - if(code[:len("e:")]=="e:"): - code =code[len("e:"):].strip() - if(name==code): - self.emits = o - else: - for match in re.finditer(constant.WORD_EQUALS, code): - if(name==match.group(1)): - self.emits = o + if(thing_which_emits.get_type()=="Subworkflow"): + emitted = thing_which_emits.get_emit() + + for o in emitted: + code = o.get_code() + if(code[:len("e:")]=="e:"): + code =code[len("e:"):].strip() + if(name==code): + self.emits = o + else: + for match in re.finditer(constant.WORD_EQUALS, code): + if(name==match.group(1)): + self.emits = o + elif(thing_which_emits.get_type()=="Process"): + outputs = thing_which_emits.get_outputs() + for o in outputs: + if(bool(re.search(fr"emit *\: *{re.escape(name)}", o))): + self.emits = thing_which_emits + else: + raise Exception("This shoudn't happen!") if(self.emits==None): raise Exception(f"No emitted matched with '{name}' (in file '{self.get_file_address()}'). Should match with emittes from '{self.emitted_by.get_first_element_called().get_name()}' (in file '{self.emitted_by.get_file_address()}'") def set_emits(self, input): thing_which_emits = self.emitted_by.get_first_element_called() - if(thing_which_emits.get_type()=="Process"): - #TODO -> i don't konw what to do with this - #self.emits = thing_which_emits - None - + if(input!=""): + try: + input = int(input) + self.set_emits_decimal(decimal=input) + except: + self.set_emits_name(name=input) else: - if(input!=""): - try: - input = int(input) - self.set_emits_decimal(decimal=input) - except: - self.set_emits_name(name=input) + if(thing_which_emits.get_type()=='Subworkflow'): + if(len(thing_which_emits.emit)!=1): + raise BioFlowInsightError(f"One channel was expected in the emit '{self.get_code()}'. Even though multiple emits are defined for the workflow '{self.emitted_by.get_first_element_called().get_name()}'", type=6, origin=self) + self.emits = thing_which_emits.emit[0] + elif(thing_which_emits.get_type()=="Process"): + if(len(thing_which_emits.get_outputs())!=1): + raise BioFlowInsightError(f"One channel was expected in the emit '{self.get_code()}'. Even though multiple emits are defined for the process '{self.emitted_by.get_first_element_called().get_name()}'", type=6, origin=self) + self.emits = thing_which_emits else: - if(thing_which_emits.get_type()=='Subworkflow'): - if(len(thing_which_emits.emit)!=1): - raise BioFlowInsightError(f"One channel was expected in the emit '{self.get_code()}'. Even though multiple emits are defined for the workflow '{self.emitted_by.get_first_element_called().get_name()}'", type=6, origin=self) - self.emits = thing_which_emits.emit[0] - else: - raise Exception("This shoudn't happen!") + raise Exception("This shoudn't happen!") def get_structure(self, dico, B): emits = self.get_emitted_by()