Skip to content

Commit

Permalink
Merge branch 'develop' into 330_truncated
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl authored Dec 18, 2024
2 parents a17aa62 + 6a433e0 commit 6f005b8
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 174 deletions.
79 changes: 10 additions & 69 deletions doc/example/example_petablint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,75 +16,26 @@
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"usage: petablint [-h] [-v] [-s SBML_FILE_NAME] [-m MEASUREMENT_FILE_NAME]\r\n",
" [-c CONDITION_FILE_NAME] [-p PARAMETER_FILE_NAME]\r\n",
" [-y YAML_FILE_NAME | -n MODEL_NAME] [-d DIRECTORY]\r\n",
"\r\n",
"Check if a set of files adheres to the PEtab format.\r\n",
"\r\n",
"optional arguments:\r\n",
" -h, --help show this help message and exit\r\n",
" -v, --verbose More verbose output\r\n",
" -s SBML_FILE_NAME, --sbml SBML_FILE_NAME\r\n",
" SBML model filename\r\n",
" -m MEASUREMENT_FILE_NAME, --measurements MEASUREMENT_FILE_NAME\r\n",
" Measurement table\r\n",
" -c CONDITION_FILE_NAME, --conditions CONDITION_FILE_NAME\r\n",
" Conditions table\r\n",
" -p PARAMETER_FILE_NAME, --parameters PARAMETER_FILE_NAME\r\n",
" Parameter table\r\n",
" -y YAML_FILE_NAME, --yaml YAML_FILE_NAME\r\n",
" PEtab YAML problem filename\r\n",
" -n MODEL_NAME, --model-name MODEL_NAME\r\n",
" Model name where all files are in the working\r\n",
" directory and follow PEtab naming convention.\r\n",
" Specifying -[smcp] will override defaults\r\n",
" -d DIRECTORY, --directory DIRECTORY\r\n"
]
}
],
"source": [
"!petablint -h"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's look at an example: In the example_Fujita folder, we have a PEtab configuration file `Fujita.yaml` telling which files belong to the Fujita model:"
]
"source": "Let's look at an example: In the `example_Fujita/` directory, we have a PEtab problem configuration file `Fujita.yaml` telling which files belong to the \"Fujita\" problem:"
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"parameter_file: Fujita_parameters.tsv\r\n",
"petab_version: 0.0.0a17\r\n",
"problems:\r\n",
"- condition_files:\r\n",
" - Fujita_experimentalCondition.tsv\r\n",
" measurement_files:\r\n",
" - Fujita_measurementData.tsv\r\n",
" sbml_files:\r\n",
" - Fujita_model.xml\r\n"
]
}
],
"source": [
"!cat example_Fujita/Fujita.yaml"
]
],
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand All @@ -95,20 +46,10 @@
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[0m"
]
}
],
"source": [
"!petablint -y example_Fujita/Fujita.yaml"
]
"source": "!petablint example_Fujita/Fujita.yaml",
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
Expand Down
5 changes: 3 additions & 2 deletions petab/petablint.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

import petab.v1 as petab
from petab.v1.C import FORMAT_VERSION
from petab.v2.lint import lint_problem
from petab.v1.yaml import validate
from petab.versions import get_major_version
from petab.yaml import validate

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -178,6 +177,8 @@ def main():
ret = petab.lint.lint_problem(problem)
sys.exit(ret)
case 2:
from petab.v2.lint import lint_problem

validation_issues = lint_problem(args.yaml_file_name)
if validation_issues:
validation_issues.log(logger=logger)
Expand Down
7 changes: 7 additions & 0 deletions petab/v1/calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ def calculate_residuals_for_table(
Calculate residuals for a single measurement table.
For the arguments, see `calculate_residuals`.
"""
# below, we rely on a unique index
measurement_df = measurement_df.reset_index(drop=True)

# create residual df as copy of measurement df, change column
residual_df = measurement_df.copy(deep=True).rename(
columns={MEASUREMENT: RESIDUAL}
Expand All @@ -120,6 +123,10 @@ def calculate_residuals_for_table(
for col in compared_cols
]
mask = reduce(lambda x, y: x & y, masks)
if mask.sum() == 0:
raise ValueError(
f"Could not find simulation for measurement {row}."
)
simulation = simulation_df.loc[mask][SIMULATION].iloc[0]
if scale:
# apply scaling
Expand Down
8 changes: 4 additions & 4 deletions petab/v1/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1149,8 +1149,8 @@ def add_measurement(
sim_cond_id: str,
time: float,
measurement: float,
observable_parameters: Sequence[str] = None,
noise_parameters: Sequence[str] = None,
observable_parameters: Sequence[str | float] = None,
noise_parameters: Sequence[str | float] = None,
preeq_cond_id: str = None,
):
"""Add a measurement to the problem.
Expand All @@ -1172,11 +1172,11 @@ def add_measurement(
}
if observable_parameters is not None:
record[OBSERVABLE_PARAMETERS] = [
PARAMETER_SEPARATOR.join(observable_parameters)
PARAMETER_SEPARATOR.join(map(str, observable_parameters))
]
if noise_parameters is not None:
record[NOISE_PARAMETERS] = [
PARAMETER_SEPARATOR.join(noise_parameters)
PARAMETER_SEPARATOR.join(map(str, noise_parameters))
]
if preeq_cond_id is not None:
record[PREEQUILIBRATION_CONDITION_ID] = [preeq_cond_id]
Expand Down
17 changes: 4 additions & 13 deletions petab/v2/C.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@
#: Experiment ID column in the measurement table
EXPERIMENT_ID = "experimentId"

# TODO: remove
#: Preequilibration condition ID column in the measurement table
PREEQUILIBRATION_CONDITION_ID = "preequilibrationConditionId"

# TODO: remove
#: Simulation condition ID column in the measurement table
SIMULATION_CONDITION_ID = "simulationConditionId"

#: Measurement value column in the measurement table
MEASUREMENT = "measurement"

Expand All @@ -30,6 +22,9 @@
#: Time value that indicates steady-state measurements
TIME_STEADY_STATE = _math.inf

#: Time value that indicates pre-equilibration in the experiments table
TIME_PREEQUILIBRATION = -_math.inf

#: Observable parameters column in the measurement table
OBSERVABLE_PARAMETERS = "observableParameters"

Expand All @@ -45,17 +40,13 @@
#: Mandatory columns of measurement table
MEASUREMENT_DF_REQUIRED_COLS = [
OBSERVABLE_ID,
# TODO: add
# EXPERIMENT_ID,
SIMULATION_CONDITION_ID,
EXPERIMENT_ID,
MEASUREMENT,
TIME,
]

#: Optional columns of measurement table
MEASUREMENT_DF_OPTIONAL_COLS = [
# TODO: remove
PREEQUILIBRATION_CONDITION_ID,
OBSERVABLE_PARAMETERS,
NOISE_PARAMETERS,
DATASET_ID,
Expand Down
5 changes: 4 additions & 1 deletion petab/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@

# import after v1
from ..version import __version__ # noqa: F401, E402
from . import models # noqa: F401, E402
from . import ( # noqa: F401, E402
C, # noqa: F401, E402
models, # noqa: F401, E402
)
from .conditions import * # noqa: F403, F401, E402
from .experiments import ( # noqa: F401, E402
get_experiment_df,
Expand Down
Loading

0 comments on commit 6f005b8

Please sign in to comment.