17.1.1.3.1.1. cobra.io.web

Provide functionality to access remote model repositories.

17.1.1.3.1.1.1. Submodules

17.1.1.3.1.1.2. Package Contents

17.1.1.3.1.1.2.1. Classes

AbstractModelRepository

Define an abstract base class that describes a remote model repository.

BiGGModels

Define a concrete implementation of the BiGG Models repository.

BioModels

Define a concrete implementation of the BioModels repository.

17.1.1.3.1.1.2.2. Functions

load_model(model_id: str, repositories: Iterable[AbstractModelRepository] = (BiGGModels(), BioModels()), cache: bool = True) → ‘Model’

Download an SBML model from a remote repository.

class cobra.io.web.AbstractModelRepository(*, url: Union[httpx.URL, str], **kwargs)[source]

Bases: abc.ABC

Define an abstract base class that describes a remote model repository.

name

The name of the remote repository.

Type

str

_progress
name :str = Abstract
property url(self) → httpx.URL

Return the repository’s URL.

abstract get_sbml(self, model_id: str) → bytes

Attempt to download an SBML document from the repository.

Parameters

model_id (str) – The identifier of the desired metabolic model. This is typically repository specific.

Returns

A gzip-compressed, UTF-8 encoded SBML document.

Return type

bytes

class cobra.io.web.BiGGModels(**kwargs)[source]

Bases: cobra.io.web.abstract_model_repository.AbstractModelRepository

Define a concrete implementation of the BiGG Models repository.

name

The name of the BiGG Models repository.

Type

str

name :str = BiGG Models
get_sbml(self, model_id: str) → bytes

Attempt to download an SBML document from the repository.

Parameters

model_id (str) – The identifier of the desired metabolic model. This is typically repository specific.

Returns

A gzip-compressed, UTF-8 encoded SBML document.

Return type

bytes

Raises

httpx.HTTPError – In case there are any connection problems.

class cobra.io.web.BioModels(**kwargs)[source]

Bases: cobra.io.web.abstract_model_repository.AbstractModelRepository

Define a concrete implementation of the BioModels repository.

name

The name of the BioModels repository.

Type

str

name :str = BioModels
get_sbml(self, model_id: str) → bytes

Attempt to download an SBML document from the repository.

Parameters

model_id (str) – The identifier of the desired metabolic model. This is typically repository specific.

Returns

A gzip-compressed, UTF-8 encoded SBML document.

Return type

bytes

Raises

httpx.HTTPError – In case there are any connection problems.

cobra.io.web.load_model(model_id: str, repositories: Iterable[AbstractModelRepository] = (BiGGModels(), BioModels()), cache: bool = True) → 'Model'[source]

Download an SBML model from a remote repository.

Downloaded SBML documents are by default stored in a cache on disk such that future access is much faster. By default, models can be loaded from the following repositories:

  • BiGG Models

  • BioModels

You can use the AbstractModelRepository class as a parent to implement your own repository accessor which you pass to the load_model function. In case you implement a new interface, please consider submitting a pull request to COBRApy.

Parameters
  • model_id (str) – The identifier of the desired metabolic model. This is typically repository specific.

  • repositories (iterable, optional) – An iterable of repository accessor instances. The model_id is searched in order.

  • cache (bool, optional) – Whether or not to use the local caching mechanism (default yes).

Returns

A model instance generated from the SBML document.

Return type

Model

Raises

RuntimeError – As with any internet connection, there are multiple errors that can occur.

Examples

# Most of the time calling load_model with an identifier should be enough. >>> print(load_model(“e_coli_core”)) e_coli_core >>> print(load_model(“MODEL1510010000”)) MODEL1510010000