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
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

## Unreleased

* `load_uniprot_tsv` always splits a gene cell of uniprot.tsv with several gene names, separated by semicolons and/or whitespace (`YPR080W; YBR118W`), into one row per gene name; the other columns are repeated on every row and an empty cell stays one row. A model gene that is any of the names finds the entry. The `split_gene_cells` option is removed. GECKO's `loadDatabases` does the same.
* The user guides (evotune, YAML format, relaxation methods, migration from GECKO MATLAB, kcat sources) moved to [gecko-docs](https://gecko-docs.readthedocs.io/en/latest/). The `docs/` folder is gone; the developer notes are in `dev/`.
* `uniprot.id` and `kegg.id` are empty by default instead of the identifiers of Saccharomyces cerevisiae (`"559292"` and `"sce"`), as in GECKO; `adapterParameters.tsv` is the same as GECKO's. `geckopy init` writes both uncommented as `""`, with examples in the comments. `make_ec_model` and `calculate_f_factor` raise `FileNotFoundError` naming `[uniprot] id` when `data/uniprot.tsv` is missing and the identifier is empty, as GECKO's `loadDatabases` raises `loadDatabases:noUniprotID`; an empty `kegg.id` leaves KEGG out with a warning. A project that relied on the yeast defaults sets the identifiers in model_adapter.toml.
* `upgrade_project` (`geckopy upgrade`) reports the calls of removed or replaced functions in the project's scripts with their replacement, for example `submit_open_kinetics_predictor`, `fetch_open_kinetics_predictor`, `build_okp_input_csv` and `truncate_values`.
* The deprecated aliases with GECKO 3 names are removed from `geckopy`: `run_dlkcat`, `read_dlkcat_output`, `write_dlkcat_input`, `apply_custom_kcats`, `get_kcat_across_isozymes`, `get_standard_kcat`, `select_kcat_value`, `merge_dlkcat_and_fuzzy_kcats`, `get_ec_from_database`, `get_ec_from_gem`, `sigma_fitter` and `constrain_flux_data`, and `find_max_value`, which ports `findMaxValue` that GECKO 4 removed. `upgrade_project` (`geckopy upgrade`) reports each of them in a project's scripts with its replacement, which `geckopy.upgrade.RENAMED` lists. `extract_enzyme_substrate_pairs` stays public.
* The `okp` source group of the presets is the OpenKineticsPredictor method KinForm-H alone by default, instead of the eight methods with combination parameters; a project that sets `[kcat_sources.okp] methods` keeps its list. `update_kcat_sources` then gathers `okp_kinform_h.tsv` only. GECKO uses the same default.
* `okp.method` is removed from model_adapter.toml; `[kcat_sources.okp] methods` is the only setting that names OpenKineticsPredictor methods (default `["KinForm-H"]`). `kcats_from_okp` without `method` uses the first entry of `methods`; it used `okp.method`. `[kcat_sources.okp_<x>] method` is removed: the method of the file `okp_<x>` is the known method whose file name is `okp_<x>` (`okp_` and the method in lower case, each run of other characters than letters and digits as `_`), and `update_kcat_sources` reports any other `okp_<x>` as failed (`<name> is not the file of a known OKP method; the files are ...`). `Unknown OKP methods in [kcat_sources.okp] methods: ...` lists the names comma-separated. `CatPred` and `TurNup` are no longer accepted in `[kcat_sources.okp] methods`: `kcats_from_okp` rejects them, so the configuration now fails early with `Unknown OKP methods`.
* The `okp` source group of the presets is the OpenKineticsPredictor method KinForm-H by default; `[kcat_sources.okp] method` sets another. `update_kcat_sources` then gathers `okp_kinform_h.tsv` only. GECKO uses the same default.
* `[kcat_sources.okp] method` is the only setting that names the OpenKineticsPredictor method (default `"KinForm-H"`); `[okp]` has no `method` key. `kcats_from_okp` without `method` uses it. `[kcat_sources.okp_<x>] method` is removed: the method of the file `okp_<x>` is the known method whose file name is `okp_<x>` (`okp_` and the method in lower case, each run of other characters than letters and digits as `_`), and `update_kcat_sources` reports any other `okp_<x>` as failed (`<name> is not the file of a known OKP method; the files are ...`). `Unknown OKP method <name> in [kcat_sources.okp] method; supported: <known>` lists the supported methods comma-separated. `CatPred` and `TurNup` are not accepted as `[kcat_sources.okp] method`: `kcats_from_okp` rejects them, so the configuration fails early with `Unknown OKP method`.
* Evotune source groups are one table each, `[evotune.source_groups.<group>]` with `sources` and `sigma0_log`, both required. `[evotune.sigma0_log_source]` and `SourceGroupRule.match_okp` are removed, and so is the `okp_method` argument of `classify_kcat_source`, `classify_kcat_sources`, `screen_kcat_leverage`, `cmaes_kcat_tuning`, `sweep_tunable_mask_size` and the other tuning functions; a group covers OpenKineticsPredictor kcats with a pattern such as `okp_*`. `sigma0_log` is a standard deviation of the natural log of the kcat. A `sources` entry ending in `*` is a prefix pattern on the origin (case-insensitive); exact matches over all groups are tried first, then patterns, the longest prefix first, and groups of equal length in file order. Without `[evotune.source_groups]` the groups are `custom` 0.1, `brenda` 0.2, `ec_tree` 0.3 and `combined` 0.4 (they were `dlkcat` 0.4, `brenda` 0.2 and `custom` 0.1); groups in the file replace the defaults entirely. Tuning warns when more than 20 % of the tunable kcats are in no group: `<n> of <m> tunable kcats match no evotune source group and get sigma0_log_default (<value>); origins: <up to 5, by count descending and then by name>`.
* `kcat_aggregate_brenda` is removed from model_adapter.toml (and `ModelParameters`); `[kcat_sources.brenda] aggregation` is the only BRENDA aggregation setting. `kcats_from_brenda` and `fuzzy_kcat_matching` without an explicit aggregation use it as the kcat assignment config resolves it: median for the default preset `brenda_ec_tree` and the other median presets, max for `gecko_classic`, and max when neither the preset nor the file sets it. They used `kcat_aggregate_brenda`, which defaulted to `"max"`, so a call without an aggregation under the default preset now takes the median.
* `kcat_aggregate_candidates` and `kcat_aggregate_isozymes` are removed from model_adapter.toml (and `ModelParameters`). `apply_kcat_list` takes `criteria="max"` and `fill_kcats_from_isozymes` takes `aggregate="mean"` as their defaults, as before; they no longer read an adapter value.
* `gr_exp` has no default (it was `0.41`, the yeast growth rate). `sensitivity_tuning`, `fit_sigma`, `flexibilize_enz_concs` and `relax_enz_concs` called without a growth rate raise `ValueError: gr_exp is not set in model_adapter.toml` when the file does not set it; `geckopy init` writes it commented out, noting that the functions that tune kcats or fit sigma require it. A project that relied on `0.41` sets `gr_exp`.
* An unknown key in model_adapter.toml is an error, whatever its place: `ModelAdapter.from_folder` raises `ValueError` with `<file>: unknown key <dotted.key> in model_adapter.toml`. This includes keys under `evotune.source_groups.<group>`, the `kcat_assignment.stage` entries and `kcat_sources.<name>`. The keys of `[kcat_sources.<name>]` are `aggregation` and `force_wildcard_level` for `brenda`, `k` for `ec_tree`, `k`, `min_identity` and `coverage` for `homologs`, `methods` for `okp`, and none for `custom`, `dlkcat` and `okp_<file of a known OKP method>`; another source name is an unknown key. A malformed evotune group raises `<file>: evotune.source_groups.<g> must be a table with sources and sigma0_log`, `... needs both sources and sigma0_log`, `... .sources must be a list of strings` or `... .sigma0_log must be a positive number`. The removed keys are unknown keys: no alias or warning remains for them.
* An unknown key in model_adapter.toml is an error, whatever its place: `ModelAdapter.from_folder` raises `ValueError` with `<file>: unknown key <dotted.key> in model_adapter.toml`. This includes keys under `evotune.source_groups.<group>`, the `kcat_assignment.stage` entries and `kcat_sources.<name>`. The keys of `[kcat_sources.<name>]` are `aggregation` and `force_wildcard_level` for `brenda`, `k` for `ec_tree`, `k`, `min_identity` and `coverage` for `homologs`, `method` for `okp`, and none for `custom`, `dlkcat` and `okp_<file of a known OKP method>`; another source name is an unknown key. A malformed evotune group raises `<file>: evotune.source_groups.<g> must be a table with sources and sigma0_log`, `... needs both sources and sigma0_log`, `... .sources must be a list of strings` or `... .sigma0_log must be a positive number`. The removed keys are unknown keys: no alias or warning remains for them.
* `geckopy adapter show [FOLDER]` (default: the current folder) and `show_adapter_params(adapter)` print one line per item in the order of `adapterParameters.tsv`: `<key> = <value> [<origin>]` with the origin `file`, `default`, `preset <name>` or `not set` (`<key> = [not set]`), without a header. The kcat assignment stages (`kcat_assignment.stage[<i>]`), the `kcat_sources.<name>.<key>` settings and the evotune source groups with their `sigma0_log` are shown as resolved. GECKO has `showAdapterParams`.
* `ModelAdapter.from_folder` checks more of model_adapter.toml when it loads it: `[kcat_sources.okp] methods` must be a list of strings and name known OKP methods (`Unknown OKP methods in [kcat_sources.okp] methods: <names in file order, once each>; methods: <known>.`), a `[kcat_sources]` entry must be a table (`<file>: kcat_sources.<name> must be a table`), `[kcat_sources.brenda] aggregation` must be `max` or `median`, an evotune group's `sources` must be a non-empty list of strings, and `sigma0_log` must be finite and positive. A function given another BRENDA aggregation raises `aggregation must be max or median`. The unlabelled-kcat warning of evotune tuning is also issued as a `UserWarning`. `geckopy adapter show` prints whole-valued numbers without decimals and lists the `kcat_sources` settings by source (brenda, ec_tree, homologs, okp, then others alphabetically) and key.
* `ModelAdapter.from_folder` checks more of model_adapter.toml when it loads it: `[kcat_sources.okp] method` must be a string and name a known OKP method (`kcat_sources.okp.method must be a string`, `Unknown OKP method <name> in [kcat_sources.okp] method; supported: <known>`), a `[kcat_sources]` entry must be a table (`<file>: kcat_sources.<name> must be a table`), `[kcat_sources.brenda] aggregation` must be `max` or `median`, an evotune group's `sources` must be a non-empty list of strings, and `sigma0_log` must be finite and positive. A function given another BRENDA aggregation raises `aggregation must be max or median`. The unlabelled-kcat warning of evotune tuning is also issued as a `UserWarning`. `geckopy adapter show` prints whole-valued numbers without decimals and lists the `kcat_sources` settings by source (brenda, ec_tree, homologs, okp, then others alphabetically) and key.
* `submit_open_kinetics_predictor`, `fetch_open_kinetics_predictor`, `build_okp_input_csv` and `parse_okp_output` are private (`_submit_open_kinetics_predictor` and so on) and no longer exported from `geckopy`, `geckopy.gather_kcats` or `geckopy.gather_kcats.open_kinetics_predictor`: `kcats_from_okp` and `kcats_from_dlkcat(via="okp")` submit and fetch OpenKineticsPredictor jobs. GECKO moves its OKP engine functions into `kcatsFromOKP` in the same way. `OKPClient` and `OKPError` stay public.
* `convert_custom_kcats` (or `geckopy upgrade`) turns `data/customKcats.tsv` into `data/kcats/custom.tsv`. `collect_kcats` and `assign_kcats` do not apply `data/customKcats.tsv`: when a stage lists custom, `data/kcats/custom.tsv` does not exist and `data/customKcats.tsv` does, they raise `ValueError` naming `convert_custom_kcats`, before they change the model. The decisions have no stage `custom`. GECKO's `collectKcats` does the same.
* `download_uniprot` and `load_uniprot_tsv` download reviewed and unreviewed entries by default (`reviewed=False`), as the adapter default `uniprot.reviewed = false`; they downloaded reviewed entries only.
Expand Down
2 changes: 1 addition & 1 deletion src/geckopy/adapter/adapterParameters.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ kcat_assignment.preset Kcat assignment preset: brenda_ec_tree (used when neith
kcat_assignment.isozymes true Fill reactions without a kcat from their isozymes after the stages
kcat_assignment.standard true Give the remaining reactions the standard kcat
kcat_assignment.stage Stages instead of a preset: action (select or combine), sources, criteria and BRENDA limits ([[kcat_assignment.stage]])
kcat_sources Settings per kcat source file: [kcat_sources.brenda] aggregation and force_wildcard_level, [kcat_sources.ec_tree] k, [kcat_sources.homologs] k, min_identity and coverage, [kcat_sources.okp] methods (the OKP methods of the okp source group; default KinForm-H)
kcat_sources Settings per kcat source file: [kcat_sources.brenda] aggregation and force_wildcard_level, [kcat_sources.ec_tree] k, [kcat_sources.homologs] k, min_identity and coverage, [kcat_sources.okp] method (the OKP method of the okp source group; default KinForm-H)
matlab.make_model_anaerobic matlab.makeModelAnaerobic MATLAB function that constrains the ecModel to anaerobic growth
matlab.change_protein_biomass matlab.changeProteinBiomass MATLAB function that changes the protein content of the biomass
26 changes: 14 additions & 12 deletions src/geckopy/adapter/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ class KcatStageParams(BaseModel):
sources: list[str] = Field(
min_length=1,
description=(
"Source file names (custom, ec_tree, dlkcat, okp_catapro, ...), the OKP "
"methods of [kcat_sources.okp] as okp, and for select the BRENDA tiers "
"Source file names (custom, ec_tree, dlkcat, okp_unikp, ...), the OKP "
"method of [kcat_sources.okp] as okp, and for select the BRENDA tiers "
"database_exact, database_top and database_bottom, which read brenda.tsv; "
"for select the first listed wins."
),
Expand Down Expand Up @@ -271,7 +271,7 @@ class EvotuneParams(BaseModel):
class OkpParams(BaseModel):
"""OpenKineticsPredictor settings (used by kcats_from_okp).

The OKP methods are set in ``[kcat_sources.okp] methods``.
The OKP method is set in ``[kcat_sources.okp] method``.

The API key is intentionally NOT here (it is a secret): provide it as a
function argument, the OKP_API_KEY environment variable, or the file
Expand Down Expand Up @@ -352,7 +352,7 @@ class ModelParameters(BaseModel):
"brenda": ("aggregation", "force_wildcard_level"),
"ec_tree": ("k",),
"homologs": ("k", "min_identity", "coverage"),
"okp": ("methods",),
"okp": ("method",),
"dlkcat": (),
"custom": (),
}
Expand Down Expand Up @@ -402,14 +402,16 @@ def _check_table(cls: type[BaseModel], data: dict, prefix: str, file: Path | str


def _check_source_values(name: str, table: dict, file: Path | str) -> None:
"""The values of ``[kcat_sources.okp] methods`` and ``[kcat_sources.brenda] aggregation``."""
if name == "okp" and "methods" in table:
methods = table["methods"]
if not isinstance(methods, list) or not all(isinstance(m, str) for m in methods):
raise ValueError(f"{file}: kcat_sources.okp.methods must be a list of strings")
from ..gather_kcats.kcat_sources import check_okp_methods

check_okp_methods(methods)
"""The values of ``[kcat_sources.okp] method`` and ``[kcat_sources.brenda] aggregation``."""
if name == "okp" and "method" in table:
method = table["method"]
if not isinstance(method, str) and not (
isinstance(method, list) and method and all(isinstance(m, str) for m in method)
):
raise ValueError(f"{file}: kcat_sources.okp.method must be a string")
from ..gather_kcats.kcat_sources import _okp_method_names

_okp_method_names(method)
if name == "brenda" and "aggregation" in table and table["aggregation"] not in ("max", "median"):
raise ValueError(f"{file}: kcat_sources.brenda.aggregation must be max or median")

Expand Down
8 changes: 4 additions & 4 deletions src/geckopy/adapter/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _stage_line(i: int, stage, shown: list[str], origin: str) -> str:

def format_adapter_params(adapter: "ModelAdapter") -> str:
"""The resolved parameters of ``adapter`` as text (see :func:`show_adapter_params`)."""
from ..gather_kcats.kcat_assignment import DEFAULT_OKP_METHODS, kcat_assignment_config
from ..gather_kcats.kcat_assignment import DEFAULT_OKP_METHOD, kcat_assignment_config

params = adapter.params
config = kcat_assignment_config(adapter)
Expand All @@ -84,16 +84,16 @@ def format_adapter_params(adapter: "ModelAdapter") -> str:
out.append(_stage_line(i, stage, shown, "file" if params.kcat_assignment.stage else preset_origin))
elif key == "kcat_sources":
sources = {name: dict(keys) for name, keys in config.sources.items()}
if "methods" not in sources.get("okp", {}):
sources.setdefault("okp", {})["methods"] = list(DEFAULT_OKP_METHODS)
if "method" not in sources.get("okp", {}):
sources.setdefault("okp", {})["method"] = DEFAULT_OKP_METHOD
order = ["brenda", "ec_tree", "homologs", "okp"]
for name in sorted(sources, key=lambda n: (order.index(n), "") if n in order else (len(order), n)):
keys = sources[name]
for k in sorted(keys):
v = keys[k]
if k in params.kcat_sources.get(name, {}):
where = "file"
elif name == "okp" and k == "methods":
elif name == "okp" and k == "method":
where = "default"
else:
where = preset_origin
Expand Down
2 changes: 1 addition & 1 deletion src/geckopy/adapter/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"# min_identity = 0.4",
"# coverage = 0.8",
"# [kcat_sources.okp]",
'# methods = ["KinForm-H"] # the first is the default method of kcats_from_okp',
'# method = "KinForm-H" # the default method of kcats_from_okp',
"",
]

Expand Down
23 changes: 8 additions & 15 deletions src/geckopy/databases/uniprot_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@
"""
from __future__ import annotations

import re
from dataclasses import dataclass, field
from pathlib import Path

import numpy as np

# Separates the gene names in a Gene Names cell.
_GENE_SEPARATOR = re.compile(r"[;\s]+")


@dataclass
class UniprotDB:
"""Parsed uniprot.tsv. Arrays are aligned: row i in every field
describes the same database entry (or gene-name row when split).
describes one gene name of a database entry.

``mw`` is in Da, matching the Mass column of the TSV verbatim.
"""
Expand Down Expand Up @@ -55,7 +59,6 @@ def find_by_id(self, uniprot_id: str) -> int | None:
def load_uniprot_tsv(
path: str | Path,
*,
split_gene_cells: bool = False,
uniprot_id: str | int | None = None,
id_type: str = "taxonomy_id",
gene_id_field: str = "gene_oln",
Expand All @@ -72,15 +75,6 @@ def load_uniprot_tsv(
path
Path to uniprot.tsv. May not exist if ``uniprot_id`` triggers
an auto-download.
split_gene_cells
If True, rows whose Gene Names cell contains whitespace-separated
multiple names are expanded into one row per gene name. All other
fields (Entry, EC, MW, sequence) are duplicated across the
expanded rows. This matters for organisms where the UniProt
``gene_oln`` field returns multiple space-separated ORF names
per entry: with the default of False, the cell is stored
verbatim (including any embedded whitespace), so an exact-match
lookup against a single ORF name silently misses those genes.
uniprot_id
UniProt-side identifier (e.g. NCBI taxonomy ID). Required
for auto-download; otherwise unused.
Expand Down Expand Up @@ -165,10 +159,9 @@ def load_uniprot_tsv(
except ValueError:
mass_da = float("nan")

if split_gene_cells and gene_cell.strip():
gene_names = gene_cell.split()
else:
gene_names = [gene_cell]
gene_names = [name for name in _GENE_SEPARATOR.split(gene_cell) if name]
if not gene_names:
gene_names = [""]

source_row_ids.append(entry)
for gene_name in gene_names:
Expand Down
Loading
Loading