-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcreategrRulesField.m
More file actions
47 lines (44 loc) · 1.6 KB
/
creategrRulesField.m
File metadata and controls
47 lines (44 loc) · 1.6 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
function model = creategrRulesField(model, positions)
% Generates the grRules optional model field from the required rules and gene fields.
%
% USAGE:
%
% modelWithField = creategrRulesField(model, positions)
%
% INPUT:
% model: The COBRA Model structure to generate the grRules Field for
% an existing grRules field will be overwritten
%
% OPTIONAL INPUT:
%
% positions: The positions to update. Can be supplied either as
% logical array, double indices, or reaction names (Default: model.rxns)
% If the model did not have grRules before, ALL rxns
% will have grRules created
%
% OUTPUT:
% model: The Output model with a grRules field
%
% .. Authors: - Thomas Pfau May 2017
if ~exist('positions','var') || ~isfield(model, 'grRules')
pos = true(size(model.rxns));
else
if islogical(positions)
pos = positions;
else
if isnumeric(positions)
pos = false(size(model.rxns));
pos(positions) = true;
elseif iscell(positions)
pos = ismember(model.rxns,positions);
if ~sum(pos) == numel(unique(positions))
error('The following reactions are not part of this model:\n%s\n',positions{~ismember(postions, model.rxns)});
end
end
end
end
currentrules = model.rules(pos);
currentrules = strrep(currentrules,'&','and');
currentrules = strrep(currentrules,'|','or');
currentrules = regexprep(currentrules,'x\(([0-9]+)\)','${model.genes{str2num($1)}}');
model.grRules(pos,1) = currentrules;