#' Influenza OAS Model
#'
#' @description Influenza Antibody Model with 2 types of B-cells/antibodies
#'
#' @details An extension of Zarnitsyna et al 2016 PLoS Pathogens
#'
#' 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 Hf : starting value for free antigen : numeric
#' @param Hb : starting value for bound antigen : numeric
#' @param B1 : starting value for Type 1 B cells : numeric
#' @param A1 : starting value for Type 1 antibodies : numeric
#' @param B2 : starting value for Type 2 B cells : numeric
#' @param A2 : starting value for Type 2 antibodies : numeric
#' @param k1 : binding rate 1 : numeric
#' @param k2 : binding rate 2 : numeric
#' @param df : free antigen decay rate : numeric
#' @param db : bound antigen decay rate : numeric
#' @param s1 : B1 cell generation rate : numeric
#' @param del1 : bound antibody strength 1 : numeric
#' @param p1 : saturation level 1 : numeric
#' @param a1 : FIM impact 1 : numeric
#' @param g1 : antibody 1 production rate : numeric
#' @param d1 : antibody 1 decay rate : numeric
#' @param s2 : B2 cell generation rate : numeric
#' @param del2 : bound antibody strength 2 : numeric
#' @param p2 : saturation level 2 : numeric
#' @param a2 : FIM impact 2 : numeric
#' @param g2 : antibody 2 production rate : numeric
#' @param d2 : antibody 2 decay rate : 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_Influenza_OAS_Model_ode()
#' # To choose values other than the standard one, specify them like this:
#' result <- simulate_Influenza_OAS_Model_ode(Hf = 20000,Hb = 0,B1 = 200,A1 = 200,B2 = 20,A2 = 20)
#' # You can display or further process the result, like this:
#' plot(result$ts[,'time'],result$ts[,'Hf'],xlab='Time',ylab='Numbers',type='l')
#' print(paste('Max number of Hf: ',max(result$ts[,'Hf'])))
#' @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-03-30
#' @section Code Author: generated by the \code{modelbuilder} R package
#' @section Code creation date: 2023-03-30
#' @export
simulate_Influenza_OAS_Model_ode <- function(Hf = 10000, Hb = 0, B1 = 100, A1 = 100, B2 = 10, A2 = 10, k1 = 0.01, k2 = 0.02, df = 0.5, db = 0.7, s1 = 1, del1 = 0, p1 = 1000, a1 = 0, g1 = 0.1, d1 = 0.1, s2 = 0.5, del2 = 0, p2 = 1000, a2 = 0, g2 = 0.1, d2 = 0.1, tstart = 0, tfinal = 100, dt = 0.1)
{
##############################
#Block of ODE equations for deSolve
##############################
Influenza_OAS_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
#free antigen : binding by antibody 1 : binding by antibody 2 : free antigen decay :
dHf_mb = -k1*A1*Hf -k2*A2*Hf -df*Hf
#bound antigen : binding by antibody 1 : binding by antibody 2 : bound antigen decay :
dHb_mb = +k1*A1*Hf +k2*A2*Hf -db*Hb
#Type 1 B cells : B1 cell activation :
dB1_mb = +s1*B1*(Hf+del1*Hb)/(p1+Hf+del1*Hb)*(1/(1+a1*Hb))
#Type 1 antibodies : A1 generation : A1 binding : A1 decay :
dA1_mb = +g1*B1 -k1*A1*Hf -d1*A1
#Type 2 B cells : B2 cell activation :
dB2_mb = +s2*B2*(Hf+del2*Hb)/(p2+Hf+del2*Hb)*(1/(1+a2*Hb))
#Type 2 antibodies : A2 generation : A2 binding : A2 decay :
dA2_mb = +g2*B2 -k2*A2*Hf -d2*A2
#EndODES
list(c(dHf_mb,dHb_mb,dB1_mb,dA1_mb,dB2_mb,dA2_mb))
} ) } #close with statement, end ODE code block
##############################
#Main function code block
##############################
#Creating named vectors
varvec_mb = c(Hf = Hf, Hb = Hb, B1 = B1, A1 = A1, B2 = B2, A2 = A2)
parvec_mb = c(k1 = k1, k2 = k2, df = df, db = db, s1 = s1, del1 = del1, p1 = p1, a1 = a1, g1 = g1, d1 = d1, s2 = s2, del2 = del2, p2 = p2, a2 = a2, g2 = g2, d2 = d2)
timevec_mb = seq(tstart, tfinal,by = dt)
#Running the model
simout = deSolve::ode(y = varvec_mb, parms = parvec_mb, times = timevec_mb, func = Influenza_OAS_Model_ode_fct, rtol = 1e-10, atol = 1e-10)
#Setting up empty list and returning result as data frame called ts
result <- list()
result$ts <- as.data.frame(simout)
return(result)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.