Model adapter (Python)#

geckopy objects in geckopy.adapter.

Functions#

Function

Summary

check_adapter_keys

Raise ValueError for a key of model_adapter.toml that no parameter uses.

ComplexParams

EvotuneParams

Hyperparameters for kcat tuning against experimental data.

format_adapter_params

The resolved parameters of adapter as text (see show_adapter_params).

generate_template_toml

Generate a commented TOML template for a new ecModel project.

KcatAssignmentParams

How kcats are assigned from the kcat source files (collect_kcats).

KcatStageParams

One [[kcat_assignment.stage]]: assigns a kcat to each reaction that is still

KeggParams

MatlabParams

Settings that only GECKO (MATLAB) reads; geckopy ignores them.

ModelAdapter

Holds the organism-specific parameters and overridable

ModelParameters

Top-level parameters for an ecModel adapter.

OkpParams

OpenKineticsPredictor settings (used by kcats_from_okp).

resolve_adapter

Return the adapter to use, falling back to model.adapter.

resolve_gr_exp

Return an explicit growth rate, else adapter.params.gr_exp.

resolve_param

Return an explicit value, else fall back to adapter.params.<attr>.

show_adapter_params

Print every adapter parameter with its value and where it comes from.

SourceGroupRule

One trust-tier entry in EvotuneParams.source_groups.

SpontaneousParams

Which reactions proceed without an enzyme.

UniprotParams

Reference#

check_adapter_keys#

check_adapter_keys(data: dict, file: Path | str)

Raise ValueError for a key of model_adapter.toml that no parameter uses.

The message is <file>: unknown key <dotted.key> in model_adapter.toml. Every table is checked: the sections, evotune.source_groups.<group>, the kcat_assignment.stage entries and kcat_sources.<name> (see KCAT_SOURCE_KEYS). matlab.params is free-form.

ComplexParams#

EvotuneParams#

Hyperparameters for kcat tuning against experimental data.

A kcat whose source is in no source_groups entry takes sigma0_log_default.

format_adapter_params#

format_adapter_params(adapter: 'ModelAdapter')

The resolved parameters of adapter as text (see show_adapter_params).

generate_template_toml#

generate_template_toml(*, project_name: str='my-ecmodel')

Generate a commented TOML template for a new ecModel project.

Every section of the schema is emitted, evotune kcat tuning hyperparameters included; optional fields are commented out at their defaults, so the template doubles as the reference for what can be set. The organism identifiers [kegg] id and [uniprot] id are written uncommented and empty, with an example in the comment.

Parameters

project_name

Name written into the template's header comment.

Returns

str

The full TOML template text, ending in a newline.

KcatAssignmentParams#

How kcats are assigned from the kcat source files (collect_kcats).

KcatStageParams#

One [[kcat_assignment.stage]]: assigns a kcat to each reaction that is still

open, from the first listed source with a value (select) or from all listed sources with a value, weighted by their reliability (combine).

KeggParams#

MatlabParams#

Settings that only GECKO (MATLAB) reads; geckopy ignores them.

They let one model_adapter.toml configure both tools.

ModelAdapter#

Holds the organism-specific parameters and overridable

helpers for one ecModel project.

Most users don't subclass this directly: they make a folder with a model_adapter.toml and call ModelAdapter.from_folder(folder).

Subclass only when a particular organism needs custom logic (e.g. an unusual way to identify spontaneous reactions, or a bespoke gene-id mapping that the default UniProt-table-driven one does not support).

ModelParameters#

Top-level parameters for an ecModel adapter.

OkpParams#

OpenKineticsPredictor settings (used by kcats_from_okp).

The OKP methods are set in [kcat_sources.okp] methods.

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 <path>/data/okpApiKey.txt.

resolve_adapter#

resolve_adapter(model, adapter: Optional['ModelAdapter']=None, *, purpose: str='this function')

Return the adapter to use, falling back to model.adapter.

Parameters

model

Any object that may have an .adapter attribute (a cobra Model, an EcModel, ...). getattr is used so plain cobra.Model doesn't trip on the missing attribute.

adapter

An explicitly-passed adapter. If non-None, returned as-is (takes priority over model.adapter).

purpose

Short description of why the calling function needs an adapter; included in the error message when none can be resolved. Example: "to read params.enzyme_comp".

Returns

ModelAdapter

Either adapter (if given) or model.adapter.

Raises

ValueError

If both adapter and model.adapter are None. The message tells the caller how to fix it.

resolve_gr_exp#

resolve_gr_exp(model, explicit=None, *, adapter: Optional['ModelAdapter']=None, purpose: str='this function')

Return an explicit growth rate, else adapter.params.gr_exp.

Raises

ValueError

If explicit is None and the adapter has no gr_exp: gr_exp is not set in model_adapter.toml. resolve_adapter raises if there is no adapter either.

resolve_param#

resolve_param(model, explicit, attr: str, *, adapter: Optional['ModelAdapter']=None, purpose: str='this function')

Return an explicit value, else fall back to adapter.params.<attr>.

Lets a function take the single parameter it needs directly, only requiring a full ModelAdapter when the value is not supplied.

Parameters

model

Any object that may have an .adapter attribute, used as the fallback source when adapter is not given.

explicit

The caller-supplied value. If not None, it is returned as-is and no adapter is consulted at all.

attr

Name of the attribute to read off adapter.params when explicit is None.

adapter

An explicitly-passed adapter, used instead of model.adapter when resolving the fallback value.

purpose

Short description of why the calling function needs the value; forwarded to resolve_adapter for its error message.

Returns

```explicitif given, otherwisegetattr(adapter.params, attr)``.` :

show_adapter_params#

show_adapter_params(adapter: 'ModelAdapter')

Print every adapter parameter with its value and where it comes from.

One line per item, in the order of adapterParameters.tsv: <key> = <value>  [<origin>]. The origin is file (set in model_adapter.toml), default, preset <name> (given by the kcat assignment preset) or not set (no value: <key> =  [not set]). The kcat assignment stages (kcat_assignment.stage[<i>]), the kcat_sources.<name>.<key> settings and the evotune source groups, in matching order with their sigma0_log, are shown as resolved.

SourceGroupRule#

One trust-tier entry in EvotuneParams.source_groups.

ec.source holds the label of the source of a kcat, such as "custom", "brenda", "ec_tree", "dlkcat", "combined" or "okp_kinform_h". An entry of sources matches the origin of the label or the whole label, in either case without regard to case. An entry ending in * is a prefix pattern on the origin: "okp_*" covers okp_eitlem_kinetics and okp_kinform_h.

SpontaneousParams#

Which reactions proceed without an enzyme.

Both rules may be given; a reaction is spontaneous if either matches. GECKO (MATLAB) reads the same keys, so a project needs no code for this.

UniprotParams#