from pyvipr.examples_models.lopez_embedded import model
import pyvipr.pysb_viz as viz
import numpy as np
from pysb.simulator import ScipyOdeSimulator
import os
import matplotlib.pyplot as plt
from scipy.spatial.distance import pdist, squareform
from numpy import genfromtxt
%matplotlib inline
# Standardization of calibrated parameters by removing the mean and scaling to unit variance
pars = np.load('data/calibrated_6572pars.npy')
kpars_idxs = [i for i, j in enumerate(model.parameters) if not j in model.parameters_initial_conditions()]
kpars = pars[:, kpars_idxs]
kpars_means = np.mean(kpars, axis=0)
kpars_means = np.tile(kpars_means, (kpars.shape[0], 1))
kpars_stds = np.std(kpars, axis=0)
kpars_stds = np.tile(kpars_stds, (kpars.shape[0], 1))
kpars_standard = (kpars - kpars_means) / kpars_stds
# Calculate the pairwise distances
dis = squareform(pdist(kpars_standard, metric='euclidean'))
# Obtain the two most dissimilar parameters
ind = np.unravel_index(np.argmax(dis, axis=None), dis.shape)
print(ind)
pars4697 = pars[4697]
pars5023 = pars[5023]
# load experimental data
data_path = os.path.join(os.path.abspath(''), 'data',
'EC-RP_IMS-RP_IC-RP_data_for_models.csv')
exp_data = genfromtxt(data_path, delimiter=',', names=True)
# Mean and variance of Td (delay time) and Ts (switching time) of MOMP, and
# yfinal (the last value of the IMS-RP trajectory)
momp_data = np.array([9810.0, 180.0, model.parameters['Smac_0'].value])
momp_var = np.array([7245000.0, 3600.0, 1e4])
# Function to display the experimendal data and the calibrated simulations to observe goodness of fit
def display_exp_data_sims(position, save_name):
param_values = position
traj = solver.run(param_values=param_values)
# normalize trajectories
bid_traj = traj.observables['mBid'] / model.parameters['Bid_0'].value
cparp_traj = traj.observables['cPARP'] / model.parameters['PARP_0'].value
aSmac_traj = traj.observables['aSmac'] / model.parameters['Smac_0'].value
# create all plots for each observable
fig, ax = plt.subplots(nrows=1, ncols=3, figsize=(9, 3), sharex=True, sharey=True)
fig.add_subplot(111, frameon=False)
plt.tick_params(labelcolor='none', top=False, bottom=False, left=False, right=False)
plt.xlabel("Time(s)")
plt.ylabel("Population")
# plot cleaved parp
ax[0].plot(tspan, bid_traj, color='r', marker='^', label='tBID sim')
ax[0].errorbar(exp_data['Time'], exp_data['norm_ICRP'],
yerr=exp_data['nrm_var_ICRP'] ** .5,
ecolor='black', color='black', elinewidth=0.5, capsize=0)
ax[0].legend(loc=2)
# plot cleaved parp
ax[1].plot(tspan, cparp_traj, color='blue', marker='*', label='cPARP sim')
ax[1].errorbar(exp_data['Time'], exp_data['norm_ECRP'],
yerr=exp_data['nrm_var_ECRP'] ** .5,
ecolor='black', color='black', elinewidth=0.5, capsize=0)
ax[1].legend(loc=2)
# plot activated SMAC
ax[2].plot(tspan, aSmac_traj, color='g', label='aSMAC sim')
ax[2].axvline(momp_data[0], -0.05, 1.05, color='black', linestyle=':',
label='exp aSMAC')
ax[2].legend(loc=2)
plt.show()
# fig.savefig('{}.png'.format(save_name), dpi=500, bbox_inches='tight')
# plt.close()
# Function to display experimental data of tBid and reproduce Figure 3.A
def display_figure3_A(positions, save_name):
traj = solver.run(param_values=positions)
# normalize trajectories
bid_traj0 = traj.observables[0]['mBid'] / model.parameters['Bid_0'].value
cparp_traj0 = traj.observables[0]['cPARP'] / model.parameters['PARP_0'].value
aSmac_traj0 = traj.observables[0]['aSmac'] / model.parameters['Smac_0'].value
bid_traj1 = traj.observables[1]['mBid'] / model.parameters['Bid_0'].value
cparp_traj1 = traj.observables[1]['cPARP'] / model.parameters['PARP_0'].value
aSmac_traj1 = traj.observables[1]['aSmac'] / model.parameters['Smac_0'].value
# create all plots for each observable
fig, ax = plt.subplots(nrows=1, ncols=3, figsize=(15, 5), sharex=True, sharey=True)
fig.add_subplot(111, frameon=False)
plt.tick_params(labelcolor='none', top=False, bottom=False, left=False, right=False)
plt.xlabel("Time(s)", fontsize=fz, labelpad=15)
plt.ylabel("Population", fontsize=fz, labelpad=15)
# plot tBid t=202.20
ax[0].scatter(tspan[::2], bid_traj0[::2], color='r', marker='*', label='tBID par 1 ', alpha=0.8, linewidth=lw)
ax[0].scatter(tspan[::3], bid_traj1[::3], color='blue', marker='+', label='tBID par 2', linewidth=lw)
ax[0].errorbar(exp_data['Time'], exp_data['norm_ICRP'],
yerr=exp_data['nrm_var_ICRP'] ** .5,
ecolor='black', color='black', elinewidth=0.5, capsize=0, alpha=0.5, fmt='none')
ax[0].legend(loc=2)
ax[0].annotate("", xy=(202.20, 0), xytext=(202.20, 0.2), arrowprops=dict(arrowstyle="->", lw=5))
# plot tBid t=4040.40
ax[1].scatter(tspan[::2], bid_traj0[::2], color='r', marker='*', label='tBID par 1 ', alpha=0.8, linewidth=lw)
ax[1].scatter(tspan[::3], bid_traj1[::3], color='blue', marker='+', label='tBID par 2', linewidth=lw)
ax[1].errorbar(exp_data['Time'], exp_data['norm_ICRP'],
yerr=exp_data['nrm_var_ICRP'] ** .5,
ecolor='black', color='black', elinewidth=0.5, capsize=0, alpha=0.5, fmt='none')
ax[1].legend(loc=2)
ax[1].annotate("", xy=(4040.40, 0), xytext=(4040.40, 0.2), arrowprops=dict(arrowstyle="->", lw=5))
# plot tBid t=7474.75
ax[2].scatter(tspan[::2], bid_traj0[::2], color='r', marker='*', label='tBID par 1 ', alpha=0.8, linewidth=lw)
ax[2].scatter(tspan[::3], bid_traj1[::3], color='blue', marker='+', label='tBID par 2', linewidth=lw)
ax[2].errorbar(exp_data['Time'], exp_data['norm_ICRP'],
yerr=exp_data['nrm_var_ICRP'] ** .5,
ecolor='black', color='black', elinewidth=0.5, capsize=0, alpha=0.5, fmt='none')
ax[2].legend(loc=2)
ax[2].annotate("", xy=(7474.75, 0.2), xytext=(7474.75, 0.4), arrowprops=dict(arrowstyle="->", lw=5))
ax[0].tick_params(axis='both', which='major', labelsize=fz)
ax[1].tick_params(axis='both', which='major', labelsize=fz)
ax[2].tick_params(axis='both', which='major', labelsize=fz)
# fig.savefig('{}.png'.format(save_name), dpi=500, bbox_inches='tight')
plt.show()
### Linewith and fontsize values to use for all plots
lw = 2.5 # Linewidth
fz = 14 # Fontsize
tspan = np.linspace(0, 20000, 100)
solver = ScipyOdeSimulator(model, tspan, compiler='python')
display_figure3_A([pars4697, pars5023], 'data_calibration_par4697_par5023_202_20')
sim4697 = ScipyOdeSimulator(model, tspan, compiler='python').run(param_values=[pars4697])
display_exp_data_sims(pars4697, 'data_calibration_par4697')
plt.plot(tspan, sim4697.all['__s37'], label='mBid', linewidth=2.5)
plt.plot(tspan, sim4697.all['__s43'], label='mBcl2-mBid', linewidth=2.5)
plt.plot(tspan, sim4697.all['__s44'], label='mBclxL-mbid', linewidth=2.5)
plt.plot(tspan, sim4697.all['__s41'], label='cBax-mBid', linewidth=2.5)
plt.xlabel('Time(s)', fontsize=14)
plt.ylabel('# Molecules', fontsize=14)
plt.legend(fontsize=14)
plt.savefig('earm_trajectories_example.png', dpi=200)
viz.sp_comm_dyn_view(sim4697, layout_name='klay', random_state=1)
pars_bax_ko= np.copy(pars4697)
pars_mcl1_ko= np.copy(pars4697)
pars_bax_ko[63] = pars_bax_ko[63] * 0 # Setting the initial condition of Bax to zero
pars_mcl1_ko[57] = pars_mcl1_ko[57] * 0 # Setting the initial condition of Mcl1 to zero
sim4697_kd_bax = ScipyOdeSimulator(model, tspan, compiler='python').run(param_values=[pars_bax_ko, pars_mcl1_ko])
plt.scatter(tspan[:57], sim4697.all['cPARP'][:57], label='WT', linewidth=lw, marker='*', color='green')
plt.plot(tspan[:57], sim4697_kd_bax.all[1]['cPARP'][:57], label='Mcl1 KO', linewidth=lw)
plt.plot(tspan[:57], sim4697_kd_bax.all[0]['cPARP'][:57], label='Bax KO', linewidth=lw)
plt.xlabel('Time', fontsize=fz)
plt.xticks(fontsize=fz)
plt.ylabel('Molecules', fontsize=fz)
plt.yticks(fontsize=fz)
plt.title('Parameter set 1: cPARP', fontsize=22)
plt.legend(fontsize=14)
plt.show()
# plt.savefig('par4697_bax_ko.png', dpi=500, bbox_inches='tight')
sim5023 = ScipyOdeSimulator(model, tspan, compiler='python').run(param_values=pars5023)
display_exp_data_sims(pars5023, 'data_calibration_par5023')
viz.sp_comm_dyn_view(sim5023, layout_name='klay', random_state=1)
pars_for_mcl1_kd = np.copy(pars5023)
pars_for_bax_kd = np.copy(pars5023)
pars_for_mcl1_kd[57] = pars_for_mcl1_kd[57] * 0 # Setting the initial condition of Mcl1 to zero
pars_for_bax_kd[63] = pars_for_bax_kd[63] * 0 # Setting the initial condition of Bax to zero
sim5023_kd_bcl2 = ScipyOdeSimulator(model, tspan, compiler='python').run(param_values=[pars_for_mcl1_kd, pars_for_bax_kd])
plt.scatter(tspan[:57], sim5023.all['cPARP'][:57], label='WT', linewidth=lw, marker='*', color='green')
plt.plot(tspan[:57], sim5023_kd_bcl2.all[0]['cPARP'][:57], label='Mcl1 KO', linewidth=lw)
plt.plot(tspan[:57], sim5023_kd_bcl2.all[1]['cPARP'][:57], label='Bax KO', linewidth=lw)
plt.xticks(fontsize=fz)
plt.yticks(fontsize=fz)
plt.xlabel('Time', fontsize=fz)
plt.ylabel('Molecules', fontsize=fz)
plt.title('Parameter set 2: cPARP', fontsize=22)
plt.legend(fontsize=14)
plt.savefig('par5023_mcl1_ko.png', dpi=500, bbox_inches='tight')