Skip to content

Commit e1b58fc

Browse files
committed
add reinitialization test
1 parent 63f371a commit e1b58fc

14 files changed

+467
-2
lines changed

petabtests/cases/v2.0.0/sbml/0021/0021.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
case = PetabTestCase(
4545
id=21,
46-
brief="Simulation. Nothing special.",
46+
brief="Observable-dependent noise formula.",
4747
description=DESCRIPTION,
4848
model=DEFAULT_SBML_FILE,
4949
condition_dfs=[],
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
from inspect import cleandoc
2+
3+
from petab.v2.C import *
4+
from petab.v2 import Problem
5+
from petabtests import (
6+
PetabTestCase,
7+
analytical_a,
8+
antimony_to_sbml_str,
9+
analytical_b,
10+
)
11+
from pathlib import Path
12+
13+
DESCRIPTION = cleandoc("""
14+
## Objective
15+
16+
This case tests simultaneous re-initialization of compartment size and
17+
contained species.
18+
19+
## Model
20+
21+
A simple conversion reaction `A <=> B` in a single compartment, following
22+
mass action kinetics.
23+
""")
24+
25+
# problem --------------------------------------------------------------------
26+
27+
28+
sbml_file = Path(__file__).parent / "model.xml"
29+
a_c0 = 2
30+
b_c0 = 1
31+
a_c10 = 2.5
32+
b_c10 = 1
33+
vol0 = 2
34+
vol_new = 10
35+
k1 = 2
36+
k2 = 1
37+
38+
ant_model = f"""
39+
model petab_test_0022
40+
compartment default_compartment = {vol0}
41+
initial_conc_A = {a_c0}
42+
initial_conc_B = {b_c0}
43+
44+
species A in default_compartment = initial_conc_A
45+
substanceOnly species a in default_compartment = initial_conc_A * default_compartment
46+
47+
species B in default_compartment = initial_conc_B
48+
substanceOnly species b in default_compartment = initial_conc_B * default_compartment
49+
50+
k1 = {k1}
51+
k2 = {k2}
52+
53+
A' = k2 * B - k1 * A
54+
B' = - k2 * B + k1 * A
55+
a' = k2 * b - k1 * a
56+
b' = - k2 * b + k1 * a
57+
58+
# the result of the PEtab reinitialization should be the same as with
59+
# the following event and no reinitialization:
60+
#
61+
# at time >= 10: A = 5, a = 5 * default_compartment, default_compartment = 4
62+
end
63+
"""
64+
sbml_file.write_text(antimony_to_sbml_str(ant_model))
65+
66+
67+
problem = Problem()
68+
problem.add_observable("obs_a", "a", noise_formula="1")
69+
problem.add_observable("obs_A", "A", noise_formula="1")
70+
problem.add_observable("obs_b", "b", noise_formula="1")
71+
problem.add_observable("obs_B", "B", noise_formula="1")
72+
73+
problem.add_parameter("k1", lb=0, ub=10, nominal_value=k1, scale=LIN)
74+
problem.add_experiment("experiment1", 0, "", 10, "condition2")
75+
problem.add_condition(
76+
"condition2", "condition2", a=a_c10, b=b_c10, default_compartment=vol_new
77+
)
78+
79+
ts = [0, 5, 10, 15]
80+
for t in ts:
81+
problem.add_measurement("obs_a", "", t, 2)
82+
problem.add_measurement("obs_A", "", t, 2)
83+
problem.add_measurement("obs_b", "", t, 1)
84+
problem.add_measurement("obs_B", "", t, 1)
85+
86+
# solutions ------------------------------------------------------------------
87+
88+
simulation_df = problem.measurement_df.copy(deep=True).rename(
89+
columns={MEASUREMENT: SIMULATION}
90+
)
91+
simulation_df[SIMULATION] = [
92+
# a, A, b, B
93+
# t=0
94+
a_c0 * vol0,
95+
a_c0,
96+
b_c0 * vol0,
97+
b_c0,
98+
# t=5
99+
analytical_a(5, a_c0, b_c0, k1, k2) * vol0,
100+
analytical_a(5, a_c0, b_c0, k1, k2),
101+
analytical_b(5, a_c0, b_c0, k1, k2) * vol0,
102+
analytical_b(5, a_c0, b_c0, k1, k2),
103+
# t=10, re-initialize compartment size and contained species
104+
a_c10 * vol_new,
105+
a_c10,
106+
b_c10 * vol_new,
107+
b_c10,
108+
# t=15
109+
analytical_a(5, a_c10, b_c10, k1, k2) * vol_new,
110+
analytical_a(5, a_c10, b_c10, k1, k2),
111+
analytical_b(5, a_c10, b_c10, k1, k2) * vol_new,
112+
analytical_b(5, a_c10, b_c10, k1, k2),
113+
]
114+
115+
case = PetabTestCase(
116+
id=22,
117+
brief="Simultaneous re-initialization of compartment size and contained species.",
118+
description=DESCRIPTION,
119+
model=sbml_file,
120+
experiment_dfs=[problem.experiment_df],
121+
condition_dfs=[problem.condition_df],
122+
observable_dfs=[problem.observable_df],
123+
measurement_dfs=[problem.measurement_df],
124+
simulation_dfs=[simulation_df],
125+
parameter_df=problem.parameter_df,
126+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# PEtab test case 0022
2+
3+
## Objective
4+
5+
This case tests simultaneous re-initialization of compartment size and
6+
contained species.
7+
8+
## Model
9+
10+
A simple conversion reaction `A <=> B` in a single compartment, following
11+
mass action kinetics.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
format_version: 2.0.0
2+
parameter_file: _parameters.tsv
3+
problems:
4+
- condition_files:
5+
- _conditions.tsv
6+
experiment_files:
7+
- _experiments.tsv
8+
measurement_files:
9+
- _measurements.tsv
10+
model_files:
11+
model_0:
12+
language: sbml
13+
location: _model.xml
14+
observable_files:
15+
- _observables.tsv
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
chi2: 1220.9443344556003
2+
llh: -625.1751837590749
3+
simulation_files:
4+
- _simulations.tsv
5+
tol_chi2: 0.001
6+
tol_llh: 0.001
7+
tol_simulations: 0.001
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
conditionId targetId operationType targetValue conditionName
2+
condition2 a setCurrentValue 2.5 ['condition2']
3+
condition2 b setCurrentValue 1.0 ['condition2']
4+
condition2 default_compartment setCurrentValue 10.0 ['condition2']
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
experimentId time conditionId
2+
experiment1 0
3+
experiment1 10 condition2
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
observableId experimentId time measurement
2+
obs_a 0 2
3+
obs_A 0 2
4+
obs_b 0 1
5+
obs_B 0 1
6+
obs_a 5 2
7+
obs_A 5 2
8+
obs_b 5 1
9+
obs_B 5 1
10+
obs_a 10 2
11+
obs_A 10 2
12+
obs_b 10 1
13+
obs_B 10 1
14+
obs_a 15 2
15+
obs_A 15 2
16+
obs_b 15 1
17+
obs_B 15 1
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Created by libAntimony version v2.15.0 with libSBML version 5.20.2. -->
3+
<sbml xmlns="http://www.sbml.org/sbml/level3/version2/core" level="3" version="2">
4+
<model metaid="petab_test_0022" id="petab_test_0022">
5+
<listOfCompartments>
6+
<compartment sboTerm="SBO:0000410" id="default_compartment" spatialDimensions="3" size="2" constant="true"/>
7+
</listOfCompartments>
8+
<listOfSpecies>
9+
<species id="A" compartment="default_compartment" hasOnlySubstanceUnits="false" boundaryCondition="false" constant="false"/>
10+
<species id="a" compartment="default_compartment" hasOnlySubstanceUnits="true" boundaryCondition="false" constant="false"/>
11+
<species id="B" compartment="default_compartment" hasOnlySubstanceUnits="false" boundaryCondition="false" constant="false"/>
12+
<species id="b" compartment="default_compartment" hasOnlySubstanceUnits="true" boundaryCondition="false" constant="false"/>
13+
</listOfSpecies>
14+
<listOfParameters>
15+
<parameter id="initial_conc_A" value="2" constant="true"/>
16+
<parameter id="initial_conc_B" value="1" constant="true"/>
17+
<parameter id="k1" value="2" constant="true"/>
18+
<parameter id="k2" value="1" constant="true"/>
19+
</listOfParameters>
20+
<listOfInitialAssignments>
21+
<initialAssignment symbol="A">
22+
<math xmlns="http://www.w3.org/1998/Math/MathML">
23+
<ci> initial_conc_A </ci>
24+
</math>
25+
</initialAssignment>
26+
<initialAssignment symbol="a">
27+
<math xmlns="http://www.w3.org/1998/Math/MathML">
28+
<apply>
29+
<times/>
30+
<ci> initial_conc_A </ci>
31+
<ci> default_compartment </ci>
32+
</apply>
33+
</math>
34+
</initialAssignment>
35+
<initialAssignment symbol="B">
36+
<math xmlns="http://www.w3.org/1998/Math/MathML">
37+
<ci> initial_conc_B </ci>
38+
</math>
39+
</initialAssignment>
40+
<initialAssignment symbol="b">
41+
<math xmlns="http://www.w3.org/1998/Math/MathML">
42+
<apply>
43+
<times/>
44+
<ci> initial_conc_B </ci>
45+
<ci> default_compartment </ci>
46+
</apply>
47+
</math>
48+
</initialAssignment>
49+
</listOfInitialAssignments>
50+
<listOfRules>
51+
<rateRule variable="A">
52+
<math xmlns="http://www.w3.org/1998/Math/MathML">
53+
<apply>
54+
<minus/>
55+
<apply>
56+
<times/>
57+
<ci> k2 </ci>
58+
<ci> B </ci>
59+
</apply>
60+
<apply>
61+
<times/>
62+
<ci> k1 </ci>
63+
<ci> A </ci>
64+
</apply>
65+
</apply>
66+
</math>
67+
</rateRule>
68+
<rateRule variable="a">
69+
<math xmlns="http://www.w3.org/1998/Math/MathML">
70+
<apply>
71+
<minus/>
72+
<apply>
73+
<times/>
74+
<ci> k2 </ci>
75+
<ci> b </ci>
76+
</apply>
77+
<apply>
78+
<times/>
79+
<ci> k1 </ci>
80+
<ci> a </ci>
81+
</apply>
82+
</apply>
83+
</math>
84+
</rateRule>
85+
<rateRule variable="B">
86+
<math xmlns="http://www.w3.org/1998/Math/MathML">
87+
<apply>
88+
<plus/>
89+
<apply>
90+
<times/>
91+
<apply>
92+
<minus/>
93+
<ci> k2 </ci>
94+
</apply>
95+
<ci> B </ci>
96+
</apply>
97+
<apply>
98+
<times/>
99+
<ci> k1 </ci>
100+
<ci> A </ci>
101+
</apply>
102+
</apply>
103+
</math>
104+
</rateRule>
105+
<rateRule variable="b">
106+
<math xmlns="http://www.w3.org/1998/Math/MathML">
107+
<apply>
108+
<plus/>
109+
<apply>
110+
<times/>
111+
<apply>
112+
<minus/>
113+
<ci> k2 </ci>
114+
</apply>
115+
<ci> b </ci>
116+
</apply>
117+
<apply>
118+
<times/>
119+
<ci> k1 </ci>
120+
<ci> a </ci>
121+
</apply>
122+
</apply>
123+
</math>
124+
</rateRule>
125+
</listOfRules>
126+
</model>
127+
</sbml>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
observableId observableFormula noiseFormula
2+
obs_a a 1
3+
obs_A A 1
4+
obs_b b 1
5+
obs_B B 1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
parameterId estimate nominalValue parameterScale lowerBound upperBound
2+
k1 1 2 lin 0 10
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
observableId experimentId time simulation
2+
obs_a 0 4.0
3+
obs_A 0 2.0
4+
obs_b 0 2.0
5+
obs_B 0 1.0
6+
obs_a 5 2.000000611804641
7+
obs_A 5 1.0000003059023206
8+
obs_b 5 3.999999388195359
9+
obs_B 5 1.9999996940976794
10+
obs_a 10 25.0
11+
obs_A 10 2.5
12+
obs_b 10 10.0
13+
obs_B 10 1.0
14+
obs_a 15 11.666670745364273
15+
obs_A 15 1.1666670745364274
16+
obs_b 15 23.33332925463573
17+
obs_B 15 2.333332925463573

0 commit comments

Comments
 (0)