Skip to content

11. Library API and run bundle

Download the notebook (executed for this page) · source

What this tutorial shows. PhosKinTime used from Python, as a script or another program would use it, with the library phoskintime.networkmodel.api: write the synthetic example, read its configuration, check the inputs, build the model and the objective without fitting, run one fit, read the results as pandas tables, and open the run bundle every run writes (manifest, provenance, tables, arrays), check it against the contract and write a second copy of it.

Place in the series. The last step of the pipeline. Tutorial 10 ran the same pipeline from the command line and looked at what makes it reproducible; this one does it in Python and goes through the bundle file by file. KinOpt and TFOpt end their series the same way (KinOpt 10, TFOpt 10): each tool is a library with a command line and an app around it, and each run ends in a bundle with the same conventions.

Where the inputs come from. KinOpt fits α (kinase → phosphosite) and β (a kinase's activity from its own protein level and phosphosites); TFOpt fits α (TF → target mRNA) and β (a TF's activity from its own protein level and phosphosites). Neither has dynamics. PhosKinTime reads their result workbooks, holds those weights fixed as the network's edge weights, and fits the rates of a coupled ODE system to protein, mRNA and phosphosite time series. The file interface is on the External tools page; the model on the Global network model page; the functions used here on the Library page.

Invented numbers

The example project's data are invented smooth curves and hand-written KinOpt/TFOpt workbooks (phoskintime.networkmodel.example), not measurements or real KinOpt/TFOpt output. The fit shows the API and the file formats; it means nothing biologically.

Setup and the example project

The setup cell finds the repository root, puts it on sys.path and makes it the working folder (a kernel started outside pixi does not get pixi's environment). api.write_example writes the same project as phoskintime example into a new temporary folder; we ask for 2 multistart starts on 2 cores.

import io
import json
import os
import sys
import tempfile
import time
import zipfile
from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

# Repository root: the first folder upwards that holds pixi.toml and phoskintime/networkmodel/.
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)

from phoskintime.networkmodel import api

pd.set_option("display.width", 140)
WORK = Path(tempfile.mkdtemp(prefix="phoskintime-tutorial-10-"))  # everything this tutorial writes
conf = api.write_example(WORK / "project", n_starts=2, cores=2)
sorted(p.relative_to(WORK).as_posix() for p in (WORK / "project").rglob("*") if p.is_file())
['project/README.md',
 'project/config.toml',
 'project/data/kinase_net.csv',
 'project/data/kinopt_results.xlsx',
 'project/data/ms.csv',
 'project/data/rna.csv',
 'project/data/tf_net.csv',
 'project/data/tfopt_results.xlsx',
 'project/priors_lognormal.toml']

Configuration

api.load_config returns the [networkmodel] table of a config.toml as a dict. Unlike KinOpt's and TFOpt's RunConfig, there is no settings object with overrides by name: you edit the config.toml, or pass runner options (python -m phoskintime.networkmodel.runner --help) as extra_args to validate_inputs and run, where they override the file. A key missing from the file takes its default (here tf_orphan_policy, default "data_drive"); the run writes every value it used to config_resolved.yaml (tutorial 10). A few of the settings that matter for this tutorial:

cfg = api.load_config(conf)
shown = {"models.default_model": cfg["models"]["default_model"]}
for k in ("fit_engine", "mechanism", "n_starts", "seed", "cores", "tf_orphan_policy", "ck_prior_centre",
          "profile_likelihood"):
    shown[k] = cfg.get(k, "(not in the file: default)")
shown["posterior.method"] = cfg["posterior"]["method"]
pd.Series(shown, name="value").to_frame()
value
models.default_model distributive
fit_engine sbmlsim
mechanism
n_starts 2
seed 42
cores 2
tf_orphan_policy (not in the file: default)
ck_prior_centre kinopt_beta
profile_likelihood False
posterior.method none

The fixed weights from KinOpt and TFOpt

phoskintime.common.external_results.read_external_results reads a workbook against the file contract (the same reader a run uses) and returns the sheets with the file's sha256. These are the weights PhosKinTime will not fit.

from phoskintime.common.external_results import KINOPT, TFOPT, read_external_results

kin = read_external_results(cfg["kinopt"], KINOPT, sheets=("Alpha Values", "Beta Values"))
tf = read_external_results(cfg["tfopt"], TFOPT, sheets=("Alpha Values", "Beta Values"))
print("KinOpt workbook sha256", kin.sha256[:16], "| TFOpt workbook sha256", tf.sha256[:16])
display(kin.sheets["Alpha Values"])
kin.sheets["Beta Values"]  # empty Psite = the kinase-level beta (the only beta rows networkmodel reads)
KinOpt workbook sha256 5f512fcbc12a21b5 | TFOpt workbook sha256 c3acadab58e94fc9
Gene Psite Kinase Alpha
0 A S_1 K1 1.0
1 A S_2 K1 1.0
2 A S_2 K2 0.0
3 B Y_4 K1 0.7
4 B Y_4 K2 0.3
5 K1 T_3 K2 1.0
Kinase Psite Beta
0 K1 NaN -0.4
1 K1 T_3 1.4
2 K2 NaN 1.0

Check the inputs

api.validate_inputs is phoskintime validate: it parses the runner options, reads the four tables and the two workbooks against the contract, and builds the network with the function every run uses (phoskintime.networkmodel.PosteriorObjective.build_run_system), without fitting. counts is what was read, dropped or defaulted. warnings lists only file-level problems (for example a missing workbook); the orphan-TF warnings of the network build go to the log, as tutorial 10 showed.

import logging

logging.disable(logging.WARNING)  # keep the model's log lines (shown in tutorial 10) out of this page
report = api.validate_inputs(conf)
logging.disable(logging.NOTSET)
print("ok:", report.ok, "| errors:", report.errors, "| warnings:", report.warnings)
print("count groups:", sorted(report.counts))
obs = report.counts["observations_in_model"]
pd.DataFrame({layer: obs[layer] for layer in ("protein", "rna", "phospho")}, index=["in the files", "in the model"])
ok: True | errors: [] | warnings: []
count groups: ['kinase_alpha', 'kinase_network', 'kinopt', 'ms', 'observations_in_model', 'phospho_site_filter', 'rna', 'tf_alpha', 'tf_network', 'tfopt']
protein rna phospho
in the files 70 27 56
in the model 56 27 56

The model and the objective, without fitting

api.problem builds what a run would fit, in this kernel: the network, the System with its mechanism and SBML model, the parameter layout with bounds and the resolved prior, and the objective on the SBML model (tutorials 01, 05 and 06 go through each part). It is how to evaluate the objective, simulate the model or try another mechanism file (extra_args=["--mechanism", path]) without a run.

prob = api.problem(conf, work_dir=WORK / "problem")
print("mechanism:", prob.sys.mechanism.name, "| parameters:", len(prob.parameter_names),
      "| fixed:", int(prob.fixed_mask.sum()))
{k: v for k, v in prob.terms(prob.theta_start).items() if k != "breakdown"}
2026-12-03 14:47:31,822 - phoskintime.networkmodel.io - INFO - [Data] Loading Kinase Net: /tmp/phoskintime-tutorial-10-v9_pq0ub/project/data/kinase_net.csv                                             ⏱ 1.87 sec
2026-12-03 14:47:31,849 - phoskintime.networkmodel.io - INFO - [Data] Loading Kinase Alphas from: /tmp/phoskintime-tutorial-10-v9_pq0ub/project/data/kinopt_results.xlsx                                ⏱ 1.89 sec
2026-12-03 14:47:31,855 - phoskintime.networkmodel.io - INFO -        Found 2 kinase priors.                                                                                                            ⏱ 1.90 sec
2026-12-03 14:47:31,863 - phoskintime.networkmodel.io - INFO - [Data] Loading TF Net: /tmp/phoskintime-tutorial-10-v9_pq0ub/project/data/tf_net.csv                                                     ⏱ 1.91 sec
2026-12-03 14:47:31,878 - phoskintime.networkmodel.io - INFO - [Data] Loading TF Alphas from: /tmp/phoskintime-tutorial-10-v9_pq0ub/project/data/tfopt_results.xlsx                                     ⏱ 1.92 sec
2026-12-03 14:47:31,888 - phoskintime.networkmodel.io - INFO -        Found 4 TF priors.                                                                                                                ⏱ 1.93 sec
2026-12-03 14:47:31,896 - phoskintime.networkmodel.io - INFO - [Data] Loading MS: /tmp/phoskintime-tutorial-10-v9_pq0ub/project/data/ms.csv                                                             ⏱ 1.94 sec
2026-12-03 14:47:31,920 - phoskintime.networkmodel.utils - INFO - [Scaled] Processed 140 rows with 2 IDs and 14 time points.                                                                            ⏱ 1.99 sec
2026-12-03 14:47:31,923 - phoskintime.networkmodel.utils - INFO - [Scaled] Scaling method: fc_start                                                                                                     ⏱ 1.99 sec
2026-12-03 14:47:31,938 - phoskintime.networkmodel.io - INFO - [Data] Loading RNA: /tmp/phoskintime-tutorial-10-v9_pq0ub/project/data/rna.csv                                                           ⏱ 1.98 sec
2026-12-03 14:47:31,962 - phoskintime.networkmodel.utils - INFO - [Scaled] Processed 36 rows with 1 IDs and 9 time points.                                                                              ⏱ 2.03 sec
2026-12-03 14:47:31,969 - phoskintime.networkmodel.utils - INFO - [Scaled] Scaling method: fc_start                                                                                                     ⏱ 2.04 sec
2026-12-03 14:47:31,979 - phoskintime.networkmodel.io - INFO - [Data] Loaded 36 RNA points.                                                                                                             ⏱ 2.02 sec
[TF] orphan TF T2 has no mrna data to drive it: fallback its own state (data_drive_fallback)
[TF] orphan TF T3 has no mrna data to drive it: fallback its own state (data_drive_fallback)
2026-12-03 14:47:32,012 - phoskintime.networkmodel.network - INFO - [Model] 6 proteins, 2 kinases, 16 state variables.                                                                                  ⏱ 1.75 sec
[TF] observations of data-driven TFs ['T1'] are inputs: 9 rows removed from the loss
2026-12-03 14:47:32,028 - phoskintime.networkmodel.BuildMatrix - INFO - [Model] Building W matrices in parallel using 2 cores...                                                                        ⏱ 1.85 sec
2026-12-03 14:47:33,174 - phoskintime.networkmodel.BuildMatrix - INFO - [Model] Stacking Global W matrix...                                                                                             ⏱ 3.00 sec
2026-12-03 14:47:33,177 - phoskintime.networkmodel.network - INFO - [Model] Initial condition data attached successfully.                                                                               ⏱ 2.92 sec
2026-12-03 14:47:33,213 - phoskintime.networkmodel.utils - INFO - ============================================================                                                                          ⏱ 3.28 sec
2026-12-03 14:47:33,216 - phoskintime.networkmodel.utils - INFO - [Bounds] CALCULATION: Performing Topological & Kinetic Analysis                                                                       ⏱ 3.29 sec
2026-12-03 14:47:33,217 - phoskintime.networkmodel.utils - INFO - ------------------------------------------------------------                                                                          ⏱ 3.29 sec
2026-12-03 14:47:33,218 - phoskintime.networkmodel.utils - INFO - Param      | Min        | Max                                                                                                         ⏱ 3.29 sec
2026-12-03 14:47:33,221 - phoskintime.networkmodel.utils - INFO - ------------------------------------------------------------                                                                          ⏱ 3.29 sec
2026-12-03 14:47:33,221 - phoskintime.networkmodel.utils - INFO - A_i        | 1.624e-05  | 7.524                                                                                                       ⏱ 3.29 sec
2026-12-03 14:47:33,221 - phoskintime.networkmodel.utils - INFO - B_i        | 0.0001102  | 0.5756                                                                                                      ⏱ 3.29 sec
2026-12-03 14:47:33,222 - phoskintime.networkmodel.utils - INFO - C_i        | 2.687e-05  | 80.36                                                                                                       ⏱ 3.29 sec
2026-12-03 14:47:33,224 - phoskintime.networkmodel.utils - INFO - D_i        | 0.0001098  | 9.21                                                                                                        ⏱ 3.29 sec
2026-12-03 14:47:33,224 - phoskintime.networkmodel.utils - INFO - E_i        | 0.0001098  | 9.21                                                                                                        ⏱ 3.29 sec
2026-12-03 14:47:33,225 - phoskintime.networkmodel.utils - INFO - c_k        | 0.0001098  | 5                                                                                                           ⏱ 3.30 sec
2026-12-03 14:47:33,226 - phoskintime.networkmodel.utils - INFO - tf_scale   | 0.5        | 5                                                                                                           ⏱ 3.30 sec
2026-12-03 14:47:33,229 - phoskintime.networkmodel.utils - INFO - Dp_i       | 0.0001098  | 9.21                                                                                                        ⏱ 3.30 sec
2026-12-03 14:47:33,230 - phoskintime.networkmodel.utils - INFO - [Bounds] Rate constants (1/min) from the sampling design (N22): delta=0.1 (assumption: no replicate data in the networkmodel inputs); k_min = -ln(1-delta)/T, k_max = -ln(delta)/dt_min⏱ 3.30 sec
2026-12-03 14:47:33,230 - phoskintime.networkmodel.utils - INFO - [Bounds]   B_i   grid=rna     k=[0.0001102, 0.5756] half-life=[1.204, 6289] min                                                       ⏱ 3.30 sec
2026-12-03 14:47:33,231 - phoskintime.networkmodel.utils - INFO - [Bounds]   D_i   grid=protein k=[0.0001098, 9.21] half-life=[0.07526, 6316] min                                                       ⏱ 3.30 sec
2026-12-03 14:47:33,232 - phoskintime.networkmodel.utils - INFO - [Bounds]   E_i   grid=phospho k=[0.0001098, 9.21] half-life=[0.07526, 6316] min                                                       ⏱ 3.30 sec
2026-12-03 14:47:33,235 - phoskintime.networkmodel.utils - INFO - [Bounds]   Dp_i  grid=phospho k=[0.0001098, 9.21] half-life=[0.07526, 6316] min                                                       ⏱ 3.31 sec
2026-12-03 14:47:33,239 - phoskintime.networkmodel.utils - INFO - [Bounds]   c_k   grid=phospho k=[0.0001098, 9.21] half-life=[0.07526, 6316] min                                                       ⏱ 3.31 sec
2026-12-03 14:47:33,242 - phoskintime.networkmodel.utils - INFO - ============================================================                                                                          ⏱ 3.31 sec
mechanism: distributive | parameters: 37 | fixed: 7
SBML written to /tmp/phoskintime_sbml_etpy2wbp/model.xml  model 'phoskintime_distributive', 0.39 s
{'objective': 19042.84092144981,
 'data_term': 19042.83593157424,
 'prior_term': 0.004989875572184045}

observations_in_model shows, per layer, how many observations the input files hold and how many belong to the model's proteins. The model has three proteins (A, B, K1: the proteins with phosphosites in the kinase network); the series of T1, T3 and K2 are not fitted. K2's protein series is still used, as its kinase drive K(t).

Run

api.run runs one fit exactly as phoskintime run does: python -m phoskintime.networkmodel.runner in a subprocess, so the run's worker processes and threads stay out of this kernel. It returns the run folder; with log= the console output goes to a file. This cell takes a few minutes.

t0 = time.perf_counter()
run_dir = api.run(conf, log=WORK / "run.log")
print(f"run folder: <work>/{run_dir.relative_to(WORK)} | {time.perf_counter() - t0:.0f} s")
run folder: <work>/project/results | 49 s

Read the results

api.read_results returns the run's tables as DataFrames, the same tables the bundle holds, plus missing: every table the bundle format defines that this run does not have, with the reason.

results = api.read_results(run_dir)
print(sorted(k for k in results if k != "missing"))
pd.Series(results["missing"], name="reason").to_frame()
['kinase_activity', 'matrix_labels', 'metrics', 'multistart', 'parameters', 'state_index', 'steady_state', 'trajectories']
reason
profile_likelihood no profile likelihoods in this run
posterior_draws no posterior sampling in this run ([networkmod...
sensitivity the sensitivity analysis was not run for this ...
embeddings the network model has no embeddings (PCA/t-SNE...
convergence the network model records no per-iteration obj...
pareto the fit keeps one vector with one scalar objec...
knockouts not part of a run: in-silico experiments are w...
perturbations not part of a run: in-silico experiments are w...
parameter_profiles not produced by the network model
perturbation_samples not part of a run: in-silico experiments are w...

multistart has one row per start. Accepted means the fit engine reported success and a finite cost; the selected start is the accepted one with the lowest objective (tutorial 07).

results["multistart"]
workflow start objective converged selected convergence_status accepted runtime_seconds
0 networkmodel 0 0.107728 True False converged True 2.569614
1 networkmodel 1 0.078991 True True converged True 3.715982

parameters holds the best fit (sample_id = "best") and every start's parameters. The groups, per protein unless noted: A_i (mRNA synthesis), B_i (mRNA decay), C_i (translation), D_i (protein degradation, applied to every state), E_i (dephosphorylation, one rate shared by all sites of the protein), Dp_i (extra loss of a phosphorylated site, per site), c_k (per kinase: the kinase drive is c_k·K(t), K from the kinase's protein series) and tf_scale (one global strength of the TF input). See the Global network model page for the equations (its "Code symbols" note maps them to these names).

identifiability_label says what the value is. Without profile likelihoods (turned off in the example) every interior value is "not assessed"; a value at an optimizer bound says so. Even with profiles the labels are provisional (KNOWN_ISSUES N30). These values are model settings that reproduce the fit, not measurements.

best = results["parameters"].query("sample_id == 'best'")
best[["name", "group", "value", "lower", "upper", "identifiability_label"]]
name group value lower upper identifiability_label
0 A_i[A] A_i 0.031450 0.000016 7.523976 not assessed
1 A_i[B] A_i 0.006630 0.000016 7.523976 not assessed
2 A_i[K1] A_i 0.087152 0.000016 7.523976 not assessed
3 A_i[T1] A_i 1.000000 1.000000 1.000000 not identifiable: no data influence
4 A_i[T2] A_i 0.001025 0.000016 7.523976 not assessed
5 A_i[T3] A_i 0.003823 0.000016 7.523976 not assessed
6 B_i[A] B_i 0.061445 0.000110 0.575646 not assessed
7 B_i[B] B_i 0.004561 0.000110 0.575646 not assessed
8 B_i[K1] B_i 0.575646 0.000110 0.575646 above resolvable rate (half-life < 72.2 s)
9 B_i[T1] B_i 0.050000 0.050000 0.050000 not identifiable: no data influence
10 B_i[T2] B_i 0.027205 0.000110 0.575646 not assessed
11 B_i[T3] B_i 0.006503 0.000110 0.575646 not assessed
12 C_i[A] C_i 0.006547 0.000027 80.362571 not assessed
13 C_i[B] C_i 0.007010 0.000027 80.362571 not assessed
14 C_i[K1] C_i 1.429038 0.000027 80.362571 not assessed
15 C_i[T1] C_i 0.500000 0.500000 0.500000 not identifiable: no data influence
16 C_i[T2] C_i 0.197412 0.000027 80.362571 not assessed
17 C_i[T3] C_i 0.018791 0.000027 80.362571 not assessed
18 D_i[A] D_i 0.001775 0.000110 9.210340 not assessed
19 D_i[B] D_i 0.007209 0.000110 9.210340 not assessed
20 D_i[K1] D_i 0.610317 0.000110 9.210340 not assessed
21 D_i[T1] D_i 0.050000 0.050000 0.050000 not identifiable: no data influence
22 D_i[T2] D_i 0.044574 0.000110 9.210340 not assessed
23 D_i[T3] D_i 0.010370 0.000110 9.210340 not assessed
24 E_i[A] E_i 1.319080 0.000110 9.210340 not assessed
25 E_i[B] E_i 1.920070 0.000110 9.210340 not assessed
26 E_i[K1] E_i 4.641825 0.000110 9.210340 not assessed
27 E_i[T1] E_i 1.000000 1.000000 1.000000 not identifiable: no data influence
28 E_i[T2] E_i 1.000000 1.000000 1.000000 not identifiable: no data influence
29 E_i[T3] E_i 1.000000 1.000000 1.000000 not identifiable: no data influence
30 c_k[K1] c_k 0.429787 0.000110 5.000000 not assessed
31 c_k[K2] c_k 2.804813 0.000110 5.000000 not assessed
32 tf_scale tf_scale 4.999998 0.500000 5.000000 at optimizer bound (upper; not a design bound)
33 Dp_i[A_S_1] Dp_i 0.003175 0.000110 9.210340 not assessed
34 Dp_i[A_S_2] Dp_i 0.036668 0.000110 9.210340 not assessed
35 Dp_i[B_Y_4] Dp_i 0.006399 0.000110 9.210340 not assessed
36 Dp_i[K1_T_3] Dp_i 0.014205 0.000110 9.210340 not assessed

trajectories is observed and predicted values per observable in long form; metrics the RMSE and MAE overall, per layer and per protein. The figure shows the four phosphosites. Every series is a fold change relative to its first time point, so all start at 1.

traj = results["trajectories"]
sites = traj.query("layer == 'phospho'")
fig, axes = plt.subplots(1, 4, figsize=(13, 2.8), sharey=True)
for ax, (state, d) in zip(axes, sites.groupby("state")):
    ax.plot(d["time"], d["value_obs"], "o", ms=3, label="observed (invented)")
    ax.plot(d["time"], d["value_pred"], "-", label="model")
    ax.set_xscale("symlog", linthresh=1.0)
    ax.set_title(state)
    ax.set_xlabel("time (min)")
axes[0].set_ylabel("fold change")
axes[0].legend(fontsize=8)
plt.tight_layout()
results["metrics"].query("protein.isna()").fillna({"layer": "all"}).pivot(index="layer", columns="metric", values="value")
metric frechet_distance mae n_obs objective rmse
layer
all 3.051544 0.118227 139.0 0.078991 0.167101
phospho 1.450983 0.160535 56.0 NaN 0.203013
protein 1.117681 0.097711 56.0 NaN 0.153564
rna 0.482880 0.073032 27.0 NaN 0.096744

png

The run bundle

Every run ends by writing <run>/<run name>.pkt.zip (api.bundle_path says where). api.check_bundle validates it against the published contract (contracts/phoskintime/1.0): the manifest schema, the sha256 and size of every file, table columns and dtypes, the declared missing tables, the parameter and state order hashes and the copied inputs. It is plain Python and needs no model code, so a reader of bundles can run it too.

bundle = api.bundle_path(run_dir)
check = api.check_bundle(bundle)
manifest = check.manifest
print("bundle", bundle.name, "| valid:", check.ok, "| errors:", check.errors, "| warnings:", check.warnings)
print("schema", manifest["bundle_schema"], "| id", manifest["bundle_id"], "| model", manifest["model"]["model_id"],
      "| producer", manifest["producer"]["phoskintime_version"], manifest["producer"]["git_commit"][:12])
bundle results.pkt.zip | valid: True | errors: [] | warnings: []
schema 1.1 | id pkt-7caa6594cabb2781 | model distributive | producer 0.7.0 b613863688dc

Layout

The zip holds one folder <run>.pkt/ with four parts:

  • manifest.json: what is in the bundle, with the sha256 and size of every other file;
  • provenance/: metadata.json, config_resolved.yaml, command.txt, console.log, priors and parameter status, and copies of the inputs (inputs/NN_<file>, up to 50 MB each);
  • tables/<table>.parquet: typed tables (columns and dtypes fixed by the contract's tables.json);
  • arrays/<name>.npy: little-endian float64 arrays (the network matrices; posterior draws when sampled).

The manifest's files list describes each one:

files = pd.DataFrame(manifest["files"])
files["part"] = files["path"].str.split("/").str[0]
files[["part", "path", "kind", "bytes", "rows"]].sort_values(["part", "path"]).reset_index(drop=True)
part path kind bytes rows
0 arrays arrays/matrix_W_site_kinase.npy array 192 NaN
1 arrays arrays/matrix_tf_target_tf.npy array 224 NaN
2 provenance provenance/command.txt provenance 142 NaN
3 provenance provenance/config_resolved.yaml provenance 8327 NaN
4 provenance provenance/console.log provenance 28074 NaN
5 provenance provenance/fitted_params_picked.json provenance 966 NaN
6 provenance provenance/inputs/00_kinase_net.csv provenance 77 NaN
7 provenance provenance/inputs/01_tf_net.csv provenance 39 NaN
8 provenance provenance/inputs/02_ms.csv provenance 2195 NaN
9 provenance provenance/inputs/03_rna.csv provenance 695 NaN
10 provenance provenance/inputs/04_kinopt_results.xlsx provenance 6484 NaN
11 provenance provenance/inputs/05_tfopt_results.xlsx provenance 6473 NaN
12 provenance provenance/metadata.json provenance 33848 NaN
13 provenance provenance/mode_metadata.json provenance 433 NaN
14 provenance provenance/model/model.xml provenance 183934 NaN
15 provenance provenance/parameter_status.csv provenance 5487 NaN
16 provenance provenance/priors_resolved.csv provenance 14275 NaN
17 tables tables/kinase_activity.parquet table 15588 2020.0
18 tables tables/matrix_labels.parquet table 1398 13.0
19 tables tables/metrics.parquet table 2179 47.0
20 tables tables/multistart.parquet table 2275 2.0
21 tables tables/parameters.parquet table 6504 111.0
22 tables tables/state_index.parquet table 1639 16.0
23 tables tables/steady_state.parquet table 1914 24.0
24 tables tables/trajectories.parquet table 5751 194.0

Tables and arrays, read directly

A bundle is ordinary files: pandas reads the Parquet tables and NumPy the arrays, without PhosKinTime. The two network matrices show what the model did with the KinOpt and TFOpt weights:

  • matrix_W_site_kinase (site × kinase) is the KinOpt α as read from the workbook, including the 0 for K2 → A S_2. A vertex weight of 0 removes that edge's influence entirely (KNOWN_ISSUES N32).
  • matrix_tf_target_tf (target × TF) holds the TF weights α·β after the orphan-TF policy: the five input edges under their own names, each with its own TF's TFOpt β (A's is negative, so A → B represses; KNOWN_ISSUES N31).
with zipfile.ZipFile(bundle) as zf:
    root = zf.namelist()[0].split("/")[0]
    labels = pd.read_parquet(io.BytesIO(zf.read(f"{root}/tables/matrix_labels.parquet")))
    arrays = {n: np.load(io.BytesIO(zf.read(f"{root}/arrays/{n}.npy")))
              for n in ("matrix_W_site_kinase", "matrix_tf_target_tf")}


def labelled(name):
    """The array as a DataFrame with its row and column labels from matrix_labels."""
    lab = labels.query("matrix == @name").sort_values("position")
    return pd.DataFrame(arrays[name], index=lab.query("axis == 0")["label"].tolist(),
                        columns=lab.query("axis == 1")["label"].tolist())


display(labelled("matrix_W_site_kinase"))
labelled("matrix_tf_target_tf")
K1 K2
A_S_1 1.0 0.0
A_S_2 1.0 0.0
B_Y_4 0.7 0.3
K1_T_3 0.0 1.0
A T1 T2 T3
A 0.00 0.36 0.4 0.0
B -0.35 0.30 0.0 0.0
K1 0.00 0.00 0.0 1.0

Write a bundle yourself

api.make_bundle writes the bundle of any finished run folder (the run folder is only read; an existing output is refused). Here a second copy as an unzipped folder, which check_bundle accepts as well. Writing a bundle needs the git commit of the code that ran, recorded in metadata.json; a run from a copy of the code without git history cannot be bundled.

folder_bundle = api.make_bundle(run_dir, out=WORK / "copy.pkt")
print("valid:", api.check_bundle(folder_bundle).ok)
sorted(p.relative_to(folder_bundle).as_posix() for p in folder_bundle.rglob("*") if p.is_file())
valid: True
['arrays/matrix_W_site_kinase.npy',
 'arrays/matrix_tf_target_tf.npy',
 'manifest.json',
 'provenance/command.txt',
 'provenance/config_resolved.yaml',
 'provenance/console.log',
 'provenance/fitted_params_picked.json',
 'provenance/inputs/00_kinase_net.csv',
 'provenance/inputs/01_tf_net.csv',
 'provenance/inputs/02_ms.csv',
 'provenance/inputs/03_rna.csv',
 'provenance/inputs/04_kinopt_results.xlsx',
 'provenance/inputs/05_tfopt_results.xlsx',
 'provenance/metadata.json',
 'provenance/mode_metadata.json',
 'provenance/model/model.xml',
 'provenance/parameter_status.csv',
 'provenance/priors_resolved.csv',
 'tables/kinase_activity.parquet',
 'tables/matrix_labels.parquet',
 'tables/metrics.parquet',
 'tables/multistart.parquet',
 'tables/parameters.parquet',
 'tables/state_index.parquet',
 'tables/steady_state.parquet',
 'tables/trajectories.parquet']

Reading the bundle elsewhere

PhosKinTime-Vis reads exactly this bundle (zip or folder) for plots and interactive exploration; it checks the same contract and refuses a major schema version it does not know. Any other reader only needs the manifest, Parquet and NumPy; the contract and the full table list are on the Run bundle page. KinOpt and TFOpt bundles follow the same conventions (manifest with sha256s, tables/, provenance/), so a KinOpt → TFOpt → PhosKinTime chain can be traced through its three bundles: the PhosKinTime bundle records the workbooks' sha256 under inputs and in provenance/metadata.json, and the workbooks come from the other two runs.

Before using real KinOpt output, check its version: workbooks written before KinOpt 0.11.0 have misassigned kinase activities, so every α in them is suspect (KNOWN_ISSUES N38).

Next

12. Build your own model: a new mechanism and network from the first file, synthetic data, a fit and the SBML ecosystem. Or back to 00. Overview, or continue with the reference pages: Library, Command line, Run bundle, External tools. The KinOpt and TFOpt series end with this tutorial's topic: KinOpt 10, TFOpt 10.