Skip to content

Build the model

You do not draw a model by hand. PhosKinTime builds it from three things:

flowchart LR
    N["networks<br/>who acts on whom"] --> B["model builder"]
    M["mechanism file<br/>which reactions, which rate laws"] --> B
    C["config.toml<br/>and your data"] --> B
    B --> S["SBML file<br/>results/model/model.xml"]
  • Change who acts on whom: edit the network files.
  • Change how things react: choose another mechanism, or write your own.
  • Change what is measured and when: edit the data and config.toml.

The SBML file

SBML is the standard file format for models in systems biology. Every simulation, fit and export of PhosKinTime uses the run's SBML file, <run folder>/model/model.xml. It is XML: readable, but long. Do not edit it; change the inputs and run again.

SBML words you need:

SBML word meaning here
species a number that changes: R_A (mRNA of A), P_A (unmodified protein A), X_A_S_1 (A phosphorylated at S_1)
reaction one arrow, with a rate law
parameter a constant, such as E_A
assignment rule a formula that is recomputed at every moment, such as S_A_S_2

Look inside, from Python

Save as look_sbml.py in the phoskintime folder:

import libsbml

model = libsbml.readSBML("my-project/results/model/model.xml").getModel()
print("species:   ", model.getNumSpecies())
print("reactions: ", model.getNumReactions())
print("parameters:", model.getNumParameters())

for rid in ["rx_transcription_B", "rx_phosphorylation_A_S_2", "rx_dephosphorylation_A_S_2"]:
    r = model.getReaction(rid)
    left = " + ".join(s.getSpecies() for s in r.getListOfReactants()) or "nothing"
    right = " + ".join(s.getSpecies() for s in r.getListOfProducts()) or "nothing"
    print(f"{rid}: {left} -> {right}   rate = {libsbml.formulaToL3String(r.getKineticLaw().getMath())}")

for name in ["S_A_S_2", "synth_B"]:
    rule = model.getAssignmentRuleByVariable(name)
    if rule is not None:
        print(f"{name} = {libsbml.formulaToL3String(rule.getMath())[:300]}")
pixi run python look_sbml.py
species:    19
reactions:  36
parameters: 67
rx_transcription_B: nothing -> R_B   rate = synth_B
rx_phosphorylation_A_S_2: P_A -> X_A_S_2   rate = S_A_S_2 * P_A
rx_dephosphorylation_A_S_2: X_A_S_2 -> P_A   rate = E_A * X_A_S_2
S_A_S_2 = 1 dimensionless * Kt_K1 + 0 dimensionless * Kt_K2
synth_B = piecewise(A_B * (1 dimensionless + tf_scale * q_B / (1 dimensionless + q_B + 1e-6 dimensionless)), q_B >= 0 dimensionless, A_B / (1 dimensionless + tf_scale * abs(q_B)))

Read the line S_A_S_2: site S_2 of protein A is phosphorylated by K1 with weight 1 and by K2 with weight 0. The weight 0 comes from the KinOpt workbook: the edge is in the network but has no effect. Check this kind of line when a knockout "does nothing".

To get the equations of your run as a readable document, export the standards archive and open equations.md in it.

Mechanism files

A mechanism file lists the reactions of one protein and their rate laws, in plain text (TOML). PhosKinTime ships models/distributive.toml, sequential.toml, combinatorial.toml and saturation.toml, and one example for another modification, models/examples/acetylation_mm.toml.

One reaction looks like this:

[[reactions]]
kind = "dephosphorylation"      # a name; the SBML reaction becomes rx_dephosphorylation_<site>
per = "site"                    # repeat this reaction for every site
reactants = ["X"]               # consumed: the phosphorylated form
products = ["P"]                # produced: the unmodified protein
rate = "{E} * {X}"              # the rate law
sbo = "SBO:0000330"             # optional annotation
go = "GO:0006470"               # optional annotation

To choose a shipped family, edit config.toml:

[networkmodel.models]
default_model = "distributive"   # or sequential, combinatorial, saturation

Write your own mechanism

Question: what if phosphatases saturate, so that dephosphorylation slows down when much substrate is phosphorylated? Replace E * X by E * X / (1 + X).

1. Copy the shipped file (use the example project from Your first model):

cp models/distributive.toml my-project/mm_dephos.toml

2. Edit the copy. Change the name at the top:

[mechanism]
name = "mm_dephos"
family = "distributive"     # keep: it fixes which species exist
doc = "distributive with saturating dephosphorylation"

In the reaction with kind = "dephosphorylation", change the rate and delete its sbo line (the term described the old rate law's kind of reaction):

rate = "{E} * {X} / (1 + {X})"

3. Check that it loads:

pixi run python -c "from phoskintime.networkmodel import mechanism; m = mechanism.load('my-project/mm_dephos.toml'); print(m.name, m.family, len(m.reactions))"
mm_dephos distributive 7

4. Make a second config that uses it and writes elsewhere:

cp my-project/config.toml my-project/config_mm.toml
sed -i.bak -e 's#^mechanism = .*#mechanism = "my-project/mm_dephos.toml"#' \
  -e 's#/results"#/results_mm"#' my-project/config_mm.toml

Mechanism paths

A relative path is looked up from the config file's folder, by validate and by a run.

5. Validate, run, compare:

pixi run phoskintime validate --conf my-project/config_mm.toml
pixi run phoskintime run --conf my-project/config_mm.toml
pixi run phoskintime analyze summary --runs distributive=my-project/results mm_dephos=my-project/results_mm --out compare

The command writes compare.md and compare.csv. Some columns:

run objective n_starts converged
distributive 0.08406 4 4
mm_dephos 0.07292 4 4

A lower objective says this variant fitted these (invented) curves more closely with these 4 starts. It does not show that phosphatases saturate. Before you compare mechanisms: use more starts, check that the best objective is found repeatedly, and ask whether the difference is larger than your measurement noise.

What a rate law may use

symbol meaning available
{R}, {P} mRNA, unmodified protein per protein
{A} {B} {C} {D} {E} {synth} the protein's parameters and synthesis rate per protein
{X}, {S}, {Dp}, {prev} the site's form, its kinase inflow, its extra decay, the previous form per site

The combinatorial family has other symbols. You cannot add new parameters, species or measured quantities: the file rearranges what exists. Every species in a rate must be listed in the reaction, and there must be a modification reaction with modifiers = "site_kinases". A mistake is refused with a message that names the reaction:

phoskintime.networkmodel.mechanism.MechanismError: my-project/bad.toml: [[reactions]] #6 (dephosphorylation): unknown symbol(s) ['Km'] in rate; allowed ['A', 'B', 'C', 'D', 'Dp', 'E', 'P', 'R', 'S', 'X', 'gene', 'prev', 'site', 'synth']

Full reference: Mechanism files. Tutorial: 01. Model creation. From a new mechanism to a fitted and simulated model, without data: 12. Build your own model.

Next: Validate and fit.