Skip to content

Commit

Permalink
Merge dbd1097 into a0014ff
Browse files Browse the repository at this point in the history
  • Loading branch information
ldecicco-USGS committed Oct 24, 2019
2 parents a0014ff + dbd1097 commit a5b58e9
Show file tree
Hide file tree
Showing 33 changed files with 344 additions and 329 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ pkgdown/favicon/*
vignettes/bibliography.Rmd
vignettes/toxeval.bib
vignettes/toxeval_orig.bib
updateV3.R
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: toxEval
Type: Package
Title: Exploring Biological Relevance of Environmental Chemistry Observations
Version: 1.1.0.9000
Version: 2.0.0.0000
Authors@R: c(person("Laura", "DeCicco",
role = c("aut","cre"),
email = "ldecicco@usgs.gov",
Expand Down Expand Up @@ -33,7 +33,7 @@ Copyright: This software is in the public domain because it contains materials
official USGS copyright policy at
https://www.usgs.gov/visual-id/credit_usgs.html#copyright
Depends:
R (>= 3.0)
R (>= 3.5.0)
Imports:
dplyr,
tidyr,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export(rank_sites_DT)
export(remove_flags)
export(tox_boxplot_data)
export(tox_chemicals)
import(dplyr)
import(ggplot2)
import(shinydashboard)
importFrom(grDevices,colorRampPalette)
Expand Down
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
toxEval 2.0.0
===========
* Switched to version 3 of the ToxCast database

toxEval 1.0.0
===========
* Initial release includes functions on incorporating
Expand Down
6 changes: 3 additions & 3 deletions R/create_toxEval.R
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ summary.toxEval <- function(object, ...){

if(is.null(object[["benchmarks"]])){
ACC <- ToxCast_ACC %>%
dplyr::filter(CAS %in% unique(object$chem_info$CAS))
filter(CAS %in% unique(object$chem_info$CAS))
bench_word <- "ToxCast"
} else {
ACC <- object[["benchmarks"]]
bench_word <- "benchmark"
}

CAS_w_data <- ACC %>% dplyr::select(CAS) %>%
dplyr::distinct() %>% dplyr::pull(CAS)
CAS_w_data <- ACC %>% select(CAS) %>%
distinct() %>% pull(CAS)

message(length(CAS_w_data)," chemicals have ", bench_word, " information")
message("Chemicals returned from this function do NOT have ", bench_word, " information:")
Expand Down
58 changes: 28 additions & 30 deletions R/endpoint_hits.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#' values in the table are the number of sites where the EAR exceeded the
#' user-defined EAR hit_threshold in that endpoint/category combination. If the
#' category "Chemical" is chosen, an "info" link is provided to the
#' chemical/endpoint information available in the "ToxCast Dashboard"
#' \url{https://actor.epa.gov/dashboard/}.
#' chemical information available in the "Comptox Dashboard"
#' \url{https://comptox.epa.gov/dashboard/}.
#'
#' The tables show slightly different results when choosing to explore data
#' from a single site rather than all sites. The value displayed in this
Expand Down Expand Up @@ -69,8 +69,8 @@ endpoint_hits_DT <- function(chemical_summary,
if(category == "Chemical"){
orig_names <- names(fullData)

casKey <- dplyr::select(chemical_summary, chnm, CAS) %>%
dplyr::distinct()
casKey <- select(chemical_summary, chnm, CAS) %>%
distinct()

numeric_hits <- fullData
hits <- sapply(fullData, function(x) as.character(x))
Expand All @@ -84,8 +84,7 @@ endpoint_hits_DT <- function(chemical_summary,
} else{
hit_char <- as.character(fullData[k,z])
}
hits[k,z] <- paste(hit_char,createLink(cas = casKey$CAS[casKey$chnm == names(fullData)[z]],
endpoint = fullData[k,1]))
hits[k,z] <- paste(hit_char,createLink(cas = casKey$CAS[casKey$chnm == names(fullData)[z]]))
}
}
}
Expand Down Expand Up @@ -149,47 +148,47 @@ endpoint_hits <- function(chemical_summary,
fullData <- fullData_init

if(category == "Chemical"){
chemical_summary <- dplyr::mutate(chemical_summary, category = chnm)
chemical_summary <- mutate(chemical_summary, category = chnm)
} else if (category == "Chemical Class"){
chemical_summary <- dplyr::mutate(chemical_summary, category = Class)
chemical_summary <- mutate(chemical_summary, category = Class)
} else {
chemical_summary <- dplyr::mutate(chemical_summary, category = Bio_category)
chemical_summary <- mutate(chemical_summary, category = Bio_category)
}

if(length(unique(chemical_summary$site)) > 1){

if(!sum_logic){
fullData <- chemical_summary %>%
dplyr::group_by(site, category, endPoint, date) %>%
dplyr::summarize(sumEAR = max(EAR)) %>%
dplyr::group_by(site, category, endPoint) %>%
dplyr::summarize(meanEAR = ifelse(mean_logic, mean(sumEAR),max(sumEAR))) %>%
dplyr::group_by(category, endPoint) %>%
dplyr::summarize(nSites = sum(meanEAR > hit_threshold)) %>%
group_by(site, category, endPoint, date) %>%
summarize(sumEAR = max(EAR)) %>%
group_by(site, category, endPoint) %>%
summarize(meanEAR = ifelse(mean_logic, mean(sumEAR),max(sumEAR))) %>%
group_by(category, endPoint) %>%
summarize(nSites = sum(meanEAR > hit_threshold)) %>%
tidyr::spread(category, nSites)
} else {
fullData <- chemical_summary %>%
dplyr::group_by(site, category, endPoint, date) %>%
dplyr::summarize(sumEAR = sum(EAR)) %>%
dplyr::group_by(site, category, endPoint) %>%
dplyr::summarize(meanEAR = ifelse(mean_logic, mean(sumEAR),max(sumEAR))) %>%
dplyr::group_by(category, endPoint) %>%
dplyr::summarize(nSites = sum(meanEAR > hit_threshold)) %>%
group_by(site, category, endPoint, date) %>%
summarize(sumEAR = sum(EAR)) %>%
group_by(site, category, endPoint) %>%
summarize(meanEAR = ifelse(mean_logic, mean(sumEAR),max(sumEAR))) %>%
group_by(category, endPoint) %>%
summarize(nSites = sum(meanEAR > hit_threshold)) %>%
tidyr::spread(category, nSites)
}

} else {
if(!sum_logic){
fullData <- chemical_summary %>%
dplyr::group_by(category, endPoint) %>%
dplyr::summarise(nSites = sum(EAR > hit_threshold)) %>%
group_by(category, endPoint) %>%
summarise(nSites = sum(EAR > hit_threshold)) %>%
tidyr::spread(category, nSites)
} else {
fullData <- chemical_summary %>%
dplyr::group_by(category, endPoint, date) %>%
dplyr::summarize(sumEAR = sum(EAR)) %>%
dplyr::group_by(category, endPoint) %>%
dplyr::summarise(nSites = sum(sumEAR > hit_threshold)) %>%
group_by(category, endPoint, date) %>%
summarize(sumEAR = sum(EAR)) %>%
group_by(category, endPoint) %>%
summarise(nSites = sum(sumEAR > hit_threshold)) %>%
tidyr::spread(category, nSites)
}
}
Expand Down Expand Up @@ -217,10 +216,9 @@ endpoint_hits <- function(chemical_summary,
#'
#' Create links
#' @param cas character
#' @param endpoint character
#' @param hits character
#' @export
#' @keywords internal
createLink <- function(cas, endpoint) {
paste0('<a href="http://actor.epa.gov/dashboard/#selected/',cas,"+",endpoint,'" target="_blank">&#9432;</a>')
createLink <- function(cas) {
paste0('<a href="https://comptox.epa.gov/dashboard/dsstoxdb/results?search=',cas,'#invitrodb-bioassays-toxcast-tox21" target="_blank">&#9432;</a>')
}
2 changes: 1 addition & 1 deletion R/filter_endPoint_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ filter_groups <- function(ep,
assay_source_name <- assay_component_endpoint_name <- ".dplyr"

ep <- ep[,c("assay_component_endpoint_name",groupCol,"assay_source_name")] %>%
dplyr::rename(endPoint = assay_component_endpoint_name,
rename(endPoint = assay_component_endpoint_name,
assaysFull = assay_source_name)
names(ep)[names(ep) == groupCol] <- "groupCol"

Expand Down
34 changes: 18 additions & 16 deletions R/get_ACC.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
#' (ACC) values for specified chemicals.
#'
#' The data used in toxEval were combined from files in the
#' "INVITRODB_V2_LEVEL5" directory that were included in the October 2015
#' "INVITRODB_V3_LEVEL5" directory that were included in the October 2018
#' release of the ToxCast database. The function \code{get_ACC} will
#' convert the ACC values in the ToxCast database from units of (log \eqn{\mu}M)
#' to units of \eqn{\mu}g/L, and reformat the data as input to toxEval.
#'
#' @param CAS Vector of CAS.
#' @param CAS Vector of CAS.
#' @import dplyr
#'
#' @return data frame with columns CAS, chnm, flags, endPoint, ACC, MlWt, and ACC_value
#' @export
#' @examples
Expand All @@ -21,22 +23,22 @@ get_ACC <- function(CAS){
Structure_MolWt <- Substance_CASRN <- casn <- Substance_Name <- ".dplyr"
chnm <- flags <- MlWt <- ACC_value <- casrn <- endPoint <- ".dplyr"

chem_list <- dplyr::select(tox_chemicals,
chem_list <- select(tox_chemicals,
casrn = Substance_CASRN,
MlWt = Structure_MolWt) %>%
dplyr::filter(casrn %in% CAS)
MlWt = Structure_MolWt)
chem_list <- filter(chem_list, casrn %in% CAS)

ACC <- ToxCast_ACC
ACC <- filter(ACC, CAS %in% CAS)
ACC <- right_join(ACC, chem_list,
by= c("CAS"="casrn"))

ACC <- ToxCast_ACC %>%
dplyr::filter(CAS %in% CAS) %>%
dplyr::right_join(chem_list,
by= c("CAS"="casrn")) %>%
data.frame() %>%
dplyr::mutate(ACC_value = 10^ACC,
ACC_value = ACC_value * MlWt) %>%
dplyr::filter(!is.na(ACC_value)) %>%
dplyr::left_join(dplyr::select(tox_chemicals,
CAS = Substance_CASRN,
chnm = Substance_Name), by="CAS")
ACC <- mutate(ACC, ACC_value = 10^ACC,
ACC_value = ACC_value * MlWt)
ACC <- filter(ACC, !is.na(ACC_value))
ACC <- left_join(ACC, select(tox_chemicals,
CAS = Substance_CASRN,
chnm = Substance_Name), by="CAS")

if(any(is.na(ACC$MlWt))){
warning("Some chemicals are missing molecular weights")
Expand Down

0 comments on commit a5b58e9

Please sign in to comment.