-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCOUR_framework.m
314 lines (247 loc) · 18.3 KB
/
SCOUR_framework.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
function SCOUR_framework(nT,cov,num_IC,rep)
warning('off','all')
rng('shuffle');
fprintf('Starting machine learning framework...\n');
%% Initial Preparation of model
% Train on autogenerated data, test on model
% yeast stoichiometric interactions
load('modelSTM.mat');
model.S = stm;
% Find model mass action (MA) interactions
[row_modelMA col_modelMA] = find(model.S < 0);
modelMA = [row_modelMA col_modelMA];
unique_flux = unique(modelMA(:,2));
count_1contMet = 1;
count_2contMet = 1;
for i = 1:length(unique_flux)
controller_met_idx = find(modelMA(:,2) == unique_flux(i));
if length(modelMA(controller_met_idx,1)) == 1
modelMA_1contMet_List(count_1contMet,:) = [modelMA(controller_met_idx,1)' unique_flux(i)];
count_1contMet = count_1contMet + 1;
elseif length(modelMA(controller_met_idx,1)) == 2
modelMA_2contMet_List(count_2contMet,:) = [modelMA(controller_met_idx,1)' unique_flux(i)];
count_2contMet = count_2contMet + 1;
end
end
model_prefix = 'model';
%% Identify 1 controller metabolite reactions
% Load autogenerated data information
load(sprintf('AutoGenerateTrain_meta_1contMet_k-01_nT-%03d_cov-%02d_rep-%03d_smooth.mat',nT,cov,rep),'train_true_regs_1contMet');
train_true_regs_meta_1contMet = train_true_regs_1contMet;
trueInRegIdx_AutoGenerateTrain_meta_1contMet = find(train_true_regs_meta_1contMet == 1);
load(sprintf('AutoGenerateTrain_1contMet_k-01_nT-%03d_cov-%02d_rep-%03d_smooth.mat',nT,cov,rep),'train_true_regs_1contMet');
trueInRegIdx_AutoGenerateTrain_1contMet = find(train_true_regs_1contMet == 1);
% Create feature matrix
autogen_prefix = 'AutoGenerateTrain_1contMet';
autogen_meta_prefix = 'AutoGenerateTrain_meta_1contMet';
createFeatMatrix_1contMet_model_noisy
% Normalize feature matrices
featureMatrix_AutoGenerateTrain_1contMet_n = (featureMatrix_AutoGenerateTrain_1contMet-prctile(featureMatrix_AutoGenerateTrain_1contMet,20,2))./(prctile(featureMatrix_AutoGenerateTrain_1contMet,80)-prctile(featureMatrix_AutoGenerateTrain_1contMet,20));
featureMatrix_AutoGenerateTrain_meta_1contMet_n = (featureMatrix_AutoGenerateTrain_meta_1contMet-prctile(featureMatrix_AutoGenerateTrain_meta_1contMet,20,2))./(prctile(featureMatrix_AutoGenerateTrain_meta_1contMet,80)-prctile(featureMatrix_AutoGenerateTrain_meta_1contMet,20));
featureMatrix_1contMet_model_n = (featureMatrix_1contMet_model-prctile(featureMatrix_1contMet_model,20,2))./(prctile(featureMatrix_1contMet_model,80)-prctile(featureMatrix_1contMet_model,20));
% Setup training set and training label
trueInteractionSet_1contMet = featureMatrix_AutoGenerateTrain_1contMet_n(:,trueInRegIdx_AutoGenerateTrain_1contMet);
trueInteractionLabel_1contMet = logical(ones(1,size(trueInteractionSet_1contMet,2)));
falseInteractionSet_1contMet = featureMatrix_AutoGenerateTrain_1contMet_n;
falseInteractionSet_1contMet(:,trueInRegIdx_AutoGenerateTrain_1contMet) = [];
falseInteractionLabel_1contMet = logical(zeros(1,size(falseInteractionSet_1contMet,2)));
trainingSet_1contMet = [trueInteractionSet_1contMet falseInteractionSet_1contMet];
trainingLabel_1contMet = [trueInteractionLabel_1contMet falseInteractionLabel_1contMet];
% Create first level models
Mdl_RF_1contMet = TreeBagger(200,trainingSet_1contMet',double(trainingLabel_1contMet),'Method','Regression','MinLeafSize',5);
Mdl_KNN_1contMet = fitcknn(trainingSet_1contMet',trainingLabel_1contMet,'NumNeighbors',6);
Mdl_SNN_1contMet = patternnet(20,'trainscg');
Mdl_SNN_1contMet.trainParam.showWindow = 0;
Mdl_SNN_1contMet = train(Mdl_SNN_1contMet,trainingSet_1contMet,trainingLabel_1contMet);
Mdl_SNN_1contMet = train(Mdl_SNN_1contMet,trainingSet_1contMet,trainingLabel_1contMet);
Mdl_SNN_1contMet = train(Mdl_SNN_1contMet,trainingSet_1contMet,trainingLabel_1contMet);
Mdl_DA_1contMet = fitcdiscr(trainingSet_1contMet',trainingLabel_1contMet,'discrimType','pseudoLinear');
% Predicted labels using second training set
trueInteractionSet_meta_1contMet = featureMatrix_AutoGenerateTrain_meta_1contMet_n(:,trueInRegIdx_AutoGenerateTrain_meta_1contMet);
trueInteractionLabel_meta_1contMet = logical(ones(1,size(trueInteractionSet_meta_1contMet,2)));
falseInteractionSet_meta_1contMet = featureMatrix_AutoGenerateTrain_meta_1contMet_n;
falseInteractionSet_meta_1contMet(:,trueInRegIdx_AutoGenerateTrain_meta_1contMet) = [];
falseInteractionLabel_meta_1contMet = logical(zeros(1,size(falseInteractionSet_meta_1contMet,2)));
trainingSet_meta_1contMet = [trueInteractionSet_meta_1contMet falseInteractionSet_meta_1contMet];
trainingLabel_meta_1contMet = [trueInteractionLabel_meta_1contMet falseInteractionLabel_meta_1contMet];
predictedLabel_RF_meta_1contMet = Mdl_RF_1contMet.predict(trainingSet_meta_1contMet');
predictedLabel_KNN_meta_1contMet = double(Mdl_KNN_1contMet.predict(trainingSet_meta_1contMet'));
predictedLabel_SNN_meta_1contMet = Mdl_SNN_1contMet(trainingSet_meta_1contMet)';
predictedLabel_DA_meta_1contMet = double(Mdl_DA_1contMet.predict(trainingSet_meta_1contMet'));
predictedLabel_L1_meta_1contMet = [predictedLabel_RF_meta_1contMet predictedLabel_KNN_meta_1contMet predictedLabel_SNN_meta_1contMet predictedLabel_DA_meta_1contMet];
% Create second level model
predictedLabel_L1_meta_1contMet_good = predictedLabel_L1_meta_1contMet;
poor_classifier_1contMet = find(all(~diff(predictedLabel_L1_meta_1contMet_good)));
if ~isempty(poor_classifier_1contMet)
predictedLabel_L1_meta_1contMet_good(:,poor_classifier_1contMet) = [];
end
Mdl_DA_meta_1contMet = fitcdiscr(predictedLabel_L1_meta_1contMet_good,trainingLabel_meta_1contMet,'discrimType','pseudoLinear');
% Model
% Setup testing set and testing label
testingSet_model_1contMet = featureMatrix_1contMet_model_n;
% Predict where 1 controller metabolite reactions occur in yeast
% model
predictedLabel_RF_model_1contMet = Mdl_RF_1contMet.predict(testingSet_model_1contMet');
predictedLabel_KNN_model_1contMet = double(Mdl_KNN_1contMet.predict(testingSet_model_1contMet'));
predictedLabel_SNN_model_1contMet = Mdl_SNN_1contMet(testingSet_model_1contMet)';
predictedLabel_DA_model_1contMet = double(Mdl_DA_1contMet.predict(testingSet_model_1contMet'));
predictedLabel_L1_model_1contMet = [predictedLabel_RF_model_1contMet predictedLabel_KNN_model_1contMet predictedLabel_SNN_model_1contMet predictedLabel_DA_model_1contMet];
if ~isempty(poor_classifier_1contMet)
predictedLabel_L1_model_1contMet(:,poor_classifier_1contMet) = [];
end
predictedLabel_L2_model_1contMet = Mdl_DA_meta_1contMet.predict(predictedLabel_L1_model_1contMet)
%% Remove 1 controller metabolite reactions
% Remove from model using predicted 1 controller metabolite
% interactions
predicted_model_1contMet = [modelMA_1contMet_List(find(predictedLabel_L2_model_1contMet==1),:)];
model_fluxes_to_remove = unique([predicted_model_1contMet(:,2)']);
if ~isequal(sort(model_fluxes_to_remove),1:size(model.S,2))
model_regScheme_2contMet = createRegSchemeList(model.S,model_fluxes_to_remove);
end
if exist('model_regScheme_2contMet','var')
%% Identify 2 controller metabolite reactions
% Load autogenerated data information
load(sprintf('AutoGenerateTrain_meta_2contMet_k-01_nT-%03d_cov-%02d_rep-%03d_smooth.mat',nT,cov,rep)','train_true_regs_2contMet','train_interaction_mets_2contMet');
train_true_regs_meta_2contMet = train_true_regs_2contMet;
train_interaction_mets_meta_2contMet = train_interaction_mets_2contMet;
trueInRegIdx_AutoGenerateTrain_meta_2contMet = find(train_true_regs_meta_2contMet == 1);
load(sprintf('AutoGenerateTrain_2contMet_k-01_nT-%03d_cov-%02d_rep-%03d_smooth.mat',nT,cov,rep)','train_true_regs_2contMet','train_interaction_mets_2contMet');
trueInRegIdx_AutoGenerateTrain_2contMet = find(train_true_regs_2contMet == 1);
% Create feature matrix
autogen_prefix = 'AutoGenerateTrain_2contMet';
autogen_meta_prefix = 'AutoGenerateTrain_meta_2contMet';
createFeatMatrix_2contMet_model_noisy
% Setup training set and training label
trueInteractionSet_2contMet = featureMatrix_AutoGenerateTrain_2contMet_n(:,trueInRegIdx_AutoGenerateTrain_2contMet);
trueInteractionLabel_2contMet = logical(ones(1,size(trueInteractionSet_2contMet,2)));
falseInteractionSet_2contMet = featureMatrix_AutoGenerateTrain_2contMet_n;
falseInteractionSet_2contMet(:,trueInRegIdx_AutoGenerateTrain_2contMet) = [];
falseInteractionLabel_2contMet = logical(zeros(1,size(falseInteractionSet_2contMet,2)));
trainingSet_2contMet = [trueInteractionSet_2contMet falseInteractionSet_2contMet];
trainingLabel_2contMet = [trueInteractionLabel_2contMet falseInteractionLabel_2contMet];
% Create first level models
Mdl_RF_2contMet = TreeBagger(200,trainingSet_2contMet',double(trainingLabel_2contMet),'Method','Regression','MinLeafSize',5);
Mdl_KNN_2contMet = fitcknn(trainingSet_2contMet',trainingLabel_2contMet,'NumNeighbors',6);
Mdl_SNN_2contMet = patternnet(20,'trainscg');
Mdl_SNN_2contMet.trainParam.showWindow = 0;
Mdl_SNN_2contMet = train(Mdl_SNN_2contMet,trainingSet_2contMet,trainingLabel_2contMet);
Mdl_SNN_2contMet = train(Mdl_SNN_2contMet,trainingSet_2contMet,trainingLabel_2contMet);
Mdl_SNN_2contMet = train(Mdl_SNN_2contMet,trainingSet_2contMet,trainingLabel_2contMet);
Mdl_DA_2contMet = fitcdiscr(trainingSet_2contMet',trainingLabel_2contMet,'discrimType','pseudoLinear');
% Predicted labels using second training set
trueInteractionSet_meta_2contMet = featureMatrix_AutoGenerateTrain_meta_2contMet_n(:,trueInRegIdx_AutoGenerateTrain_meta_2contMet);
trueInteractionLabel_meta_2contMet = logical(ones(1,size(trueInteractionSet_meta_2contMet,2)));
falseInteractionSet_meta_2contMet = featureMatrix_AutoGenerateTrain_meta_2contMet_n;
falseInteractionSet_meta_2contMet(:,trueInRegIdx_AutoGenerateTrain_meta_2contMet) = [];
falseInteractionLabel_meta_2contMet = logical(zeros(1,size(falseInteractionSet_meta_2contMet,2)));
trainingSet_meta_2contMet = [trueInteractionSet_meta_2contMet falseInteractionSet_meta_2contMet];
trainingLabel_meta_2contMet = [trueInteractionLabel_meta_2contMet falseInteractionLabel_meta_2contMet];
predictedLabel_RF_meta_2contMet = Mdl_RF_2contMet.predict(trainingSet_meta_2contMet');
predictedLabel_KNN_meta_2contMet = double(Mdl_KNN_2contMet.predict(trainingSet_meta_2contMet'));
predictedLabel_SNN_meta_2contMet = Mdl_SNN_2contMet(trainingSet_meta_2contMet)';
predictedLabel_DA_meta_2contMet = double(Mdl_DA_2contMet.predict(trainingSet_meta_2contMet'));
predictedLabel_L1_meta_2contMet = [predictedLabel_RF_meta_2contMet predictedLabel_KNN_meta_2contMet predictedLabel_SNN_meta_2contMet predictedLabel_DA_meta_2contMet];
% Create second level model
predictedLabel_L1_meta_2contMet_good = predictedLabel_L1_meta_2contMet;
poor_classifier_2contMet = find(all(~diff(predictedLabel_L1_meta_2contMet_good)));
if ~isempty(poor_classifier_2contMet)
predictedLabel_L1_meta_2contMet_good(:,poor_classifier_2contMet) = [];
end
Mdl_DA_meta_2contMet = fitcdiscr(predictedLabel_L1_meta_2contMet_good,trainingLabel_meta_2contMet,'discrimType','pseudoLinear');
% Model
% Setup testing set and testing label
testingSet_model_2contMet = featureMatrix_2contMet_model_n;
% Predict where 2 controller metabolite reactions occur in yeast
% model
predictedLabel_RF_model_2contMet = Mdl_RF_2contMet.predict(testingSet_model_2contMet');
predictedLabel_KNN_model_2contMet = double(Mdl_KNN_2contMet.predict(testingSet_model_2contMet'));
predictedLabel_SNN_model_2contMet = Mdl_SNN_2contMet(testingSet_model_2contMet)';
predictedLabel_DA_model_2contMet = double(Mdl_DA_2contMet.predict(testingSet_model_2contMet'));
predictedLabel_L1_model_2contMet = [predictedLabel_RF_model_2contMet predictedLabel_KNN_model_2contMet predictedLabel_SNN_model_2contMet predictedLabel_DA_model_2contMet];
if ~isempty(poor_classifier_2contMet)
predictedLabel_L1_model_2contMet(:,poor_classifier_2contMet) = [];
end
predictedLabel_L2_model_2contMet = Mdl_DA_meta_2contMet.predict(predictedLabel_L1_model_2contMet)
%% Remove 2 controller metabolite reactions
% Remove from model using predicted 2 controller metabolite
% interactions
predicted_model_2contMet = [model_regScheme_2contMet(find(predictedLabel_L2_model_2contMet==1),:)];
model_fluxes_to_remove = unique([predicted_model_1contMet(:,2)' predicted_model_2contMet(:,3)']);
if ~isequal(sort(model_fluxes_to_remove),1:size(model.S,2))
[~,model_regScheme_3contMet] = createRegSchemeList(model.S,model_fluxes_to_remove);
end
end
if exist('model_regScheme_3contMet','var')
%% Identify 3 controller metabolite reactions
% Load autogenerated data information
load(sprintf('AutoGenerateTrain_meta_3contMet_k-01_nT-%03d_cov-%02d_rep-%03d_smooth.mat',nT,cov,rep),'train_true_regs_3contMet','train_interaction_mets_3contMet');
train_true_regs_meta_3contMet = train_true_regs_3contMet;
train_interaction_mets_meta_3contMet = train_interaction_mets_3contMet;
trueInRegIdx_AutoGenerateTrain_meta_3contMet = find(train_true_regs_meta_3contMet == 1);
load(sprintf('AutoGenerateTrain_3contMet_k-01_nT-%03d_cov-%02d_rep-%03d_smooth.mat',nT,cov,rep),'train_true_regs_3contMet','train_interaction_mets_3contMet');
trueInRegIdx_AutoGenerateTrain_3contMet = find(train_true_regs_3contMet == 1);
% Create feature matrix
autogen_prefix = 'AutoGenerateTrain_3contMet';
autogen_meta_prefix = 'AutoGenerateTrain_meta_3contMet';
createFeatMatrix_3contMet_model_noisy
% Setup training set and training label
trueInteractionSet_3contMet = featureMatrix_AutoGenerateTrain_3contMet_n(:,trueInRegIdx_AutoGenerateTrain_3contMet);
trueInteractionLabel_3contMet = logical(ones(1,size(trueInteractionSet_3contMet,2)));
falseInteractionSet_3contMet = featureMatrix_AutoGenerateTrain_3contMet_n;
falseInteractionSet_3contMet(:,trueInRegIdx_AutoGenerateTrain_3contMet) = [];
falseInteractionLabel_3contMet = logical(zeros(1,size(falseInteractionSet_3contMet,2)));
trainingSet_3contMet = [trueInteractionSet_3contMet falseInteractionSet_3contMet];
trainingLabel_3contMet = [trueInteractionLabel_3contMet falseInteractionLabel_3contMet];
% Create first level models
Mdl_RF_3contMet = TreeBagger(200,trainingSet_3contMet',double(trainingLabel_3contMet),'Method','Regression','MinLeafSize',5);
Mdl_KNN_3contMet = fitcknn(trainingSet_3contMet',trainingLabel_3contMet,'NumNeighbors',6);
Mdl_SNN_3contMet = patternnet(20,'trainscg');
Mdl_SNN_3contMet.trainParam.showWindow = 0;
Mdl_SNN_3contMet = train(Mdl_SNN_3contMet,trainingSet_3contMet,trainingLabel_3contMet);
Mdl_SNN_3contMet = train(Mdl_SNN_3contMet,trainingSet_3contMet,trainingLabel_3contMet);
Mdl_SNN_3contMet = train(Mdl_SNN_3contMet,trainingSet_3contMet,trainingLabel_3contMet);
Mdl_DA_3contMet = fitcdiscr(trainingSet_3contMet',trainingLabel_3contMet,'discrimType','pseudoLinear');
% Predicted labels using second training set
trueInteractionSet_meta_3contMet = featureMatrix_AutoGenerateTrain_meta_3contMet_n(:,trueInRegIdx_AutoGenerateTrain_meta_3contMet);
trueInteractionLabel_meta_3contMet = logical(ones(1,size(trueInteractionSet_meta_3contMet,2)));
falseInteractionSet_meta_3contMet = featureMatrix_AutoGenerateTrain_meta_3contMet_n;
falseInteractionSet_meta_3contMet(:,trueInRegIdx_AutoGenerateTrain_meta_3contMet) = [];
falseInteractionLabel_meta_3contMet = logical(zeros(1,size(falseInteractionSet_meta_3contMet,2)));
trainingSet_meta_3contMet = [trueInteractionSet_meta_3contMet falseInteractionSet_meta_3contMet];
trainingLabel_meta_3contMet = [trueInteractionLabel_meta_3contMet falseInteractionLabel_meta_3contMet];
predictedLabel_RF_meta_3contMet = Mdl_RF_3contMet.predict(trainingSet_meta_3contMet');
predictedLabel_KNN_meta_3contMet = double(Mdl_KNN_3contMet.predict(trainingSet_meta_3contMet'));
predictedLabel_SNN_meta_3contMet = Mdl_SNN_3contMet(trainingSet_meta_3contMet)';
predictedLabel_DA_meta_3contMet = double(Mdl_DA_3contMet.predict(trainingSet_meta_3contMet'));
predictedLabel_L1_meta_3contMet = [predictedLabel_RF_meta_3contMet predictedLabel_KNN_meta_3contMet predictedLabel_SNN_meta_3contMet predictedLabel_DA_meta_3contMet];
% Create second level model
predictedLabel_L1_meta_3contMet_good = predictedLabel_L1_meta_3contMet;
poor_classifier_3contMet = find(all(~diff(predictedLabel_L1_meta_3contMet_good)));
if ~isempty(poor_classifier_3contMet)
predictedLabel_L1_meta_3contMet_good(:,poor_classifier_3contMet) = [];
end
Mdl_DA_meta_3contMet = fitcdiscr(predictedLabel_L1_meta_3contMet_good,trainingLabel_meta_3contMet,'discrimType','pseudoLinear');
% Model
% Setup testing set and testing label
testingSet_model_3contMet = featureMatrix_3contMet_model_n;
% Predict where 3 controller metabolite reactions occur in yeast
% model
predictedLabel_RF_model_3contMet = Mdl_RF_3contMet.predict(testingSet_model_3contMet');
predictedLabel_KNN_model_3contMet = double(Mdl_KNN_3contMet.predict(testingSet_model_3contMet'));
predictedLabel_SNN_model_3contMet = Mdl_SNN_3contMet(testingSet_model_3contMet)';
predictedLabel_DA_model_3contMet = double(Mdl_DA_3contMet.predict(testingSet_model_3contMet'));
predictedLabel_L1_model_3contMet = [predictedLabel_RF_model_3contMet predictedLabel_KNN_model_3contMet predictedLabel_SNN_model_3contMet predictedLabel_DA_model_3contMet];
if ~isempty(poor_classifier_3contMet)
predictedLabel_L1_model_3contMet(:,poor_classifier_3contMet) = [];
end
predictedLabel_L2_model_3contMet = Mdl_DA_meta_3contMet.predict(predictedLabel_L1_model_3contMet)
%% Remove 3 controller metabolite reactions
% Remove from model using predicted 3 controller metabolite
% interactions
predicted_model_3contMet = [model_regScheme_3contMet(find(predictedLabel_L2_model_3contMet==1),:)];
model_fluxes_to_remove = unique([predicted_model_1contMet(:,2)' predicted_model_2contMet(:,3)' predicted_model_3contMet(:,4)']);
if ~isequal(sort(model_fluxes_to_remove),1:size(model.S,2))
[~,~,model_regScheme_4contMet] = createRegSchemeList(model.S,model_fluxes_to_remove);
end
end
save(sprintf('model_results_IC-%02d_nT-%03d_cov-%02d_rep-%02d.mat',num_IC,nT,cov,rep));