CD - momapy

Skip to content

# CD

## `` momapy.celldesigner.io.celldesigner

Classes for reading CellDesigner files (extended SBML)

Classes:

Name | Description
--- | ---
`CellDesignerReader` | Class for CellDesigner reader objects

### `` CellDesignerReader

Bases: `Reader`

Class for CellDesigner reader objects

Methods:

Name | Description
--- | ---
`check_file` | Return `true` if the file is a CellDesigner file, `false` otherwise
`read` | Read a CellDesigner file and return a reader result object

#### `` check_file `classmethod`

    check_file(file_path: str | PathLike)

Return `true` if the file is a CellDesigner file, `false` otherwise

Source code in `src/momapy/celldesigner/io/celldesigner.py`

    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    @classmethod
    def check_file(cls, file_path: str | os.PathLike):
        """Return `true` if the file is a CellDesigner file, `false` otherwise"""
        try:
            with open(file_path) as f:
                for line in f:
                    if "http://www.sbml.org/2001/ns/celldesigner" in line:
                        return True
        except UnicodeDecodeError:
            return False
        else:
            return False

#### `` read `classmethod`

    read(
        file_path: str | PathLike,
        return_type: Literal["map", "model", "layout"] = "map",
        with_model=True,
        with_layout=True,
        with_annotations=True,
        with_notes=True,
    ) -> ReaderResult

Read a CellDesigner file and return a reader result object

Source code in `src/momapy/celldesigner/io/celldesigner.py`

    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    @classmethod
    def read(
        cls,
        file_path: str | os.PathLike,
        return_type: typing.Literal["map", "model", "layout"] = "map",
        with_model=True,
        with_layout=True,
        with_annotations=True,
        with_notes=True,
    ) -> momapy.io.ReaderResult:
        """Read a CellDesigner file and return a reader result object"""
        cd_document = lxml.objectify.parse(file_path)
        cd_sbml = cd_document.getroot()
        obj, annotations, notes, ids = cls._make_main_obj_from_cd_model(
            cd_model=cd_sbml.model,
            return_type=return_type,
            with_model=with_model,
            with_layout=with_layout,
            with_annotations=with_annotations,
            with_notes=with_notes,
        )
        result = momapy.io.ReaderResult(
            obj=obj,
            notes=notes,
            annotations=annotations,
            file_path=file_path,
            ids=ids,
        )
        return result