/
figS32.py
200 lines (164 loc) · 4.74 KB
/
figS32.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
#%%
import os
import glob
import numpy as np
import scipy as sp
import pandas as pd
import statsmodels.api as sm
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()
# Increase dpi
#%%
# 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 moments for multi-promoter model
df_mom_rep = pd.read_csv(datadir + 'MaxEnt_multi_prom_constraints.csv')
# Read experimental determination of noise
df_noise = pd.read_csv(f'{homedir}/data/csv_microscopy/' +
'microscopy_noise_bootstrap.csv')
df_noise = df_noise[df_noise.percentile == 0.95]
# Find the mean unregulated levels to compute the fold-change
mean_m_delta = np.mean(df_mom_rep[df_mom_rep.repressor == 0].m1p0)
mean_p_delta = np.mean(df_mom_rep[df_mom_rep.repressor == 0].m0p1)
# Compute the noise for the multi-promoter data
df_mom_rep = df_mom_rep.assign(
m_noise=(
np.sqrt(df_mom_rep.m2p0 - df_mom_rep.m1p0 ** 2) / df_mom_rep.m1p0
),
p_noise=(
np.sqrt(df_mom_rep.m0p2 - df_mom_rep.m0p1 ** 2) / df_mom_rep.m0p1
),
m_fold_change=df_mom_rep.m1p0 / mean_m_delta,
p_fold_change=df_mom_rep.m0p1 / mean_p_delta,
)
# Initialize list to save theoretical noise
thry_noise = list()
# Iterate through rows
for idx, row in df_noise.iterrows():
# Extract information
rep = float(row.repressor)
op = row.operator
if np.isnan(row.IPTG_uM):
iptg = 0
else:
iptg = row.IPTG_uM
# Extract equivalent theoretical prediction
thry = df_mom_rep[(df_mom_rep.repressor == rep) &
(df_mom_rep.operator == op) &
(df_mom_rep.inducer_uM == iptg)].p_noise
# Append to list
thry_noise.append(thry.iloc[0])
df_noise = df_noise.assign(noise_theory = thry_noise)
#%%
# Linear regression to find multiplicative factor
# Select data with experimetal noise < 10
data = df_noise[df_noise.noise < 10]
# Define the weights for each of the datum to be the width
# of their bootstrap confidence interval.
noise_range = (data.noise_upper.values - data.noise_lower.values)
weights = noise_range
# Assign the non-zero minimum value to all zero weights
weights[weights == 0] = min(weights[weights > 0])
# Normalize weights
weights = weights / weights.sum()
def add_factor(x, a):
'''
Function to find additive constant used with scipy curve_fit
'''
return a + x
popt, pcov = sp.optimize.curve_fit(
add_factor,
data.noise_theory.values,
data.noise.values,
sigma=weights,
)
factor = popt[0]
# Print result
print(
f"Additive factor: {factor}"
)
#%%
# Initialize figure
fig, ax = plt.subplots(1, 2, figsize=(5, 2))
# Linear scale
# Plot reference line
ax[0].plot([1e-2, 1e2], [1e-2, 1e2], "--", color="gray")
# Plot error bars
ax[0].errorbar(
x=df_noise.noise_theory + factor,
y=df_noise.noise,
yerr=[
df_noise.noise - df_noise.noise_lower,
df_noise.noise_upper - df_noise.noise,
],
color="gray",
alpha=0.5,
mew=0,
zorder=0,
fmt=".",
)
# Plot data with color depending on log fold-change
ax[0].scatter(
df_noise.noise_theory + factor,
df_noise.noise,
c=np.log10(df_noise.fold_change),
cmap="viridis",
s=10,
)
ax[0].set_xlabel("theoretical noise")
ax[0].set_ylabel("experimental noise")
ax[0].set_title("linear scale")
ax[0].set_xlim(0, 2)
ax[0].set_ylim(0, 2)
# Log scale
# Plot reference line
line = [1e-1, 1e2]
ax[1].loglog(line, line, "--", color="gray")
# Plot data with color depending on log fold-change
ax[1].errorbar(
x=df_noise.noise_theory + factor,
y=df_noise.noise,
yerr=[
df_noise.noise - df_noise.noise_lower,
df_noise.noise_upper - df_noise.noise,
],
color="gray",
alpha=0.5,
mew=0,
zorder=0,
fmt=".",
)
plot = ax[1].scatter(
df_noise.noise_theory + factor,
df_noise.noise,
c=np.log10(df_noise.fold_change),
cmap="viridis",
s=10,
)
ax[1].set_xlabel("theoretical noise")
ax[1].set_ylabel("experimental noise")
ax[1].set_title("log scale")
ax[1].set_xlim([0.1, 10])
# show color scale
fig.subplots_adjust(right=0.8)
cbar_ax = fig.add_axes([0.82, 0.15, 0.02, 0.7])
cbar = fig.colorbar(plot, cax=cbar_ax, ticks=[0, -1, -2, -3])
cbar.ax.set_ylabel("fold-change")
cbar.ax.set_yticklabels(["1", "0.1", "0.01", "0.001"])
cbar.ax.tick_params(width=0)
plt.subplots_adjust(wspace=0.4)
plt.savefig(figdir + "figS32.pdf", bbox_inches="tight")