Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/python/benchmark_models_petab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Python tool to access the model collection.
"""

from .base import get_problem, get_problem_yaml_path
from .base import get_problem, get_problem_yaml_path, get_simulation_df
from .C import MODEL_DIRS, MODELS, MODELS_DIR
from .overview import get_overview_df
from importlib.metadata import PackageNotFoundError, version
Expand Down
20 changes: 20 additions & 0 deletions src/python/benchmark_models_petab/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from .C import MODELS_DIR

import pandas as pd


def get_problem_yaml_path(id_: str) -> Path:
"""Get the path to the PEtab problem YAML file.
Expand Down Expand Up @@ -40,3 +42,21 @@ def get_problem(id_: str) -> petab.Problem:
yaml_file = get_problem_yaml_path(id_)
petab_problem = petab.Problem.from_yaml(yaml_file)
return petab_problem


def get_simulation_df(id_: str) -> pd.DataFrame | None:
"""Get the simulation dataframe for the benchmark collection problem with
the given name.

Parameters
----------
id_: Problem name, as in `benchmark_models_petab.MODELS`.

Returns
-------
The simulation dataframe if it exists, else None.
"""
path = Path(MODELS_DIR, id_, f"simulatedData_{id_}.tsv")
if path.is_file():
return petab.get_simulation_df(path)
return None
5 changes: 5 additions & 0 deletions src/python/test/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ def test_get_problem():
"""Test whether extracting a petab problem works."""
problem = models.get_problem(models.MODELS[0])
assert problem.measurement_df is not None


def test_get_simulation_df():
assert models.get_simulation_df("Elowitz_Nature2000").empty is False
assert models.get_simulation_df("not a problem name") is None