forked from bhanum1/CoCulture_KnockOut_Protocol_2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCode3_for_MCS.m
159 lines (139 loc) · 5.75 KB
/
Code3_for_MCS.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
clear;
cd /Users/bhanumamillapalli/Desktop/Models/
addpath('/Users/bhanumamillapalli/Desktop/Models/')
addpath(genpath('/Users/bhanumamillapalli/Desktop/CellNetAnalyzer/'))
startcna(1)
% Cplex Path
addpath('/Applications/CPLEX_Studio1210/cplex/matlab/x86-64_osx')
load MCS_Com_iAF_PP
%% Make a list of all Ex_reactions that remains open
idx.bm = find(ismember(Com.c,1));
idx.o2 = find(contains(Com.rxns,{'EX_o2_e'}));
% Setting the Cplex problem
Cplex_Com.Aeq=Com.S;
Cplex_Com.lb=Com.lb;
Cplex_Com.ub=Com.ub;
Cplex_Com.f=-Com.c;
Cplex_Com.beq=Com.b;
% Run FBA with both organisms growth as objective
Cplex_Com.f(idx.bm(2)) = 0;
FBA_org1=cplexlp(Cplex_Com.f,[],[],Cplex_Com.Aeq,Cplex_Com.beq,Cplex_Com.lb,Cplex_Com.ub);
Cplex_Com.f(idx.bm(2)) = -1;
Cplex_Com.f(idx.bm(1)) = 0;
FBA_org2=cplexlp(Cplex_Com.f,[],[],Cplex_Com.Aeq,Cplex_Com.beq,Cplex_Com.lb,Cplex_Com.ub);
% Set and run pFBA
Nogenes=cellfun(@isempty,Com.grRules);
Nogenes(find(ismember(Com.grRules,strcat(strcat('x(',num2str(find(contains(Com.genes,'shared')))),')')))) = 1; %Do not include the artificial genes
Genes=Nogenes==0;
Cplex_Com.lb(idx.bm) = FBA_org1(idx.bm);
Cplex_Com.f(:,1) = 0;
Cplex_Com.f(Genes,1)=1;
pFBA_org1=cplexlp(Cplex_Com.f,[],[],Cplex_Com.Aeq,Cplex_Com.beq,Cplex_Com.lb,Cplex_Com.ub);
Cplex_Com.lb(idx.bm) = FBA_org2(idx.bm);
pFBA_org2=cplexlp(Cplex_Com.f,[],[],Cplex_Com.Aeq,Cplex_Com.beq,Cplex_Com.lb,Cplex_Com.ub);
% Find all rxns that are always open in both cases
EX_rxns = find(startsWith(Com.rxns,'EX_'));
EX_Open_aero = [Com.rxns(EX_rxns(find(pFBA_org1(EX_rxns)~=0)));...
Com.rxns(EX_rxns(find(pFBA_org2(EX_rxns)~=0)))];
EX_Open_FBA = [Com.rxns(EX_rxns(find(FBA_org1(EX_rxns)~=0)));...
Com.rxns(EX_rxns(find(FBA_org2(EX_rxns)~=0)))];
Keep = [EX_Open_aero;...
Com.rxns(find(ismember(Com.rxns,strrep(strrep(Com.rxns(find(startsWith(Com.rxns,'S_'))),'S_','EX_'),'_s','_e_org1'))));...
Com.rxns(find(ismember(Com.rxns,strrep(strrep(Com.rxns(find(startsWith(Com.rxns,'S_'))),'S_','EX_'),'_s','_e_org2'))))];
%% Make the model
%if ~exist('cnan','var')
% startcna(1);
% wait(parfevalOnAll(@startcna,0,1));
%end
max = 100;
Com.lb(EX_rxns) = 0;
Com.ub(EX_rxns) = 0;
Com.lb(find(ismember(Com.rxns,Keep))) = Cplex_Com.lb(find(ismember(Com.rxns,Keep)));
Com.ub(find(ismember(Com.rxns,Keep))) = Cplex_Com.ub(find(ismember(Com.rxns,Keep)));
% Com.ub(contains(Com.rxns,'EX_') & contains(Com.rxns,'_s') & ~contains(Com.rxns,'_e_org')) = 100;
Com.lb(find(contains(Com.rxns,'tr_s_'))) = -100;
cnap = CNAcobra2cna(Com);
% Add gprRules from Cobra to CNA
cnap = CNAsetGenericReactionData_with_array(cnap,'geneProductAssociation',Com.grRules);
cnap.reacMin(cnap.reacMin==-max) = -inf;
cnap.reacMax(cnap.reacMax== max) = inf;
idx.glc = find(ismember(cnap.reacID,{'EX_glc__D_e_com'}));
idx.atpm_org1 = find(ismember(cnap.reacID,{'ATPM_org1'}));
idx.atpm_org2 = find(ismember(cnap.reacID,{'ATPM_org2'}));
cnap.reacMax(idx.atpm_org1) = inf;
cnap.reacMax(idx.atpm_org2) = inf;
% Uncomment to test feasibility
% FBA = CNAoptimizeFlux(cnap,[],[],2,0,0,[],[]);
% FBA(idx.bm)
% CNAplotPhasePlane(cnap,idx.bm)
%% Set up cMCS input
modules{1}.sense = 'target';
modules{1}.type = 'lin_constraints';
modules{1}.V = zeros(2,cnap.numr);
modules{1}.V(1,idx.bm(1)) = 1;
modules{1}.V(2,idx.bm(2)) = -1;
modules{1}.v = zeros(2,1);
modules{1}.v(2,1) = -0.05;
% modules{1}.v(1,1) = 0.01;
modules{2}.sense = 'target';
modules{2}.type = 'lin_constraints';
modules{2}.V = zeros(2,cnap.numr);
modules{2}.V(1,idx.bm(2)) = 1;
modules{2}.V(2,idx.bm(1)) = -1;
modules{2}.v = zeros(2,1);
modules{2}.v(2,1) = -0.05;
% modules{1}.v(1,1) = 0.01;
modules{3}.sense = 'desired';
modules{3}.type = 'lin_constraints';
modules{3}.V = zeros(1,cnap.numr);
modules{3}.V(1,idx.bm(1)) = -1;
modules{3}.v = -0.05;
modules{4}.sense = 'desired';
modules{4}.type = 'lin_constraints';
modules{4}.V = zeros(1,cnap.numr);
modules{4}.V(1,idx.bm(2)) = -1;
modules{4}.v = -0.05;
% modules{5}.sense = 'target';
% modules{5}.type = 'lin_constraints';
% modules{5}.V = zeros(2,cnap.numr);
% modules{5}.V(1,find(ismember(Com.rxns,'AKGtr_s_org1'))) = 1;
% modules{5}.V(2,find(ismember(Com.rxns,'GLU__Ltr_s_org2'))) = -1;
% modules{5}.v = zeros(2,1);
% modules{5}.v(1,:) = 0.01;
% modules{5}.v(2,:) = -0.01;
%% Rxns should not feasible ko
rkoCost = ones(cnap.numr,1);
rkoCost(find(ismember(Genes,0))) = nan;
rkoCost(find(contains(Com.rxns,'H2Ot_'))) = nan;
rkoCost(find(contains(Com.rxns,'tr_s_'))) = nan;
rkiCost = nan(cnap.numr,1);
% rkiCost(find(contains(Com.rxns,'_s_org'))) = 1;
% specifying gene knockout costs
% Generate list of genes as a template to define k/o genes
% [~,~,genes,gpr_rules] = CNAgenerateGPRrules(cnap);
% gkoCost = ones(numel(genes),1);
% gkiCost = nan(numel(genes),1);
% gkiCost(find(ismember(genes,strcat('x',num2str(find(contains(Com.genes,'shared'))))))) = 0;
maxSolutions = 10;
maxCost = 100;
options.milp_solver = 'cplex';
options.milp_time_limit = 43200;
% options.milp_bigM = 10000; %Try true, options.seed (change could help)
options.mcs_search_mode = 1;
verbose = 1;
%% Run cMCS and save outcome
[mcs, status, cmp_mcs, cmp_cnap, mcs_idx_cmp_full, obj] = ...
CNAMCSEnumerator3(cnap,modules,rkoCost,rkiCost,maxSolutions,maxCost,options,verbose);
% [mcs, status, cmp_mcs, cmp_cnap, mcs_idx_cmp_full, obj] = ...
% CNAgeneMCSEnççççumerator3(cnap,modules,{},{},maxSolutions,maxCost,gkoCost,gkiCost,{},options,verbose);
Com.keep = Keep;
save ('ComStrategyiAF_PP_test.mat','Com','cnap','mcs');
%save ('MCS_ComCore_test.mat','Com','cnap','idx')
mcs_test = mcs(:,1);
cnap_original = cnap;
cnap.reacMin(mcs_test == -1) = 0;
cnap.reacMax(mcs_test == -1) = 0;
CNAplotPhasePlane(cnap,idx.bm)
cnap.objFunc(idx.bm(1)) = 0;
FBA = CNAoptimizeFlux(cnap,[],[],2,0,0,[],[]);
FBA(idx.bm)