forked from opencobra/cobratoolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
changeGeneAssociation.m
87 lines (77 loc) · 2.92 KB
/
changeGeneAssociation.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
function model = changeGeneAssociation(model,rxnName,grRule,geneNameList,systNameList)
%changeGeneAssociation Change gene associations in a model
%
% model = changeGeneAssociation(model,rxnName,grRule,geneName,systName)
%
%INPUTS
% model COBRA Toolbox model structure
% rxnName Name of the new reaction
% grRule Gene-reaction rule in boolean format (and/or allowed)
%
%OPTIONAL INPUTS
% geneNameList List of gene names (used only for translation from
% common gene names to systematic gene names)
% systNameList List of systematic names
%
%OUTPUT
% model COBRA Toolbox model structure with new gene reaction
% associations
%
% Markus Herrgard 1/12/07
if (nargin < 4)
translateNamesFlag = false;
else
translateNamesFlag = true;
end
[isInModel,rxnID] = ismember(rxnName,model.rxns);
if (~isInModel)
error(['Reaction ' rxnName ' not in the model']);
end
if ~isfield(model,'genes')
model.genes = {};
end
nGenes = length(model.genes);
model.rules{rxnID} = '';
% IT 01/2010 - this line caused problems for xls2model.m
model.rxnGeneMat(rxnID,:) = zeros(1,nGenes);
model.rxnGeneMat(rxnID,find(model.rxnGeneMat(rxnID,:))) = 0;
if (~isempty(grRule))
% Ronan & Stefan 13/9/2011 - moved this inside check if empty
% Remove extra white space
grRule = regexprep(grRule,'\s{2,}',' ');
grRule = regexprep(grRule,'( ','(');
grRule = regexprep(grRule,' )',')');
[genes,rule] = parseBoolean(grRule);
for i = 1:length(genes)
if (translateNamesFlag)
% Translate gene names to systematic names
[isInList,translID] = ismember(genes{i},geneNameList);
if isInList
newGene = systNameList{translID};
grRule = regexprep(grRule,[genes{i} '$'],newGene);
grRule = regexprep(grRule,[genes{i} '\s'],[newGene ' ']);
grRule = regexprep(grRule,[genes{i} ')'],[newGene ')']);
genes{i} = newGene;
else
warning(['Gene name ' genes{i} ' not in translation list']);
end
end
geneID = find(strcmp(model.genes,genes{i}));
if (isempty(geneID))
warning(['New gene ' genes{i} ' added to model']);
% Append gene
model.genes = [model.genes; genes(i)];
nGenes = length(model.genes);
model.rxnGeneMat(rxnID,end+1) = 1;
rule = strrep(rule,['x(' num2str(i) ')'],['x(' num2str(nGenes) ')']);
else
model.rxnGeneMat(rxnID,geneID) = 1;
rule = strrep(rule,['x(' num2str(i) ')'],['x(' num2str(geneID) ')']);
end
end
model.rules{rxnID} = rule;
end
model.grRules{rxnID} = grRule;
%make sure variables are column vectors
model.rules = columnVector(model.rules);
model.grRules = columnVector(model.grRules);