diff --git a/R/tcplVarMat.R b/R/tcplVarMat.R index c6caf1d..9562c89 100644 --- a/R/tcplVarMat.R +++ b/R/tcplVarMat.R @@ -9,6 +9,8 @@ #' #' @param dsstox_substance_id Integer, chemical ID values to subset on #' @param aeid Integer, assay endpoint ID values to subset on +#' @param std.vars Character, standard set of matrices; use this parameter to +#' subset this list #' @param add.vars Character, mc4 or mc5 field(s) not included in the standard #' list to add additional matrices #' @param flag Integer or Logical of length 1, passed to @@ -29,9 +31,9 @@ #' winning model. #' \item "acc_verbose" -- The ACC for the winning model, with text describing #' some situations. -#' \item "mc_hitc" -- The hit-call for the winning model in +#' \item "hitc_mc" -- The hit-call for the winning model in #' multiple-concentration (mc) screening. -#' \item "sc_hitc" -- The hit-call in single concentration (sc) screening. +#' \item "hitc_sc" -- The hit-call in single concentration (sc) screening. #' \item "zscore" -- The z-score based on the output from \code{tcplCytoPt}. #' The formula used for calculating the z-score is #' \eqn{-(\mathit{ac50} - \mathit{cyto\_pt})/\mathit{global\_mad}} @@ -85,6 +87,7 @@ #' dtxsid <- c("DTXSID4034653", "DTXSID2032683", "DTXSID6032358", #' "DTXSID0032651", "DTXSID8034401") #' varmat <- tcplVarMat(aeid = aeids, dsstox_substance_id = dtxsid) +#' varmat <- tcplVarMat(aeid = aeids, std.vars = c("ac50", "zscore")) #' varmat <- tcplVarMat(aeid = aeids, add.vars = c("m4id", "resp_max", "max_med")) #' #' ## To save output to file @@ -101,6 +104,7 @@ tcplVarMat <- function(dsstox_substance_id = NULL, aeid = NULL, + std.vars = c("ac50", "ac50_verbose", "acc", "acc_verbose", "hitc_mc", "hitc_sc", "zscore"), add.vars = NULL, flag = TRUE, cyto.pars = list()) { @@ -117,9 +121,7 @@ tcplVarMat <- function(dsstox_substance_id = NULL, if (!all(add.vars %in% valid_var)) stop("Invald add.vars value(s).") - ac50str = ifelse(check_tcpl_db_schema(),"ac50","modl_ga") - - std.vars <- c(ac50str, paste0(ac50str, "_verbose"), "acc", "acc_verbose", "hitc", "hitc.y", "zscore") + std.vars[std.vars == "ac50"] = ifelse(check_tcpl_db_schema(),"ac50","modl_ga") vars <- c(std.vars, add.vars) ## Load all possibilities to create matrix dimensions @@ -186,9 +188,11 @@ tcplVarMat <- function(dsstox_substance_id = NULL, var <- sub("_verbose", "", var) verbose = TRUE } + mc_var <- sub("\\_mc|\\_sc", "", var) + if (!mc_var %in% colnames(mc5)) stop(paste(mc_var, "is not a valid column in mc4 or mc5.")) long_mc5 <- mc5 |> group_by(dsstox_substance_id,aenm,chnm) |> - summarise(across(all_of(sub("\\.y", "", var)), mean)) |> filter(!is.na(dsstox_substance_id)) - long_all <- long_mc5 |> full_join(long_sc2, by = c("dsstox_substance_id","aenm", "chnm")) + summarise(across(all_of(mc_var), mean)) |> filter(!is.na(dsstox_substance_id)) + long_all <- long_mc5 |> full_join(long_sc2, suffix = c("_mc", "_sc"), by = c("dsstox_substance_id","aenm", "chnm")) long_res <- if (substr(var, 1, 2) == "ac") long_all |> mutate("{var}" := case_when(is.na(get(var)) && hitc == 0 ~ 1e8, is.na(get(var)) && hitc == 1 ~ 1e7, @@ -205,7 +209,7 @@ tcplVarMat <- function(dsstox_substance_id = NULL, mat_list <- lapply(vars, build_matrix) - names(mat_list) = c("ac50", "ac50_verbose", "acc", "acc_verbose", "mc_hitc", "sc_hitc", "zscore", add.vars) + names(mat_list) <- vars mat_list diff --git a/man/tcplVarMat.Rd b/man/tcplVarMat.Rd index df3f720..3de52ab 100644 --- a/man/tcplVarMat.Rd +++ b/man/tcplVarMat.Rd @@ -7,6 +7,8 @@ tcplVarMat( dsstox_substance_id = NULL, aeid = NULL, + std.vars = c("ac50", "ac50_verbose", "acc", "acc_verbose", "hitc_mc", "hitc_sc", + "zscore"), add.vars = NULL, flag = TRUE, cyto.pars = list() @@ -17,6 +19,9 @@ tcplVarMat( \item{aeid}{Integer, assay endpoint ID values to subset on} +\item{std.vars}{Character, standard set of matrices; use this parameter to +subset this list} + \item{add.vars}{Character, mc4 or mc5 field(s) not included in the standard list to add additional matrices} @@ -47,9 +52,9 @@ for different parameters. The standard list of matrices returned includes: winning model. \item "acc_verbose" -- The ACC for the winning model, with text describing some situations. - \item "mc_hitc" -- The hit-call for the winning model in + \item "hitc_mc" -- The hit-call for the winning model in multiple-concentration (mc) screening. - \item "sc_hitc" -- The hit-call in single concentration (sc) screening. + \item "hitc_sc" -- The hit-call in single concentration (sc) screening. \item "zscore" -- The z-score based on the output from \code{tcplCytoPt}. The formula used for calculating the z-score is \eqn{-(\mathit{ac50} - \mathit{cyto\_pt})/\mathit{global\_mad}} @@ -99,6 +104,7 @@ aeids <- c(80) dtxsid <- c("DTXSID4034653", "DTXSID2032683", "DTXSID6032358", "DTXSID0032651", "DTXSID8034401") varmat <- tcplVarMat(aeid = aeids, dsstox_substance_id = dtxsid) +varmat <- tcplVarMat(aeid = aeids, std.vars = c("ac50", "zscore")) varmat <- tcplVarMat(aeid = aeids, add.vars = c("m4id", "resp_max", "max_med")) ## To save output to file