SBGN-ML - momapy

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`

    3121
    3122
    3123
    3124
    3125
    3126
    3127
    3128
    @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`

    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    @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`

    3345
    3346
    3347
    3348
    3349
    3350
    3351
    3352
    3353
    3354
    3355
    3356
    3357
    3358
    3359
    3360
    3361
    3362
    3363
    3364
    3365
    3366
    3367
    3368
    3369
    3370
    3371
    3372
    3373
    3374
    3375
    3376
    3377
    @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`

    3147
    3148
    3149
    3150
    3151
    3152
    3153
    3154
    @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`

    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    @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`

    3345
    3346
    3347
    3348
    3349
    3350
    3351
    3352
    3353
    3354
    3355
    3356
    3357
    3358
    3359
    3360
    3361
    3362
    3363
    3364
    3365
    3366
    3367
    3368
    3369
    3370
    3371
    3372
    3373
    3374
    3375
    3376
    3377
    @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()
            )