From 0568d919c0ef46d9e4a72c0342cb8bc3b2b49fdc Mon Sep 17 00:00:00 2001 From: Laura DeCicco Date: Fri, 5 Jan 2018 16:41:41 -0600 Subject: [PATCH 1/2] Export benchmarks --- R/get_chemical_summary.R | 26 +++++++++------------ inst/shiny/benchmarks.R | 45 +++++++++++++++++++++++++++++++++++++ man/get_chemical_summary.Rd | 24 +++++++++----------- 3 files changed, 66 insertions(+), 29 deletions(-) create mode 100644 inst/shiny/benchmarks.R diff --git a/R/get_chemical_summary.R b/R/get_chemical_summary.R index 41b78f2a..1906daf9 100644 --- a/R/get_chemical_summary.R +++ b/R/get_chemical_summary.R @@ -1,14 +1,19 @@ #' get_chemical_summary #' #' Get ACC values for vector of CAS's -#' @param ACClong data frame with at least columns: CAS, chnm, endPoint, ACC_value -#' @param filtered_ep data frame with colums: endPoints, groupCol #' @param tox_list list with data frames for chem_data, chem_info, chem_site, #' and optionally exclusions and benchmarks. Created with \code{\link{create_toxEval}} -#' @param chem.data data frame with (at least) columns: CAS, SiteID, Value -#' @param chem.site data frame with (at least) columns: SiteID, Short Name -#' @param chem.info data frame with (at least) columns: CAS, class -#' @param exclusion OPTIONAL data frame with (at least) columns: CAS and endPoint +#' @param ACClong data frame with at least columns: CAS, chnm, endPoint, ACC_value +#' @param filtered_ep data frame with colums: endPoints, groupCol. Default is \code{"All"}, where no +#' filtering occurs. +#' @param chem.data OPTIONAL data frame with (at least) columns: CAS, SiteID, Value. Default is \code{NULL}. +#' Will over-ride what is in tox_list. +#' @param chem.site OPTIONAL data frame with (at least) columns: SiteID, Short Name. Default is \code{NULL}. +#' Will over-ride what is in tox_list. +#' @param chem.info OPTIONAL data frame with (at least) columns: CAS, class. Default is \code{NULL}. +#' Will over-ride what is in tox_list. +#' @param exclusion OPTIONAL data frame with (at least) columns: CAS and endPoint. Default is \code{NULL}. +#' Will over-ride what is in tox_list. #' @export #' @importFrom tidyr gather #' @importFrom dplyr full_join filter mutate select left_join right_join anti_join @@ -27,15 +32,6 @@ #' #' chemicalSummary <- get_chemical_summary(tox_list, ACClong, filtered_ep) #' -#' library(readxl) -#' chem_data <- read_excel(full_path, sheet = "Data") -#' chem_info <- read_excel(full_path, sheet = "Chemicals") -#' chem_site <- read_excel(full_path, sheet = "Sites") -#' -#' chemicalSummary1 <- get_chemical_summary(tox_list = NULL, ACClong, filtered_ep, -#' chem.data = chem_data, -#' chem.site = chem_site, -#' chem.info = chem_info) get_chemical_summary <- function(tox_list, ACClong = NULL, filtered_ep = "All", chem.data=NULL, chem.site=NULL, chem.info=NULL, exclusion=NULL){ diff --git a/inst/shiny/benchmarks.R b/inst/shiny/benchmarks.R new file mode 100644 index 00000000..32fbe03b --- /dev/null +++ b/inst/shiny/benchmarks.R @@ -0,0 +1,45 @@ +output$downloadBenchmarks <- downloadHandler( + + filename = "Benchmarks.csv", + + content = function(filename) { + write.csv(get_benchmarks(), filename, row.names = FALSE) + } +) + +get_benchmarks <- reactive({ + + groupCol <- epDF[["groupColName"]] + assays <- epDF[["assays"]] + flags <- epDF[["flags"]] + sites <- epDF[["sites"]] + groups <- epDF[["group"]] + removeFlags <- all_flags[!(all_flags %in% flags)] + rawData <- rawData() + + if(!is.null(rawData)){ + if(all(is.null(rawData$benchmarks))){ + + ACClong <- get_ACC(rawData$chem_info$CAS) + ACClong <- remove_flags(ACClong, flagsShort = removeFlags) + + remove_groups <- unique(cleaned_ep[[groupCol]])[which(!unique(cleaned_ep[[groupCol]]) %in% groups)] + remove_groups <- remove_groups[!is.na(remove_groups)] + + filtered_ep <- filter_groups(cleaned_ep, + groupCol = groupCol, assays = assays, + remove_groups = remove_groups) + + bench <- ACClong %>% + filter(endPoint %in% filtered_ep$endPoint) %>% + rename(Value = ACC_value, + Chemical = chnm) %>% + left_join(filtered_ep, by = "endPoint") + + } else { + bench <- rawData$benchmarks + } + } + + return(bench) +}) \ No newline at end of file diff --git a/man/get_chemical_summary.Rd b/man/get_chemical_summary.Rd index d460f34d..3e330f7e 100644 --- a/man/get_chemical_summary.Rd +++ b/man/get_chemical_summary.Rd @@ -14,15 +14,20 @@ and optionally exclusions and benchmarks. Created with \code{\link{create_toxEva \item{ACClong}{data frame with at least columns: CAS, chnm, endPoint, ACC_value} -\item{filtered_ep}{data frame with colums: endPoints, groupCol} +\item{filtered_ep}{data frame with colums: endPoints, groupCol. Default is \code{"All"}, where no +filtering occurs.} -\item{chem.data}{data frame with (at least) columns: CAS, SiteID, Value} +\item{chem.data}{OPTIONAL data frame with (at least) columns: CAS, SiteID, Value. Default is \code{NULL}. +Will over-ride what is in tox_list.} -\item{chem.site}{data frame with (at least) columns: SiteID, Short Name} +\item{chem.site}{OPTIONAL data frame with (at least) columns: SiteID, Short Name. Default is \code{NULL}. +Will over-ride what is in tox_list.} -\item{chem.info}{data frame with (at least) columns: CAS, class} +\item{chem.info}{OPTIONAL data frame with (at least) columns: CAS, class. Default is \code{NULL}. +Will over-ride what is in tox_list.} -\item{exclusion}{OPTIONAL data frame with (at least) columns: CAS and endPoint} +\item{exclusion}{OPTIONAL data frame with (at least) columns: CAS and endPoint. Default is \code{NULL}. +Will over-ride what is in tox_list.} } \description{ Get ACC values for vector of CAS's @@ -42,13 +47,4 @@ filtered_ep <- filter_groups(cleaned_ep) chemicalSummary <- get_chemical_summary(tox_list, ACClong, filtered_ep) -library(readxl) -chem_data <- read_excel(full_path, sheet = "Data") -chem_info <- read_excel(full_path, sheet = "Chemicals") -chem_site <- read_excel(full_path, sheet = "Sites") - -chemicalSummary1 <- get_chemical_summary(tox_list = NULL, ACClong, filtered_ep, - chem.data = chem_data, - chem.site = chem_site, - chem.info = chem_info) } From ba55b43334a07167e888bedcb5fb7f27c593fa1e Mon Sep 17 00:00:00 2001 From: Laura DeCicco Date: Fri, 5 Jan 2018 16:55:50 -0600 Subject: [PATCH 2/2] Better example --- R/get_chemical_summary.R | 3 +++ man/exclude_points.Rd | 3 +++ 2 files changed, 6 insertions(+) diff --git a/R/get_chemical_summary.R b/R/get_chemical_summary.R index 1906daf9..4af70378 100644 --- a/R/get_chemical_summary.R +++ b/R/get_chemical_summary.R @@ -236,6 +236,9 @@ remove_flags <- function(ACClong, flagsShort = c("Borderline", #' # The example workflow takes a bit of time to load and compute, #' # so an example chemicalSummary is included pre-calculated in the package. #' chemicalSummary <- ex_chemSum #loading example data +#' exclusion <- data.frame(CAS = c("134-62-3","486-56-6"), +#' endPoint = c("", "TOX21_p53_BLA_p3_viability"), +#' stringsAsFactors = FALSE) #' chemicalSummary <- exclude_points(chemicalSummary, exclusion) exclude_points <- function(chemicalSummary, exclusion){ diff --git a/man/exclude_points.Rd b/man/exclude_points.Rd index 9d0415d3..546514de 100644 --- a/man/exclude_points.Rd +++ b/man/exclude_points.Rd @@ -33,5 +33,8 @@ chemicalSummary <- get_chemical_summary(tox_list, ACClong, filtered_ep) # The example workflow takes a bit of time to load and compute, # so an example chemicalSummary is included pre-calculated in the package. chemicalSummary <- ex_chemSum #loading example data +exclusion <- data.frame(CAS = c("134-62-3","486-56-6"), + endPoint = c("", "TOX21_p53_BLA_p3_viability"), + stringsAsFactors = FALSE) chemicalSummary <- exclude_points(chemicalSummary, exclusion) }