Skip to content

00. PhosKinTime tutorial overview

Download the notebook (executed for this page) · source

What this tutorial shows. What PhosKinTime estimates, where its inputs come from in the chain KinOpt → TFOpt → PhosKinTime → PhosKinTime-Vis, the three ways to use it (command line, app, library), and a map of this series. The series has thirteen tutorials (00–12): it starts with the model itself (01: mechanism files and the SBML model), goes through the inputs, the network, the parameters and the objective, then the fit, its diagnostics, identifiability and the posterior, and ends with a whole run from the command line (10) and from Python (11). Tutorial 12 then builds a new model from the first file.

Every tutorial uses the synthetic example project of phoskintime example (phoskintime.networkmodel.example), written into a temporary folder. Its numbers are invented smooth curves, not measurements, and nothing fitted to them means anything biologically. The tutorials never read data/, results*/ or other real data.

Three tools, one chain

PhosKinTime is the last of three model-fitting steps. The two earlier tools are separate projects; PhosKinTime does not import or install them. It reads their result workbooks through a file contract (External tools).

step tool fits to result used downstream
1 KinOpt α (kinase → site) and β (how a kinase's protein and own sites combine into its activity) phosphosite time series, without dynamics (a weighted sum at each time point) kinopt_results.xlsx: sheets Alpha Values, Beta Values
2 TFOpt α (TF → target mRNA) and β (how a TF's protein or mRNA and own sites combine into its activity) mRNA time series, without dynamics tfopt_results.xlsx: sheets Alpha Values, Beta Values
3 PhosKinTime (this project) the rates of one coupled ODE system (transcription, mRNA decay, translation, protein turnover, modification and demodification of sites), the kinase gains c_k and the TF gain tf_scale protein, mRNA and phosphosite time series together the run folder and its run bundle <run>.pkt.zip
4 PhosKinTime-Vis nothing — plots and interactive views of a run bundle

KinOpt predicts a site's signal as an α-weighted sum of kinase activities, each a β-weighted sum of the kinase's own series: \(\hat P_i(t) = \max\big(0, \sum_k \alpha_{ik} \sum_j \beta_{kj} X_{kj}(t)\big)\). TFOpt does the same for a target mRNA with TF activities. Both models are static: the prediction at time t uses only the input series at the same t. There is no ODE and no state.

PhosKinTime takes those weights as fixed network weights and fits rates. In the default reading:

  • the kinase → site weight in the matrix W is KinOpt α; the inflow of site s of protein g is \(S_{g,s}(t) = \sum_k W_{(g,s),k}\, c_k K_k(t)\), with \(K_k(t)\) the kinase's measured protein fold change and \(c_k\) a fitted gain;
  • the TF → target weight is TFOpt α × β (TF-level β), and each target's TF input is divided by its row sum \(\sum |\alpha\beta|\);
  • KinOpt's kinase-level β is c_k's starting value and prior centre (ck_prior_centre = "kinopt_beta"). This is questionable: β is a share inside KinOpt's activity mixture, not a scale (KNOWN_ISSUES N38).

The reactions of each protein (which states exist, which reactions connect them, their rate laws) are a mechanism file: PhosKinTime's four models are the files in models/ (tutorial 01). From the file and the network PhosKinTime writes an SBML model, and every simulation, fit, profile and posterior runs on it in libroadrunner; the fit is a PEtab problem solved by sbmlsim (or by AMICI and pyPESTO). The full equations are on the Global Network Model page; note that it writes the kinase gain as \(\beta_k\), which is PhosKinTime's c_k, not KinOpt's β.

import os
import sys
from pathlib import Path

# Find the repository root (the folder with pixi.toml and phoskintime/networkmodel/), put it first on sys.path and work from
# there. A Jupyter kernel started outside pixi does not get pixi's PYTHONPATH.
REPO_ROOT = next(p for p in [Path.cwd(), *Path.cwd().parents]
                 if (p / "pixi.toml").is_file() and (p / "phoskintime" / "networkmodel").is_dir())
sys.path.insert(0, str(REPO_ROOT))
os.chdir(REPO_ROOT)

import subprocess
import tempfile

import pandas as pd

from phoskintime.networkmodel import api

pd.set_option("display.max_colwidth", None)   # show table cells in full
print("repository root:", REPO_ROOT)
repository root: <repository>

Three ways to use PhosKinTime

All three run the same code on the same files: a config.toml and a run folder.

  1. Command line phoskintime (Command line): pixi run phoskintime example my-project, pixi run phoskintime validate --conf my-project/config.toml, pixi run phoskintime run --conf ..., then analyze, export and bundle on the run folder (tutorial 10).
  2. The app pixi run app (The PhosKinTime app): a guided app in the browser (local only) to set up, validate, run and browse.
  3. The library from phoskintime.networkmodel import api (Library), used in these tutorials (tutorial 11).

The command list below is the real --help output (pixi run phoskintime runs python -m phoskintime.config.cli).

# The command line's help text; NO_COLOR and COLUMNS keep the output plain and narrow.
env = {**os.environ, "NO_COLOR": "1", "COLUMNS": "110", "TERM": "dumb"}
out = subprocess.run([sys.executable, "-m", "phoskintime.config.cli", "--help"], cwd=REPO_ROOT, env=env,
                     capture_output=True, text=True, check=True)
print(out.stdout)
 Usage: python -m phoskintime.config.cli [OPTIONS] COMMAND [ARGS]...            

 PhosKinTime: signalling and gene-regulation network model (command line).      

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --install-completion        <bool>  Install completion for the current       │
│                                     shell.                                   │
│ --show-completion           <bool>  Show completion for the current shell,   │
│                                     to copy it or customize the              │
│                                     installation.                            │
│ --help                      <bool>  Show this message and exit.              │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────╮
│ prep      Preprocess the raw inputs (phoskintime.processing.cleanup); writes │
│           input1-4 to data/.                                                 │
│ run       Run the network model: phoskintime run --conf config.toml <runner  │
│           options>. Every option goes to                                     │
│           python -m phoskintime.networkmodel.runner (phoskintime run --help  │
│           lists them). The run ends by writing its bundle                    │
│           <run>/<run name>.pkt.zip (--no-bundle skips it).                   │
│ validate  Check what a run with this config would read, without fitting:     │
│           input files, the KinOpt/TFOpt file contract,                       │
│           time columns, and that the network can be built. Further runner    │
│           options override the config.                                       │
│ example   Write a synthetic example project: data/ (inputs and KinOpt/TFOpt  │
│           workbooks, invented curves), config.toml                           │
│           and README.md. Then: phoskintime validate --conf                   │
│           <folder>/config.toml and phoskintime run --conf ....               │
│ app       The guided app in the browser: set up and validate a project, run  │
│           and monitor the network model, browse runs,                        │
│           run the analyses and download the bundle for phoskintime-vis.      │
│           Local only (127.0.0.1).                                            │
│ analyze   Post-run analyses: phoskintime analyze <name> <options>;           │
│           phoskintime analyze --list lists them and                          │
│           phoskintime analyze <name> --help shows an analysis's options.     │
│ simulate  In-silico experiments on a fitted model: phoskintime simulate      │
│           run|show|web|conformance <options>.                                │
│ export    Exports of a finished run: phoskintime export sbml|petab <options> │
│           (<format> --help).                                                 │
│ clean     Remove Python/Numba caches recursively, and build/, dist/ and      │
│           *.egg-info at                                                      │
│           the repository top level. Never touches .pixi/ or .git/.           │
│ bundle    Run bundles (<run>.pkt / .pkt.zip): the versioned, checksummed     │
│           export of a network-model run that phoskintime-vis reads           │
│           (contract: contracts/phoskintime/1.0).                             │
╰──────────────────────────────────────────────────────────────────────────────╯

The library functions, with the first line of each docstring:

names = ["write_example", "load_config", "validate_inputs", "problem", "run", "read_results", "bundle_path",
         "make_bundle", "check_bundle"]
pd.DataFrame({"function": [f"api.{n}" for n in names],
              "what it does": [getattr(api, n).__doc__.strip().splitlines()[0] for n in names]})
function what it does
0 api.write_example Write a synthetic example project (`phoskintime.networkmodel.example.write_example_project`).
1 api.load_config Read the ``[networkmodel]`` table of a config.toml (default: the repository's config.toml).
2 api.validate_inputs Check what a run with this config would read, without fitting.
3 api.problem Build the estimation problem a run with this config fits, in this process and without fitting.
4 api.run Run one network-model fit, as ``phoskintime run`` runs it.
5 api.read_results Read the tables of a finished run as pandas DataFrames, without writing a bundle.
6 api.bundle_path Return where a run writes its bundle (``<run>/<run name>.pkt.zip``).
7 api.make_bundle Write a run bundle (`phoskintime.common.bundle.make_bundle`).
8 api.check_bundle Check a run bundle (`phoskintime.common.bundle.check_bundle`).

The example project

api.write_example writes the project that every tutorial starts from: four input CSVs, the two workbooks (standing in for real KinOpt and TFOpt output) and a config.toml. The table records which step of the chain produces each file in a real study.

WORK = Path(tempfile.mkdtemp(prefix="phoskintime-tutorial-00-"))   # never inside the repository
conf = api.write_example(WORK / "project", n_starts=2, cores=1)
data = conf.parent / "data"

produced_by = {
    "kinase_net.csv": "input2 (kinase network): preprocessing; KinOpt reads the same file",
    "tf_net.csv": "input4 (TF network): preprocessing; TFOpt reads the same file",
    "ms.csv": "input1 (MS: protein and phosphosite rows): preprocessing; KinOpt and TFOpt read it too",
    "rna.csv": "input3 (RNA): preprocessing; TFOpt reads it too",
    "kinopt_results.xlsx": "KinOpt result workbook (here: invented values)",
    "tfopt_results.xlsx": "TFOpt result workbook (here: invented values)",
}
pd.DataFrame({"file": sorted(p.name for p in data.iterdir())}).assign(
    role=lambda d: d["file"].map(produced_by))
file role
0 kinase_net.csv input2 (kinase network): preprocessing; KinOpt reads the same file
1 kinopt_results.xlsx KinOpt result workbook (here: invented values)
2 ms.csv input1 (MS: protein and phosphosite rows): preprocessing; KinOpt and TFOpt read it too
3 rna.csv input3 (RNA): preprocessing; TFOpt reads it too
4 tf_net.csv input4 (TF network): preprocessing; TFOpt reads the same file
5 tfopt_results.xlsx TFOpt result workbook (here: invented values)
# The input section of the example's config.toml (absolute paths into the temporary folder).
cfg = api.load_config(conf)
{k: cfg[k] for k in ("kinase_net", "tf_net", "ms", "rna", "kinopt", "tfopt", "mechanism", "fit_engine", "output_dir",
                     "n_starts")}
{'kinase_net': '/tmp/phoskintime-tutorial-00-5ilptxiw/project/data/kinase_net.csv',
 'tf_net': '/tmp/phoskintime-tutorial-00-5ilptxiw/project/data/tf_net.csv',
 'ms': '/tmp/phoskintime-tutorial-00-5ilptxiw/project/data/ms.csv',
 'rna': '/tmp/phoskintime-tutorial-00-5ilptxiw/project/data/rna.csv',
 'kinopt': '/tmp/phoskintime-tutorial-00-5ilptxiw/project/data/kinopt_results.xlsx',
 'tfopt': '/tmp/phoskintime-tutorial-00-5ilptxiw/project/data/tfopt_results.xlsx',
 'mechanism': '',
 'fit_engine': 'sbmlsim',
 'output_dir': '/tmp/phoskintime-tutorial-00-5ilptxiw/project/results',
 'n_starts': 2}

Map of the series

# PhosKinTime tutorial related KinOpt / TFOpt tutorial
00 Overview (this page) KinOpt 00, TFOpt 00
01 Model creation: mechanism files in models/, the SBML model, a mechanism of your own —
02 Toy dataset format: the input files and the workbook sheets PhosKinTime reads KinOpt 01, TFOpt 01
03 Load and validate data: validate_inputs, the inputs report, contract errors KinOpt 02, TFOpt 02
04 From KinOpt and TFOpt weights to the network KinOpt 03, TFOpt 03
05 Parameter layout of the network model KinOpt 04, TFOpt 04
06 Simulation, observables and the objective KinOpt 05, TFOpt 05
07 The fit: the PEtab problem, sbmlsim or AMICI/pyPESTO, the multistart record KinOpt 06, TFOpt 06
08 Fit metrics and diagnostics KinOpt 07, TFOpt 07
09 Identifiability and the posterior: profiles, labels, Laplace, zeus MCMC, prediction bands KinOpt 08, TFOpt 08
10 End-to-end reproducible pipeline: the command line from inputs to bundle and exports KinOpt 09, TFOpt 09
11 Library API and run bundle KinOpt 10, TFOpt 10
12 Build your own model: config file, a new mechanism, synthetic data, fit, SBML ecosystem —

KinOpt and TFOpt have no dynamics and no model to build, so PhosKinTime's 01 has no counterpart and the numbers are shifted by one from 02 on. Their tutorial 08 is about the KKT conditions of the α/β simplex constraints; PhosKinTime's parameters are bounded rates of an ODE system, so its 09 is about what the data determine (profile likelihoods) and the posterior.

Limitations to keep in mind

  • Input weights. KinOpt workbooks written before KinOpt 0.11.0 build each kinase's activity from another protein's series, so every α and β in them is suspect; use KinOpt ≥ 0.11.0 and TFOpt ≥ 0.2.0 (KNOWN_ISSUES N38, T6).
  • Vertex solutions. KinOpt and TFOpt α often sit on a vertex of the simplex: some edges get weight 0 and are then deleted in effect, without a warning (N32). The example contains one such edge (K2 → A S_2).
  • Orphan TFs. A TF that is not a protein with sites in the kinase network is driven by its own measured data (mRNA by default), which then leave the objective; a TF without those data becomes its own unobserved mRNA and protein state (N31; tutorial 04).
  • Parameter labels. Identifiability labels from profile likelihoods are provisional (N30; tutorial 09).

Next

01. Model creation: the mechanism files in models/, the SBML model PhosKinTime writes from them, and a mechanism of your own.