Skip to main content

Download from the BioModels API

Project description

BioModels

biomodels is a Python library to download models from BioModels. Models are cached locally in the OS user cache directory, so they will not be redownloaded every time.

Usage

Get model metadata

The first time we download a file, it will let us know that it is being downloaded and cached locally.

>>> import biomodels
>>> metadata = biomodels.get_metadata("BIOMD0000000012")  # doctest: +SKIP
Downloading data from 'https://www.ebi.ac.uk/biomodels/model/files/BIOMD0000000012?format=json' to file '.../Caches/biomodels/model/files/BIOMD0000000012'.
SHA256 hash of downloaded file: ...
Use this value as the 'known_hash' argument of 'pooch.retrieve' to ensure that the file hasn't changed if it is downloaded again in the future.

Later, this file will get fetched from the local cache, instead of being redownloaded.

>>> metadata = biomodels.get_metadata("BIOMD12")  # no need to input the leading zeros
>>> metadata
    name                         description                            size
--  ---------------------------  -----------------------------------  ------
 0  BIOMD0000000012_url.xml      main                                  46274
 1  BIOMD0000000012-biopax2.owl  Auto-generated BioPAX (Level 2)       16748
 2  BIOMD0000000012-biopax3.owl  Auto-generated BioPAX (Level 3)       23577
 3  BIOMD0000000012.m            Auto-generated Octave file             4994
 4  BIOMD0000000012.pdf          Auto-generated PDF file              205156
 5  BIOMD0000000012.png          Auto-generated Reaction graph (PNG)   39018
 6  BIOMD0000000012.sci          Auto-generated Scilab file              154
 7  BIOMD0000000012.svg          Auto-generated Reaction graph (SVG)   35750
 8  BIOMD0000000012.vcml         Auto-generated VCML file              60183
 9  BIOMD0000000012.xpp          Auto-generated XPP file                4114
10  BIOMD0000000012_urn.xml      Auto-generated SBML file with URNs    47097

Get a particular file

To get a particular file, you can either pass the filename and model_id:

>>> biomodels.get_file("BIOMD0000000012_url.xml", model_id="BIOMD12")
PosixPath('<CACHE_DIR>/biomodels/model/download/BIOMD0000000012/BIOMD0000000012_url.xml')

or choose one from the metadata:

>>> path = biomodels.get_file(metadata[0])
>>> path
PosixPath('<CACHE_DIR>/biomodels/model/download/BIOMD0000000012/BIOMD0000000012_url.xml')

Then, you can use that Path object to load the file:

>>> print(path.read_text())
<?xml version="1.0" encoding="UTF-8"?>
<sbml xmlns="http://www.sbml.org/sbml/level2/version3" metaid="_153818" level="2" version="3">
...

Get COMBINE archive

If you are interested in all the model files, it might be better to download the COMBINE archive, which is a compressed file (260KB vs 500KB for this small model):

>>> omex = biomodels.get_omex("BIOMD12")
>>> omex
    location                     format                                                                 master
--  ---------------------------  ---------------------------------------------------------------------  --------
 0                               https://identifiers.org/combine.specifications/omex                    False
 1  BIOMD0000000012-biopax2.owl  https://identifiers.org/combine.specifications/biopax.level-2          False
 2  BIOMD0000000012-biopax3.owl  https://identifiers.org/combine.specifications/biopax.level-3          False
 3  BIOMD0000000012.m            https://purl.org/NET/mediatypes/application/x.unknown                  False
 4  BIOMD0000000012.pdf          https://purl.org/NET/mediatypes/application/pdf                        False
 5  BIOMD0000000012.png          https://purl.org/NET/mediatypes/image/png                              False
 6  BIOMD0000000012.sci          https://purl.org/NET/mediatypes/application/x.unknown                  False
 7  BIOMD0000000012.svg          https://purl.org/NET/mediatypes/application/xml                        False
 8  BIOMD0000000012.vcml         https://purl.org/NET/mediatypes/application/xml                        False
 9  BIOMD0000000012.xpp          https://purl.org/NET/mediatypes/application/x.unknown                  False
10  BIOMD0000000012_manual.png   https://purl.org/NET/mediatypes/image/png                              False
11  BIOMD0000000012_manual.svg   https://purl.org/NET/mediatypes/application/xml                        False
12  BIOMD0000000012_url.xml      https://identifiers.org/combine.specifications/sbml.level-2.version-3  True
13  BIOMD0000000012_urn.xml      https://identifiers.org/combine.specifications/sbml.level-2.version-3  False
14  manifest.xml                 https://identifiers.org/combine.specifications/omex-manifest           False
15  metadata.rdf                 https://identifiers.org/combine.specifications/omex-metadata           False

We can select a particular file by indexing:

>>> content = omex[12]
>>> content
Content(location='BIOMD0000000012_url.xml', format='https://identifiers.org/combine.specifications/sbml.level-2.version-3', master=True)

Then, you can get a zipfile.Path object with the Content.path attribute, and read the contents from the OMEX file:

>>> print(content.path.read_text())
<?xml version="1.0" encoding="UTF-8"?>
<sbml xmlns="http://www.sbml.org/sbml/level2/version3" metaid="_153818" level="2" version="3">
...

Installation

pip install biomodels

Development

We are using pytest for testing, and pre-commit hooks to format and lint the codebase.

To easily set-up a development environment, run the following commands:

git clone https://github.com/maurosilber/biomodels
cd biomodels
conda env create --file environment-dev.yml
pre-commit install

which assume you have git and conda preinstalled.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

biomodels-0.3.1.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

biomodels-0.3.1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file biomodels-0.3.1.tar.gz.

File metadata

  • Download URL: biomodels-0.3.1.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for biomodels-0.3.1.tar.gz
Algorithm Hash digest
SHA256 6f2d437ccf2ee588c22e457acb47f4fc8db74ea65f183734e81ba6fa2f7de548
MD5 2df9664bde9303a81bdc1fb6ea35d9b5
BLAKE2b-256 a3f77b2c47560da946fa512e7e5de2a2baec6c6f505730a837c3e350c9ccdfc9

See more details on using hashes here.

File details

Details for the file biomodels-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: biomodels-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for biomodels-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 801a3d6b32245d5eee0b9d06bc2040d1e9e2c25a921e6fd655f642f01e540cd4
MD5 a0674fc077203b9804ae4caec757e1eb
BLAKE2b-256 7d96599b6b0cc529001b81d7ca8a0a892eea2989e932422690a2d973a7c63227

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page