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
87 changes: 87 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0026/0026.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
from inspect import cleandoc

from petab.v2.C import *
from petab.v2 import Problem

from petabtests import (
PetabV2TestCase,
analytical_a,
analytical_b,
antimony_to_sbml_str,
)
from pathlib import Path

DESCRIPTION = cleandoc("""
## Objective

This case tests the handling of initial concentrations that are specified
via mathematical expressions (rather than a single value or parameter) in
the conditions table. For species `A`, the initial concentration is given
by an expression containing both parameters to be estimated and parameters
that are not estimated. For species `B`, the initial concentration is
specified via an expression involving only parameters that are not
estimated.

## Model

A simple conversion reaction `A <=> B` in a single compartment, following
mass action kinetics.
""")

# problem --------------------------------------------------------------------
ant_model = """
model *petab_test_0026()
compartment compartment_ = 1;
species A in compartment_, B in compartment_;

fwd: A => B; compartment_ * k1 * A;
rev: B => A; compartment_ * k2 * B;

A = a0;
B = 1;
a0 = 1;
k1 = 0;
k2 = 0;
end
"""
model_file = Path(__file__).parent / "_model.xml"
model_file.write_text(antimony_to_sbml_str(ant_model))

problem = Problem()

problem.add_condition("c0", A="initial_A1 + initial_A2", B="initial_B1 / initial_B2")
problem.add_experiment("e1", 0, "c0")

problem.add_observable("obs_a", "A", noise_formula="0.5")
problem.add_observable("obs_b", "B", noise_formula="0.5")
problem.add_measurement("obs_a", experiment_id="e1", time=0, measurement=0.7)
problem.add_measurement("obs_a", experiment_id="e1", time=10, measurement=0.1)
problem.add_measurement("obs_b", experiment_id="e1", time=0, measurement=0.7)
problem.add_measurement("obs_b", experiment_id="e1", time=10, measurement=0.1)

problem.add_parameter("k1", lb=0, ub=10, nominal_value=0.8, estimate=True)
problem.add_parameter("k2", lb=0, ub=10, nominal_value=0.6, estimate=True)
problem.add_parameter("initial_A1", lb=1, ub=10, nominal_value=0.5, estimate=True)
problem.add_parameter("initial_A2", lb=1, ub=10, nominal_value=1.5, estimate=False)
problem.add_parameter("initial_B1", lb=0, ub=10, nominal_value=9, estimate=False)
problem.add_parameter("initial_B2", lb=0, ub=10, nominal_value=3, estimate=False)


# solutions ------------------------------------------------------------------

simulation_df = problem.measurement_df.copy(deep=True).rename(
columns={MEASUREMENT: SIMULATION}
)
simulation_df[SIMULATION] = [
*(analytical_a(t, 2, 3, 0.8, 0.6) for t in (0, 10)),
*(analytical_b(t, 2, 3, 0.8, 0.6) for t in (0, 10)),
]

case = PetabV2TestCase.from_problem(
id=26,
brief="Simulation. Estimated initial value via math expressions in conditions table.",
description=DESCRIPTION,
model=model_file,
problem=problem,
simulation_df=simulation_df,
)
16 changes: 16 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0026/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# PEtab test case 0026

## Objective

This case tests the handling of initial concentrations that are specified
via mathematical expressions (rather than a single value or parameter) in
the conditions table. For species `A`, the initial concentration is given
by an expression containing both parameters to be estimated and parameters
that are not estimated. For species `B`, the initial concentration is
specified via an expression involving only parameters that are not
estimated.

## Model

A simple conversion reaction `A <=> B` in a single compartment, following
mass action kinetics.
15 changes: 15 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0026/_0026.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
condition_files:
- _conditions.tsv
experiment_files:
- _experiments.tsv
format_version: 2.0.0
measurement_files:
- _measurements.tsv
model_files:
model_0:
language: sbml
location: _model.xml
observable_files:
- _observables.tsv
parameter_files:
- _parameters.tsv
7 changes: 7 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0026/_0026_solution.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
chi2: 75.02040884206437
llh: -38.41336983161109
simulation_files:
- _simulations.tsv
tol_chi2: 0.001
tol_llh: 0.001
tol_simulations: 0.001
3 changes: 3 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0026/_conditions.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
conditionId targetId targetValue
c0 A initial_A1 + initial_A2
c0 B initial_B1/initial_B2
2 changes: 2 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0026/_experiments.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
experimentId time conditionId
e1 0.0 c0
5 changes: 5 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0026/_measurements.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
modelId observableId experimentId time measurement observableParameters noiseParameters
obs_a e1 0.0 0.7
obs_a e1 10.0 0.1
obs_b e1 0.0 0.7
obs_b e1 10.0 0.1
63 changes: 63 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0026/_model.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created by libAntimony version v3.1.1 with libSBML version 5.20.5. -->
<sbml xmlns="http://www.sbml.org/sbml/level3/version2/core" level="3" version="2">
<model metaid="petab_test_0026" id="petab_test_0026">
<listOfCompartments>
<compartment id="compartment_" spatialDimensions="3" size="1" constant="true"/>
</listOfCompartments>
<listOfSpecies>
<species id="A" compartment="compartment_" hasOnlySubstanceUnits="false" boundaryCondition="false" constant="false"/>
<species id="B" compartment="compartment_" initialConcentration="1" hasOnlySubstanceUnits="false" boundaryCondition="false" constant="false"/>
</listOfSpecies>
<listOfParameters>
<parameter id="k1" value="0" constant="true"/>
<parameter id="k2" value="0" constant="true"/>
<parameter id="a0" value="1" constant="true"/>
</listOfParameters>
<listOfInitialAssignments>
<initialAssignment symbol="A">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<ci> a0 </ci>
</math>
</initialAssignment>
</listOfInitialAssignments>
<listOfReactions>
<reaction id="fwd" reversible="false">
<listOfReactants>
<speciesReference species="A" stoichiometry="1" constant="true"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="B" stoichiometry="1" constant="true"/>
</listOfProducts>
<kineticLaw>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply>
<times/>
<ci> compartment_ </ci>
<ci> k1 </ci>
<ci> A </ci>
</apply>
</math>
</kineticLaw>
</reaction>
<reaction id="rev" reversible="false">
<listOfReactants>
<speciesReference species="B" stoichiometry="1" constant="true"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="A" stoichiometry="1" constant="true"/>
</listOfProducts>
<kineticLaw>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply>
<times/>
<ci> compartment_ </ci>
<ci> k2 </ci>
<ci> B </ci>
</apply>
</math>
</kineticLaw>
</reaction>
</listOfReactions>
</model>
</sbml>
3 changes: 3 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0026/_observables.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
observableId observableName observableFormula noiseFormula noiseDistribution observablePlaceholders noisePlaceholders
obs_a A 0.500000000000000 normal
obs_b B 0.500000000000000 normal
7 changes: 7 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0026/_parameters.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameterId lowerBound upperBound nominalValue estimate priorDistribution priorParameters
k1 0.0 10.0 0.8 true
k2 0.0 10.0 0.6 true
initial_A1 1.0 10.0 0.5 true
initial_A2 1.0 10.0 1.5 false
initial_B1 0.0 10.0 9.0 false
initial_B2 0.0 10.0 3.0 false
5 changes: 5 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0026/_simulations.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
modelId observableId experimentId time simulation observableParameters noiseParameters
obs_a e1 0.0 2.0
obs_a e1 10.0 2.1428570240673257
obs_b e1 0.0 3.0
obs_b e1 10.0 2.8571429759326743
86 changes: 86 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0027/0027.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from inspect import cleandoc
from pathlib import Path

from petab.v2.C import *
from petab.v2 import Problem
from petabtests import PetabV2TestCase, analytical_a, antimony_to_sbml_str

DESCRIPTION = cleandoc("""
## Objective

This case tests support for parametric overrides from condition table
via math expressions.

The model is simulated for two different experimental conditions
(here: different initial concentrations). The observable is offset via
a parametric override in the condition table (i.e. the actual value
has to be taken from the parameter table). The formulas in the
condition table are mathematical expressions consisting of
numerical values, parameters to be estimated, and parameters that
are not to be estimated.

## Model

A simple conversion reaction `A <=> B` in a single compartment, following
mass action kinetics.
""")

# problem --------------------------------------------------------------------
ant_model = """
model *petab_test_0027()
compartment compartment_ = 1;
species A in compartment_, B in compartment_;

fwd: A => B; compartment_ * k1 * A;
rev: B => A; compartment_ * k2 * B;

A = a0;
B = b0;
offset_A = 0;
a0 = 1;
b0 = 0;
k1 = 0;
k2 = 0;
end
"""
model_file = Path(__file__).parent / "_model.xml"
model_file.write_text(antimony_to_sbml_str(ant_model))

problem = Problem()
problem.add_condition("c0", offset_A="offset_A1_c0 + offset_A2_c0")
problem.add_condition("c1", offset_A="offset_A1_c1 / 3.0")

problem.add_experiment("e1", 0, "c0")
problem.add_experiment("e2", 0, "c1")

problem.add_observable("obs_a", "A + offset_A", noise_formula="1")

problem.add_measurement("obs_a", experiment_id="e1", time=10, measurement=2.1)
problem.add_measurement("obs_a", experiment_id="e2", time=10, measurement=3.2)

problem.add_parameter("a0", lb=0, ub=10, nominal_value=1, estimate=True)
problem.add_parameter("b0", lb=0, ub=10, nominal_value=0, estimate=True)
problem.add_parameter("k1", lb=0, ub=10, nominal_value=0.8, estimate=True)
problem.add_parameter("k2", lb=0, ub=10, nominal_value=0.6, estimate=True)
problem.add_parameter("offset_A1_c0", lb=0, ub=10, nominal_value=0.5, estimate=True)
problem.add_parameter("offset_A2_c0", lb=0, ub=10, nominal_value=1.5, estimate=False)
problem.add_parameter("offset_A1_c1", lb=0, ub=10, nominal_value=9, estimate=True)

# solutions ------------------------------------------------------------------

simulation_df = problem.measurement_df.copy(deep=True).rename(
columns={MEASUREMENT: SIMULATION}
)
simulation_df[SIMULATION] = [
analytical_a(10, 1, 0, 0.8, 0.6) + offset for offset in [2, 3]
]

case = PetabV2TestCase.from_problem(
id=27,
brief="Simulation. Condition-specific parameters defined via "
"math expressions in the parameter table.",
description=DESCRIPTION,
model=model_file,
problem=problem,
simulation_df=simulation_df,
)
19 changes: 19 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0027/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# PEtab test case 0027

## Objective

This case tests support for parametric overrides from condition table
via math expressions.

The model is simulated for two different experimental conditions
(here: different initial concentrations). The observable is offset via
a parametric override in the condition table (i.e. the actual value
has to be taken from the parameter table). The formulas in the
condition table are mathematical expressions consisting of
numerical values, parameters to be estimated, and parameters that
are not to be estimated.

## Model

A simple conversion reaction `A <=> B` in a single compartment, following
mass action kinetics.
15 changes: 15 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0027/_0027.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
condition_files:
- _conditions.tsv
experiment_files:
- _experiments.tsv
format_version: 2.0.0
measurement_files:
- _measurements.tsv
model_files:
model_0:
language: sbml
location: _model.xml
observable_files:
- _observables.tsv
parameter_files:
- _parameters.tsv
7 changes: 7 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0027/_0027_solution.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
chi2: 0.16020461109629
llh: -1.91797937195749
simulation_files:
- _simulations.tsv
tol_chi2: 0.001
tol_llh: 0.001
tol_simulations: 0.001
3 changes: 3 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0027/_conditions.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
conditionId targetId targetValue
c0 offset_A offset_A1_c0 + offset_A2_c0
c1 offset_A 0.333333333333333*offset_A1_c1
3 changes: 3 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0027/_experiments.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
experimentId time conditionId
e1 0.0 c0
e2 0.0 c1
3 changes: 3 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0027/_measurements.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
modelId observableId experimentId time measurement observableParameters noiseParameters
obs_a e1 10.0 2.1
obs_a e2 10.0 3.2
Loading