kinopt 0.10.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- config_loader.py +122 -0
- kinopt/__init__.py +9 -0
- kinopt/fitanalysis/__init__.py +7 -0
- kinopt/fitanalysis/__main__.py +9 -0
- kinopt/fitanalysis/helpers/__init__.py +1 -0
- kinopt/fitanalysis/helpers/postfit.py +598 -0
- kinopt/fitanalysis/performance.py +61 -0
- kinopt/local/__init__.py +7 -0
- kinopt/local/__main__.py +154 -0
- kinopt/local/config/__init__.py +1 -0
- kinopt/local/config/constants.py +145 -0
- kinopt/local/config/helpers/__init__.py +21 -0
- kinopt/local/config/logconf.py +159 -0
- kinopt/local/exporter/__init__.py +1 -0
- kinopt/local/exporter/helpers/__init__.py +31 -0
- kinopt/local/exporter/plotout.py +326 -0
- kinopt/local/exporter/sheetutils.py +124 -0
- kinopt/local/objfn/__init__.py +9 -0
- kinopt/local/objfn/minfn.py +252 -0
- kinopt/local/opt/__init__.py +1 -0
- kinopt/local/opt/methods.py +26 -0
- kinopt/local/opt/optrun.py +559 -0
- kinopt/local/optcon/__init__.py +18 -0
- kinopt/local/optcon/construct.py +400 -0
- kinopt/local/utils/__init__.py +4 -0
- kinopt/local/utils/iodata.py +268 -0
- kinopt/local/utils/params.py +90 -0
- kinopt/optimality/KKT.py +22 -0
- kinopt/optimality/__init__.py +1 -0
- kinopt/optimality/checks.py +247 -0
- kinopt-0.10.0.dist-info/METADATA +134 -0
- kinopt-0.10.0.dist-info/RECORD +38 -0
- kinopt-0.10.0.dist-info/WHEEL +5 -0
- kinopt-0.10.0.dist-info/entry_points.txt +2 -0
- kinopt-0.10.0.dist-info/licenses/LICENSE +29 -0
- kinopt-0.10.0.dist-info/licenses/LICENSE-docs.md +16 -0
- kinopt-0.10.0.dist-info/licenses/THIRD_PARTY.md +137 -0
- kinopt-0.10.0.dist-info/top_level.txt +2 -0
config_loader.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""Read KinOpt settings from `config.toml`.
|
|
2
|
+
|
|
3
|
+
`load` returns the settings of one section (for example `[kinopt]`) merged with one of its modes, plus the
|
|
4
|
+
`[paths]` table and the project root. `ensure_dirs` creates the folders named in `[paths]`.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from functools import lru_cache
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
try:
|
|
13
|
+
import tomllib # py>=3.11
|
|
14
|
+
except ModuleNotFoundError: # pragma: no cover
|
|
15
|
+
import tomli as tomllib # py<3.11
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _project_root(start: Path | None = None) -> Path:
|
|
19
|
+
"""Find the project root, the first folder upwards that contains `config.toml`.
|
|
20
|
+
|
|
21
|
+
Walks upwards from `start` first (in a checkout this finds the repository), then from the working directory
|
|
22
|
+
(for an installed package run from a project folder).
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
start: Folder to start the first walk from. If None, the folder of this module is used.
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
The first folder found that contains `config.toml`.
|
|
29
|
+
|
|
30
|
+
Raises:
|
|
31
|
+
FileNotFoundError: Neither walk finds a `config.toml`.
|
|
32
|
+
"""
|
|
33
|
+
start = Path(start or Path(__file__).resolve().parent).resolve()
|
|
34
|
+
cwd = Path.cwd().resolve()
|
|
35
|
+
for base in (start, cwd):
|
|
36
|
+
for p in [base, *base.parents]:
|
|
37
|
+
if (p / "config.toml").is_file():
|
|
38
|
+
return p
|
|
39
|
+
raise FileNotFoundError(
|
|
40
|
+
f"No config.toml found above {start} or above the working directory {cwd}. "
|
|
41
|
+
"Run KinOpt from a project folder that contains config.toml (see the KinOpt repository for a template)."
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _deep_merge(base: dict[str, Any], override: dict[str, Any]) -> dict[str, Any]:
|
|
46
|
+
"""Merge two dictionaries recursively; values in `override` take precedence.
|
|
47
|
+
|
|
48
|
+
Nested dictionaries present in both are merged; any other value in `override` replaces the one in `base`.
|
|
49
|
+
Neither input is modified.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
base: Dictionary with the default values.
|
|
53
|
+
override: Dictionary with the values that take precedence. None is treated as empty.
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
A new merged dictionary.
|
|
57
|
+
"""
|
|
58
|
+
out = dict(base)
|
|
59
|
+
for k, v in (override or {}).items():
|
|
60
|
+
if isinstance(v, dict) and isinstance(out.get(k), dict):
|
|
61
|
+
out[k] = _deep_merge(out[k], v)
|
|
62
|
+
else:
|
|
63
|
+
out[k] = v
|
|
64
|
+
return out
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@lru_cache(maxsize=8)
|
|
68
|
+
def load(mode: str, section: str) -> dict[str, Any]:
|
|
69
|
+
"""Load one section of `config.toml`, merged with the settings of one mode.
|
|
70
|
+
|
|
71
|
+
Reads `[<section>]` and deep-merges `[<section>.modes.<mode>]` over it. Results are cached per
|
|
72
|
+
`(mode, section)`, so later changes to the file are not seen within the same process.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
mode: Mode name under `<section>.modes`, for example `"local"`.
|
|
76
|
+
section: Top-level table name, for example `"kinopt"`.
|
|
77
|
+
|
|
78
|
+
Returns:
|
|
79
|
+
The merged settings. The `modes` table itself is kept, and two keys are added: `_paths` (the `[paths]`
|
|
80
|
+
table) and `_root` (the project root as a string).
|
|
81
|
+
|
|
82
|
+
Raises:
|
|
83
|
+
FileNotFoundError: No `config.toml` is found (see `_project_root`).
|
|
84
|
+
"""
|
|
85
|
+
root = _project_root()
|
|
86
|
+
with (root / "config.toml").open("rb") as f:
|
|
87
|
+
raw = tomllib.load(f)
|
|
88
|
+
|
|
89
|
+
base = raw.get(section, {}) or {}
|
|
90
|
+
modes = (base.get("modes", {}) or {})
|
|
91
|
+
merged = _deep_merge(base, modes.get(mode, {}))
|
|
92
|
+
|
|
93
|
+
merged["_paths"] = raw.get("paths", {}) or {}
|
|
94
|
+
merged["_root"] = str(root)
|
|
95
|
+
|
|
96
|
+
return merged
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def ensure_dirs() -> None:
|
|
100
|
+
"""Create the data, results, logs and ODE data folders named in `[paths]` of `config.toml`.
|
|
101
|
+
|
|
102
|
+
Paths are relative to the project root. Defaults: `data_dir="data"`, `results_dir="results"`,
|
|
103
|
+
`logs_dir="results/logs"`, `ode_data_dir="data"`. Existing folders are left as they are.
|
|
104
|
+
|
|
105
|
+
Raises:
|
|
106
|
+
FileNotFoundError: No `config.toml` is found (see `_project_root`).
|
|
107
|
+
"""
|
|
108
|
+
root = _project_root()
|
|
109
|
+
with (root / "config.toml").open("rb") as f:
|
|
110
|
+
raw = tomllib.load(f)
|
|
111
|
+
|
|
112
|
+
paths = raw.get("paths", {}) or {}
|
|
113
|
+
|
|
114
|
+
data_dir = paths.get("data_dir", "data")
|
|
115
|
+
results_dir = paths.get("results_dir", "results")
|
|
116
|
+
logs_dir = paths.get("logs_dir", "results/logs")
|
|
117
|
+
ode_data_dir = paths.get("ode_data_dir", "data")
|
|
118
|
+
|
|
119
|
+
(root / data_dir).mkdir(parents=True, exist_ok=True)
|
|
120
|
+
(root / results_dir).mkdir(parents=True, exist_ok=True)
|
|
121
|
+
(root / logs_dir).mkdir(parents=True, exist_ok=True)
|
|
122
|
+
(root / ode_data_dir).mkdir(parents=True, exist_ok=True)
|
kinopt/__init__.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""KinOpt: optimization-based estimation of cumulative kinase effects on substrate phosphorylation.
|
|
2
|
+
|
|
3
|
+
Subpackages:
|
|
4
|
+
|
|
5
|
+
- `kinopt.local`: fits the kinase-substrate model with local (gradient-based) optimization and writes the
|
|
6
|
+
results workbook.
|
|
7
|
+
- `kinopt.fitanalysis`: post-fit plots and tables built from the results workbook.
|
|
8
|
+
- `kinopt.optimality`: constraint (feasibility) checks and summary statistics on the results workbook.
|
|
9
|
+
"""
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""Post-fit analysis of a KinOpt optimization run.
|
|
2
|
+
|
|
3
|
+
Reads the results workbook written by `kinopt.local` and produces goodness-of-fit plots, parameter
|
|
4
|
+
distribution plots, PCA and t-SNE plots of the estimated α and β, a Sankey diagram of kinase-substrate
|
|
5
|
+
connections, and CSV tables. The entry point is `optimization_performance`.
|
|
6
|
+
"""
|
|
7
|
+
from kinopt.fitanalysis.performance import optimization_performance
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""Run the post-fit analysis on an existing results folder: `python -m kinopt.fitanalysis`.
|
|
2
|
+
|
|
3
|
+
Reads the results workbook `OUT_FILE` (at the top of `results_dir` in config.toml) and writes the analysis plots
|
|
4
|
+
and tables to `OUT_DIR`; the Pixi task is `kinopt-fitanalysis`.
|
|
5
|
+
"""
|
|
6
|
+
from kinopt.fitanalysis.performance import optimization_performance
|
|
7
|
+
|
|
8
|
+
if __name__ == "__main__":
|
|
9
|
+
optimization_performance()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Helper functions for the post-fit analysis in `kinopt.fitanalysis`."""
|