addIdentifierPrefix If reaction, metabolite, compartment, gene or model identifiers do not start with a letter or _, which conflicts with SBML specifications, prefixes are added for all identifiers in the respective model field. The prefixes are: "R_" for model.rxns, "M_" for model.mets, "C_" for model.comps; "G_" for model.genes (and also represented in model.grRules) Input: model model whose identifiers should be modified fields cell array with model field names that should be checked if prefixes should be added, possible values: 'rxns', 'mets', 'comps', 'genes', 'id'. (optional, by default all listed model fields will be checked). Output: model modified model hasChanged cell array with fields and prefixes that are added Usage: [model, hasChanged]=addIdentifierPrefix(model,fields)
0001 function [model, hasChanged]=addIdentifierPrefix(model,fields) 0002 % addIdentifierPrefix 0003 % If reaction, metabolite, compartment, gene or model identifiers do not 0004 % start with a letter or _, which conflicts with SBML specifications, 0005 % prefixes are added for all identifiers in the respective model field. 0006 % The prefixes are: 0007 % "R_" for model.rxns, 0008 % "M_" for model.mets, 0009 % "C_" for model.comps; 0010 % "G_" for model.genes (and also represented in model.grRules) 0011 % 0012 % Input: 0013 % model model whose identifiers should be modified 0014 % fields cell array with model field names that should be 0015 % checked if prefixes should be added, possible values: 0016 % 'rxns', 'mets', 'comps', 'genes', 'id'. (optional, by 0017 % default all listed model fields will be checked). 0018 % 0019 % Output: 0020 % model modified model 0021 % hasChanged cell array with fields and prefixes that are added 0022 % 0023 % Usage: [model, hasChanged]=addIdentifierPrefix(model,fields) 0024 0025 if nargin<2 || isempty(fields) 0026 fields = {'rxns','mets','comps','genes','id'}; 0027 end 0028 0029 modelFields = {'rxns','R_'; 0030 'mets','M_'; 0031 'comps','C_'; 0032 'genes','G_'; 0033 'id','M_'}; 0034 0035 toChangeIdx = find(ismember(modelFields(:,1),fields)); 0036 hasChanged = false(numel(modelFields(:,1)),1); 0037 for i=1:numel(toChangeIdx) 0038 currName = modelFields{toChangeIdx(i),1}; 0039 currPrefix = modelFields{toChangeIdx(i),2}; 0040 if isfield(model,currName) 0041 currField = model.(currName); 0042 else 0043 continue; 0044 end 0045 if ~all(startsWith(currField,regexpPattern('^[a-zA-Z_]'))) 0046 currField = strcat(currPrefix, currField); 0047 hasChanged(toChangeIdx(i)) = true; 0048 0049 if strcmp(currName,'genes') 0050 model.grRules = regexprep(model.grRules, '(\<[0-9_a-zA-Z])', 'G_$1'); 0051 model.grRules = regexprep(model.grRules, ' G_or ', ' or '); 0052 model.grRules = regexprep(model.grRules, ' G_and ', ' and '); 0053 end 0054 model.(currName) = currField; 0055 end 0056 end 0057 0058 hasChanged = modelFields(hasChanged,:); 0059 hasChanged = append('model.', hasChanged(:,1), ' (', hasChanged(:,2), ' prefix)'); 0060 end