removeIdentifierPrefix This function removes identifier prefixes: "R_" for model.rxns, model.rxnNames and model.id, "M_" for model.mets and model.metNames, "C_" for model.comps; "G_" for model.genes (and also represented in model.grRules). By default, the prefixes are only removed if all entries in a particular field has the prefix. The prefixes might have been present because one or more identifiers do not start with a letter or _, which conflicts with SBML specifications. Input: model model whose identifiers should be modified fields cell array with model field names from which the identifiers should be removed, possible values: 'rxns', 'mets', 'comps', 'genes', 'metNames', 'rxnNames', 'id'. (optional, by default all listed model fields will be checked). forceRemove if prefixes should be removed even if not all entries in a model field have the prefix (optional, default false) Output: model modified model hasChanged cell array with fields and prefixes that are removed Usage: model=removeIdentifierPrefix(model,fields,forceRemove)
0001 function [model, hasChanged]=removeIdentifierPrefix(model,fields,forceRemove) 0002 % removeIdentifierPrefix 0003 % This function removes identifier prefixes: 0004 % "R_" for model.rxns, model.rxnNames and model.id, 0005 % "M_" for model.mets and model.metNames, 0006 % "C_" for model.comps; 0007 % "G_" for model.genes (and also represented in model.grRules). 0008 % By default, the prefixes are only removed if all entries in a 0009 % particular field has the prefix. The prefixes might have been present 0010 % because one or more identifiers do not start with a letter or _, which 0011 % conflicts with SBML specifications. 0012 % 0013 % Input: 0014 % model model whose identifiers should be modified 0015 % fields cell array with model field names from which the 0016 % identifiers should be removed, possible values: 0017 % 'rxns', 'mets', 'comps', 'genes', 'metNames', 0018 % 'rxnNames', 'id'. (optional, by default all listed 0019 % model fields will be checked). 0020 % forceRemove if prefixes should be removed even if not all entries 0021 % in a model field have the prefix (optional, default 0022 % false) 0023 % 0024 % Output: 0025 % model modified model 0026 % hasChanged cell array with fields and prefixes that are removed 0027 % 0028 % Usage: model=removeIdentifierPrefix(model,fields,forceRemove) 0029 0030 if nargin<2 || isempty(fields) 0031 fields = {'rxns','mets','comps','genes','metNames','rxnNames','id'}; 0032 end 0033 if nargin<3 || isempty(forceRemove) 0034 forceRemove = false; 0035 end 0036 0037 modelFields = {'rxns', 'R_'; 0038 'mets', 'M_'; 0039 'comps', 'C_'; 0040 'genes', 'G_'; 0041 'metNames', 'M_'; 0042 'rxnNames', 'R_'; 0043 'id', 'M_'}; 0044 0045 toChangeIdx = find(ismember(modelFields(:,1),fields)); 0046 hasChanged = false(numel(modelFields(:,1)),1); 0047 for i=1:numel(toChangeIdx) 0048 currName = modelFields{toChangeIdx(i),1}; 0049 currPrefix = modelFields{toChangeIdx(i),2}; 0050 currField = model.(currName); 0051 0052 if forceRemove && any(startsWith(currField,currPrefix)) 0053 hasPrefix = true; 0054 else 0055 hasPrefix = all(startsWith(currField,currPrefix)); 0056 end 0057 if hasPrefix 0058 currField = regexprep(currField,['^' currPrefix],''); 0059 hasChanged(toChangeIdx(i)) = true; 0060 if strcmp(currName,'genes') 0061 model.grRules=regexprep(model.grRules,'^G_',''); 0062 model.grRules=regexprep(model.grRules,'\(G_','('); 0063 model.grRules=regexprep(model.grRules,' G_',' '); 0064 end 0065 end 0066 model.(currName) = currField; 0067 end 0068 hasChanged = modelFields(hasChanged,:); 0069 hasChanged = append('model.', hasChanged(:,1), ' (', hasChanged(:,2), ' prefix)'); 0070 end