R/parameterize_model.R

Defines functions parameterize_model

Documented in parameterize_model

#' parameterize_model
#' 
#' This wrapper function allows for a consistent workflow where user can set a variable for 
#' the model being used such as MODEL <- "pbtk", then call wrapper function, 
#' p <- parameterize_model(chem.name=MY.CHEM, model=MODEL), and then solve for other 
#' properties such as Cvt <- solve_model(parameters=p, model=MODEL).
#' 
#' @param chem.name Either the chemical name, CAS number, or the parameters
#' must be specified.
#' 
#' @param chem.cas Either the chemical name, CAS number, or the parameters must
#' be specified.
#' 
#' @param dtxsid EPA's DSSTox Structure ID (\url{https://comptox.epa.gov/dashboard})  
#' the chemical must be identified by either CAS, name, or DTXSIDs
#' 
#' @param model Specified model to use in simulation: "pbtk", "3compartment",
#' "3compartmentss", "1compartment", "schmitt", ...
#'
#' @param ... Additional arguments passed to the model parameterization function.
#' 
#' @return A matrix of class deSolve with a column for time(in days), each
#' compartment, the area under the curve, and plasma concentration and a row
#' for each time point.
#' 
#' @seealso \code{\link{list_models}}
#' @seealso \code{\link{solve_model}}
#' 
#' @author John Wambaugh
#' 
#' @concept model parameterization
#' @concept standard model tools
#' 
#' @export parameterize_model
#' 
#' @importFrom purrr compact 
parameterize_model <- function(chem.name = NULL,
                    chem.cas = NULL,
                    dtxsid = NULL,
                    model = "sumclearancesplus",
                    ...)
{
# We need to describe the chemical to be simulated one way or another:
  if (is.null(chem.cas) & 
      is.null(chem.name) & 
      is.null(dtxsid)) 
    stop('chem.name, chem.cas, or dtxsid must be specified.')

  # We need to know model-specific information (from modelinfo_[MODEL].R]) 
  # to set up the solver:
  if (is.null(model)) stop("Model must be specified.")
  model <- tolower(model)
  if (!(model %in% names(model.list)))            
  {
    stop(paste("Model",model,"not available. Please select from:",
      paste(names(model.list),collapse=", ")))
  } else {
# Model parameter names:
    param_names <- model.list[[model]]$param.names
# name of function that generates the model parameters:
    parameterize_function <- model.list[[model]]$parameterize.func
  }

  parameters <- do.call(parameterize_function, args=purrr::compact(c(
    list(
        chem.cas=chem.cas,
        chem.name=chem.name,
        dtxsid=dtxsid
        ),
      list(...)))) 

  if (!all(param_names %in% names(parameters)))
  {
    stop(paste("Missing parameters:",
      paste(param_names[which(!param_names %in% 
      names(parameters))],collapse=', '),
      ". ",
      parameterize_function,
      " does not specify all parameters defined by param_names in modelinfo file.",sep="")) 
  }

  return(parameters) 
}

Try the httk package in your browser

Any scripts or data that you put into this service are public.

httk documentation built on Nov. 26, 2026, 9:08 a.m.