-
Notifications
You must be signed in to change notification settings - Fork 0
/
calcGCS.asv
227 lines (192 loc) · 6.44 KB
/
calcGCS.asv
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
%function gcs = calcGCS(results)
% Calculate GCS according to the yield space area
function gcs = calcGCS(results, results_WT)
%% Calculate wild type yield space area
yRange = results_WT.yieldR;
% rmRange = results_WT.muR;
mRange = results_WT.bmYield;
[muMaxWT,posMuMaxWT] = max(mRange);
intPart = 0;
if yRange(posMuMaxWT) == 0
% calculate Ober/Untersumme
for i=1:(length(mRange)-1)
sumO = (mRange(i)-mRange(i+1))*yRange(i);
sumU = (mRange(i)-mRange(i+1))*yRange(i+1);
intPart = ((sumO+sumU)/2)+intPart;
end
areaWT = intPart;
else
% if GC occurs in WT
for i=1:(posMuMaxWT-1)
sumO = (-mRange(i)+mRange(i+1))*yRange(i);
sumU = (-mRange(i)+mRange(i+1))*yRange(i+1);
intPart = ((sumO+sumU)/2)+intPart;
end
ysLow = intPart;
intPart = 0;
for i=posMuMaxWT:(length(mRange)-1)
sumO = (mRange(i)-mRange(i+1))*yRange(i);
sumU = (mRange(i)-mRange(i+1))*yRange(i+1);
intPart = ((sumO+sumU)/2)+intPart;
end
% areaWT = intPart-ysLow;
areaWT = intPart;
end
% %% Calculate mutant yield space area
% yRange = results.printData.yieldR;
% mRange = results.printData.muR;
% pRange = results.printData.prodR;
%
% [muMax,posMuMax] = max(mRange);
%
% intPart = 0;
% for i=1:(posMuMax-1)
% sumO = (mRange(i+1)-mRange(i))*yRange(i);
% sumU = (mRange(i+1)-mRange(i))*yRange(i+1);
% intPart = ((sumO+sumU)/2)+intPart;
% end
% areaMutLow = intPart;
%
% intPart = 0;
% for i=posMuMax:(length(mRange)-1)
% sumO = (mRange(i)-mRange(i+1))*yRange(i);
% sumU = (mRange(i)-mRange(i+1))*yRange(i+1);
% intPart = ((sumO+sumU)/2)+intPart;
% end
%
% areaMut = intPart-areaMutLow;
%
% gcs = -areaMut/areaWT;
%% Alternative Calculate GCS for mutant
% Determine maximal growth rate for mutant
yRangeMut = results.printData.yieldR;
mRangeMut = results.printData.muR;
% yRangeMut = results.yieldR;
% mRangeMut = results.muR;
% pRangeMut = results.prodR;
yRangeWT = results_WT.yieldR;
mRangeWT = results_WT.muR;
[muMax,posMuMax] = max(mRangeMut);
yMuMax = yRangeMut(posMuMax);
% area below mutant yield space
intPart = 0;
for i=1:(posMuMax-1)
sumO = (mRangeMut(i+1)-mRangeMut(i))*yRangeMut(i);
sumU = (mRangeMut(i+1)-mRangeMut(i))*yRangeMut(i+1);
intPart = ((sumO+sumU)/2)+intPart;
end
areaMutLow = intPart;
% area above mutant production envelop
% determine growth rate in wild type data
[muMax_wt,posMuMax_wt] = max(mRangeWT);
for i=posMuMax_wt(end):length(mRangeWT)
if mRangeWT(i)<=muMax
posMuMax_mut_wt = i;
break
end
end
% recalculate position f maximal growth (adapt to closest to wild type)
prev_muDiff = abs(mRangeMut(posMuMax)-mRangeWT(posMuMax_mut_wt));
posMuMax_recalc = [];
for i=posMuMax+1:length(mRangeMut)
muDiff = abs(mRangeMut(i)-mRangeWT(posMuMax_mut_wt));
if muDiff > prev_muDiff
posMuMax_recalc = i-1;
break
else
prev_muDiff = muDiff;
end
end
if isempty(posMuMax_recalc)
posMuMax_recalc = posMuMax;
end
intPart = 0;
for i=(posMuMax_recalc):(length(mRangeMut)-1)
sumO = (mRangeMut(i)-mRangeMut(i+1))*yRangeMut(i);
sumU = (mRangeMut(i)-mRangeMut(i+1))*yRangeMut(i+1);
intPart = ((sumO+sumU)/2)+intPart;
end
areaMutHigh = intPart;
intPart = 0;
for i=posMuMax_mut_wt:(length(mRangeWT)-1)
sumO = (mRangeWT(i)-mRangeWT(i+1))*yRangeWT(i);
sumU = (mRangeWT(i)-mRangeWT(i+1))*yRangeWT(i+1);
intPart = ((sumO+sumU)/2)+intPart;
end
areaWtHigh = intPart;
areaDiff_mut_wt = areaWtHigh-areaMutHigh;
% area wild type yield space beyond maximal growth rate of mutant
intPart_low = 0;
intPart_high = 0;
pos = 1;
for i=1:(length(mRange)-1)
if mRangeWT(i) >= muMax
if mRangeWT(i) == muMaxWT
pos = 0;
end
if pos
sumO = (-mRangeWT(i)+mRangeWT(i+1))*yRangeWT(i);
sumU = (-mRangeWT(i)+mRangeWT(i+1))*yRangeWT(i+1);
intPart_low = ((sumO+sumU)/2)+intPart_low;
else
sumO = (mRangeWT(i)-mRangeWT(i+1))*yRangeWT(i);
sumU = (mRangeWT(i)-mRangeWT(i+1))*yRangeWT(i+1);
intPart_high = ((sumO+sumU)/2)+intPart_high;
end
end
end
areaWTMuMax = intPart_high-intPart_low;
% for i=1:(length(mRange)-1)
% if yRangeWT(i) > yMuMax
% % if yield at maximal growth of the mutant is not on wild type
% % yield space hull curve
% intPart = intPart+(mRangeWT(i-1)-muMax)*((yRangeWT(i-1)+yMuMax)/2)
% break;
% else
% sumO = (mRangeWT(i)-mRangeWT(i+1))*yRangeWT(i);
% sumU = (mRangeWT(i)-mRangeWT(i+1))*yRangeWT(i+1);
% intPart = ((sumO+sumU)/2)+intPart;
% end
% end
% areaWTMuMax = intPart;
%
if 0
% if yRange(posMuMax) ~= 0
intPart = 0;
for i=1:posMuMaxWT
sumO = (mRangeWT(i+1)-mRangeWT(i))*yRangeWT(i);
sumU = (mRangeWT(i+1)-mRangeWT(i))*yRangeWT(i+1);
intPart = ((sumO+sumU)/2)+intPart;
end
areaWTLow = intPart;
else
areaWTLow = 0;
end
% % consider WT area beyond mu max of the mutant
% areaLow = areaWTMuMax+areaMutLow-areaWTLow;
% DO NOT consider WT area beyond mu max of the mutant
areaLow = areaMutLow-areaWTLow;
% areaWT
% areaDiff_mut_wt
% areaWTMuMax
[yMin,~] = min(yRangeMut); % minimal accessible yield
muMaxYzero = sum(mRangeMut(yRangeMut==0));
% Account for guaranteed yield at maximal growth
[minGY,~] = min(yRangeMut(mRangeMut==muMax));
[maxY,~] = max(yRange);
% Calculate GCS (case analysis)
if abs(areaWT-areaWTMuMax) < 1e-4
gcs = -2;
else
if yMin > 0
% gcs = ((areaLow-areaDiff_mut_wt)/(areaWT-areaWTMuMax))*(minGY/maxY);
gcs = ((areaLow)/(areaWT-areaWTMuMax))*(minGY/maxY);
elseif yMin == 0 && muMaxYzero == 0
% gcs = -1+((areaLow/(areaWT+areaDiff_mut_wt-areaWTMuMax))*(minGY/maxY));
gcs = -1+(((areaLow)/(areaWT-areaWTMuMax))*(minGY/maxY));
elseif muMaxYzero > 0
% gcs = -2+((areaLow/(areaWT+areaDiff_mut_wt-areaWTMuMax))*(minGY/maxY));
gcs = -2+(((areaLow)/(areaWT-areaWTMuMax))*(minGY/maxY));
end
end
end