forked from opencobra/cobratoolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateRules.m
61 lines (49 loc) · 1.83 KB
/
generateRules.m
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
61
function [model2] = generateRules(model)
% If a model does not have a model.rules field but has a model.grRules
% field, can be regenerated using this script
% Input:
% model with model.grRules***
% Output:
% model2 same model but with model.rules added
% Aarash Bordar 11/17/2010
grRules = model.grRules;
genes = model.genes;
[m,n] = size(model.S);
rules(1:n,1) = {''};
for i = 1:n
if length(grRules{i}) > 0
tmp = grRules{i};
tmp = splitString(tmp,' ');
tmp = strrep(tmp,' ','');
tmp2 = [];
for j = 1:length(tmp)
if strcmp(tmp{j},'or')
tmp2 = [tmp2,'| '];
elseif strcmp(tmp{j},'and')
tmp2 = [tmp2,'& '];
elseif strcmp(tmp{j}(1),'(') & strcmp(tmp{j}(end),')')
tmp{j} = strrep(tmp{j},'(','');
tmp{j} = strrep(tmp{j},')','');
loc = strmatch(tmp{j},genes,'exact');
tmp2 = [tmp2,'(x(',num2str(loc),')) '];
elseif strcmp(tmp{j}(1),'(')
tmp{j} = strrep(tmp{j},'(','');
tmp{j} = strrep(tmp{j},')','');
loc = strmatch(tmp{j},genes,'exact');
tmp2 = [tmp2,'(x(',num2str(loc),') '];
elseif strcmp(tmp{j}(end),')')
tmp{j} = strrep(tmp{j},'(','');
tmp{j} = strrep(tmp{j},')','');
loc = strmatch(tmp{j},genes,'exact');
tmp2 = [tmp2,'x(',num2str(loc),')) '];
else
loc = strmatch(tmp{j},genes,'exact');
tmp2 = [tmp2,'x(',num2str(loc),') '];
end
end
tmp2 = tmp2(1:end-1);
rules{i} = tmp2;
end
end
model2 = model;
model2.rules = rules;