def validate_equation(self): ok = False test_reaction = cobra.Reaction( "xxxx_cnapy_test_reaction", name="cnapy test reaction") with self.parent.appdata.project.cobra_py_model as model: model.add_reaction(test_reaction) try: eqtxt = self.equation.text().rstrip() if len(eqtxt) > 0 and eqtxt[-1] == '+': turn_red(self.equation) else: test_reaction.build_reaction_from_string(eqtxt) turn_white(self.equation) ok = True except ValueError: turn_red(self.equation) try: test_reaction = self.parent.appdata.project.cobra_py_model.reactions.get_by_id( "xxxx_cnapy_test_reaction") self.parent.appdata.project.cobra_py_model.remove_reactions( [test_reaction], remove_orphans=True) except KeyError: pass return ok
def apply(self): try: self.reaction.id = self.id.text() except ValueError: turn_red(self.id) QMessageBox.information( self, 'Invalid id', 'Could not apply changes identifier ' + self.id.text() + ' already used.') else: self.reaction.name = self.name.text() self.reaction.build_reaction_from_string(self.equation.text()) self.reaction.lower_bound = float(self.lower_bound.text()) self.reaction.upper_bound = float(self.upper_bound.text()) self.reaction.objective_coefficient = float(self.coefficent.text()) self.reaction.gene_reaction_rule = self.gene_reaction_rule.text() self.reaction.annotation = {} rows = self.annotation.rowCount() for i in range(0, rows): key = self.annotation.item(i, 0).text() if self.annotation.item(i, 1) is None: value = "" else: value = self.annotation.item(i, 1).text() self.reaction.annotation[key] = value self.changed = False self.reactionChanged.emit(self.reaction)
def apply(self): try: self.metabolite.id = self.id.text() except ValueError: turn_red(self.id) QMessageBox.information( self, 'Invalid id', 'Could not apply changes identifier ' + self.id.text()+' already used.') else: self.metabolite.name = self.name.text() self.metabolite.formula = self.formula.text() if self.charge.text() == "": self.metabolite.charge = None else: self.metabolite.charge = int(self.charge.text()) self.metabolite.compartment = self.compartment.text() self.metabolite.annotation = {} rows = self.annotation.rowCount() for i in range(0, rows): key = self.annotation.item(i, 0).text() if self.annotation.item(i, 1) is None: value = "" else: value = self.annotation.item(i, 1).text() self.metabolite.annotation[key] = value self.changed = False self.metaboliteChanged.emit(self.metabolite)
def validate_gene_reaction_rule(self): try: _x = float(self.gene_reaction_rule.text()) except ValueError: turn_red(self.gene_reaction_rule) return False else: turn_white(self.gene_reaction_rule) return True
def validate_coefficient(self): try: _x = float(self.coefficent.text()) except ValueError: turn_red(self.coefficent) return False else: turn_white(self.coefficent) return True
def validate_upperbound(self): try: _x = float(self.upper_bound.text()) except ValueError: turn_red(self.upper_bound) return False else: turn_white(self.upper_bound) return True
def validate_charge(self): try: if self.charge.text() != "": _x = int(self.charge.text()) except ValueError: turn_red(self.charge) return False else: turn_white(self.charge) return True
def validate_name(self): with self.parent.appdata.project.cobra_py_model as model: try: r = cobra.Reaction(id="testid", name=self.name.text()) model.add_reaction(r) except ValueError: turn_red(self.name) return False else: turn_white(self.name) return True
def validate_name(self): with self.appdata.project.cobra_py_model as model: try: m = cobra.Metabolite(id="test_id", name=self.name.text()) model.add_metabolites([m]) except ValueError: turn_red(self.name) return False else: turn_white(self.name) return True
def validate_compartment(self): try: if ' ' in self.compartment.text(): turn_red(self.compartment) return False if '-' in self.compartment.text(): turn_red(self.compartment) return False _m = cobra.Metabolite(id="test_id", name=self.compartment.text()) except ValueError: turn_red(self.compartment) return False else: turn_white(self.compartment) return True
def validate_id(self): with self.appdata.project.cobra_py_model as model: text = self.id.text() if text == "": turn_red(self.id) return False if ' ' in text: turn_red(self.id) return False try: m = cobra.Metabolite(id=self.id.text()) model.add_metabolites([m]) except ValueError: turn_red(self.id) return False else: turn_white(self.id) return True