Skip to content

Commit

Permalink
feat: added get biomodel helper
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPatrie committed Dec 13, 2024
1 parent 6f1a97f commit d9cc650
Show file tree
Hide file tree
Showing 7 changed files with 2,250 additions and 408 deletions.
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM ghcr.io/biosimulators/bio-check-worker:latest

SHELL ["/usr/bin/env", "bash", "-c"]

ENV JUPYTER_TOKEN='' \
JUPYTER_ENABLE_LAB=yes \
GRANT_SUDO=yes

EXPOSE 8888

WORKDIR /app

COPY dockerfile-assets/requirements.image.txt /tmp/requirements.image.txt

RUN source ~/.bashrc \
&& mkdir -p /opt/notebooks \
&& poetry run pip install -r /tmp/requirements.image.txt

CMD ["bash", "-c", "source ~/.bashrc && poetry run jupyter lab --ip='*' --port=8888 --allow-root --no-browser"]
39 changes: 39 additions & 0 deletions bio_compose/api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import os
import time
import warnings
from typing import *
from functools import wraps

import requests

from bio_compose.processing_tools import get_job_signature
from bio_compose.runner import SimulationRunner, SimulationResult
from bio_compose.verifier import Verifier, VerificationResult
Expand Down Expand Up @@ -201,3 +204,39 @@ def visualize_rmse(job_id: str, save_dest: str = None, fig_dimensions: tuple[int
return API_VERIFIER.visualize_rmse(job_id=job_id, save_dest=save_dest, fig_dimensions=fig_dimensions, color_mapping=color_mapping)


def get_biomodel(model_id: str, dest_dir: Optional[str] = None) -> str:
"""
Visualize the root-mean-squared error between simulator verification outputs as a heatmap.
:param model_id: (`Union[str, List[str`]) A single biomodel id passed as a string, or a list of biomodel ids as strings.
:param dest_dir: (`str`) destination directory at which to save downloaded file. If `None` is passed, downloads to cwd. Defaults to `None`.
:return: Filepath of the downloaded biomodel file
:rtype: `str`
"""
url = "https://www.ebi.ac.uk/biomodels/search/download"
params = {"models": model_id}

try:
response = requests.get(url, params=params, stream=True)

# download the file if success, otherwise notify.
if response.status_code == 200:
file_name = f"{model_id}.omex"
dest = dest_dir or os.getcwd()
fp = os.path.join(dest, file_name)
with open(fp, "wb") as file:
for chunk in response.iter_content(chunk_size=8192):
file.write(chunk)
warnings.warn(f"File downloaded successfully and saved as {fp}")
return fp
elif response.status_code == 400:
warnings.warn("Error 400: File Not Found")
elif response.status_code == 404:
warnings.warn("Error 404: Invalid Model ID Supplied")
else:
warnings.warn(f"Unexpected error: {response.status_code} - {response.text}")
except requests.RequestException as e:
return f"An error occurred: {e}"


5 changes: 5 additions & 0 deletions dockerfile-assets/requirements.image.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
requests-toolbelt
seaborn
toml
process-bigraph
jupyterlab
2,557 changes: 2,159 additions & 398 deletions poetry.lock

Large diffs are not rendered by default.

24 changes: 15 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
# This project configuration should relate only to the high level notebook api (as primary deps).
[tool.poetry]
name = "bio-compose"
version = "0.7.2"
version = "0.7.3"
description = "Create, execute, and introspect reproducible composite simulations of dynamic biological systems."
authors = ["Alex Patrie <[email protected]>"]
readme = "README.md"
packages = [{include = "bio_compose"}, {include = "tests"}]
include = ["pyproject.toml"]


[tool.poetry.scripts]
verify = "bio_compose.__main__:verification_cli"
run-simulation = "bio_compose.__main__:simulation_run_cli"


[tool.poetry.dependencies]
python = ">=3.10"
python = "^3.10"
requests-toolbelt = "^1.0.0"
seaborn = "^0.13.2"
antimony = "^2.15.0"
antimony = "*"
toml = "^0.10.2"
process-bigraph = "^0.0.21"
requests = "^2.32.3"


[tool.poetry.group.dev.dependencies]
pytest = "^8.3.2"
sphinx = "^8.0.2"
sphinx-autodoc-typehints = "^2.2.3"
[tool.poetry.group.docs.dependencies]
sphinx = "^8.1.3"
sphinx-autodoc-typehints = "^2.5.0"


[tool.poetry.group.image.dependencies]
jupyterlab = "^4.3.0"

[project.optional-dependencies]
documentation = ["sphinx-autodoc-typehints"]

[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "--ignore=setup.py"
python_files = "main.py"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Expand Down
14 changes: 13 additions & 1 deletion tests/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import os

from bio_compose import get_compatible_verification_simulators
from bio_compose.api import get_biomodel
from bio_compose.verifier import Verifier
from bio_compose.runner import SimulationRunner
from bio_compose.composer import Composer
Expand Down Expand Up @@ -49,5 +52,14 @@ def test_verify_omex():


def test_run_composition():
pass
pass


def test_get_biomodel():
biomd_id = 'BIOMD0000000044'
dest = '/Users/alexanderpatrie/Desktop/repos/bio-compose/tests/outputs'
fp = get_biomodel(biomd_id, dest)
# print(f'Biomodel {biomd_id} exists at {fp}: {os.path.exists(fp)}')
print(fp)


Binary file added tests/outputs/BIOMD0000000044.omex
Binary file not shown.

0 comments on commit d9cc650

Please sign in to comment.