Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
* `zero_unmeasured_isozymes` lowers the usage upper bound of the unmeasured isozymes of a reaction that has a measured isozyme, to 0 or to a detection limit (`method="detection_limit"`), as GECKO's `zeroUnmeasuredIsozymes`; it lowers the bounds in place and returns a DataFrame, and a lower bound above the new upper bound is lowered with it.
* `level_complex_concs` and `level_complex_abundances` keep a subunit with a concentration of 0 at 0 instead of filling it with the level of its complex.
* `flexibilize_enz_concs` warns about enzymes with a concentration of 0, which it cannot raise, and does not report them as flexibilized; with `per_complex=True` the count of a complex is recorded on its first subunit with a concentration above 0.
* `format_kcat_source` and `parse_kcat_source` write and read the provenance strings of `model.ec.source`, `<origin>[ (<detail>)][ | tuned=<method>[+<method>...] (prior=<value>)]`, and `KcatSource` holds the parts of one. `format_kcat_source(origin, detail=None, tuned=(), prior=None)` replaces `format_kcat_source(source, wildcard_level, origin)` and writes the same string for the same non-empty source, wildcard level and origin; an empty source with a detail is written as `unknown`. GECKO's `formatKcatSource` and `parseKcatSource` do the same.
* `sensitivity_tuning` and `cmaes_kcat_tuning` keep the origin and detail of the source of a kcat they change and add the method (`sensitivity`, `cmaes`) to its tuning status, with the kcat before the first tuning as `prior`. `sensitivity_tuning` no longer writes `sensitivityTuning` to `ec.source` or the kcat before tuning to `ec.notes`. `tune_prior_penalty_weight` restores `ec.source` with `ec.kcat`.
* `set_kcat_for_reactions` writes the source `manual`, which was `setKcatForReactions`, and drops any tuning status.
* `assign_standard_kcat`, `remove_standard_kcat`, `review_assignment`, `convert_custom_kcats` and the evotune trust tiers read the origin of `ec.source`, so a source with a detail or a tuning status is recognised. A standard kcat with a tuning status was changed on purpose and `remove_standard_kcat` keeps it.

## 4.0.0b2 — 2026-11-02

Expand Down
6 changes: 6 additions & 0 deletions src/geckopy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@
# Gather-kcats
from geckopy.gather_kcats import (
EcStats,
KcatSource,
apply_kcat_list,
assign_kcats,
assign_standard_kcat,
collect_kcats,
ec_stats_from_brenda,
fetch_open_kinetics_predictor,
format_kcat_source,
fuzzy_kcat_matching,
get_standard_kcat, # deprecated; alias of assign_standard_kcat
kcats_from_brenda,
Expand All @@ -97,6 +99,7 @@
load_kcat_source,
merge_dlkcat_and_fuzzy_kcats, # deprecated; alias of merge_kcats
merge_kcats,
parse_kcat_source,
read_dlkcat_output,
read_kcat_source,
remove_standard_kcat,
Expand Down Expand Up @@ -218,12 +221,14 @@
"set_kcat_for_reactions",
"set_prot_pool_size",
# Gather-kcats
"KcatSource",
"apply_kcat_list",
"assign_kcats",
"assign_standard_kcat",
"collect_kcats",
"ec_stats_from_brenda",
"fetch_open_kinetics_predictor",
"format_kcat_source",
"fuzzy_kcat_matching",
"kcats_from_brenda",
"kcats_from_dlkcat",
Expand All @@ -233,6 +238,7 @@
"load_kcat_source",
"merge_dlkcat_and_fuzzy_kcats", # deprecated; alias of merge_kcats
"merge_kcats",
"parse_kcat_source",
"read_dlkcat_output",
"read_kcat_source",
"remove_standard_kcat",
Expand Down
6 changes: 4 additions & 2 deletions src/geckopy/ec_model/pipeline/apply_custom_kcats.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
logger = logging.getLogger(__name__)

_EXP_SUFFIX_REGEX = re.compile(r"_EXP_\d+$")
_SOURCE_TAG = "custom"
_NOTES_SEPARATOR = ", "


Expand Down Expand Up @@ -309,9 +308,12 @@ def _apply_to_indices(
updated_indices: set[int],
) -> None:
"""Write kcat, source, and notes to ec.* for the given indices."""
# Imported here because gather_kcats imports this module.
from ...gather_kcats.kcat_source_format import format_kcat_source
source = format_kcat_source("custom")
for idx in indices:
model.ec.kcat[idx] = kcat
model.ec.source[idx] = _SOURCE_TAG
model.ec.source[idx] = source
if notes:
existing = model.ec.notes[idx]
if existing:
Expand Down
6 changes: 4 additions & 2 deletions src/geckopy/ec_model/pipeline/fill_kcats.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
logger = logging.getLogger(__name__)

_EXP_SUFFIX_REGEX = re.compile(r"_EXP_\d+$")
_SOURCE_TAG = "isozymes"

_AGGREGATORS = {
"mean": np.mean,
Expand Down Expand Up @@ -116,6 +115,9 @@ def fill_kcats_from_isozymes(
if known:
known_by_base.setdefault(bid, []).append(float(k))

# Imported here because gather_kcats imports this module.
from ...gather_kcats.kcat_source_format import format_kcat_source
source = format_kcat_source("isozymes")
# For each missing entry, look up its base group and average if available.
filled_indices: list[int] = []
for i, (bid, missing) in enumerate(zip(base_ids, missing_mask)):
Expand All @@ -125,7 +127,7 @@ def fill_kcats_from_isozymes(
if not siblings:
continue
model.ec.kcat[i] = float(combine(siblings))
model.ec.source[i] = _SOURCE_TAG
model.ec.source[i] = source
filled_indices.append(i)

if not filled_indices:
Expand Down
12 changes: 6 additions & 6 deletions src/geckopy/ec_model/pipeline/set_kcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@


_EXP_SUFFIX_PATTERN = re.compile(r"_EXP_\d+$")
_SOURCE_TAG = "setKcatForReactions"


def set_kcat_for_reactions(
Expand Down Expand Up @@ -57,10 +56,8 @@ def set_kcat_for_reactions(
passing the suffixed reaction IDs explicitly when the mapping
matters, so intent doesn't depend on ``ec.rxns``'s row order.

``ec.source`` is set to ``"setKcatForReactions"`` for every
reaction changed by this call, matching MATLAB's ``ec.source``
label (its own docstring says ``'from setKcatForReactions'``, but
the actual assignment writes the bare function name).
``ec.source`` is set to ``"manual"`` for every reaction changed by
this call, which drops any tuning status the source had.

Parameters
----------
Expand Down Expand Up @@ -142,9 +139,12 @@ def set_kcat_for_reactions(
for indices in matches_per_input:
flat_indices.extend(indices)

# Imported here because gather_kcats imports this module.
from ...gather_kcats.kcat_source_format import format_kcat_source
source = format_kcat_source("manual")
for idx, value in zip(flat_indices, kcat_per_index):
model.ec.kcat[idx] = value
model.ec.source[idx] = _SOURCE_TAG
model.ec.source[idx] = source

updated_ids = [ec_rxns[i] for i in flat_indices]

Expand Down
9 changes: 4 additions & 5 deletions src/geckopy/gather_kcats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .kcat_assignment import assign_kcats, collect_kcats, update_kcat_sources
from .homologs import kcats_from_homologs
from .kcat_sources import ec_rxn_keys, load_kcat_source, read_kcat_source, save_kcat_source
from .kcat_source_format import KcatSource, format_kcat_source, parse_kcat_source
from .kcats_from import kcats_from_brenda, kcats_from_dlkcat, kcats_from_ec_tree, kcats_from_okp
from .get_standard_kcat import assign_standard_kcat, get_standard_kcat
from .merge_dlkcat_and_fuzzy_kcats import merge_dlkcat_and_fuzzy_kcats
Expand All @@ -20,15 +21,12 @@
from .remove_standard_kcat import remove_standard_kcat
from .review import EcStats, ec_stats_from_brenda, review_assignment
from .run_dlkcat import run_dlkcat
from .select_kcat_value import (
apply_kcat_list,
format_kcat_source,
select_kcat_value,
)
from .select_kcat_value import apply_kcat_list, select_kcat_value
from .write_dlkcat_input import extract_enzyme_substrate_pairs, write_dlkcat_input

__all__ = [
"EcStats",
"KcatSource",
"OKPClient",
"OKPError",
"apply_kcat_list",
Expand All @@ -51,6 +49,7 @@
"merge_dlkcat_and_fuzzy_kcats", # deprecated; use merge_kcats
"merge_kcats",
"normalize_source",
"parse_kcat_source",
"read_kcat_source",
"read_dlkcat_output",
"remove_standard_kcat",
Expand Down
12 changes: 7 additions & 5 deletions src/geckopy/gather_kcats/get_standard_kcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from ..ec_model.constants import POOL_ID
from ..ec_model.pipeline.protein_pool import _resolve_enzyme_compartment_id
from .kcat_source_format import format_kcat_source, is_standard_source

if TYPE_CHECKING:
from ..databases import UniprotDB
Expand Down Expand Up @@ -54,7 +55,8 @@ def assign_standard_kcat(
A reaction with an empty subsystem has none.

The function is idempotent: previous "standard" entries
(identified by ``model.ec.source == "standard"``) are stripped
(rows whose ``model.ec.source`` has the origin ``standard`` and no
tuning status) are stripped
before re-applying.

Filtering: exchange (a reaction without a substrate or without a
Expand Down Expand Up @@ -300,7 +302,7 @@ def _load_custom_pseudo_rxns(adapter) -> set[str]:


def _remove_previous_standard(model: "EcModel") -> None:
"""Strip out entries marked source='standard' from a prior run."""
"""Strip out the entries of a prior run whose source marks the standard kcat."""
n = model.ec.n_rxns
if n == 0:
return
Expand All @@ -317,7 +319,7 @@ def _remove_previous_standard(model: "EcModel") -> None:
rows_to_remove: list[int] = []
rows_to_reset: list[int] = []
for i in range(n):
if model.ec.source[i] != "standard":
if not is_standard_source(model.ec.source[i]):
continue
if std_col is not None and rxn_enz_dense[i, std_col] > 0:
rows_to_remove.append(i)
Expand Down Expand Up @@ -417,7 +419,7 @@ def _assign_standard_kcat_to_missing(
model.ec.kcat = np.concatenate(
[model.ec.kcat, np.array(kcats_to_add, dtype=float)]
)
model.ec.source = list(model.ec.source) + ["standard"] * n_new
model.ec.source = list(model.ec.source) + [format_kcat_source(_STANDARD_NAME)] * n_new
model.ec.notes = list(model.ec.notes) + [""] * n_new
model.ec.eccodes = list(model.ec.eccodes) + [""] * n_new

Expand All @@ -444,7 +446,7 @@ def _fill_zero_kcats(model: "EcModel", standard_kcat: float) -> list[str]:
model.ec.kcat[unset_mask] = standard_kcat
indices = np.where(unset_mask)[0]
for i in indices:
model.ec.source[int(i)] = "standard"
model.ec.source[int(i)] = format_kcat_source(_STANDARD_NAME)
return [model.ec.rxns[int(i)] for i in indices]


Expand Down
5 changes: 3 additions & 2 deletions src/geckopy/gather_kcats/kcat_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from ..ec_model.pipeline.apply_kcat import apply_kcat_constraints
from ..ec_model.pipeline.fill_kcats import fill_kcats_from_isozymes
from .get_standard_kcat import assign_standard_kcat
from .kcat_source_format import format_kcat_source, is_standard_source
from .kcat_sources import load_kcat_source, read_kcat_source
from .kcats_from import _brenda_release, _measurements, kcats_from_brenda, kcats_from_dlkcat, kcats_from_ec_tree, kcats_from_okp
from .merge_kcats import _strip_okp_prefix, merge_kcats, normalize_source
Expand Down Expand Up @@ -204,7 +205,7 @@ def load(name: str) -> Optional[pd.DataFrame]:
combined["n"], combined["spread_log10"]):
i = index[rxn]
ec.kcat[i] = kcat
ec.source[i] = f"combined (sd={sdv:.2f}, n={nsrc})"
ec.source[i] = format_kcat_source("combined", {"sd": f"{sdv:.2f}", "n": int(nsrc)})
stage[i], candidates[i], spread[i], sd[i] = str(s), nsrc, spr, sdv
continue
lists: list[pd.DataFrame] = []
Expand Down Expand Up @@ -266,7 +267,7 @@ def load(name: str) -> Optional[pd.DataFrame]:
spread = np.concatenate([spread, np.full(extra, np.nan)])
sd = np.concatenate([sd, np.full(extra, np.nan)])
for i, src in enumerate(ec.source):
if src == "standard" and ec.kcat[i] > 0:
if is_standard_source(src) and ec.kcat[i] > 0:
stage[i] = "standard"

decisions = pd.DataFrame({
Expand Down
Loading
Loading