File: cobrapy_repository.py

package info (click to toggle)
python-cobra 0.29.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,512 kB
  • sloc: python: 14,703; xml: 12,841; makefile: 137; sh: 30
file content (56 lines) | stat: -rw-r--r-- 1,362 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Provide functions for loading metabolic models from local package data."""

import importlib.resources

import cobra.data

from .abstract_model_repository import AbstractModelRepository


class Cobrapy(AbstractModelRepository):
    """
    Define a concrete implementation of the cobrapy (local package) repository.

     Attributes
    ----------
    name : str
        The name of the Cobrapy repository.
    """

    name: str = "Cobrapy"

    def __init__(
        self,
        **kwargs,
    ) -> None:
        """
        Initialize a local Cobrapy repository interface.

        Other Parameters
        ----------------
        kwargs
            Passed to the parent constructor in order to enable multiple inheritance.

        """
        super().__init__(url="file://", **kwargs)

    def get_sbml(self, model_id: str) -> bytes:
        """
        Attempt to open an SBML document from the local repository.

        Parameters
        ----------
        model_id : str
            The identifier of the desired metabolic model. This is typically repository
            specific.

        Returns
        -------
        bytes
            A gzip-compressed, UTF-8 encoded SBML document.
        """
        return (
            importlib.resources.files(cobra.data)
            .joinpath(f"{model_id}.xml.gz")
            .read_bytes()
        )