-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathaddIdentifierPrefix.m
More file actions
60 lines (55 loc) · 2.17 KB
/
Copy pathaddIdentifierPrefix.m
File metadata and controls
60 lines (55 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function [model, hasChanged]=addIdentifierPrefix(model,fields)
% 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)
if nargin<2 || isempty(fields)
fields = {'rxns','mets','comps','genes','id'};
end
modelFields = {'rxns','R_';
'mets','M_';
'comps','C_';
'genes','G_';
'id','M_'};
toChangeIdx = find(ismember(modelFields(:,1),fields));
hasChanged = false(numel(modelFields(:,1)),1);
for i=1:numel(toChangeIdx)
currName = modelFields{toChangeIdx(i),1};
currPrefix = modelFields{toChangeIdx(i),2};
if isfield(model,currName)
currField = model.(currName);
else
continue;
end
if ~all(startsWith(currField,regexpPattern('^[a-zA-Z_]')))
currField = strcat(currPrefix, currField);
hasChanged(toChangeIdx(i)) = true;
if strcmp(currName,'genes')
model.grRules = regexprep(model.grRules, '(\<[0-9_a-zA-Z])', 'G_$1');
model.grRules = regexprep(model.grRules, ' G_or ', ' or ');
model.grRules = regexprep(model.grRules, ' G_and ', ' and ');
end
model.(currName) = currField;
end
end
hasChanged = modelFields(hasChanged,:);
hasChanged = append('model.', hasChanged(:,1), ' (', hasChanged(:,2), ' prefix)');
end