-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_muncher_code.py
376 lines (307 loc) · 10.8 KB
/
data_muncher_code.py
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
import openpyxl as xlsx
import numpy as np
import matplotlib.pyplot as plt
import data_muncher as dm
from scipy.optimize import fmin
#Loading the 16_07_09 plate reader file
fnew = '16_07_09 ss13 growth curve data new.xlsx'
ex = dm.Experiment(fnew);
data_series = ex.read('Time [s]')
time_labels = data_series.list_of_series[0]
PlateReadout = dm.Sample();
row_ids = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
column_ids = map(str, range(1, 13))
well_ids = [ r + c for r in row_ids for c in column_ids if ex.search(r + c)]
for w in well_ids:
W = dm.Well();
W.measurements = ex.read(w) #Read well data vertically in columns from plate reader spreadsheet
PlateReadout.addWell(w, W)
data_series = PlateReadout.get_measurements()
#Assigning Samples from plate layout
#SS07 1/10 dilution
SS07_10 = dm.Sample()
SS07_10.addWell('A10', PlateReadout['A10'])
SS07_10.addWell('A11', PlateReadout['A11'])
SS07_10.addWell('A12', PlateReadout['A12'])
#SS07 1/20 dilution
SS07_20 = dm.Sample()
SS07_20.addWell('B10', PlateReadout['B10'])
SS07_20.addWell('B11', PlateReadout['B11'])
SS07_20.addWell('B12', PlateReadout['B12'])
#SS13 preinduced 1/10 dilution
SS13pre_10 = dm.Sample()
SS13pre_10.addWell('C10', PlateReadout['C10'])
SS13pre_10.addWell('C11', PlateReadout['C11'])
SS13pre_10.addWell('C12', PlateReadout['C12'])
#SS13 preinduced 1/20 dilution
SS13pre_20 = dm.Sample()
SS13pre_20.addWell('D10', PlateReadout['D10'])
SS13pre_20.addWell('D11', PlateReadout['D11'])
SS13pre_20.addWell('D12', PlateReadout['D12'])
#SS13 postinduced 1/10 dilution
SS13post_10 = dm.Sample()
SS13post_10.addWell('E10', PlateReadout['E10'])
SS13post_10.addWell('E11', PlateReadout['E11'])
SS13post_10.addWell('E12', PlateReadout['E12'])
#SS13 postinduced 1/20 dilution
SS13post_20 = dm.Sample()
SS13post_20.addWell('F10', PlateReadout['F10'])
SS13post_20.addWell('F11', PlateReadout['F11'])
SS13post_20.addWell('F12', PlateReadout['F12'])
#SS13 uninduced 1/10 dilution
SS13un_10 = dm.Sample()
SS13un_10.addWell('G10', PlateReadout['G10'])
SS13un_10.addWell('G11', PlateReadout['G11'])
SS13un_10.addWell('G12', PlateReadout['G12'])
#SS13 uninduced 1/20 dilution
SS13un_20 = dm.Sample()
SS13un_20.addWell('H10', PlateReadout['H10'])
SS13un_20.addWell('H11', PlateReadout['H11'])
#SS13un_20.addWell('H12', PlateReadout['H12'])
#It cannot find H12
# Luria Broth
LB = dm.Sample()
LB.addWell('H9', PlateReadout['H9'])
LB.addWell('H8', PlateReadout['H8'])
LB.addWell('H7', PlateReadout['H7'])
#List all of the wells in the data file
print(PlateReadout)
#Graph the growth curve for 1:10 dilution
plt.plot(time_labels,SS07_10.mean())
plt.plot(time_labels,SS13pre_10.mean())
plt.plot(time_labels,SS13post_10.mean())
plt.plot(time_labels,SS13un_10.mean())
plt.plot(time_labels, LB.mean())
plt.ylabel('optical density (OD)')
plt.xlabel('Time (sec)')
#plt.legend(['SS07', 'SS13++', 'SS13-+', 'SS13--', 'Blank'])
plt.title('Optical Density for 1/10 Diltuion Factor')
plt.show()
#Graph the growth curve for 1:20 dilution
plt.plot(time_labels,SS07_20.mean())
plt.plot(time_labels,SS13pre_20.mean())
plt.plot(time_labels,SS13post_20.mean())
plt.plot(time_labels,SS13un_20.mean())
plt.plot(time_labels, LB.mean())
plt.ylabel('optical density (OD)')
plt.xlabel('Time (sec)')
#plt.legend(['SS07', 'SS13++', 'SS13-+', 'SS13--', 'Blank'])
plt.title('Optical Density for 1/20 Diltuion Factor')
plt.show()
#Subtract the Mean of the Blank from the Mean of each Data Series
LB_a = np.asarray(LB.mean())
LBstd = np.asarray(LB.std());
# LOQ is the standard deviation of the blank multiplied by 3
LOQ = 3 * LBstd
#The 1:10 Dilution Data with the Blank subtracted and 3 times the LOQ masked
SS07_10_a = np.asarray(SS07_10.mean())
SS07_10_a = SS07_10_a - LB_a
mask = (SS07_10_a > LOQ)
SS07_10_a[mask]
SS13pre_10_a = np.asarray(SS13pre_10.mean())
SS13pre_10_a = SS13pre_10_a - LB_a
mask = SS13pre_10_a > LOQ
SS13pre_10_a[mask]
SS13post_10_a = np.asarray(SS13post_10.mean())
SS13post_10_a = SS13post_10_a - LB_a
mask = SS13post_10_a > LOQ
SS13post_10_a[mask]
SS13un_10_a = np.asarray(SS13un_10.mean())
SS13un_10_a = SS13un_10_a - LB_a
mask = SS13un_10_a > LOQ
SS13un_10_a[mask]
#The 1:20 Dilution Data with the Blank subtracted at 3 times the LOQ masked
SS07_20_a = np.asarray(SS07_20.mean())
SS07_20_a = SS07_20_a - LB_a
mask = SS07_20_a > LOQ
SS07_20_a[mask]
SS13pre_20_a = np.asarray(SS13pre_20.mean())
SS13pre_20_a = SS13pre_20_a - LB_a
mask = SS13pre_20_a > LOQ
SS13pre_20_a[mask]
SS13post_20_a = np.asarray(SS13post_20.mean())
SS13post_20_a = SS13post_20_a - LB_a
mask = SS13post_20_a > LOQ
SS13pre_20_a[mask]
SS13un_20_a = np.asarray(SS13un_20.mean())
SS13un_20_a = SS13un_20_a - LB_a
mask = SS13un_20_a > LOQ
SS13un_20_a[mask]
#Translating from ODE to ADF for all of the data
# ADF(Arbitrary Dilution Factor) --> ACF(Arbitrary Cell/Concentration Factor)
# y(ACF) = a(ODE)^2 + b(ODE) + c
a = 0.3433
b = 1.2228
c = -0.0603
SS07_10_ACF = list()
for value in SS07_10_a[mask]:
ACF = a * value * value + b * value + c
SS07_10_ACF.append(ACF)
SS07_10_ACF = np.asarray([ a * value * value + b * value + c for value in SS07_10_a[mask] ])
SS13pre_10_ACF = list()
for value in SS13pre_10_a[mask]:
ACF = a * value * value + b * value + c
SS13pre_10_ACF.append(ACF)
SS13post_10_ACF = list()
for value in SS13post_10_a[mask]:
ACF = a * value * value + b * value + c
SS13post_10_ACF.append(ACF)
SS13un_10_ACF = list()
for value in SS13un_10_a[mask]:
ACF = a * value *value + b * value + c
SS13un_10_ACF.append(ACF)
#Translating from ODE to ADF for 1:20 dilution data
SS07_20_ACF = list()
for value in SS07_20_a[mask]:
ACF = a * value *value + b * value + c
SS07_20_ACF.append(ACF)
SS13pre_20_ACF = list()
for value in SS13pre_20_a[mask]:
ACF = a * value * value + b * value + c
SS13pre_20_ACF.append(ACF)
SS13post_20_ACF = list()
for value in SS13post_20_a[mask]:
ACF = a * value * value + b * value + c
SS13post_20_ACF.append(ACF)
SS13un_20_ACF = list()
for value in SS13un_20_a[mask]:
ACF = a * value * value + b * value + c
SS13un_20_ACF.append(ACF)
plt.plot(time_labels,SS07_10_ACF)
plt.plot(time_labels,SS13pre_10_ACF)
plt.plot(time_labels,SS13post_10_ACF)
plt.plot(time_labels,SS13un_10_ACF)
plt.plot(time_labels, LB.mean())
plt.ylabel('ACF')
plt.xlabel('Time (sec)')
#plt.legend(['SS07', 'SS13++', 'SS13-+', 'SS13--', 'Blank'])
plt.title('Optical Density for 1/10 Diltuion Factor')
plt.show()
#Graph the growth curve for 1:20 dilution
plt.plot(time_labels,SS07_20_ACF)
plt.plot(time_labels,SS13pre_20_ACF)
plt.plot(time_labels,SS13post_20_ACF)
plt.plot(time_labels,SS13un_20_ACF)
plt.plot(time_labels, LB.mean())
plt.ylabel('optical density (OD)')
plt.xlabel('Time (sec)')
#plt.legend(['SS07', 'SS13++', 'SS13-+', 'SS13--', 'Blank'])
plt.title('Optical Density for 1/20 Diltuion Factor')
plt.show()
'''
#Estimating the initial point of the graph by doing a 1:1000 dilution for
#smallest value that was calculated for the ACF for each data set
#Once the guess is made it is then added the beginning of each array
Initial_SS07_10_ACF = SS07_10_ACF[0] / 1000
SS07_10_ACF = np.asarray(SS07_10_ACF)
SS07_10_ACF = np.insert(SS07_10_ACF, 0, Initial_SS07_10_ACF)
Initial_SS13pre_10_ACF = SS13pre_10_ACF[0] / 1000
SS13pre_10_ACF = np.asarray(SS13pre_10_ACF)
SS13pre_10_ACF = np.insert(SS13pre_10_ACF, 0, Initial_SS13pre_10_ACF)
Initial_SS13post_10_ACF = SS13post_10_ACF[0] / 1000
SS13post_10_ACF = np.asarray(SS13post_10_ACF)
SS13post_10_ACF = np.insert(SS13post_10_ACF, 0, Initial_SS13post_10_ACF)
Initial_SS13un_10_ACF = SS13un_10_ACF[0] / 1000
SS13un_10_ACF = np.asarray(SS13un_10_ACF)
SS13un_10_ACF = np.insert(SS13un_10_ACF, 0, Initial_SS13un_10_ACF)
#ACF addition for 1:20 Dilution
Initial_SS07_20_ACF = SS07_20_ACF[0] / 1000
SS07_20_ACF = np.asarray(SS07_20_ACF)
SS07_20_ACF = np.insert(SS07_20_ACF, 0, Initial_SS07_20_ACF)
Initial_SS13pre_20_ACF = SS13pre_20_ACF[0] / 1000
SS13pre_20_ACF = np.asarray(SS13pre_20_ACF)
SS13pre_20_ACF = np.insert(SS13pre_20_ACF, 0, Initial_SS13pre_20_ACF)
Initial_SS13post_20_ACF = SS13post_20_ACF[0] / 1000
SS13post_20_ACF = np.asarray(SS13post_20_ACF)
SS13post_20_ACF = np.insert(SS13post_20_ACF, 0, Initial_SS13post_20_ACF)
Initial_SS13un_20_ACF = SS13un_20_ACF[0] / 1000
SS13un_20_ACF = np.asarray(SS13un_20_ACF)
SS13un_20_ACF = np.insert(SS13un_20_ACF, 0, Initial_SS13un_20_ACF)
'''
# The 1:10 dilution normalization
maxVal = SS07_10_ACF[0]
for value in SS07_10_ACF:
if value > maxVal:
maxVal = value
SS07_10_ACF = SS07_10_ACF/maxVal
maxVal = SS13pre_10_ACF[0]
for value in SS13pre_10_ACF:
if value > maxVal:
maxVal = value
SS13pre_10_ACF = SS13pre_10_ACF/maxVal
maxVal = SS13post_10_ACF[0]
for value in SS13post_10_ACF:
if value > maxVal:
maxVal = value
SS13post_10_ACF = SS13post_10_ACF/maxVal
maxVal = SS13un_10_ACF[0]
for value in SS13un_10_ACF:
if value > maxVal:
maxVal = value
SS13un_10_ACF = SS13un_10_ACF/maxVal
# The 1:20 dilution normalization where the max value divides all of the
# rest of the data values for each data series
'''
maxVal = SS07_20_ACF[0]
for value in SS07_20_ACF:
if value > maxVal:
maxVal = value
SS07_20_ACF = SS07_20_ACF/maxVal
maxVal = SS13pre_20_ACF[0]
for value in SS13pre_20_ACF:
if value > maxVal:
maxVal = value
SS13pre_20_ACF = SS13pre_20_ACF/maxVal
maxVal = SS13post_20_ACF[0]
for value in SS13post_20_ACF:
if value > maxVal:
maxVal = value
SS13post_20_ACF = SS13post_20_ACF/maxVal
maxVal = SS13un_20_ACF[0]
for value in SS13un_20_ACF:
if value > maxVal:
maxVal = value
SS13un_20_ACF = SS13un_20_ACF/maxVal
'''
# Normalize with LOQ
# a = max Value
# u = growth rate
# y = beginning linear range
def Gompertz(initial_guesses, t):
results = [] # collects the returned values
e = np.exp(1)
for x in t:
results.append( a * np.exp(-np.exp((initial_guesses[0]*e)/a*(initial_guesses[1] -x) + 1)))
return results
# Solving the Objective function for a given set of gueses for 1/20 dilutution data set
# used for the optimization
def Object_20(initial_guesses, data):
t = time_labels
output = Gompertz(initial_guesses, t)
output = np.asarray(output)
result = np.sum(np.power((data - output), 2))
return result
#Calling the objective function and Gompertz for 1/20 dilution
a =1
u = np.log(2)/20./60
y =2500
guesses = (u, y)
initial_guesses = np.asarray(guesses)
estimates = fmin(Object_20, initial_guesses, args = (SS07_20_ACF,))
print estimates
values = Gompertz(estimates, time_labels)
plt.plot(time_labels, values)
plt.plot(time_labels, SS07_20_ACF)
plt.show()
'''
plt.plot(time_labels,SS07_10_ACF)
plt.plot(time_labels,SS13pre_10_ACF)
plt.plot(time_labels,SS13post_10_ACF)
plt.plot(time_labels,SS13un_10_ACF)
plt.plot(time_labels, LB.mean())
plt.ylabel('ACF')
plt.xlabel('Time (sec)')
plt.legend(['SS07', 'SS13++', 'SS13-+', 'SS13--', 'Blank'])
plt.title('Optical Density for 1/10 Diltuion Factor')
plt.show()
'''