-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathremovefutiles.m
66 lines (54 loc) · 2.5 KB
/
removefutiles.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
function model = removefutiles(model, rxns, directions, checkgrowth, CplexParameters)
% Set properly the desired parameters for cplex LP and MILP
[mipTolInt, scalPar, feasTol, emphPar] = setCplexParamHelper(CplexParameters);
mets = unique(rxns(:,2));
for i = 1:size(mets)
[~, ba] = ismember(rxns(:, 2), mets(i));
to_check = rxns(find(ba), 1);
dir_to_check = directions(find(ba));
[~, ba] = ismember(to_check, model.rxns);
if length(find(ba>0))>1
to_check = to_check(find(ba));
dir_to_check = dir_to_check(find(ba));
pairs = combnk(1:length(to_check),2);
for j = 1:size(pairs, 1)
model_orig = model;
num_constr = size(model.A, 1);
model.rhs(num_constr+1,1) = 1;
model.constraintType{num_constr+1,1} = '<';
if dir_to_check(pairs(j,1))==dir_to_check(pairs(j,2))
rxn1 = strcat('FU_', to_check{pairs(j,1)});
rxn2 = strcat('BU_', to_check{pairs(j,2)});
rxn3 = strcat('BU_', to_check{pairs(j,1)});
rxn4 = strcat('FU_', to_check{pairs(j,2)});
else
rxn1 = strcat('FU_', to_check{pairs(j,1)});
rxn2 = strcat('FU_', to_check{pairs(j,2)});
rxn3 = strcat('BU_', to_check{pairs(j,1)});
rxn4 = strcat('BU_', to_check{pairs(j,2)});
end
model.constraintNames{num_constr+1,1} = strcat('Futile_',rxn1,'_',rxn2,'_',num2str(j));
[~, ba] = ismember(rxn1, model.varNames);
[~, bb] = ismember(rxn2, model.varNames);
[~, bc] = ismember(rxn3, model.varNames);
[~, bd] = ismember(rxn4, model.varNames);
model.A(num_constr+1, ba) = 1;
model.A(num_constr+1, bb) = 1;
num_constr = size(model.A,1);
model.rhs(num_constr+1,1) = 1;
model.constraintNames{num_constr+1,1} = strcat('Futile_',rxn3,'_',rxn4,'_',num2str(j));
model.constraintType{num_constr+1,1} = '<';
model.A(num_constr+1, bc) = 1;
model.A(num_constr+1, bd) = 1;
if checkgrowth
sol = solveTFAmodelCplex(model, 300, [], mipTolInt, emphPar, feasTol, scalPar, []);
if isempty(sol.x)
model = model_orig;
elseif sol.val<0.01
model = model_orig;
end
end
end
end
end
end