Model adapter#

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

Functions#

Function

Summary

adapterTemplate

KEY_CLASSNAME Template ModelAdapter to copy and adapt per organism.

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.

TomlAdapter

Model adapter configured by model_adapter.toml.

writeAdapterToml

Write a struct as a model adapter TOML file.

Reference#

adapterTemplate#

KEY_CLASSNAME Template ModelAdapter to copy and adapt per organism.

Starting point for a species-specific adapter. Copy this file, rename the class, and edit the parameter values set in the constructor and the getSpontaneousReactions method to match the target organism and model.

See also

ModelAdapter, ModelAdapterManager

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 carry them over:

  • 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];

  • 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.

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 and evotune.sigma0_log_source tables, one entry per ec.source value;

  • 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).

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

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