-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormalise.py
49 lines (46 loc) · 2.15 KB
/
normalise.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
import pandas
import numpy as np
def normalise(infile, outfile, min_to_back=True):
"""In our dataset the fluorescence sometimes goes below the
autofluorescence, for comparison we take the minimum
value of fluorescence as the background. This function performs
the normalisation taking the minimum flourescence as the
background fluorescence, if and only if min_to_back is
True. Otherwise, the normalisation is performed using only the
autofluorescence plasmid. """
df = pandas.read_csv(infile, index_col=0)
print("starting normalisation")
if min_to_back:
df = pandas.merge(df,
df.groupby([
'backbone', 'strain'
]).volume_decomposed_log_mean_gfp.min().to_frame(),
on=["strain", "backbone"],
how='outer',
suffixes=("", "_min"))
else:
df = pandas.merge(df,
df.query('plasmid=="1201"').groupby([
'backbone', 'strain'
]).volume_decomposed_log_mean_gfp.mean().to_frame(),
on=["strain", "backbone"],
how='outer',
suffixes=("", "_min"))
df = pandas.merge(df,
df.query('plasmid=="1717"').groupby([
'backbone', 'strain'
]).volume_decomposed_log_mean_gfp.mean().to_frame(),
on=["strain", "backbone"],
how='outer',
suffixes=("", "_standard"))
df["rrpu"] = ((np.exp(df.volume_decomposed_log_mean_gfp) -
np.exp(df.volume_decomposed_log_mean_gfp_min)) /
(np.exp(df.volume_decomposed_log_mean_gfp_standard) -
np.exp(df.volume_decomposed_log_mean_gfp_min)))
compactdf = df.copy()
compactdf = compactdf.drop(columns=[
'filename', "date", "real_time", "log_mean_v_mean",
"volume_decomposed_log_mean_gfp_min",
"volume_decomposed_log_mean_gfp_standard"])
compactdf.to_csv(outfile)
return compactdf