Skip to content

brenda_transformer

GenericTreeTransformer

Bases: BaseTransformer

Transform extracted values from bottom-up.

Formats the tree into a dictionary with child token types as keys.

ReactionTreeTransformer

Bases: GenericTreeTransformer

Commentary in (...) are on substrates, and in |...| on products.

reaction(children)

Parse the reaction in the description node.

There should be three parts
  • The left-hand-side of the reaction, which is a list of chemical names, separated by <space>+<space>.
  • The separator <space>=<space>.
  • The right-hand-side of the reaction, which is a list of chemical names, separated by <space>+<space>.
Source code in parser/brenda_transformer.py
def reaction(self, children: list[Token]) -> Token:
    """Parse the reaction in the description node.

    There should be three parts:
        - The left-hand-side of the reaction, which is a list of chemical
            names, separated by ``<space>+<space>``.
        - The separator ``<space>=<space>``.
        - The right-hand-side of the reaction, which is a list of chemical
            names, separated by ``<space>+<space>``.
    """
    reaction = " ".join([x.value.strip() for x in children])
    reaction = self._fix_string(reaction)
    if " = " not in reaction:
        return Token("reaction_description", reaction)
    lhs, rhs = reaction.split(" = ")
    lhs = lhs.split(" + ")
    rhs = rhs.split(" + ")
    res = {"lhs": lhs, "rhs": rhs}
    return Token("reaction", res)

reversibility(children)

r for reversible, ir for irreversible, ? for unknown.

Source code in parser/brenda_transformer.py
def reversibility(self, children: list[Token]) -> Token:
    """``r`` for reversible, ``ir`` for irreversible, ``?`` for unknown."""
    x = children[0].value
    x = x.replace("{", "")
    x = x.replace("}", "")
    if not x:
        x = "?"
    return Token("reversibility", x)