/
fig05B.py
151 lines (117 loc) · 4.03 KB
/
fig05B.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
#%%
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/main/'
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
operator = ["O3"]
# Define repressors to be included
repressors = [1740, 22]
# Define concnentration to include in plot
inducer = np.sort(df_maxEnt.inducer_uM.unique())[::2]
# Define binstep for plot, meaning how often to plot
# an entry
binstep = 100
# Define sample space
mRNA_space = np.array([0])
protein_space = np.arange(0, 1.5e4)
# Initialize plot
fig, ax = plt.subplots(
len(repressors), 1, figsize=(5 / 3, 2.5), sharex=True, sharey=True
)
# Define displacement
displacement = 5e-5
# Loop through repressors
for i, rep in enumerate(repressors):
# Extract the multipliers for a specific strain
df_sample = df_maxEnt[
(df_maxEnt.operator == operator[0])
& (df_maxEnt.repressor == rep)
& (df_maxEnt.inducer_uM.isin(inducer))
]
# Group multipliers by inducer concentration
df_group = df_sample.groupby("inducer_uM", sort=True)
# Extract and invert groups to start from higher to lower
groups = np.flip([group for group, data in df_group])
# Define colors for plot
colors = sns.color_palette("Greens", n_colors=len(df_group) + 1)
# Initialize matrix to save probability distributions
Pp = np.zeros([len(df_group), len(protein_space)])
# Loop through each of the entries
for k, group in enumerate(groups):
data = df_group.get_group(group)
# Select the Lagrange multipliers
lagrange_sample = data.loc[
:, [col for col in data.columns if "lambda" in col]
].values[0]
# Compute distribution from Lagrange multipliers values
Pp[k, :] = ccutils.maxent.maxEnt_from_lagrange(
mRNA_space, protein_space, lagrange_sample, exponents=moments
).T
# Generate PMF plot
ax[i].plot(
protein_space[0::binstep],
Pp[k, 0::binstep] + k * displacement,
drawstyle="steps",
lw=1,
color="k",
zorder=len(df_group) * 2 - (2 * k),
)
# Fill between each histogram
ax[i].fill_between(
protein_space[0::binstep],
Pp[k, 0::binstep] + k * displacement,
[displacement * k] * len(protein_space[0::binstep]),
color=colors[k],
alpha=1,
step="pre",
zorder=len(df_group) * 2 - (2 * k + 1),
)
# Add x label to lower plots
if i == 1:
ax[i].set_xlabel("protein / cell")
ax[i].set_ylabel("[IPTG] ($\mu$M)")
# Change x axis font size
ax[i].tick_params(axis="y", labelsize=5.5)
# Change lim
ax[0].set_ylim([-3e-5, 3.5e-4 + len(df_group) * displacement])
# Adjust spacing between plots
plt.subplots_adjust(hspace=0.1, wspace=0.04)
# Set y axis ticks
yticks = np.arange(len(df_group)) * displacement
yticklabels = [int(x) for x in groups]
ax[0].yaxis.set_ticks(yticks)
ax[0].yaxis.set_ticklabels(yticklabels)
ax[0].yaxis.set_ticklabels(yticklabels)
# Set x axis ticks
xticks = [0, 4e3, 8e3, 1.2e4]
ax[0].xaxis.set_ticks(xticks)
plt.savefig(figdir + "fig05B.pdf", bbox_inches="tight")
plt.savefig(figdir + "fig05B.png", bbox_inches="tight")