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
2 changes: 1 addition & 1 deletion databases/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

GECKO does not include BRENDA data. `fetchBrendaAsset` downloads the files of the [toolbox-assets](https://github.com/CompMetEng/toolbox-assets) release `brenda-2026.1-1` ([BRENDA](https://www.brenda-enzymes.org) 2026.1, CC BY 4.0) on first use into `databases/brenda-2026.1-1`, checked against the manifest checksums. geckopy uses the same release. A project can use its own BRENDA files instead, in `data/brenda`, written by the `geckopy brenda-refresh` CLI of [geckopy](https://github.com/CompMetEng/geckopy).

- `kcat.tsv`: kcat values per organism, reaction and substrate. Both a per-triple maximum (`kcat_max`) and median (`kcat_median`) are recorded. Which one is used is set by `params.kcatAggregation` on the model adapter, or per call with `fuzzyKcatMatching(model,'kcatAggregation','median')`; the default is `max`.
- `kcat.tsv`: kcat values per organism, reaction and substrate. Both a per-triple maximum (`kcat_max`) and median (`kcat_median`) are recorded. Which one is used is set by `aggregation` in `[kcat_sources.brenda]` of `model_adapter.toml` (the preset's: `median` for the default preset, `max` for `gecko_classic`), or per call with `fuzzyKcatMatching(model,'kcatAggregation','median')`.
- `sa.tsv`: specific activities per organism, reaction and substrate, with a maximum (`sa_max`) and median (`sa_median`); `loadBRENDAdata` uses `sa_max`.
- `mw.tsv`: molecular weights per organism and reaction (without explicitly referring to a protein identifier).
- `measurements.tsv`: one row per wild-type k<sub>cat</sub> measurement with an EC number: EC number, substrate (name and InChIKey), organism, UniProt accession and sequence id, k<sub>cat</sub> (1/s; the geometric midpoint of a range), temperature, pH and PubMed id. Values more than four orders of magnitude below their EC class, and clusters of values below 0.01 /s that sit three orders of magnitude under the other values of their EC number, are left out as unit errors. `kcatsFromECTree` reads it (see `loadBrendaMeasurements`).
Expand Down
2 changes: 1 addition & 1 deletion src/change_model/applyKcatConstraints.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
%
% See also
% --------
% makeEcModel, getKcatAcrossIsozymes, setKcatForReactions
% makeEcModel, fillKcatsFromIsozymes, setKcatForReactions

p = parseGECKOargs(varargin, { ...
'updateRxns', []});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function model = getKcatAcrossIsozymes(model)
% getKcatAcrossIsozymes Fill missing kcats from isozymes of the same reaction.
function model = fillKcatsFromIsozymes(model)
% fillKcatsFromIsozymes Fill missing kcats from isozymes of the same reaction.
%
% Low-level: collectKcats and assignKcats run this function; call it
% directly only to change kcats by hand.
Expand All @@ -24,7 +24,7 @@
%
% Examples
% --------
% model = getKcatAcrossIsozymes(model);
% model = fillKcatsFromIsozymes(model);
%
% See also
% --------
Expand Down
2 changes: 1 addition & 1 deletion src/change_model/setKcatForReactions.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
%
% See also
% --------
% applyKcatConstraints, getKcatAcrossIsozymes
% applyKcatConstraints, fillKcatsFromIsozymes
rxnIds = convertCharArray(rxnIds);

hasExp = ~cellfun(@isempty,regexp(rxnIds,'_EXP_\d+$'));
Expand Down
32 changes: 0 additions & 32 deletions src/deprecated/adapterTemplate.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@
% Provide your organism scientific name
obj.params.org_name = 'genus species';

% Which BRENDA aggregate fuzzyKcatMatching reads for each
% (EC, substrate, organism) triple: 'max' (the highest
% turnover reported) or 'median' (the middle one). Can also
% be given per call as
% fuzzyKcatMatching(model,'kcatAggregation','median').
obj.params.kcatAggregation = 'max';

% Taxonomic identifier for Complex Portal
obj.params.complex.taxonomicID = [];

Expand Down Expand Up @@ -96,31 +89,6 @@
% this does not interfere with them catalyzing reactions in
% different compartments). Typically, cytoplasm is chosen.
obj.params.enzyme_comp = 'cytoplasm';

%% Hyperparameters for evotune (CMA-ES) kcat fitting
% Default initial uncertainty (standard deviation in log-space) for kcat values
obj.params.evotune.sigma0logDefault = 0.5;
% Data sources for kcat values, ordered from least to most trusted
obj.params.evotune.kcatSources = {'dlkcat','brenda','custom'};
% Initial uncertainty for each source (lower = more trusted data)
obj.params.evotune.sigma0logSource = [0.4; 0.2; 0.1];

% Weight on the max-growth RMSE against the flux RMSE:
% (rmseFlux + w*rmseMaxGrowth) / (w+1). At 1 both count equally.
obj.params.evotune.maxGrowthWeight = 1.0;
% Weight on a prior term in the search objective,
% rmse + w*mean((log(k/k0)/sigma0log)^2). Keeps large corrections
% reproducible across seeds; 0 scores on RMSE alone.
obj.params.evotune.priorPenaltyWeight = 0.03;
% Give isozyme copies of one reaction (sharing a prior value and
% a source) a single shared kcat, so the search cannot invent a
% distinction the kcat assignment never made.
obj.params.evotune.tieIsozymes = true;

% Stop optimization when RMSE falls below this threshold
obj.params.evotune.rmseThreshold = 0.2;
% Maximum number of CMA-ES generations before termination
obj.params.evotune.maxGenerations = 150;
end

% function ecModel = makeModelAnaerobic(ecModel)
Expand Down
14 changes: 14 additions & 0 deletions src/deprecated/getKcatAcrossIsozymes.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function model = getKcatAcrossIsozymes(model)
% getKcatAcrossIsozymes Deprecated alias for fillKcatsFromIsozymes.
%
% Kept for backward compatibility with earlier GECKO 4 code. Will be removed
% in a future release; switch to fillKcatsFromIsozymes.
%
% See also
% --------
% fillKcatsFromIsozymes

warning('GECKO:deprecatedName', ...
'getKcatAcrossIsozymes is deprecated; use fillKcatsFromIsozymes instead. The old name will be removed in a future release.');
model = fillKcatsFromIsozymes(model);
end
6 changes: 3 additions & 3 deletions src/download_databases/loadBRENDAdata.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
% a loaded model adapter (default: the current default model adapter).
% kcatAggregation : char
% which aggregate to read from kcat.tsv and sa.tsv, 'max' or
% 'median' (default: params.kcatAggregation from the model adapter,
% or 'max' if the adapter does not set it). A triple's max is the
% 'median' (default: [kcat_sources.brenda] aggregation as resolved from the preset or the
% stages (median for the default preset, max when no stage sets it)). A triple's max is the
% highest turnover reported for it; its median is the middle one.
% filterOutlierKcats : logical
% whether to drop a row whose kcat is implausibly low for its EC
Expand Down Expand Up @@ -58,7 +58,7 @@
'kcatAggregation', [], @(x) assert(isempty(x) || any(strcmpi(x, ...
{'max','median'})), ...
'loadBRENDAdata:invalidKcatAggregation', ...
'kcatAggregation must be ''max'' or ''median''.'); ...
'aggregation must be max or median'); ...
'filterOutlierKcats', true, @(x) assert((islogical(x) || isnumeric(x)) && ...
isscalar(x), ...
'loadBRENDAdata:invalidFilterOutlierKcats', ...
Expand Down
39 changes: 36 additions & 3 deletions src/download_databases/loadDatabases.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
% modelAdapter : ModelAdapter
% a loaded model adapter (default: the current default model adapter;
% send in [] for default).
% splitGeneCells : logical
% whether to expand each uniprot.tsv entry whose gene cell holds several
% whitespace-separated gene names into one row per gene name (default
% false). The other columns of the entry (ID, EC number, MW, sequence)
% are repeated on every row, so uniprot.ID then holds an ID once per
% gene name. An empty gene cell stays one row. With false the gene cell
% is kept as one string, and only a model gene that equals the whole
% cell matches the entry.
%
% Returns
% -------
Expand All @@ -23,18 +31,20 @@
% Examples
% --------
% % optional arguments may be given positionally or as name-value pairs:
% databases = loadDatabases('both', adapter);
% databases = loadDatabases('selectDatabase', 'both');
% databases = loadDatabases('both', adapter, true);
% databases = loadDatabases('selectDatabase', 'both', 'splitGeneCells', true);
%
% See also
% --------
% getECfromDatabase, loadBRENDAdata, downloadKEGG, downloadUniProt

p = parseGECKOargs(varargin, { ...
'selectDatabase', 'both'; ...
'modelAdapter', []});
'modelAdapter', []; ...
'splitGeneCells', false});
selectDatabase = p.selectDatabase;
modelAdapter = p.modelAdapter;
splitGeneCells = p.splitGeneCells;

if isempty(modelAdapter)
modelAdapter = ModelAdapterManager.getDefault();
Expand Down Expand Up @@ -80,13 +90,17 @@
databases.uniprot = [];
end
if ~isempty(databases.uniprot)
% Duplicates are counted per file row, before any gene cell is split
[uniqueIDs,uniqueIdx] = unique(databases.uniprot.ID,'stable');
if numel(uniqueIDs) < numel(databases.uniprot.ID)
duplID = setdiff(1:numel(databases.uniprot.ID),uniqueIdx);
error('%s', ravenList(['Duplicate entries are found for the following proteins. '...
'Manually curate the ''uniprot.tsv'' file, or adjust the uniprot parameters '...
'in the model adapter:'],databases.uniprot.ID(duplID)));
end
if splitGeneCells
databases.uniprot = splitUniprotGeneCells(databases.uniprot);
end
end
end

Expand Down Expand Up @@ -116,3 +130,22 @@
end
end
end

function uniprot = splitUniprotGeneCells(uniprot)
% Expand each entry with several whitespace-separated gene names into one row
% per gene name. A cell that is empty or only whitespace stays one row as it is.
geneNames = cell(size(uniprot.genes));
for i = 1:numel(uniprot.genes)
if isempty(strtrim(uniprot.genes{i}))
geneNames{i} = uniprot.genes(i);
else
geneNames{i} = regexp(strtrim(uniprot.genes{i}), '\s+', 'split').';
end
end
rowIdx = repelem((1:numel(geneNames)).', cellfun(@numel, geneNames));
uniprot.ID = uniprot.ID(rowIdx);
uniprot.genes = vertcat(geneNames{:});
uniprot.eccodes = uniprot.eccodes(rowIdx);
uniprot.MW = uniprot.MW(rowIdx);
uniprot.seq = uniprot.seq(rowIdx);
end
19 changes: 10 additions & 9 deletions src/download_databases/resolveKcatAggregation.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
%
% The BRENDA snapshot records both a maximum and a median per
% (EC, substrate, organism) triple. Which one a run uses can be given per
% call, or once on the model adapter as params.kcatAggregation; an
% adapter that sets neither gets 'max', which is what GECKO has always
% used.
% call. Without one, it is [kcat_sources.brenda] aggregation of the kcat
% assignment configuration (kcatAssignmentConfig): the preset's, which is
% 'median' for the default preset brenda_ec_tree and 'max' for
% gecko_classic, or the one that model_adapter.toml sets. A configuration
% in which no stage sets an aggregation for brenda gives 'max'.
%
% Input Arguments
% ---------------
Expand All @@ -25,18 +27,17 @@
% loadBRENDAdata, fuzzyKcatMatching

if isempty(kcatAggregation)
params = modelAdapter.getParameters();
if isfield(params,'kcatAggregation') && ~isempty(params.kcatAggregation)
kcatAggregation = params.kcatAggregation;
else
kcatAggregation = 'max';
config = kcatAssignmentConfig(modelAdapter.getParameters());
kcatAggregation = 'max';
if isfield(config.sources, 'brenda') && isfield(config.sources.brenda, 'aggregation')
kcatAggregation = config.sources.brenda.aggregation;
end
end

if ~(ischar(kcatAggregation) || isstring(kcatAggregation)) || ...
~any(strcmpi(kcatAggregation,{'max','median'}))
error('resolveKcatAggregation:invalidKcatAggregation', ...
'kcatAggregation must be ''max'' or ''median''.')
'aggregation must be max or median')
end
kcatAggregation = lower(char(kcatAggregation));
end
4 changes: 2 additions & 2 deletions src/gather_kcats/collectKcats.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
%
% After the stages:
% - with isozymes, reactions without a kcat take one from their isozymes
% (getKcatAcrossIsozymes);
% (fillKcatsFromIsozymes);
% - with standard, the remaining reactions get the standard kcat
% (getStandardKcat).
%
Expand Down Expand Up @@ -257,7 +257,7 @@

if config.isozymes && ~ecModel.ec.geckoLight
before = ecModel.ec.kcat == 0;
ecModel = getKcatAcrossIsozymes(ecModel);
ecModel = fillKcatsFromIsozymes(ecModel);
stage(before & ecModel.ec.kcat > 0) = {'isozymes'};
end
if config.standard
Expand Down
6 changes: 5 additions & 1 deletion src/gather_kcats/fuzzyKcatMatching.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
% forceWClvl : double
% number of extra levels, from the right, replaced by a wildcard (on top
% of any wildcard already in the code; default 0).
% kcatAggregation : char
% which BRENDA aggregate to read, 'max' or 'median' (default:
% [kcat_sources.brenda] aggregation as resolved from the preset or the
% stages (median for the default preset, max when no stage sets it)).
%
% Returns
% -------
Expand Down Expand Up @@ -102,7 +106,7 @@
'kcatAggregation', [], @(x) assert(isempty(x) || any(strcmpi(x, ...
{'max','median'})), ...
'fuzzyKcatMatching:invalidKcatAggregation', ...
'kcatAggregation must be ''max'' or ''median''.')});
'aggregation must be max or median')});
ecRxns = p.ecRxns;
modelAdapter = p.modelAdapter;
forceWClvl = p.forceWClvl;
Expand Down
12 changes: 8 additions & 4 deletions src/gather_kcats/kcatAssignmentConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,23 @@
end
end
% The okp group: the OKP methods of [kcat_sources.okp] methods.
known = {'CataPro','CatPred','CatRange','DLKcat','EITLEM','KinForm-H','KinForm-L', ...
'OmniESI','OmniESI-O2DENet','TurNup','UniKP'};
% The default: KinForm-H, as the default of params.okp.method.
% The methods kcatsFromOKP accepts: those that predict from one enzyme and
% one substrate (CatPred and TurNup read whole reactions).
known = {'CataPro','CatRange','DLKcat','EITLEM','KinForm-H','KinForm-L', ...
'OmniESI','OmniESI-O2DENet','UniKP'};
% The default: KinForm-H.
config.okpMethods = {'KinForm-H'};
if isfield(config.sources, 'okp') && isfield(config.sources.okp, 'methods') && ~isempty(config.sources.okp.methods)
config.okpMethods = cellstr(config.sources.okp.methods);
config.okpMethods = config.okpMethods(:)';
end
unknown = setdiff(config.okpMethods, known);
unknown = unique(config.okpMethods(~ismember(config.okpMethods, known)), 'stable');
if ~isempty(unknown)
error('kcatAssignment:config', 'Unknown OKP methods in [kcat_sources.okp] methods: %s; methods: %s.', ...
strjoin(unknown, ', '), strjoin(known, ', '))
end
% The file of a method: okp_ and the lower-case method name, with runs of
% characters other than letters and digits replaced by _.
okpFiles = cellfun(@(m) ['okp_' lower(regexprep(regexprep(m, '[^A-Za-z0-9]+', '_'), '^_+|_+$', ''))], ...
config.okpMethods, 'UniformOutput', false);
for s = 1:numel(config.stages)
Expand Down
4 changes: 2 additions & 2 deletions src/gather_kcats/kcatsFromBrenda.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
% --------------------
% aggregation : char
% which BRENDA value per EC number, substrate and organism is used:
% 'max' or 'median' (default: params.kcatAggregation of the model
% adapter, or 'max').
% 'max' or 'median' (default: [kcat_sources.brenda] aggregation as resolved from the preset or the
% stages (median for the default preset, max when no stage sets it)).
% forceWClvl : double
% number of extra levels, from the right, replaced by a wildcard in the
% EC numbers (on top of any wildcard already in the code; default 0).
Expand Down
22 changes: 11 additions & 11 deletions src/gather_kcats/kcatsFromOKP.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
% Name-Value Arguments
% --------------------
% method : char
% OKP method, e.g. 'CataPro', 'CatPred', 'CatRange', 'DLKcat',
% 'EITLEM', 'KinForm-H', 'KinForm-L', 'OmniESI', 'TurNup', 'UniKP'
% (default: params.okp.method of the model adapter, or 'KinForm-H').
% OKP method that predicts from one enzyme and one substrate: 'CataPro',
% 'CatRange', 'DLKcat', 'EITLEM', 'KinForm-H', 'KinForm-L', 'OmniESI',
% 'OmniESI-O2DENet' or 'UniKP' (default: the first entry of
% [kcat_sources.okp] methods of the model adapter, KinForm-H when it
% lists none).
% wait : logical
% wait until the job is done (default false).
% resubmit : logical
Expand Down Expand Up @@ -97,17 +99,16 @@
params = modelAdapter.params;
method = char(p.method);
if isempty(method)
if isfield(params, 'okp') && isfield(params.okp, 'method') && ~isempty(params.okp.method)
method = char(params.okp.method);
else
method = 'KinForm-H';
end
config = kcatAssignmentConfig(params);
method = config.okpMethods{1};
end
if any(strcmp(method, {'CatPred', 'TurNup'}))
error('kcatsFromOKP:method', ['%s reads whole reactions (its substrate set, and products ' ...
'for TurNup); kcatsFromOKP submits enzyme-substrate pairs only.'], method)
end
tag = lower(regexprep(method, '[^A-Za-z0-9]+', '_'));
% The file name of a method: lower case, runs of characters other than
% letters and digits replaced by _ (the same rule as okp_<method> sources).
tag = lower(regexprep(regexprep(method, '[^A-Za-z0-9]+', '_'), '^_+|_+$', ''));
dataDir = fullfile(params.path, 'data');
jobFile = fullfile(dataDir, ['OKP_job_' tag '.txt']);
outFile = fullfile(dataDir, ['OKP_output_' tag '.csv']);
Expand Down Expand Up @@ -272,8 +273,7 @@ function checkOptions(args, names, functionName)
error('ecRxns should be a logical vector with length equal to model.ec.rxns')
end
% Request options: defaults, then params.okp, then the method of this job.
okp = struct('method','KinForm-H', ...
'handleLongSequences','truncate', ...
okp = struct('handleLongSequences','truncate', ...
'includeSimilarityColumns',true,'canonicalizeSubstrates',true);
if isfield(params,'okp')
fn = fieldnames(params.okp);
Expand Down
Loading
Loading