diff --git a/.github/workflows/test-on-PR.yaml b/.github/workflows/test-on-PR.yaml index e9549a97..6a991b0d 100644 --- a/.github/workflows/test-on-PR.yaml +++ b/.github/workflows/test-on-PR.yaml @@ -2,7 +2,7 @@ # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: pull_request: - branches: [main] + branches: [main, dev] name: test-coverage diff --git a/R/data.R b/R/data.R index 7e34358e..b5da029c 100644 --- a/R/data.R +++ b/R/data.R @@ -490,4 +490,258 @@ #' \item{scagg}{Column names returned requesting sc lvl "agg" data} #' } #' @source ToxCast database -"load_data_columns" \ No newline at end of file +"load_data_columns" + + +#' List of lists containing queries sent to tcplQuery associated with each test +#' case. Each list also contains the associated ids with each case. Only meant +#' to be used with automated testing with mocking for mc data. +#' @format A list with 30 items: +#' \describe{ +#' \item{tcplConfQuery}{Data table with 1 row and 2 columns used for each test +#' case for establishing connection using tcplConf. This data table mocks the +#' response one would get from connecting with invitrodb.} +#' \item{mc0_by_m0id}{List containing the queries used for loading mc0 data by +#' m0id via tcplLoadData. Each query has an associated data table response for +#' mocking an actual connection. Contains one 'm0id' labeled item storing the +#' id used to load the data, for use in tests.} +#' \item{mc0_by_acid}{List containing the queries used for loading mc0 data by +#' acid via tcplLoadData. Each query has an associated data table response for +#' mocking an actual connection. Contains one 'acid' labeled item storing the +#' id used to load the data, for use in tests.} +#' \item{mc1_by_m1id}{List containing the queries used for loading mc1 data by +#' m1id via tcplLoadData. Each query has an associated data table response for +#' mocking an actual connection. Contains one 'm1id' labeled item storing the +#' id used to load the data, for use in tests.} +#' \item{mc1_by_acid}{List containing the queries used for loading mc1 data by +#' acid via tcplLoadData. Each query has an associated data table response for +#' mocking an actual connection. Contains one 'acid' labeled item storing the +#' id used to load the data, for use in tests.} +#' \item{mc2_by_m2id}{List containing the queries used for loading mc2 data by +#' m2id via tcplLoadData. Each query has an associated data table response for +#' mocking an actual connection. Contains one 'm2id' labeled item storing the +#' id used to load the data, for use in tests.} +#' \item{mc2_by_acid}{List containing the queries used for loading mc2 data by +#' acid via tcplLoadData. Each query has an associated data table response for +#' mocking an actual connection. Contains one 'acid' labeled item storing the +#' id used to load the data, for use in tests.} +#' \item{mc3_by_m3id}{List containing the queries used for loading mc3 data by +#' m3id via tcplLoadData. Each query has an associated data table response for +#' mocking an actual connection. Contains one 'm3id' labeled item storing the +#' id used to load the data, for use in tests.} +#' \item{mc3_by_aeid}{List containing the queries used for loading mc3 data by +#' aeid via tcplLoadData. Each query has an associated data table response for +#' mocking an actual connection. Contains one 'aeid' labeled item storing the +#' id used to load the data, for use in tests.} +#' \item{mc4_by_m4id}{List containing the queries used for loading mc4 data by +#' m4id via tcplLoadData. Each query has an associated data table response for +#' mocking an actual connection. Contains one 'm4id' labeled item storing the +#' id used to load the data, for use in tests.} +#' \item{mc4_by_aeid}{List containing the queries used for loading mc4 data by +#' aeid via tcplLoadData. Each query has an associated data table response for +#' mocking an actual connection. Contains one 'aeid' labeled item storing the +#' id used to load the data, for use in tests.} +#' \item{mc5_by_m5id}{List containing the queries used for loading mc5 data by +#' m5id via tcplLoadData. Each query has an associated data table response for +#' mocking an actual connection. Contains one 'm5id' labeled item storing the +#' id used to load the data, for use in tests.} +#' \item{mc5_by_aeid}{List containing the queries used for loading mc5 data by +#' aeid via tcplLoadData. Each query has an associated data table response for +#' mocking an actual connection. Contains one 'aeid' labeled item storing the +#' id used to load the data, for use in tests.} +#' \item{mc6_by_m6id}{List containing the queries used for loading mc6 data by +#' m6id via tcplLoadData. Each query has an associated data table response for +#' mocking an actual connection. Contains one 'm6id' labeled item storing the +#' id used to load the data, for use in tests.} +#' \item{mc6_by_aeid}{List containing the queries used for loading mc6 data by +#' aeid via tcplLoadData. Each query has an associated data table response for +#' mocking an actual connection. Contains one 'aeid' labeled item storing the +#' id used to load the data, for use in tests.} +#' \item{mc7_by_m7id}{List containing the queries used for loading mc7 data by +#' m7id via tcplLoadData. Each query has an associated data table response for +#' mocking an actual connection. Contains one 'm7id' labeled item storing the +#' id used to load the data, for use in tests.} +#' \item{mc7_by_aeid}{List containing the queries used for loading mc7 data by +#' aeid via tcplLoadData. Each query has an associated data table response for +#' mocking an actual connection. Contains one 'aeid' labeled item storing the +#' id used to load the data, for use in tests.} +#' \item{mcagg_by_aeid}{List containing the queries used for loading mc 'agg' +#' data by aeid via tcplLoadData. Each query has an associated data table +#' response for mocking an actual connection. Contains one 'aeid' labeled item +#' storing the id used to load the data, for use in tests.} +#' \item{plot_single_m4id}{List containing the queries used for loading and +#' plotting mc data by m4id via tcplPlot. Each query has an associated data +#' table response for mocking an actual connection. Contains one 'm4id' +#' labeled item storing the id used to load the data, for use in tests.} +#' \item{plot_multiple_m4id}{List containing the queries used for loading and +#' plotting mc data by multiple m4ids via tcplPlot. Each query has an +#' associated data table response for mocking an actual connection. Contains +#' one 'm4id' labeled item storing the ids used to load the data, for use in +#' tests.} +#' \item{plot_single_aeid}{List containing the queries used for loading and +#' plotting mc data by aeid via tcplPlot. Each query has an associated data +#' table response for mocking an actual connection. Contains one 'aeid' +#' labeled item storing the id used to load the data, for use in tests.} +#' \item{plot_multiple_aeid}{List containing the queries used for loading and +#' plotting mc data by multiple aeids via tcplPlot. Each query has an +#' associated data table response for mocking an actual connection. Contains +#' one 'aeid' labeled item storing the ids used to load the data, for use in +#' tests.} +#' \item{plot_single_spid}{List containing the queries used for loading and +#' plotting mc data by spid/aeid via tcplPlot. Each query has an associated +#' data table response for mocking an actual connection. Contains 'spid' and +#' 'aeid' labeled items storing the ids used to load the data, for use in +#' tests.} +#' \item{plot_multiple_spid}{List containing the queries used for loading and +#' plotting mc data by multiple spids/aeid via tcplPlot. Each query has an +#' associated data table response for mocking an actual connection. Contains +#' 'spid' and 'aeid' labeled items storing the ids used to load the data, for +#' use in tests.} +#' \item{plot_single_m4id_compare}{List containing the queries used for +#' loading and plotting compared mc data by m4id via tcplPlot. Each query has +#' an associated data table response for mocking an actual connection. +#' Contains 'm4id' and 'compare.m4id' labeled items storing the ids used to +#' load the data, for use in tests.} +#' \item{plot_multiple_m4id_compare}{List containing the queries used for loading and +#' plotting compared mc data by multiple m4ids via tcplPlot. Each query has an +#' associated data table response for mocking an actual connection. Contains +#' 'm4id' and 'compare.m4id' labeled items storing the ids used to load the +#' data, for use in tests.} +#' \item{plot_single_aeid_compare}{List containing the queries used for +#' loading and plotting compared mc data by aeid via tcplPlot. Each query has +#' an associated data table response for mocking an actual connection. +#' Contains 'aeid' and 'compare.aeid' labeled items storing the ids used to +#' load the data, for use in tests.} +#' \item{plot_multiple_aeid_compare}{List containing the queries used for +#' loading and plotting compared mc data by multiple aeids via tcplPlot. Each +#' query has an associated data table response for mocking an actual +#' connection. Contains 'aeid' and 'compare.aeid' labeled items storing the +#' ids used to load the data, for use in tests.} +#' \item{plot_single_spid_compare}{List containing the queries used for +#' loading and plotting compared mc data by spid/aeid via tcplPlot. Each query +#' has an associated data table response for mocking an actual connection. +#' Contains 'spid', 'compare.spid', 'aeid', and 'compare.aeid' labeled items +#' storing the ids used to load the data, for use in tests.} +#' \item{plot_multiple_spid_compare}{List containing the queries used for +#' loading and plotting compared mc data by multiple spids/aeid via tcplPlot. +#' Each query has an associated data table response for mocking an actual +#' connection. Contains 'spid', 'compare.spid', 'aeid', and 'compare.aeid' +#' labeled items storing the ids used to load the data, for use in tests.} +#' } +#' @source ToxCast database +"mc_test" + + +#' List of lists containing queries sent to tcplQuery associated with each test +#' case. Each list also contains the associated ids with each case. Only meant +#' to be used with automated testing with mocking for sc data. +#' @format A list with 20 items: +#' \describe{ +#' \item{tcplConfQuery}{Data table with 1 row and 2 columns used for each test +#' case for establishing connection using tcplConf. This data table mocks the +#' response one would get from connecting with invitrodb.} +#' \item{sc0_by_s0id}{List containing the queries used for loading sc0 data by +#' s0id via tcplLoadData. Each query has an associated data table response for +#' mocking an actual connection. Contains one 's0id' labeled item storing the +#' id used to load the data, for use in tests.} +#' \item{sc0_by_acid}{List containing the queries used for loading sc0 data by +#' acid via tcplLoadData. Each query has an associated data table response for +#' mocking an actual connection. Contains one 'acid' labeled item storing the +#' id used to load the data, for use in tests.} +#' \item{sc1_by_s1id}{List containing the queries used for loading sc1 data by +#' s1id via tcplLoadData. Each query has an associated data table response for +#' mocking an actual connection. Contains one 's1id' labeled item storing the +#' id used to load the data, for use in tests.} +#' \item{sc1_by_acid}{List containing the queries used for loading sc1 data by +#' acid via tcplLoadData. Each query has an associated data table response for +#' mocking an actual connection. Contains one 'acid' labeled item storing the +#' id used to load the data, for use in tests.} +#' \item{sc2_by_s2id}{List containing the queries used for loading sc2 data by +#' s2id via tcplLoadData. Each query has an associated data table response for +#' mocking an actual connection. Contains one 's2id' labeled item storing the +#' id used to load the data, for use in tests.} +#' \item{sc2_by_aeid}{List containing the queries used for loading sc2 data by +#' aeid via tcplLoadData. Each query has an associated data table response for +#' mocking an actual connection. Contains one 'aeid' labeled item storing the +#' id used to load the data, for use in tests.} +#' \item{scagg_by_aeid}{List containing the queries used for loading sc 'agg' +#' data by aeid via tcplLoadData. Each query has an associated data table +#' response for mocking an actual connection. Contains one 'aeid' labeled item +#' storing the id used to load the data, for use in tests.} +#' \item{plot_single_s2id}{List containing the queries used for loading and +#' plotting sc data by s2id via tcplPlot. Each query has an associated data +#' table response for mocking an actual connection. Contains one 's2id' +#' labeled item storing the id used to load the data, for use in tests.} +#' \item{plot_multiple_s2id}{List containing the queries used for loading and +#' plotting sc data by multiple s2ids via tcplPlot. Each query has an +#' associated data table response for mocking an actual connection. Contains +#' one 's2id' labeled item storing the ids used to load the data, for use in +#' tests.} +#' \item{plot_single_aeid}{List containing the queries used for loading and +#' plotting sc data by aeid via tcplPlot. Each query has an associated data +#' table response for mocking an actual connection. Contains one 'aeid' +#' labeled item storing the id used to load the data, for use in tests.} +#' \item{plot_multiple_aeid}{List containing the queries used for loading and +#' plotting sc data by multiple aeids via tcplPlot. Each query has an +#' associated data table response for mocking an actual connection. Contains +#' one 'aeid' labeled item storing the ids used to load the data, for use in +#' tests.} +#' \item{plot_single_spid}{List containing the queries used for loading and +#' plotting sc data by spid/aeid via tcplPlot. Each query has an associated +#' data table response for mocking an actual connection. Contains 'spid' and +#' 'aeid' labeled items storing the ids used to load the data, for use in +#' tests.} +#' \item{plot_multiple_spid}{List containing the queries used for loading and +#' plotting sc data by multiple spids/aeid via tcplPlot. Each query has an +#' associated data table response for mocking an actual connection. Contains +#' 'spid' and 'aeid' labeled items storing the ids used to load the data, for +#' use in tests.} +#' \item{plot_single_s2id_compare}{List containing the queries used for +#' loading and plotting compared sc data by s2id via tcplPlot. Each query has +#' an associated data table response for mocking an actual connection. +#' Contains 's2id' and 'compare.s2id' labeled items storing the ids used to +#' load the data, for use in tests.} +#' \item{plot_multiple_s2id_compare}{List containing the queries used for loading and +#' plotting compared sc data by multiple s2ids via tcplPlot. Each query has an +#' associated data table response for mocking an actual connection. Contains +#' 's2id' and 'compare.s2id' labeled items storing the ids used to load the +#' data, for use in tests.} +#' \item{plot_single_aeid_compare}{List containing the queries used for +#' loading and plotting compared sc data by aeid via tcplPlot. Each query has +#' an associated data table response for mocking an actual connection. +#' Contains 'aeid' and 'compare.aeid' labeled items storing the ids used to +#' load the data, for use in tests.} +#' \item{plot_multiple_aeid_compare}{List containing the queries used for +#' loading and plotting compared sc data by multiple aeids via tcplPlot. Each +#' query has an associated data table response for mocking an actual +#' connection. Contains 'aeid' and 'compare.aeid' labeled items storing the +#' ids used to load the data, for use in tests.} +#' \item{plot_single_spid_compare}{List containing the queries used for +#' loading and plotting compared sc data by spid/aeid via tcplPlot. Each query +#' has an associated data table response for mocking an actual connection. +#' Contains 'spid', 'compare.spid', 'aeid', and 'compare.aeid' labeled items +#' storing the ids used to load the data, for use in tests.} +#' \item{plot_multiple_spid_compare}{List containing the queries used for +#' loading and plotting compared sc data by multiple spids/aeid via tcplPlot. +#' Each query has an associated data table response for mocking an actual +#' connection. Contains 'spid', 'compare.spid', 'aeid', and 'compare.aeid' +#' labeled items storing the ids used to load the data, for use in tests.} +#' } +#' @source ToxCast database +"sc_test" + + +#' List containing ids used for different automated tests of tcpl integration +#' with the CTX APIs, randomly selected from what is available via API. +#' @format A list with 7 items: +#' \describe{ +#' \item{aeid}{Randomly selected assay component endpoint id} +#' \item{acid}{Assay component id associated with the above aeid} +#' \item{aid}{Assay id associated with the above aeid} +#' \item{asid}{Assay source id associated with the above aeid} +#' \item{dtxsid}{dsstox substance id of one sample from the above aeid} +#' \item{spid}{Sample id of one (the same) sample from the above aeid} +#' \item{m4id}{Level 4 id of one (the same) sample from the above aeid} +#' } +#' @source CTX Bioactivity API +"test_api" \ No newline at end of file diff --git a/R/tcplConf.R b/R/tcplConf.R index 8fc42930..8c6071c4 100644 --- a/R/tcplConf.R +++ b/R/tcplConf.R @@ -74,9 +74,9 @@ tcplConf <- function (drvr = NULL, user = NULL, pass = NULL, host = NULL, if (drvr == "API") { options("TCPL_DRVR" = "API") - if (is.null(pass)) stop("'API' driver requires an API-key, supply it to - the 'pass' parameter. To request a key, send an - email to ccte_api@epa.gov.") + if (is.null(pass)) stop("'API' driver requires an API-key, supply it to ", + "the 'pass' parameter. To request a key, send an ", + "email to ccte_api@epa.gov.") if (is.null(host)) options("TCPL_HOST" = "https://api-ccte.epa.gov/bioactivity") register_ctx_api_key(key = pass) } diff --git a/R/tcplLoadChem.R b/R/tcplLoadChem.R index 80e1f525..7b50a7ab 100644 --- a/R/tcplLoadChem.R +++ b/R/tcplLoadChem.R @@ -59,6 +59,9 @@ tcplLoadChem <- function(field = NULL, val = NULL, exact = TRUE, if (tolower(field) != "spid") stop("When drvr option is set to 'API', only 'spid' is a valid 'field' value.") if (!exact) exact <- TRUE dat <- tcplQueryAPI(resource = "data", fld = "spid", val = val, return_flds = c("spid", "chid", "casn", "chnm", "dsstox_substance_id")) + if (!length(colnames(dat))) { + return(dat) + } setorder(dat, "spid") } else { tbl <- c("chemical", "sample") diff --git a/R/tcplLoadConcUnit.R b/R/tcplLoadConcUnit.R index 31dd8c23..b8d7f155 100644 --- a/R/tcplLoadConcUnit.R +++ b/R/tcplLoadConcUnit.R @@ -21,8 +21,10 @@ tcplLoadConcUnit <- function(spid) { if (getOption("TCPL_DRVR") == "API") { dat <- tcplQueryAPI(resource = "data", fld = "spid", val = spid, return_flds = c("spid", "tested_conc_unit")) - setnames(dat, "tested_conc_unit", "conc_unit") - setorder(dat, "spid") + if (length(colnames(dat))) { + setnames(dat, "tested_conc_unit", "conc_unit") + setorder(dat, "spid") + } return(unique(dat, by = c("spid", "conc_unit"))) } diff --git a/R/tcplLoadData.R b/R/tcplLoadData.R index fdfb73b4..c510cb57 100644 --- a/R/tcplLoadData.R +++ b/R/tcplLoadData.R @@ -108,7 +108,7 @@ tcplLoadData <- function(lvl, fld = NULL, val = NULL, type = "mc", add.fld = TRU } else if (lvl == 1L) { sc1 <- sc_vignette[["sc1"]] - sc1 <- sc1[,c("s0id","s1id","spid","acid","aeid","apid","rowi","coli","wllt","logc","resp")] + sc1 <- sc1[,c("s0id","s1id","spid","acid","aeid","apid","rowi","coli","wllt","conc","resp")] return(sc1) } @@ -121,7 +121,7 @@ tcplLoadData <- function(lvl, fld = NULL, val = NULL, type = "mc", add.fld = TRU sc1 <- sc_vignette[["sc1"]] sc2 <- sc_vignette[["sc2"]] agg <- sc1[sc2, on = c("spid","aeid")] - agg <- agg[,c("aeid","s2id","s1id","s0id","logc","resp")] + agg <- agg[,c("aeid","s2id","s1id","s0id","conc","resp")] return(agg) } else stop("example tables for sc0, sc1, sc2, agg available.") @@ -146,14 +146,17 @@ tcplLoadData <- function(lvl, fld = NULL, val = NULL, type = "mc", add.fld = TRU } else if (lvl == 3L) { mc3 <- mc_vignette[["mc3"]] - mc3 <- mc3[,c("m0id","m1id","m2id","m3id","spid","aeid","logc","resp","cndx","wllt","apid","rowi","coli","repi")] + mc3 <- mc3[,c("m0id","m1id","m2id","m3id","spid","aeid","conc","resp","cndx","wllt","apid","rowi","coli","repi")] return(mc3) } else if (lvl == 4L) { mc4 <- mc_vignette[["mc4"]] if (!add.fld) { - mc4 <- mc4[,c("m4id","aeid","spid","bmad","resp_max","resp_min","max_mean","max_mean_conc","max_med","max_med_conc", - "logc_max","logc_min","nconc","npts","nrep","nmed_gtbl")] + mc4 <- mc4[,c("m4id", "aeid", "spid", "bmad", "resp_max", "resp_min", + "max_mean", "max_mean_conc", "min_mean", "min_mean_conc", + "max_med", "max_med_conc", "min_med", "min_med_conc", + "max_med_diff", "max_med_diff_conc", "conc_max", "conc_min", + "nconc", "npts", "nrep", "nmed_gtbl_pos", "nmed_gtbl_neg")] } else { mc4 <- mc4[,!c("chid","casn","chnm","dsstox_substance_id","code","aenm","resp_unit","conc_unit")] setcolorder(mc4, c("m4id", "aeid", "spid")) @@ -163,10 +166,15 @@ tcplLoadData <- function(lvl, fld = NULL, val = NULL, type = "mc", add.fld = TRU else if (lvl == 5L) { mc5 <- mc_vignette[["mc5"]] if (!add.fld){ - mc5 <- mc5[,c("m5id","m4id","aeid","spid","bmad","resp_max","resp_min","max_mean","max_mean_conc","max_med", - "max_med_conc","logc_max","logc_min","nconc","npts","nrep","nmed_gtbl","hitc","modl","fitc","coff")] + mc5 <- mc5[,c("m5id","m4id", "aeid", "spid", "bmad", "resp_max", "resp_min", + "max_mean", "max_mean_conc", "min_mean", "min_mean_conc", + "max_med", "max_med_conc", "min_med", "min_med_conc", + "max_med_diff", "max_med_diff_conc", "conc_max", "conc_min", + "nconc", "npts", "nrep", "nmed_gtbl_pos", "nmed_gtbl_neg", + "hitc", "modl", "fitc", "coff")] } else { - mc5 <- mc5[,!c("chid","casn","chnm","dsstox_substance_id","code","aenm","resp_unit","conc_unit","tp","ga","q","la","ac50_loss")] + mc5 <- mc5[,!c("chid","casn","chnm","dsstox_substance_id","code","aenm", + "resp_unit","conc_unit","tp","ga","q","la","ac50_loss")] setcolorder(mc5, c("m5id", "m4id","aeid", "spid")) } return(mc5) @@ -175,7 +183,8 @@ tcplLoadData <- function(lvl, fld = NULL, val = NULL, type = "mc", add.fld = TRU mc3 <- mc_vignette[["mc3"]] mc4 <- mc_vignette[["mc4"]] agg <- mc3[mc4, on = c("spid","aeid")] - agg <- agg[, c("aeid", "m4id", "m3id", "m2id", "m1id", "m0id", "spid", "logc", "resp")] + agg <- agg[, c("aeid", "m4id", "m3id", "m2id", "m1id", "m0id", "spid", + "conc", "resp")] return(agg) } @@ -204,15 +213,18 @@ tcplLoadData <- function(lvl, fld = NULL, val = NULL, type = "mc", add.fld = TRU # query the API dat <- tcplQueryAPI(fld = fld, val = val, return_flds = cols) - if (lvl == 3) { - dat$resp <- lapply(dat$resp, unlist) - dat$logc <- lapply(dat$logc, unlist) - dat <- unnest_longer(dat, c(conc, logc, resp)) %>% as.data.table() - } - - if (lvl == 6) { - dat$flag <- lapply(dat$flag, unlist) - dat <- unnest_longer(dat, flag) %>% filter(flag != "NULL") %>% as.data.table() + if (length(colnames(dat))) { + if (lvl == 3 | lvl == "agg") { + dat$resp <- lapply(dat$resp, unlist) + dat$logc <- lapply(dat$logc, unlist) + if (lvl == 3) dat <- unnest_longer(dat, c(conc, logc, resp)) %>% as.data.table() + else dat <- unnest_longer(dat, c(logc, resp)) %>% as.data.table() + } + + if (lvl == 6) { + dat$flag <- lapply(dat$flag, unlist) + dat <- unnest_longer(dat, flag) %>% filter(flag != "NULL") %>% as.data.table() + } } return(dat) diff --git a/R/tcplPlot.R b/R/tcplPlot.R index e29445ce..a7a44cdc 100644 --- a/R/tcplPlot.R +++ b/R/tcplPlot.R @@ -202,7 +202,7 @@ tcplPlotlyPlot <- function(dat, lvl = 5){ # extract range from level 3 data for creating plotting all the functions # increase resolution to get smoother curves resolution <- 100 - x_min_max <- range(l3_dat_both$conc) + x_min_max <- range(l3_dat_both$conc, na.rm=TRUE) #if the overall minimum conc is greater than 0 (test wells) if (x_min_max[1] > 0) { hline_range <- 10^(seq(from = log10(x_min_max[1]/100), to = log10(x_min_max[2]*100), length.out = resolution)) @@ -413,11 +413,13 @@ tcplPlotlyPlot <- function(dat, lvl = 5){ } # compare data - if (!is.null(compare.dat$coff) && compare.dat$max_med < 0) { - compare.dat$coff <- compare.dat$coff * -1 - } - if (!is.null(compare.dat$coff) && !is.null(compare.dat$hitc) && compare.dat$hitc < 0) { - compare.dat$coff <- compare.dat$coff * -1 + if (nrow(compare.dat) > 0) { + if (!is.null(compare.dat$coff) && compare.dat$max_med < 0) { + compare.dat$coff <- compare.dat$coff * -1 + } + if (!is.null(compare.dat$coff) && !is.null(compare.dat$hitc) && compare.dat$hitc < 0) { + compare.dat$coff <- compare.dat$coff * -1 + } } } diff --git a/R/tcplPlotUtils.R b/R/tcplPlotUtils.R index bcaa921b..467b1b09 100644 --- a/R/tcplPlotUtils.R +++ b/R/tcplPlotUtils.R @@ -38,7 +38,7 @@ tcplPlotSetYRange <- function(dat,yuniform,yrange,type){ } - tcplPlotValidate <- function(type = "mc",flags = NULL,output = "none",multi = FALSE,verbose = FALSE){ + tcplPlotValidate <- function(type = "mc",flags = NULL,output = "none",multi = NULL,verbose = FALSE){ # set lvl based on type lvl <- 5 @@ -46,6 +46,7 @@ tcplPlotSetYRange <- function(dat,yuniform,yrange,type){ lvl <- 2 if (flags == TRUE) { warning("'flags' was set to TRUE - no flags exist for plotting single concentration") + flags = FALSE } } diff --git a/data-raw/mc_test.R b/data-raw/mc_test.R new file mode 100644 index 00000000..cd209fad --- /dev/null +++ b/data-raw/mc_test.R @@ -0,0 +1,161 @@ +#==============================================================================# +# NOTE: This script is written such that it is run from 'top' to 'bottom' +# or programmatically via the Terminal. +# ('R CMD BATCH --vanilla '.) +# Please do not jump around when running this script. +#==============================================================================# +# NOTE: You MUST temporarily update tcplQuery() by adding a line at the top of the +# function: print(query). +# This is because the queries will be captured from output and saved as +# part of the mocking data. +#==============================================================================# +## r packages +devtools::load_all() + +library(here) +library(dplyr) +library(stringr) +#---------------------------# +## code to prepare `mc_test` dataset goes here +# source the user ID, password, host, and database information for connection +# - NOTE: To replicate one will need to save their own 'db_cred.R', including +# the 'userid', 'userpwd', 'host', and DB collection via 'ivtdb'. +source(file = here::here("data-raw/db_cred.R"),verbose = FALSE) +# connect to the DB +tcplConf(user = userid, + pass = userpwd, + host = host, + db = ivtdb, + drvr = "MySQL") + +# pick endpoints and ids +# load the number of rows and max hitc per aeid +mc5_counts <- tcplQuery("SELECT DISTINCT aeid, + COUNT( aeid ) as n, + max(hitc) as max_hitc + FROM invitrodb.mc5 GROUP BY aeid") +# filter to only include where at least one sample is active and n < 10 +mc5_counts <- mc5_counts %>% filter(max_hitc > 0.9 & n == 2) +# pick one aeid +aeid <- selected <- mc5_counts[sample(1:nrow(mc5_counts),size = 1,replace = FALSE),aeid] +# obtain the acid for the example dataset +acid <- tcplLoadAcid(fld = 'aeid',val = aeid)$acid +# pick one sample/row from each level (lvl 3 contains ids back to lvl 0 and lvl 6 does back to lvl 4) +l3 <- tcplLoadData(lvl = 3, fld = "acid", val = acid) +l3_sample1 <- l3[sample(1:nrow(l3),size = 1,replace = FALSE)] +l3_sample2 <- l3[sample(1:nrow(l3),size = 2,replace = FALSE)] +l5 <- tcplLoadData(lvl = 5, fld = "aeid", val = aeid, add.fld = FALSE) +l5_sample1 <- l5[sample(1:nrow(l5),size = 1,replace = FALSE)] +l5_sample2 <- l5[sample(1:nrow(l5),size = 2,replace = FALSE)] +l6 <- tcplLoadData(lvl = 6, fld = "aeid", val = aeid, add.fld = FALSE) +l6_sample1 <- l6[sample(1:nrow(l6),size = 1,replace = FALSE)] +l6_sample2 <- l6[sample(1:nrow(l6),size = 2,replace = FALSE)] +l7 <- tcplLoadData(lvl = 7, fld = "aeid", val = aeid, add.fld = FALSE) +l7_sample1 <- l7[sample(1:nrow(l7),size = 1,replace = FALSE)] +l7_sample2 <- l7[sample(1:nrow(l7),size = 2,replace = FALSE)] +# pick compare.val endpoints and ids +# be sure to only allow to choose from endpoints with the same number of samples +mc5_counts <- filter(mc5_counts, n == mc5_counts[aeid == selected]$n & aeid != selected) +compare.aeid <- mc5_counts[sample(1:nrow(mc5_counts),size = 1,replace = FALSE),aeid] +compare.l5 <- tcplLoadData(lvl = 5, fld = "aeid", val = compare.aeid) +compare.l5_sample1 <- compare.l5[sample(1:nrow(compare.l5),size = 1,replace = FALSE)] +compare.l5_sample2 <- compare.l5[sample(1:nrow(compare.l5),size = 2,replace = FALSE)] + + +get_query_data <- function(lvl, fld, val, compare.val = NULL, add.fld = TRUE, func = "tcplLoadData") { + message(compare.val) + if (func == "tcplLoadData") { + # IMPORTANT || MUST ADD TEMPORARY LINE TO TCPLQUERY -------------------------- + # add temporary line to top of tcplQuery to get the query string: print(query) + query_strings <- capture.output(result<-tcplLoadData(lvl = lvl, fld = fld, val = val, add.fld = add.fld)) + } else if (func == "tcplPlot") { + query_strings <- capture.output(result<-tcplPlot(type = "mc", fld = fld, + val = val, compare.val = compare.val, + output = "pdf", multi = TRUE, flags = TRUE, + fileprefix = "temp_tcplPlot")) + file.remove(stringr::str_subset(list.files(), "^temp_tcplPlot")) # clean up + } + + query_strings <- unique(gsub("\\\\", "\\\"", gsub("\"", "", gsub("\\\\n", "\\\n", gsub("\\[1\\] ", "", query_strings))))) + + # use queries to save data + dat <- lapply(query_strings, function(query_string) { + return(tcplQuery(query_string)) + }) + names(dat) <- query_strings + + # also store fld and val in list object for use in test case + dat[fld] <- val + if (!is.null(compare.val)) dat[sprintf("compare.%s", fld)] <- compare.val + return(dat) + +} + + +# to add more tests with new/different data to test-tcplLoadData.R, add lines below and run script +mc_test <- list( + tcplConfQuery = tcplQuery("SHOW VARIABLES LIKE 'max_allowed_packet'"), + mc0_by_m0id = get_query_data(lvl = 0, fld = "m0id", val = l3_sample1$m0id), + mc0_by_acid = get_query_data(lvl = 0, fld = "acid", val = acid), + mc1_by_m1id = get_query_data(lvl = 1, fld = "m1id", val = l3_sample1$m1id), + mc1_by_acid = get_query_data(lvl = 1, fld = "acid", val = acid), + mc2_by_m2id = get_query_data(lvl = 2, fld = "m2id", val = l3_sample1$m2id), + mc2_by_acid = get_query_data(lvl = 2, fld = "acid", val = acid), + mc3_by_m3id = get_query_data(lvl = 3, fld = "m3id", val = l3_sample1$m3id), + mc3_by_aeid = get_query_data(lvl = 3, fld = "aeid", val = aeid), + mc4_by_m4id = get_query_data(lvl = 4, fld = "m4id", val = l5_sample1$m4id), + mc4_by_aeid = get_query_data(lvl = 4, fld = "aeid", val = aeid, add.fld = FALSE), + mc5_by_m5id = get_query_data(lvl = 5, fld = "m5id", val = l5_sample1$m5id), + mc5_by_aeid = get_query_data(lvl = 5, fld = "aeid", val = aeid, add.fld = FALSE), + mc6_by_m6id = get_query_data(lvl = 6, fld = "m6id", val = l6_sample1$m6id), + mc6_by_aeid = get_query_data(lvl = 6, fld = "aeid", val = aeid), + mc7_by_m7id = get_query_data(lvl = 7, fld = "m7id", val = l7_sample1$m7id), + mc7_by_aeid = get_query_data(lvl = 7, fld = "aeid", val = aeid), + mcagg_by_aeid = get_query_data(lvl = "agg", fld = "aeid", val = aeid), + plot_single_m4id = get_query_data(fld = "m4id", + val = l5_sample1$m4id, + func = "tcplPlot"), + plot_multiple_m4id = get_query_data(fld = "m4id", + val = list(l5_sample2$m4id), + func = "tcplPlot"), + plot_single_aeid = get_query_data(fld = "aeid", + val = aeid, + func = "tcplPlot"), + plot_multiple_aeid = get_query_data(fld = "aeid", + val = list(c(aeid, compare.aeid)), + func = "tcplPlot"), + plot_single_spid = get_query_data(fld = c("spid", "aeid"), + val = list(l5_sample1$spid, aeid), + func = "tcplPlot"), + plot_multiple_spid = get_query_data(fld = c("spid", "aeid"), + val = list(l5_sample2$spid, aeid), + func = "tcplPlot"), + plot_single_m4id_compare = get_query_data(fld = "m4id", + val = l5_sample1$m4id, + compare.val = compare.l5_sample1$m4id, + func = "tcplPlot"), + plot_multiple_m4id_compare = get_query_data(fld = "m4id", + val = list(l5_sample2$m4id), + compare.val = list(compare.l5_sample2$m4id), + func = "tcplPlot"), + plot_single_aeid_compare = get_query_data(fld = "aeid", + val = aeid, + compare.val = compare.aeid, + func = "tcplPlot"), + plot_multiple_aeid_compare = get_query_data(fld = "aeid", + val = list(c(aeid, compare.aeid)), + compare.val = list(c(compare.aeid, aeid)), + func = "tcplPlot"), + plot_single_spid_compare = get_query_data(fld = c("spid", "aeid"), + val = list(l5_sample1$spid, aeid), + compare.val = list(compare.l5_sample1$spid, compare.aeid), + func = "tcplPlot"), + plot_multiple_spid_compare = get_query_data(fld = c("spid", "aeid"), + val = list(l5_sample2$spid, aeid), + compare.val = list(compare.l5_sample2$spid, compare.aeid), + func = "tcplPlot") +) +#---------------------------# +## save the data +usethis::use_data(mc_test, overwrite = TRUE) +#---------------------------# \ No newline at end of file diff --git a/data-raw/sc_test.R b/data-raw/sc_test.R new file mode 100644 index 00000000..4928f9ae --- /dev/null +++ b/data-raw/sc_test.R @@ -0,0 +1,146 @@ +#==============================================================================# +# NOTE: This script is written such that it is run from 'top' to 'bottom' +# or programmatically via the Terminal. +# ('R CMD BATCH --vanilla '.) +# Please do not jump around when running this script. +#==============================================================================# +# NOTE: You MUST temporarily update tcplQuery() by adding a line at the top of the +# function: print(query). +# This is because the queries will be captured from output and saved as +# part of the mocking data. +#==============================================================================# +## r packages +devtools::load_all() + +library(here) +library(dplyr) +library(stringr) +#---------------------------# +## code to prepare `sc_test` dataset goes here +# source the user ID, password, host, and database information for connection +# - NOTE: To replicate one will need to save their own 'db_cred.R', including +# the 'userid', 'userpwd', 'host', and DB collection via 'ivtdb'. +source(file = here::here("data-raw/db_cred.R"),verbose = FALSE) +# connect to the DB +tcplConf(user = userid, + pass = userpwd, + host = host, + db = ivtdb, + drvr = "MySQL") + +# pick endpoints and ids +# load the number of rows and max hitc per aeid +sc2_counts <- tcplQuery("SELECT DISTINCT aeid, + COUNT( aeid ) as n, + max(hitc) as max_hitc + FROM invitrodb.sc2 GROUP BY aeid") +# filter to only include where at least one sample is active and n = 7 +sc2_counts <- sc2_counts %>% filter(max_hitc > 0.9 & n == 7) +# pick one aeid +aeid <- selected <- sc2_counts[sample(1:nrow(sc2_counts),size = 1,replace = FALSE),aeid] +# obtain the acid for the example dataset +acid <- tcplLoadAcid(fld = 'aeid',val = aeid)$acid +# pick one sample/row from each level (lvl 1 contains ids back to lvl 0) +l1 <- tcplLoadData(type = "sc", lvl = 1, fld = "acid", val = acid) +l1_sample1 <- l1[sample(1:nrow(l1),size = 1,replace = FALSE)] +l1_sample2 <- l1[sample(1:nrow(l1),size = 2,replace = FALSE)] +l2 <- tcplLoadData(type = "sc", lvl = 2, fld = "aeid", val = aeid) +l2_sample1 <- l2[sample(1:nrow(l2),size = 1,replace = FALSE)] +l2_sample2 <- l2[sample(1:nrow(l2),size = 2,replace = FALSE)] +# pick compare.val endpoints and ids +# be sure to only allow to choose from endpoints with the same number of samples +sc2_counts <- filter(sc2_counts, n == sc2_counts[aeid == selected]$n & aeid != selected) +compare.aeid <- sc2_counts[sample(1:nrow(sc2_counts),size = 1,replace = FALSE),aeid] +compare.l2 <- tcplLoadData(type = "sc", lvl = 2, fld = "aeid", val = compare.aeid) +compare.l2_sample1 <- compare.l2[sample(1:nrow(compare.l2),size = 1,replace = FALSE)] +compare.l2_sample2 <- compare.l2[sample(1:nrow(compare.l2),size = 2,replace = FALSE)] + + +get_query_data <- function(lvl, fld, val, compare.val = NULL, add.fld = TRUE, func = "tcplLoadData") { + + # IMPORTANT || MUST ADD TEMPORARY LINE TO TCPLQUERY -------------------------- + # add temporary line to top of tcplQuery to get the query string: print(query) + if (func == "tcplLoadData") { + query_strings <- capture.output(result<-tcplLoadData(type = "sc", lvl = lvl, fld = fld, val = val, add.fld = add.fld)) + } else if (func == "tcplPlot") { + query_strings <- capture.output(result<-tcplPlot(type = "sc", fld = fld, + val = val, compare.val = compare.val, + output = "pdf", multi = TRUE, verbose = TRUE, + fileprefix = "temp_tcplPlot")) + file.remove(stringr::str_subset(list.files(), "^temp_tcplPlot")) # clean up + } + + query_strings <- unique(gsub("\\\\", "\\\"", gsub("\"", "", gsub("\\\\n", "\\\n", gsub("\\[1\\] ", "", query_strings))))) + + # use queries to save data + dat <- lapply(query_strings, function(query_string) { + return(tcplQuery(query_string)) + }) + names(dat) <- query_strings + + # also store fld and val in list object for use in test case + dat[fld] <- val + if (!is.null(compare.val)) dat[sprintf("compare.%s", fld)] <- compare.val + return(dat) + +} + + + +# to add more tests with new/different data to test-tcplLoadData.R, add lines below and run script +sc_test <- list( + tcplConfQuery = tcplQuery("SHOW VARIABLES LIKE 'max_allowed_packet'"), + sc0_by_s0id = get_query_data(lvl = 0, fld = "s0id", val = l1_sample1$s0id), + sc0_by_acid = get_query_data(lvl = 0, fld = "acid", val = acid), + sc1_by_s1id = get_query_data(lvl = 1, fld = "s1id", val = l1_sample1$s1id), + sc1_by_acid = get_query_data(lvl = 1, fld = "acid", val = acid), + sc2_by_s2id = get_query_data(lvl = 2, fld = "s2id", val = l2_sample1$s2id), + sc2_by_aeid = get_query_data(lvl = 2, fld = "aeid", val = aeid), + scagg_by_aeid = get_query_data(lvl = "agg", fld = "aeid", val = aeid), + plot_single_s2id = get_query_data(fld = "s2id", + val = l2_sample1$s2id, + func = "tcplPlot"), + plot_multiple_s2id = get_query_data(fld = "s2id", + val = list(l2_sample2$s2id), + func = "tcplPlot"), + plot_single_aeid = get_query_data(fld = "aeid", + val = aeid, + func = "tcplPlot"), + plot_multiple_aeid = get_query_data(fld = "aeid", + val = list(c(aeid, compare.aeid)), + func = "tcplPlot"), + plot_single_spid = get_query_data(fld = c("spid", "aeid"), + val = list(l2_sample1$spid, aeid), + func = "tcplPlot"), + plot_multiple_spid = get_query_data(fld = c("spid", "aeid"), + val = list(l2_sample2$spid, aeid), + func = "tcplPlot"), + plot_single_s2id_compare = get_query_data(fld = "s2id", + val = l2_sample1$s2id, + compare.val = compare.l2_sample1$s2id, + func = "tcplPlot"), + plot_multiple_s2id_compare = get_query_data(fld = "s2id", + val = list(l2_sample2$s2id), + compare.val = list(compare.l2_sample2$s2id), + func = "tcplPlot"), + plot_single_aeid_compare = get_query_data(fld = "aeid", + val = aeid, + compare.val = compare.aeid, + func = "tcplPlot"), + plot_multiple_aeid_compare = get_query_data(fld = "aeid", + val = list(c(aeid, compare.aeid)), + compare.val = list(c(compare.aeid, aeid)), + func = "tcplPlot"), + plot_single_spid_compare = get_query_data(fld = c("spid", "aeid"), + val = list(l2_sample1$spid, aeid), + compare.val = list(compare.l2_sample1$spid, compare.aeid), + func = "tcplPlot"), + plot_multiple_spid_compare = get_query_data(fld = c("spid", "aeid"), + val = list(l2_sample2$spid, aeid), + compare.val = list(compare.l2_sample2$spid, compare.aeid), + func = "tcplPlot") +) +#---------------------------# +## save the data +usethis::use_data(sc_test, overwrite = TRUE) +#---------------------------# \ No newline at end of file diff --git a/data-raw/sc_vignette.R b/data-raw/sc_vignette.R index ade6e63d..d2f2fd73 100644 --- a/data-raw/sc_vignette.R +++ b/data-raw/sc_vignette.R @@ -5,8 +5,7 @@ # Please do not jump around when running this script. #==============================================================================# ## r packages -library(tcplfit2) -library(tcpl) +devtools::load_all() library(here) library(data.table) @@ -43,8 +42,8 @@ atg.acid.sc <- atg.acid %>% filter(.,acid%in%atg.sc.ids) %>% as.data.table() # print the data.table of acid's atg.acid.sc # obtain the aeid's for the atg single concentration data -atg.aeid.sc <- tcplLoadAeid(fld = 'acid',val = atg.acid.sc) %>% - filter(.,grepl(aenm,pattern = "up$")) +atg.aeid.sc <- tcplLoadAeid(fld = 'acid',val = atg.acid.sc) #%>% + #filter(.,grepl(aenm,pattern = "up$")) # obtain the level 2 sc data tictoc::tic() atg.sc2 <- tcplPrepOtpt( @@ -110,9 +109,9 @@ tictoc::toc() tictoc::tic() atg.sc1.ss <- atg.sc1 %>% # keep only those observations that are related to the level 2 spids - dplyr::filter(spid %in% atg.sc2.ss[,spid]) %>% + dplyr::filter(spid %in% atg.sc2.ss[,spid]) #%>% # keep only those observations that are related to the 'up' endpoints - dplyr::filter(.,grepl(aenm,pattern = "up$")) + #dplyr::filter(.,grepl(aenm,pattern = "up$")) tictoc::toc() # collate the data into a single object 'sc_vignette' diff --git a/data-raw/test_api.R b/data-raw/test_api.R new file mode 100644 index 00000000..db16336b --- /dev/null +++ b/data-raw/test_api.R @@ -0,0 +1,49 @@ +#==============================================================================# +# NOTE: This script is written such that it is run from 'top' to 'bottom' +# or programmatically via the Terminal. +# ('R CMD BATCH --vanilla '.) +# Please do not jump around when running this script. +#==============================================================================# +# NOTE: You MUST temporarily update tcplQuery() by adding a line at the top of the +# function: print(query). +# This is because the queries will be captured from output and saved as +# part of the mocking data. +#==============================================================================# +## r packages +devtools::load_all() +library(ctxR) +library(here) +library(dplyr) +library(stringr) +#---------------------------# +## code to prepare `test_api` dataset goes here +# source the user ID, password, host, and database information for connection +# - NOTE: To replicate one will need to save their own 'db_cred.R', including +# the 'apikey'. +source(file = here::here("data-raw/db_cred.R"),verbose = FALSE) +# connect to the DB +tcplConf(pass = apikey, + drvr = "API") + +assays <- get_all_assays(Server = paste0(getOption("TCPL_HOST"))) +aeid <- assays[sample(1:nrow(assays), 1),]$aeid +acid <- tcplLoadAcid(fld = "aeid", val = aeid)$acid +aid <- tcplLoadAid(fld = "aeid", val = aeid)$aid +asid <- tcplLoadAsid(fld = "aeid", val = aeid)$asid +dat <- tcplLoadData(lvl = 5, fld = "aeid", val = aeid) +sample <- dat[sample(1:nrow(dat), 1),] + +# to add more tests with new/different data to test-tcplLoadData.R, add lines below and run script +test_api <- list( + aeid = aeid, + acid = acid, + aid = aid, + asid = asid, + dtxsid = sample$dtxsid, + spid = sample$spid, + m4id = sample$m4id +) +#---------------------------# +## save the data +usethis::use_data(test_api, overwrite = TRUE) +#---------------------------# \ No newline at end of file diff --git a/data/mc_test.rda b/data/mc_test.rda new file mode 100644 index 00000000..cdca61c1 Binary files /dev/null and b/data/mc_test.rda differ diff --git a/data/sc_test.rda b/data/sc_test.rda new file mode 100644 index 00000000..2998be80 Binary files /dev/null and b/data/sc_test.rda differ diff --git a/data/sc_vignette.rda b/data/sc_vignette.rda index e478e9c9..19310c0a 100644 Binary files a/data/sc_vignette.rda and b/data/sc_vignette.rda differ diff --git a/data/test_api.rda b/data/test_api.rda new file mode 100644 index 00000000..06fd1302 Binary files /dev/null and b/data/test_api.rda differ diff --git a/man/mc_test.Rd b/man/mc_test.Rd new file mode 100644 index 00000000..b98db1de --- /dev/null +++ b/man/mc_test.Rd @@ -0,0 +1,154 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{mc_test} +\alias{mc_test} +\title{List of lists containing queries sent to tcplQuery associated with each test +case. Each list also contains the associated ids with each case. Only meant +to be used with automated testing with mocking for mc data.} +\format{ +A list with 30 items: +\describe{ + \item{tcplConfQuery}{Data table with 1 row and 2 columns used for each test + case for establishing connection using tcplConf. This data table mocks the + response one would get from connecting with invitrodb.} + \item{mc0_by_m0id}{List containing the queries used for loading mc0 data by + m0id via tcplLoadData. Each query has an associated data table response for + mocking an actual connection. Contains one 'm0id' labeled item storing the + id used to load the data, for use in tests.} + \item{mc0_by_acid}{List containing the queries used for loading mc0 data by + acid via tcplLoadData. Each query has an associated data table response for + mocking an actual connection. Contains one 'acid' labeled item storing the + id used to load the data, for use in tests.} + \item{mc1_by_m1id}{List containing the queries used for loading mc1 data by + m1id via tcplLoadData. Each query has an associated data table response for + mocking an actual connection. Contains one 'm1id' labeled item storing the + id used to load the data, for use in tests.} + \item{mc1_by_acid}{List containing the queries used for loading mc1 data by + acid via tcplLoadData. Each query has an associated data table response for + mocking an actual connection. Contains one 'acid' labeled item storing the + id used to load the data, for use in tests.} + \item{mc2_by_m2id}{List containing the queries used for loading mc2 data by + m2id via tcplLoadData. Each query has an associated data table response for + mocking an actual connection. Contains one 'm2id' labeled item storing the + id used to load the data, for use in tests.} + \item{mc2_by_acid}{List containing the queries used for loading mc2 data by + acid via tcplLoadData. Each query has an associated data table response for + mocking an actual connection. Contains one 'acid' labeled item storing the + id used to load the data, for use in tests.} + \item{mc3_by_m3id}{List containing the queries used for loading mc3 data by + m3id via tcplLoadData. Each query has an associated data table response for + mocking an actual connection. Contains one 'm3id' labeled item storing the + id used to load the data, for use in tests.} + \item{mc3_by_aeid}{List containing the queries used for loading mc3 data by + aeid via tcplLoadData. Each query has an associated data table response for + mocking an actual connection. Contains one 'aeid' labeled item storing the + id used to load the data, for use in tests.} + \item{mc4_by_m4id}{List containing the queries used for loading mc4 data by + m4id via tcplLoadData. Each query has an associated data table response for + mocking an actual connection. Contains one 'm4id' labeled item storing the + id used to load the data, for use in tests.} + \item{mc4_by_aeid}{List containing the queries used for loading mc4 data by + aeid via tcplLoadData. Each query has an associated data table response for + mocking an actual connection. Contains one 'aeid' labeled item storing the + id used to load the data, for use in tests.} + \item{mc5_by_m5id}{List containing the queries used for loading mc5 data by + m5id via tcplLoadData. Each query has an associated data table response for + mocking an actual connection. Contains one 'm5id' labeled item storing the + id used to load the data, for use in tests.} + \item{mc5_by_aeid}{List containing the queries used for loading mc5 data by + aeid via tcplLoadData. Each query has an associated data table response for + mocking an actual connection. Contains one 'aeid' labeled item storing the + id used to load the data, for use in tests.} + \item{mc6_by_m6id}{List containing the queries used for loading mc6 data by + m6id via tcplLoadData. Each query has an associated data table response for + mocking an actual connection. Contains one 'm6id' labeled item storing the + id used to load the data, for use in tests.} + \item{mc6_by_aeid}{List containing the queries used for loading mc6 data by + aeid via tcplLoadData. Each query has an associated data table response for + mocking an actual connection. Contains one 'aeid' labeled item storing the + id used to load the data, for use in tests.} + \item{mc7_by_m7id}{List containing the queries used for loading mc7 data by + m7id via tcplLoadData. Each query has an associated data table response for + mocking an actual connection. Contains one 'm7id' labeled item storing the + id used to load the data, for use in tests.} + \item{mc7_by_aeid}{List containing the queries used for loading mc7 data by + aeid via tcplLoadData. Each query has an associated data table response for + mocking an actual connection. Contains one 'aeid' labeled item storing the + id used to load the data, for use in tests.} + \item{mcagg_by_aeid}{List containing the queries used for loading mc 'agg' + data by aeid via tcplLoadData. Each query has an associated data table + response for mocking an actual connection. Contains one 'aeid' labeled item + storing the id used to load the data, for use in tests.} + \item{plot_single_m4id}{List containing the queries used for loading and + plotting mc data by m4id via tcplPlot. Each query has an associated data + table response for mocking an actual connection. Contains one 'm4id' + labeled item storing the id used to load the data, for use in tests.} + \item{plot_multiple_m4id}{List containing the queries used for loading and + plotting mc data by multiple m4ids via tcplPlot. Each query has an + associated data table response for mocking an actual connection. Contains + one 'm4id' labeled item storing the ids used to load the data, for use in + tests.} + \item{plot_single_aeid}{List containing the queries used for loading and + plotting mc data by aeid via tcplPlot. Each query has an associated data + table response for mocking an actual connection. Contains one 'aeid' + labeled item storing the id used to load the data, for use in tests.} + \item{plot_multiple_aeid}{List containing the queries used for loading and + plotting mc data by multiple aeids via tcplPlot. Each query has an + associated data table response for mocking an actual connection. Contains + one 'aeid' labeled item storing the ids used to load the data, for use in + tests.} + \item{plot_single_spid}{List containing the queries used for loading and + plotting mc data by spid/aeid via tcplPlot. Each query has an associated + data table response for mocking an actual connection. Contains 'spid' and + 'aeid' labeled items storing the ids used to load the data, for use in + tests.} + \item{plot_multiple_spid}{List containing the queries used for loading and + plotting mc data by multiple spids/aeid via tcplPlot. Each query has an + associated data table response for mocking an actual connection. Contains + 'spid' and 'aeid' labeled items storing the ids used to load the data, for + use in tests.} + \item{plot_single_m4id_compare}{List containing the queries used for + loading and plotting compared mc data by m4id via tcplPlot. Each query has + an associated data table response for mocking an actual connection. + Contains 'm4id' and 'compare.m4id' labeled items storing the ids used to + load the data, for use in tests.} + \item{plot_multiple_m4id_compare}{List containing the queries used for loading and + plotting compared mc data by multiple m4ids via tcplPlot. Each query has an + associated data table response for mocking an actual connection. Contains + 'm4id' and 'compare.m4id' labeled items storing the ids used to load the + data, for use in tests.} + \item{plot_single_aeid_compare}{List containing the queries used for + loading and plotting compared mc data by aeid via tcplPlot. Each query has + an associated data table response for mocking an actual connection. + Contains 'aeid' and 'compare.aeid' labeled items storing the ids used to + load the data, for use in tests.} + \item{plot_multiple_aeid_compare}{List containing the queries used for + loading and plotting compared mc data by multiple aeids via tcplPlot. Each + query has an associated data table response for mocking an actual + connection. Contains 'aeid' and 'compare.aeid' labeled items storing the + ids used to load the data, for use in tests.} + \item{plot_single_spid_compare}{List containing the queries used for + loading and plotting compared mc data by spid/aeid via tcplPlot. Each query + has an associated data table response for mocking an actual connection. + Contains 'spid', 'compare.spid', 'aeid', and 'compare.aeid' labeled items + storing the ids used to load the data, for use in tests.} + \item{plot_multiple_spid_compare}{List containing the queries used for + loading and plotting compared mc data by multiple spids/aeid via tcplPlot. + Each query has an associated data table response for mocking an actual + connection. Contains 'spid', 'compare.spid', 'aeid', and 'compare.aeid' + labeled items storing the ids used to load the data, for use in tests.} +} +} +\source{ +ToxCast database +} +\usage{ +mc_test +} +\description{ +List of lists containing queries sent to tcplQuery associated with each test +case. Each list also contains the associated ids with each case. Only meant +to be used with automated testing with mocking for mc data. +} +\keyword{datasets} diff --git a/man/sc_test.Rd b/man/sc_test.Rd new file mode 100644 index 00000000..841e9a41 --- /dev/null +++ b/man/sc_test.Rd @@ -0,0 +1,114 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{sc_test} +\alias{sc_test} +\title{List of lists containing queries sent to tcplQuery associated with each test +case. Each list also contains the associated ids with each case. Only meant +to be used with automated testing with mocking for sc data.} +\format{ +A list with 20 items: +\describe{ + \item{tcplConfQuery}{Data table with 1 row and 2 columns used for each test + case for establishing connection using tcplConf. This data table mocks the + response one would get from connecting with invitrodb.} + \item{sc0_by_s0id}{List containing the queries used for loading sc0 data by + s0id via tcplLoadData. Each query has an associated data table response for + mocking an actual connection. Contains one 's0id' labeled item storing the + id used to load the data, for use in tests.} + \item{sc0_by_acid}{List containing the queries used for loading sc0 data by + acid via tcplLoadData. Each query has an associated data table response for + mocking an actual connection. Contains one 'acid' labeled item storing the + id used to load the data, for use in tests.} + \item{sc1_by_s1id}{List containing the queries used for loading sc1 data by + s1id via tcplLoadData. Each query has an associated data table response for + mocking an actual connection. Contains one 's1id' labeled item storing the + id used to load the data, for use in tests.} + \item{sc1_by_acid}{List containing the queries used for loading sc1 data by + acid via tcplLoadData. Each query has an associated data table response for + mocking an actual connection. Contains one 'acid' labeled item storing the + id used to load the data, for use in tests.} + \item{sc2_by_s2id}{List containing the queries used for loading sc2 data by + s2id via tcplLoadData. Each query has an associated data table response for + mocking an actual connection. Contains one 's2id' labeled item storing the + id used to load the data, for use in tests.} + \item{sc2_by_aeid}{List containing the queries used for loading sc2 data by + aeid via tcplLoadData. Each query has an associated data table response for + mocking an actual connection. Contains one 'aeid' labeled item storing the + id used to load the data, for use in tests.} + \item{scagg_by_aeid}{List containing the queries used for loading sc 'agg' + data by aeid via tcplLoadData. Each query has an associated data table + response for mocking an actual connection. Contains one 'aeid' labeled item + storing the id used to load the data, for use in tests.} + \item{plot_single_s2id}{List containing the queries used for loading and + plotting sc data by s2id via tcplPlot. Each query has an associated data + table response for mocking an actual connection. Contains one 's2id' + labeled item storing the id used to load the data, for use in tests.} + \item{plot_multiple_s2id}{List containing the queries used for loading and + plotting sc data by multiple s2ids via tcplPlot. Each query has an + associated data table response for mocking an actual connection. Contains + one 's2id' labeled item storing the ids used to load the data, for use in + tests.} + \item{plot_single_aeid}{List containing the queries used for loading and + plotting sc data by aeid via tcplPlot. Each query has an associated data + table response for mocking an actual connection. Contains one 'aeid' + labeled item storing the id used to load the data, for use in tests.} + \item{plot_multiple_aeid}{List containing the queries used for loading and + plotting sc data by multiple aeids via tcplPlot. Each query has an + associated data table response for mocking an actual connection. Contains + one 'aeid' labeled item storing the ids used to load the data, for use in + tests.} + \item{plot_single_spid}{List containing the queries used for loading and + plotting sc data by spid/aeid via tcplPlot. Each query has an associated + data table response for mocking an actual connection. Contains 'spid' and + 'aeid' labeled items storing the ids used to load the data, for use in + tests.} + \item{plot_multiple_spid}{List containing the queries used for loading and + plotting sc data by multiple spids/aeid via tcplPlot. Each query has an + associated data table response for mocking an actual connection. Contains + 'spid' and 'aeid' labeled items storing the ids used to load the data, for + use in tests.} + \item{plot_single_s2id_compare}{List containing the queries used for + loading and plotting compared sc data by s2id via tcplPlot. Each query has + an associated data table response for mocking an actual connection. + Contains 's2id' and 'compare.s2id' labeled items storing the ids used to + load the data, for use in tests.} + \item{plot_multiple_s2id_compare}{List containing the queries used for loading and + plotting compared sc data by multiple s2ids via tcplPlot. Each query has an + associated data table response for mocking an actual connection. Contains + 's2id' and 'compare.s2id' labeled items storing the ids used to load the + data, for use in tests.} + \item{plot_single_aeid_compare}{List containing the queries used for + loading and plotting compared sc data by aeid via tcplPlot. Each query has + an associated data table response for mocking an actual connection. + Contains 'aeid' and 'compare.aeid' labeled items storing the ids used to + load the data, for use in tests.} + \item{plot_multiple_aeid_compare}{List containing the queries used for + loading and plotting compared sc data by multiple aeids via tcplPlot. Each + query has an associated data table response for mocking an actual + connection. Contains 'aeid' and 'compare.aeid' labeled items storing the + ids used to load the data, for use in tests.} + \item{plot_single_spid_compare}{List containing the queries used for + loading and plotting compared sc data by spid/aeid via tcplPlot. Each query + has an associated data table response for mocking an actual connection. + Contains 'spid', 'compare.spid', 'aeid', and 'compare.aeid' labeled items + storing the ids used to load the data, for use in tests.} + \item{plot_multiple_spid_compare}{List containing the queries used for + loading and plotting compared sc data by multiple spids/aeid via tcplPlot. + Each query has an associated data table response for mocking an actual + connection. Contains 'spid', 'compare.spid', 'aeid', and 'compare.aeid' + labeled items storing the ids used to load the data, for use in tests.} +} +} +\source{ +ToxCast database +} +\usage{ +sc_test +} +\description{ +List of lists containing queries sent to tcplQuery associated with each test +case. Each list also contains the associated ids with each case. Only meant +to be used with automated testing with mocking for sc data. +} +\keyword{datasets} diff --git a/man/test_api.Rd b/man/test_api.Rd new file mode 100644 index 00000000..9f352c5d --- /dev/null +++ b/man/test_api.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{test_api} +\alias{test_api} +\title{List containing ids used for different automated tests of tcpl integration +with the CTX APIs, randomly selected from what is available via API.} +\format{ +A list with 7 items: +\describe{ + \item{aeid}{Randomly selected assay component endpoint id} + \item{acid}{Assay component id associated with the above aeid} + \item{aid}{Assay id associated with the above aeid} + \item{asid}{Assay source id associated with the above aeid} + \item{dtxsid}{dsstox substance id of one sample from the above aeid} + \item{spid}{Sample id of one (the same) sample from the above aeid} + \item{m4id}{Level 4 id of one (the same) sample from the above aeid} +} +} +\source{ +CTX Bioactivity API +} +\usage{ +test_api +} +\description{ +List containing ids used for different automated tests of tcpl integration +with the CTX APIs, randomly selected from what is available via API. +} +\keyword{datasets} diff --git a/tests/testthat/_snaps/tcplPlot/negative-cutoff-bmr.svg b/tests/testthat/_snaps/tcplPlot/negative-cutoff-bmr.svg deleted file mode 100644 index edd4e0ab..00000000 --- a/tests/testthat/_snaps/tcplPlot/negative-cutoff-bmr.svg +++ /dev/null @@ -1,195 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --0.4 --0.2 -0.0 - - - - - - - -0.1 -1.0 -10.0 -100.0 -Concentration (uM) -Log2 Fold Induction - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Winning Model -(pow) -Losing Models -Cutoff -BMD -AC50 -DTXSID10379991 3-(Perfluorooctyl)propanol -SPID:1210314466 AEID:80 AENM:ATG_GLI_CIS_up -M4ID:482359 HITC:0.960 - - diff --git a/tests/testthat/_snaps/tcplPlot/test-output-482273.svg b/tests/testthat/_snaps/tcplPlot/test-output-482273.svg deleted file mode 100644 index 4fd6daf6..00000000 --- a/tests/testthat/_snaps/tcplPlot/test-output-482273.svg +++ /dev/null @@ -1,790 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -0.0 -0.3 -0.6 - - - - - - - -0.1 -1.0 -10.0 -100.0 -Concentration (uM) -Log2 Fold Induction - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Winning Model -(exp2) -Losing Models -Cutoff -BMD -AC50 -DTXSID80379721 1H,1H,6H,6H-Perfluorohexane-1,6-diol diacrylate -SPID:01504209 AEID:80 AENM:ATG_GLI_CIS_up -M4ID:482273 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Hitcall - - - - -1.000 - - - - -model - - - - -poly2 - - - - -BMD - - - - -46.275 - - - - -aic - - - - -pow - - - - -AC50 - - - - -79.547 - - - - -rme - - - - -exp2 - - - - -hill - - - - -exp3 - - - - -exp5 - - - - -gnls - - - - -poly1 - - - - -exp4 - - - - -cnst - - - - --2.1e+01 - - - - --2.1e+01 - - - - --2.1e+01 - - - - --1.9e+01 - - - - --1.9e+01 - - - - --1.9e+01 - - - - --1.5e+01 - - - - --1.5e+01 - - - - --7.3e+00 - - - - -4.350 - - - - -0.094 - - - - -0.094 - - - - -0.093 - - - - -0.094 - - - - -0.093 - - - - -0.094 - - - - -0.094 - - - - -0.116 - - - - -0.142 - - - - -0.332 - - - - diff --git a/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/assay.json b/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/assay.json new file mode 100644 index 00000000..3d4de4e4 --- /dev/null +++ b/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/assay.json @@ -0,0 +1,236 @@ +[ + { + "aeid": 1390, + "assayComponentEndpointName": "LTEA_HepaRG_SLC22A6", + "exportReady": 1, + "internalReady": 1, + "assayComponentEndpointDesc": "Data from the assay component LTEA_HepaRG_SLC22A6 was analyzed into 1 endpoint. This assay endpoint, LTEA_HepaRG_SLC22A6, was analyzed with bidirectional fitting relative to DMSO as the negative control and baseline of activity. Using a type of inducible reporter, measures of mRNA induction for gain or loss-of-signal activity can be used to understand regulation of transcription factor activity. To generalize the intended target to other relatable targets, this assay endpoint is annotated to the transporter intended target family, where the subfamily is organic anion transporter.", + "assayFunctionType": "reporter gene", + "normalizedDataType": "log2_fold_induction", + "burstAssay": 0, + "keyPositiveControl": null, + "signalDirection": "bidirectional", + "intendedTargetType": "rna", + "intendedTargetTypeSub": "mRNA", + "intendedTargetFamily": "transporter", + "intendedTargetFamilySub": "organic anion transporter", + "cellViabilityAssay": 0, + "dataUsability": 1, + "acid": 957, + "assayComponentName": "LTEA_HepaRG_SLC22A6", + "assayComponentDesc": "LTEA_HepaRG_SLC22A6 is one of 102 assay component(s) measured in the LTEA HepaRG cell culture assay. It is a marker of NR mediated transport.", + "assayComponentTargetDesc": "Metabolically-competent HepaRG cell cultures were exposed to a chemical for 48 hours before cytotoxicty (LDH) and alterations in transcription were assessed.", + "parameterReadoutType": "single", + "assayDesignType": "inducible reporter", + "assayDesignTypeSub": "mRNA induction", + "biologicalProcessTarget": "regulation of transcription factor activity", + "detectionTechnologyType": "Fluorescence", + "detectionTechnologyTypeSub": "Fluorescence intensity", + "detectionTechnology": "Fluidigm qRT-PCR", + "keyAssayReagentType": null, + "keyAssayReagent": null, + "technologicalTargetType": "rna", + "technologicalTargetTypeSub": "mRNA", + "aid": 371, + "assayName": "LTEA_HepaRG", + "assayDesc": "LTEA_HepaRG is a cell based, multiplexed-readout assay that uses HepaRG, a human liver cell line, with measurements taken at 48 hours after chemical dosing on a 96-well plate.", + "timepointHr": 48.0, + "organismId": 9606, + "organism": "human", + "tissue": "liver", + "cellFormat": "cell line", + "cellFreeComponentSource": "", + "cellShortName": "HepaRG", + "cellGrowthMode": "adherent", + "assayFootprint": "microplate: 96-well plate", + "assayFormatType": "cell-based", + "assayFormatTypeSub": "cell-based format", + "contentReadoutType": "multiplexed", + "dilutionSolvent": "DMSO", + "dilutionSolventPercentMax": 0.5, + "asid": 9, + "assaySourceName": "LTEA", + "assaySourceLongName": "LifeTech/Expression Analysis", + "assaySourceDesc": "Life Technologies, acquired by Thermo Fisher, is a Contract Research Organization (CRO) that provides transcriptomics and expression screening.", + "gene": { + "geneId": 353, + "geneName": "solute carrier family 22 (organic anion transporter), member 6", + "description": null, + "geneSymbol": "SLC22A6", + "organismId": 1, + "trackStatus": "live", + "entrezGeneId": 9356, + "officialSymbol": "SLC22A6", + "officialFullName": "solute carrier family 22 (organic anion transporter), member 6", + "uniprotAccessionNumber": "Q4U2R8" + }, + "assayList": null, + "citations": { + "doi": "doi: 10.1038/s41540-020-00166-2", + "url": "https://pubmed.ncbi.nlm.nih.gov/33504769/", + "pmid": 33504769, + "title": "High-throughput toxicogenomic screening of chemicals in the environment using metabolically competent hepatic cell cultures", + "author": "Franzosa JA, Bonzo JA, Jack J, Baker NC, Kothiya P, Witek RP, Hurban P, Siferd S, Hester S, Shah I, Ferguson SS, Houck KA, Wambaugh JF", + "citation": "Franzosa JA, Bonzo JA, Jack J, Baker NC, Kothiya P, Witek RP, Hurban P, Siferd S, Hester S, Shah I, Ferguson SS, Houck KA, Wambaugh JF. High-throughput toxicogenomic screening of chemicals in the environment using metabolically competent hepatic cell cultures. NPJ Syst Biol Appl. 2021 Jan 27;7(1):7. doi: 10.1038/s41540-020-00166-2. PMID: 33504769; PMCID: PMC7840683.", + "otherId": "0", + "citationId": 247, + "otherSource": "" + } + }, + { + "aeid": 1392, + "assayComponentEndpointName": "LTEA_HepaRG_KLK3", + "exportReady": 1, + "internalReady": 1, + "assayComponentEndpointDesc": "Data from the assay component LTEA_HepaRG_KLK3 was analyzed into 1 endpoint. This assay endpoint, LTEA_HepaRG_KLK3, was analyzed with bidirectional fitting relative to DMSO as the negative control and baseline of activity. Using a type of inducible reporter, measures of mRNA induction for gain or loss-of-signal activity can be used to understand regulation of transcription factor activity. To generalize the intended target to other relatable targets, this assay endpoint is annotated to the protease intended target family, where the subfamily is Cellular remodeling.", + "assayFunctionType": "reporter gene", + "normalizedDataType": "log2_fold_induction", + "burstAssay": 0, + "keyPositiveControl": null, + "signalDirection": "bidirectional", + "intendedTargetType": "rna", + "intendedTargetTypeSub": "mRNA", + "intendedTargetFamily": "protease", + "intendedTargetFamilySub": "Cellular remodeling", + "cellViabilityAssay": 0, + "dataUsability": 1, + "acid": 958, + "assayComponentName": "LTEA_HepaRG_KLK3", + "assayComponentDesc": "LTEA_HepaRG_KLK3 is one of 102 assay component(s) measured in the LTEA HepaRG cell culture assay. It is a marker of Cellular remodeling.", + "assayComponentTargetDesc": "Metabolically-competent HepaRG cell cultures were exposed to a chemical for 48 hours before cytotoxicty (LDH) and alterations in transcription were assessed.", + "parameterReadoutType": "single", + "assayDesignType": "inducible reporter", + "assayDesignTypeSub": "mRNA induction", + "biologicalProcessTarget": "regulation of transcription factor activity", + "detectionTechnologyType": "Fluorescence", + "detectionTechnologyTypeSub": "Fluorescence intensity", + "detectionTechnology": "Fluidigm qRT-PCR", + "keyAssayReagentType": null, + "keyAssayReagent": null, + "technologicalTargetType": "rna", + "technologicalTargetTypeSub": "mRNA", + "aid": 371, + "assayName": "LTEA_HepaRG", + "assayDesc": "LTEA_HepaRG is a cell based, multiplexed-readout assay that uses HepaRG, a human liver cell line, with measurements taken at 48 hours after chemical dosing on a 96-well plate.", + "timepointHr": 48.0, + "organismId": 9606, + "organism": "human", + "tissue": "liver", + "cellFormat": "cell line", + "cellFreeComponentSource": "", + "cellShortName": "HepaRG", + "cellGrowthMode": "adherent", + "assayFootprint": "microplate: 96-well plate", + "assayFormatType": "cell-based", + "assayFormatTypeSub": "cell-based format", + "contentReadoutType": "multiplexed", + "dilutionSolvent": "DMSO", + "dilutionSolventPercentMax": 0.5, + "asid": 9, + "assaySourceName": "LTEA", + "assaySourceLongName": "LifeTech/Expression Analysis", + "assaySourceDesc": "Life Technologies, acquired by Thermo Fisher, is a Contract Research Organization (CRO) that provides transcriptomics and expression screening.", + "gene": { + "geneId": 25, + "geneName": "kallikrein-related peptidase 3", + "description": null, + "geneSymbol": "KLK3", + "organismId": 1, + "trackStatus": "live", + "entrezGeneId": 354, + "officialSymbol": "KLK3", + "officialFullName": "kallikrein-related peptidase 3", + "uniprotAccessionNumber": "P07288" + }, + "assayList": null, + "citations": { + "doi": "doi: 10.1038/s41540-020-00166-2", + "url": "https://pubmed.ncbi.nlm.nih.gov/33504769/", + "pmid": 33504769, + "title": "High-throughput toxicogenomic screening of chemicals in the environment using metabolically competent hepatic cell cultures", + "author": "Franzosa JA, Bonzo JA, Jack J, Baker NC, Kothiya P, Witek RP, Hurban P, Siferd S, Hester S, Shah I, Ferguson SS, Houck KA, Wambaugh JF", + "citation": "Franzosa JA, Bonzo JA, Jack J, Baker NC, Kothiya P, Witek RP, Hurban P, Siferd S, Hester S, Shah I, Ferguson SS, Houck KA, Wambaugh JF. High-throughput toxicogenomic screening of chemicals in the environment using metabolically competent hepatic cell cultures. NPJ Syst Biol Appl. 2021 Jan 27;7(1):7. doi: 10.1038/s41540-020-00166-2. PMID: 33504769; PMCID: PMC7840683.", + "otherId": "0", + "citationId": 247, + "otherSource": "" + } + }, + { + "aeid": 1394, + "assayComponentEndpointName": "LTEA_HepaRG_SLC10A1", + "exportReady": 1, + "internalReady": 1, + "assayComponentEndpointDesc": "Data from the assay component LTEA_HepaRG_SLC10A1 was analyzed into 1 endpoint. This assay endpoint, LTEA_HepaRG_SLC10A1, was analyzed with bidirectional fitting relative to DMSO as the negative control and baseline of activity. Using a type of inducible reporter, measures of mRNA induction for gain or loss-of-signal activity can be used to understand regulation of transcription factor activity. To generalize the intended target to other relatable targets, this assay endpoint is annotated to the transporter intended target family, where the subfamily is sodium/bile acid cotransporter.", + "assayFunctionType": "reporter gene", + "normalizedDataType": "log2_fold_induction", + "burstAssay": 0, + "keyPositiveControl": null, + "signalDirection": "bidirectional", + "intendedTargetType": "rna", + "intendedTargetTypeSub": "mRNA", + "intendedTargetFamily": "transporter", + "intendedTargetFamilySub": "sodium/bile acid cotransporter", + "cellViabilityAssay": 0, + "dataUsability": 1, + "acid": 959, + "assayComponentName": "LTEA_HepaRG_SLC10A1", + "assayComponentDesc": "LTEA_HepaRG_SLC10A1 is one of 102 assay component(s) measured in the LTEA HepaRG cell culture assay. It is a marker of NR mediated transport.", + "assayComponentTargetDesc": "Metabolically-competent HepaRG cell cultures were exposed to a chemical for 48 hours before cytotoxicty (LDH) and alterations in transcription were assessed.", + "parameterReadoutType": "single", + "assayDesignType": "inducible reporter", + "assayDesignTypeSub": "mRNA induction", + "biologicalProcessTarget": "regulation of transcription factor activity", + "detectionTechnologyType": "Fluorescence", + "detectionTechnologyTypeSub": "Fluorescence intensity", + "detectionTechnology": "Fluidigm qRT-PCR", + "keyAssayReagentType": null, + "keyAssayReagent": null, + "technologicalTargetType": "rna", + "technologicalTargetTypeSub": "mRNA", + "aid": 371, + "assayName": "LTEA_HepaRG", + "assayDesc": "LTEA_HepaRG is a cell based, multiplexed-readout assay that uses HepaRG, a human liver cell line, with measurements taken at 48 hours after chemical dosing on a 96-well plate.", + "timepointHr": 48.0, + "organismId": 9606, + "organism": "human", + "tissue": "liver", + "cellFormat": "cell line", + "cellFreeComponentSource": "", + "cellShortName": "HepaRG", + "cellGrowthMode": "adherent", + "assayFootprint": "microplate: 96-well plate", + "assayFormatType": "cell-based", + "assayFormatTypeSub": "cell-based format", + "contentReadoutType": "multiplexed", + "dilutionSolvent": "DMSO", + "dilutionSolventPercentMax": 0.5, + "asid": 9, + "assaySourceName": "LTEA", + "assaySourceLongName": "LifeTech/Expression Analysis", + "assaySourceDesc": "Life Technologies, acquired by Thermo Fisher, is a Contract Research Organization (CRO) that provides transcriptomics and expression screening.", + "gene": { + "geneId": 299, + "geneName": "solute carrier family 10 (sodium/bile acid cotransporter), member 1", + "description": null, + "geneSymbol": "SLC10A1", + "organismId": 1, + "trackStatus": "live", + "entrezGeneId": 6554, + "officialSymbol": "SLC10A1", + "officialFullName": "solute carrier family 10 (sodium/bile acid cotransporter), member 1", + "uniprotAccessionNumber": "Q14973" + }, + "assayList": null, + "citations": { + "doi": "doi: 10.1038/s41540-020-00166-2", + "url": "https://pubmed.ncbi.nlm.nih.gov/33504769/", + "pmid": 33504769, + "title": "High-throughput toxicogenomic screening of chemicals in the environment using metabolically competent hepatic cell cultures", + "author": "Franzosa JA, Bonzo JA, Jack J, Baker NC, Kothiya P, Witek RP, Hurban P, Siferd S, Hester S, Shah I, Ferguson SS, Houck KA, Wambaugh JF", + "citation": "Franzosa JA, Bonzo JA, Jack J, Baker NC, Kothiya P, Witek RP, Hurban P, Siferd S, Hester S, Shah I, Ferguson SS, Houck KA, Wambaugh JF. High-throughput toxicogenomic screening of chemicals in the environment using metabolically competent hepatic cell cultures. NPJ Syst Biol Appl. 2021 Jan 27;7(1):7. doi: 10.1038/s41540-020-00166-2. PMID: 33504769; PMCID: PMC7840683.", + "otherId": "0", + "citationId": 247, + "otherSource": "" + } + } +] \ No newline at end of file diff --git a/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-aeid/0.json b/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-aeid/0.json new file mode 100644 index 00000000..41b42e67 --- /dev/null +++ b/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-aeid/0.json @@ -0,0 +1,3 @@ +[ + +] diff --git a/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-aeid/1390.json b/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-aeid/1390.json new file mode 100644 index 00000000..98ff9665 --- /dev/null +++ b/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-aeid/1390.json @@ -0,0 +1,372 @@ +[ + { + "aeid": 1390, + "m4id": 906167, + "spid": "TX009761", + "chid": 24845, + "casn": "64-86-8", + "chnm": "Colchicine", + "dtxsid": "DTXSID5024845", + "bmad": 0.9405044150032765, + "respMax": 2.60967253749995, + "respMin": 2.1440377088333484, + "maxMean": 2.3768551231666493, + "maxMeanConc": -1.5228787452803376, + "maxMed": 2.3768551231666493, + "maxMedConc": -1.5228787452803376, + "logcMax": -1.5228787452803376, + "logcMin": -1.5228787452803376, + "nconc": 1, + "npts": 2, + "nrep": 2.0, + "nmedGtbl": 0, + "tmpi": 72, + "m5id": 6384473, + "modl": "none", + "hitc": 0.0, + "fitc": 2, + "coff": 2.8215132450098297, + "actp": null, + "modelType": 2, + "chidRep": 1, + "stkc": 20.0, + "stkcUnit": "mM", + "testedConcUnit": "uM", + "mc3Param": { + "logc": [ + -1.5228787452803376, + -1.5228787452803376 + ], + "resp": [ + 2.1440377088333484, + 2.60967253749995 + ] + }, + "mc4Param": { + "pow_a": null, + "pow_p": null, + "exp2_a": null, + "exp2_b": null, + "exp3_a": null, + "exp3_b": null, + "exp3_p": null, + "exp5_p": null, + "gnls_p": null, + "gnls_q": null, + "hill_p": null, + "pow_er": null, + "cnst_er": null, + "exp2_er": null, + "exp3_er": null, + "exp4_er": null, + "exp4_ga": null, + "exp4_tp": null, + "exp5_er": null, + "exp5_ga": null, + "exp5_tp": null, + "gnls_er": null, + "gnls_ga": null, + "gnls_la": null, + "gnls_tp": null, + "hill_er": null, + "hill_ga": null, + "hill_tp": null, + "poly1_a": null, + "poly2_a": null, + "poly2_b": null, + "pow_aic": null, + "pow_cov": null, + "pow_rme": null, + "all_bmed": 0, + "cnst_aic": null, + "cnst_rme": null, + "exp2_aic": null, + "exp2_cov": null, + "exp2_rme": null, + "exp3_aic": null, + "exp3_cov": null, + "exp3_rme": null, + "exp4_aic": null, + "exp4_cov": null, + "exp4_rme": null, + "exp5_aic": null, + "exp5_cov": null, + "exp5_rme": null, + "gnls_aic": null, + "gnls_cov": null, + "gnls_rme": null, + "hill_aic": null, + "hill_cov": null, + "hill_rme": null, + "poly1_er": null, + "poly2_er": null, + "pow_a_sd": null, + "pow_p_sd": null, + "all_onesd": 1.0063376519421736, + "exp2_a_sd": null, + "exp2_b_sd": null, + "exp3_a_sd": null, + "exp3_b_sd": null, + "exp3_p_sd": null, + "exp5_p_sd": null, + "gnls_p_sd": null, + "gnls_q_sd": null, + "hill_p_sd": null, + "poly1_aic": null, + "poly1_cov": null, + "poly1_rme": null, + "poly2_aic": null, + "poly2_cov": null, + "poly2_rme": null, + "pow_er_sd": null, + "exp2_er_sd": null, + "exp3_er_sd": null, + "exp4_er_sd": null, + "exp4_ga_sd": null, + "exp4_tp_sd": null, + "exp5_er_sd": null, + "exp5_ga_sd": null, + "exp5_tp_sd": null, + "gnls_er_sd": null, + "gnls_ga_sd": null, + "gnls_la_sd": null, + "gnls_tp_sd": null, + "hill_er_sd": null, + "hill_ga_sd": null, + "hill_tp_sd": null, + "poly1_a_sd": null, + "poly2_a_sd": null, + "poly2_b_sd": null, + "poly1_er_sd": null, + "poly2_er_sd": null, + "pow_success": null, + "cnst_success": null, + "exp2_success": null, + "exp3_success": null, + "exp4_success": null, + "exp5_success": null, + "gnls_success": null, + "hill_success": null, + "poly1_success": null, + "poly2_success": null + }, + "mc5Param": { + "bmr": 1.3575494924699922, + "hitcall": 0 + }, + "mc6Param": null + }, + { + "aeid": 1390, + "m4id": 906192, + "spid": "TX012530", + "chid": 34192, + "casn": "10161-33-8", + "chnm": "17beta-Trenbolone", + "dtxsid": "DTXSID0034192", + "bmad": 0.9405044150032765, + "respMax": 2.717409684333399, + "respMin": -0.8545140676665994, + "maxMean": 1.3163384146666992, + "maxMeanConc": -1.5228787452803376, + "maxMed": 1.3163384146666992, + "maxMedConc": -1.5228787452803376, + "logcMax": 1.4771212547196624, + "logcMin": -1.5228787452803376, + "nconc": 6, + "npts": 10, + "nrep": 2.0, + "nmedGtbl": 0, + "tmpi": 97, + "m5id": 6384498, + "modl": "poly1", + "hitc": 1.5382110124750505E-5, + "fitc": 13, + "coff": 2.8215132450098297, + "actp": null, + "modelType": 2, + "chidRep": 1, + "stkc": 19.58913043530091, + "stkcUnit": "mM", + "testedConcUnit": "uM", + "mc3Param": { + "logc": [ + -1.5228787452803376, + 1.4771212547196624, + 0.47712125471966244, + -1.5228787452803376, + 0, + 0, + -0.5228787452803376, + -1, + -0.5228787452803376, + -1 + ], + "resp": [ + -0.08473285500000038, + -0.3307718959999999, + 0.2718659670000001, + 2.717409684333399, + -0.7598897116665988, + 0.616657414666701, + 0.9084294140000004, + -0.5178109723332991, + -0.8545140676665994, + -0.15577021666659974 + ] + }, + "mc4Param": { + "pow_a": -0.0000032015551244766303, + "pow_p": 3.3938876456093636, + "exp2_a": -0.0008425672205370199, + "exp2_b": 5.025952810047121, + "exp3_a": -0.3165412302939914, + "exp3_b": 32.7886760846325, + "exp3_p": 3.823113636098184, + "exp5_p": 4.521308309626776, + "gnls_p": 0.7060536922649157, + "gnls_q": 7.995803111831659, + "hill_p": 7.999995740946841, + "pow_er": -0.3948197735362726, + "cnst_er": -0.3688009411915791, + "exp2_er": -0.39189255925874833, + "exp3_er": -0.394828315652932, + "exp4_er": -0.39001576568747853, + "exp4_ga": 94.86188101488622, + "exp4_tp": -1.536218042365886, + "exp5_er": -0.3943079735577426, + "exp5_ga": 38.01553780063972, + "exp5_tp": -1.5637566207089924, + "gnls_er": -0.3888279954274361, + "gnls_ga": 0.008360957321139052, + "gnls_la": 0.26439669331621307, + "gnls_tp": -0.11011944003100936, + "hill_er": -0.3969989913318005, + "hill_ga": 0.05553142030323221, + "hill_tp": -0.14277058589126485, + "poly1_a": -0.010176546872189638, + "poly2_a": -0.00014558397574643742, + "poly2_b": 0.6414632462188614, + "pow_aic": 32.701296578338486, + "pow_cov": 1, + "pow_rme": 1.0134598100344008, + "pow_top": -0.33002326866351944, + "all_bmed": 0, + "cnst_aic": 28.986099667961145, + "cnst_rme": 1.0188398204286804, + "exp2_aic": 32.70205365440622, + "exp2_cov": 1, + "exp2_rme": 1.013472783830085, + "exp2_top": -0.3287033214604972, + "exp3_aic": 34.70116703286695, + "exp3_cov": 1, + "exp3_rme": 1.0134574027805858, + "exp3_top": -0.32852403639508787, + "exp4_aic": 32.74728386838651, + "exp4_cov": 1, + "exp4_rme": 1.0143301743393136, + "exp4_top": -1.536218042365886, + "exp5_aic": 34.70111771210726, + "exp5_cov": 1, + "exp5_rme": 1.0134565513089702, + "exp5_top": -1.5637566207089924, + "gnls_aic": 38.93400660033059, + "gnls_cov": 1, + "gnls_rme": 1.034443341409848, + "gnls_top": -0.09639462099752036, + "hill_aic": 34.71752150835012, + "hill_cov": 1, + "hill_rme": 1.0156361325302317, + "hill_top": -0.14277058589126485, + "poly1_er": -0.3904282715639928, + "poly2_er": -0.3885113969429605, + "pow_a_sd": 0.000007635522959665768, + "pow_ac50": 24.458147755686916, + "pow_p_sd": 0.639975040113934, + "all_onesd": 1.0063376519421736, + "exp2_a_sd": 0.02555615257745943, + "exp2_ac50": 26.529108697337612, + "exp2_b_sd": 25.57941425563839, + "exp3_a_sd": null, + "exp3_ac50": 26.099812908926182, + "exp3_b_sd": null, + "exp3_p_sd": null, + "exp4_ac50": 94.86188101488622, + "exp5_ac50": 38.01553780063972, + "exp5_p_sd": 175.1469903178518, + "gnls_ac50": 0.005863101227685299, + "gnls_p_sd": null, + "gnls_q_sd": null, + "hill_ac50": 0.05553142030323221, + "hill_p_sd": 33.18967248654182, + "poly1_aic": 30.74302350258141, + "poly1_cov": 1, + "poly1_rme": 1.0142482587192818, + "poly1_top": -0.3052964061656891, + "poly2_aic": 32.706800555191634, + "poly2_cov": 1, + "poly2_rme": 1.0135546465438303, + "poly2_top": -0.3252376206529743, + "pow_er_sd": 0.3056178894168387, + "exp2_er_sd": 0.30593434754216753, + "exp3_er_sd": null, + "exp4_er_sd": 0.30493315529014337, + "exp4_ga_sd": 1415.862995217581, + "exp4_tp_sd": 20.95632072022936, + "exp5_er_sd": 0.30568017455861324, + "exp5_ga_sd": 1717.327449801869, + "exp5_tp_sd": 256.65062953004656, + "gnls_er_sd": null, + "gnls_ga_sd": null, + "gnls_la_sd": null, + "gnls_tp_sd": null, + "hill_er_sd": 0.3082074518503941, + "hill_ga_sd": 0.1384923679951287, + "hill_tp_sd": 0.27120396237793026, + "poly1_a_sd": 0.02009033680518044, + "poly1_ac50": 14.999999999999998, + "poly2_a_sd": 0.0044102960138753585, + "poly2_ac50": 21.12046278082584, + "poly2_b_sd": 9.884046203612312, + "poly1_er_sd": 0.30494359178836106, + "poly2_er_sd": 0.306194068294261, + "pow_success": 1, + "cnst_success": 1, + "exp2_success": 1, + "exp3_success": 1, + "exp4_success": 1, + "exp5_success": 1, + "gnls_success": 1, + "hill_success": 1, + "poly1_success": 1, + "poly2_success": 1, + "gnls_ac50_loss": 0.2676524754092505 + }, + "mc5Param": { + "a": -0.010176546872189638, + "er": -0.3904282715639928, + "ac5": 1.4999999999999998, + "bmd": 133.399817199279, + "bmr": 1.3575494924699922, + "mll": -13.371511751290704, + "top": -0.3052964061656891, + "ac10": 2.9999999999999996, + "ac20": 5.999999999999999, + "ac50": 14.999999999999998, + "bmdl": 28.55532213605833, + "rmse": 1.0142482587192818, + "ac1sd": 98.88792972518829, + "caikwt": 0.7065033912112693, + "hitcall": 0.000015382110124750505, + "top_over_cutoff": 0.10820307390214838 + }, + "mc6Param": { + "flag": [ + "Bmd > ac50, indication of high baseline variability" + ], + "mc6MthdId": [ + 9 + ] + } + } +] \ No newline at end of file diff --git a/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-dtxsid/DTXSID7024827.json b/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-dtxsid/DTXSID7024827.json new file mode 100644 index 00000000..021c2671 --- /dev/null +++ b/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-dtxsid/DTXSID7024827.json @@ -0,0 +1,217 @@ +[ + { + "aeid": 1390, + "m4id": 906160, + "spid": "TX007998", + "chid": 24827, + "casn": "69-09-0", + "chnm": "Chlorpromazine hydrochloride", + "dtxsid": "DTXSID7024827", + "bmad": 0.9405044150032765, + "respMax": 1.8515926973332988, + "respMin": -1.4281684306667, + "maxMean": 1.8515926973332988, + "maxMeanConc": 0.47712125471966244, + "maxMed": 1.8515926973332988, + "maxMedConc": 0.47712125471966244, + "logcMax": 1.4771212547196624, + "logcMin": -1.5228787452803376, + "nconc": 7, + "npts": 11, + "nrep": 2.0, + "nmedGtbl": 0, + "tmpi": 65, + "m5id": 6384466, + "modl": "poly1", + "hitc": 0.0024578389852192156, + "fitc": 13, + "coff": 2.8215132450098297, + "actp": null, + "modelType": 2, + "chidRep": 1, + "stkc": 20.0, + "stkcUnit": "mM", + "testedConcUnit": "uM", + "mc3Param": { + "logc": [ + -1.5228787452803376, + 1.4771212547196624, + 1, + 1, + 0, + -0.5228787452803376, + -1, + 0, + -0.5228787452803376, + -1, + 0.47712125471966244 + ], + "resp": [ + -0.9813260029999995, + 1.5374573823333009, + -1.4281684306667, + -0.32735703500000035, + -1.3241634073333994, + -1.0260995583333994, + -1.0514509676666997, + -0.5339457896666993, + 0.12475134633329965, + 0.19027474800000022, + 1.8515926973332988 + ] + }, + "mc4Param": { + "pow_a": -0.12566043650192105, + "pow_p": 0.3000000760970656, + "exp2_a": 0.00005409723692181811, + "exp2_b": 2.926433605638978, + "exp3_a": 0.0860553861034103, + "exp3_b": 25.39417577173585, + "exp3_p": 6.462227914321612, + "exp5_p": 7.999995501143407, + "gnls_p": 7.999999766002532, + "gnls_q": 5.893182343508286, + "hill_p": 7.999977254660707, + "pow_er": -0.02668788798634633, + "cnst_er": -0.00005587395876571964, + "exp2_er": -0.14143509239759122, + "exp3_er": -0.13812042333901542, + "exp4_er": -0.16122837373604454, + "exp4_ga": 0.0030000004459148624, + "exp4_tp": -0.4810580307329651, + "exp5_er": -0.014805216328310444, + "exp5_ga": 2.1980811936727713, + "exp5_tp": 0.531614971877592, + "gnls_er": -0.1375957170803842, + "gnls_ga": 27.127146335911107, + "gnls_la": 2743.9146424667124, + "gnls_tp": 2.2219107252768273, + "hill_er": -0.13751350433218543, + "hill_ga": 27.12725380446655, + "hill_tp": 2.221910837751462, + "poly1_a": 0.034174465728783694, + "poly2_a": 0.00000581387559022372, + "poly2_b": 0.0613437971523207, + "pow_aic": 40.730575914149746, + "pow_cov": 1, + "pow_rme": 1.108005849297976, + "pow_top": -0.34860615663608846, + "all_bmed": 0, + "cnst_aic": 36.88069322285861, + "cnst_rme": 1.0933976567217754, + "exp2_aic": 38.30484249916912, + "exp2_cov": 1, + "exp2_rme": 0.990514101299949, + "exp2_top": 1.5320750752034935, + "exp3_aic": 40.29939443038798, + "exp3_cov": 1, + "exp3_rme": 0.9903013443725064, + "exp3_top": 1.5355429734335535, + "exp4_aic": 38.95205323487634, + "exp4_cov": 1, + "exp4_rme": 1.0804367450037984, + "exp4_top": -0.4810580307329651, + "exp5_aic": 42.41773720168884, + "exp5_cov": 1, + "exp5_rme": 1.0680140469043815, + "exp5_top": 0.531614971877592, + "gnls_aic": 44.30150704437108, + "gnls_cov": 1, + "gnls_rme": 0.9903897984324356, + "gnls_top": 2.221910034969751, + "hill_aic": 40.301507223703744, + "hill_cov": 1, + "hill_rme": 0.9903898000887952, + "hill_top": 2.221910837751462, + "poly1_er": -0.04768893180125318, + "poly2_er": -0.1076996570720005, + "pow_a_sd": null, + "pow_ac50": 2.9763787168112, + "pow_p_sd": null, + "all_onesd": 1.0063376519421736, + "exp2_a_sd": 0.0005773152369056387, + "exp2_ac50": 27.9716541234155, + "exp2_b_sd": 3.052516069810458, + "exp3_a_sd": null, + "exp3_ac50": 28.87725370503856, + "exp3_b_sd": null, + "exp3_p_sd": null, + "exp4_ac50": 0.0030000004459148624, + "exp5_ac50": 2.1980811936727713, + "exp5_p_sd": 27.739007083026586, + "gnls_ac50": 27.127144229078343, + "gnls_p_sd": 29.579967451529043, + "gnls_q_sd": 1225546.386380094, + "hill_ac50": 27.12725380446655, + "hill_p_sd": 29.553198047151273, + "poly1_aic": 37.96640788888903, + "poly1_cov": 1, + "poly1_rme": 1.0561318921086802, + "poly1_top": 1.0252339718635106, + "poly2_aic": 38.922635208397416, + "poly2_cov": 1, + "poly2_rme": 1.0160491957368996, + "poly2_top": 1.3933302600334307, + "pow_er_sd": null, + "exp2_er_sd": 0.2650852722288604, + "exp3_er_sd": null, + "exp4_er_sd": 0.2857915198655576, + "exp4_ga_sd": 0.02653437280711767, + "exp4_tp_sd": 0.3119497794295538, + "exp5_er_sd": 0.25462944166653867, + "exp5_ga_sd": 3.03566950705641, + "exp5_tp_sd": 0.7757908917924725, + "gnls_er_sd": 0.2654683915084613, + "gnls_ga_sd": 84.57292159743136, + "gnls_la_sd": 3264804642.55479, + "gnls_tp_sd": 18.273240826272417, + "hill_er_sd": 0.265475852091525, + "hill_ga_sd": 84.26162495005872, + "hill_tp_sd": 18.20715964440844, + "poly1_a_sd": 0.03019381035149349, + "poly1_ac50": 14.999999999999996, + "poly2_a_sd": 0.000005527708582237654, + "poly2_ac50": 21.204230920194803, + "poly2_b_sd": 0.022513901449174135, + "poly1_er_sd": 0.2597243178031879, + "poly2_er_sd": 0.26562527897815486, + "pow_success": 1, + "cnst_success": 1, + "exp2_success": 1, + "exp3_success": 1, + "exp4_success": 1, + "exp5_success": 1, + "gnls_success": 1, + "hill_success": 1, + "poly1_success": 1, + "poly2_success": 1, + "gnls_ac50_loss": 2743.9149317779675 + }, + "mc5Param": { + "a": 0.034174465728783694, + "er": -0.04768893180125318, + "ac5": 1.4999999999999998, + "bmd": 39.724088248922826, + "bmr": 1.3575494924699922, + "mll": -16.983203944444515, + "top": 1.0252339718635106, + "ac10": 2.9999999999999996, + "ac20": 5.999999999999999, + "ac50": 14.999999999999996, + "bmdl": 16.683323649719604, + "rmse": 1.0561318921086802, + "ac1sd": 29.44706319416073, + "caikwt": 0.6324768555183732, + "hitcall": 0.0024578389852192156, + "top_over_cutoff": 0.3633631611252418 + }, + "mc6Param": { + "flag": [ + "Bmd > ac50, indication of high baseline variability" + ], + "mc6MthdId": [ + 9 + ] + } + } +] diff --git a/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-dtxsid/fakedtxsid.json b/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-dtxsid/fakedtxsid.json new file mode 100644 index 00000000..41b42e67 --- /dev/null +++ b/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-dtxsid/fakedtxsid.json @@ -0,0 +1,3 @@ +[ + +] diff --git a/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-m4id/0.json b/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-m4id/0.json new file mode 100644 index 00000000..41b42e67 --- /dev/null +++ b/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-m4id/0.json @@ -0,0 +1,3 @@ +[ + +] diff --git a/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-m4id/906160.json b/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-m4id/906160.json new file mode 100644 index 00000000..a845c4a4 --- /dev/null +++ b/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-m4id/906160.json @@ -0,0 +1,215 @@ +{ + "aeid": 1390, + "m4id": 906160, + "spid": "TX007998", + "chid": 24827, + "casn": "69-09-0", + "chnm": "Chlorpromazine hydrochloride", + "dtxsid": "DTXSID7024827", + "bmad": 0.9405044150032765, + "respMax": 1.8515926973332988, + "respMin": -1.4281684306667, + "maxMean": 1.8515926973332988, + "maxMeanConc": 0.47712125471966244, + "maxMed": 1.8515926973332988, + "maxMedConc": 0.47712125471966244, + "logcMax": 1.4771212547196624, + "logcMin": -1.5228787452803376, + "nconc": 7, + "npts": 11, + "nrep": 2.0, + "nmedGtbl": 0, + "tmpi": 65, + "m5id": 6384466, + "modl": "poly1", + "hitc": 0.0024578389852192156, + "fitc": 13, + "coff": 2.8215132450098297, + "actp": null, + "modelType": 2, + "chidRep": 1, + "stkc": 20.0, + "stkcUnit": "mM", + "testedConcUnit": "uM", + "mc3Param": { + "logc": [ + -1.5228787452803376, + 1.4771212547196624, + 1, + 1, + 0, + -0.5228787452803376, + -1, + 0, + -0.5228787452803376, + -1, + 0.47712125471966244 + ], + "resp": [ + -0.9813260029999995, + 1.5374573823333009, + -1.4281684306667, + -0.32735703500000035, + -1.3241634073333994, + -1.0260995583333994, + -1.0514509676666997, + -0.5339457896666993, + 0.12475134633329965, + 0.19027474800000022, + 1.8515926973332988 + ] + }, + "mc4Param": { + "pow_a": -0.12566043650192105, + "pow_p": 0.3000000760970656, + "exp2_a": 0.00005409723692181811, + "exp2_b": 2.926433605638978, + "exp3_a": 0.0860553861034103, + "exp3_b": 25.39417577173585, + "exp3_p": 6.462227914321612, + "exp5_p": 7.999995501143407, + "gnls_p": 7.999999766002532, + "gnls_q": 5.893182343508286, + "hill_p": 7.999977254660707, + "pow_er": -0.02668788798634633, + "cnst_er": -0.00005587395876571964, + "exp2_er": -0.14143509239759122, + "exp3_er": -0.13812042333901542, + "exp4_er": -0.16122837373604454, + "exp4_ga": 0.0030000004459148624, + "exp4_tp": -0.4810580307329651, + "exp5_er": -0.014805216328310444, + "exp5_ga": 2.1980811936727713, + "exp5_tp": 0.531614971877592, + "gnls_er": -0.1375957170803842, + "gnls_ga": 27.127146335911107, + "gnls_la": 2743.9146424667124, + "gnls_tp": 2.2219107252768273, + "hill_er": -0.13751350433218543, + "hill_ga": 27.12725380446655, + "hill_tp": 2.221910837751462, + "poly1_a": 0.034174465728783694, + "poly2_a": 0.00000581387559022372, + "poly2_b": 0.0613437971523207, + "pow_aic": 40.730575914149746, + "pow_cov": 1, + "pow_rme": 1.108005849297976, + "pow_top": -0.34860615663608846, + "all_bmed": 0, + "cnst_aic": 36.88069322285861, + "cnst_rme": 1.0933976567217754, + "exp2_aic": 38.30484249916912, + "exp2_cov": 1, + "exp2_rme": 0.990514101299949, + "exp2_top": 1.5320750752034935, + "exp3_aic": 40.29939443038798, + "exp3_cov": 1, + "exp3_rme": 0.9903013443725064, + "exp3_top": 1.5355429734335535, + "exp4_aic": 38.95205323487634, + "exp4_cov": 1, + "exp4_rme": 1.0804367450037984, + "exp4_top": -0.4810580307329651, + "exp5_aic": 42.41773720168884, + "exp5_cov": 1, + "exp5_rme": 1.0680140469043815, + "exp5_top": 0.531614971877592, + "gnls_aic": 44.30150704437108, + "gnls_cov": 1, + "gnls_rme": 0.9903897984324356, + "gnls_top": 2.221910034969751, + "hill_aic": 40.301507223703744, + "hill_cov": 1, + "hill_rme": 0.9903898000887952, + "hill_top": 2.221910837751462, + "poly1_er": -0.04768893180125318, + "poly2_er": -0.1076996570720005, + "pow_a_sd": null, + "pow_ac50": 2.9763787168112, + "pow_p_sd": null, + "all_onesd": 1.0063376519421736, + "exp2_a_sd": 0.0005773152369056387, + "exp2_ac50": 27.9716541234155, + "exp2_b_sd": 3.052516069810458, + "exp3_a_sd": null, + "exp3_ac50": 28.87725370503856, + "exp3_b_sd": null, + "exp3_p_sd": null, + "exp4_ac50": 0.0030000004459148624, + "exp5_ac50": 2.1980811936727713, + "exp5_p_sd": 27.739007083026586, + "gnls_ac50": 27.127144229078343, + "gnls_p_sd": 29.579967451529043, + "gnls_q_sd": 1225546.386380094, + "hill_ac50": 27.12725380446655, + "hill_p_sd": 29.553198047151273, + "poly1_aic": 37.96640788888903, + "poly1_cov": 1, + "poly1_rme": 1.0561318921086802, + "poly1_top": 1.0252339718635106, + "poly2_aic": 38.922635208397416, + "poly2_cov": 1, + "poly2_rme": 1.0160491957368996, + "poly2_top": 1.3933302600334307, + "pow_er_sd": null, + "exp2_er_sd": 0.2650852722288604, + "exp3_er_sd": null, + "exp4_er_sd": 0.2857915198655576, + "exp4_ga_sd": 0.02653437280711767, + "exp4_tp_sd": 0.3119497794295538, + "exp5_er_sd": 0.25462944166653867, + "exp5_ga_sd": 3.03566950705641, + "exp5_tp_sd": 0.7757908917924725, + "gnls_er_sd": 0.2654683915084613, + "gnls_ga_sd": 84.57292159743136, + "gnls_la_sd": 3264804642.55479, + "gnls_tp_sd": 18.273240826272417, + "hill_er_sd": 0.265475852091525, + "hill_ga_sd": 84.26162495005872, + "hill_tp_sd": 18.20715964440844, + "poly1_a_sd": 0.03019381035149349, + "poly1_ac50": 14.999999999999996, + "poly2_a_sd": 0.000005527708582237654, + "poly2_ac50": 21.204230920194803, + "poly2_b_sd": 0.022513901449174135, + "poly1_er_sd": 0.2597243178031879, + "poly2_er_sd": 0.26562527897815486, + "pow_success": 1, + "cnst_success": 1, + "exp2_success": 1, + "exp3_success": 1, + "exp4_success": 1, + "exp5_success": 1, + "gnls_success": 1, + "hill_success": 1, + "poly1_success": 1, + "poly2_success": 1, + "gnls_ac50_loss": 2743.9149317779675 + }, + "mc5Param": { + "a": 0.034174465728783694, + "er": -0.04768893180125318, + "ac5": 1.4999999999999998, + "bmd": 39.724088248922826, + "bmr": 1.3575494924699922, + "mll": -16.983203944444515, + "top": 1.0252339718635106, + "ac10": 2.9999999999999996, + "ac20": 5.999999999999999, + "ac50": 14.999999999999996, + "bmdl": 16.683323649719604, + "rmse": 1.0561318921086802, + "ac1sd": 29.44706319416073, + "caikwt": 0.6324768555183732, + "hitcall": 0.0024578389852192156, + "top_over_cutoff": 0.3633631611252418 + }, + "mc6Param": { + "flag": [ + "Bmd > ac50, indication of high baseline variability" + ], + "mc6MthdId": [ + 9 + ] + } +} diff --git a/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-spid/TX007998.json b/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-spid/TX007998.json new file mode 100644 index 00000000..021c2671 --- /dev/null +++ b/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-spid/TX007998.json @@ -0,0 +1,217 @@ +[ + { + "aeid": 1390, + "m4id": 906160, + "spid": "TX007998", + "chid": 24827, + "casn": "69-09-0", + "chnm": "Chlorpromazine hydrochloride", + "dtxsid": "DTXSID7024827", + "bmad": 0.9405044150032765, + "respMax": 1.8515926973332988, + "respMin": -1.4281684306667, + "maxMean": 1.8515926973332988, + "maxMeanConc": 0.47712125471966244, + "maxMed": 1.8515926973332988, + "maxMedConc": 0.47712125471966244, + "logcMax": 1.4771212547196624, + "logcMin": -1.5228787452803376, + "nconc": 7, + "npts": 11, + "nrep": 2.0, + "nmedGtbl": 0, + "tmpi": 65, + "m5id": 6384466, + "modl": "poly1", + "hitc": 0.0024578389852192156, + "fitc": 13, + "coff": 2.8215132450098297, + "actp": null, + "modelType": 2, + "chidRep": 1, + "stkc": 20.0, + "stkcUnit": "mM", + "testedConcUnit": "uM", + "mc3Param": { + "logc": [ + -1.5228787452803376, + 1.4771212547196624, + 1, + 1, + 0, + -0.5228787452803376, + -1, + 0, + -0.5228787452803376, + -1, + 0.47712125471966244 + ], + "resp": [ + -0.9813260029999995, + 1.5374573823333009, + -1.4281684306667, + -0.32735703500000035, + -1.3241634073333994, + -1.0260995583333994, + -1.0514509676666997, + -0.5339457896666993, + 0.12475134633329965, + 0.19027474800000022, + 1.8515926973332988 + ] + }, + "mc4Param": { + "pow_a": -0.12566043650192105, + "pow_p": 0.3000000760970656, + "exp2_a": 0.00005409723692181811, + "exp2_b": 2.926433605638978, + "exp3_a": 0.0860553861034103, + "exp3_b": 25.39417577173585, + "exp3_p": 6.462227914321612, + "exp5_p": 7.999995501143407, + "gnls_p": 7.999999766002532, + "gnls_q": 5.893182343508286, + "hill_p": 7.999977254660707, + "pow_er": -0.02668788798634633, + "cnst_er": -0.00005587395876571964, + "exp2_er": -0.14143509239759122, + "exp3_er": -0.13812042333901542, + "exp4_er": -0.16122837373604454, + "exp4_ga": 0.0030000004459148624, + "exp4_tp": -0.4810580307329651, + "exp5_er": -0.014805216328310444, + "exp5_ga": 2.1980811936727713, + "exp5_tp": 0.531614971877592, + "gnls_er": -0.1375957170803842, + "gnls_ga": 27.127146335911107, + "gnls_la": 2743.9146424667124, + "gnls_tp": 2.2219107252768273, + "hill_er": -0.13751350433218543, + "hill_ga": 27.12725380446655, + "hill_tp": 2.221910837751462, + "poly1_a": 0.034174465728783694, + "poly2_a": 0.00000581387559022372, + "poly2_b": 0.0613437971523207, + "pow_aic": 40.730575914149746, + "pow_cov": 1, + "pow_rme": 1.108005849297976, + "pow_top": -0.34860615663608846, + "all_bmed": 0, + "cnst_aic": 36.88069322285861, + "cnst_rme": 1.0933976567217754, + "exp2_aic": 38.30484249916912, + "exp2_cov": 1, + "exp2_rme": 0.990514101299949, + "exp2_top": 1.5320750752034935, + "exp3_aic": 40.29939443038798, + "exp3_cov": 1, + "exp3_rme": 0.9903013443725064, + "exp3_top": 1.5355429734335535, + "exp4_aic": 38.95205323487634, + "exp4_cov": 1, + "exp4_rme": 1.0804367450037984, + "exp4_top": -0.4810580307329651, + "exp5_aic": 42.41773720168884, + "exp5_cov": 1, + "exp5_rme": 1.0680140469043815, + "exp5_top": 0.531614971877592, + "gnls_aic": 44.30150704437108, + "gnls_cov": 1, + "gnls_rme": 0.9903897984324356, + "gnls_top": 2.221910034969751, + "hill_aic": 40.301507223703744, + "hill_cov": 1, + "hill_rme": 0.9903898000887952, + "hill_top": 2.221910837751462, + "poly1_er": -0.04768893180125318, + "poly2_er": -0.1076996570720005, + "pow_a_sd": null, + "pow_ac50": 2.9763787168112, + "pow_p_sd": null, + "all_onesd": 1.0063376519421736, + "exp2_a_sd": 0.0005773152369056387, + "exp2_ac50": 27.9716541234155, + "exp2_b_sd": 3.052516069810458, + "exp3_a_sd": null, + "exp3_ac50": 28.87725370503856, + "exp3_b_sd": null, + "exp3_p_sd": null, + "exp4_ac50": 0.0030000004459148624, + "exp5_ac50": 2.1980811936727713, + "exp5_p_sd": 27.739007083026586, + "gnls_ac50": 27.127144229078343, + "gnls_p_sd": 29.579967451529043, + "gnls_q_sd": 1225546.386380094, + "hill_ac50": 27.12725380446655, + "hill_p_sd": 29.553198047151273, + "poly1_aic": 37.96640788888903, + "poly1_cov": 1, + "poly1_rme": 1.0561318921086802, + "poly1_top": 1.0252339718635106, + "poly2_aic": 38.922635208397416, + "poly2_cov": 1, + "poly2_rme": 1.0160491957368996, + "poly2_top": 1.3933302600334307, + "pow_er_sd": null, + "exp2_er_sd": 0.2650852722288604, + "exp3_er_sd": null, + "exp4_er_sd": 0.2857915198655576, + "exp4_ga_sd": 0.02653437280711767, + "exp4_tp_sd": 0.3119497794295538, + "exp5_er_sd": 0.25462944166653867, + "exp5_ga_sd": 3.03566950705641, + "exp5_tp_sd": 0.7757908917924725, + "gnls_er_sd": 0.2654683915084613, + "gnls_ga_sd": 84.57292159743136, + "gnls_la_sd": 3264804642.55479, + "gnls_tp_sd": 18.273240826272417, + "hill_er_sd": 0.265475852091525, + "hill_ga_sd": 84.26162495005872, + "hill_tp_sd": 18.20715964440844, + "poly1_a_sd": 0.03019381035149349, + "poly1_ac50": 14.999999999999996, + "poly2_a_sd": 0.000005527708582237654, + "poly2_ac50": 21.204230920194803, + "poly2_b_sd": 0.022513901449174135, + "poly1_er_sd": 0.2597243178031879, + "poly2_er_sd": 0.26562527897815486, + "pow_success": 1, + "cnst_success": 1, + "exp2_success": 1, + "exp3_success": 1, + "exp4_success": 1, + "exp5_success": 1, + "gnls_success": 1, + "hill_success": 1, + "poly1_success": 1, + "poly2_success": 1, + "gnls_ac50_loss": 2743.9149317779675 + }, + "mc5Param": { + "a": 0.034174465728783694, + "er": -0.04768893180125318, + "ac5": 1.4999999999999998, + "bmd": 39.724088248922826, + "bmr": 1.3575494924699922, + "mll": -16.983203944444515, + "top": 1.0252339718635106, + "ac10": 2.9999999999999996, + "ac20": 5.999999999999999, + "ac50": 14.999999999999996, + "bmdl": 16.683323649719604, + "rmse": 1.0561318921086802, + "ac1sd": 29.44706319416073, + "caikwt": 0.6324768555183732, + "hitcall": 0.0024578389852192156, + "top_over_cutoff": 0.3633631611252418 + }, + "mc6Param": { + "flag": [ + "Bmd > ac50, indication of high baseline variability" + ], + "mc6MthdId": [ + 9 + ] + } + } +] diff --git a/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-spid/fakespid.json b/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-spid/fakespid.json new file mode 100644 index 00000000..41b42e67 --- /dev/null +++ b/tests/testthat/ctx/api-ccte.epa.gov/bioactivity/data/search/by-spid/fakespid.json @@ -0,0 +1,3 @@ +[ + +] diff --git a/tests/testthat/test-tcplConf.R b/tests/testthat/test-tcplConf.R index 966c1b4f..18e8eefa 100644 --- a/tests/testthat/test-tcplConf.R +++ b/tests/testthat/test-tcplConf.R @@ -1,13 +1,29 @@ test_that("example=driver updates option TCPL_DRVR", { - tcplConf(drvr = "example") - expect_equal("example", - getOption("TCPL_DRVR")) + drvr <- "example" + tcplConf(drvr) + expect_equal(getOption("TCPL_DRVR"), + drvr) }) test_that("unsupported driver error message", { drvr <- "test" expect_error( tcplConf(drvr), - paste0(drvr," is not a supported database driver. Must be 'MySQL', 'tcplLite', or 'example'.") + paste0(drvr," is not a supported database driver. Must be 'MySQL', 'tcplLite', 'API' or 'example'.") ) +}) + +test_that("API driver no key error message", { + drvr <- "API" + expect_error( + tcplConf(drvr), + "'API' driver requires an API-key, supply it to the 'pass' parameter. To request a key, send an email to ccte_api@epa.gov." + ) +}) + +test_that("API driver properly sets URL", { + tcplConf(drvr = "API", pass = "api_key") + expect_equal(getOption("TCPL_HOST"), + "https://api-ccte.epa.gov/bioactivity" + ) }) \ No newline at end of file diff --git a/tests/testthat/test-tcplLoadAcid.R b/tests/testthat/test-tcplLoadAcid.R new file mode 100644 index 00000000..254a6a8f --- /dev/null +++ b/tests/testthat/test-tcplLoadAcid.R @@ -0,0 +1,37 @@ +#------------------------------------------------------------------------------- +# Covers testing tcplLoadAcid with "API" driver +# Using httptest mocking to automatically save json responses from http requests +# NOTE -- updates to the CTX API may mean stored json files are out of date. In +# this case, delete the 'ctx' folder and follow the instructions in the test- +# tcplLoadData test file. +#------------------------------------------------------------------------------- +httptest::with_mock_dir("ctx", { + apikey <- "apikey" + tcplConf(pass = apikey, + drvr = "API") + data(test_api) + assays <- tcplQueryAPI(resource = "assay") + test_that("tcplLoadAcid works by aeid", { + expect_no_error(dat <- tcplLoadAcid(fld = "aeid", val = test_api$aeid)) + expect_true(is.data.table(dat)) + expect_equal(nrow(dat), 1) + expect_true(all(c("aeid", "acid", "acnm") %in% colnames(dat))) + expect_equal(dat$acid, test_api$acid) + }) + test_that("tcplLoadAcid works by non-id", { + expect_no_error(dat <- tcplLoadAcid(fld = c("intended_target_type", "detection_technology_type"), val = list(assays$intended_target_type[1], assays$detection_technology_type[1]))) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("intended_target_type", "detection_technology_type", "acid", "acnm") %in% colnames(dat))) + expect_equal(unique(dat$intended_target_type), assays$intended_target_type[1]) + expect_equal(unique(dat$detection_technology_type), assays$detection_technology_type[1]) + }) + #error cases + test_that("data not found results in null data.table", { + expect_no_error(dat <- tcplLoadAcid(fld = "aeid", val = 0)) + expect_equal(nrow(dat), 0) + }) + test_that("invalid field results in error", { + expect_error(dat <- tcplLoadAcid(fld = "awid", val = 0), "Query field\\(s\\) 'awid' not available. Try using from the following:*") + }) +}) \ No newline at end of file diff --git a/tests/testthat/test-tcplLoadAeid.R b/tests/testthat/test-tcplLoadAeid.R new file mode 100644 index 00000000..1a4e0573 --- /dev/null +++ b/tests/testthat/test-tcplLoadAeid.R @@ -0,0 +1,37 @@ +#------------------------------------------------------------------------------- +# Covers testing tcplLoadAeid with "API" driver +# Using httptest mocking to automatically save json responses from http requests +# NOTE -- updates to the CTX API may mean stored json files are out of date. In +# this case, delete the 'ctx' folder and follow the instructions in the test- +# tcplLoadData test file. +#------------------------------------------------------------------------------- +httptest::with_mock_dir("ctx", { + apikey <- "apikey" + tcplConf(pass = apikey, + drvr = "API") + data(test_api) + assays <- tcplQueryAPI(resource = "assay") + test_that("tcplLoadAeid works by acid", { + expect_no_error(dat <- tcplLoadAeid(fld = "acid", val = test_api$acid)) + expect_true(is.data.table(dat)) + expect_equal(nrow(dat), 1) + expect_true(all(c("acid", "aeid", "aenm") %in% colnames(dat))) + expect_equal(dat$aeid, test_api$aeid) + }) + test_that("tcplLoadAeid works by non-id", { + expect_no_error(dat <- tcplLoadAeid(fld = c("intended_target_type", "detection_technology_type"), val = list(assays$intended_target_type[1], assays$detection_technology_type[1]))) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("intended_target_type", "detection_technology_type", "aeid", "aenm") %in% colnames(dat))) + expect_equal(unique(dat$intended_target_type), assays$intended_target_type[1]) + expect_equal(unique(dat$detection_technology_type), assays$detection_technology_type[1]) + }) + #error cases + test_that("data not found results in null data.table", { + expect_no_error(dat <- tcplLoadAeid(fld = "acid", val = 0)) + expect_equal(nrow(dat), 0) + }) + test_that("invalid field results in error", { + expect_error(dat <- tcplLoadAeid(fld = "awid", val = 0), "Query field\\(s\\) 'awid' not available. Try using from the following:*") + }) +}) \ No newline at end of file diff --git a/tests/testthat/test-tcplLoadAid.R b/tests/testthat/test-tcplLoadAid.R new file mode 100644 index 00000000..49006709 --- /dev/null +++ b/tests/testthat/test-tcplLoadAid.R @@ -0,0 +1,37 @@ +#------------------------------------------------------------------------------- +# Covers testing tcplLoadAid with "API" driver +# Using httptest mocking to automatically save json responses from http requests +# NOTE -- updates to the CTX API may mean stored json files are out of date. In +# this case, delete the 'ctx' folder and follow the instructions in the test- +# tcplLoadData test file. +#------------------------------------------------------------------------------- +httptest::with_mock_dir("ctx", { + apikey <- "apikey" + tcplConf(pass = apikey, + drvr = "API") + data(test_api) + assays <- tcplQueryAPI(resource = "assay") + test_that("tcplLoadAid works by aeid", { + expect_no_error(dat <- tcplLoadAid(fld = "aeid", val = test_api$aeid)) + expect_true(is.data.table(dat)) + expect_equal(nrow(dat), 1) + expect_true(all(c("aeid", "aid", "anm") %in% colnames(dat))) + expect_equal(dat$aid, test_api$aid) + }) + test_that("tcplLoadAid works by non-id", { + expect_no_error(dat <- tcplLoadAid(fld = c("intended_target_type", "detection_technology_type"), val = list(assays$intended_target_type[1], assays$detection_technology_type[1]))) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("intended_target_type", "detection_technology_type", "aid", "anm") %in% colnames(dat))) + expect_equal(unique(dat$intended_target_type), assays$intended_target_type[1]) + expect_equal(unique(dat$detection_technology_type), assays$detection_technology_type[1]) + }) + #error cases + test_that("data not found results in null data.table", { + expect_no_error(dat <- tcplLoadAid(fld = "aeid", val = 0)) + expect_equal(nrow(dat), 0) + }) + test_that("invalid field results in error", { + expect_error(dat <- tcplLoadAid(fld = "awid", val = 0), "Query field\\(s\\) 'awid' not available. Try using from the following:*") + }) +}) \ No newline at end of file diff --git a/tests/testthat/test-tcplLoadAsid.R b/tests/testthat/test-tcplLoadAsid.R new file mode 100644 index 00000000..4312dc16 --- /dev/null +++ b/tests/testthat/test-tcplLoadAsid.R @@ -0,0 +1,37 @@ +#------------------------------------------------------------------------------- +# Covers testing tcplLoadAsid with "API" driver +# Using httptest mocking to automatically save json responses from http requests +# NOTE -- updates to the CTX API may mean stored json files are out of date. In +# this case, delete the 'ctx' folder and follow the instructions in the test- +# tcplLoadData test file. +#------------------------------------------------------------------------------- +httptest::with_mock_dir("ctx", { + apikey <- "apikey" + tcplConf(pass = apikey, + drvr = "API") + data(test_api) + assays <- tcplQueryAPI(resource = "assay") + test_that("tcplLoadAsid works by aeid", { + expect_no_error(dat <- tcplLoadAsid(fld = "aeid", val = test_api$aeid)) + expect_true(is.data.table(dat)) + expect_equal(nrow(dat), 1) + expect_true(all(c("aeid", "asid", "asnm") %in% colnames(dat))) + expect_equal(dat$asid, test_api$asid) + }) + test_that("tcplLoadAsid works by non-id", { + expect_no_error(dat <- tcplLoadAsid(fld = c("intended_target_type", "detection_technology_type"), val = list(assays$intended_target_type[1], assays$detection_technology_type[1]))) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("intended_target_type", "detection_technology_type", "asid", "asnm") %in% colnames(dat))) + expect_equal(unique(dat$intended_target_type), assays$intended_target_type[1]) + expect_equal(unique(dat$detection_technology_type), assays$detection_technology_type[1]) + }) + #error cases + test_that("data not found results in null data.table", { + expect_no_error(dat <- tcplLoadAsid(fld = "aeid", val = 0)) + expect_equal(nrow(dat), 0) + }) + test_that("invalid field results in error", { + expect_error(dat <- tcplLoadAsid(fld = "awid", val = 0), "Query field\\(s\\) 'awid' not available. Try using from the following:*") + }) +}) \ No newline at end of file diff --git a/tests/testthat/test-tcplLoadChem.R b/tests/testthat/test-tcplLoadChem.R new file mode 100644 index 00000000..fa2c9e10 --- /dev/null +++ b/tests/testthat/test-tcplLoadChem.R @@ -0,0 +1,37 @@ +#------------------------------------------------------------------------------- +# Covers testing tcplLoadChem with "API" driver +# Using httptest mocking to automatically save json responses from http requests +# NOTE -- updates to the CTX API may mean stored json files are out of date. In +# this case, delete the 'ctx' folder and follow the instructions in the test- +# tcplLoadData test file. +#------------------------------------------------------------------------------- +httptest::with_mock_dir("ctx", { + apikey <- "apikey" + tcplConf(pass = apikey, + drvr = "API") + data(test_api) + assays <- tcplQueryAPI(resource = "assay") + test_that("tcplLoadChem works by spid", { + expect_no_error(dat <- tcplLoadChem(field = "spid", val = test_api$spid)) + expect_true(is.data.table(dat)) + expect_equal(nrow(dat), 1) + expect_true(all(c("spid", "chid", "casn", "chnm", "dsstox_substance_id", "code") %in% colnames(dat))) + expect_equal(dat$spid, test_api$spid) + }) + test_that("exact is silently changed to TRUE if driver is API", { + expect_no_error(dat <- tcplLoadChem(field = "spid", val = test_api$spid, exact = FALSE)) + expect_true(is.data.table(dat)) + expect_equal(nrow(dat), 1) + expect_true(all(c("spid", "chid", "casn", "chnm", "dsstox_substance_id", "code") %in% colnames(dat))) + expect_equal(dat$spid, test_api$spid) + }) + #error cases + test_that("field can only be spid if driver is API", { + expect_error(tcplLoadChem(field = "chnm", val = "fakechnm"), "When drvr option is set to 'API', only 'spid' is a valid 'field' value.") + }) + test_that("data not found results in null data.table", { + expect_warning(dat <- tcplLoadChem(field = "spid", val = "fakespid"), "Data not found for the following 'fld' and 'val' combos: +SPID: fakespid") + expect_equal(nrow(dat), 0) + }) +}) \ No newline at end of file diff --git a/tests/testthat/test-tcplLoadConcUnit.R b/tests/testthat/test-tcplLoadConcUnit.R new file mode 100644 index 00000000..404edb82 --- /dev/null +++ b/tests/testthat/test-tcplLoadConcUnit.R @@ -0,0 +1,26 @@ +#------------------------------------------------------------------------------- +# Covers testing tcplLoadConcUnit with "API" driver +# Using httptest mocking to automatically save json responses from http requests +# NOTE -- updates to the CTX API may mean stored json files are out of date. In +# this case, delete the 'ctx' folder and follow the instructions in the test- +# tcplLoadData test file. +#------------------------------------------------------------------------------- +httptest::with_mock_dir("ctx", { + apikey <- "apikey" + tcplConf(pass = apikey, + drvr = "API") + data(test_api) + test_that("tcplLoadConcUnit works by spid", { + expect_no_error(dat <- tcplLoadConcUnit(spid = test_api$spid)) + expect_true(is.data.table(dat)) + expect_equal(nrow(dat), 1) + expect_true(all(c("spid", "conc_unit") %in% colnames(dat))) + expect_equal(dat$spid, test_api$spid) + }) + #error cases + test_that("data not found results in null data.table", { + expect_warning(dat <- tcplLoadConcUnit(spid = "fakespid"), "Data not found for the following 'fld' and 'val' combos: +SPID: fakespid") + expect_equal(nrow(dat), 0) + }) +}) \ No newline at end of file diff --git a/tests/testthat/test-tcplLoadData.R b/tests/testthat/test-tcplLoadData.R index c1d673a5..6565e3d0 100644 --- a/tests/testthat/test-tcplLoadData.R +++ b/tests/testthat/test-tcplLoadData.R @@ -156,6 +156,701 @@ test_that("mc example error message appears", { ) }) -# test_that("description", { -# expect_*(code) -# }) \ No newline at end of file + +#------------------------------------------------------------------------------- +# Covers testing tcplLoadData with "MySQL" driver +# new method using mocking for tcplQuery function +#------------------------------------------------------------------------------- + +# SC0 +test_that("tcplLoadData loads sc0 data for one s0id", { + data("sc_test") + mocked <- sc_test$sc0_by_s0id + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(type = "sc", lvl = 0, fld = "s0id", val = mocked$s0id) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("s0id", "acid", "spid", "wllt", "wllq", "conc", "rval") %in% colnames(dat))) + expect_true(mocked$s0id %in% dat$s0id) +}) + +test_that("tcplLoadData loads sc0 data for one acid", { + data("sc_test") + mocked <- sc_test$sc0_by_acid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(type = "sc", lvl = 0, fld = "acid", val = mocked$acid) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("s0id", "acid", "spid", "wllt", "wllq", "conc", "rval") %in% colnames(dat))) + expect_true(mocked$acid %in% dat$acid) +}) + +# SC1 +test_that("tcplLoadData loads sc1 data for one s1id", { + data("sc_test") + mocked <- sc_test$sc1_by_s1id + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(type = "sc", lvl = 1, fld = "s1id", val = mocked$s1id) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("s0id", "s1id", "acid", "aeid", "spid", "wllt", "wllq", "conc", "resp") %in% colnames(dat))) + expect_true(mocked$s1id %in% dat$s1id) +}) + +test_that("tcplLoadData loads sc1 data for one acid", { + data("sc_test") + mocked <- sc_test$sc1_by_acid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(type = "sc", lvl = 1, fld = "acid", val = mocked$acid) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("s0id", "s1id", "acid", "aeid", "spid", "wllt", "wllq", "conc", "resp") %in% colnames(dat))) + expect_true(mocked$acid %in% dat$acid) +}) + +# SC2 +test_that("tcplLoadData loads sc2 data for one s2id", { + data("sc_test") + mocked <- sc_test$sc2_by_s2id + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(type = "sc", lvl = 2, fld = "s2id", val = mocked$s2id) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("s2id", "aeid", "spid", "bmad", "max_med", "coff", "hitc") %in% colnames(dat))) + expect_true(mocked$s2id %in% dat$s2id) +}) + +test_that("tcplLoadData loads sc2 data for one aeid", { + data("sc_test") + mocked <- sc_test$sc2_by_aeid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(type = "sc", lvl = 2, fld = "aeid", val = mocked$aeid) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("s2id", "aeid", "spid", "bmad", "max_med", "coff", "hitc") %in% colnames(dat))) + expect_true(mocked$aeid %in% dat$aeid) +}) + +# SCagg +test_that("tcplLoadData loads sc 'agg' data for one aeid", { + data("sc_test") + mocked <- sc_test$scagg_by_aeid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(type = "sc", lvl = "agg", fld = "aeid", val = mocked$aeid) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("s0id", "s1id", "s2id", "acid", "aeid", "conc", "resp") %in% colnames(dat))) + expect_true(mocked$aeid %in% dat$aeid) +}) + +# MC0 +test_that("tcplLoadData loads mc0 data for one m0id", { + data("mc_test") + mocked <- mc_test$mc0_by_m0id + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(lvl = 0, fld = "m0id", val = mocked$m0id) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m0id", "acid", "spid", "wllt", "wllq", "conc", "rval") %in% colnames(dat))) + expect_true(mocked$m0id %in% dat$m0id) +}) + +test_that("tcplLoadData loads mc0 data for one acid", { + data("mc_test") + mocked <- mc_test$mc0_by_acid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(lvl = 0, fld = "acid", val = mocked$acid) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m0id", "acid", "spid", "wllt", "wllq", "conc", "rval") %in% colnames(dat))) + expect_true(mocked$acid %in% dat$acid) +}) + +# MC1 +test_that("tcplLoadData loads mc1 data for one m1id", { + data("mc_test") + mocked <- mc_test$mc1_by_m1id + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(lvl = 1, fld = "m1id", val = mocked$m1id) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m0id", "m1id", "acid", "spid", "wllt", "wllq", "conc", "rval") %in% colnames(dat))) + expect_true(mocked$m1id %in% dat$m1id) +}) + +test_that("tcplLoadData loads mc1 data for one acid", { + data("mc_test") + mocked <- mc_test$mc1_by_acid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(lvl = 1, fld = "acid", val = mocked$acid) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m0id", "m1id", "acid", "spid", "wllt", "wllq", "conc", "rval") %in% colnames(dat))) + expect_true(mocked$acid %in% dat$acid) +}) + +# MC2 +test_that("tcplLoadData loads mc2 data for one m2id", { + data("mc_test") + mocked <- mc_test$mc2_by_m2id + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(lvl = 2, fld = "m2id", val = mocked$m2id) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m0id", "m1id", "m2id", "acid", "spid", "wllt", "wllq", "conc", "rval", "cval") %in% colnames(dat))) + expect_true(mocked$m2id %in% dat$m2id) +}) + +test_that("tcplLoadData loads mc2 data for one acid", { + data("mc_test") + mocked <- mc_test$mc2_by_acid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(lvl = 2, fld = "acid", val = mocked$acid) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m0id", "m1id", "m2id", "acid", "spid", "wllt", "wllq", "conc", "rval", "cval") %in% colnames(dat))) + expect_true(mocked$acid %in% dat$acid) +}) + +# MC3 +test_that("tcplLoadData loads mc3 data for one m3id", { + data("mc_test") + mocked <- mc_test$mc3_by_m3id + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(lvl = 3, fld = "m3id", val = mocked$m3id) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m0id", "m1id", "m2id", "m3id", "acid", "aeid", "spid", "wllt", "wllq", "conc", "rval", "resp") %in% colnames(dat))) + expect_true(mocked$m3id %in% dat$m3id) +}) + +test_that("tcplLoadData loads mc3 data for one aeid", { + data("mc_test") + mocked <- mc_test$mc3_by_aeid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(lvl = 3, fld = "aeid", val = mocked$aeid) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m0id", "m1id", "m2id", "m3id", "acid", "aeid", "spid", "wllt", "wllq", "conc", "rval", "resp") %in% colnames(dat))) + expect_true(mocked$aeid %in% dat$aeid) +}) + +# MC4 +test_that("tcplLoadData loads mc4 data for one m4id", { + data("mc_test") + mocked <- mc_test$mc4_by_m4id + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(lvl = 4, fld = "m4id", val = mocked$m4id) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m4id", "aeid", "spid", "bmad", "nconc", "nrep", "cnst_aic") %in% colnames(dat))) + expect_true(mocked$m4id %in% dat$m4id) +}) + +test_that("tcplLoadData loads mc4 data for one aeid with add.fld = FALSE", { + data("mc_test") + mocked <- mc_test$mc4_by_aeid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(lvl = 4, fld = "aeid", val = mocked$aeid, add.fld = FALSE) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m4id", "aeid", "spid", "bmad", "nconc", "nrep") %in% colnames(dat))) + expect_true(mocked$aeid %in% dat$aeid) +}) + +# MC5 +test_that("tcplLoadData loads mc5 data for one m5id", { + data("mc_test") + mocked <- mc_test$mc5_by_m5id + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(lvl = 5, fld = "m5id", val = mocked$m5id) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m4id", "m5id", "aeid", "spid", "bmad", "nconc", "nrep", "modl", "hitc", "coff", "top") %in% colnames(dat))) + expect_true(mocked$m5id %in% dat$m5id) +}) + +test_that("tcplLoadData loads mc5 data for one aeid with add.fld = FALSE", { + data("mc_test") + mocked <- mc_test$mc5_by_aeid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(lvl = 5, fld = "aeid", val = mocked$aeid, add.fld = FALSE) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m4id", "m5id", "aeid", "spid", "bmad", "nconc", "nrep", "modl", "hitc", "coff") %in% colnames(dat))) + expect_true(mocked$aeid %in% dat$aeid) +}) + +# MC6 +test_that("tcplLoadData loads mc6 data for one m6id", { + data("mc_test") + mocked <- mc_test$mc6_by_m6id + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(lvl = 6, fld = "m6id", val = mocked$m6id) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m4id", "m5id", "m6id", "aeid", "spid", "bmad", "nconc", "nrep", "flag") %in% colnames(dat))) + expect_true(mocked$m6id %in% dat$m6id) +}) + +test_that("tcplLoadData loads mc6 data for one aeid", { + data("mc_test") + mocked <- mc_test$mc6_by_aeid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(lvl = 6, fld = "aeid", val = mocked$aeid) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m4id", "m5id", "m6id", "aeid", "spid", "bmad", "nconc", "nrep", "flag") %in% colnames(dat))) + expect_true(mocked$aeid %in% dat$aeid) +}) + +# MC7 +test_that("tcplLoadData loads mc7 data for one m7id", { + data("mc_test") + mocked <- mc_test$mc7_by_m7id + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(lvl = 7, fld = "m7id", val = mocked$m7id) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m4id", "m7id", "aeid", "spid", "bmad", "nconc", "nrep", "aed_val") %in% colnames(dat))) + expect_true(mocked$m7id %in% dat$m7id) +}) + +test_that("tcplLoadData loads mc7 data for one aeid", { + data("mc_test") + mocked <- mc_test$mc7_by_aeid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(lvl = 7, fld = "aeid", val = mocked$aeid) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m4id", "m7id", "aeid", "spid", "bmad", "nconc", "nrep", "aed_val") %in% colnames(dat))) + expect_true(mocked$aeid %in% dat$aeid) +}) + +# MCagg +test_that("tcplLoadData loads mc 'agg' data for one aeid", { + data("mc_test") + mocked <- mc_test$mcagg_by_aeid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplLoadData(lvl = "agg", fld = "aeid", val = mocked$aeid) + #expectations + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m0id", "m1id", "m2id", "m3id", "m4id", "acid", "aeid", "spid", + "conc", "resp", "bmad", "nconc", "nrep") %in% colnames(dat))) + expect_true(mocked$aeid %in% dat$aeid) +}) + +# error cases +test_that("invalid lvl and type error message", { + data("mc_test") + mocked <- mc_test$mcagg_by_aeid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_error( + tcplLoadData(lvl = 5, type = "sc"), + "Invalid 'lvl' and 'type' combination." + ) +}) + +test_that("missing val error message", { + data("mc_test") + mocked <- mc_test$mcagg_by_aeid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_error( + tcplLoadData(lvl = 5, type = "mc", fld = "aeid"), + "'val' cannot be NULL check that a valid value was provided for the specified field" + ) +}) + + +#------------------------------------------------------------------------------- +# Covers testing tcplLoadData with "API" driver +# Using httptest mocking to automatically save json responses from http requests +# NOTE -- updates to the CTX API may mean stored json files are out of date. In +# this case, delete the 'ctx' folder and rerun this ENTIRE test file (temporarily +# replacing the 'apikey' string with a valid key) to repopulate the stored +# .jsons. These will likely be huge and will need to be edited by hand to reduce +# their sizes. To do this, open the file(s) and remove all but one element of +# the outer array -- we don't need more than one endpoint-sample. When editing +# down the files, it is recommended to make sure the same aeid is present in each +# selected endpoint-sample, or assay for the saved assay.json response, to make +# sure every test has its necessary data still available. +#------------------------------------------------------------------------------- +httptest::with_mock_dir("ctx", { + apikey <- "apikey" + tcplConf(pass = apikey, + drvr = "API") + data(test_api) + test_that("level 3 API data loads by m4id", { + expect_no_error(dat <- tcplLoadData(lvl = 3, fld = "m4id", val = test_api$m4id, add.fld = FALSE)) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 1) + expect_true(all(c("m4id", "spid", "conc", "aeid") %in% colnames(dat))) + expect_true(test_api$m4id %in% dat$m4id) + }) + test_that("level 3 API data loads by aeid", { + expect_no_error(dat <- tcplLoadData(lvl = 3, fld = "aeid", val = test_api$aeid, add.fld = FALSE)) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 1) + expect_true(all(c("aeid", "spid", "conc") %in% colnames(dat))) + expect_true(test_api$aeid %in% dat$aeid) + }) + test_that("level 3 API data loads by dtxsid", { + expect_no_error(dat <- tcplLoadData(lvl = 3, fld = "dtxsid", val = test_api$dtxsid, add.fld = FALSE)) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 1) + expect_true(all(c("dtxsid", "spid", "conc", "aeid") %in% colnames(dat))) + expect_true(test_api$dtxsid %in% dat$dtxsid) + }) + test_that("level 3 API data loads by spid", { + expect_no_error(dat <- tcplLoadData(lvl = 3, fld = "spid", val = test_api$spid, add.fld = FALSE)) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 1) + expect_true(all(c("aeid", "spid", "conc") %in% colnames(dat))) + expect_true(test_api$spid %in% dat$spid) + }) + test_that("level 4 API data loads by m4id", { + expect_no_error(dat <- tcplLoadData(lvl = 4, fld = "m4id", val = test_api$m4id, add.fld = FALSE)) + expect_true(is.data.table(dat)) + expect_equal(nrow(dat), 1) + expect_true(all(c("m4id", "aeid", "bmad", "spid", "max_med", "nconc", "nrep") %in% colnames(dat))) + expect_true(test_api$m4id %in% dat$m4id) + }) + test_that("level 4 API data loads by aeid", { + expect_no_error(dat <- tcplLoadData(lvl = 4, fld = "aeid", val = test_api$aeid, add.fld = FALSE)) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m4id", "aeid", "spid", "bmad", "max_med", "nconc", "nrep") %in% colnames(dat))) + expect_true(test_api$aeid %in% dat$aeid) + }) + test_that("level 4 API data loads by dtxsid", { + expect_no_error(dat <- tcplLoadData(lvl = 4, fld = "dtxsid", val = test_api$dtxsid, add.fld = FALSE)) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("dtxsid", "spid", "m4id", "aeid", "bmad", "max_med", "nconc", "nrep") %in% colnames(dat))) + expect_true(test_api$dtxsid %in% dat$dtxsid) + }) + test_that("level 4 API data loads by spid", { + expect_no_error(dat <- tcplLoadData(lvl = 4, fld = "spid", val = test_api$spid, add.fld = FALSE)) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("spid", "m4id", "aeid", "bmad", "max_med", "nconc", "nrep") %in% colnames(dat))) + expect_true(test_api$spid %in% dat$spid) + }) + test_that("level 5 API data loads by m4id", { + expect_no_error(dat <- tcplLoadData(lvl = 5, fld = "m4id", val = test_api$m4id, add.fld = FALSE)) + expect_true(is.data.table(dat)) + expect_equal(nrow(dat), 1) + expect_true(all(c("m4id", "m5id", "aeid", "spid", "bmad", "max_med", "nconc", "nrep", "modl", "hitc", "coff", "model_type") %in% colnames(dat))) + expect_true(test_api$m4id %in% dat$m4id) + }) + test_that("level 5 API data loads by aeid", { + expect_no_error(dat <- tcplLoadData(lvl = 5, fld = "aeid", val = test_api$aeid, add.fld = FALSE)) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m4id", "m5id", "aeid", "spid", "bmad", "max_med", "nconc", "nrep", "modl", "hitc", "coff", "model_type") %in% colnames(dat))) + expect_true(test_api$aeid %in% dat$aeid) + }) + test_that("level 5 API data loads by dtxsid", { + expect_no_error(dat <- tcplLoadData(lvl = 5, fld = "dtxsid", val = test_api$dtxsid, add.fld = FALSE)) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("dtxsid", "m4id", "m5id", "aeid", "spid", "bmad", "max_med", "nconc", "nrep", "modl", "hitc", "coff", "model_type") %in% colnames(dat))) + expect_true(test_api$dtxsid %in% dat$dtxsid) + }) + test_that("level 5 API data loads by spid", { + expect_no_error(dat <- tcplLoadData(lvl = 5, fld = "spid", val = test_api$spid, add.fld = FALSE)) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m4id", "m5id", "aeid", "spid", "bmad", "max_med", "nconc", "nrep", "modl", "hitc", "coff", "model_type") %in% colnames(dat))) + expect_true(test_api$spid %in% dat$spid) + }) + test_that("level 6 API data loads by m4id", { + expect_no_error(dat <- tcplLoadData(lvl = 6, fld = "m4id", val = test_api$m4id, add.fld = FALSE)) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m4id", "m5id", "aeid", "spid", "bmad", "max_med", "nconc", "nrep", "flag") %in% colnames(dat))) + expect_true(test_api$m4id %in% dat$m4id) + }) + test_that("level 6 API data loads by aeid", { + expect_no_error(dat <- tcplLoadData(lvl = 6, fld = "aeid", val = test_api$aeid, add.fld = FALSE)) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m4id", "m5id", "aeid", "spid", "bmad", "max_med", "nconc", "nrep", "flag") %in% colnames(dat))) + expect_true(test_api$aeid %in% dat$aeid) + }) + test_that("level 6 API data loads by dtxsid", { + expect_no_error(dat <- tcplLoadData(lvl = 6, fld = "dtxsid", val = test_api$dtxsid, add.fld = FALSE)) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("dtxsid", "m4id", "m5id", "aeid", "spid", "bmad", "max_med", "nconc", "nrep", "flag") %in% colnames(dat))) + expect_true(test_api$dtxsid %in% dat$dtxsid) + }) + test_that("level 6 API data loads by spid", { + expect_no_error(dat <- tcplLoadData(lvl = 6, fld = "spid", val = test_api$spid, add.fld = FALSE)) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("m4id", "m5id", "aeid", "spid", "bmad", "max_med", "nconc", "nrep", "flag") %in% colnames(dat))) + expect_true(test_api$spid %in% dat$spid) + }) + test_that("agg level API data loads by m4id", { + expect_no_error(dat <- tcplLoadData(lvl = "agg", fld = "m4id", val = test_api$m4id, add.fld = FALSE)) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 1) + expect_true(all(c("m4id", "aeid", "spid", "bmad", "logc", "resp", "max_med", "nconc", "nrep") %in% colnames(dat))) + expect_true(test_api$m4id %in% dat$m4id) + }) + test_that("agg level API data loads by aeid", { + expect_no_error(dat <- tcplLoadData(lvl = "agg", fld = "aeid", val = test_api$aeid, add.fld = FALSE)) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 1) + expect_true(all(c("m4id", "aeid", "spid", "bmad", "logc", "resp", "max_med", "nconc", "nrep") %in% colnames(dat))) + expect_true(test_api$aeid %in% dat$aeid) + }) + test_that("agg level API data loads by dtxsid", { + expect_no_error(dat <- tcplLoadData(lvl = "agg", fld = "dtxsid", val = test_api$dtxsid, add.fld = FALSE)) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 1) + expect_true(all(c("dtxsid", "m4id", "aeid", "spid", "bmad", "logc", "resp", "max_med", "nconc", "nrep") %in% colnames(dat))) + expect_true(test_api$dtxsid %in% dat$dtxsid) + }) + test_that("agg level API data loads by spid", { + expect_no_error(dat <- tcplLoadData(lvl = "agg", fld = "spid", val = test_api$spid, add.fld = FALSE)) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 1) + expect_true(all(c("m4id", "aeid", "spid", "bmad", "logc", "resp", "max_med", "nconc", "nrep") %in% colnames(dat))) + expect_true(test_api$spid %in% dat$spid) + }) + # error cases + test_that("more than one field results in error", { + expect_error(tcplLoadData(lvl = 5, fld = c("aeid", "spid"), val = list(test_api$aeid, test_api$spid), add.fld = FALSE), + "'fld' must be length 1") + }) + test_that("fields outside of dtxsid, aeid, m4id, spid result in error", { + expect_error(tcplLoadData(lvl = 3, fld = "acid", val = test_api$acid, add.fld = FALSE), + "'fld' must be one of 'AEID', 'SPID', 'm4id', or 'DTXSID'") + }) + test_that("levels other than 3-6 and 'agg' result in error", { + expect_error(tcplLoadData(lvl = 2, fld = "aeid", val = test_api$aeid, add.fld = FALSE), + "Only lvl = c(3,4,5,6) and 'agg' are supported using API data as source.", fixed = TRUE) + }) + test_that("type = 'sc' result in error", { + expect_error(tcplLoadData(type = "sc", lvl = 2, fld = "aeid", val = test_api$aeid, add.fld = FALSE), + "Only type = 'mc' is supported using API data as source.") + }) + test_that("data not found results in null data.table", { + expect_warning(dat <- tcplLoadData(lvl = 3, fld = "aeid", val = 0, add.fld = FALSE), + "Data not found for the following 'fld' and 'val' combos: +AEID: 0", fixed = TRUE) + expect_equal(nrow(dat), 0) + expect_warning(dat <- tcplLoadData(lvl = 4, fld = "spid", val = "fakespid", add.fld = FALSE), + "Data not found for the following 'fld' and 'val' combos: +SPID: fakespid", fixed = TRUE) + expect_equal(nrow(dat), 0) + expect_warning(dat <- tcplLoadData(lvl = 5, fld = "dtxsid", val = "fakedtxsid", add.fld = FALSE), + "Data not found for the following 'fld' and 'val' combos: +DTXSID: fakedtxsid", fixed = TRUE) + expect_equal(nrow(dat), 0) + expect_warning(dat <- tcplLoadData(lvl = 6, fld = "m4id", val = 0, add.fld = FALSE), + "Data not found for the following 'fld' and 'val' combos: +m4id: 0", fixed = TRUE) + expect_equal(nrow(dat), 0) + }) + test_that("some data not found results in warning", { + expect_warning(dat <- tcplLoadData(lvl = 3, fld = "aeid", val = c(0, test_api$aeid), add.fld = FALSE), + "Data not found for the following 'fld' and 'val' combos: +AEID: 0", fixed = TRUE) + expect_true(nrow(dat) > 0) + expect_warning(dat <- tcplLoadData(lvl = 4, fld = "spid", val = c("fakespid", test_api$spid), add.fld = FALSE), + "Data not found for the following 'fld' and 'val' combos: +SPID: fakespid", fixed = TRUE) + expect_true(nrow(dat) > 0) + expect_warning(dat <- tcplLoadData(lvl = 5, fld = "dtxsid", val = c("fakedtxsid", test_api$dtxsid), add.fld = FALSE), + "Data not found for the following 'fld' and 'val' combos: +DTXSID: fakedtxsid", fixed = TRUE) + expect_true(nrow(dat) > 0) + expect_warning(dat <- tcplLoadData(lvl = 6, fld = "m4id", val = c(0, test_api$m4id), add.fld = FALSE), + "Data not found for the following 'fld' and 'val' combos: +m4id: 0", fixed = TRUE) + expect_true(nrow(dat) > 0) + }) +}) diff --git a/tests/testthat/test-tcplLoadUnit.R b/tests/testthat/test-tcplLoadUnit.R new file mode 100644 index 00000000..1ea7f402 --- /dev/null +++ b/tests/testthat/test-tcplLoadUnit.R @@ -0,0 +1,25 @@ +#------------------------------------------------------------------------------- +# Covers testing tcplLoadUnit with "API" driver +# Using httptest mocking to automatically save json responses from http requests +# NOTE -- updates to the CTX API may mean stored json files are out of date. In +# this case, delete the 'ctx' folder and follow the instructions in the test- +# tcplLoadData test file. +#------------------------------------------------------------------------------- +httptest::with_mock_dir("ctx", { + apikey <- "apikey" + tcplConf(pass = apikey, + drvr = "API") + data(test_api) + test_that("tcplLoadUnit works by aeid", { + expect_no_error(dat <- tcplLoadUnit(aeid = test_api$aeid)) + expect_true(is.data.table(dat)) + expect_equal(nrow(dat), 1) + expect_true(all(c("aeid", "resp_unit") %in% colnames(dat))) + expect_equal(dat$aeid, test_api$aeid) + }) + #error cases + test_that("data not found results in null data.table", { + expect_no_error(dat <- tcplLoadUnit(aeid = 0)) + expect_equal(nrow(dat), 0) + }) +}) \ No newline at end of file diff --git a/tests/testthat/test-tcplPlot.R b/tests/testthat/test-tcplPlot.R index 55e65081..8b28419a 100644 --- a/tests/testthat/test-tcplPlot.R +++ b/tests/testthat/test-tcplPlot.R @@ -1,3 +1,7 @@ +#------------------------------------------------------------------------------- +# old tests using drvr = "example" +#------------------------------------------------------------------------------- + tcplConf(drvr="example") if (!interactive()) pdf(NULL) @@ -7,153 +11,9 @@ test_that("round_n function works", { c("1.2e+03",NA,"0.333")) }) -test_that("check_tcpl_db_schema() loaded", { - expect_false( - (check_tcpl_db_schema()) - ) -}) - -test_that("error message works: 'No data for fld/val provided'", { - input <- NULL - expect_error( - if (nrow(input) == 0) stop("No data for fld/val provided") - ) -}) - -test_that("tcplPlot loads data", { - input <- tcplLoadData(lvl = 4, type = "mc") - expect_no_error( - if (nrow(input) == 0) stop("No data for fld/val provided") - ) -}) - -test_that("logic check works: assign multi=TRUE for output='pdf'", { - output <- "pdf" - multi <- NULL - if (output == "pdf" && is.null(multi)) { - multi <- TRUE - } - expect_true(multi) -}) - -test_that("logic check works: assign multi=FALSE for output != 'pdf', - verbose=FALSE for output='console'", { - output = 'console' - if (output !="pdf") { - multi <- FALSE - if(output =="console"){ - verbose <- FALSE - } - } - expect_false(multi) - expect_false(verbose) - }) - -test_that("logic check works: assign nrow = ncol = 1 for output='pdf' and - multi=FALSE to plot one plot per page", { - output = 'pdf' - multi = FALSE - input <- tcplLoadData(lvl = 4, type = "mc") - if(nrow(input) > 1 && output == "pdf" && multi == FALSE) { - nrow = ncol = 1 - } - expect_equal( - c(nrow,ncol), - c(1,1) - ) -}) - -test_that("error message: output = 'console' and multi = FALSE - to avoid multiple plots in console", { - input <- tcplLoadData(lvl = 4, type = "mc") - expect_error( - if(nrow(input) > 1 && output == "console" && multi == FALSE) stop("More than 1 concentration series returned for given field/val combination. Set output to pdf or reduce the number of curves to 1. Current number of curves: ", nrow(input)) - ) -}) - - -test_that("nrow value set based on verbose", { - nrow = NULL - verbose = TRUE - if(is.null(nrow)){ - nrow <- ifelse(verbose,2,2) - } - expect_equal(nrow,2) -}) - -test_that("ncol value set based on verbose", { - ncol = NULL - verbose = FALSE - if(is.null(ncol)){ - ncol <- ifelse(verbose,2,3) - } - expect_equal(ncol,3) -}) - -test_that("m4id filters mc4 input", { - input <- tcplLoadData(lvl = 4, type = "mc") - m4id <- input$m4id - expect_length(m4id,5) -}) - -test_that("m4id filters mc5 input", { - input <- tcplLoadData(lvl = 5, type = "mc") - m4id <- input$m4id - expect_length(m4id,5) -}) - -test_that("dat table loads", { - lvl = 5 - l4 <- tcplLoadData(lvl = 4, type = "mc", add.fld = TRUE) - if (lvl >= 5L) { - l5 <- tcplLoadData(lvl = 5, type = "mc", add.fld = TRUE) - dat <- l4[l5, on = "m4id"] - } - expect_length(dat,length(l5)+length(l4)-1) -}) - -test_that("tcplPrepOtpt loads chemical and units", { - lvl = 5 - l4 <- tcplLoadData(lvl = 4, type = "mc", add.fld = TRUE) - if (lvl >= 5L) { - l5 <- mc_vignette[["mc5"]] - dat <- l4[l5, on = c("m4id","aeid")] - dat <- dat[,!c("tp","ga","q","la","ac50_loss")] - } - expect_length(dat,188) - expect_type(dat$dsstox_substance_id,"character") - expect_type(dat$conc_unit,"character") -}) - -test_that("unlog conc data table works", { - agg <- tcplLoadData(lvl = "agg", type = "mc") - conc_resp_table <- agg %>% - group_by(m4id) %>% - summarise(conc = list(10^logc), resp = list(resp)) %>% - as.data.table() - expect_true(is.data.table(conc_resp_table)) - expect_length(conc_resp_table,3) - expect_length(conc_resp_table$conc,5) -}) - -test_that("conc_resp_table joins dat table correctly", { - lvl = 5 - l4 <- tcplLoadData(lvl = 4, type = "mc", add.fld = TRUE) - if (lvl >= 5L) { - l5 <- tcplLoadData(lvl = 5, type = "mc", add.fld = TRUE) - dat <- l4[l5, on = "m4id"] - } - agg <- tcplLoadData(lvl = "agg", type = "mc") - conc_resp_table <- agg %>% - group_by(m4id) %>% - summarise(conc = list(10^logc), resp = list(resp)) %>% - as.data.table() - dat <- dat[conc_resp_table, on = "m4id"] - expect_length(dat,183) -}) test_that("one m4id tcplPlot works", { - skip_on_ci() + skip() lvl = 5 verbose = TRUE l4 <- tcplLoadData(lvl = 4, type = "mc", add.fld = TRUE) @@ -165,17 +25,19 @@ test_that("one m4id tcplPlot works", { agg <- tcplLoadData(lvl = "agg", type = "mc") conc_resp_table <- agg %>% group_by(m4id) %>% - summarise(conc = list(10^logc), resp = list(resp)) %>% + summarise(conc = list(conc), resp = list(resp)) %>% as.data.table() dat <- dat[conc_resp_table, on = "m4id"] dat <- dat[,normalized_data_type:="log2_fold_induction"] dat <- dat[spid == "01504209"] - mc5_tcplplot <- tcplggplot(dat,verbose = verbose) + mc5_tcplplot <- suppressWarnings(tcplggplot(dat,verbose = verbose)) expect_no_warning(mc5_tcplplot) vdiffr::expect_doppelganger("test_output_482273", mc5_tcplplot) }) +# needs updates or removal; new spid is not in downward direction test_that("negative direction plot has negative bmr and cutoff lines", { + skip() lvl = 5 verbose = FALSE l4 <- tcplLoadData(lvl = 4, type = "mc", add.fld = TRUE) @@ -187,33 +49,730 @@ test_that("negative direction plot has negative bmr and cutoff lines", { agg <- tcplLoadData(lvl = "agg", type = "mc") conc_resp_table <- agg %>% group_by(m4id) %>% - summarise(conc = list(10^logc), resp = list(resp)) %>% + summarise(conc = list(conc), resp = list(resp)) %>% as.data.table() dat <- dat[conc_resp_table, on = "m4id"] dat <- dat[,normalized_data_type:="log2_fold_induction"] - dat <- dat[spid == "1210314466"] - mc5_tcplplot <- tcplggplot(dat,verbose = verbose) + dat <- dat[spid == "01504209"] + mc5_tcplplot <- suppressWarnings(tcplggplot(dat,verbose = verbose)) vdiffr::expect_doppelganger("negative_cutoff_bmr", mc5_tcplplot) }) -test_that("coff,bmr should be negative if winning model has negative top", { - lvl = 5 - l4 <- tcplLoadData(lvl = 4, type = "mc", add.fld = TRUE) - if (lvl >= 5L) { - l5 <- tcplLoadData(lvl = 5, type = "mc", add.fld = TRUE) - dat <- l4[l5, on = "m4id"] - } - dat <- dat[spid == "1210314466"] - if (!is.null(dat$top) && !is.null(dat$coff) && !is.na(dat$top) && !is.null(dat$bmr)) { - if (dat$top < 0) { - dat$coff <- dat$coff * -1 - dat$bmr <- dat$bmr * -1 + +#------------------------------------------------------------------------------- +# new tests using drvr = "MySQL" and mocking +#------------------------------------------------------------------------------- +# Format +# test_that("something works", { + # data("mc_test") + # mocked <- mc_test$mc0_by_m0id # change this + # local_mocked_bindings( + # tcplQuery = function(query, db, tbl) { + # if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + # else mocked[query][[1]] + # } + # ) + # tcplConf(drvr = "MySQL", db = "invitrodb") # must include both +# }) + +# Test tcplPlotLoadData +test_that("tcplPlotLoadData loads all necessary mc data", { + data("mc_test") + mocked <- mc_test$plot_single_m4id + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplPlotLoadData(val = mocked$m4id, flags = TRUE) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("dsstox_substance_id", "aenm", "m4id", "bmad", "hitc", "modl", + "cnst_aic", "flag", "ac50", "order", "conc", "resp", "conc_unit", + "resp_unit", "normalized_data_type") %in% colnames(dat))) + expect_true(mocked$m4id %in% dat$m4id) +}) + +test_that("tcplPlotLoadData loads all necessary sc data", { + data("sc_test") + mocked <- sc_test$plot_single_s2id + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplPlotLoadData(type = "sc", fld = "s2id", val = mocked$s2id) + expect_true(is.data.table(dat)) + expect_true(nrow(dat) > 0) + expect_true(all(c("dsstox_substance_id", "aenm", "s2id", "bmad", "hitc", "max_med", + "order", "conc", "resp", "conc_unit", "coff", + "resp_unit", "normalized_data_type") %in% colnames(dat))) + expect_true(mocked$s2id %in% dat$s2id) +}) + +test_that("tcplPlotLoadData errors if type is not 'mc' or 'sc'", { + data("mc_test") + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_error(tcplPlotLoadData(type = "ms", val = 123, flags = TRUE), + "Invalid 'lvl' and 'type' combination.") +}) + +# Test tcplPlotValidate +test_that("tcplPlotValidate warns user if flags = TRUE and type = 'sc'", { + expect_warning(validated_params <- tcplPlotValidate(type = "sc",flags = TRUE,output = "pdf",multi = NULL,verbose = FALSE)) + expect_equal(validated_params, list(lvl = 2, type = "sc", flags = FALSE, output = "pdf", multi = TRUE, verbose = FALSE)) +}) + +test_that("tcplPlotValidate force assigns multi = FALSE and verbose = FALSE if output != pdf", { + validated_params <- tcplPlotValidate(type = "mc",flags = TRUE,output = "console",multi = TRUE,verbose = TRUE) + expect_equal(validated_params, list(lvl = 5, type = "mc", flags = TRUE, output = "console", multi = FALSE, verbose = FALSE)) +}) + +test_that("tcplPlotValidate doesn't change correctly assigned parameters", { + validated_params <- tcplPlotValidate(type = "mc",flags = TRUE,output = "pdf",multi = TRUE,verbose = TRUE) + expect_equal(validated_params, list(lvl = 5, type = "mc", flags = TRUE, output = "pdf", multi = TRUE, verbose = TRUE)) +}) + +# Test tcplPlotSetYRange +test_that("tcplPlotSetYRange validates range", { + # error cases + expect_error(tcplPlotSetYRange(dat=NULL,yuniform=FALSE,yrange=c(1,2,3),type="mc"), "'yrange' must be of length 2") + expect_error(tcplPlotSetYRange(dat=NULL,yuniform=FALSE,yrange=1,type="mc"), "'yrange' must be of length 2") + expect_error(tcplPlotSetYRange(dat=NULL,yuniform=FALSE,yrange=NULL,type="mc"), "'yrange' must be of length 2") + # validate existing set yrange and doesn't overwrite it regardless if yuniform is TRUE + expect_equal(tcplPlotSetYRange(dat=NULL,yuniform=FALSE,yrange=c(-100,100),type="mc"),c(-100,100)) + expect_equal(tcplPlotSetYRange(dat=NULL,yuniform=TRUE,yrange=c(-100,100),type="mc"),c(-100,100)) +}) + +test_that("tcplPlotSetYRange correctly sets yrange for mc data", { + data("mc_test") + mocked <- mc_test$plot_multiple_aeid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplPlotLoadData(fld = "aeid", val = mocked$aeid, flags = TRUE) + expect_no_error(yrange <- tcplPlotSetYRange(dat=dat,yuniform=TRUE,yrange=c(NA,NA),type="mc")) + expect_length(yrange,2) + min <- min(dat$resp_min, unlist(dat$resp)) + max <- max(dat$resp_max, unlist(dat$resp)) + if (2 %in% dat$model_type) { + cutoffs <- dat[model_type == 2]$coff + min <- min(min, cutoffs, cutoffs * -1) + max <- max(max, cutoffs, cutoffs * -1) + } + # any gain models contained in dat, cutoff only positive + if (3 %in% dat$model_type) { + cutoffs <- dat[model_type == 3]$coff + min <- min(min, cutoffs) + max <- max(max, cutoffs) + } + # any loss models contained in dat, cutoff only negative + if (4 %in% dat$model_type) { + cutoffs <- dat[model_type == 4]$coff + min <- min(min, cutoffs * -1) + max <- max(max, cutoffs * -1) } - expect_lt(dat$coff,0) - expect_lt(dat$bmr,0) + expect_equal(yrange, c(min,max)) }) -# test_that("description", { -# expect_*(code) -# }) +test_that("tcplPlotSetYRange correctly sets yrange for sc data", { + data("sc_test") + mocked <- sc_test$plot_multiple_aeid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplPlotLoadData(type = "sc", fld = "aeid", val = mocked$aeid) + expect_no_error(yrange <- tcplPlotSetYRange(dat=dat,yuniform=TRUE,yrange=c(NA,NA),type="sc")) + expect_length(yrange,2) + min <- min(dat$resp_min, unlist(dat$resp)) + max <- max(dat$resp_max, unlist(dat$resp)) + min <- min(min, dat$coff, dat$coff * -1) + max <- max(max, dat$coff, dat$coff * -1) + expect_equal(yrange, c(min,max)) +}) + +# Test tcplPlot - mc +test_that("tcplPlot works for single m4id", { + data("mc_test") + mocked <- mc_test$plot_single_m4id + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = "m4id", val = mocked$m4id, output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = "m4id", val = mocked$m4id, output = "pdf", multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = "m4id", val = mocked$m4id, output = "console", verbose = TRUE, flags = TRUE, multi = TRUE))) + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("tcplPlot works for multiple m4id", { + data("mc_test") + mocked <- mc_test$plot_multiple_m4id + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = "m4id", val = mocked$m4id, output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = "m4id", val = mocked$m4id, output = "pdf", multi = TRUE, fileprefix = "temp_tcplPlot"))) + # console does not work with length(val) > 1 + expect_error(tcplPlot(type = "mc", fld = "m4id", val = mocked$m4id, output = "console", verbose = TRUE, flags = TRUE, multi = TRUE), + "More than 1 concentration series returned for given field/val combination. Set output to pdf or reduce the number of curves to 1. Current number of curves: 2") + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("tcplPlot works for single aeid", { + data("mc_test") + mocked <- mc_test$plot_single_aeid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = "aeid", val = mocked$aeid, output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = "aeid", val = mocked$aeid, output = "pdf", multi = TRUE, fileprefix = "temp_tcplPlot"))) + # console does not work with length(val) > 1 + expect_error(tcplPlot(type = "mc", fld = "aeid", val = mocked$aeid, output = "console", verbose = TRUE, flags = TRUE, multi = TRUE), + "More than 1 concentration series returned for given field/val combination. Set output to pdf or reduce the number of curves to 1. Current number of curves: 2") + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("tcplPlot works for multiple aeid", { + data("mc_test") + mocked <- mc_test$plot_multiple_aeid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = "aeid", val = mocked$aeid, output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = "aeid", val = mocked$aeid, output = "pdf", by = "aeid", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = "aeid", val = mocked$aeid, output = "pdf", flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = "aeid", val = mocked$aeid, output = "pdf", flags = TRUE, by = "aeid", multi = TRUE, fileprefix = "temp_tcplPlot"))) + # console does not work with length(val) > 1 + expect_error(tcplPlot(type = "mc", fld = "aeid", val = mocked$aeid, output = "console", verbose = TRUE, flags = TRUE, multi = TRUE), + "More than 1 concentration series returned for given field/val combination. Set output to pdf or reduce the number of curves to 1. Current number of curves: 4") + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 3) # exactly three files created (2 from `by = "aeid"` output) + file.remove(fn) # clean up +}) + +test_that("tcplPlot works for single spid/aeid", { + data("mc_test") + mocked <- mc_test$plot_single_spid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = c("spid", "aeid"), val = list(mocked$spid, mocked$aeid), output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = c("spid", "aeid"), val = list(mocked$spid, mocked$aeid), output = "pdf", multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = c("spid", "aeid"), val = list(mocked$spid, mocked$aeid), output = "console", verbose = TRUE, flags = TRUE, multi = TRUE))) + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("tcplPlot works for multiple spid/aeid", { + data("mc_test") + mocked <- mc_test$plot_multiple_spid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = c("spid", "aeid"), val = list(mocked$spid, mocked$aeid), output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = c("spid", "aeid"), val = list(mocked$spid, mocked$aeid), output = "pdf", multi = TRUE, fileprefix = "temp_tcplPlot"))) + # console does not work with length(val) > 1 + expect_error(tcplPlot(type = "mc", fld = c("spid", "aeid"), val = list(mocked$spid, mocked$aeid), output = "console", verbose = TRUE, flags = TRUE, multi = TRUE), + "More than 1 concentration series returned for given field/val combination. Set output to pdf or reduce the number of curves to 1. Current number of curves: 2") + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("tcplPlot works for single m4id compared", { + data("mc_test") + mocked <- mc_test$plot_single_m4id_compare + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = "m4id", val = mocked$m4id, compare.val = mocked$compare.m4id, output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = "m4id", val = mocked$m4id, compare.val = mocked$compare.m4id, output = "pdf", multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = "m4id", val = mocked$m4id, compare.val = mocked$compare.m4id, output = "console", verbose = TRUE, flags = TRUE, multi = TRUE))) + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("tcplPlot works for multiple m4id compared", { + data("mc_test") + mocked <- mc_test$plot_multiple_m4id_compare + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = "m4id", val = mocked$m4id, compare.val = mocked$compare.m4id, output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = "m4id", val = mocked$m4id, compare.val = mocked$compare.m4id, output = "pdf", flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + # console does not work with length(val) > 1 + expect_error(tcplPlot(type = "mc", fld = "m4id", val = mocked$m4id, compare.val = mocked$compare.m4id, output = "console", verbose = TRUE, flags = TRUE, multi = TRUE), + "More than 1 concentration series returned for given field/val combination. Set output to pdf or reduce the number of curves to 1. Current number of curves: 4") + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("tcplPlot works for single aeid compared", { + data("mc_test") + mocked <- mc_test$plot_single_aeid_compare + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = "aeid", val = mocked$aeid, compare.val = mocked$compare.aeid, output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = "aeid", val = mocked$aeid, compare.val = mocked$compare.aeid, output = "pdf", multi = TRUE, fileprefix = "temp_tcplPlot"))) + # console does not work with length(val) > 1 + expect_error(tcplPlot(type = "mc", fld = "aeid", val = mocked$aeid, compare.val = mocked$compare.aeid, output = "console", verbose = TRUE, flags = TRUE, multi = TRUE), + "More than 1 concentration series returned for given field/val combination. Set output to pdf or reduce the number of curves to 1. Current number of curves: 4") + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("tcplPlot works for multiple aeid compared", { + data("mc_test") + mocked <- mc_test$plot_multiple_aeid_compare + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = "aeid", val = mocked$aeid, compare.val = mocked$compare.aeid, output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = "aeid", val = mocked$aeid, compare.val = mocked$compare.aeid, output = "pdf", multi = TRUE, flags = TRUE, fileprefix = "temp_tcplPlot"))) + # console does not work with length(val) > 1 + expect_error(tcplPlot(type = "mc", fld = "aeid", val = mocked$aeid, compare.val = mocked$compare.aeid, output = "console", verbose = TRUE, flags = TRUE, multi = TRUE), + "More than 1 concentration series returned for given field/val combination. Set output to pdf or reduce the number of curves to 1. Current number of curves: 8") + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("tcplPlot works for single spid/aeid compared", { + data("mc_test") + mocked <- mc_test$plot_single_spid_compare + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = c("spid", "aeid"), val = list(mocked$spid, mocked$aeid), compare.val = list(mocked$compare.spid, mocked$compare.aeid), output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = c("spid", "aeid"), val = list(mocked$spid, mocked$aeid), compare.val = list(mocked$compare.spid, mocked$compare.aeid), output = "pdf", multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = c("spid", "aeid"), val = list(mocked$spid, mocked$aeid), compare.val = list(mocked$compare.spid, mocked$compare.aeid), output = "console", verbose = TRUE, flags = TRUE, multi = TRUE))) + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("tcplPlot works for multiple spid/aeid compared", { + data("mc_test") + mocked <- mc_test$plot_multiple_spid_compare + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = c("spid", "aeid"), val = list(mocked$spid, mocked$aeid), compare.val = list(mocked$compare.spid, mocked$compare.aeid), output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "mc", fld = c("spid", "aeid"), val = list(mocked$spid, mocked$aeid), compare.val = list(mocked$compare.spid, mocked$compare.aeid), output = "pdf", flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + # console does not work with length(val) > 1 + expect_error(tcplPlot(type = "mc", fld = c("spid", "aeid"), val = list(mocked$spid, mocked$aeid), compare.val = list(mocked$compare.spid, mocked$compare.aeid), output = "console", verbose = TRUE, flags = TRUE, multi = TRUE), + "More than 1 concentration series returned for given field/val combination. Set output to pdf or reduce the number of curves to 1. Current number of curves: 4") + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +# Test tcplPlot - sc +test_that("tcplPlot works for single s2id", { + data("sc_test") + mocked <- sc_test$plot_single_s2id + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "sc", fld = "s2id", val = mocked$s2id, output = "pdf", verbose = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "sc", fld = "s2id", val = mocked$s2id, output = "console", verbose = TRUE, multi = TRUE))) + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("tcplPlot works for multiple s2id", { + data("sc_test") + mocked <- sc_test$plot_multiple_s2id + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "sc", fld = "s2id", val = mocked$s2id, output = "pdf", verbose = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + # console does not work with length(val) > 1 + expect_error(tcplPlot(type = "sc", fld = "s2id", val = mocked$s2id, output = "console", verbose = TRUE, multi = TRUE), + "More than 1 concentration series returned for given field/val combination. Set output to pdf or reduce the number of curves to 1. Current number of curves: 2") + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("tcplPlot works for single aeid", { + data("sc_test") + mocked <- sc_test$plot_single_aeid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "sc", fld = "aeid", val = mocked$aeid, output = "pdf", verbose = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + # console does not work with length(val) > 1 + expect_error(tcplPlot(type = "sc", fld = "aeid", val = mocked$aeid, output = "console", verbose = TRUE, multi = TRUE), + "More than 1 concentration series returned for given field/val combination. Set output to pdf or reduce the number of curves to 1. Current number of curves: 7") + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("tcplPlot works for multiple aeid", { + data("sc_test") + mocked <- sc_test$plot_multiple_aeid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "sc", fld = "aeid", val = mocked$aeid, output = "pdf", verbose = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "sc", fld = "aeid", val = mocked$aeid, by = "aeid", output = "pdf", verbose = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + # console does not work with length(val) > 1 + expect_error(tcplPlot(type = "sc", fld = "aeid", val = mocked$aeid, output = "console", verbose = TRUE, multi = TRUE), + "More than 1 concentration series returned for given field/val combination. Set output to pdf or reduce the number of curves to 1. Current number of curves: 14") + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 3) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("tcplPlot works for single spid/aeid", { + data("sc_test") + mocked <- sc_test$plot_single_spid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "sc", fld = c("spid", "aeid"), val = list(mocked$spid, mocked$aeid), output = "pdf", verbose = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "sc", fld = c("spid", "aeid"), val = list(mocked$spid, mocked$aeid), output = "console", verbose = TRUE, multi = TRUE))) + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("tcplPlot works for multiple spid/aeid", { + data("sc_test") + mocked <- sc_test$plot_multiple_spid + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "sc", fld = c("spid", "aeid"), val = list(mocked$spid, mocked$aeid), output = "pdf", verbose = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + # console does not work with length(val) > 1 + expect_error(tcplPlot(type = "sc", fld = c("spid", "aeid"), val = list(mocked$spid, mocked$aeid), output = "console", verbose = TRUE, multi = TRUE), + "More than 1 concentration series returned for given field/val combination. Set output to pdf or reduce the number of curves to 1. Current number of curves: 2") + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("tcplPlot works for single s2id compared", { + data("sc_test") + mocked <- sc_test$plot_single_s2id_compare + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "sc", fld = "s2id", val = mocked$s2id, compare.val = mocked$compare.s2id, output = "pdf", verbose = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "sc", fld = "s2id", val = mocked$s2id, compare.val = mocked$compare.s2id, output = "console", verbose = TRUE, multi = TRUE))) + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("tcplPlot works for multiple s2id compared", { + data("sc_test") + mocked <- sc_test$plot_multiple_s2id_compare + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "sc", fld = "s2id", val = mocked$s2id, compare.val = mocked$compare.s2id, output = "pdf", verbose = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + # console does not work with length(val) > 1 + expect_error(tcplPlot(type = "sc", fld = "s2id", val = mocked$s2id, compare.val = mocked$compare.s2id, output = "console", verbose = TRUE, multi = TRUE), + "More than 1 concentration series returned for given field/val combination. Set output to pdf or reduce the number of curves to 1. Current number of curves: 4") + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("tcplPlot works for single aeid compared", { + data("sc_test") + mocked <- sc_test$plot_single_aeid_compare + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "sc", fld = "aeid", val = mocked$aeid, compare.val = mocked$compare.aeid, output = "pdf", verbose = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + # console does not work with length(val) > 1 + expect_error(tcplPlot(type = "sc", fld = "aeid", val = mocked$aeid, compare.val = mocked$compare.aeid, output = "console", verbose = TRUE, multi = TRUE), + "More than 1 concentration series returned for given field/val combination. Set output to pdf or reduce the number of curves to 1. Current number of curves: 14") + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("tcplPlot works for multiple aeid compared", { + data("sc_test") + mocked <- sc_test$plot_multiple_aeid_compare + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "sc", fld = "aeid", val = mocked$aeid, compare.val = mocked$compare.aeid, output = "pdf", verbose = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + # console does not work with length(val) > 1 + expect_error(tcplPlot(type = "sc", fld = "aeid", val = mocked$aeid, compare.val = mocked$compare.aeid, output = "console", verbose = TRUE, multi = TRUE), + "More than 1 concentration series returned for given field/val combination. Set output to pdf or reduce the number of curves to 1. Current number of curves: 28") + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("tcplPlot works for single spid/aeid compared", { + data("sc_test") + mocked <- sc_test$plot_single_spid_compare + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "sc", fld = c("spid", "aeid"), val = list(mocked$spid, mocked$aeid), compare.val = list(mocked$compare.spid, mocked$compare.aeid), output = "pdf", verbose = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + expect_no_error(suppressWarnings(tcplPlot(type = "sc", fld = c("spid", "aeid"), val = list(mocked$spid, mocked$aeid), compare.val = list(mocked$compare.spid, mocked$compare.aeid), output = "console", verbose = TRUE, multi = TRUE))) + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("tcplPlot works for multiple spid/aeid compared", { + data("sc_test") + mocked <- sc_test$plot_multiple_spid_compare + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + expect_no_error(suppressWarnings(tcplPlot(type = "sc", fld = c("spid", "aeid"), val = list(mocked$spid, mocked$aeid), compare.val = list(mocked$compare.spid, mocked$compare.aeid), output = "pdf", verbose = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + # console does not work with length(val) > 1 + expect_error(tcplPlot(type = "sc", fld = c("spid", "aeid"), val = list(mocked$spid, mocked$aeid), compare.val = list(mocked$compare.spid, mocked$compare.aeid), output = "console", verbose = TRUE, multi = TRUE), + "More than 1 concentration series returned for given field/val combination. Set output to pdf or reduce the number of curves to 1. Current number of curves: 4") + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +# Stand-alone plotting +test_that("standalone plotting works in mc", { + data("mc_test") + mocked <- mc_test$plot_single_m4id + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplPlotLoadData(val = mocked$m4id, flags = TRUE) + expect_no_error(suppressWarnings(tcplPlot(dat = dat, type = "mc", fld = "m4id", val = mocked$m4id, output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("standalone advanced comparison plotting works in mc", { + data("mc_test") + mocked <- mc_test$plot_single_m4id_compare + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") mc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplPlotLoadData(val = mocked$m4id, flags = TRUE) + expect_no_error(suppressWarnings(tcplPlot(dat = dat, type = "mc", fld = "m4id", val = mocked$m4id, compare.val = mocked$compare.m4id , output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("standalone plotting works in sc", { + data("sc_test") + mocked <- sc_test$plot_single_s2id + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplPlotLoadData(type = "sc", fld = "s2id", val = mocked$s2id) + expect_no_error(suppressWarnings(tcplPlot(dat = dat, type = "sc", fld = "s2id", val = mocked$s2id, output = "pdf", verbose = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + +test_that("standalone advanced comparison plotting works in sc", { + data("sc_test") + mocked <- sc_test$plot_single_s2id_compare + local_mocked_bindings( + tcplQuery = function(query, db, tbl) { + if (query == "SHOW VARIABLES LIKE 'max_allowed_packet'") sc_test$tcplConfQuery + else mocked[query][[1]] + } + ) + tcplConf(drvr = "MySQL", db = "invitrodb") # must include both + dat <- tcplPlotLoadData(type = "sc", fld = "s2id", val = mocked$s2id) + expect_no_error(suppressWarnings(tcplPlot(dat = dat, type = "sc", fld = "s2id", val = mocked$s2id, compare.val = mocked$compare.s2id , output = "pdf", verbose = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up +}) + + + +#------------------------------------------------------------------------------- +# Covers testing tcplLoadData with "API" driver +# Using httptest mocking to automatically save json responses from http requests +# NOTE -- updates to the CTX API may mean stored json files are out of date. In +# this case, delete the 'ctx' folder and rerun this ENTIRE test file (temporarily +# replacing the 'apikey' string with a valid key) to repopulate the stored +# .jsons. These will likely be huge and will need to be edited by hand to reduce +# their sizes. To do this, open the file(s) and remove all but one element of +# the outer array -- we don't need more than one endpoint-sample. +#------------------------------------------------------------------------------- +httptest::with_mock_dir("ctx", { + apikey <- "apikey" + tcplConf(pass = apikey, + drvr = "API") + data(test_api) + test_that("tcplPlot works with API data by m4id", { + expect_no_error(suppressWarnings(tcplPlot(val = test_api$m4id, output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up + }) + test_that("tcplPlot works with API data by aeid", { + expect_no_error(suppressWarnings(tcplPlot(fld = "aeid", val = test_api$aeid, output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up + }) + test_that("tcplPlot works with API data by spid", { + expect_no_error(suppressWarnings(tcplPlot(fld = "spid", val = test_api$spid, output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up + }) + test_that("tcplPlot works with API data by dtxsid", { + expect_no_error(suppressWarnings(tcplPlot(fld = "dtxsid", val = test_api$dtxsid, output = "pdf", verbose = TRUE, flags = TRUE, multi = TRUE, fileprefix = "temp_tcplPlot"))) + fn <- stringr::str_subset(list.files(), "^temp_tcplPlot") + expect_length(fn, 1) # exactly one file created + file.remove(fn) # clean up + }) +}) \ No newline at end of file