biomodels.models¶
Access to the BioModels database: search, model info, download, selection.
The curated model set is queried and downloaded through the BioModels REST
API (https://www.biomodels.org, www.ebi.ac.uk/biomodels rejects the
quoted search query used here). Model info and the downloaded SBML are
cached on disk under biomodels_cache() so a rerun of the check never
re-fetches a model it already has.
BioModelsError
¶
Bases: RuntimeError
A BioModels request failed or returned an unexpected response.
ModelInfo
dataclass
¶
Metadata of one BioModels model, from /{id}?format=json.
Selection
dataclass
¶
A snapshot of the curated model ids, e.g. biomodels/models.json.
biomodels_cache
¶
Cache directory of the BioModels info and downloads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache
|
Path | None
|
cache root, |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
|
query_curated_ids
¶
Ids of every manually curated SBML model, paged through the search.
Returns:
| Type | Description |
|---|---|
list[str]
|
The model ids, sorted and without duplicates. |
Raises:
| Type | Description |
|---|---|
BioModelsError
|
if a search page cannot be fetched. |
model_info
¶
Metadata of a model, cached as <cache>/biomodels/<id>/info.json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
BioModels id, e.g. |
required |
cache
|
Path | None
|
cache root, |
None
|
Returns:
| Type | Description |
|---|---|
ModelInfo
|
The model metadata. |
Raises:
| Type | Description |
|---|---|
BioModelsError
|
if the request fails or the response has no main SBML file. |
download_model
¶
Download the main SBML file of a model, cached on disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
BioModels id, e.g. |
required |
cache
|
Path | None
|
cache root, |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path of the cached SBML file. |
Raises:
| Type | Description |
|---|---|
BioModelsError
|
if the info or download request fails. |
load_selection
¶
Read a selection file (e.g. biomodels/models.json).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
the selection file. |
required |
Returns:
| Type | Description |
|---|---|
Selection
|
The selection. |
write_selection
¶
Write a selection file with today's date and the given ids.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
file to write. |
required |
ids
|
list[str]
|
model ids, written sorted and without duplicates. |
required |
Returns:
| Type | Description |
|---|---|
Selection
|
The selection written. |
packages
¶
SBML packages an SBML file uses, not merely declares.
A package declared through the root element's xmlns counts only when
an element with its prefix actually occurs in the file, e.g. <comp:...
for a comp declaration. comp is the exception: its port elements
do not change the math, so it counts only when a <comp:submodel,
<comp:modelDefinition or <comp:externalModelDefinition element
occurs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sbml_path
|
Path
|
SBML file to inspect. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
The package names, sorted and without duplicates. |