Skip to content

Commit

Permalink
Add test case with estimated initial conditions specified via the con… (
Browse files Browse the repository at this point in the history
#63)

Add test case with estimated initial conditions specified via the conditions table

Closes #62


Co-authored-by: Dilan Pathirana <59329744+dilpath@users.noreply.github.com>
  • Loading branch information
dweindl and dilpath authored Jun 13, 2024
1 parent 2222464 commit 7c264b4
Show file tree
Hide file tree
Showing 26 changed files with 590 additions and 2 deletions.
2 changes: 1 addition & 1 deletion petabtests/cases/v1.0.0/sbml/0011/0011.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
This case tests initial concentrations in the condition table.
For species `B`, the initial concentration is specified in the condition
table, while for `A` it is given via an assignment rule in the SBML model.
table, while for `A` it is given via an initial assignment in the SBML model.
## Model
Expand Down
2 changes: 1 addition & 1 deletion petabtests/cases/v1.0.0/sbml/0011/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

This case tests initial concentrations in the condition table.
For species `B`, the initial concentration is specified in the condition
table, while for `A` it is given via an assignment rule in the SBML model.
table, while for `A` it is given via an initial assignment in the SBML model.

## Model

Expand Down
69 changes: 69 additions & 0 deletions petabtests/cases/v1.0.0/sbml/0019/0019.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from inspect import cleandoc

import pandas as pd
from petab.C import *

from petabtests import PetabTestCase, analytical_a

DESCRIPTION = cleandoc("""
## Objective
This case tests handling of initial concentrations that are specified
in the conditions table. For species `A`, the initial concentration is
estimated. 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 --------------------------------------------------------------------

condition_df = pd.DataFrame(data={
CONDITION_ID: ['c0'],
'A': ["initial_A"],
'B': ["initial_B"],
}).set_index([CONDITION_ID])

measurement_df = pd.DataFrame(data={
OBSERVABLE_ID: ['obs_a', 'obs_a'],
SIMULATION_CONDITION_ID: ['c0', 'c0'],
TIME: [0, 10],
MEASUREMENT: [0.7, 0.1]
})

observable_df = pd.DataFrame(data={
OBSERVABLE_ID: ['obs_a'],
OBSERVABLE_FORMULA: ['A'],
NOISE_FORMULA: [0.5]
}).set_index([OBSERVABLE_ID])

parameter_df = pd.DataFrame(data={
PARAMETER_ID: ['k1', 'k2', 'initial_A', 'initial_B'],
PARAMETER_SCALE: [LIN, LIN, LOG10, LIN],
LOWER_BOUND: [0, 0, 1, 0],
UPPER_BOUND: [10] * 4,
NOMINAL_VALUE: [0.8, 0.6, 2, 3],
ESTIMATE: [1] * 3 + [0],
}).set_index(PARAMETER_ID)

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

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

case = PetabTestCase(
id=19,
brief="Simulation. Estimated initial value via conditions table.",
description=DESCRIPTION,
model='conversion_modified.xml',
condition_dfs=[condition_df],
observable_dfs=[observable_df],
measurement_dfs=[measurement_df],
simulation_dfs=[simulation_df],
parameter_df=parameter_df,
)
13 changes: 13 additions & 0 deletions petabtests/cases/v1.0.0/sbml/0019/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# PEtab test case 0019

## Objective

This case tests handling of initial concentrations that are specified
in the conditions table. For species `A`, the initial concentration is
estimated. 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.
11 changes: 11 additions & 0 deletions petabtests/cases/v1.0.0/sbml/0019/_0019.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
format_version: 1
parameter_file: _parameters.tsv
problems:
- condition_files:
- _conditions.tsv
measurement_files:
- _measurements.tsv
observable_files:
- _observables.tsv
sbml_files:
- _model.xml
7 changes: 7 additions & 0 deletions petabtests/cases/v1.0.0/sbml/0019/_0019_solution.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
chi2: 23.45305928312484
llh: -12.17811234685187
simulation_files:
- _simulations.tsv
tol_chi2: 0.001
tol_llh: 0.001
tol_simulations: 0.001
2 changes: 2 additions & 0 deletions petabtests/cases/v1.0.0/sbml/0019/_conditions.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
conditionId A B
c0 initial_A initial_B
3 changes: 3 additions & 0 deletions petabtests/cases/v1.0.0/sbml/0019/_measurements.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
observableId simulationConditionId time measurement
obs_a c0 0 0.7
obs_a c0 10 0.1
87 changes: 87 additions & 0 deletions petabtests/cases/v1.0.0/sbml/0019/_model.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<sbml xmlns="http://www.sbml.org/sbml/level2/version4" level="2" version="4">
<model id="conversion_reaction_0" name="Conversion Reaction 0">

<listOfUnitDefinitions>
<unitDefinition id="volume" name="volume">
<listOfUnits>
<unit kind="litre" exponent="1" scale="-3" multiplier="1"/>
</listOfUnits>
</unitDefinition>
<unitDefinition id="substance" name="substance">
<listOfUnits>
<unit kind="mole" exponent="1" scale="-3" multiplier="1"/>
</listOfUnits>
</unitDefinition>
</listOfUnitDefinitions>

<listOfCompartments>
<compartment id="compartment" name="compartment" spatialDimensions="3" size="1" constant="true">
</compartment>
</listOfCompartments>

<listOfSpecies>
<species id="A" name="A" compartment="compartment" initialConcentration="1" boundaryCondition="false" constant="false">
</species>
<species id="B" name="B" compartment="compartment" initialConcentration="1" boundaryCondition="false" constant="false">
</species>
</listOfSpecies>

<listOfParameters>
<parameter id="a0" name="a0" value="1" constant="true">
</parameter>
<parameter id="k1" name="k1" value="0" constant="true">
</parameter>
<parameter id="k2" name="k2" value="0" constant="true">
</parameter>
</listOfParameters>

<listOfInitialAssignments>
<initialAssignment symbol="A">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<ci> a0 </ci>
</math>
</initialAssignment>
</listOfInitialAssignments>

<listOfReactions>
<reaction id="fwd" name="fwd" reversible="false">
<listOfReactants>
<speciesReference species="A" stoichiometry="1"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="B" stoichiometry="1"/>
</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" name="rev" reversible="false">
<listOfReactants>
<speciesReference species="B" stoichiometry="1"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="A" stoichiometry="1"/>
</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>
2 changes: 2 additions & 0 deletions petabtests/cases/v1.0.0/sbml/0019/_observables.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
observableId observableFormula noiseFormula
obs_a A 0.5
5 changes: 5 additions & 0 deletions petabtests/cases/v1.0.0/sbml/0019/_parameters.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameterId parameterScale lowerBound upperBound nominalValue estimate
k1 lin 0 10 0.8 1
k2 lin 0 10 0.6 1
initial_A log10 1 10 2.0 1
initial_B lin 0 10 3.0 0
3 changes: 3 additions & 0 deletions petabtests/cases/v1.0.0/sbml/0019/_simulations.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
observableId simulationConditionId time simulation
obs_a c0 0 2.0
obs_a c0 10 2.1428570240673257
87 changes: 87 additions & 0 deletions petabtests/cases/v1.0.0/sbml/0019/conversion_modified.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<sbml xmlns="http://www.sbml.org/sbml/level2/version4" level="2" version="4">
<model id="conversion_reaction_0" name="Conversion Reaction 0">

<listOfUnitDefinitions>
<unitDefinition id="volume" name="volume">
<listOfUnits>
<unit kind="litre" exponent="1" scale="-3" multiplier="1"/>
</listOfUnits>
</unitDefinition>
<unitDefinition id="substance" name="substance">
<listOfUnits>
<unit kind="mole" exponent="1" scale="-3" multiplier="1"/>
</listOfUnits>
</unitDefinition>
</listOfUnitDefinitions>

<listOfCompartments>
<compartment id="compartment" name="compartment" spatialDimensions="3" size="1" constant="true">
</compartment>
</listOfCompartments>

<listOfSpecies>
<species id="A" name="A" compartment="compartment" initialConcentration="1" boundaryCondition="false" constant="false">
</species>
<species id="B" name="B" compartment="compartment" initialConcentration="1" boundaryCondition="false" constant="false">
</species>
</listOfSpecies>

<listOfParameters>
<parameter id="a0" name="a0" value="1" constant="true">
</parameter>
<parameter id="k1" name="k1" value="0" constant="true">
</parameter>
<parameter id="k2" name="k2" value="0" constant="true">
</parameter>
</listOfParameters>

<listOfInitialAssignments>
<initialAssignment symbol="A">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<ci> a0 </ci>
</math>
</initialAssignment>
</listOfInitialAssignments>

<listOfReactions>
<reaction id="fwd" name="fwd" reversible="false">
<listOfReactants>
<speciesReference species="A" stoichiometry="1"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="B" stoichiometry="1"/>
</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" name="rev" reversible="false">
<listOfReactants>
<speciesReference species="B" stoichiometry="1"/>
</listOfReactants>
<listOfProducts>
<speciesReference species="A" stoichiometry="1"/>
</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>
4 changes: 4 additions & 0 deletions petabtests/cases/v1.0.0/sbml/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ Simulation. Preequilibration. One species reinitialized, one not (NaN in conditi

Simulation. Preequilibration and RateRules. One state reinitialized, one not (NaN in condition table). InitialAssignment to species overridden.

# [0019](0019/)

Simulation. Estimated initial value via conditions table.

69 changes: 69 additions & 0 deletions petabtests/cases/v2.0.0/sbml/0020/0020.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from inspect import cleandoc

import pandas as pd
from petab.C import *

from petabtests import PetabTestCase, analytical_a

DESCRIPTION = cleandoc("""
## Objective
This case tests handling of initial concentrations that are specified
in the conditions table. For species `A`, the initial concentration is
estimated. 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 --------------------------------------------------------------------

condition_df = pd.DataFrame(data={
CONDITION_ID: ['c0'],
'A': ["initial_A"],
'B': ["initial_B"],
}).set_index([CONDITION_ID])

measurement_df = pd.DataFrame(data={
OBSERVABLE_ID: ['obs_a', 'obs_a'],
SIMULATION_CONDITION_ID: ['c0', 'c0'],
TIME: [0, 10],
MEASUREMENT: [0.7, 0.1]
})

observable_df = pd.DataFrame(data={
OBSERVABLE_ID: ['obs_a'],
OBSERVABLE_FORMULA: ['A'],
NOISE_FORMULA: [0.5]
}).set_index([OBSERVABLE_ID])

parameter_df = pd.DataFrame(data={
PARAMETER_ID: ['k1', 'k2', 'initial_A', 'initial_B'],
PARAMETER_SCALE: [LIN, LIN, LOG10, LIN],
LOWER_BOUND: [0, 0, 1, 0],
UPPER_BOUND: [10] * 4,
NOMINAL_VALUE: [0.8, 0.6, 2, 3],
ESTIMATE: [1] * 3 + [0],
}).set_index(PARAMETER_ID)

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

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

case = PetabTestCase(
id=20,
brief="Simulation. Estimated initial value via conditions table.",
description=DESCRIPTION,
model='conversion_modified.xml',
condition_dfs=[condition_df],
observable_dfs=[observable_df],
measurement_dfs=[measurement_df],
simulation_dfs=[simulation_df],
parameter_df=parameter_df,
)
Loading

0 comments on commit 7c264b4

Please sign in to comment.