Skip to content
Merged
87 changes: 87 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0032/0032.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 handling of parameters to be estimated both assigning
initial concentrations, and appearing in the observable formula.
For species `A`, the initial concentration is estimated, and the parameter
setting the concentration of A appears in the observable formulas. For species
`B`, the initial concentration is specified in the parameters table.

## Model

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

# problem --------------------------------------------------------------------
ant_model = """
model *petab_test_0032()
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_A", B="initial_B")
problem.add_experiment("e1", 0, "c0")

problem.add_observable("obs_a", "A + initial_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_A", lb=1, ub=10, nominal_value=2, estimate=True)
problem.add_parameter(
"initial_B", lb=0, ub=10, nominal_value=3, estimate=False
)


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

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

case = PetabV2TestCase.from_problem(
id=32,
brief="Simulation. A parameter to estimate both sets initial value and appears in observable \
formulas",
description=DESCRIPTION,
model=model_file,
problem=problem,
simulation_df=simulation_df,
)
14 changes: 14 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0032/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# PEtab test case 0032

## Objective

This case tests handling of parameters to be estimated both assigning
initial concentrations, and appearing in the observable formula.
For species `A`, the initial concentration is estimated, and the parameter
setting the concentration of A appears in the observable formulas. For species
`B`, the initial concentration is specified in the parameters table.

## 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/0032/_0032.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/0032/_0032_solution.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
chi2: 160.50612122714156
llh: -81.1562260241497
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/0032/_conditions.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
conditionId targetId targetValue
c0 A initial_A
c0 B initial_B
2 changes: 2 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0032/_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/0032/_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/0032/_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_0032" id="petab_test_0032">
<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/0032/_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 + initial_A 0.500000000000000 normal
obs_b B 0.500000000000000 normal
5 changes: 5 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0032/_parameters.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameterId lowerBound upperBound nominalValue estimate priorDistribution priorParameters
k1 0.0 10.0 0.8 true
k2 0.0 10.0 0.6 true
initial_A 1.0 10.0 2.0 true
initial_B 0.0 10.0 3.0 false
5 changes: 5 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0032/_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 4.0
obs_a e1 10.0 4.142857024067325
obs_b e1 0.0 3.0
obs_b e1 10.0 2.8571429759326743
4 changes: 4 additions & 0 deletions petabtests/cases/v2.0.0/sbml/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,7 @@ Simultaneous trigger of PEtab condition and SBML event.

Simulation. Two PEtab conditions applied at the same time point.

# [0032](0032/)

Simulation. A parameter to estimate both sets initial value and appears in observable formulas

Loading