/
figS18.py
164 lines (131 loc) · 4.14 KB
/
figS18.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
#%%
import os
import glob
import numpy as np
import scipy as sp
import pandas as pd
import re
import git
# Import matplotlib stuff for plotting
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import matplotlib as mpl
# Seaborn, useful for graphics
import seaborn as sns
# Import the project utils
import ccutils
# Set PBoC plotting format
ccutils.viz.set_plotting_style()
#%%
# Find home directory for repo
repo = git.Repo("./", search_parent_directories=True)
homedir = repo.working_dir
# Define directories for data and figure
figdir = f'{homedir}/fig/si/'
datadir = f'{homedir}/data/csv_maxEnt_dist/'
# %%
# Read resulting values for the multipliers.
df_maxEnt = pd.read_csv(datadir + "MaxEnt_Lagrange_mult_protein.csv")
# Extract protein moments in constraints
prot_mom = [x for x in df_maxEnt.columns if "lambda_m0" in x]
# Define index of moments to be used in the computation
moments = [tuple(map(int, re.findall(r"\d+", s))) for s in prot_mom]
# Define operators to be included
operators = ["O1", "O2", "O3"]
# Remove these dates
df_micro = pd.read_csv(
"../../data/csv_microscopy/single_cell_microscopy_data.csv"
)
df_micro[["date", "operator", "rbs", "mean_intensity", "intensity"]].head()
# group df by date
df_group = df_micro.groupby("date")
# loop through dates
for group, data in df_group:
# Extract mean autofluorescence
mean_auto = data[data.rbs == "auto"].mean_intensity.mean()
# Extract ∆lacI data
delta = data[data.rbs == "delta"]
mean_delta = (delta.intensity - delta.area * mean_auto).mean()
# Compute fold-change
fc = (data.intensity - data.area * mean_auto) / mean_delta
# Add result to original dataframe
df_micro.loc[fc.index, "fold_change"] = fc
# Define sample space
mRNA_space = np.array([0])
protein_space = np.arange(0, 2.2e4)
# Extract the multipliers for a specific strain
df_maxEnt_delta = df_maxEnt[
(df_maxEnt.operator == "O1")
& (df_maxEnt.repressor == 0)
& (df_maxEnt.inducer_uM == 0)
]
# Select the Lagrange multipliers
lagrange_sample = df_maxEnt_delta.loc[
:, [col for col in df_maxEnt_delta.columns if "lambda" in col]
].values[0]
# Compute distribution from Lagrange multipliers values
Pp = ccutils.maxent.maxEnt_from_lagrange(
mRNA_space,
protein_space,
lagrange_sample,
exponents=moments
).T
# Compute mean protein copy number
mean_delta_p = np.sum(protein_space * Pp)
# Transform protein_space into fold-change
fc_space = protein_space / mean_delta_p
## Plot ECDF for experimental data
# Keep only data for ∆lacI
df_delta = df_micro[df_micro.rbs == "delta"]
# Group data by operator
df_group = df_delta.groupby("operator")
# Initialize figure
fig, ax = plt.subplots(1, 3, figsize=(7, 2.5), sharex=True, sharey=True)
# Define colors for operators
col_list = ["Blues_r", "Reds_r", "Greens_r"]
col_dict = dict(zip(("O1", "O2", "O3"), col_list))
# Loop through operators
for i, (group, data) in enumerate(df_group):
# Group data by date
data_group = data.groupby("date")
# Generate list of colors
colors = sns.color_palette(col_dict[group], n_colors=len(data_group))
# Loop through dates
for j, (g, d) in enumerate(data_group):
# Generate ECDF
x, y = ccutils.stats.ecdf(d.fold_change)
# Plot ECDF
ax[i].plot(
x[::10],
y[::10],
lw=0,
marker=".",
color=colors[j],
alpha=0.3,
label="",
)
# Label x axis
ax[i].set_xlabel("fold-change")
# Set title
label = r"operator {:s}".format(group)
ax[i].set_title(label, bbox=dict(facecolor="#ffedce"))
# Plot theoretical prediction
ax[i].plot(
fc_space[0::100],
np.cumsum(Pp)[0::100],
linestyle="--",
color="k",
linewidth=1.5,
label="theory",
)
# Add fake data point for legend
ax[i].plot([], [], lw=0, marker=".", color=colors[0], label="microscopy")
# Add legend
ax[i].legend()
# Label y axis of left plot
ax[0].set_ylabel("ECDF")
# Change limit
ax[0].set_xlim(right=3)
# Change spacing between plots
plt.subplots_adjust(wspace=0.05)
plt.savefig(figdir + "figS18.pdf", bbox_inches="tight")