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

202 integrate ccdR into tcpl load data #221

Merged
merged 11 commits into from
Apr 8, 2024

Conversation

cthunes
Copy link
Contributor

@cthunes cthunes commented Mar 27, 2024

This PR closes #202. ccdR is integrated into tcplConf, tcplLoadData, and tcplLoadAeid. tcplQueryAPI was added to interface with ccdR. Other tcplLoadXxxx functions can be integrated soon after with new tickets.

Here are a bunch of tests, copy+paste to try it out!

devtools::install_github("USEPA/ccdR")
library("ccdR") #while ccdR is not on CRAN, must load manually

devtools::load_all() # or install_git from this branch, then library(tcpl)
tcplConf(pass='<apikey>', drvr = 'API') # add your API key


# tcplQueryAPI -- main use is by another function, like the tcplLoadAeid and tcplLoadData
# still possible to use directly however
tcplQueryAPI(resource = "assay", fld = "asid", val = 7)
tcplQueryAPI(resource = "assay", fld = "aeid", val = 891, return_flds = "acid")
tcplQueryAPI(fld = c("aeid", "acid"), val = 891) #error is right! if using tcplQueryAPI with default "data" for 'resource' parameter, can only use one fld (aeid, spid, m4id, dtxsid)


# tcplLoadAeid
tcplLoadAeid(fld = "acid", val = 400)
tcplLoadAeid(fld = "intended_target_type", val = "protein")
tcplLoadAeid(fld = "detection_technology_type", val = "Colorimetric")
tcplLoadAeid(fld = "aeid", val = 891)
tcplLoadAeid(fld = c("intended_target_type", "detection_technology_type"), val = list("protein", "Colorimetric"))
tcplLoadAeid(fld = c("intended_target_type", "detection_technology_type"), val = list("protein", "Radiometry", "Colorimetric")) #error is right! fld and val must be equal. put the last two elements in a vector to make the lengths match
tcplLoadAeid(fld = c("intended_target_type", "detection_technology_type"), val = list("protein", c("Radiometry", "Colorimetric")))
tcplLoadAeid(fld = "intended_target_type", val = c("protein", "rna"))
tcplLoadAeid(add.fld = "intended_target_type") #add any column(s) to table
tcplLoadAeid(fld = c("hello", "goodbye"), val = list(0,1)) #error is right! "hello" and "goodbye" are not valid fields to query with


# tcplLoadData
# five levels are available to load and there are four flds to query on, here some combinations
tcplLoadData(lvl = 3, fld = "aeid", val = 891, add.fld = FALSE) # each conc-resp gets its own row
tcplLoadData(lvl = 4, fld = "spid", val = "TP0001055F12", add.fld = FALSE)
tcplLoadData(lvl = 5, fld = "m4id", val = 739695, add.fld = FALSE)
tcplLoadData(lvl = 6, fld = "dtxsid", val = "DTXSID7020182", add.fld = FALSE) # each flag gets its own row
tcplLoadData(lvl = "agg", fld = "aeid", val = 891, add.fld = TRUE) # use add.fld = TRUE (default), if you want every field returned regardless of level and what is normally returned
# error cases
tcplLoadData(lvl = 5, fld = c("aeid", "spid"), val = list(891, "TP0001055F12"), add.fld = FALSE) # can only query by 1 fld for tcplLoadData
tcplLoadData(lvl = 5, fld = "acid", val = 400, add.fld = FALSE) # must query by one of the four supported by ccdR
tcplLoadData(lvl = 2, fld = "aeid", val = 891, add.fld = FALSE) # only levels 3-6 are supported using the API
tcplLoadData(lvl = "agg", fld = "aeid", val = 891, type = "sc", add.fld = FALSE) # only "mc" is supported using the API
tcplLoadData(lvl = 4, fld = "spid", val = "helloworld", add.fld = FALSE) # null data.table return, no "helloworld" spid found
tcplLoadData(lvl = 4, fld = "spid", val = c("TP0001055F12", "helloworld", "goodbye"), add.fld = FALSE) # some data returned if found, rest shows warning that it is missing

the 'pass' parameter. To request a key, send an
email to [email protected].")
if (is.null(host)) options("TCPL_HOST" = "https://api-ccte.epa.gov/bioactivity")
register_ccdr(key = pass)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calling register_ccdr requires @import statement in roxygen skeleton/documentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

purposefully haven't added ccdR imports as they would would make it so you couldn't load the package i thought. Waiting until ccdR is on CRAN

@brown-jason
Copy link
Collaborator

All of the examples you provided could/should be made as unit tests. Let's discuss how we implemented mocking into ccdr and how it can be applied in this situation.

@cthunes
Copy link
Contributor Author

cthunes commented Apr 2, 2024

Imports added. Unit tests are a great idea.

Known problem with CRAN version of ccdR as an import to tcpl: when calling register_ccdr() within tcplConf, an error prints when saving api key for session. However, the key is already saved at the point of error and this does not affect functionality. ccdR team will plan to patch this soon, so I have chosen to not suppress this on the tcpl side, by forcibly fully loading ccdR with if (is.null(getOption('ccdr'))) library('ccdR', quietly = TRUE). This means that for now, we will just ignore the error when running tcplConf.

Copy link
Collaborator

@brown-jason brown-jason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with dev version of ccdr and is working.
l5 <- tcplLoadData(lvl = 5, fld = "DTXSID", val = "DTXSID7020182")
Takes a while to load, we should investigate keys with asif to ensure we have keys for each fld specified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate ccdR into tcplloaddata
2 participants