import pandas as pd
import plotnine as p9
import numpy as np
from scipy.integrate import odeint
from plotnine import ggplot, aes, geom_point, geom_line, facet_wrap
p9.theme_set(p9.theme_bw())
def dict_to_tuple(x):
return tuple(x.values())Elena’s paper
Elena’s paper
Started to play with Elena’s paper: Link to the paper


def get_p_and_y0(df, d = 1, i = 1):
pp = df.iloc[i].to_dict()
p = {key: pp[key] for key in ['Pz', 'Pyx', 'Pxy', 'TKI', 'Kz', 'Ky', 'Py', 'm', 'rz', 'a']}
p['d'] = d
y_0 = {key: pp[key] for key in ['X(0)', 'Y(0)', 'Z(0)']}
return p, y_0
params_df = pd.read_csv('ParameterSets.csv')
p, y0 = get_p_and_y0(params_df, 1)
params_dfFileNotFoundError: [Errno 2] No such file or directory: 'ParameterSets.csv'
def cml_model(y, t, Pz, Pyx, Pxy, TKI, Kz, Ky, Py, m, rz, a, d):
X, Y, Z = y
dX = Pyx * Y - Pxy * X
dY = Pxy * X - Pyx * Y + Py * (1 - Y / Ky) * Y - m * Z * Y - d * TKI * Y
dZ = rz + Z * Pz * (Y / (Kz ** 2 + Y ** 2)) - a * Z
return (dX, dY, dZ)ii = tuple(range(0, len(params_df) - 1))
ii = tuple(range(0, 9))
t = np.arange(0.0, 100, 0.01)
result_list = []
for i in ii:
p, y0 = get_p_and_y0(params_df, i = i)
result = odeint(cml_model,
dict_to_tuple(y0),
t,
args=dict_to_tuple(p))
df = pd.DataFrame(result, columns = ['X', 'Y', 'Z'])
df = df.assign(t = t)
df['PatID'] = i
result_list.append(df)
result = pd.concat(result_list, ignore_index=True)
result['PatID'] = result['PatID'].astype('category')result_long = pd.melt(result,
id_vars = ['t', 'PatID'],
value_vars = ['X', 'Y', 'Z'],
value_name = 'cell_count')
(
ggplot(result_long, aes('t', 'cell_count', color = 'variable')) +
geom_line() +
facet_wrap('PatID')+ p9.scale_y_continuous(trans='log10') +
p9.theme(figure_size=(12,9)) +
p9.labs(y='Cell count', color = 'Compartment')
)

(
ggplot(result, aes('t', 'Y', color = 'PatID')) +
geom_line() + p9.scale_y_continuous(trans='log10')
)

def LRATIO(Y, KY=1e6):
return Y / (Y + 2 * (KY - Y))
result['LRATIO'] = LRATIO(result["Y"])
(
ggplot(result, aes('t', 'LRATIO', color='PatID')) +
geom_line() + p9.scale_y_continuous(trans='log10',
breaks=(1, 1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6),
labels=('MR0 (100%)', 'MR1 (10%)', 'MR2 (1%)', 'MR3 (0.1%)', 'MR4 (0.01%)', 'MR5 (0.001%)', 'MR6 (0.0001)')) +
p9.theme(figure_size=(10, 7))
)