Skip to content

SBML

momapy.sbml.io.sbml

Classes for reading SBML files.

Modules:

Name Description
reader

SBML reader with ReadingContext dataclass.

Classes:

Name Description
SBMLReader

SBMLReader

Bases: Reader

Methods:

Name Description
check_file

Check if this reader supports the given file.

read

Read a file and return the result.

check_file classmethod

check_file(file_path: str | PathLike)

Check if this reader supports the given file.

Parameters:

Name Type Description Default
file_path str | PathLike

Path of the file to check.

required

Returns:

Type Description
bool

True if the file is supported by this reader.

Source code in src/momapy/sbml/io/sbml/reader.py
@classmethod
def check_file(cls, file_path: str | os.PathLike):
    try:
        with open(file_path) as f:
            for line in f:
                if "<sbml " in line:
                    return True
        return False
    except Exception:
        return False

read classmethod

read(file_path: str | PathLike, with_annotations=True, with_notes=True) -> ReaderResult

Read a file and return the result.

Parameters:

Name Type Description Default
file_path str | PathLike

Path of the file to read.

required
options Any

Reader-specific options.

{}

Returns:

Type Description
ReaderResult

ReaderResult containing the read object.

Source code in src/momapy/sbml/io/sbml/reader.py
@classmethod
def read(
    cls,
    file_path: str | os.PathLike,
    with_annotations=True,
    with_notes=True,
) -> momapy.io.core.ReaderResult:
    sbml_document = lxml.objectify.parse(file_path)
    sbml = sbml_document.getroot()
    obj, annotations, notes = cls._make_main_obj(
        sbml_model=sbml.model,
        with_annotations=with_annotations,
        with_notes=with_notes,
    )
    result = momapy.io.core.ReaderResult(
        obj=obj,
        element_to_notes=notes,
        element_to_annotations=annotations,
        file_path=file_path,
    )
    return result