R/dose.R

#' Function to represent a Hill curve.
#'
#' @param ecFifty The EC50 of the drug.
#' @param conc The concentration or concentrations.
#' @param n The hill coefficient.
#'
#' @return The magnitude of drug effect to use at each concentration.
#' @export
#'
#' @examples
#' hillEq(1.0, 0.5, 1.2)
hillEq <- function(ecFifty, conc, n) {
  return(conc^n / (ecFifty + conc^n))
}


#' Function to convert from a Hill curve to parameter values.
#'
#' @param ecFifty The EC50 of the drug.
#' @param conc The concentration or concentrations.
#' @param n The hill coefficient.
#' @param Pcontrol The parameters that define the control condition.
#' @param Pdrug The parameters that define the drug effect.
#'
#' @return The parameters for the drug concentration.
#' @export
#'
#' @examples
drugParam <- function(ecFifty, conc, n, Pcontrol, Pdrug) {
  theta <- hillEq(ecFifty, conc, n)

  if (length(Pcontrol) != 4) {
    stop("Pcontrol should have four values.")
  } else if (length(Pdrug) != 4) {
    stop("Pdrug should have four values.")
  }

  Pout <- Pcontrol + theta * Pdrug

  return(Pout)
}


#' Title
#'
#' @param Pcontrol The parameters that define the control condition.
#' @param Pdrug The parameters that define the drug effect.
#' @param n The hill coefficient.
#' @param ecFifty The EC50 of the drug.
#' @param delay The delay before we switch to drug having an effect.
#' @param conc A vector or list of drug concentrations.
#' @param times A vector of list of times to solve for.
#'
#' @return
#' @export
#'
#' @examples
drugSim <- function(Pcontrol, Pdrug, n, ecFifty, delay, conc, times) {
  outt <- lapply(conc, function(x) drugParam(ecFifty, x, n, Pcontrol, Pdrug))

  outtt <- mapply(function(x, y) cycleModelDelay(Pcontrol, x, delay, start = c(1.0, 1.0, 0.0), y), outt, times)

  return(outtt)
}
meyer-lab/cell-cycle-growth documentation built on May 13, 2019, 6:09 p.m.