Skip to content

SBGN-ML

momapy.sbgn.io.sbgnml

Classes for reading and writing SBGN-ML files

Classes:

Name Description
SBGNML0_2Reader

Class for SBGN-ML 0.2 reader objects

SBGNML0_2Writer

Class for SBGN-ML 0.2 writer objects

SBGNML0_3Reader

Class for SBGN-ML 0.3 reader objects

SBGNML0_3Writer

Class for SBGN-ML 0.3 writer objects

SBGNML0_2Reader

Bases: _SBGNMLReader

Class for SBGN-ML 0.2 reader objects

Methods:

Name Description
check_file

Return true if the given file is an SBGN-ML 0.2 document, false otherwise

read

Read an SBGN-ML file and return a reader result object

check_file classmethod

check_file(file_path)

Return true if the given file is an SBGN-ML 0.2 document, false otherwise

Source code in src/momapy/sbgn/io/sbgnml.py
@classmethod
def check_file(cls, file_path):
    """Return `true` if the given file is an SBGN-ML 0.2 document, `false` otherwise"""
    with open(file_path) as f:
        for line in f:
            if "http://sbgn.org/libsbgn/0.2" in line:
                return True
    return False

read classmethod

read(file_path: str | PathLike, return_type: Literal['map', 'model', 'layout'] = 'map', with_model: bool = True, with_layout: bool = True, with_annotations: bool = True, with_notes: bool = True, with_styles: bool = True, xsep: float = 0, ysep: float = 0) -> ReaderResult

Read an SBGN-ML file and return a reader result object

Source code in src/momapy/sbgn/io/sbgnml.py
@classmethod
def read(
    cls,
    file_path: str | os.PathLike,
    return_type: typing.Literal["map", "model", "layout"] = "map",
    with_model: bool = True,
    with_layout: bool = True,
    with_annotations: bool = True,
    with_notes: bool = True,
    with_styles: bool = True,
    xsep: float = 0,
    ysep: float = 0,
) -> momapy.io.ReaderResult:
    """Read an SBGN-ML file and return a reader result object"""

    sbgnml_document = lxml.objectify.parse(file_path)
    sbgnml_sbgn = sbgnml_document.getroot()
    obj, annotations, notes = cls._make_main_obj_from_sbgnml_map(
        sbgnml_map=sbgnml_sbgn.map,
        return_type=return_type,
        with_model=with_model,
        with_layout=with_layout,
        with_annotations=with_annotations,
        with_notes=with_notes,
        xsep=xsep,
        ysep=ysep,
    )
    result = momapy.io.ReaderResult(
        obj=obj,
        notes=notes,
        annotations=annotations,
        file_path=file_path,
    )
    return result

SBGNML0_2Writer

Bases: _SBGNMLWriter

Class for SBGN-ML 0.2 writer objects

Methods:

Name Description
write

Write an object to a file and return a writer result using the writer

write classmethod

write(obj: SBGNMap, file_path, annotations=None, notes=None, ids=None, with_render_information=True, with_annotations=True, with_notes=True)

Write an object to a file and return a writer result using the writer

Source code in src/momapy/sbgn/io/sbgnml.py
@classmethod
def write(
    cls,
    obj: momapy.sbgn.core.SBGNMap,
    file_path,
    annotations=None,
    notes=None,
    ids=None,
    with_render_information=True,
    with_annotations=True,
    with_notes=True,
):
    if annotations is None:
        annotations = {}
    if ids is None:
        ids = {}
    sbgnml_sbgn = cls._make_lxml_element("sbgn", nsmap=cls._NSMAP)
    sbgnml_map = cls._make_sbgnml_map_from_map(
        obj,
        annotations=annotations,
        notes=notes,
        ids=ids,
        with_render_information=with_render_information,
        with_annotations=with_annotations,
        with_notes=with_notes,
    )
    sbgnml_sbgn.append(sbgnml_map)
    with open(file_path, "w") as f:
        f.write(
            lxml.etree.tostring(
                sbgnml_sbgn, pretty_print=True, xml_declaration=True
            ).decode()
        )

SBGNML0_3Reader

Bases: _SBGNMLReader

Class for SBGN-ML 0.3 reader objects

Methods:

Name Description
check_file

Return true if the given file is an SBGN-ML 0.3 document, false otherwise

read

Read an SBGN-ML file and return a reader result object

check_file classmethod

check_file(file_path)

Return true if the given file is an SBGN-ML 0.3 document, false otherwise

Source code in src/momapy/sbgn/io/sbgnml.py
@classmethod
def check_file(cls, file_path):
    """Return `true` if the given file is an SBGN-ML 0.3 document, `false` otherwise"""
    with open(file_path) as f:
        for line in f:
            if "http://sbgn.org/libsbgn/0.3" in line:
                return True
    return False

read classmethod

read(file_path: str | PathLike, return_type: Literal['map', 'model', 'layout'] = 'map', with_model: bool = True, with_layout: bool = True, with_annotations: bool = True, with_notes: bool = True, with_styles: bool = True, xsep: float = 0, ysep: float = 0) -> ReaderResult

Read an SBGN-ML file and return a reader result object

Source code in src/momapy/sbgn/io/sbgnml.py
@classmethod
def read(
    cls,
    file_path: str | os.PathLike,
    return_type: typing.Literal["map", "model", "layout"] = "map",
    with_model: bool = True,
    with_layout: bool = True,
    with_annotations: bool = True,
    with_notes: bool = True,
    with_styles: bool = True,
    xsep: float = 0,
    ysep: float = 0,
) -> momapy.io.ReaderResult:
    """Read an SBGN-ML file and return a reader result object"""

    sbgnml_document = lxml.objectify.parse(file_path)
    sbgnml_sbgn = sbgnml_document.getroot()
    obj, annotations, notes = cls._make_main_obj_from_sbgnml_map(
        sbgnml_map=sbgnml_sbgn.map,
        return_type=return_type,
        with_model=with_model,
        with_layout=with_layout,
        with_annotations=with_annotations,
        with_notes=with_notes,
        xsep=xsep,
        ysep=ysep,
    )
    result = momapy.io.ReaderResult(
        obj=obj,
        notes=notes,
        annotations=annotations,
        file_path=file_path,
    )
    return result

SBGNML0_3Writer

Bases: _SBGNMLWriter

Class for SBGN-ML 0.3 writer objects

Methods:

Name Description
write

Write an object to a file and return a writer result using the writer

write classmethod

write(obj: SBGNMap, file_path, annotations=None, notes=None, ids=None, with_render_information=True, with_annotations=True, with_notes=True)

Write an object to a file and return a writer result using the writer

Source code in src/momapy/sbgn/io/sbgnml.py
@classmethod
def write(
    cls,
    obj: momapy.sbgn.core.SBGNMap,
    file_path,
    annotations=None,
    notes=None,
    ids=None,
    with_render_information=True,
    with_annotations=True,
    with_notes=True,
):
    if annotations is None:
        annotations = {}
    if ids is None:
        ids = {}
    sbgnml_sbgn = cls._make_lxml_element("sbgn", nsmap=cls._NSMAP)
    sbgnml_map = cls._make_sbgnml_map_from_map(
        obj,
        annotations=annotations,
        notes=notes,
        ids=ids,
        with_render_information=with_render_information,
        with_annotations=with_annotations,
        with_notes=with_notes,
    )
    sbgnml_sbgn.append(sbgnml_map)
    with open(file_path, "w") as f:
        f.write(
            lxml.etree.tostring(
                sbgnml_sbgn, pretty_print=True, xml_declaration=True
            ).decode()
        )