def get_probs(d, ag): assert np.abs(d["pth1"] + d["ptfh"] + d["ptr1"] + d["ptfhc"] - 1) < 1e-6 pTh1 = d["pth1"] * neg_fb(ag, d["K_ag"]) pTfh = d["ptfh"] * neg_fb(ag, d["K_ag"]) pTr1 = d["ptr1"] * pos_fb(ag, d["K_ag"]) pTfhc = d["ptfhc"] * pos_fb(ag, d["K_ag"]) return pTh1, pTfh, pTr1, pTfhc
def th_cell_diff(state, time, d, prolif_model, core_model, virus_model): """ takes state vector to differentiate effector cells as linear chain needs alpha and beta(r) of response time distribution, probability and number of precursor cells """ # divide array into cell states myc = state[-1] il2 = state[-2] C = state[-3] tchronic = state[-4] n_chronic = 1 n_molecules = 3 th_state = state[:-(n_molecules + n_chronic)] tnaive, teff = get_cell_states(th_state, d) all_cells = tchronic + teff + tnaive # get proliferation and death based on proliferation model (il2/timer) beta_p = d["beta_p"] * prolif_model(state, d) # add carrying capacity beta_p = (1 - all_cells / d["K_carr"]) * beta_p beta_p = beta_p * fb_fc(tchronic, d["neg_fb_chr"], d["K_neg_fb_chr"]) # compute il2 and myc changes based on antigen load (set vir load to 0 for no ag effect) ag = virus_model(time) dt_myc = -d["deg_myc"] * myc # ag inhibits myc degradation dt_il2 = get_il2(tnaive, teff, il2, ag, d) # ag induces il2 secretion by effectors dt_C = -d["deg_C"] * teff * C # apply feedback on rate beta beta = d["beta"] # ag effects r chronic menten style r_chronic = d["r_chronic"] * pos_fb(ag, d["K_ag_chr"]) r_chronic = r_chronic * fb_fc(tchronic, d["pos_fb_chr"], d["K_pos_fb_chr"]) n_div = d["beta_p"]**( 1 / float(d["alpha"]) ) # have to double check if my other analyses still hold if I use this formulation pcore = [ d["b"], d["d_naive"], d["alpha"], d["d_prec"], n_div, beta, d["r_death"], beta_p, r_chronic ] dt_state = core_model(th_state, *pcore) dt_chronic = r_chronic * teff # feedback of chronic cells on chronic cell diff # output dt_state = np.concatenate( (dt_state, [dt_chronic], [dt_C], [dt_il2], [dt_myc])) return dt_state
def model_crawford(state, time, d, virus_model, prolif_model, myc_model): naive = state[0] prec = state[1] prec1 = state[2] th1 = state[3] th1_2 = state[4] tfhc = state[5] tfhc_2 = state[6] th1_mem = state[7] il2 = state[8] myc = state[9] ag = virus_model(time) tprec = prec1 + prec teff = th1 + th1_2 d_il2 = d["r_il2"] * (naive + tprec) - d["up_il2"] * il2 * teff # get probabilities, add feedback by ag and normalize p_fb = get_probs(d, ag) p_norm = norm_probs(p_fb) pTh1, pTfhc = p_norm # get proliferation based on myc prolif_Th1 = d["prolif_th1"] * prolif_model(state, d) d_myc = -d["deg_myc"] * myc_model(state, ag, d) * myc prolif_Tfhc = d["prolif_tfhc"] * pos_fb(myc, d["K_myc"]) #prolif_Tfhc = 0 d_naive = -d["r_naive"] * naive d_prec = 2 * d["r_naive"] * naive + -(d["r_prec"] + d["death_prec"]) * prec # precursor differentiation d_prec1 = d["r_prec"] * prec - (d["r_prec"] + d["death_prec"]) * prec1 # effector differentiation d_th1 = d["n_div"] * pTh1 * d["r_prec"] * prec1 + prolif_Th1 * ( 2 * th1_2 - th1) - d["death_th1"] * th1 d_th1_2 = prolif_Th1 * (th1 - th1_2) - (d["death_th1"] + d["r_mem"]) * th1_2 # chronic Tfh d_tfhc = d["n_div"] * pTfhc * d["r_prec"] * prec1 + prolif_Tfhc * ( 2 * tfhc_2 - tfhc) - d["death_tfhc"] * tfhc d_tfhc_2 = prolif_Tfhc * (tfhc - tfhc_2) - d["death_tfhc"] * tfhc_2 # memory d_th1_mem = d["r_mem"] * th1_2 - d["death_mem"] * th1_mem # molecules #### timer integrates il2 and antigen depending on prolif model dt_state = [ d_naive, d_prec, d_prec1, d_th1, d_th1_2, d_tfhc, d_tfhc_2, d_th1_mem, d_il2, d_myc ] return dt_state
def simple_chain(state, time, d): # split states naive = state[:d["alpha_naive"]] eff1 = state[d["alpha_naive"]:(d["alpha_naive"]+d["alpha_eff1"])] eff2 = state[(d["alpha_naive"]+d["alpha_eff1"]):-3] myc = state[-1] cyto2 = state[-2] cyto1 = state[-3] # cytokine ODE with perturbation if d["block_fb_start"] <= time < d["block_fb_start"] + d["block_dur"]: p1 = d["p1"] uptake_cyto1 = 0 else: p1 = d["p1"] * prob_fb(cyto1, d["fb_eff1"], d["fb_EC50"]) uptake_cyto1 = d["uptake_cyto1"] dt_cyto1 = d["r_cyto1"]*np.sum(eff1) - uptake_cyto1*cyto1*np.sum(eff1) dt_cyto2 = d["r_cyto2"]*np.sum(eff2) - d["uptake_cyto2"]*cyto2*np.sum(eff2) dt_myc = -d["deg_myc"]*myc # compute influx into next chain influx_naive = 0 # algebraic relations timer beta_p = d["beta_p"]*pos_fb(myc, d["EC50_myc"]) p2 = (1-d["p1"]) * prob_fb(cyto2, d["fb_eff2"], d["fb_EC50"]) p1,p2 = norm_prob(p1,p2) beta = d["beta"] influx_eff1 = naive[-1]*beta * p1 influx_eff2 = naive[-1] * beta * p2 death = d["d_eff"] dt_naive = diff_chain(naive, influx_naive, beta, d["d_naive"], d["div_naive"]) dt_eff_1 = diff_chain(eff1, influx_eff1, beta_p, death, d["div_eff"]) dt_eff_2 = diff_chain(eff2, influx_eff2, beta_p, death, d["div_eff"]) dt_state = np.concatenate((dt_naive, dt_eff_1, dt_eff_2, [dt_cyto1], [dt_cyto2],[dt_myc])) return dt_state
def model_2021_py(state, time, d, virus_model, prolif_model): naive = state[0] prec = state[1] prec1 = state[2] th1 = state[3] th1_2 = state[4] tfh = state[5] tfh_2 = state[6] tfhc = state[7] tfhc_2 = state[8] tr1 = state[9] tr1_2 = state[10] th1_mem = state[11] tfh_mem = state[12] il2 = state[13] myc = state[14] ag = virus_model(time) tprec = prec1 + prec teff = th1 + th1_2 + tfh + tfh_2 d_il2 = get_il2(naive, tprec, teff, il2, ag, d) # get probabilities, add feedback by ag and normalize p_fb = get_probs(d, ag) p_norm = norm_probs(p_fb) p_prec = 0.25 p_norm = (1 - p_prec) * p_norm pTh1, pTfh, pTr1, pTfhc = p_norm # get proliferation based on myc prolif_Th1 = d["prolif_Th1"] * prolif_model(state, d) prolif_Tfh = d["prolif_Tfh"] * prolif_model(state, d) prolif_Tr1 = d["prolif_Tr1"] * pos_fb(myc, d["K_myc"]) prolif_Tfhc = d["prolif_Tfhc"] * pos_fb(myc, d["K_myc"]) # proliferation of precursors prolif_Prec = d["prolif_Prec"] * prolif_model(state, d) d_naive = -d["r_naive"] * naive d_prec = 2 * d["r_naive"] * naive + ( 2 * prolif_Prec * p_prec * d["r_prec"]) * prec1 - (d["r_prec"] + d["death_prec"]) * prec # precursor differentiation d_prec1 = d["r_prec"] * prec - (d["r_prec"] + d["death_prec"]) * prec1 # effector differentiation d_th1 = d["n_div"] * pTh1 * d["r_prec"] * prec1 + prolif_Th1 * ( 2 * th1_2 - th1) - d["death_th1"] * th1 d_th1_2 = prolif_Th1 * (th1 - th1_2) - (d["death_th1"] + d["r_mem"]) * th1_2 d_tfh = d["n_div"] * pTfh * d["r_prec"] * prec1 + prolif_Tfh * ( 2 * tfh_2 - tfh) - d["death_tfh"] * tfh d_tfh_2 = prolif_Tfh * (tfh - tfh_2) - (d["death_tfh"] + d["r_mem"]) * tfh_2 # chronic Tfh d_tfhc = d["n_div"] * pTfhc * d["r_prec"] * prec1 + prolif_Tfhc * ( 2 * tfhc_2 - tfhc) - d["death_tfhc"] * tfhc d_tfhc_2 = prolif_Tfhc * (tfhc - tfhc_2) - d["death_tfhc"] * tfhc_2 # Tr1 cells d_tr1 = d["n_div"] * pTr1 * d["r_prec"] * prec1 + prolif_Tr1 * ( 2 * tr1_2 - tr1) - d["death_tr1"] * tr1 d_tr1_2 = prolif_Tr1 * (tr1 - tr1_2) - d["death_tr1"] * tr1_2 # memory d_th1_mem = d["r_mem"] * th1_2 - d["death_mem"] * th1_mem d_tfh_mem = d["r_mem"] * tfh_2 - d["death_mem"] * tfh_mem # molecules d_myc = -d["deg_myc"] * myc dt_state = [ d_naive, d_prec, d_prec1, d_th1, d_th1_2, d_tfh, d_tfh_2, d_tfhc, d_tfhc_2, d_tr1, d_tr1_2, d_th1_mem, d_tfh_mem, d_il2, d_myc ] return dt_state
def get_eff_prolif(state, d): myc = state[13] params = ["prolif_" + n for n in ["th1", "tfh", "tr1", "tfhc"]] prolif_arr = [d[p] * pos_fb(myc, d["EC50_myc"]) for p in params] return prolif_arr
def menten_prolif(state, d, idx, K): # keep d because menten prolif 2 needs it as well # index will get either il2 or myc val = state[-idx] beta_p = pos_fb(val, K) return beta_p