diff --git a/src/download_databases/loadDatabases.m b/src/download_databases/loadDatabases.m index ecf448c5..9abdf6ea 100644 --- a/src/download_databases/loadDatabases.m +++ b/src/download_databases/loadDatabases.m @@ -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 @@ -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 @@ -31,8 +28,8 @@ % 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 % -------- @@ -40,11 +37,9 @@ p = parseGECKOargs(varargin, { ... 'selectDatabase', 'both'; ... - 'modelAdapter', []; ... - 'splitGeneCells', false}); + 'modelAdapter', []}); selectDatabase = p.selectDatabase; modelAdapter = p.modelAdapter; -splitGeneCells = p.splitGeneCells; if isempty(modelAdapter) modelAdapter = ModelAdapterManager.getDefault(); @@ -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 @@ -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)); diff --git a/src/gather_kcats/collectKcats.m b/src/gather_kcats/collectKcats.m index d000ae54..ce46269a 100644 --- a/src/gather_kcats/collectKcats.m +++ b/src/gather_kcats/collectKcats.m @@ -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 @@ -36,21 +36,21 @@ % sequences). The parameters come with the BRENDA files % (kcatCombineParams.tsv). model.ec.source reads 'combined (sd=, n=)'; 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 @@ -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 diff --git a/src/gather_kcats/kcatAssignmentConfig.m b/src/gather_kcats/kcatAssignmentConfig.m index a27371d3..a81a3c77 100644 --- a/src/gather_kcats/kcatAssignmentConfig.m +++ b/src/gather_kcats/kcatAssignmentConfig.m @@ -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.] table sets taking their value % from that table. @@ -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 diff --git a/src/gather_kcats/kcatsFromOKP.m b/src/gather_kcats/kcatsFromOKP.m index 4fbe09e5..bca5248e 100644 --- a/src/gather_kcats/kcatsFromOKP.m +++ b/src/gather_kcats/kcatsFromOKP.m @@ -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_.txt and its own -% result in data/OKP_output_.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_.txt and its result +% in data/OKP_output_.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 @@ -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 @@ -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 ' ... diff --git a/src/gather_kcats/updateKcatSources.m b/src/gather_kcats/updateKcatSources.m index 52ca8ff7..8ca1d4b3 100644 --- a/src/gather_kcats/updateKcatSources.m +++ b/src/gather_kcats/updateKcatSources.m @@ -25,11 +25,11 @@ % aggregation = "median" % % [kcat_sources.okp] -% methods = ["CataPro", "KinForm-H"] +% method = "KinForm-H" % % The keys that a [kcat_sources.] 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_ files +% coverage for homologs, and method for okp; the okp_ files % have none (their method is the one whose file name they carry). % % Parameters diff --git a/src/get_enzyme_data/getECfromDatabase.m b/src/get_enzyme_data/getECfromDatabase.m index a2b9bbdf..2c6a1981 100644 --- a/src/get_enzyme_data/getECfromDatabase.m +++ b/src/get_enzyme_data/getECfromDatabase.m @@ -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 @@ -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 @@ -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', ... @@ -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; diff --git a/src/model_adapter/adapterParameters.tsv b/src/model_adapter/adapterParameters.tsv index 6b9f29b7..575796d6 100644 --- a/src/model_adapter/adapterParameters.tsv +++ b/src/model_adapter/adapterParameters.tsv @@ -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 diff --git a/src/model_adapter/adapterTemplate.toml b/src/model_adapter/adapterTemplate.toml index 761e3d67..35c759f4 100644 --- a/src/model_adapter/adapterTemplate.toml +++ b/src/model_adapter/adapterTemplate.toml @@ -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] @@ -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 diff --git a/src/model_adapter/loadAdapterParams.m b/src/model_adapter/loadAdapterParams.m index bdccdd37..1fa3905e 100644 --- a/src/model_adapter/loadAdapterParams.m +++ b/src/model_adapter/loadAdapterParams.m @@ -212,7 +212,7 @@ function checkNested(data, tomlFile) % reads for each; dlkcat, custom and the okp_ 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}) @@ -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(); diff --git a/src/model_adapter/showAdapterParams.m b/src/model_adapter/showAdapterParams.m index 06f65040..bff368fa 100644 --- a/src/model_adapter/showAdapterParams.m +++ b/src/model_adapter/showAdapterParams.m @@ -124,8 +124,8 @@ function add(k, v, o) end case 'kcat_sources' sources = config.sources; - if ~(isfield(sources, 'okp') && isfield(sources.okp, 'methods')) - sources.okp.methods = config.okpMethods; + if ~(isfield(sources, 'okp') && isfield(sources.okp, 'method')) + sources.okp.method = config.okpMethod; end % brenda, ec_tree, homologs and okp first, other sources and the % keys of each source alphabetically @@ -140,7 +140,7 @@ function add(k, v, o) o = fromPreset; if given o = 'file'; - elseif strcmp(names{j}, 'okp') && strcmp(keys{i}, 'methods') + elseif strcmp(names{j}, 'okp') && strcmp(keys{i}, 'method') o = 'default'; end add(sprintf('%s.%s.%s', tomlKey, names{j}, keys{i}), ... diff --git a/test/unit_tests/adapterTomlTests.m b/test/unit_tests/adapterTomlTests.m index 683508bd..bd825743 100644 --- a/test/unit_tests/adapterTomlTests.m +++ b/test/unit_tests/adapterTomlTests.m @@ -243,7 +243,7 @@ function testUnknownKeys_tc0732(testCase) {'[kcat_sources.brenda]', 'aggregate = "max"'}, 'kcat_sources.brenda.aggregate'; ... {'[kcat_sources.ec_tree]', 'min_identity = 40'}, 'kcat_sources.ec_tree.min_identity'; ... {'[kcat_sources.okp_kinform_h]', 'method = "KinForm-H"'}, 'kcat_sources.okp_kinform_h.method'; ... - {'[kcat_sources.okp]', 'method = "KinForm-H"'}, 'kcat_sources.okp.method'; ... + {'[kcat_sources.okp]', 'methods = "KinForm-H"'}, 'kcat_sources.okp.methods'; ... {'[kcat_sources.foo]'}, 'kcat_sources.foo'; ... {'[kcat_sources.okp_nosuchmethod]'}, 'kcat_sources.okp_nosuchmethod'; ... {'[kcat_sources.dlkcat]', 'k = 1'}, 'kcat_sources.dlkcat.k'}; @@ -268,7 +268,7 @@ function testUnknownKeys_tc0732(testCase) writeTemp([base, {'[kcat_sources.dlkcat]', '[kcat_sources.okp_unikp]', '[kcat_sources.custom]', ... '[kcat_sources.brenda]', 'aggregation = "max"', 'force_wildcard_level = 1', ... '[kcat_sources.homologs]', 'k = 3', 'min_identity = 40', 'coverage = 0.5', ... - '[kcat_sources.okp]', 'methods = ["UniKP"]'}], fullfile(folder, 'model_adapter.toml')); + '[kcat_sources.okp]', 'method = "UniKP"'}], fullfile(folder, 'model_adapter.toml')); params = loadAdapterParams(folder); verifyEqual(testCase, params.kcat_sources.brenda.aggregation, 'max') end @@ -403,7 +403,7 @@ function testBrendaDirectCallsUsePresetAggregation_tc0743(testCase) end function testKcatsFromOKPDefaultMethod_tc0737(testCase) - % Without a method, kcatsFromOKP uses the first of [kcat_sources.okp] methods. + % Without a method, kcatsFromOKP uses [kcat_sources.okp] method. adapter = ModelAdapterManager.getAdapter(fullfile(findGECKOroot,'test','unit_tests','ecTestGEM', 'TestGEMAdapter.m')); scratchDir = tempname; mkdir(fullfile(scratchDir, 'data')); @@ -417,7 +417,7 @@ function testKcatsFromOKPDefaultMethod_tc0737(testCase) end verifyEqual(testCase, err.identifier, 'kcatsFromOKP:noStored') verifySubstring(testCase, err.message, 'KinForm-H') - adapter.params.kcat_sources.okp.methods = {'UniKP', 'CataPro'}; + adapter.params.kcat_sources.okp.method = 'UniKP'; try kcatsFromOKP(ecModel, 'useStored', true, 'save', false, 'modelAdapter', adapter); err = []; @@ -427,20 +427,20 @@ function testKcatsFromOKPDefaultMethod_tc0737(testCase) verifySubstring(testCase, err.message, 'UniKP') end -function testOkpMethodsAndFiles_tc0738(testCase) - % CatPred and TurNup are not accepted in [kcat_sources.okp] methods, and +function testOkpMethodAndFiles_tc0738(testCase) + % CatPred and TurNup are not accepted as [kcat_sources.okp] method, and % an okp_ file that is no known method's file fails naming the file. verifyError(testCase, @() kcatAssignmentConfig(struct('kcat_sources', ... - struct('okp', struct('methods', {{'CatPred'}})))), 'kcatAssignment:config') + struct('okp', struct('method', 'CatPred')))), 'kcatAssignment:config') known = 'CataPro, CatRange, DLKcat, EITLEM, KinForm-H, KinForm-L, OmniESI, OmniESI-O2DENet, UniKP'; try - kcatAssignmentConfig(struct('kcat_sources', struct('okp', struct('methods', {{'Zed', 'UniKP', 'Zed', 'Abc'}})))); + kcatAssignmentConfig(struct('kcat_sources', struct('okp', struct('method', 'Zed')))); err = []; catch err end - verifyEqual(testCase, err.message, ['Unknown OKP methods in [kcat_sources.okp] methods: Zed, Abc; methods: ' known '.']) + verifyEqual(testCase, err.message, ['Unknown OKP method Zed in [kcat_sources.okp] method; supported: ' known]) verifyError(testCase, @() kcatAssignmentConfig(struct('kcat_sources', ... - struct('okp', struct('methods', {{'TurNup'}})))), 'kcatAssignment:config') + struct('okp', struct('method', 'TurNup')))), 'kcatAssignment:config') folder = tempname; mkdir(folder); cleanupDir = onCleanup(@() rmdir(folder, 's')); writeTemp({'conv_gem = "x.xml"', 'org_name = "x"', '[[kcat_assignment.stage]]', ... @@ -454,15 +454,14 @@ function testOkpMethodsAndFiles_tc0738(testCase) 'okp_omniesi_o2denet, okp_unikp.']) end -function testOkpMethodsAtLoad_tc0744(testCase) - % The methods are checked when the file is read. +function testOkpMethodAtLoad_tc0744(testCase) + % The method is checked when the file is read. base = {'conv_gem = "x.xml"', 'org_name = "x"', '[kcat_sources.okp]'}; known = 'CataPro, CatRange, DLKcat, EITLEM, KinForm-H, KinForm-L, OmniESI, OmniESI-O2DENet, UniKP'; cases = { ... - {'methods = "KinForm-H"'}, 'kcat_sources.okp.methods must be a list of strings'; ... - {'methods = [1, 2]'}, 'kcat_sources.okp.methods must be a list of strings'; ... - {'methods = ["Zed", "UniKP", "Zed", "CatPred"]'}, ... - ['Unknown OKP methods in [kcat_sources.okp] methods: Zed, CatPred; methods: ' known '.']}; + {'method = 1'}, 'kcat_sources.okp.method must be a string'; ... + {'method = [1, 2]'}, 'kcat_sources.okp.method must be a string'; ... + {'method = "CatPred"'}, ['Unknown OKP method CatPred in [kcat_sources.okp] method; supported: ' known]}; for k = 1:size(cases, 1) folder = tempname; mkdir(folder); file = fullfile(folder, 'model_adapter.toml'); @@ -566,7 +565,7 @@ function testShowAdapterParamsOrder_tc0747(testCase) sourceLines = lines(startsWith(lines, 'kcat_sources.')); verifyEqual(testCase, cellfun(@(l) l(1:find(l == ' ', 1)-1), sourceLines, 'UniformOutput', false), ... {'kcat_sources.brenda.aggregation'; 'kcat_sources.ec_tree.k'; 'kcat_sources.homologs.coverage'; ... - 'kcat_sources.homologs.k'; 'kcat_sources.homologs.min_identity'; 'kcat_sources.okp.methods'}) + 'kcat_sources.homologs.k'; 'kcat_sources.homologs.min_identity'; 'kcat_sources.okp.method'}) end function testGrExpNotSet_tc0739(testCase) @@ -608,7 +607,7 @@ function testShowAdapterParams_tc0740(testCase) cleanupDir = onCleanup(@() rmdir(folder, 's')); writeTemp({'conv_gem = "x.xml"', 'org_name = "x"', 'p_tot = 0.4', ... '[kcat_assignment]', 'preset = "gecko_classic"', ... - '[kcat_sources.okp]', 'methods = ["UniKP", "CataPro"]'}, fullfile(folder, 'model_adapter.toml')); + '[kcat_sources.okp]', 'method = "UniKP"'}, fullfile(folder, 'model_adapter.toml')); lines = splitlines(strtrim(evalc('showAdapterParams(ModelAdapterManager.getAdapter(folder))'))); verifyTrue(testCase, ismember('p_tot = 0.4 [file]', lines)) verifyTrue(testCase, ismember('sigma = 0.5 [default]', lines)) @@ -620,7 +619,7 @@ function testShowAdapterParams_tc0740(testCase) verifyTrue(testCase, ismember(['kcat_assignment.stage[1] = select: custom, database_top, dlkcat, database_bottom; ' ... 'top_origin_limit=6 [preset gecko_classic]'], lines)) verifyTrue(testCase, ismember('kcat_sources.brenda.aggregation = max [preset gecko_classic]', lines)) - verifyTrue(testCase, ismember('kcat_sources.okp.methods = UniKP, CataPro [file]', lines)) + verifyTrue(testCase, ismember('kcat_sources.okp.method = UniKP [file]', lines)) verifyTrue(testCase, ismember('evotune.source_groups.custom = custom; sigma0_log 0.1 [default]', lines)) verifyTrue(testCase, ismember('evotune.source_groups.combined = combined; sigma0_log 0.4 [default]', lines)) % Integer-valued numbers print whole, other numbers with %g. diff --git a/test/unit_tests/combineTests.m b/test/unit_tests/combineTests.m index 64cd4b62..aa2c1083 100644 --- a/test/unit_tests/combineTests.m +++ b/test/unit_tests/combineTests.m @@ -6,24 +6,33 @@ end function testOkpPresetCombines_tc0088(testCase) - % CataPro 100 /s (similarity 30: bin <40, bias 0.2, variance 2) and - % UniKP 10 /s (similarity 50: bin 40-60, bias -0.3, variance 1): - % (1.8 * 0.5 + 1.3 * 1) / 1.5; sd sqrt(1/1.5 + 0.25) with the okp scale - % 1. geckopy's test_okp_presets has the same numbers. + % CataPro 100 /s (similarity 30: bin <40, bias 0.2, variance 2): the + % corrected value is 1.8; sd sqrt(1/0.5 + 0.25) with the okp scale 1. + % geckopy's test_okp_presets has the same numbers. [model, adapter, rxns] = buildProject('okp'); report = updateKcatSources(model, 'dryRun', true, 'modelAdapter', adapter); + verifyEqual(testCase, report.source', {'custom', 'okp_catapro'}) + saveKcatSource(model, okpList(rxns(1:3), 100, 30, 'CataPro'), 'okp_catapro', 'modelAdapter', adapter); + decisions = collectKcats(model, 'modelAdapter', adapter, 'writeReport', false); + i = find(strcmp(decisions.ecRxn, rxns{1})); + verifyEqual(testCase, decisions.kcat(i), 10 ^ 1.8, 'RelTol', 1e-12) + verifyEqual(testCase, decisions.stage{i}, '2') + verifyEqual(testCase, decisions.sdLog10(i), sqrt(1/0.5 + 0.25), 'AbsTol', 1e-12) +end + +function testOkpMethodValueForms_tc0088(testCase) + [model, adapter, rxns] = buildProject('okp'); + adapter.params.kcat_sources.okp.method = {'CataPro', 'UniKP'}; + report = updateKcatSources(model, 'dryRun', true, 'modelAdapter', adapter); verifyEqual(testCase, report.source', {'custom', 'okp_catapro', 'okp_unikp'}) saveKcatSource(model, okpList(rxns(1:3), 100, 30, 'CataPro'), 'okp_catapro', 'modelAdapter', adapter); saveKcatSource(model, okpList(rxns(1), 10, 50, 'UniKP'), 'okp_unikp', 'modelAdapter', adapter); decisions = collectKcats(model, 'modelAdapter', adapter, 'writeReport', false); i = find(strcmp(decisions.ecRxn, rxns{1})); verifyEqual(testCase, decisions.kcat(i), 10 ^ ((1.8 * 0.5 + 1.3) / 1.5), 'RelTol', 1e-12) - verifyEqual(testCase, decisions.source{i}, sprintf('combined (sd=%.2f, n=2)', sqrt(1/1.5 + 0.25))) - verifyEqual(testCase, decisions.stage{i}, '2') verifyEqual(testCase, decisions.candidates(i), 2) - verifyEqual(testCase, decisions.sdLog10(i), sqrt(1/1.5 + 0.25), 'AbsTol', 1e-12) - j = find(strcmp(decisions.ecRxn, rxns{2})); - verifyEqual(testCase, decisions.kcat(j), 10 ^ 1.8, 'RelTol', 1e-12) + shown = evalc('showAdapterParams(adapter)'); + verifySubstring(testCase, shown, 'kcat_sources.okp.method = CataPro, UniKP') end function testEcTreeOkpPreset_tc0089(testCase) @@ -60,11 +69,11 @@ function testExactHomologDominates_tc0098(testCase) function testCombineErrors_tc0090(testCase) % An OKP method without combination parameters, and an unknown method. [model, adapter, rxns] = buildProject('okp'); - adapter.params.kcat_sources.okp.methods = {'EITLEM'}; + adapter.params.kcat_sources.okp.method = 'EITLEM'; saveKcatSource(model, okpList(rxns(1), 100, 30, 'EITLEM'), 'okp_eitlem', 'modelAdapter', adapter); verifyError(testCase, @() collectKcats(model, 'modelAdapter', adapter, 'writeReport', false), ... 'collectKcats:combine') - adapter.params.kcat_sources.okp.methods = {'CataPro', 'NoSuchMethod'}; + adapter.params.kcat_sources.okp.method = 'NoSuchMethod'; verifyError(testCase, @() kcatAssignmentConfig(adapter.params), 'kcatAssignment:config') end @@ -83,7 +92,7 @@ function testCombineErrors_tc0090(testCase) delete(fullfile(project, 'data', 'customKcats.tsv')); adapter.params.path = project; adapter.params.kcat_assignment = struct('preset', preset); - adapter.params.kcat_sources = struct('okp', struct('methods', {{'CataPro', 'UniKP'}})); + adapter.params.kcat_sources = struct('okp', struct('method', 'CataPro')); % TestGEMAdapter's BRENDA folder is the project's data folder. fid = fopen(fullfile(project, 'data', 'kcatCombineParams.tsv'), 'w'); fprintf(fid, ['# Combination parameters for tests\n# measurement_sd: 0.5\n# min_variance: 0.01\n' ... diff --git a/test/unit_tests/ecFromDatabaseConflictTests.m b/test/unit_tests/ecFromDatabaseConflictTests.m index e3e7ec91..90005fb9 100644 --- a/test/unit_tests/ecFromDatabaseConflictTests.m +++ b/test/unit_tests/ecFromDatabaseConflictTests.m @@ -64,39 +64,40 @@ function testGetECfromDatabaseRejectsUnsupportedAction_tc0409(testCase) verifyError(testCase, @() getECfromDatabase(ecModel, [], 'other', adapter), 'getECfromDatabase:unsupportedAction') end -function testLoadDatabasesSplitGeneCells_tc0734(testCase) - % A gene cell with several names is one row by default and one row per - % name with splitGeneCells; an empty cell stays one row, and a repeated - % ID across file rows is still a duplicate. +function testLoadDatabasesSplitsGeneCells_tc0748(testCase) + % A gene cell with several names is one row per name, whatever separates + % them; an empty cell stays one row, and a repeated ID across file rows is + % still a duplicate. [~, adapter] = conflictModel(testCase); file = fullfile(adapter.params.path, 'data', 'uniprot.tsv'); + before = loadDatabases('uniprot', adapter); fid = fopen(file, 'a'); fprintf(fid, 'P7\tG7 G8\tx\t70000\tMKAL\nP8\t\ty\t80000\tMNTD\n'); + fprintf(fid, 'P9\tG9; G10;G11\tz\t90000\tMSYN\nP10\t ; \tw\t10000\tMAAA\n'); fclose(fid); - off = loadDatabases('uniprot', adapter); - on = loadDatabases('uniprot', adapter, true); - verifyEqual(testCase, loadDatabases('uniprot', adapter, false), off) - verifyEqual(testCase, off.uniprot.genes(strcmp(off.uniprot.ID, 'P7')), {'G7 G8'}) - i = strcmp(on.uniprot.ID, 'P7'); - verifyEqual(testCase, on.uniprot.genes(i), {'G7';'G8'}) - verifyEqual(testCase, on.uniprot.eccodes(i), {'x';'x'}) - verifyEqual(testCase, on.uniprot.MW(i), [70000;70000]) - verifyEqual(testCase, on.uniprot.seq(i), {'MKAL';'MKAL'}) - verifyEqual(testCase, on.uniprot.genes(strcmp(on.uniprot.ID, 'P8')), {''}) - verifyEqual(testCase, numel(on.uniprot.ID), numel(off.uniprot.ID) + 1) + db = loadDatabases('uniprot', adapter); + i = strcmp(db.uniprot.ID, 'P7'); + verifyEqual(testCase, db.uniprot.genes(i), {'G7';'G8'}) + verifyEqual(testCase, db.uniprot.eccodes(i), {'x';'x'}) + verifyEqual(testCase, db.uniprot.MW(i), [70000;70000]) + verifyEqual(testCase, db.uniprot.seq(i), {'MKAL';'MKAL'}) + verifyEqual(testCase, db.uniprot.genes(strcmp(db.uniprot.ID, 'P9')), {'G9';'G10';'G11'}) + verifyEqual(testCase, db.uniprot.genes(strcmp(db.uniprot.ID, 'P8')), {''}) + verifyEqual(testCase, db.uniprot.genes(strcmp(db.uniprot.ID, 'P10')), {''}) + verifyEqual(testCase, numel(db.uniprot.ID), numel(before.uniprot.ID) + 2 + 3 + 1 + 1) fid = fopen(file, 'a'); - fprintf(fid, 'P7\tG9\tz\t90000\tMSYN\n'); + fprintf(fid, 'P7\tG12\tz\t90000\tMSYN\n'); fclose(fid); - verifyError(testCase, @() loadDatabases('uniprot', adapter, true), ?MException) + verifyError(testCase, @() loadDatabases('uniprot', adapter), ?MException) end -function testGetECfromDatabaseSplitGeneCells_tc0735(testCase) - % With the default, a model gene that is one of several names in a gene - % cell finds no UniProt entry; with splitGeneCells it does. +function testGetECfromDatabaseMatchesSecondGeneName_tc0749(testCase) + % A model gene that is the second name in a gene cell finds its UniProt + % entry; before, only a gene equal to the whole cell matched. [ecModel, adapter] = conflictModel(testCase); file = fullfile(adapter.params.path, 'data', 'uniprot.tsv'); txt = fileread(file); - txt = strrep(txt, sprintf('P5\tG5\t\t'), sprintf('P5\tXX G5\t3.3.3.3\t')); + txt = strrep(txt, sprintf('P5\tG5\t\t'), sprintf('P5\tXX; G5\t3.3.3.3\t')); verifyNotEqual(testCase, txt, fileread(file)) fid = fopen(file, 'w'); fwrite(fid, txt); @@ -105,10 +106,8 @@ function testGetECfromDatabaseSplitGeneCells_tc0735(testCase) cleanup = onCleanup(@() warning('on', 'getECfromDatabase:conflicts')); %#ok r = find(strcmp(ecModel.ec.rxns, 'R5')); verifyNumElements(testCase, r, 1) - off = getECfromDatabase(ecModel, [], 'ignore', adapter); - on = getECfromDatabase(ecModel, [], 'ignore', adapter, true); - verifyNotEqual(testCase, off.ec.eccodes{r}, '3.3.3.3') % the KEGG entry of G5 is found instead - verifyEqual(testCase, on.ec.eccodes{r}, '3.3.3.3') + model = getECfromDatabase(ecModel, [], 'ignore', adapter); + verifyEqual(testCase, model.ec.eccodes{r}, '3.3.3.3') end function [ecModel, adapter] = conflictModel(testCase) diff --git a/test/unit_tests/ecTreeTests.m b/test/unit_tests/ecTreeTests.m index 2ffc2a22..70d8aaea 100644 --- a/test/unit_tests/ecTreeTests.m +++ b/test/unit_tests/ecTreeTests.m @@ -61,7 +61,7 @@ function testKcatsFromECTreeWritesFile_tc0086(testCase) function testBrendaEcTreePreset_tc0087(testCase) % The default preset: custom.tsv, then BRENDA at origin 1, then the EC - % tree; then the OKP methods combined. + % tree; then the OKP predictions. [model, adapter, project] = buildProject(); verifyFalse(testCase, isfield(adapter.params, 'kcat_assignment')) writeMeasurements(fullfile(project, 'data', 'measurements.tsv'), measurementsFor(model)); diff --git a/test/unit_tests/geckoCoreFunctionTests.m b/test/unit_tests/geckoCoreFunctionTests.m index f333bfad..5ed09662 100644 --- a/test/unit_tests/geckoCoreFunctionTests.m +++ b/test/unit_tests/geckoCoreFunctionTests.m @@ -2972,14 +2972,15 @@ function testKcatSourcesTableMergesWithPreset_tc0721(testCase) function testOkpSourceGroupDefault_tc0723(testCase) % The okp source group of the presets is KinForm-H, unless the project - % sets [kcat_sources.okp] methods. + % sets [kcat_sources.okp] method. config = kcatAssignmentConfig(struct('kcat_assignment', struct('preset', 'okp'))); - verifyEqual(testCase, config.okpMethods, {'KinForm-H'}) + verifyEqual(testCase, config.okpMethod, {'KinForm-H'}) verifyTrue(testCase, any(strcmp(config.stages(end).files, 'okp_kinform_h'))) params.kcat_assignment = struct('preset', 'okp'); - params.kcat_sources.okp = struct('methods', {{'CataPro', 'UniKP'}}); + params.kcat_sources.okp = struct('method', 'UniKP'); config = kcatAssignmentConfig(params); - verifyEqual(testCase, config.okpMethods, {'CataPro', 'UniKP'}) + verifyEqual(testCase, config.okpMethod, {'UniKP'}) + verifyTrue(testCase, any(strcmp(config.stages(end).files, 'okp_unikp'))) end function testDeprecatedDLKcatFunctions_tc0724(testCase) diff --git a/tutorials/full_ecModel/model_adapter.toml b/tutorials/full_ecModel/model_adapter.toml index 0910b66b..048c1da1 100644 --- a/tutorials/full_ecModel/model_adapter.toml +++ b/tutorials/full_ecModel/model_adapter.toml @@ -92,9 +92,9 @@ sigma0_log = 0.1 [kcat_assignment] preset = "brenda_ec_tree" -# The OpenKineticsPredictor methods of the okp stage of the preset. +# The OpenKineticsPredictor method of the okp stage of the preset. [kcat_sources.okp] -methods = ["KinForm-H"] +method = "KinForm-H" # Read by GECKO only. During kcat tuning, anaerobic conditions are set by # anaerobicModel_GECKO in the code folder, which GECKO adds to the path. diff --git a/tutorials/full_ecModel/protocol.m b/tutorials/full_ecModel/protocol.m index 9dfb460a..85e46b9d 100644 --- a/tutorials/full_ecModel/protocol.m +++ b/tutorials/full_ecModel/protocol.m @@ -99,7 +99,7 @@ % class when the EC number has few measurements (ec_tree.tsv); % 4. for the remaining reactions, the predictions of the % OpenKineticsPredictor (OKP) method KinForm-H ([kcat_sources.okp] -% methods), in okp_kinform_h.tsv. +% method), in okp_kinform_h.tsv. % kcatAssignmentConfig shows the stages of a preset, and the guide page % "Choose the kcat sources" compares the presets. @@ -113,7 +113,7 @@ % ecModel = getECfromDatabase(ecModel,'ecRxns',noEC); ecModel = getECfromDatabase(ecModel); -% The OKP methods read the SMILES of the substrates. findMetSmiles reads +% The OKP method reads the SMILES of the substrates. findMetSmiles reads % them from data/smilesDB.tsv and queries PubChem for the metabolite names % that are not in that file. noSmiles lists the metabolites without a % SMILES. diff --git a/tutorials/light_ecModel/model_adapter.toml b/tutorials/light_ecModel/model_adapter.toml index 1aa001be..624ced0d 100644 --- a/tutorials/light_ecModel/model_adapter.toml +++ b/tutorials/light_ecModel/model_adapter.toml @@ -60,9 +60,9 @@ file = "data/spontaneousReactions.tsv" [kcat_assignment] preset = "brenda_ec_tree" -# The OpenKineticsPredictor methods of the okp stage of the preset. +# The OpenKineticsPredictor method of the okp stage of the preset. [kcat_sources.okp] -methods = ["KinForm-H"] +method = "KinForm-H" [matlab.params] # Glucose uptake, average across NCI60 cell lines [mmol/gDW/h].