/
figS10.py
358 lines (295 loc) · 10.8 KB
/
figS10.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
#%%
import os
import pickle
import cloudpickle
import itertools
import glob
import numpy as np
import scipy as sp
import pandas as pd
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 matrix for binomial partitioning into memory
with open(f'{homedir}/src/theory/pkl_files/binom_coeff_matrix.pkl',
'rb') as file:
unpickler = pickle.Unpickler(file)
Z_mat = unpickler.load()
expo_binom = unpickler.load()
# %%
# Load constants
param = ccutils.model.load_constants()
# Integrate dynamics for single promoter steady state
gp_init = 1 / (60 * 60)
rp_init = 500 * gp_init
# Read protein ununregulated matrix
with open(f'{homedir}/src/theory/pkl_files/two_state_protein_dynamics_matrix.pkl', 'rb') as file:
# Load sympy object containing the matrix A that define the
# moment dynamics
A_mat_unreg_lam = cloudpickle.load(file)
# Load the list of moments included in the matrix
expo = cloudpickle.load(file)
# Substitute value of parameters on matrix
## Initial conditions
A_mat_unreg_s_init = A_mat_unreg_lam(param['kp_on'], param['kp_off'],
param['rm'], param['gm'],
rp_init, gp_init)
# Define time on which to perform integration
t = np.linspace(0, 4000 * 60, 2000)
# Define initial conditions
mom_init = np.zeros(len(expo) * 2)
# Set initial condition for zero moment
# Since this needs to add up to 1
mom_init[0] = 1
# Numerically integrate equations
mp_sol = sp.integrate.odeint(ccutils.model.rhs_dmomdt, mom_init, t,
args=(A_mat_unreg_s_init,))
mp_init = mp_sol[-1, :]
#%%
# Define doubling time
doubling_time = 100
# Define fraction of cell cycle spent with one copy
t_single_frac = 0.6
# Define time for single-promoter state
t_single = 60 * t_single_frac * doubling_time # sec
t_double = 60 * (1 - t_single_frac) * doubling_time # sec
# Define number of cell cycles
n_cycles = 6
# Define list of parameters
par_single = [param['kp_on'], param['kp_off'], param['rm'], param['gm'],
param['rp'], 0]
par_double = [param['kp_on'], param['kp_off'], 2 * param['rm'],
param['gm'], param['rp'], 0]
# Integrate moment equations
df_p_unreg = ccutils.model.dmomdt_cycles(mp_init, t_single, t_double,
A_mat_unreg_lam,
par_single, par_double, expo,
n_cycles, Z_mat, n_steps=10000)
# Extract index for mRNA and protein first moment
first_mom_names_m = [x for x in df_p_unreg.columns
if 'm1p0' in x]
first_mom_names_p = [x for x in df_p_unreg.columns
if 'm0p1' in x]
# Extract the last cycle information
df_m_unreg_first = df_p_unreg.loc[df_p_unreg.cycle == df_p_unreg.cycle.max(),
first_mom_names_m]
df_p_unreg_first = df_p_unreg.loc[df_p_unreg.cycle == df_p_unreg.cycle.max(),
first_mom_names_p]
# Extract time of last cell cycle
time = np.sort(df_p_unreg.loc[df_p_unreg.cycle ==
df_p_unreg.cycle.max(),
'time'].unique())
# Compute the time differences
time_diff = np.diff(time)
# Compute the cumulative time difference
time_cumsum = np.cumsum(time_diff)
time_cumsum = time_cumsum / time_cumsum[-1]
# Define array for spacing of cell cycle
a_array = np.zeros(len(time))
a_array[1:] = time_cumsum
# Compute probability based on this array
p_a_array = np.log(2) * 2**(1 - a_array)
# Perform numerical integration
m_mean_unreg = sp.integrate.simps(df_m_unreg_first.sum(axis=1) * p_a_array,
a_array)
p_mean_unreg = sp.integrate.simps(df_p_unreg_first.sum(axis=1) * p_a_array,
a_array)
# %%
# Extract index for first moment
first_mom_names_m = [x for x in df_p_unreg.columns if 'm1p0' in x]
first_mom_names_p = [x for x in df_p_unreg.columns if 'm0p1' in x]
# Compute the mean mRNA copy number
m_mean = df_p_unreg.loc[:, first_mom_names_m].sum(axis=1)
p_mean = df_p_unreg.loc[:, first_mom_names_p].sum(axis=1)
# %%
# Read protein ununregulated matrix
with open(f'{homedir}/src/theory/pkl_files/three_state_protein_dynamics_matrix.pkl', 'rb') as file:
A_mat_reg_lam = cloudpickle.load(file)
expo_reg = cloudpickle.load(file)
#%%
# repressor-DNA binding energy
op = "O2"
eRA = -13.9 # kBT
# Define repressor copy number list
rep_array = [22, 260, 1740] # repressors per cell
# Define IPTG concentrations
iptg_array = [0, 0.1, 5, 10, 25, 50, 75, 100, 250, 500, 1000] # µM
# Initialize data frame to save fold-changes
names = [
"operator",
"energy",
"repressors",
"iptg_uM",
"mean_m_reg",
"mean_m_unreg",
"fold_change_m",
"mean_p_reg",
"mean_p_unreg",
"fold_change_p",
]
df_fc_iptg = pd.DataFrame(columns=names)
# Loop through operators
for j, iptg in enumerate(iptg_array):
print(iptg)
# Loop through repressor copy numbers
for i, rep in enumerate(rep_array):
# Define parameters
eRA = param[f"epR_{op}"]
kp_on = param["kp_on"]
kp_off = param["kp_off"]
kr_off = param["kr_off_O2"]
ko = param["k0"]
rm = param["rm"]
gm = param["gm"]
rp = param["rp"]
ka = param["Ka"]
ki = param["Ki"]
epAI = param["epAI"]
# Calculate the repressor on rate including the MWC model
kr_on = ko * rep * ccutils.model.p_act(iptg, ka, ki, epAI)
# Generate matrices for dynamics
# Single promoter
par_reg_s = [kr_on, kr_off, kp_on, kp_off, rm, gm, rp, 0]
# Two promoters
par_reg_d = [kr_on, kr_off, kp_on, kp_off, 2 * rm, gm, rp, 0]
# Initial conditions
A_reg_s_init = A_mat_reg_lam(
kr_on, kr_off, kp_on, kp_off, rm, gm, rp_init, gp_init
)
# Define initial conditions
mom_init = np.zeros(len(expo_reg) * 3)
# Set initial condition for zero moment
# Since this needs to add up to 1
mom_init[0] = 1
# Define time on which to perform integration
t = np.linspace(0, 4000 * 60, 10000)
# Numerically integrate equations
m_init = sp.integrate.odeint(ccutils.model.rhs_dmomdt,
mom_init, t, args=(A_reg_s_init,))
# Keep last time point as initial condition
m_init = m_init[-1, :]
# Integrate moment equations
df = ccutils.model.dmomdt_cycles(
m_init,
t_single,
t_double,
A_mat_reg_lam,
par_reg_s,
par_reg_d,
expo_reg,
n_cycles,
Z_mat,
states=["A", "I", "R"],
n_steps=3000,
)
# Keep only last cycle
df = df[df["cycle"] == df["cycle"].max()]
# Extract index for first moment
first_mom_names_m = [x for x in df.columns if "m1p0" in x]
first_mom_names_p = [x for x in df.columns if "m0p1" in x]
# Extract the last cycle information of the first moments
df_m_reg_first = df.loc[:, first_mom_names_m]
df_p_reg_first = df.loc[:, first_mom_names_p]
# Extract time of last cell cycle
time = np.sort(df["time"].unique())
# Compute the time differences
time_diff = np.diff(time)
# Compute the cumulative time difference
time_cumsum = np.cumsum(time_diff)
time_cumsum = time_cumsum / time_cumsum[-1]
# Define array for spacing of cell cycle
a_array = np.zeros(len(time))
a_array[1:] = time_cumsum
# Compute probability based on this array
p_a_array = np.log(2) * 2 ** (1 - a_array)
# Perform numerical integration
m_mean_reg = sp.integrate.simps(
df_m_reg_first.sum(axis=1) * p_a_array, a_array
)
p_mean_reg = sp.integrate.simps(
df_p_reg_first.sum(axis=1) * p_a_array, a_array
)
# Compute the fold-change
fold_change_m = m_mean_reg / m_mean_unreg
fold_change_p = p_mean_reg / p_mean_unreg
# Save results into series in order to append it to data frame
series = pd.Series(
[
op,
eRA,
rep,
iptg,
m_mean,
m_mean_unreg,
fold_change_m,
p_mean,
p_mean_unreg,
fold_change_p,
],
index=names,
)
df_fc_iptg = df_fc_iptg.append(series, ignore_index=True)
#%%
# Define IPTG range to compute thermodynamic fold-change
iptg = np.logspace(-1, 3, 50)
iptg_lin = [0, 0.1]
# Group data frame by repressor copy number
df_group = df_fc_iptg.groupby('repressors')
# Define colors
colors = sns.color_palette('colorblind', n_colors=len(df_group))
# Loop through each of the repressor copy numbers
for i, (rep, data) in enumerate(df_group):
Nns = param['Nns']
# Compute thermodynamic fold-change
fc_thermo = (1 + rep / Nns * ccutils.model.p_act(iptg, ka, ki, epAI) *
np.exp(- data.energy.unique()[0]))**-1
fc_thermo_lin = (1 + rep / Nns * ccutils.model.p_act(iptg_lin,
ka, ki, epAI) *
np.exp(- data.energy.unique()[0]))**-1
# Plot thermodynamic fold-change prediction
plt.plot(iptg, fc_thermo, label=str(rep), color=colors[i])
plt.plot(iptg_lin, fc_thermo_lin, label='', color=colors[i],
linestyle='--')
# Plot the kinetic fold-change prediciton
# Protein
plt.plot(data.iptg_uM.values, data.fold_change_p.values, lw=0, marker='o',
color=colors[i], label='')
# mRNA
plt.plot(data.iptg_uM.values, data.fold_change_m.values, lw=0, marker='v',
markeredgecolor=colors[i], markeredgewidth=1,
markerfacecolor='w', label='')
# Generate labels for mRNA and protein
plt.plot([], [], lw=0, marker='v',
markeredgecolor='k', markeredgewidth=1,
markerfacecolor='w', label='mRNA')
plt.plot([], [], lw=0, marker='o',
color='k', label='protein')
# Change scale to log
plt.xscale('symlog', linthreshx=1E-1, linscalex=0.5)
# Label axis
plt.xlabel(r'IPTG ($\mu$M)')
plt.ylabel('fold-change')
# Set legend
legend = plt.legend(title=r'$\beta\Delta\epsilon_r = -13.5$' '\n rep. / cell',
fontsize=5)
plt.setp(legend.get_title(),fontsize=6)
# Save figure
plt.tight_layout()
plt.savefig(figdir + 'figS10.pdf', bbox_inches='tight')