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
40 changes: 18 additions & 22 deletions src/download_databases/loadDatabases.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
% databases that are required to extract protein information. The uniprot.ID
% and kegg.ID are taken from the ModelAdapter.
%
% A gene cell of uniprot.tsv that holds several gene names, separated by
% semicolons and/or whitespace (such as 'YPR080W; YBR118W'), is expanded into
% one row per gene name. 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 an empty gene.
%
% Name-Value Arguments
% --------------------
% selectDatabase : char
Expand All @@ -13,15 +19,6 @@
% 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
% -------
% databases : struct
Expand All @@ -31,20 +28,18 @@
% Examples
% --------
% % optional arguments may be given positionally or as name-value pairs:
% databases = loadDatabases('both', adapter, true);
% databases = loadDatabases('selectDatabase', 'both', 'splitGeneCells', true);
% databases = loadDatabases('both', adapter);
% databases = loadDatabases('selectDatabase', 'both');
%
% See also
% --------
% getECfromDatabase, loadBRENDAdata, downloadKEGG, downloadUniProt

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

if isempty(modelAdapter)
modelAdapter = ModelAdapterManager.getDefault();
Expand Down Expand Up @@ -98,9 +93,7 @@
'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
databases.uniprot = splitUniprotGeneCells(databases.uniprot);
end
end

Expand Down Expand Up @@ -132,14 +125,17 @@
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.
% Expand each entry into one row per gene name, splitting its gene cell on
% semicolons and whitespace and dropping empty pieces. A cell without any gene
% name stays one row with an empty gene.
geneNames = cell(size(uniprot.genes));
for i = 1:numel(uniprot.genes)
if isempty(strtrim(uniprot.genes{i}))
geneNames{i} = uniprot.genes(i);
names = regexp(uniprot.genes{i}, '[;\s]+', 'split');
names = names(~cellfun(@isempty, names));
if isempty(names)
geneNames{i} = {''};
else
geneNames{i} = regexp(strtrim(uniprot.genes{i}), '\s+', 'split').';
geneNames{i} = names(:);
end
end
rowIdx = repelem((1:numel(geneNames)).', cellfun(@numel, geneNames));
Expand Down
24 changes: 11 additions & 13 deletions src/gather_kcats/collectKcats.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
% top_origin_limit = 1
%
% [kcat_sources.okp]
% methods = ["CataPro", "UniKP"] # the okp source group
% method = "UniKP" # the OKP method of the okp source group
%
% A stage sets the kcat of the reactions that are still open:
% - select: the first listed source with a value (see mergeKcats). Sources
% are the names of source files (custom, ec_tree, dlkcat, okp_catapro,
% are the names of source files (custom, ec_tree, dlkcat, okp_unikp,
% ...) and the BRENDA quality tiers database_exact, database_top and
% database_bottom, which read brenda.tsv.
% - combine: all listed sources with a value, each corrected for its bias
Expand All @@ -36,21 +36,21 @@
% sequences). The parameters come with the BRENDA files
% (kcatCombineParams.tsv). model.ec.source reads 'combined (sd=<log10
% sd>, n=<sources>)'; sd is the uncertainty for a new measurement.
% In both, okp stands for the OKP methods of [kcat_sources.okp] methods
% (default: KinForm-H).
% In both, okp stands for the file of the OKP method of [kcat_sources.okp]
% method (default: KinForm-H).
%
% The presets:
% - brenda_ec_tree (the default): custom kcats, the BRENDA median of
% measurements of the organism on the reaction's substrate (origin 1,
% without EC wildcards), the EC tree (kcatsFromECTree); then the OKP
% methods combined for the reactions left (without an EC number).
% predictions for the reactions left (without an EC number).
% - ec_tree_homologs: custom kcats, the organism's own BRENDA value; then
% the EC tree and homologs (kcatsFromHomologs) combined; then the OKP
% methods combined.
% predictions.
% - ec_tree_okp: custom kcats, the organism's own BRENDA value; then the EC
% tree, homologs and the OKP methods combined; then the OKP methods
% combined.
% - okp: custom kcats; then the OKP methods combined.
% tree, homologs and the OKP predictions combined; then the OKP
% predictions.
% - okp: custom kcats; then the OKP predictions.
% - gecko_median: custom kcats, the BRENDA median of matches without EC
% wildcards from the organism or other organisms, with or without the
% substrate (origin 1 to 4), DLKcat, then the other BRENDA matches (EC
Expand All @@ -60,10 +60,8 @@
% tutorial.
% Against measured kcats hidden from the search, the EC tree was closer
% than the BRENDA median at origins 2 and 4 and with EC wildcards and as
% close at origins 1 and 3; the EC tree combined with eight OKP methods
% (CataPro, DLKcat, EITLEM, KinForm-H, KinForm-L, OmniESI, OmniESI-O2DENet
% and UniKP) was slightly closer than the EC tree, and these eight methods
% combined as close. The default okp source group is KinForm-H alone.
% close at origins 1 and 3; the EC tree combined with OKP predictions was
% slightly closer than the EC tree. The default OKP method is KinForm-H.
% In ecModels, values combined with predictions set high-turnover enzymes
% such as ATP synthase too low, which is why the default uses predictions
% only where there is no value from measurements. The BRENDA aggregation is
Expand Down
28 changes: 16 additions & 12 deletions src/gather_kcats/kcatAssignmentConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
% - isozymes, standard: logical;
% - stages: struct array with action ('select' or 'combine'), sources
% (cell, as given), files (the source files they read, with okp
% replaced by the files of its methods), criteria, topOriginLimit,
% replaced by the file of the OKP method), criteria, topOriginLimit,
% bottomOriginLimit and wildcardLimit;
% - okpMethods: the OKP methods of the okp source group ([kcat_sources.okp]
% methods; default {'KinForm-H'});
% - okpMethod: the OKP method of the okp source group ([kcat_sources.okp]
% method; default {'KinForm-H'});
% - sources: per source name its options: those of the preset, with
% the keys that a [kcat_sources.<name>] table sets taking their value
% from that table.
Expand Down Expand Up @@ -80,26 +80,30 @@
end
end
end
% The okp group: the OKP methods of [kcat_sources.okp] methods.
% The okp group: the OKP method of [kcat_sources.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(:)';
config.okpMethod = {'KinForm-H'};
if isfield(config.sources, 'okp') && isfield(config.sources.okp, 'method') && ~isempty(config.sources.okp.method)
given = config.sources.okp.method;
if ~(ischar(given) || (iscell(given) && all(cellfun(@ischar, given))))
error('kcatAssignment:config', 'kcat_sources.okp.method must be a string');
end
config.okpMethod = cellstr(given);
config.okpMethod = config.okpMethod(:)';
end
unknown = unique(config.okpMethods(~ismember(config.okpMethods, known)), 'stable');
unknown = unique(config.okpMethod(~ismember(config.okpMethod, known)), 'stable');
if ~isempty(unknown)
error('kcatAssignment:config', 'Unknown OKP methods in [kcat_sources.okp] methods: %s; methods: %s.', ...
error('kcatAssignment:config', 'Unknown OKP method %s in [kcat_sources.okp] method; supported: %s', ...
strjoin(unknown, ', '), strjoin(known, ', '))
end
% The file of a method: okp_ and the lower-case method name, with runs of
% The file of the 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);
config.okpMethod, 'UniformOutput', false);
for s = 1:numel(config.stages)
files = {};
for t = config.stages(s).sources
Expand Down
14 changes: 6 additions & 8 deletions src/gather_kcats/kcatsFromOKP.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
% - with a job, it fetches the result. When the job is done the file is
% written; otherwise it reports the job's status and writes nothing.
%
% Each method keeps its own job in data/OKP_job_<method>.txt and its own
% result in data/OKP_output_<method>.csv, so jobs of several methods can
% run at the same time. The job file records which job the stored result
% came from; useStored only uses a result of the current job.
% The job of a method is kept in data/OKP_job_<method>.txt and its result
% in data/OKP_output_<method>.csv. The job file records which job the stored
% result came from; useStored only uses a result of the current job.
%
% An API key is needed. Keys are free: open
% https://predictor.openkinetics.org/api-docs, click "Generate" in the "API
Expand All @@ -34,9 +33,8 @@
% method : char
% 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).
% 'OmniESI-O2DENet' or 'UniKP' (default: [kcat_sources.okp] method of
% the model adapter, KinForm-H when it sets none).
% wait : logical
% wait until the job is done (default false).
% resubmit : logical
Expand Down Expand Up @@ -100,7 +98,7 @@
method = char(p.method);
if isempty(method)
config = kcatAssignmentConfig(params);
method = config.okpMethods{1};
method = config.okpMethod{1};
end
if any(strcmp(method, {'CatPred', 'TurNup'}))
error('kcatsFromOKP:method', ['%s reads whole reactions (its substrate set, and products ' ...
Expand Down
4 changes: 2 additions & 2 deletions src/gather_kcats/updateKcatSources.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
% aggregation = "median"
%
% [kcat_sources.okp]
% methods = ["CataPro", "KinForm-H"]
% method = "KinForm-H"
%
% The keys that a [kcat_sources.<name>] table can set are aggregation and
% force_wildcard_level for brenda, k for ec_tree, k, min_identity and
% coverage for homologs, and methods for okp; the okp_<method> files
% coverage for homologs, and method for okp; the okp_<method> files
% have none (their method is the one whose file name they carry).
%
% Parameters
Expand Down
13 changes: 3 additions & 10 deletions src/get_enzyme_data/getECfromDatabase.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@
% Any other action raises getECfromDatabase:unsupportedAction.
% modelAdapter : ModelAdapter
% a loaded model adapter (default: the current default model adapter).
% splitGeneCells : logical
% passed to loadDatabases: whether a gene cell of uniprot.tsv with
% several whitespace-separated gene names is expanded into one database
% row per gene name, so each name matches (default false).
%
% Returns
% -------
% model : struct
Expand All @@ -45,7 +40,7 @@
% Examples
% --------
% % optional arguments may be given positionally or as name-value pairs:
% model = getECfromDatabase(model, ecRxns, action, modelAdapter, splitGeneCells);
% model = getECfromDatabase(model, ecRxns, action, modelAdapter);
% model = getECfromDatabase(model, 'action', 'ignore');
%
% See also
Expand All @@ -55,12 +50,10 @@
p = parseGECKOargs(varargin, { ...
'ecRxns', []; ...
'action', 'display'; ...
'modelAdapter', []; ...
'splitGeneCells', false});
'modelAdapter', []});
ecRxns = p.ecRxns;
action = p.action;
modelAdapter = p.modelAdapter;
splitGeneCells = p.splitGeneCells;

if ~(ischar(action) && any(strcmpi(action,{'display','ignore'})))
error('getECfromDatabase:unsupportedAction', ...
Expand All @@ -82,7 +75,7 @@
rxnEnzMat = model.ec.rxnEnzMat;
genes = modelAdapter.getUniprotCompatibleGenes(model.ec.genes);

data = loadDatabases('both', modelAdapter, splitGeneCells);
data = loadDatabases('both', modelAdapter);
uniprot = data.uniprot;
kegg = data.kegg;

Expand Down
2 changes: 1 addition & 1 deletion src/model_adapter/adapterParameters.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ kcat_assignment.preset Kcat assignment preset: brenda_ec_tree (used when neith
kcat_assignment.isozymes true Fill reactions without a kcat from their isozymes after the stages
kcat_assignment.standard true Give the remaining reactions the standard kcat
kcat_assignment.stage Stages instead of a preset: action (select or combine), sources, criteria and BRENDA limits ([[kcat_assignment.stage]])
kcat_sources Settings per kcat source file: [kcat_sources.brenda] aggregation and force_wildcard_level, [kcat_sources.ec_tree] k, [kcat_sources.homologs] k, min_identity and coverage, [kcat_sources.okp] methods (the OKP methods of the okp source group; default KinForm-H)
kcat_sources Settings per kcat source file: [kcat_sources.brenda] aggregation and force_wildcard_level, [kcat_sources.ec_tree] k, [kcat_sources.homologs] k, min_identity and coverage, [kcat_sources.okp] method (the OKP method of the okp source group; default KinForm-H)
matlab.make_model_anaerobic matlab.makeModelAnaerobic MATLAB function that constrains the ecModel to anaerobic growth
matlab.change_protein_biomass matlab.changeProteinBiomass MATLAB function that changes the protein content of the biomass
16 changes: 8 additions & 8 deletions src/model_adapter/adapterTemplate.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ max_generations = 150
# - brenda_ec_tree: custom kcats, the BRENDA median of measurements of the
# organism on the reaction's substrate, the EC tree (the EC's median kcat,
# leaning on its EC class when it has few measurements); then the
# OpenKineticsPredictor (OKP) methods combined for reactions without an
# EC number.
# OpenKineticsPredictor (OKP) predictions combined for reactions without
# an EC number.
# - ec_tree_homologs: custom kcats, the organism's own BRENDA value, then the
# EC tree and the kcats of homologous enzymes combined, then the OKP
# methods combined.
# predictions.
# - ec_tree_okp: custom kcats, the organism's own BRENDA value, then the EC
# tree, the kcats of homologous enzymes and the OKP methods combined.
# - okp: custom kcats, then the OKP methods combined.
# tree, the kcats of homologous enzymes and the OKP predictions combined.
# - okp: custom kcats, then the OKP predictions.
# - gecko_median and gecko_classic: BRENDA's fuzzy matches and DLKcat, with
# the BRENDA median and maximum.
[kcat_assignment]
Expand All @@ -131,13 +131,13 @@ standard = true

# Settings per kcat source, used by updateKcatSources: aggregation
# ("max" or "median") and force_wildcard_level for brenda, k for ec_tree,
# k, min_identity and coverage for homologs, and methods for okp, the OKP
# methods the presets combine (default: KinForm-H). The BRENDA aggregation
# k, min_identity and coverage for homologs, and method for okp, the OKP
# method of the presets (default: KinForm-H). The BRENDA aggregation
# of the preset is median, or max for gecko_classic.
# [kcat_sources.brenda]
# aggregation = "median"
# [kcat_sources.okp]
# methods = ["CataPro", "KinForm-H", "UniKP"]
# method = "KinForm-H"

# Read by GECKO only. Names of MATLAB functions, for instance in the code
# folder, used during kcat tuning: one that constrains the ecModel to
Expand Down
28 changes: 16 additions & 12 deletions src/model_adapter/loadAdapterParams.m
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function checkNested(data, tomlFile)
% reads for each; dlkcat, custom and the okp_<method> files take none.
allowed = struct('brenda', {{'aggregation', 'force_wildcard_level'}}, ...
'ec_tree', {{'k'}}, 'homologs', {{'k', 'min_identity', 'coverage'}}, ...
'okp', {{'methods'}}, 'dlkcat', {{}}, 'custom', {{}});
'okp', {{'method'}}, 'dlkcat', {{}}, 'custom', {{}});
names = fieldnames(data.kcat_sources);
for k = 1:numel(names)
if isfield(allowed, names{k})
Expand All @@ -232,35 +232,39 @@ function checkNested(data, tomlFile)
error('GECKO:loadAdapterParams', ...
'%s: kcat_sources.brenda.aggregation must be max or median', tomlFile);
end
if strcmp(names{k}, 'okp') && isfield(source, 'methods')
checkOkpMethods(source.methods, tomlFile);
if strcmp(names{k}, 'okp') && isfield(source, 'method')
checkOkpMethod(source.method, tomlFile);
end
end
end
end

function checkOkpMethods(methods, tomlFile)
% [kcat_sources.okp] methods: a list of the OKP methods that kcatsFromOKP accepts.
if ~(iscell(methods) && all(cellfun(@ischar, methods)))
error('GECKO:loadAdapterParams', '%s: kcat_sources.okp.methods must be a list of strings', tomlFile);
function checkOkpMethod(method, tomlFile)
% [kcat_sources.okp] method: an OKP method that kcatsFromOKP accepts.
if ischar(method)
names = {method};
elseif iscell(method) && ~isempty(method) && all(cellfun(@ischar, method))
names = method(:)';
else
error('GECKO:loadAdapterParams', '%s: kcat_sources.okp.method must be a string', tomlFile);
end
known = okpMethodNames();
unknown = unique(methods(~ismember(methods, known)), 'stable');
unknown = unique(names(~ismember(names, known)), 'stable');
if ~isempty(unknown)
error('kcatAssignment:config', 'Unknown OKP methods in [kcat_sources.okp] methods: %s; methods: %s.', ...
error('kcatAssignment:config', 'Unknown OKP method %s in [kcat_sources.okp] method; supported: %s', ...
strjoin(unknown, ', '), strjoin(known, ', '))
end
end

function known = okpMethodNames()
% The methods that predict from one enzyme and one substrate (CatPred and
% TurNup read whole reactions).
% The OKP methods 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'};
end

function files = okpFileNames()
% The files of the OKP methods that kcatsFromOKP accepts: okp_ and the
% The file of each OKP method that kcatsFromOKP accepts: okp_ and the
% lower-case method name, with runs of characters other than letters and
% digits replaced by _.
known = okpMethodNames();
Expand Down
Loading
Loading