Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

70 Investigate full coverage for tcplDefine. Updated tcplQuery/tcplDefine for example data #73

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/test-on-PR.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:

name: test-coverage

env:
DISPLAY: 0.0

jobs:
test-coverage:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Authors@R: c(
person("Madison","Feshuk",role = "ctb",email = "[email protected]", comment = c(ORCID = "0000-0002-1390-6405")),
person("Lori","Kolaczkowski",role = "ctb",email = "[email protected]"),
person("Kurt", "Dunham", role = "ctb", email = "[email protected]"),
person("Carter", "Thunes", role = "ctb", email = "[email protected]"),
person("Todd", "Zurlinden", role="ctb"),
person("Parth", "Kothiya", role = "ctb"),
person("Woodrow R", "Setzer", role = "ctb"),
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
YEAR: 2022
YEAR: 2023
COPYRIGHT HOLDER: U.S. Federal Government
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License

Copyright (c) 2022 U.S. Federal Government
Copyright (c) 2023 U.S. Federal Government

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
59 changes: 18 additions & 41 deletions R/tcplDefine.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,59 +50,36 @@
#' @export

tcplDefine <- function(val = NULL) {

tbl = c("invitrodb_dd")

drvr <- getOption("TCPL_DRVR")
qformat <- "SELECT invitrodb_table, invitrodb_field, description FROM invitrodb_dd"

# example driver
if (drvr == "example"){
if (!is.null(val)) {

dd <- invitrodb_dd[]
vstring <- paste0("\"", val, "\"", collapse = ",")
qformat <- paste(qformat, "WHERE invitrodb_table IN (%s) OR invitrodb_field IN (%s);")
qstring <- sprintf(qformat, vstring, vstring)

if (!is.null(val)) {
dd <- dd[dd$invitrodb_table %in% val | dd$invitrodb_field %in% val,]

if (nrow(dd) == 0) {
warning("The given table and/or field names were not found.")
}
}
} else {

return(dd)
qstring <- paste0(qformat, ";")

}
# MySQL driver
if (drvr != "example") {

tbl = c("invitrodb_dd")

qformat <- "SELECT invitrodb_table, invitrodb_field, description FROM invitrodb_dd"

if (!is.null(val)) {

vstring <- paste0("\"", val, "\"", collapse = ",")
qformat <- paste(qformat, "WHERE invitrodb_table IN (%s) OR invitrodb_field IN (%s);")
qstring <- sprintf(qformat, vstring, vstring)

} else {

qstring <- paste0(qformat, ";")

}

dat <- tcplQuery(query = qstring, db = getOption("TCPL_DB"), tbl=tbl)

dat <- tcplQuery(query = qstring, db = getOption("TCPL_DB"), tbl=tbl)

if (!is.null(val)) {

if (!is.null(val)) {

if (nrow(dat) == 0) {
warning("The given table and/or field names were not found.")
return(dat[])
}

if (nrow(dat) == 0) {
warning("The given table and/or field names were not found.")
return(dat[])
}

dat[]

}

dat[]

}

#-------------------------------------------------------------------------------
8 changes: 7 additions & 1 deletion R/tcplQuery.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ tcplQuery <- function(query, db = getOption("TCPL_DB"),
}

result <- as.data.table(sqldf(query, stringsAsFactors=F))


}

if (drvr == "example") {
db_pars <- "Using example data"

result <- as.data.table(sqldf(query, stringsAsFactors=F))

}

Expand Down
345 changes: 157 additions & 188 deletions tests/testthat/_snaps/tcplDefine.md

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions tests/testthat/test-tcplDefine.R
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
test_that("empty returns full dictionary", {
tcplConf(drvr = "example")
expect_snapshot(tcplDefine())
expect_snapshot_value(tcplDefine(), style = "serialize")
})

test_that("multiple values returns all necessary definitions", {
tcplConf(drvr = "example")
# just tables
expect_snapshot(tcplDefine(c("chemical", "sample")))
expect_snapshot_value(tcplDefine(c("chemical", "sample")), style = "serialize")
# just fields
expect_snapshot(tcplDefine(c("spid", "rval", "wllt")))
expect_snapshot_value(tcplDefine(c("spid", "rval", "wllt")), style = "serialize")
# mix of tables and fields
expect_snapshot(tcplDefine(c("sc0", "chid")))
expect_snapshot_value(tcplDefine(c("sc0", "chid")), style = "serialize")
})

test_that("one value returns all necessary definitions", {
tcplConf(drvr = "example")
# just a table
expect_snapshot(tcplDefine("chemical"))
expect_snapshot_value(tcplDefine("chemical"), style = "serialize")
# just a field
expect_snapshot(tcplDefine("spid"))
expect_snapshot_value(tcplDefine("spid"), style = "serialize")
})

test_that("no values found shows a warning", {
Expand Down
26 changes: 26 additions & 0 deletions vignettes/Data_retrieval.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,32 @@ head(mc2_fmtd)

When loading data, the user must indicate the applicable fields and ids for the corresponding data level of interest. Loading level 0 (SC0 and MC0), MC1, and MC2 data the assay component id ($\mathit{acid}$) will always be used. As described in Table 1 of the tcpl Data Processing vignette, SC1 and MC3 processing levels perform data normalization where assay component ids ($\mathit{acid}$) are converted to assay endpoint ids ($\mathit{aeid}$). Thus, the SC1 and MC3 data tables contain both $\mathit{acid}$ and ($\mathit{aeid}$) ID's. Data can be loaded using either id as long as it is properly specified. Loading SC2, MC4, and MC5, one should always use the assay endpoint id ($\mathit{aeid}$). Selected id(s) are based on the primary key within each table containing data. Examples of loading data are detailed in later sections.

### Assay Annotations

Assay source, assay, assay component, and assay endpoint are registered via tcpl scripting into a collection of tables. The database structure takes the annotations and organizes them as attributes of the assay conductors, the assays (i.e., experiments), the assay components (i.e., raw readouts), or the assay endpoints (i.e., normalized component data) enabling aggregation and differentiation of the data generated through ToxCast and Tox21. The annotations capture four types of information:

i. Identification information
ii. Design information such as the technology, format, and objective aspects that decompress the assay’s innovations,
iii. Target information such as the target of technological measurement and the
biologically intended target, and
iv. Analysis information about how the data were processed and analyzed.

```{r annotation_query_ex, eval = FALSE}
#load libraries and connections
library(RMySQL)
con <- dbConnect(drv = RMySQL::MySQL(), user="user", pass="pass", db="InvitroDB", host="host")
#query database using RMySQL:
#use source table to identify which ids are needed in subsequent queries.
tcplLoadAsid()
source <- tcplLoadAeid(fld="asid", val=1, add.fld = c("aid", "anm", "acid", "acnm"))
#select annotation and subset by ids or name
assay <- dbGetQuery(con, "SELECT * FROM invitrodb.assay where aid=1;")
component <- dbGetQuery(con, "SELECT * FROM invitrodb.assay_component;")
component <- subset(component, acid %in% source$acid)
endpoint <- dbGetQuery(con, "SELECT * FROM invitrodb.assay_component_endpoint;")
endpoint <- endpoint[grepl("ATG", endpoint$assay_component_endpoint_name),]
```

### Chemical Information

The <font face="CMTT10">tcplLoadChem</font> function returns chemical information for user specified parameters, e.g. the chemical name (chnm) and chemical id (chid). The <font face="CMTT10">tcplLoadClib</font> function provides more information about the ToxCast chemical library used for sample generation.
Expand Down