Skip to content

Commit

Permalink
259 remove tcpl lite and add api throughout package (#283)
Browse files Browse the repository at this point in the history
* 259 remove tcplLite and add API throughout package

* 259 remove tcplLite and add API throughout package

* 259 fix test after removal of 'tcplLite' in error message

* 259 deleted tcplConfExample, removed config related lines in examples

also wrapped examples in \dontrun{}

* 259 ran devtools::document

* 259 remove inst/csv and inst/example, used by tcplLite, tests passing

* 259 fix build error with example in tcplListFlds

* 259 removed chdat, replaced it in vignette with static version

* 259 removed chdat docs

* added rmdformats to suggests
  • Loading branch information
cthunes authored Sep 6, 2024
1 parent 558d8f6 commit 30a811b
Show file tree
Hide file tree
Showing 137 changed files with 147 additions and 1,351 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ Suggests:
colorspace,
magrittr,
vdiffr,
httptest
httptest,
rmdformats
License: MIT + file LICENSE
LazyData: true
RoxygenNote: 7.3.1
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export(tcplAddModel)
export(tcplCode2CASN)
export(tcplConf)
export(tcplConfDefault)
export(tcplConfExample)
export(tcplConfList)
export(tcplConfLoad)
export(tcplConfReset)
Expand Down
11 changes: 2 additions & 9 deletions R/assay_funcs.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@
#' return the assay source ID (asid) and assay source name (asnm).
#'
#' @examples
#' ## Store the current config settings, so they can be reloaded at the end
#' ## of the examples
#' conf_store <- tcplConfList()
#' TCPLlite <- file.path(system.file(package = "tcpl"), "example")
#' tcplConf(db = TCPLlite, user = NA, host = NA, drvr = "tcplLite")
#'
#' \dontrun{
#' ## The load assay functions can be used without any parameters to list the
#' ## full list of registered assay elements:
#' tcplLoadAsid()
Expand All @@ -43,9 +38,7 @@
#' a1 <- tcplLoadAeid(fld = "anm", val = "Steroidogenesis")
#' a2 <- tcplLoadAeid(fld = "assay_name", val = "Steroidogenesis")
#' identical(a1, a2)
#'
#' ## Reset configuration
#' options(conf_store)
#' }
#'
#' @return A data.table containing the ID, name, and any additional fields.
NULL
7 changes: 3 additions & 4 deletions R/config_funcs.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#' @param ... Additional arguments that should be passed to dbConnect function
#'
#' @details
#' Currently, the tcpl package only supports the "MySQL" and "tcplLite" database
#' drivers.
#' Currently, the tcpl package supports the "MySQL", "example", and "API"
#' database drivers.
#'
#' The settings can be stored in a configuration file to make the using the
#' package more user-friendly. To create the configuration file, the user must
Expand Down Expand Up @@ -48,8 +48,7 @@
#' configuration file.
#'
#' \code{tcplConfDefault} changes the \code{options} to reflect the default
#' settings for the example tcplLite database, i.e. local directory, but does
#' not alter the configuration file.
#' settings for the API connection, but does not alter the configuration file.
#'
#' \code{tcplConfReset} is used to generate the initial configuration script,
#' and can be used to reset or regenerate the configuration script by the user.
Expand Down
19 changes: 2 additions & 17 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' A subset of ToxCast data showing changes in transcription factor activity for multiple targets.
#'
#' The example dataset is used to illustrate how the user can pipeline single-concentration
#' data from chemical screening using tcplLite.
#' data from chemical screening using tcpl.
#'
#' @format A data frame with 320 rows and 10 variables:
#' \describe{
Expand All @@ -22,7 +22,7 @@
#' A subset of ToxCast data showing changes in the activity of the intracellular estrogen receptor.
#'
#' The example dataset is used to illustrate how the user can pipeline multiple-concentration
#' data from chemical screening using tcplLite.
#' data from chemical screening using tcpl.
#'
#' @format A data frame with 14183 rows and 10 variables:
#' \describe{
Expand All @@ -39,21 +39,6 @@
#' }
#' @source ToxCast database
"mcdat"
#' Chemical library of tested chemicals in the example datasets with the corresponding sample IDs.
#'
#'
#' @format A data frame with 6 rows and 6 variables:
#' \describe{
#' \item{spid}{sample ID}
#' \item{casn}{Chemical Abstract Service(CAS) number}
#' \item{chnm}{chemical name}
#' \item{dsstox_substance_id}{chemical-specific DTXSID}
#' \item{code}{CAS number compressed into numeric string}
#' \item{chid}{unique chemical ID number for tcpl}
#'
#' }
#' @source ToxCast database
"chdat"


#' List with multi-concentration data for the vignette
Expand Down
1 change: 0 additions & 1 deletion R/mc2_mthds.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
#' \item{agg.percent.rep.spid}{Use for binary data. Aggregate technical replicates as percentage by taking the sum of rval (raw values) relative to total replicates per sample id (spid) and concentration index (cndx); \eqn{cval = (sum(rval)/.N)*100}{cval = (sum(rval)/.N)*100}.}
#' \item{agg.percent.rep.spid.min1}{Use for binary data with variable number of replicates. Aggregate technical replicates as percentage by taking the sum of rval (raw values) relative to total replicates per per sample id (spid) and concentration index (cndx), where there is more than one replicate; \eqn{cval=(sum(rval)/.N)*100,~where~.N>1}{cval = (sum(rval)/.N)*100, where .N>1}.} Rvals are collapsed to one value per cndx.}
#' }
#' }
#'
#' @note
#' This function is not exported and is not intended to be used by the user.
Expand Down
6 changes: 1 addition & 5 deletions R/mc6.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ mc6 <- function(ae, wr = FALSE) {
## Load assay information to check for cell viability. Fill with 0 if unavailable.
tbl <- "assay_component_endpoint"
drvr = getOption("TCPL_DRVR")
if (drvr == "MySQL") {
flds <- tcplQuery(paste0("DESCRIBE ", tbl, ";"))$Field
} else if (drvr == "tcplLite") {
flds <- tcplQuery(paste0("PRAGMA table_info(", tbl, ");"),tbl=c(tbl))$name
}
flds <- tcplQuery(paste0("DESCRIBE ", tbl, ";"))$Field

if("cell_viability_assay" %in% flds){
cell_viability <- tcplLoadAeid(fld = "aeid",val = ae,add.fld = "cell_viability_assay")
Expand Down
9 changes: 1 addition & 8 deletions R/mthd_funcs.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@
#' and the delete cascade are available in the package vignette.
#'
#' @examples
#' ## Store the current config settings, so they can be reloaded at the end
#' ## of the examples
#' conf_store <- tcplConfList()
#' tcplConfDefault()
#'
#' \dontrun{
#' ## tcplListMthd allows the user to display the available methods for
#' ## a given level and data type
#' head(tcplMthdList(lvl = 2, type = "mc"))
Expand All @@ -46,7 +42,6 @@
#' ## whether an ID exists before assigning/clearing methods.
#' tcplMthdLoad(lvl = 2, id = 55, type = "mc")
#'
#' \dontrun{
#' ## ACID 55 does not have any methods. Assign methods from the list above.
#' tcplMthdAssign(lvl = 2,
#' id = 55,
Expand All @@ -63,6 +58,4 @@
#' ## Cleanup example method assigments
#' tcplMthdClear(lvl = 2, id = 53:55, type = "mc")
#' }
#' ## Reset configuration
#' options(conf_store)
NULL
22 changes: 6 additions & 16 deletions R/query_funcs.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @inheritParams tcplConf
#'
#' @details
#' Currently, the tcpl package supports the "MySQL", "tcplLite", and "API"
#' Currently, the tcpl package supports the "MySQL", "example", and "API"
#' database drivers.
#'
#' \code{tcplQuery} returns a data.table object with the query results.
Expand All @@ -20,23 +20,13 @@
#' connected using "API" as driver.
#'
#' @examples
#'
#' ## Store the current config settings, so they can be reloaded at the end
#' ## of the examples
#' conf_store <- tcplConfList()
#' TCPLlite <- file.path(system.file(package = "tcpl"), "example")
#' tcplConf(db = TCPLlite, user = NA, host = NA, drvr = "tcplLite")
#'
#' \dontrun{
#' # only with MySQL driver
#' tcplQuery("SELECT 'Hello World';")
#'
#' ## When using tcplLite, name of table must be passed into tcplQuery
#' if (conf_store$TCPL_DRVR == 'MySQL') {
#' tcplQuery("SELECT * FROM assay;")
#' } else {
#' tcplQuery("SELECT * FROM assay;", tbl='assay')
#' # only with API driver
#' tcplConfDefault()
#' tcplQueryAPI(resource = "data", fld = "aeid", val = 2)
#' }
#'
#' ## Reset configuration
#' options(conf_store)
#'
NULL
17 changes: 0 additions & 17 deletions R/rgstr_funcs.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@
#' the registration process and all of the fields is available in the vignette.
#'
#' @examples
#'
#' \dontrun{
#' ## Store the current config settings, so they can be reloaded at the end
#' ## of the examples
#' conf_store <- tcplConfList()
#' tcplConfDefault()
#'
#' ## Load current ASID information
#' tcplLoadAsid()
#'
Expand All @@ -66,17 +60,6 @@
#'
#' ## Remove the created ASID. Note: Manually deleting primary keys can cause
#' ## serious database problems and should not generally be done.
#'
#' ## If using the tcplLite DRVR, must specify table name
#' if (conf_store$TCPL_DRVR == 'MySQL') {
#' tcplSendQuery(paste0("DELETE FROM assay_source WHERE asid = ", i1, ";"))
#' } else {
#' qy <- paste0("SELECT * FROM assay_source WHERE NOT asid = ", i1, ";")
#' tcplSendQuery(qy, tbl='assay_source', delete=TRUE)
#' }
#'
#' ## Reset configuration
#' options(conf_store)
#' }
#'
NULL
60 changes: 3 additions & 57 deletions R/tcplAppend.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ tcplAppend <- function(dat, tbl, db, lvl=NULL) {

db_pars <- NULL

if (getOption("TCPL_DRVR") == "API") {
stop("'API' driver not supported in tcplAppend.")
}

if (getOption("TCPL_DRVR") == "MySQL") {

Expand Down Expand Up @@ -66,63 +69,6 @@ tcplAppend <- function(dat, tbl, db, lvl=NULL) {

}

if (getOption("TCPL_DRVR") == "tcplLite") {
# Rather than write to db, write to appropriate csv in db dir
db_pars <- db
fpath <- paste(db, tbl, sep='/') # Stitch together the dir path and the level table we're working on
fpath <- paste(fpath, 'csv', sep='.')

tbl_cols <- colnames(read.table(fpath, header=T, sep=',', fill=T))
if (length(setdiff(tbl_cols,names(dat)))>0){
setDT(dat)[, setdiff(tbl_cols, names(dat)) := NA]
}else{
setDT(dat)
}

setcolorder(dat, tbl_cols)


# Need to set the "<type><lvl>id" column. Don't have the luxury of the sql auto increment schema
autoFlag <- T
if (!is.null(lvl)) {
if (lvl %in% 0L:6L) {
if (startsWith(tbl, "mc")) {
autoIncr <- paste0("m",lvl,"id")
} else if (startsWith(tbl, "sc")) {
autoIncr <- paste0("s", lvl, "id")
}
} else if (lvl == "acid") {
autoIncr <- "acid"
} else if (lvl == "aeid") {
autoIncr <- "aeid"
} else if (lvl == "aid") {
autoIncr <- "aid"
} else if (lvl == "asid") {
autoIncr <- "asid"
} else {
autoFlag <- F
}

if (autoFlag == T){
temp_dt <- read.csv(fpath, sep=',', header=T)
if (length(temp_dt[,eval(autoIncr)]) == 0) {
start = 1
} else {
start = tail(temp_dt[,eval(autoIncr)], 1) + 1
}

end <- nrow(dat)+start-1
dat[, eval(autoIncr)] <- seq.int(start,end)
}
}



write.table(dat, file=fpath, append=T, row.names=F, sep=',', col.names=F)

return(TRUE)
}

if (is.null(db_pars)) {

stop(getOption("TCPL_DRVR"), " is not a supported database system. See ",
Expand Down
14 changes: 2 additions & 12 deletions R/tcplConf.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ tcplConf <- function (drvr = NULL, user = NULL, pass = NULL, host = NULL,
db = NULL,...) {
#tcplConf(user='_dataminer', pass='pass', host='au.epa.gov', drvr = 'MySQL',db = 'invitrodb')

# Notes for tcplLite
# ==================
# Allow drvr='tcplLite' for writing flat files for each level of analysis
# db=<local dir for writing files>

# Notes for example
# ==================
# Allow drvr='example' for loading example data from data directory in tcpl package
Expand Down Expand Up @@ -47,9 +42,9 @@ tcplConf <- function (drvr = NULL, user = NULL, pass = NULL, host = NULL,

if (!is.null(drvr)) {

if (!drvr %in% c( "MySQL", "tcplLite", "example", "API")) {
if (!drvr %in% c( "MySQL", "example", "API")) {
stop(drvr, " is not a supported database driver. Must be ",
"'MySQL', 'tcplLite', 'API' or 'example'.")
"'MySQL', 'API', or 'example'.")
}

if (drvr == "example"){
Expand All @@ -67,11 +62,6 @@ tcplConf <- function (drvr = NULL, user = NULL, pass = NULL, host = NULL,
}
}

if (drvr == "tcplLite") {
tcplLiteInit()
options("TCPL_DRVR" = "tcplLite")
}

if (drvr == "API") {
options("TCPL_DRVR" = "API")
if (is.null(pass)) stop("'API' driver requires an API-key, supply it to ",
Expand Down
15 changes: 0 additions & 15 deletions R/tcplConfExample.R

This file was deleted.

7 changes: 3 additions & 4 deletions R/tcplConfReset.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ tcplConfReset <- function () {
"## Detailed information about this file available in the help file for",
"## tcplConf (?tcplConf).",
"",
"DRVR <- \"tcplLite\"",
"DRVR <- \"API\"",
"HOST <- NA_character_",
"USER <- NA_character_",
"PASS <- NA_character_",
"DB <- file.path(system.file(package = \"tcpl\"),",
" \"csv\")",
"PASS <- \"01cbaf22-904f-11ee-954e-325096b39f47\"",
"DB <- NA_character_",
"",
"###################################################################",
sep = "\n",
Expand Down
4 changes: 2 additions & 2 deletions R/tcplConfSave.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ tcplConfSave <- function () {
}

drvr <- getOption("TCPL_DRVR")
if (!drvr %in% c("MySQL", "tcplLite")) {
stop(drvr, " is not a supported database driver. Must be 'tcplLite' or ",
if (!drvr %in% c("MySQL", "API")) {
stop(drvr, " is not a supported database driver. Must be 'API' or ",
"'MySQL'.")
}
drvr <- shQuote(drvr)
Expand Down
Loading

0 comments on commit 30a811b

Please sign in to comment.