Skip to content

Commit 6f005b8

Browse files
authored
Merge branch 'develop' into 330_truncated
2 parents a17aa62 + 6a433e0 commit 6f005b8

File tree

11 files changed

+236
-174
lines changed

11 files changed

+236
-174
lines changed

doc/example/example_petablint.ipynb

Lines changed: 10 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -16,75 +16,26 @@
1616
},
1717
{
1818
"cell_type": "code",
19-
"execution_count": 1,
2019
"metadata": {},
21-
"outputs": [
22-
{
23-
"name": "stdout",
24-
"output_type": "stream",
25-
"text": [
26-
"usage: petablint [-h] [-v] [-s SBML_FILE_NAME] [-m MEASUREMENT_FILE_NAME]\r\n",
27-
" [-c CONDITION_FILE_NAME] [-p PARAMETER_FILE_NAME]\r\n",
28-
" [-y YAML_FILE_NAME | -n MODEL_NAME] [-d DIRECTORY]\r\n",
29-
"\r\n",
30-
"Check if a set of files adheres to the PEtab format.\r\n",
31-
"\r\n",
32-
"optional arguments:\r\n",
33-
" -h, --help show this help message and exit\r\n",
34-
" -v, --verbose More verbose output\r\n",
35-
" -s SBML_FILE_NAME, --sbml SBML_FILE_NAME\r\n",
36-
" SBML model filename\r\n",
37-
" -m MEASUREMENT_FILE_NAME, --measurements MEASUREMENT_FILE_NAME\r\n",
38-
" Measurement table\r\n",
39-
" -c CONDITION_FILE_NAME, --conditions CONDITION_FILE_NAME\r\n",
40-
" Conditions table\r\n",
41-
" -p PARAMETER_FILE_NAME, --parameters PARAMETER_FILE_NAME\r\n",
42-
" Parameter table\r\n",
43-
" -y YAML_FILE_NAME, --yaml YAML_FILE_NAME\r\n",
44-
" PEtab YAML problem filename\r\n",
45-
" -n MODEL_NAME, --model-name MODEL_NAME\r\n",
46-
" Model name where all files are in the working\r\n",
47-
" directory and follow PEtab naming convention.\r\n",
48-
" Specifying -[smcp] will override defaults\r\n",
49-
" -d DIRECTORY, --directory DIRECTORY\r\n"
50-
]
51-
}
52-
],
5320
"source": [
5421
"!petablint -h"
55-
]
22+
],
23+
"outputs": [],
24+
"execution_count": null
5625
},
5726
{
5827
"cell_type": "markdown",
5928
"metadata": {},
60-
"source": [
61-
"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:"
62-
]
29+
"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:"
6330
},
6431
{
6532
"cell_type": "code",
66-
"execution_count": 2,
6733
"metadata": {},
68-
"outputs": [
69-
{
70-
"name": "stdout",
71-
"output_type": "stream",
72-
"text": [
73-
"parameter_file: Fujita_parameters.tsv\r\n",
74-
"petab_version: 0.0.0a17\r\n",
75-
"problems:\r\n",
76-
"- condition_files:\r\n",
77-
" - Fujita_experimentalCondition.tsv\r\n",
78-
" measurement_files:\r\n",
79-
" - Fujita_measurementData.tsv\r\n",
80-
" sbml_files:\r\n",
81-
" - Fujita_model.xml\r\n"
82-
]
83-
}
84-
],
8534
"source": [
8635
"!cat example_Fujita/Fujita.yaml"
87-
]
36+
],
37+
"outputs": [],
38+
"execution_count": null
8839
},
8940
{
9041
"cell_type": "markdown",
@@ -95,20 +46,10 @@
9546
},
9647
{
9748
"cell_type": "code",
98-
"execution_count": 3,
9949
"metadata": {},
100-
"outputs": [
101-
{
102-
"name": "stdout",
103-
"output_type": "stream",
104-
"text": [
105-
"\u001b[0m"
106-
]
107-
}
108-
],
109-
"source": [
110-
"!petablint -y example_Fujita/Fujita.yaml"
111-
]
50+
"source": "!petablint example_Fujita/Fujita.yaml",
51+
"outputs": [],
52+
"execution_count": null
11253
},
11354
{
11455
"cell_type": "markdown",

petab/petablint.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212

1313
import petab.v1 as petab
1414
from petab.v1.C import FORMAT_VERSION
15-
from petab.v2.lint import lint_problem
15+
from petab.v1.yaml import validate
1616
from petab.versions import get_major_version
17-
from petab.yaml import validate
1817

1918
logger = logging.getLogger(__name__)
2019

@@ -178,6 +177,8 @@ def main():
178177
ret = petab.lint.lint_problem(problem)
179178
sys.exit(ret)
180179
case 2:
180+
from petab.v2.lint import lint_problem
181+
181182
validation_issues = lint_problem(args.yaml_file_name)
182183
if validation_issues:
183184
validation_issues.log(logger=logger)

petab/v1/calculate.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ def calculate_residuals_for_table(
9797
Calculate residuals for a single measurement table.
9898
For the arguments, see `calculate_residuals`.
9999
"""
100+
# below, we rely on a unique index
101+
measurement_df = measurement_df.reset_index(drop=True)
102+
100103
# create residual df as copy of measurement df, change column
101104
residual_df = measurement_df.copy(deep=True).rename(
102105
columns={MEASUREMENT: RESIDUAL}
@@ -120,6 +123,10 @@ def calculate_residuals_for_table(
120123
for col in compared_cols
121124
]
122125
mask = reduce(lambda x, y: x & y, masks)
126+
if mask.sum() == 0:
127+
raise ValueError(
128+
f"Could not find simulation for measurement {row}."
129+
)
123130
simulation = simulation_df.loc[mask][SIMULATION].iloc[0]
124131
if scale:
125132
# apply scaling

petab/v1/problem.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,8 +1149,8 @@ def add_measurement(
11491149
sim_cond_id: str,
11501150
time: float,
11511151
measurement: float,
1152-
observable_parameters: Sequence[str] = None,
1153-
noise_parameters: Sequence[str] = None,
1152+
observable_parameters: Sequence[str | float] = None,
1153+
noise_parameters: Sequence[str | float] = None,
11541154
preeq_cond_id: str = None,
11551155
):
11561156
"""Add a measurement to the problem.
@@ -1172,11 +1172,11 @@ def add_measurement(
11721172
}
11731173
if observable_parameters is not None:
11741174
record[OBSERVABLE_PARAMETERS] = [
1175-
PARAMETER_SEPARATOR.join(observable_parameters)
1175+
PARAMETER_SEPARATOR.join(map(str, observable_parameters))
11761176
]
11771177
if noise_parameters is not None:
11781178
record[NOISE_PARAMETERS] = [
1179-
PARAMETER_SEPARATOR.join(noise_parameters)
1179+
PARAMETER_SEPARATOR.join(map(str, noise_parameters))
11801180
]
11811181
if preeq_cond_id is not None:
11821182
record[PREEQUILIBRATION_CONDITION_ID] = [preeq_cond_id]

petab/v2/C.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@
1313
#: Experiment ID column in the measurement table
1414
EXPERIMENT_ID = "experimentId"
1515

16-
# TODO: remove
17-
#: Preequilibration condition ID column in the measurement table
18-
PREEQUILIBRATION_CONDITION_ID = "preequilibrationConditionId"
19-
20-
# TODO: remove
21-
#: Simulation condition ID column in the measurement table
22-
SIMULATION_CONDITION_ID = "simulationConditionId"
23-
2416
#: Measurement value column in the measurement table
2517
MEASUREMENT = "measurement"
2618

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

25+
#: Time value that indicates pre-equilibration in the experiments table
26+
TIME_PREEQUILIBRATION = -_math.inf
27+
3328
#: Observable parameters column in the measurement table
3429
OBSERVABLE_PARAMETERS = "observableParameters"
3530

@@ -45,17 +40,13 @@
4540
#: Mandatory columns of measurement table
4641
MEASUREMENT_DF_REQUIRED_COLS = [
4742
OBSERVABLE_ID,
48-
# TODO: add
49-
# EXPERIMENT_ID,
50-
SIMULATION_CONDITION_ID,
43+
EXPERIMENT_ID,
5144
MEASUREMENT,
5245
TIME,
5346
]
5447

5548
#: Optional columns of measurement table
5649
MEASUREMENT_DF_OPTIONAL_COLS = [
57-
# TODO: remove
58-
PREEQUILIBRATION_CONDITION_ID,
5950
OBSERVABLE_PARAMETERS,
6051
NOISE_PARAMETERS,
6152
DATASET_ID,

petab/v2/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727

2828
# import after v1
2929
from ..version import __version__ # noqa: F401, E402
30-
from . import models # noqa: F401, E402
30+
from . import ( # noqa: F401, E402
31+
C, # noqa: F401, E402
32+
models, # noqa: F401, E402
33+
)
3134
from .conditions import * # noqa: F403, F401, E402
3235
from .experiments import ( # noqa: F401, E402
3336
get_experiment_df,

0 commit comments

Comments
 (0)