-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCOUR_Yeast_noisy.m
458 lines (382 loc) · 24.1 KB
/
SCOUR_Yeast_noisy.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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
function SCOUR_Yeast_noisy(nT,cov,num_IC,rep)
warning('off','all')
rng('shuffle');
fprintf('Starting machine learning framework...\n');
%% Initial Preparation of Hynne yeast model
% Train on autogenerated data, test on Hynne yeast model
% yeast stoichiometric interactions
load('hynneSTM.mat');
Hynne.S = stm;
% Find Hynne mass action (MA) interactions
[row_HynneMA col_HynneMA] = find(Hynne.S < 0);
HynneMA = [row_HynneMA col_HynneMA];
unique_flux = unique(HynneMA(:,2));
count_1contMet = 1;
count_2contMet = 1;
for i = 1:length(unique_flux)
controller_met_idx = find(HynneMA(:,2) == unique_flux(i));
if length(HynneMA(controller_met_idx,1)) == 1
HynneMA_1contMet_List(count_1contMet,:) = [HynneMA(controller_met_idx,1)' unique_flux(i)];
count_1contMet = count_1contMet + 1;
elseif length(HynneMA(controller_met_idx,1)) == 2
HynneMA_2contMet_List(count_2contMet,:) = [HynneMA(controller_met_idx,1)' unique_flux(i)];
count_2contMet = count_2contMet + 1;
end
end
Hynne_prefix = 'hynne';
%% Identify 1 controller metabolite reactions
% List of Hynne interactions with one controller metabolite
true_1contMet_Hynne = [14,11;
17,14;
19,17;
20,19;
3,23;];
count = 1;
for regIdx = 1:length(HynneMA_1contMet_List)
for trueIdx = 1:size(true_1contMet_Hynne,1)
if isequal(HynneMA_1contMet_List(regIdx,:),true_1contMet_Hynne(trueIdx,:))
Hynne_1contMet_trueInRegIdx(count,1) = regIdx;
count = count + 1;
end
end
end
% 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_hynne_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_Hynne_n = (featureMatrix_1contMet_Hynne-prctile(featureMatrix_1contMet_Hynne,20,2))./(prctile(featureMatrix_1contMet_Hynne,80)-prctile(featureMatrix_1contMet_Hynne,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');
% Hynne
% Setup testing set and testing label
testingSet_Hynne_1contMet = featureMatrix_1contMet_Hynne_n;
testingLabel_Hynne_1contMet = logical(zeros(size(testingSet_Hynne_1contMet,2),1));
testingLabel_Hynne_1contMet(Hynne_1contMet_trueInRegIdx) = 1;
% Predict where 1 controller metabolite reactions occur in yeast
% model
predictedLabel_RF_Hynne_1contMet = Mdl_RF_1contMet.predict(testingSet_Hynne_1contMet');
predictedLabel_KNN_Hynne_1contMet = double(Mdl_KNN_1contMet.predict(testingSet_Hynne_1contMet'));
predictedLabel_SNN_Hynne_1contMet = Mdl_SNN_1contMet(testingSet_Hynne_1contMet)';
predictedLabel_DA_Hynne_1contMet = double(Mdl_DA_1contMet.predict(testingSet_Hynne_1contMet'));
predictedLabel_L1_Hynne_1contMet = [predictedLabel_RF_Hynne_1contMet predictedLabel_KNN_Hynne_1contMet predictedLabel_SNN_Hynne_1contMet predictedLabel_DA_Hynne_1contMet];
if ~isempty(poor_classifier_1contMet)
predictedLabel_L1_Hynne_1contMet(:,poor_classifier_1contMet) = [];
end
predictedLabel_L2_Hynne_1contMet = Mdl_DA_meta_1contMet.predict(predictedLabel_L1_Hynne_1contMet)
% Accuracy, sensitivity, and specificity calculations
predictionAccuracy_Hynne_1contMet = sum(predictedLabel_L2_Hynne_1contMet==testingLabel_Hynne_1contMet)/length(testingLabel_Hynne_1contMet)
fp = 0;
fn = 0;
for k = 1:length(testingLabel_Hynne_1contMet)
if testingLabel_Hynne_1contMet(k) == 1 && predictedLabel_L2_Hynne_1contMet(k) == 0
fn = fn + 1;
elseif testingLabel_Hynne_1contMet(k) == 0 && predictedLabel_L2_Hynne_1contMet(k) == 1
fp = fp + 1;
end
end
tp = 0;
tn = 0;
for k = 1:length(testingLabel_Hynne_1contMet)
if testingLabel_Hynne_1contMet(k) == 1 && predictedLabel_L2_Hynne_1contMet(k) == 1
tp = tp + 1;
elseif testingLabel_Hynne_1contMet(k) == 0 && predictedLabel_L2_Hynne_1contMet(k) == 0
tn = tn + 1;
end
end
sensitivity_Hynne_1contMet = tp / (fn+tp)
specificity_Hynne_1contMet = tn / (tn+fp)
ppv_Hynne_1contMet = tp / (tp+fp);
npv_Hynne_1contMet = tp / (tn+fn);
%% Remove 1 controller metabolite reactions
% Remove from Hynne using predicted 1 controller metabolite
% interactions
predicted_Hynne_1contMet = [HynneMA_1contMet_List(find(predictedLabel_L2_Hynne_1contMet==1),:)];
Hynne_fluxes_to_remove = unique([1 predicted_Hynne_1contMet(:,2)']);
%Hynne_fluxes_to_remove = unique([1 11 14 17 19 23]);
if ~isequal(sort(Hynne_fluxes_to_remove),1:size(Hynne.S,2))
Hynne_regScheme_2contMet = createRegSchemeList_hynne(Hynne.S,Hynne_fluxes_to_remove);
end
if exist('Hynne_regScheme_2contMet','var')
%% Identify 2 controller metabolite reactions
% List of Hynne interactions with two controller metabolites
true_2contMet_Hynne = [2,3,3;
4,6,4;
8,9,7;
5,13,10;
12,15,12;
16,17,13;
18,19,16;
15,20,18;
20,21,20;
3,4,22;];
count = 1;
for regIdx = 1:length(Hynne_regScheme_2contMet)
for trueIdx = 1:size(true_2contMet_Hynne,1)
if isequal(Hynne_regScheme_2contMet(regIdx,:),true_2contMet_Hynne(trueIdx,:))
Hynne_2contMet_trueInRegIdx(count,1) = regIdx;
count = count + 1;
end
end
end
% 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_hynne_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');
% Hynne
% Setup testing set and testing label
testingSet_Hynne_2contMet = featureMatrix_2contMet_Hynne_n;
testingLabel_Hynne_2contMet = logical(zeros(size(testingSet_Hynne_2contMet,2),1));
if exist('Hynne_2contMet_trueInRegIdx','var')
testingLabel_Hynne_2contMet(Hynne_2contMet_trueInRegIdx) = 1;
end
% Predict where 2 controller metabolite reactions occur in yeast
% model
predictedLabel_RF_Hynne_2contMet = Mdl_RF_2contMet.predict(testingSet_Hynne_2contMet');
predictedLabel_KNN_Hynne_2contMet = double(Mdl_KNN_2contMet.predict(testingSet_Hynne_2contMet'));
predictedLabel_SNN_Hynne_2contMet = Mdl_SNN_2contMet(testingSet_Hynne_2contMet)';
predictedLabel_DA_Hynne_2contMet = double(Mdl_DA_2contMet.predict(testingSet_Hynne_2contMet'));
predictedLabel_L1_Hynne_2contMet = [predictedLabel_RF_Hynne_2contMet predictedLabel_KNN_Hynne_2contMet predictedLabel_SNN_Hynne_2contMet predictedLabel_DA_Hynne_2contMet];
if ~isempty(poor_classifier_2contMet)
predictedLabel_L1_Hynne_2contMet(:,poor_classifier_2contMet) = [];
end
predictedLabel_L2_Hynne_2contMet = Mdl_DA_meta_2contMet.predict(predictedLabel_L1_Hynne_2contMet)
% Accuracy, sensitivity, and specificity calculations
predictionAccuracy_Hynne_2contMet = sum(predictedLabel_L2_Hynne_2contMet==testingLabel_Hynne_2contMet)/length(testingLabel_Hynne_2contMet)
fp = 0;
fn = 0;
for k = 1:length(testingLabel_Hynne_2contMet)
if testingLabel_Hynne_2contMet(k) == 1 && predictedLabel_L2_Hynne_2contMet(k) == 0
fn = fn + 1;
elseif testingLabel_Hynne_2contMet(k) == 0 && predictedLabel_L2_Hynne_2contMet(k) == 1
fp = fp + 1;
end
end
tp = 0;
tn = 0;
for k = 1:length(testingLabel_Hynne_2contMet)
if testingLabel_Hynne_2contMet(k) == 1 && predictedLabel_L2_Hynne_2contMet(k) == 1
tp = tp + 1;
elseif testingLabel_Hynne_2contMet(k) == 0 && predictedLabel_L2_Hynne_2contMet(k) == 0
tn = tn + 1;
end
end
sensitivity_Hynne_2contMet = tp / (fn+tp)
specificity_Hynne_2contMet = tn / (tn+fp)
ppv_Hynne_2contMet = tp / (tp+fp);
npv_Hynne_2contMet = tp / (tn+fn);
%% Remove 2 controller metabolite reactions
% Remove from Hynne using predicted 2 controller metabolite
% interactions
predicted_Hynne_2contMet = [Hynne_regScheme_2contMet(find(predictedLabel_L2_Hynne_2contMet==1),:)];
Hynne_fluxes_to_remove = unique([1 predicted_Hynne_1contMet(:,2)' predicted_Hynne_2contMet(:,3)']);
%Hynne_fluxes_to_remove = unique([1 11 14 17 19 23 3 4 7 10 12 13 16 18 20 22]);
if ~isequal(sort(Hynne_fluxes_to_remove),1:size(Hynne.S,2))
[~,Hynne_regScheme_3contMet] = createRegSchemeList_hynne(Hynne.S,Hynne_fluxes_to_remove);
end
end
if exist('Hynne_regScheme_3contMet','var')
%% Identify 3 controller metabolite reactions
% List of Hynne interactions with three controller metabolites
true_3contMet_Hynne = [1 2 4,2;
3 6 22,5;
7 8 9,6;
9 10 12,15;
3 5 22,24];
count = 1;
for regIdx = 1:length(Hynne_regScheme_3contMet)
for trueIdx = 1:size(true_3contMet_Hynne,1)
if isequal(Hynne_regScheme_3contMet(regIdx,:),true_3contMet_Hynne(trueIdx,:))
Hynne_3contMet_trueInRegIdx(count,1) = regIdx;
count = count + 1;
end
end
end
% 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_hynne_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');
% Hynne
% Setup testing set and testing label
testingSet_Hynne_3contMet = featureMatrix_3contMet_Hynne_n;
testingLabel_Hynne_3contMet = logical(zeros(size(testingSet_Hynne_3contMet,2),1));
if exist('Hynne_3contMet_trueInRegIdx','var')
testingLabel_Hynne_3contMet(Hynne_3contMet_trueInRegIdx) = 1;
end
% Predict where 3 controller metabolite reactions occur in yeast
% model
predictedLabel_RF_Hynne_3contMet = Mdl_RF_3contMet.predict(testingSet_Hynne_3contMet');
predictedLabel_KNN_Hynne_3contMet = double(Mdl_KNN_3contMet.predict(testingSet_Hynne_3contMet'));
predictedLabel_SNN_Hynne_3contMet = Mdl_SNN_3contMet(testingSet_Hynne_3contMet)';
predictedLabel_DA_Hynne_3contMet = double(Mdl_DA_3contMet.predict(testingSet_Hynne_3contMet'));
predictedLabel_L1_Hynne_3contMet = [predictedLabel_RF_Hynne_3contMet predictedLabel_KNN_Hynne_3contMet predictedLabel_SNN_Hynne_3contMet predictedLabel_DA_Hynne_3contMet];
if ~isempty(poor_classifier_3contMet)
predictedLabel_L1_Hynne_3contMet(:,poor_classifier_3contMet) = [];
end
predictedLabel_L2_Hynne_3contMet = Mdl_DA_meta_3contMet.predict(predictedLabel_L1_Hynne_3contMet)
% Accuracy, sensitivity, and specificity calculations
predictionAccuracy_Hynne_3contMet = sum(predictedLabel_L2_Hynne_3contMet==testingLabel_Hynne_3contMet)/length(testingLabel_Hynne_3contMet)
fp = 0;
fn = 0;
for k = 1:length(testingLabel_Hynne_3contMet)
if testingLabel_Hynne_3contMet(k) == 1 && predictedLabel_L2_Hynne_3contMet(k) == 0
fn = fn + 1;
elseif testingLabel_Hynne_3contMet(k) == 0 && predictedLabel_L2_Hynne_3contMet(k) == 1
fp = fp + 1;
end
end
tp = 0;
tn = 0;
for k = 1:length(testingLabel_Hynne_3contMet)
if testingLabel_Hynne_3contMet(k) == 1 && predictedLabel_L2_Hynne_3contMet(k) == 1
tp = tp + 1;
elseif testingLabel_Hynne_3contMet(k) == 0 && predictedLabel_L2_Hynne_3contMet(k) == 0
tn = tn + 1;
end
end
sensitivity_Hynne_3contMet = tp / (fn+tp)
specificity_Hynne_3contMet = tn / (tn+fp)
ppv_Hynne_3contMet = tp / (tp+fp);
npv_Hynne_3contMet = tp / (tn+fn);
%% Remove 3 controller metabolite reactions
% Remove from Hynne using predicted 3 controller metabolite
% interactions
predicted_Hynne_3contMet = [Hynne_regScheme_3contMet(find(predictedLabel_L2_Hynne_3contMet==1),:)];
Hynne_fluxes_to_remove = unique([1 predicted_Hynne_1contMet(:,2)' predicted_Hynne_2contMet(:,3)' predicted_Hynne_3contMet(:,4)']);
%Hynne_fluxes_to_remove = unique([1 11 14 17 19 23 3 4 7 10 12 13 16 18 20 22 2 5 6 15 24]);
if ~isequal(sort(Hynne_fluxes_to_remove),1:size(Hynne.S,2))
[~,~,Hynne_regScheme_4contMet] = createRegSchemeList_hynne(Hynne.S,Hynne_fluxes_to_remove);
end
end
save(sprintf('yeast_results_IC-%02d_nT-%03d_cov-%02d_rep-%02d.mat',num_IC,nT,cov,rep));