/
figS22.py
152 lines (128 loc) · 3.59 KB
/
figS22.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
#%%
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_gillespie/'
# %%
df_sim_prot = pd.read_csv(datadir + "two_state_protein_gillespie.csv")
# Extract mRNA data
mRNA_names = [x for x in df_sim_prot.columns if re.match(r"[m]\d", x)]
mRNA_data = df_sim_prot.loc[:, mRNA_names].values
# Compute mean mRNA
mRNA_mean = mRNA_data.mean(axis=1)
# Extract protein data
protein_names = [x for x in df_sim_prot.columns if re.match(r"[p]\d", x)]
protein_data = df_sim_prot.loc[:, protein_names].values
# Compute mean protein
protein_mean = protein_data.mean(axis=1)
# Initialize plot
fig, ax = plt.subplots(2, 1, figsize=(2.5, 2), sharex=True)
# Define colors
colors = sns.color_palette("Paired", n_colors=2)
# Define time stepsize for plot
binstep = 10
# Define every how many trajectories to plot
simnum = 10
# Plot mRNA trajectories
ax[0].plot(
df_sim_prot["time"][0::binstep] / 60,
mRNA_data[0::binstep, 0::simnum],
color=colors[0],
)
# Plot mean mRNA
ax[0].plot(
df_sim_prot["time"][0::binstep] / 60,
mRNA_mean[0::binstep],
color=colors[1],
)
# Plot protein trajectories
ax[1].plot(
df_sim_prot["time"][0::binstep] / 60,
protein_data[0::binstep, 0::simnum],
color=colors[0],
)
# Plot mean protein
ax[1].plot(
df_sim_prot["time"][0::binstep] / 60,
protein_mean[0::binstep],
color=colors[1],
)
# Group data frame by cell cycle
df_group = df_sim_prot.groupby("cycle")
# Loop through cycles
for i, (group, data) in enumerate(df_group):
# Define the label only for the last cell cycle not to repeat in legend
if group == df_sim_prot["cycle"].max():
label_s = "single promoter"
label_d = "two promoters"
else:
label_s = ""
label_d = ""
# Find index for one-promoter state
idx = np.where(data.state == "single")[0]
# Indicate states with two promoters
ax[0].axvspan(
data.iloc[idx.min()]["time"] / 60,
data.iloc[idx.max()]["time"] / 60,
facecolor="#e3dcd1",
label=label_s,
)
ax[1].axvspan(
data.iloc[idx.min()]["time"] / 60,
data.iloc[idx.max()]["time"] / 60,
facecolor="#e3dcd1",
label=label_s,
)
# Find index for two-promoter state
idx = np.where(data.state == "double")[0]
# Indicate states with two promoters
ax[0].axvspan(
data.iloc[idx.min()]["time"] / 60,
data.iloc[idx.max()]["time"] / 60,
facecolor="#ffedce",
label=label_d,
)
ax[1].axvspan(
data.iloc[idx.min()]["time"] / 60,
data.iloc[idx.max()]["time"] / 60,
facecolor="#ffedce",
label=label_d,
)
# Set limits
ax[0].set_xlim(df_sim_prot["time"].min() / 60, df_sim_prot["time"].max() / 60)
# Label plot
ax[1].set_xlabel("time (min)")
ax[0].set_ylabel("mRNA/cell")
ax[1].set_ylabel("protein/cell")
# Set legend for both plots
ax[0].legend(
loc="upper left",
ncol=2,
frameon=False,
bbox_to_anchor=(-0.12, 0, 0, 1.3),
fontsize=6.5,
)
# Align y axis labels
fig.align_ylabels()
plt.subplots_adjust(hspace=0.05)
plt.savefig(figdir + "figS22.pdf", bbox_inches="tight")