auxiliary/modelfiles/other/simulators/simulate_Stratified_Inoculum_Model_ode.R

#' Stratified Inoculum Model
#' 
#' @description 
#' 
#' @details 
#' 
#' This code was generated by the modelbuilder R package.  
#' The model is implemented as a set of ordinary differential equations using the deSolve package. 
#' The following R packages need to be loaded for the function to work: deSolve. 
#' 
#' @param H1 : starting value for antigen : numeric
#' @param H2 : starting value for antigen : numeric
#' @param H3 : starting value for antigen : numeric
#' @param H4 : starting value for antigen : numeric
#' @param H5 : starting value for antigen : numeric
#' @param H6 : starting value for antigen : numeric
#' @param H7 : starting value for antigen : numeric
#' @param H8 : starting value for antigen : numeric
#' @param H9 : starting value for antigen : numeric
#' @param H10 : starting value for antigen : numeric
#' @param H11 : starting value for antigen : numeric
#' @param H12 : starting value for antigen : numeric
#' @param H13 : starting value for antigen : numeric
#' @param H14 : starting value for antigen : numeric
#' @param F : starting value for innate response : numeric
#' @param B1 : starting value for B cells : numeric
#' @param B2 : starting value for B cells : numeric
#' @param B3 : starting value for B cells : numeric
#' @param B4 : starting value for B cells : numeric
#' @param B5 : starting value for B cells : numeric
#' @param B6 : starting value for B cells : numeric
#' @param B7 : starting value for B cells : numeric
#' @param B8 : starting value for B cells : numeric
#' @param B9 : starting value for B cells : numeric
#' @param B10 : starting value for B cells : numeric
#' @param B11 : starting value for B cells : numeric
#' @param B12 : starting value for B cells : numeric
#' @param B13 : starting value for B cells : numeric
#' @param B14 : starting value for B cells : numeric
#' @param A1 : starting value for antibodies : numeric
#' @param A2 : starting value for antibodies : numeric
#' @param A3 : starting value for antibodies : numeric
#' @param A4 : starting value for antibodies : numeric
#' @param A5 : starting value for antibodies : numeric
#' @param A6 : starting value for antibodies : numeric
#' @param A7 : starting value for antibodies : numeric
#' @param A8 : starting value for antibodies : numeric
#' @param A9 : starting value for antibodies : numeric
#' @param A10 : starting value for antibodies : numeric
#' @param A11 : starting value for antibodies : numeric
#' @param A12 : starting value for antibodies : numeric
#' @param A13 : starting value for antibodies : numeric
#' @param A14 : starting value for antibodies : numeric
#' @param k1 : killing rate 1 : numeric
#' @param k2 : killing rate 2 : numeric
#' @param k3 : killing rate 3 : numeric
#' @param k4 : killing rate 4 : numeric
#' @param k5 : killing rate 5 : numeric
#' @param k6 : killing rate 6 : numeric
#' @param k7 : killing rate 7 : numeric
#' @param k8 : killing rate 8 : numeric
#' @param k9 : killing rate 9 : numeric
#' @param k10 : killing rate 10 : numeric
#' @param k11 : killing rate 11 : numeric
#' @param k12 : killing rate 12 : numeric
#' @param k13 : killing rate 13 : numeric
#' @param k14 : killing rate 14 : numeric
#' @param c1 : antigen decay 1 : numeric
#' @param c2 : antigen decay 2 : numeric
#' @param c3 : antigen decay 3 : numeric
#' @param c4 : antigen decay 4 : numeric
#' @param c5 : antigen decay 5 : numeric
#' @param c6 : antigen decay 6 : numeric
#' @param c7 : antigen decay 7 : numeric
#' @param c8 : antigen decay 8 : numeric
#' @param c9 : antigen decay 9 : numeric
#' @param c10 : antigen decay 10 : numeric
#' @param c11 : antigen decay 11 : numeric
#' @param c12 : antigen decay 12 : numeric
#' @param c13 : antigen decay 13 : numeric
#' @param c14 : antigen decay 14 : numeric
#' @param p : innate growth : numeric
#' @param m : innate decay : numeric
#' @param q : innate induction : numeric
#' @param fmax : innate saturation : numeric
#' @param n : antigen halfpoint : numeric
#' @param g1 : B cell growth 1 : numeric
#' @param g2 : B cell growth 2 : numeric
#' @param g3 : B cell growth 3 : numeric
#' @param g4 : B cell growth 4 : numeric
#' @param g5 : B cell growth 5 : numeric
#' @param g6 : B cell growth 6 : numeric
#' @param g7 : B cell growth 7 : numeric
#' @param g8 : B cell growth 8 : numeric
#' @param g9 : B cell growth 9 : numeric
#' @param g10 : B cell growth 10 : numeric
#' @param g11 : B cell growth 11 : numeric
#' @param g12 : B cell growth 12 : numeric
#' @param g13 : B cell growth 13 : numeric
#' @param g14 : B cell growth 14 : numeric
#' @param s1 : b cell halfpoint 1 : numeric
#' @param s2 : b cell halfpoint 2 : numeric
#' @param s3 : b cell halfpoint 3 : numeric
#' @param s4 : b cell halfpoint 4 : numeric
#' @param s5 : b cell halfpoint 5 : numeric
#' @param s6 : b cell halfpoint 6 : numeric
#' @param s7 : b cell halfpoint 7 : numeric
#' @param s8 : b cell halfpoint 8 : numeric
#' @param s9 : b cell halfpoint 9 : numeric
#' @param s10 : b cell halfpoint 10 : numeric
#' @param s11 : b cell halfpoint 11 : numeric
#' @param s12 : b cell halfpoint 12 : numeric
#' @param s13 : b cell halfpoint 13 : numeric
#' @param s14 : b cell halfpoint 14 : numeric
#' @param r1 : antibody production 1 : numeric
#' @param r2 : antibody production 2 : numeric
#' @param r3 : antibody production 3 : numeric
#' @param r4 : antibody production 4 : numeric
#' @param r5 : antibody production 5 : numeric
#' @param r6 : antibody production 6 : numeric
#' @param r7 : antibody production 7 : numeric
#' @param r8 : antibody production 8 : numeric
#' @param r9 : antibody production 9 : numeric
#' @param r10 : antibody production 10 : numeric
#' @param r11 : antibody production 11 : numeric
#' @param r12 : antibody production 12 : numeric
#' @param r13 : antibody production 13 : numeric
#' @param r14 : antibody production 14 : numeric
#' @param d1 : antibody decay 1 : numeric
#' @param d2 : antibody decay 2 : numeric
#' @param d3 : antibody decay 3 : numeric
#' @param d4 : antibody decay 4 : numeric
#' @param d5 : antibody decay 5 : numeric
#' @param d6 : antibody decay 6 : numeric
#' @param d7 : antibody decay 7 : numeric
#' @param d8 : antibody decay 8 : numeric
#' @param d9 : antibody decay 9 : numeric
#' @param d10 : antibody decay 10 : numeric
#' @param d11 : antibody decay 11 : numeric
#' @param d12 : antibody decay 12 : numeric
#' @param d13 : antibody decay 13 : numeric
#' @param d14 : antibody decay 14 : numeric
#' @param tstart : Start time of simulation : numeric
#' @param tfinal : Final time of simulation : numeric
#' @param dt : Time step : numeric
#' @return The function returns the output as a list. 
#' The time-series from the simulation is returned as a dataframe saved as list element \code{ts}. 
#' The \code{ts} dataframe has one column per compartment/variable. The first column is time.   
#' @examples  
#' # To run the simulation with default parameters:  
#' result <- simulate_Stratified_Inoculum_Model_ode() 
#' # To choose values other than the standard one, specify them like this:  
#' result <- simulate_Stratified_Inoculum_Model_ode(H1 = 200,H2 = 200,H3 = 200,H4 = 200,H5 = 200,H6 = 200,H7 = 200,H8 = 200,H9 = 200,H10 = 200,H11 = 200,H12 = 200,H13 = 200,H14 = 200,F = 2,B1 = 2,B2 = 2,B3 = 2,B4 = 2,B5 = 2,B6 = 2,B7 = 2,B8 = 2,B9 = 2,B10 = 2,B11 = 2,B12 = 2,B13 = 2,B14 = 2,A1 = 2,A2 = 2,A3 = 2,A4 = 2,A5 = 2,A6 = 2,A7 = 2,A8 = 2,A9 = 2,A10 = 2,A11 = 2,A12 = 2,A13 = 2,A14 = 2) 
#' # You can display or further process the result, like this:  
#' plot(result$ts[,'time'],result$ts[,'H1'],xlab='Time',ylab='Numbers',type='l') 
#' print(paste('Max number of H1: ',max(result$ts[,'H1']))) 
#' @section Warning: This function does not perform any error checking. So if you try to do something nonsensical (e.g. have negative values for parameters), the code will likely abort with an error message.
#' @section Model Author: Andreas Handel
#' @section Model creation date: 2023-05-08
#' @section Code Author: generated by the \code{modelbuilder} R package 
#' @section Code creation date: 2023-05-08
#' @export 
 
simulate_Stratified_Inoculum_Model_ode <- function(H1 = 100, H2 = 100, H3 = 100, H4 = 100, H5 = 100, H6 = 100, H7 = 100, H8 = 100, H9 = 100, H10 = 100, H11 = 100, H12 = 100, H13 = 100, H14 = 100, F = 1, B1 = 1, B2 = 1, B3 = 1, B4 = 1, B5 = 1, B6 = 1, B7 = 1, B8 = 1, B9 = 1, B10 = 1, B11 = 1, B12 = 1, B13 = 1, B14 = 1, A1 = 1, A2 = 1, A3 = 1, A4 = 1, A5 = 1, A6 = 1, A7 = 1, A8 = 1, A9 = 1, A10 = 1, A11 = 1, A12 = 1, A13 = 1, A14 = 1, k1 = 1e-04, k2 = 1e-04, k3 = 1e-04, k4 = 1e-04, k5 = 1e-04, k6 = 1e-04, k7 = 1e-04, k8 = 1e-04, k9 = 1e-04, k10 = 1e-04, k11 = 1e-04, k12 = 1e-04, k13 = 1e-04, k14 = 1e-04, c1 = 2, c2 = 2, c3 = 2, c4 = 2, c5 = 2, c6 = 2, c7 = 2, c8 = 2, c9 = 2, c10 = 2, c11 = 2, c12 = 2, c13 = 2, c14 = 2, p = 4, m = 4, q = 3, fmax = 1e+05, n = 100, g1 = 0.5, g2 = 0.5, g3 = 0.5, g4 = 0.5, g5 = 0.5, g6 = 0.5, g7 = 0.5, g8 = 0.5, g9 = 0.5, g10 = 0.5, g11 = 0.5, g12 = 0.5, g13 = 0.5, g14 = 0.5, s1 = 10, s2 = 10, s3 = 10, s4 = 10, s5 = 10, s6 = 10, s7 = 10, s8 = 10, s9 = 10, s10 = 10, s11 = 10, s12 = 10, s13 = 10, s14 = 10, r1 = 100, r2 = 100, r3 = 100, r4 = 100, r5 = 100, r6 = 100, r7 = 100, r8 = 100, r9 = 100, r10 = 100, r11 = 100, r12 = 100, r13 = 100, r14 = 100, d1 = 10, d2 = 10, d3 = 10, d4 = 10, d5 = 10, d6 = 10, d7 = 10, d8 = 10, d9 = 10, d10 = 10, d11 = 10, d12 = 10, d13 = 10, d14 = 10, tstart = 0, tfinal = 20, dt = 0.1) 
{ 
  ############################## 
  #Block of ODE equations for deSolve 
  ############################## 
  Stratified_Inoculum_Model_ode_fct <- function(t, y, parms) 
  {
    with( as.list(c(y,parms)), { #lets us access variables and parameters stored in y and parms by name 
    #StartODES
    #antigen : removal : decay :
    dH1_mb = +k1*A1*H1 -c1*H1
    #antigen : removal : decay :
    dH2_mb = +k2*A2*H2 -c2*H2
    #antigen : removal : decay :
    dH3_mb = +k3*A3*H3 -c3*H3
    #antigen : removal : decay :
    dH4_mb = +k4*A4*H4 -c4*H4
    #antigen : removal : decay :
    dH5_mb = +k5*A5*H5 -c5*H5
    #antigen : removal : decay :
    dH6_mb = +k6*A6*H6 -c6*H6
    #antigen : removal : decay :
    dH7_mb = +k7*A7*H7 -c7*H7
    #antigen : removal : decay :
    dH8_mb = +k8*A8*H8 -c8*H8
    #antigen : removal : decay :
    dH9_mb = +k9*A9*H9 -c9*H9
    #antigen : removal : decay :
    dH10_mb = +k10*A10*H10 -c10*H10
    #antigen : removal : decay :
    dH11_mb = +k11*A11*H11 -c11*H11
    #antigen : removal : decay :
    dH12_mb = +k12*A12*H12 -c12*H12
    #antigen : removal : decay :
    dH13_mb = +k13*A13*H13 -c13*H13
    #antigen : removal : decay :
    dH14_mb = +k14*A14*H14 -c14*H14
    #innate response : growth : decay : max growth : decay from max :
    dF_mb = +p -m*F +q*fmax*H1/(H1+n) -q*F*H1/(H1+n)
    #B cells : induction :
    dB1_mb = +g1*B1*H1*F/(s1+H1*F)
    #B cells : induction :
    dB2_mb = +g2*B2*H2*F/(s2+H2*F)
    #B cells : induction :
    dB3_mb = +g3*B3*H3*F/(s3+H3*F)
    #B cells : induction :
    dB4_mb = +g4*B4*H4*F/(s4+H4*F)
    #B cells : induction :
    dB5_mb = +g5*B5*H5*F/(s5+H5*F)
    #B cells : induction :
    dB6_mb = +g6*B6*H6*F/(s6+H6*F)
    #B cells : induction :
    dB7_mb = +g7*B7*H7*F/(s7+H7*F)
    #B cells : induction :
    dB8_mb = +g8*B8*H8*F/(s8+H8*F)
    #B cells : induction :
    dB9_mb = +g9*B9*H9*F/(s9+H9*F)
    #B cells : induction :
    dB10_mb = +g10*B10*H10*F/(s10+H10*F)
    #B cells : induction :
    dB11_mb = +g11*B11*H11*F/(s11+H11*F)
    #B cells : induction :
    dB12_mb = +g12*B12*H12*F/(s12+H12*F)
    #B cells : induction :
    dB13_mb = +g13*B13*H13*F/(s13+H13*F)
    #B cells : induction :
    dB14_mb = +g14*B14*H14*F/(s14+H14*F)
    #antibodies : removal : production of antibodies : decay :
    dA1_mb = -k1*A1*H1 +r1*B1 -d1*A1
    #antibodies : removal : production of antibodies : decay :
    dA2_mb = -k2*A2*H2 +r2*B2 -d2*A2
    #antibodies : removal : production of antibodies : decay :
    dA3_mb = -k3*A3*H3 +r3*B3 -d3*A3
    #antibodies : removal : production of antibodies : decay :
    dA4_mb = -k4*A4*H4 +r4*B4 -d4*A4
    #antibodies : removal : production of antibodies : decay :
    dA5_mb = -k5*A5*H5 +r5*B5 -d5*A5
    #antibodies : removal : production of antibodies : decay :
    dA6_mb = -k6*A6*H6 +r6*B6 -d6*A6
    #antibodies : removal : production of antibodies : decay :
    dA7_mb = -k7*A7*H7 +r7*B7 -d7*A7
    #antibodies : removal : production of antibodies : decay :
    dA8_mb = -k8*A8*H8 +r8*B8 -d8*A8
    #antibodies : removal : production of antibodies : decay :
    dA9_mb = -k9*A9*H9 +r9*B9 -d9*A9
    #antibodies : removal : production of antibodies : decay :
    dA10_mb = -k10*A10*H10 +r10*B10 -d10*A10
    #antibodies : removal : production of antibodies : decay :
    dA11_mb = -k11*A11*H11 +r11*B11 -d11*A11
    #antibodies : removal : production of antibodies : decay :
    dA12_mb = -k12*A12*H12 +r12*B12 -d12*A12
    #antibodies : removal : production of antibodies : decay :
    dA13_mb = -k13*A13*H13 +r13*B13 -d13*A13
    #antibodies : removal : production of antibodies : decay :
    dA14_mb = -k14*A14*H14 +r14*B14 -d14*A14
    #EndODES
    list(c(dH1_mb,dH2_mb,dH3_mb,dH4_mb,dH5_mb,dH6_mb,dH7_mb,dH8_mb,dH9_mb,dH10_mb,dH11_mb,dH12_mb,dH13_mb,dH14_mb,dF_mb,dB1_mb,dB2_mb,dB3_mb,dB4_mb,dB5_mb,dB6_mb,dB7_mb,dB8_mb,dB9_mb,dB10_mb,dB11_mb,dB12_mb,dB13_mb,dB14_mb,dA1_mb,dA2_mb,dA3_mb,dA4_mb,dA5_mb,dA6_mb,dA7_mb,dA8_mb,dA9_mb,dA10_mb,dA11_mb,dA12_mb,dA13_mb,dA14_mb)) 
  } ) } #close with statement, end ODE code block 
 
  ############################## 
  #Main function code block 
  ############################## 
  #Creating named vectors 
  varvec_mb = c(H1 = H1, H2 = H2, H3 = H3, H4 = H4, H5 = H5, H6 = H6, H7 = H7, H8 = H8, H9 = H9, H10 = H10, H11 = H11, H12 = H12, H13 = H13, H14 = H14, F = F, B1 = B1, B2 = B2, B3 = B3, B4 = B4, B5 = B5, B6 = B6, B7 = B7, B8 = B8, B9 = B9, B10 = B10, B11 = B11, B12 = B12, B13 = B13, B14 = B14, A1 = A1, A2 = A2, A3 = A3, A4 = A4, A5 = A5, A6 = A6, A7 = A7, A8 = A8, A9 = A9, A10 = A10, A11 = A11, A12 = A12, A13 = A13, A14 = A14) 
  parvec_mb = c(k1 = k1, k2 = k2, k3 = k3, k4 = k4, k5 = k5, k6 = k6, k7 = k7, k8 = k8, k9 = k9, k10 = k10, k11 = k11, k12 = k12, k13 = k13, k14 = k14, c1 = c1, c2 = c2, c3 = c3, c4 = c4, c5 = c5, c6 = c6, c7 = c7, c8 = c8, c9 = c9, c10 = c10, c11 = c11, c12 = c12, c13 = c13, c14 = c14, p = p, m = m, q = q, fmax = fmax, n = n, g1 = g1, g2 = g2, g3 = g3, g4 = g4, g5 = g5, g6 = g6, g7 = g7, g8 = g8, g9 = g9, g10 = g10, g11 = g11, g12 = g12, g13 = g13, g14 = g14, s1 = s1, s2 = s2, s3 = s3, s4 = s4, s5 = s5, s6 = s6, s7 = s7, s8 = s8, s9 = s9, s10 = s10, s11 = s11, s12 = s12, s13 = s13, s14 = s14, r1 = r1, r2 = r2, r3 = r3, r4 = r4, r5 = r5, r6 = r6, r7 = r7, r8 = r8, r9 = r9, r10 = r10, r11 = r11, r12 = r12, r13 = r13, r14 = r14, d1 = d1, d2 = d2, d3 = d3, d4 = d4, d5 = d5, d6 = d6, d7 = d7, d8 = d8, d9 = d9, d10 = d10, d11 = d11, d12 = d12, d13 = d13, d14 = d14) 
  timevec_mb = seq(tstart, tfinal,by = dt) 
  #Running the model 
  simout = deSolve::ode(y = varvec_mb, parms = parvec_mb, times = timevec_mb,  func = Stratified_Inoculum_Model_ode_fct, rtol = 1e-12, atol = 1e-12) 
  #Setting up empty list and returning result as data frame called ts 
  result <- list() 
  result$ts <- as.data.frame(simout) 
  return(result) 
} 
ahgroup/modelbuilder documentation built on April 14, 2024, 2:29 p.m.