Model adapter#

MATLAB functions in GECKO/src/model_adapter of the GECKO toolbox.

Functions#

Function

Summary

convertAdapterToToml

Write the parameters of an adapter class to model_adapter.toml.

loadAdapterParams

Read model adapter parameters from a TOML file.

ModelAdapter

Abstract base class for species-specific model adapters.

ModelAdapterManager

Resolve and cache the active ModelAdapter.

readAdapterToml

Read a model adapter TOML file into a struct.

showAdapterParams

Print the parameters of a model adapter and where each comes from.

TomlAdapter

Model adapter configured by model_adapter.toml.

writeAdapterToml

Write a struct as a model adapter TOML file.

Reference#

convertAdapterToToml#

function report = convertAdapterToToml(adapter, tomlFile)

Write the parameters of an adapter class to model_adapter.toml.

Converts an existing ModelAdapter class (GECKO 3 or 4 style) to model_adapter.toml, the configuration file shared by GECKO and geckopy. Parameter names are translated with adapterParameters.tsv (for instance Ptot becomes p_tot), paths inside the project folder are written relative to it, and parameters without a geckopy name are kept under [matlab.params], so that loadAdapterParams gives back the same params.

Methods that the adapter class overrides cannot be written to TOML. They are listed in the report, with how to convert them:

  • getSpontaneousReactions: set [spontaneous] name_contains or file;

  • makeModelAnaerobic, changeProteinBiomass: set [matlab] make_model_anaerobic or change_protein_biomass to a function name;

  • other methods: keep the adapter class and let its constructor call loadAdapterParams.

Parameters

adapter : ModelAdapter or char

an adapter object, or the path to its .m file.

tomlFile : char, optional

file to write (default: model_adapter.toml in the adapter's params.path). An existing file is not overwritten.

Returns

report : struct
  • file: the file written;

  • unmapped: parameters written under [matlab.params];

  • notCarried: parameters that model_adapter.toml has no key for and that are not written: kcatAggregation (set aggregation in [kcat_sources.brenda]) and evotune.kcatSources and evotune.sigma0logSource (write [evotune.source_groups] tables);

  • methods: overridden methods that need carrying over by hand.

Examples

report = convertAdapterToToml(fullfile(projectPath,'MyGEMAdapter.m'));
adapter = TomlAdapter(projectPath);

See also

TomlAdapter, loadAdapterParams, writeAdapterToml

loadAdapterParams#

function params = loadAdapterParams(tomlFile)

Read model adapter parameters from a TOML file.

Reads model_adapter.toml, the configuration file shared by GECKO and geckopy, and returns the parameters with GECKO's field names, so that they can be used as ModelAdapter.params. Keys are translated with adapterParameters.tsv (for instance p_tot becomes Ptot); keys that are not given get the default listed there, which is geckopy's default. A key that is not known is an error, also inside [evotune.source_groups], [[kcat_assignment.stage]] and [kcat_sources.]; the keys of a kcat source are those that updateKcatSources reads.

Parameters

tomlFile : char

path to model_adapter.toml, or to the project folder that holds it.

Returns

params : struct

the adapter parameters, as in ModelAdapter.params:

  • path: the project folder (the folder of the TOML file);

  • convGEM and spontaneous.file: absolute paths;

  • evotune.kcatSources and evotune.sigma0logSource: built from the evotune.source_groups tables, one entry per element of sources (a prefix pattern keeps its trailing *), in group order, with the sigma0_log of its group, and evotune.kcatGroups the group name of each entry. Without [evotune.source_groups] the groups are custom 0.1, brenda 0.2, ec_tree 0.3 and combined 0.4;

  • fields under [matlab.params] are copied as they are, for parameters that only GECKO uses.

Examples

params = loadAdapterParams(fullfile(projectPath,'model_adapter.toml'));

See also

TomlAdapter, readAdapterToml, convertAdapterToToml

ModelAdapter#

Abstract base class for species-specific model adapters.

Defines the interface that every species adapter must implement and provides shared default behaviour for retrieving GECKO parameters, mapping model genes to UniProt, and locating reference databases. Concrete subclasses override these methods for a particular organism.

Notes

  • params : struct of model-specific GECKO parameters (public property).

  • getSpontaneousReactions : abstract method that subclasses must define.

See also

ModelAdapterManager

ModelAdapterManager#

Resolve and cache the active ModelAdapter.

Static helper class that loads a model adapter from a file path and stores a process-wide default adapter, so that GECKO functions can retrieve the active adapter without it being passed explicitly.

An adapter is loaded from model_adapter.toml (give the file or the project folder; see TomlAdapter) or from an adapter class (give its .m file). Adapter classes that do not subclass TomlAdapter are deprecated: the first one loaded in a MATLAB session raises the warning GECKO:deprecatedAdapterClass.

Notes

All methods are static. The default adapter is held in a persistent variable and shared across the whole GECKO session.

See also

ModelAdapter

readAdapterToml#

function data = readAdapterToml(filename)

Read a model adapter TOML file into a struct.

Reads the subset of TOML that model adapter files use: comments, bare keys, basic and literal strings, integers, floats, booleans, arrays of these values (also over several lines), tables ([kegg], [a.b.c]) and arrays of tables ([[a]]). Anything else, such as dates, inline tables, multi-line strings or quoted keys, stops with an error that names the line.

Parameters

filename : char

path to the TOML file.

Returns

data : struct

one field per key, with tables as nested structs and arrays of tables as struct arrays. Strings are char, numbers double, booleans logical, arrays of strings a 1xn cell and arrays of numbers or booleans a 1xn vector. An empty array is an empty cell.

Examples

data = readAdapterToml(fullfile(projectPath,'model_adapter.toml'));

See also

writeAdapterToml, loadAdapterParams

showAdapterParams#

function T = showAdapterParams(modelAdapter)

Print the parameters of a model adapter and where each comes from.

Prints one line per parameter of adapterParameters.tsv, in that order:

<key> = <value>  [<origin>]

The origin is file (set in model_adapter.toml, or by an adapter class), default (the default of adapterParameters.tsv or of the code), preset (given by the kcat assignment preset) or not set (no value; the line is " = [not set]"). Strings are shown bare, booleans as true or false, lists comma-joined, integer-valued numbers whole and other numbers with %g. The resolved kcat assignment is listed as kcat_assignment.stage[] lines (the stages of the preset or the file, with the settings that the file sets or that differ from the defaults criteria max, top_origin_limit 4, bottom_origin_limit 6 and wildcard_limit 3), the settings of each kcat source as kcat_sources.. lines and the evotune source groups, in group order, as evotune.source_groups. lines with their sigma0_log. geckopy's "geckopy adapter show" prints the same lines.

Parameters

modelAdapter : ModelAdapter, optional

a loaded model adapter (default: the current default model adapter).

Returns

T : table, optional

the listing, with the columns key, value and origin. Without an output argument the lines are printed.

Examples

showAdapterParams(ModelAdapterManager.getDefault())

See also

loadAdapterParams, kcatAssignmentConfig

TomlAdapter#

Model adapter configured by model_adapter.toml.

The model adapter for a project whose parameters are in model_adapter.toml, the configuration file that GECKO and geckopy share. No adapter class has to be written: what used to be code in an adapter class is set in the TOML file.

  • Spontaneous reactions: [spontaneous] name_contains (reactions whose name contains the text) and/or file (a TSV of reaction identifiers, optionally with a second 0/1 column).

  • Anaerobic conditions and protein content during kcat tuning: [matlab] make_model_anaerobic and change_protein_biomass name MATLAB functions, for instance in the project's code folder, which is added to the MATLAB path. Each takes the ecModel (and, for change_protein_biomass, the protein content) and returns the ecModel.

A project that needs other custom code can keep an adapter class and read its parameters from the TOML file in its constructor:

obj.params = loadAdapterParams(fullfile(projectPath,'model_adapter.toml'));

Examples

adapter = TomlAdapter(fullfile(projectPath,'model_adapter.toml'));
% or, as the default adapter:
ModelAdapterManager.setDefault(projectPath);

See also

ModelAdapter, ModelAdapterManager, loadAdapterParams, convertAdapterToToml

writeAdapterToml#

function writeAdapterToml(data, filename, header)

Write a struct as a model adapter TOML file.

Writes the subset of TOML that readAdapterToml reads: values first, then each nested struct as a [table] and each struct array as an array of tables ([[name]]).

Parameters

data : struct

values may be char or string scalars, numeric or logical scalars or vectors, cell arrays of char, structs and struct arrays.

filename : char

path of the TOML file to write; an existing file is overwritten.

header : char or cell, optional

comment lines written at the top of the file (without '#').

Examples

writeAdapterToml(struct('sigma',0.5), 'model_adapter.toml', ...
    {'Adapter for ecYeastGEM'});

See also

readAdapterToml, convertAdapterToToml