-
Notifications
You must be signed in to change notification settings - Fork 0
/
sampleNutrientEnvironments.m
141 lines (126 loc) · 4.44 KB
/
sampleNutrientEnvironments.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
function [aaMat,aaMinMat,aaMaxMat] = sampleNutrientEnvironments(model,nSamples,fileNameSuffix)
%sampleNutrientEnvironments Simulates growth on multiple environmental
%conditions and predicts the amino acid composition of the metabolic
%proteome.
%
% USAGE:
%
% environmentalGrowth(model)
%
% INPUTS:
% model: AcidFBA model structure
%
% nSamples: Number of nutrient combinations
%
% fileNameSuffix: Suffix of the filename to store the output data
%
% OUTPUTS:
% aaMat: nSamples x 20 matrix of amino acid distributions
%
% aaMinMat: nSamples x 20 matrix of min amino acid flux
% (FVA)
%
% aaMaxMat: nSamples x 20 matrix of max amino acid flux
% (FVA)
%
% .. Authors:
% - Vetle Simensen 08/09/21
%% Initialize
rng('default'); % set random seed for reproducibility
params = getParameters;
aaDrains = params.aaDrains;
aaRxnIds = findRxnIDs(model,params.aaDrains);
% Constrain protein availability
protAmount = 0.5;
f = 0.4461;
sigma = 0.44;
model = constrainProtPool(model,protAmount,f,sigma);
% Wild type FBA
wtFBA = optimizeCbModel(model);
wtGrowth = wtFBA.f;
%% Identify viable carbon, nitrogen, phosphorus, and sulfur sources
% By default, the model uses glucose, ammonia, phosphate, and
% sulphate. Test the remaining exchange reactions for viable
% candidates for each elemental nutrient source.
fprintf('Identifying viable nutrient sources... ');
dfltExc = {'r_1714_REV','r_1654_REV','r_2005_REV','r_2060_REV'};
elements = {'C','N','P','S'};
excRxns = model.rxns(findExcRxns(model));
excRxns = excRxns(contains(excRxns,'_REV')); % only uptake rxns
excRxns(ismember(excRxns,'r_2111_REV')) = []; % remove biomass exchange
nExcRxns = length(excRxns);
eleSrcs = zeros(nExcRxns,4);
environment = getEnvironment();
parfor i = 1:nExcRxns
restoreEnvironment(environment);
excRxn = excRxns{i,1};
excMet = findMetsFromRxns(model,excRxn);
excMetIdx = findMetIDs(model,excMet);
metFormula = model.metFormulas{excMetIdx};
for j = 1:4
if contains(metFormula,elements{j})
growthBool = testNutrientSource(model,excRxn,dfltExc{j},j);
eleSrcs(i,j) = growthBool;
end
end
end
% All nutrient combinations
nutrComb = {excRxns(logical(eleSrcs(:,1))),excRxns(logical(eleSrcs(:,2))),excRxns(logical(eleSrcs(:,3))),excRxns(logical(eleSrcs(:,4)))};
n = length(nutrComb);
[nutrComb{:}] = ndgrid(nutrComb{:});
nutrComb = reshape(cat(n + 1,nutrComb{:}),[],n);
nutrComb = nutrComb(randi(length(nutrComb),round(nSamples * 1.5),1),:); % 50% as many combinations in case of infeasible solutions
nNutrComb = length(nutrComb);
fprintf('DONE\n');
%% Calculate amino acid usage when changing only carbon source
fprintf('Simulating optimal growth on various nutrient sources...');
aaMinMat = zeros(nNutrComb,20);
aaMaxMat = zeros(nNutrComb,20);
aaMat = zeros(nNutrComb,20);
environment = getEnvironment();
parfor i = 1:nNutrComb
restoreEnvironment(environment);
simModel = model;
simModel = changeRxnBounds(simModel,dfltExc,0,'u'); % remove default nutrients
simModel = changeRxnBounds(simModel,nutrComb(i,:),1000,'u'); % add new nutrient sources
sol = optimizeCbModel(simModel,'max');
if sol.f > wtGrowth * 0.01 && sol.stat == 1
try
[aaMin,aaMax] = fluxVariability(simModel,99,'max',aaDrains);
catch
aaMin = zeros(1,length(aaDrains));
aaMax = zeros(1,length(aaDrains));
end
aaMat(i,:) = sol.x(aaRxnIds);
aaMinMat(i,:) = aaMin;
aaMaxMat(i,:) = aaMax;
end
end
fprintf('DONE\n');
% Remove superfluous/infeasible samples
aaMat(all(aaMat == 0,2),:) = [];
aaMinMat(all(aaMinMat == 0,2),:) = [];
aaMaxMat(all(aaMaxMat == 0,2),:) = [];
if length(aaMat) > nSamples
aaMat(nSamples + 1:end,:) = [];
aaMinMat(nSamples + 1:end,:) = [];
aaMaxMat(nSamples + 1:end,:) = [];
end
% Save files
writematrix(aaMat,['data/aaMat' fileNameSuffix '.csv']);
writematrix(aaMinMat,['data/aaMinMat' fileNameSuffix '.csv']);
writematrix(aaMaxMat,['data/aaMaxMat' fileNameSuffix '.csv']);
end
function growthBool = testNutrientSource(model,newExc,oldExc,j)
growthBool = 0;
model = changeRxnBounds(model,oldExc,0,'u');
model = changeRxnBounds(model,newExc,1000,'u');
try
sol = optimizeCbModel(model);
if sol.f > 0 && sol.stat == 1
growthBool = 1;
end
catch
fprintf('Failed (%s)\n',str(j));
end
end