In [65]:
import numpy as np
import pandas as pd
from scipy import stats
import matplotlib

In [7]:
%matplotlib inline

In [54]:
curve = pd.read_csv('data/optical_density_curve.csv')
curve['dilution'] = 1 / curve['dilution']
curve


Out[54]:
isolate dilution A_630 replicate
0 MNH120 0.500000 2.237 1
1 MNH120 0.333333 1.524 1
2 MNH120 0.250000 1.155 1
3 MNH120 0.200000 0.745 1
4 MNH120 0.166667 0.650 1
5 MNH120 0.142857 0.498 1
6 MNH120 0.125000 0.494 1
7 MNH120 0.111111 0.469 1
8 MNH120 0.100000 0.331 1
9 MNH120 0.083333 0.274 1
10 MNH120 0.066667 0.247 1
11 MNH120 0.050000 0.195 1

In [83]:
slope, intercept, r_value, p_value, std_err = stats.linregress(curve.dilution, curve.A_630)
def model(x, y_int=intercept):
    return slope * x + y_int

def model_dilution(y, y_int=intercept):
    return (y - y_int) / slope

print(slope, intercept)


4.70628339431 -0.100043995056

$y = 4.7063 \times y - 0.1000$


In [67]:
curve[['A_630', 'dilution']].plot('dilution')


Out[67]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fd234715630>

In [80]:
ods = pd.read_csv('data/optical_densities.csv')
ods['dilution'] = 1 / ods['dilution']
ods['isolate'] = ods['isolate'].astype('category')
ods_mean = ods[["isolate", "A_630"]].groupby("isolate").mean()
ods_mean


Out[80]:
A_630
isolate
120.17 0.283000
120.19 0.630333
120.37 0.532667
120.61 0.162750
120.67 0.595333
120.9 0.443000
MNH120 0.686333
USR5 0.261333

In [93]:
dilution_required = list()
for i, row in ods_mean.iterrows():
    diff = row.A_630 - model(0.2)
    dilution_required.append(model_dilution(0.5, diff))
ods_mean["dilution_reqd"] = pd.Series(dilution_required, index=ods_mean.index)

In [94]:
ods_mean


Out[94]:
A_630 dilution_reqd
isolate
120.17 0.283000 0.224851
120.19 0.630333 0.151049
120.37 0.532667 0.171801
120.61 0.162750 0.250402
120.67 0.595333 0.158486
120.9 0.443000 0.190854
MNH120 0.686333 0.139150
USR5 0.261333 0.229455

In [ ]: