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.2.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: biomodels-0.3.2.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.2.tar.gz
Algorithm Hash digest
SHA256 5dfbf021c16781159c0d1f1faf7da02115173151d35b0ef6685662f17520af3c
MD5 5aacbcec089366d0789ae400fe9e8cd8
BLAKE2b-256 736bf8809c816326724ac5cbddff0da65c556bde5946060ff2759414ec471d53

See more details on using hashes here.

File details

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

File metadata

  • Download URL: biomodels-0.3.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e0a3baa0a7b93c3c14ab3a4508f56be2a3746bd33b8cef6a780e094eb17f30cf
MD5 83b7c2120129a92ffa830e1db4818c35
BLAKE2b-256 24a41465d88ac1058e598fef80e3afcf77ef5e2dc4dc194716bb8b68aa6f8f9a

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