def is_complex_assembly(reaction: libsbml.Reaction, model: libsbml.Model): """ Returns true iff 'reaction' can be classified as a biomolecular complex assembly. Rules: - The reaction must have at least two reactants and exactly one product - The product must be annotated with the same non-empty set of identifiers as the full set of identifiers for all reactants. (This is assumed to mean that the product contains all and consists only of the specified reactants, so the reaction is a complex assembly.) :param reaction: libSBML Reaction object to classify as a transport. :param model: libsbml Model containing the 'reaction' object. :rtype: bool """ if len(reaction.getListOfReactants()) < 2 or len( reaction.getListOfProducts()) != 1: return False reactant_identifiers = set() for reactant in reaction.getListOfReactants(): reactant_species = model.getSpecies( reactant.toXMLNode().getAttrValue('species')) reactant_identifiers.update( extract_annotation_identifiers( reactant_species.getAnnotationString())) product = reaction.getListOfProducts()[0] product_species = model.getSpecies( product.toXMLNode().getAttrValue('species')) product_identifiers = set( extract_annotation_identifiers(product_species.getAnnotationString())) return len(reactant_identifiers ) > 0 and reactant_identifiers == product_identifiers
def equationStringFromReaction( reaction: libsbml.Reaction, sep_reversible: str = "⇆", sep_irreversible: str = "➞", modifiers: bool = False, ) -> str: """Create equation for reaction. :param reaction: SBML reaction instance for which equation is to be generated :param sep_reversible: escape sequence for reversible equation (<=>) separator :param sep_irreversible: escape sequence for irreversible equation (=>) separator :param modifiers: boolean flag to use modifiers :return equation string generated for the reaction """ left = _halfEquation(reaction.getListOfReactants()) right = _halfEquation(reaction.getListOfProducts()) if reaction.getReversible(): # '<=>' sep = sep_reversible else: # '=>' sep = sep_irreversible if modifiers: mods = _modifierEquation(reaction.getListOfModifiers()) if mods is None: return " ".join([left, sep, right]) else: return " ".join([left, sep, right, mods]) return " ".join([left, sep, right])
def is_transport(reaction: libsbml.Reaction, model: libsbml.Model): """ Returns true iff 'reaction' can be classified as a biological transport. Rules: - The reaction must have exactly one reactant and one product - The reactant and product must be annotated with the same non-empty set of identifiers (if they are annotated with the same identifiers, they are assumed to refer to the same biological object) - The reactant and product must reside in different compartments. :param reaction: libSBML Reaction object to classify as a transport. :param model: libsbml Model containing the 'reaction' object. :rtype: bool """ if len(reaction.getListOfReactants()) != 1 or len( reaction.getListOfProducts()) != 1: return False reactant, product = reaction.getListOfReactants( )[0], reaction.getListOfProducts()[0] reactant_species = model.getSpecies( reactant.toXMLNode().getAttrValue('species')) product_species = model.getSpecies( product.toXMLNode().getAttrValue('species')) reactant_compartment = model.getCompartment( reactant_species.getCompartment()) product_compartment = model.getCompartment( product_species.getCompartment()) reactant_identifiers = set( extract_annotation_identifiers(reactant_species.getAnnotationString())) product_identifiers = set( extract_annotation_identifiers(product_species.getAnnotationString())) return (len(reactant_identifiers) > 0 and reactant_identifiers.intersection(product_identifiers) and reactant_compartment != product_compartment)
def __init__(self, reaction: libsbml.Reaction): super().__init__(reaction) # references, not actual species self.reactants = list(reaction.getListOfReactants()) self.products = list(reaction.getListOfProducts()) # inhibitors / activators self.modifiers = list(reaction.getListOfModifiers()) self.reversible: bool = reaction.getReversible() self.kl = reaction.getKineticLaw() self.unit = libsbml.UnitDefinition.printUnits( self.kl.getDerivedUnitDefinition()) self.regex = re.compile( "(" + "|".join([p.id for p in self.kl.getListOfParameters()]) + ")", re.VERBOSE, ) self.text_formula = self.regex.sub(f"{self.id}_\\1", self.kl.formula) self.formula = compile(self.text_formula, "<string>", "eval")