Skip to content

Commit

Permalink
Big update of material for the appendix
Browse files Browse the repository at this point in the history
  • Loading branch information
gchure committed Oct 27, 2023
1 parent c400c57 commit 11e49ab
Show file tree
Hide file tree
Showing 40 changed files with 22,025 additions and 21,960 deletions.
Binary file added code/analysis/data_inference/wildtype_inference
Binary file not shown.
17 changes: 4 additions & 13 deletions code/analysis/data_inference/wildtype_inference.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
"""
Wildtype Inference
==================
This script executes a bayesian inferential model to estimate size and protein
load parameters from measurements of wildtype E. coli. This generates figures
illustrating the posterior predictive checks of the size, growth, and protein
inference as well as CSV files of the summarized posteriors for each parameter.
"""
# %%
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -113,7 +104,7 @@
ppc = samples.posterior[f'{n}_ppc'].to_dataframe().reset_index()

for g, d in ppc.groupby(f'{n}_ppc_dim_0'):
ax[i].plot(1 + np.ones_like(d[::3]) * g, d[f'{n}_ppc'].values[::3] / mod,
ax[i].plot(1 + np.ones_like(d[::10]) * g, d[f'{n}_ppc'].values[::10] / mod,
'_', markeredgecolor=cor['primary_black'], markeredgewidth=0.1,
alpha=0.75)

Expand All @@ -135,8 +126,8 @@
phi['phiRb'], '_',
markeredgecolor=cor['primary_red'],
markeredgewidth=0.5)
ax[4].set_title('ribosomal allocation', fontsize=6)
ax[4].set_ylabel('$\phi_{Rb}$', fontsize=6)
ax[4].set_title('ribosomal proteome fraction', fontsize=6)
ax[4].set_ylabel('$\phi_{rib}$', fontsize=6)

ax[5].plot(flow['idx'],
flow['cells_per_biomass'] / 1E9, '_',
Expand All @@ -161,7 +152,7 @@
for i, q in enumerate(['width', 'length', 'aspect_ratio', 'surface_area', 'volume', 'surface_to_volume']):
ppc = samples.posterior[f'{q}_ppc'].to_dataframe().reset_index()
for g, d in ppc.groupby(f'{q}_ppc_dim_0'):
ax[i].plot(1 + np.ones_like(d[::3]) * g, d[f'{q}_ppc'].values[::3] / mod,
ax[i].plot(1 + np.ones_like(d[::10]) * g, d[f'{q}_ppc'].values[::10] / mod,
'_', markeredgecolor=cor['primary_black'], markeredgewidth=0.1,
alpha=0.75)
ax[i].set_title(q, fontsize=6)
Expand Down
1 change: 0 additions & 1 deletion code/analysis/data_inference/wildtype_inference.stan
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ model {
surface_to_volume_sigma ~ std_normal();
surface_to_volumes ~ normal(surface_to_volume_mu[size_idx], surface_to_volume_sigma[size_idx]);


aspect_ratio_zeroed_mu ~ std_normal();
alpha_zeroed_sigma ~ normal(0, 0.1);
aspect_ratio_zeroed ~ normal(aspect_ratio_zeroed_mu[size_idx], alpha_zeroed_sigma[size_idx]);
Expand Down
Binary file added code/analysis/model_inference/SAV_model_inference
Binary file not shown.
2 changes: 1 addition & 1 deletion code/analysis/model_inference/SAV_model_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
# %%
# Summarize the predicted growth-rate dependencies
pars = ['pred_lam_prot', 'volume_pred', 'length_pred', 'aspect_ratio_pred', 'width_pred',
'm_peri_pred', 'rho_peri_pred', 'rho_mem_pred', 'phi_mem_pred', 'phi_Rb_pred', 'phi_peri_lam_pred',
'm_peri_pred', 'rho_peri_pred', 'rho_mem_pred', 'rho_dry_pred', 'phi_mem_pred', 'phi_Rb_pred', 'phi_peri_lam_pred',
'SA_fit']
lam_par_percs = pd.DataFrame([])
for i, p in enumerate(tqdm.tqdm(pars)):
Expand Down
2 changes: 2 additions & 0 deletions code/analysis/model_inference/SAV_model_inference.stan
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,15 @@ generated quantities {
vector[N_pred] m_peri_pred;
vector[N_pred] rho_peri_pred;
vector[N_pred] rho_mem_pred;
vector[N_pred] rho_dry_pred;
vector[N_pred] phi_mem_pred;
vector[N_pred] phi_peri_pred;
vector[N_pred] phi_peri_lam_pred;
for (i in 1:N_pred) {
aspect_ratio_pred[i] = alpha_mu;
m_peri_pred[i] = m_peri;
rho_mem_pred[i] = rho_mem_mu;
rho_dry_pred[i] = drymass_mu;
phi_mem_pred[i] = phi_mem_mu;
phi_peri_pred[i] = m_peri / pred_phiRb_prot[i];
phi_peri_lam_pred[i] = m_peri / pred_lam_prot[i];
Expand Down
25 changes: 25 additions & 0 deletions code/visualization/FigAX_SA_fit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#%%
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import size.viz
cor, pal = size.viz.matplotlib_style()
data = pd.read_csv('../../data/literature/collated_literature_size_data.csv')
fit = pd.read_csv('../../data/mcmc/theory_growth_rate_prediction_summaries.csv')

fig, ax = plt.subplots(1, 1, figsize=(3,2))

inter_colors = {'95%':'pale_', '75%':'light_', '25%':'primary_', 'median':''}

for g, d in fit[fit['quantity']=='SA_fit'].groupby('interval', sort=False):
ax.fill_between(d['growth_rate_hr'], d['lower'], d['upper'], color=cor[f'{inter_colors[g]}red'], alpha=0.5)

for g, d in data.groupby('source'):
fmt = size.viz.style_point(g)
ax.plot(d['growth_rate_hr'], d['surface_area_um2'], **fmt)
ax.set_ylim([0, 15])
ax.legend(fontsize=6, loc='upper left')
ax.set_ylabel('$S_A$ [µm$^2$]\naverage cell surface area', fontsize=6)
ax.set_xlabel('growth rate\n$\lambda$ [hr$^{-1}$]', fontsize=6)

plt.savefig('../../figures/FigAX_sa_bayes.pdf')
43 changes: 43 additions & 0 deletions code/visualization/FigAX_lit_size_comparison.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#%%
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import size.viz
cor, pal = size.viz.matplotlib_style()

size_data = pd.read_csv('../../data/literature/collated_literature_size_data.csv')
size_data = size_data[~size_data['source'].isin(['Si et al. 2017', 'Taher-Araghi et al. 2015', 'Basan et al. 2015'])]
wt_data = pd.read_csv('../../data/mcmc/wildtype_posterior_parameter_summaries.csv')

fig, ax = plt.subplots(1, 2, figsize=(4, 1.5))
ax[0].set_xlim([0, 2.2])
ax[0].set_ylim([0.45, 1.2])
ax[1].set_ylim([1, 5])
for a in ax:
a.set_xlabel('growth rate\n$\lambda$ [hr$^{-1}$]', fontsize=6)
ax[0].set_ylabel('$w$ [µm]\naverage cell width', fontsize=6)
ax[1].set_ylabel('$\ell$ [µm]\naverage cell length', fontsize=6)

for g, d in size_data.groupby('source'):
fmt = size.viz.style_point(g)
ax[0].plot(d['growth_rate_hr'], d['width_um'], **fmt)
ax[1].plot(d['growth_rate_hr'], d['length_um'], **fmt)


x = 0
for g, d in wt_data[wt_data['quantity'].isin(['width', 'length', 'growth_rate'])].groupby('carbon_source'):
lam = d[d['quantity']=='growth_rate']
w = d[d['quantity']=='width']
l = d[d['quantity']=='length']
if x == 0:
label = 'This study'
else:
label = '__nolegend__'
for i, p in enumerate([w, l]):
ax[i].vlines(lam['median_value'], p['2.5%'], p['97.5%'], lw=1, color=cor['primary_black'], label='__nolegend__')
ax[i].hlines(p['median_value'], lam['2.5%'], lam['97.5%'], lw=1, color=cor['primary_black'], label='__nolegend__')
ax[i].plot(lam['median_value'], p['median_value'], 'o', ms=5, markeredgecolor=cor['primary_black'],
markeredgewidth=1, markerfacecolor='w', label=label)
x += 1
ax[1].legend(fontsize=5, bbox_to_anchor=(1,1))
plt.savefig('../../figures/FigAX_lit_size_comparison.pdf')
27 changes: 27 additions & 0 deletions code/visualization/FigAX_phi_mem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#%%
#%%
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import size.viz
cor, pal = size.viz.matplotlib_style()
data = pd.read_csv('../../data/literature/collated_mass_fractions_empirics.csv')
data = data[data['localization']=='membrane']
fit = pd.read_csv('../../data/mcmc/theory_growth_rate_prediction_summaries.csv')

fig, ax = plt.subplots(1, 1, figsize=(3,2))
ax.set_ylim([0, 0.2])
inter_colors = {'95%':'pale_', '75%':'light_', '25%':'primary_', 'median':''}


for g, d in fit[fit['quantity']=='phi_mem_pred'].groupby('interval', sort=False):
ax.fill_between(d['growth_rate_hr'], d['lower'], d['upper'], color=cor[f'{inter_colors[g]}red'], alpha=0.5)
for g, d in data.groupby('dataset_name'):
fmt = size.viz.style_point(g)
ax.plot(d['growth_rate_hr'], d['mass_frac'], **fmt)

ax.legend()
ax.set_ylabel('$\phi_{mem}$ \nmembrane proteome fraction', fontsize=6)
ax.set_xlabel('growth rate\n$\lambda$ [hr$^{-1}$]', fontsize=6)

plt.savefig('../../figures/FigAX_phi_mem_bayes.pdf')
26 changes: 26 additions & 0 deletions code/visualization/FigAX_phi_peri.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#%%
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import size.viz
cor, pal = size.viz.matplotlib_style()
data = pd.read_csv('../../data/literature/collated_mass_fractions_empirics.csv')
data = data[data['localization']=='periplasm']
fit = pd.read_csv('../../data/mcmc/theory_growth_rate_prediction_summaries.csv')

fig, ax = plt.subplots(1, 1, figsize=(3,2))

inter_colors = {'95%':'pale_', '75%':'light_', '25%':'primary_', 'median':''}

for g, d in fit[fit['quantity']=='phi_peri_lam_pred'].groupby('interval', sort=False):
ax.fill_between(d['growth_rate_hr'], d['lower'], d['upper'], color=cor[f'{inter_colors[g]}red'], alpha=0.5)

for g, d in data.groupby('dataset_name'):
fmt = size.viz.style_point(g)
ax.plot(d['growth_rate_hr'], d['mass_frac'], **fmt)
ax.set_ylim([0, 0.12])
ax.legend(fontsize=5, loc='upper right')
ax.set_ylabel('$\phi_{peri}$ \nperiplasmic proteome fraction', fontsize=6)
ax.set_xlabel('growth rate\n$\lambda$ [hr$^{-1}$]', fontsize=6)

plt.savefig('../../figures/FigAX_phi_peri_bayes.pdf')
25 changes: 25 additions & 0 deletions code/visualization/FigAX_phirib_fit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#%%
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import size.viz
cor, pal = size.viz.matplotlib_style()
data = pd.read_csv('../../data/literature/Chure2023/chure2023_collated_mass_fractions.csv')
data = data[(data['source']!='Si et al. 2017') & (data['source']!='Taher-Araghi et al. 2015')]
fit = pd.read_csv('../../data/mcmc/theory_growth_rate_prediction_summaries.csv')

fig, ax = plt.subplots(1, 1, figsize=(3,2))

inter_colors = {'95%':'pale_', '75%':'light_', '25%':'primary_', 'median':''}

for g, d in fit[fit['quantity']=='phi_Rb_pred'].groupby('interval', sort=False):
ax.fill_between(d['growth_rate_hr'], d['lower'], d['upper'], color=cor[f'{inter_colors[g]}red'], alpha=0.5, zorder=1000)
for g, d in data.groupby('source'):
fmt = size.viz.style_point(g, alpha=0.5)
ax.plot(d['growth_rate_hr'], d['mass_fraction'], **fmt,ms=5)

ax.legend(fontsize=5, bbox_to_anchor=(1,1))
ax.set_ylabel('$\phi_{rib}$\nribosomal proteome fraction', fontsize=6)
ax.set_xlabel('growth rate\n$\lambda$ [hr$^{-1}$]', fontsize=6)

plt.savefig('../../figures/FigAX_phi_rib_bayes.pdf')
25 changes: 25 additions & 0 deletions code/visualization/FigAX_prot_fit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#%%
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import size.viz
cor, pal = size.viz.matplotlib_style()
data = pd.read_csv('../../data/literature/collated_protein_per_cell.csv')
fit = pd.read_csv('../../data/mcmc/theory_growth_rate_prediction_summaries.csv')

fig, ax = plt.subplots(1, 1, figsize=(3,2))

inter_colors = {'95%':'pale_', '75%':'light_', '25%':'primary_', 'median':''}


for g, d in fit[fit['quantity']=='pred_lam_prot'].groupby('interval', sort=False):
ax.fill_between(d['growth_rate_hr'], d['lower'], d['upper'], color=cor[f'{inter_colors[g]}red'], alpha=0.5)
for g, d in data.groupby('source'):
fmt = size.viz.style_point(g)
ax.plot(d['growth_rate_hr'], d['fg_protein_per_cell'], **fmt)

ax.legend()
ax.set_ylabel('$M_{prot}^{(tot)}$ [fg / cell]\ntotal protein', fontsize=6)
ax.set_xlabel('growth rate\n$\lambda$ [hr$^{-1}$]', fontsize=6)

plt.savefig('../../figures/FigAX_protein_bayes.pdf')
26 changes: 26 additions & 0 deletions code/visualization/FigAX_rho_dry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#%%
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import size.viz
cor, pal = size.viz.matplotlib_style()
data = pd.read_csv('../../data/literature/collated_drymass_densities.csv')
fit = pd.read_csv('../../data/mcmc/theory_growth_rate_prediction_summaries.csv')

fig, ax = plt.subplots(1, 1, figsize=(3,2))
ax.set_ylim([150, 450])

inter_colors = {'95%':'pale_', '75%':'light_', '25%':'primary_', 'median':''}

for g, d in fit[fit['quantity']=='rho_dry_pred'].groupby('interval', sort=False):
ax.fill_between(d['growth_rate_hr'], d['lower'], d['upper'], color=cor[f'{inter_colors[g]}red'], alpha=0.5, zorder=1000)

for g, d in data.groupby('source'):
fmt = size.viz.style_point(g)
ax.plot(d['growth_rate_hr'], d['drymass_density_fg_fL'], **fmt)

ax.legend(fontsize=5, bbox_to_anchor=(1,1))
ax.set_ylabel(r'$\rho_{dry}$ [fg / fL]'+'\ndrymass density', fontsize=6)
ax.set_xlabel('growth rate\n$\lambda$ [hr$^{-1}$]', fontsize=6)

plt.savefig('../../figures/FigAX_rho_dry_bayes.pdf')
24 changes: 24 additions & 0 deletions code/visualization/FigAX_sigma_mem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#%%
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import size.viz
cor, pal = size.viz.matplotlib_style()
data = pd.read_csv('../../data/mcmc/mass_spec_empirical_summaries_wide.csv')
fit = pd.read_csv('../../data/mcmc/theory_growth_rate_prediction_summaries.csv')

fig, ax = plt.subplots(1, 1, figsize=(3,2))
ax.set_ylim([0, 6])
inter_colors = {'95%':'pale_', '75%':'light_', '25%':'primary_', 'median':''}

for g, d in fit[fit['quantity']=='rho_mem_pred'].groupby('interval', sort=False):
ax.fill_between(d['growth_rate_hr'], d['lower'], d['upper'], color=cor[f'{inter_colors[g]}red'], alpha=0.5)
for g, d in data[data['quantity']=='ms_rho_mem'].groupby('source'):
fmt = size.viz.style_point(g, alpha=0.5)
ax.plot(d['growth_rate_hr'], d['median_value'], **fmt,ms=5)

ax.legend(fontsize=5, bbox_to_anchor=(1,1))
ax.set_ylabel('$\sigma_{mem}$ [fg / µm$^2$\naverage membrane protein areal density', fontsize=6)
ax.set_xlabel('growth rate\n$\lambda$ [hr$^{-1}$]', fontsize=6)

plt.savefig('../../figures/FigAX_sigma_mem_bayes.pdf')
Loading

0 comments on commit 11e49ab

Please sign in to comment.