cobra.io.web.load

Provide a function load_model to access remote model repositories.

Module Contents

Functions

load_model(→ cobra.core.Model)

Download an SBML model from a remote repository.

_cached_load(→ bytes)

Attempt to load a gzip-compressed SBML document from the cache.

_fetch_model(→ bytes)

Attempt to load a gzip-compressed SBML document from the given repositories.

get_model_from_gzip_sbml(→ cobra.core.Model)

Generate a model instance from a gzip-compressed, UTF-8 encoded SBML document.

Attributes

logger

configuration

DEFAULT_REPOSITORIES

cobra.io.web.load.logger[source]
cobra.io.web.load.configuration[source]
cobra.io.web.load.DEFAULT_REPOSITORIES[source]
cobra.io.web.load.load_model(model_id: str, repositories: Iterable[cobra.io.web.abstract_model_repository.AbstractModelRepository] = DEFAULT_REPOSITORIES, cache: bool = True) cobra.core.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

See also

BiGGModels, BioModels

cobra.io.web.load._cached_load(model_id: str, repositories: Iterable[cobra.io.web.abstract_model_repository.AbstractModelRepository]) bytes[source]

Attempt to load a gzip-compressed SBML document from the cache.

If the given model identifier is not in the cache, the remote repositories are searched.

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

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

Returns

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

Return type

bytes

cobra.io.web.load._fetch_model(model_id: str, repositories: Iterable[cobra.io.web.abstract_model_repository.AbstractModelRepository]) bytes[source]

Attempt to load a gzip-compressed SBML document from the given repositories.

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

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

Returns

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

Return type

bytes

cobra.io.web.load.get_model_from_gzip_sbml(stream: bytes) cobra.core.Model[source]

Generate a model instance from a gzip-compressed, UTF-8 encoded SBML document.

Parameters

stream (bytes) – A gzip-compressed, UTF-8 encoded SBML document.

Returns

A model instance generated from the SBML document.

Return type

Model