Skip to content

sbml

SBMLParser(sbml)

Converting MetaCyc files to a Neo4j database. Documentation on the MetaCyc files and format FAQs can be found at:

Parameters:

Name Type Description Default
sbml Union[str, Path]

The path to the MetaCyc SBML file to convert.

required

Attributes:

Name Type Description
sbml_file

Filepath to the input SBML file.

Source code in parser/sbml.py
def __init__(self, sbml: Union[str, Path]):
    self.sbml_file = validate_path(sbml)
    if not self.sbml_file:
        raise ValueError("Missing SBML file path.")
    logger.info(f"SBML file: {self.sbml_file}")

Add gene products to a reaction. This could be complicated where the child nodes could be:

Parameters:

Name Type Description Default
reactions Iterable[libsbml.Reaction]

An iterable of SBML reactions.

required
Source code in parser/sbml.py
def collect_reaction_gene_product_links(self, reactions: Iterable[libsbml.Reaction]):
    """Add gene products to a reaction. This could be complicated where the child nodes could
    be:

    #. GeneProductRef
    #. fbc:or -> GeneProductRef
    #. fbc:and -> GeneProductRef
    #. fbc:or -> {fbc:and -> GeneProductRef, GeneProductRef}

    Args:
        reactions: An iterable of SBML reactions.
    """
    # We need to know the metaId of children of each geneSet / geneComplex.
    # Also need to name the geneSet / geneComplex nodes.
    # Note that the same set/complex can catalyze multiple reactions.
    gene_sets: dict[str, set[str]] = {}
    gene_complexes: dict[str, set[str]] = {}

    # For each reaction, we store its associated gene products
    reaction_genes = {}
    for r in tqdm(reactions, desc="Associated GeneProduct"):
        mcid = r.getId()
        gpa = r.getPlugin("fbc").getGeneProductAssociation()
        if gpa is not None:
            gpa: libsbml.GeneProductAssociation
            node = gpa.getAssociation()
            reaction_genes[mcid] = self._parse_gene_association_nodes(
                node, gene_sets, gene_complexes
            )

    return reaction_genes, gene_sets, gene_complexes