-
Notifications
You must be signed in to change notification settings - Fork 1
/
TestCase_generateContextSpecificModels.m
185 lines (155 loc) · 6.69 KB
/
TestCase_generateContextSpecificModels.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
model=readCbModel('..\Data\Yeast_8_4_0_V6.xls');
result = cell(3991,5);
zeroGeneExpressionThreshold = 0;
logicalOperators = ["and" "or" "(" ")" "((" "))"];
global geneIds
global expressionValues
% GET TRANSCRIPTOMICS DATA
% SRR8994357_WT, SRR8994358_WT, SRR8994359_WT (wild type no stress)
% SRR8994378_S47D, SRR8994379_S47D, SRR8994380_S47D (S47D no stress)
sheetNames = {'SRR8994357_WT', 'SRR8994358_WT', 'SRR8994359_WT', 'SRR8994378_S47D', 'SRR8994379_S47D', 'SRR8994380_S47D'};
for o=1:1:length(sheetNames)
sheetName = sheetNames{o};
filename = '..\Data\TranscriptomicsData.xlsx';
[numbers, text, tr_data] = xlsread(filename,sheetName);
tr_genes = tr_data(:,1);
tr_count = tr_data(:,2);
transcriptomicsData=readtable(filename,'Sheet',sheetName);
geneIds = transcriptomicsData.Geneid;
expressionValues = transcriptomicsData.Data;
% DELETE NON EXPRESSED GENES
genes_to_delete = {};
counter = 1;
% Non expressed genes
for i=2:1:length(tr_genes)
if tr_count{i} <= zeroGeneExpressionThreshold % Only genes that are not expressed
for n=1:1:length(model.genes)
if strcmp(tr_genes{i}, model.genes{n}) % Metabolic genes only
% Test is gene deletions affects growth
[grRatio, grRateKO, grRateWT, hasEffect, delRxns] = singleGeneDeletion(model, 'FBA', tr_genes(i));
if grRatio == 1
genes_to_delete{counter} = tr_genes{i};
counter = counter + 1;
end
end
end
end
end
% SET REACTION BOUNDS BASED ON TRANSCRIPTOMICS DATA
for i=1:1:length(model.rxns)
result{i,1} = model.rxns{i};
result{i,2} = model.grRules{i};
% No associated genes
if model.grRules{i} == ""
result{i,3} = 'No associated genes';
% One Gene (expression does not contain brackets)
elseif ~contains(model.grRules{i},"(")
result{i,3} = 'One Gene';
value = findTranscriptionValue(model.grRules{i});
if value ~= 0
result{i,5} = findTranscriptionValue(model.grRules{i});
end
% Gene combination AND + OR (expression contains double brackets)
elseif contains(model.grRules{i},"((") || contains(model.grRules{i},"))")
result{i,3} = 'AND + OR';
value = model.grRules{i};
%Split ORs
ands = split(model.grRules{i},"or");
orsToCompare = [];
for k=1:1:length(ands)
%Split ANDs
operands = split(ands(k));
andsToCompare = [];
for l=1:1:length(operands)
if ~ismember(operands{l},logicalOperators) && operands(l)~=""
tr_Val = findTranscriptionValue(operands{l});
andsToCompare = [andsToCompare tr_Val];
end
end
orsToCompare = [orsToCompare min(andsToCompare)];
end
operands = split(model.grRules{i});
for l=1:1:length(operands)
if ~ismember(operands{l},logicalOperators)
tr_Val = findTranscriptionValue(operands{l});
value = strrep(value,operands{l},num2str(tr_Val));
end
end
result{i,4} = value;
result{i,5} = max(orsToCompare);
% Gene combination AND
elseif contains(model.grRules{i},"and")
result{i,3} = 'AND only';
value = model.grRules{i};
operands = split(model.grRules{i});
numbersToCompare = [];
for l=1:1:length(operands)
if ~ismember(operands{l},logicalOperators)
tr_Val = findTranscriptionValue(operands{l});
numbersToCompare = [numbersToCompare tr_Val];
value = strrep(value,operands{l},num2str(tr_Val));
end
end
result{i,4} = value;
result{i,5} = min(numbersToCompare);
% Gene combination OR
elseif contains(model.grRules{i},"or")
result{i,3} = 'OR only';
value = model.grRules{i};
operands = split(model.grRules{i});
numbersToCompare = [];
for l=1:1:length(operands)
if ~ismember(operands{l},logicalOperators)
tr_Val = findTranscriptionValue(operands{l});
numbersToCompare = [numbersToCompare tr_Val];
value = strrep(value,operands{l},num2str(tr_Val));
end
end
result{i,4} = value;
result{i,5} = max(numbersToCompare);
end
%Set reaction bounds
if ~isempty(result{i,5})
% Irreversible only
if model.lb(i) == 0
model = changeRxnBounds(model,model.rxns{i},result{i,5},'u');
end
end
end
% Delete genes
[model, hasEffect, constrRxnNames, deletedGenes] = deleteModelGenes(model, genes_to_delete);
% GET EXPERIMENTAL DATA FOR TRANSPORT REACTIONS
fileName = '..\Data\MediumData.xlsx';
sheet = 'Sheet1';
[numbers, text, mediumData] = xlsread(fileName,sheet);
% Set bounds for external metabolites
for n=2:1:height(mediumData)
model = changeRxnBounds(model,mediumData{n,1}, mediumData{n,2}, 'l');
model = changeRxnBounds(model,mediumData{n,1}, mediumData{n,3}, 'u');
end
% Set objective function
model = changeObjective(model,'r_2111'); % growth
% Perform optimizations
FBAsolutionMin = optimizeCbModel(model,'min');
FBAsolutionMax = optimizeCbModel(model,'max');
[minFlux, maxFlux] = fluxVariability(model, 90, 'min');
% Save results
excelFileName = convertStringsToChars(strcat('../Results post-optimization/',sheetName, '_GT1_', string(zeroGeneExpressionThreshold), '.xls'));
writeCbModel(model, excelFileName);
[d1,d2, existingData] = xlsread(excelFileName);
FBAMin = ["FBAMin" ;FBAsolutionMin.x];
FBAMax = ["FBAMax" ;FBAsolutionMax.x];
minFlux = ["MinFlux" ;minFlux];
maxFlux = ["MaxFlux" ;maxFlux];
newData = [existingData, FBAMin, FBAMax, minFlux, maxFlux]; % append the new column with existing data.
writematrix(newData,excelFileName);
end
function value = findTranscriptionValue(geneId)
global geneIds
global expressionValues
for k=1:1:length(geneIds)
if strcmp(geneId, geneIds(k))
value = expressionValues(k);
end
end
end