Skip to content

Commit 9542847

Browse files
sebaperssondweindl
andauthored
Two PEtab conditions simultaneously (#108)
Test case with two PEtab conditions triggering simultaneously. As per the spec, they should be treated as a single event. --------- Co-authored-by: Daniel Weindl <[email protected]>
1 parent f8c2840 commit 9542847

File tree

12 files changed

+226
-0
lines changed

12 files changed

+226
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
from inspect import cleandoc
2+
3+
from petab.v2.C import *
4+
from petab.v2 import Problem
5+
from petabtests import PetabV2TestCase, analytical_a, analytical_b, DEFAULT_SBML_FILE
6+
7+
DESCRIPTION = cleandoc("""
8+
## Objective
9+
10+
This case tests applying two PEtab conditions simultaneously, at a time
11+
point that also has measurement values.
12+
13+
## Model
14+
15+
A simple conversion reaction `A <=> B` in a single compartment, following
16+
mass action kinetics.
17+
""")
18+
19+
# problem --------------------------------------------------------------------
20+
a0 = 1
21+
b0 = 1
22+
k1 = 0.8
23+
k2 = 0.6
24+
problem = Problem()
25+
26+
problem.add_condition(
27+
"condition1",
28+
A="A + 5.0",
29+
)
30+
problem.add_condition(
31+
"condition2",
32+
B="B + 3.0",
33+
)
34+
problem.add_experiment("experiment1",
35+
0, "",
36+
10, "condition1",
37+
10, "condition2")
38+
39+
problem.add_observable("obs_a", "A", noise_formula="0.5")
40+
problem.add_observable("obs_b", "B", noise_formula="0.1")
41+
problem.add_measurement("obs_a", experiment_id="experiment1", time=0, measurement=0.7)
42+
problem.add_measurement("obs_b", experiment_id="experiment1", time=0, measurement=1.0)
43+
problem.add_measurement("obs_a", experiment_id="experiment1", time=10, measurement=0.1)
44+
problem.add_measurement("obs_b", experiment_id="experiment1", time=10, measurement=0.4)
45+
46+
problem.add_parameter("k1", lb=0, ub=10, nominal_value=k1, estimate=True)
47+
problem.add_parameter("k2", lb=0, ub=10, nominal_value=k2, estimate=True)
48+
49+
50+
# solutions ------------------------------------------------------------------
51+
52+
simulation_df = problem.measurement_df.copy(deep=True).rename(
53+
columns={MEASUREMENT: SIMULATION}
54+
)
55+
# in the model, concentrations are used, which do not depend on the
56+
# compartment size, so that the species values should stay the same
57+
simulation_df[SIMULATION] = [
58+
a0,
59+
b0,
60+
analytical_a(10.0, a0=a0, b0=b0, k1=k1, k2=k2) + 5.0,
61+
analytical_b(10.0, a0=a0, b0=b0, k1=k1, k2=k2) + 3.0,
62+
]
63+
64+
case = PetabV2TestCase.from_problem(
65+
id=31,
66+
brief="Simulation. Two PEtab conditions applied at the same "
67+
"time point.",
68+
description=DESCRIPTION,
69+
model=DEFAULT_SBML_FILE,
70+
problem=problem,
71+
simulation_df=simulation_df,
72+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# PEtab test case 0031
2+
3+
## Objective
4+
5+
This case tests applying two PEtab conditions simultaneously, at a time
6+
point that also has measurement values.
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+
condition_files:
2+
- _conditions.tsv
3+
experiment_files:
4+
- _experiments.tsv
5+
format_version: 2.0.0
6+
measurement_files:
7+
- _measurements.tsv
8+
model_files:
9+
model_0:
10+
language: sbml
11+
location: _model.xml
12+
observable_files:
13+
- _observables.tsv
14+
parameter_files:
15+
- _parameters.tsv
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
chi2: 1533.8366512423358
2+
llh: -764.6026152068787
3+
simulation_files:
4+
- _simulations.tsv
5+
tol_chi2: 0.001
6+
tol_llh: 0.001
7+
tol_simulations: 0.001
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
conditionId targetId targetValue
2+
condition1 A A + 5.0
3+
condition2 B B + 3.0
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
experimentId time conditionId
2+
experiment1 0.0
3+
experiment1 10.0 condition1
4+
experiment1 10.0 condition2
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
modelId observableId experimentId time measurement observableParameters noiseParameters
2+
obs_a experiment1 0.0 0.7
3+
obs_b experiment1 0.0 1.0
4+
obs_a experiment1 10.0 0.1
5+
obs_b experiment1 10.0 0.4
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<sbml xmlns="http://www.sbml.org/sbml/level2/version4" level="2" version="4">
3+
<model id="conversion_reaction_0" name="Conversion Reaction 0">
4+
5+
<listOfUnitDefinitions>
6+
<unitDefinition id="volume" name="volume">
7+
<listOfUnits>
8+
<unit kind="litre" exponent="1" scale="-3" multiplier="1"/>
9+
</listOfUnits>
10+
</unitDefinition>
11+
<unitDefinition id="substance" name="substance">
12+
<listOfUnits>
13+
<unit kind="mole" exponent="1" scale="-3" multiplier="1"/>
14+
</listOfUnits>
15+
</unitDefinition>
16+
</listOfUnitDefinitions>
17+
18+
<listOfCompartments>
19+
<compartment id="compartment" name="compartment" spatialDimensions="3" size="1" constant="true">
20+
</compartment>
21+
</listOfCompartments>
22+
23+
<listOfSpecies>
24+
<species id="A" name="A" compartment="compartment" initialConcentration="2" boundaryCondition="false" constant="false">
25+
</species>
26+
<species id="B" name="B" compartment="compartment" initialConcentration="2" boundaryCondition="false" constant="false">
27+
</species>
28+
</listOfSpecies>
29+
30+
<listOfParameters>
31+
<parameter id="a0" name="a0" value="1" constant="true">
32+
</parameter>
33+
<parameter id="b0" name="b0" value="1" constant="true">
34+
</parameter>
35+
<parameter id="k1" name="k1" value="0" constant="true">
36+
</parameter>
37+
<parameter id="k2" name="k2" value="0" constant="true">
38+
</parameter>
39+
</listOfParameters>
40+
41+
<listOfInitialAssignments>
42+
<initialAssignment symbol="A">
43+
<math xmlns="http://www.w3.org/1998/Math/MathML">
44+
<ci> a0 </ci>
45+
</math>
46+
</initialAssignment>
47+
<initialAssignment symbol="B">
48+
<math xmlns="http://www.w3.org/1998/Math/MathML">
49+
<ci> b0 </ci>
50+
</math>
51+
</initialAssignment>
52+
</listOfInitialAssignments>
53+
54+
<listOfReactions>
55+
<reaction id="fwd" name="fwd" reversible="false">
56+
<listOfReactants>
57+
<speciesReference species="A" stoichiometry="1"/>
58+
</listOfReactants>
59+
<listOfProducts>
60+
<speciesReference species="B" stoichiometry="1"/>
61+
</listOfProducts>
62+
<kineticLaw>
63+
<math xmlns="http://www.w3.org/1998/Math/MathML">
64+
<apply>
65+
<times/>
66+
<ci> compartment </ci>
67+
<ci> k1 </ci>
68+
<ci> A </ci>
69+
</apply>
70+
</math>
71+
</kineticLaw>
72+
</reaction>
73+
<reaction id="rev" name="rev" reversible="false">
74+
<listOfReactants>
75+
<speciesReference species="B" stoichiometry="1"/>
76+
</listOfReactants>
77+
<listOfProducts>
78+
<speciesReference species="A" stoichiometry="1"/>
79+
</listOfProducts>
80+
<kineticLaw>
81+
<math xmlns="http://www.w3.org/1998/Math/MathML">
82+
<apply>
83+
<times/>
84+
<ci> compartment </ci>
85+
<ci> k2 </ci>
86+
<ci> B </ci>
87+
</apply>
88+
</math>
89+
</kineticLaw>
90+
</reaction>
91+
</listOfReactions>
92+
93+
</model>
94+
</sbml>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
observableId observableName observableFormula noiseFormula noiseDistribution observablePlaceholders noisePlaceholders
2+
obs_a A 0.500000000000000 normal
3+
obs_b B 0.100000000000000 normal
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
parameterId lowerBound upperBound nominalValue estimate priorDistribution priorParameters
2+
k1 0.0 10.0 0.8 true
3+
k2 0.0 10.0 0.6 true

0 commit comments

Comments
 (0)