Model adapter#
MATLAB functions in GECKO/src/model_adapter of the GECKO toolbox.
Functions#
Function |
Summary |
|---|---|
Write the parameters of an adapter class to model_adapter.toml. |
|
Read model adapter parameters from a TOML file. |
|
Abstract base class for species-specific model adapters. |
|
Resolve and cache the active ModelAdapter. |
|
Read a model adapter TOML file into a struct. |
|
Print the parameters of a model adapter and where each comes from. |
|
Model adapter configured by model_adapter.toml. |
|
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 charan adapter object, or the path to its .m file.
tomlFile: char, optionalfile to write (default: model_adapter.toml in the adapter's params.path). An existing file is not overwritten.
Returns
report: structfile: 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.
Parameters
tomlFile: charpath to model_adapter.toml, or to the project folder that holds it.
Returns
params: structthe 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: charpath to the TOML file.
Returns
data: structone 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
Parameters
modelAdapter: ModelAdapter, optionala loaded model adapter (default: the current default model adapter).
Returns
T: table, optionalthe 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: structvalues may be char or string scalars, numeric or logical scalars or vectors, cell arrays of char, structs and struct arrays.
filename: charpath of the TOML file to write; an existing file is overwritten.
header: char or cell, optionalcomment 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