Exemplo n.º 1
0
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])
Exemplo n.º 2
0
    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")