Skip to content

Commit

Permalink
Merge pull request #2 from bzhanglab/cran_comments
Browse files Browse the repository at this point in the history
Address cran comments
  • Loading branch information
iblacksand authored Jun 24, 2024
2 parents 584cc51 + 622c930 commit c939707
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 48 deletions.
3 changes: 2 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
^pkgdown$
^\.github$
^man\\figures\.gitkeep$
^man/figures/\.gitkeep$
^man/figures/\.gitkeep$
^CRAN-SUBMISSION$
3 changes: 3 additions & 0 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Version: 1.0.4
Date: 2024-06-18 18:58:59 UTC
SHA: 584cc5189e1e0674fdbb7b28fedda3b4de5a2d87
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ Description: Provides an interface to the 'ClinicalOmicsDB' API, allowing for ea
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Imports: httr2, R6, dplyr, utils, jsonlite
BugReports: https://github.com/bzhanglab/clinicalomicsdbR/issues/new
34 changes: 18 additions & 16 deletions R/clinicalomicsdbR.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ clinicalomicsdbR <- R6Class("clinicalomicsdbR", list(
hostname = "https://trials.linkedomics.org",
#' @field study_list The list of all the studies that are a result of filtering.
study_list = c(),
#' @field verbosity The level of messages wanted for downloads (defaults to 0: No Output). Follows httr2 documentatation for `req_perform`
verbosity = 0,
#' @description
#' filter objects according to the specified drugs and cancers
#' @param drugs list or vector containing drugs that studies need to contain at least one of
Expand Down Expand Up @@ -52,10 +54,10 @@ clinicalomicsdbR <- R6Class("clinicalomicsdbR", list(
\"cancers\": ", cancer_text, "
}
"))
resp <- req_perform(req)
resp <- req_perform(req, verbosity = self$verbosity)
filter_res <- resp %>% resp_body_json()
self$study_list <- unlist(filter_res$study_list)
print(paste0("Filtered to ", length(self$study_list), " studies."))
message(paste0("Filtered to ", length(self$study_list), " studies."))
invisible(self)
},
#' @description
Expand All @@ -67,47 +69,47 @@ clinicalomicsdbR <- R6Class("clinicalomicsdbR", list(
req <- req %>%
req_method("GET") %>%
req_headers("Accept" = "application/json, text/plain")
resp <- req_perform(req)
resp <- req_perform(req, verbosity = self$verbosity)
resp_json <- resp %>% resp_body_json()
return(resp_json$download_url)
},
#' @description
#' Download all files of the studies in `self$study_list`. Use `filter` function first
#' @param output_dir Directory to download files to. Default to `clindb`
#' @param output_dir Directory to download files to.
#' @return unmodifed clinicalomicsdbR object
download = function(output_dir = "clindb") {
download = function(output_dir) {
cidr <- getwd()
dir.create(file.path(cidr, output_dir), recursive = TRUE, showWarnings = FALSE)
for (study_id in self$study_list) {
dl_url <- self$get_download_url(study_id)
print(paste0("Downloading study ", study_id, " from ", dl_url))
message(paste0("Downloading study ", study_id, " from ", dl_url))
download.file(dl_url, paste0(output_dir, "/", study_id))
}
print(paste0("Downloaded ", length(self$study_list), " studies."))
message(paste0("Downloaded ", length(self$study_list), " studies."))
invisible(self)
},
#' @description
#' Download all file from `study_id` into `output_dir` directory
#' @param study_id String containing the ID of the study to download
#' @param output_dir Directory to download files to. Default to `clindb`
#' @param output_dir Directory to download files to.
#' @return unmodifed clinicalomicsdbR object
download_from_id = function(study_id, output_dir = "clindb") {
download_from_id = function(study_id) {
cidr <- getwd()
dir.create(file.path(cidr, output_dir), recursive = TRUE, showWarnings = FALSE)
dl_url <- self$get_download_url(study_id)
tryCatch(
{
print(paste0("Downloading study ", study_id, " from ", dl_url))
message(paste0("Downloading study ", study_id, " from ", dl_url))
download.file(dl_url, paste0(output_dir, "/", study_id))
print("Done downloading study.")
message("Done downloading study.")
invisible(self)
},
error = function(err) {
print(paste0("Error fetching study with ID: ", study_id, ".\nVerify ID is correct or change hostname."))
message(paste0("Error fetching study with ID: ", study_id, ".\nVerify ID is correct or change hostname."))
stop(paste0("Could not fetch study: ", study_id))
},
warning = function(warn) {
print(paste0("Warning fetching study with ID: ", study_id, ".\nVerify ID is correct or change hostname."))
message(paste0("Warning fetching study with ID: ", study_id, ".\nVerify ID is correct or change hostname."))
warn(paste0("Warning with study: ", study_id))
}
)
Expand All @@ -130,15 +132,15 @@ clinicalomicsdbR <- R6Class("clinicalomicsdbR", list(
tryCatch(
{
dl_url <- self$get_download_url(study_id)
print(paste0("Getting dataframe of study ", study_id, " from ", dl_url))
message(paste0("Getting dataframe of study ", study_id, " from ", dl_url))
return(read.csv(dl_url))
},
error = function(err) {
print(paste0("Error fetching study with ID: ", study_id, ".\nVerify ID is correct or change hostname."))
message(paste0("Error fetching study with ID: ", study_id, ".\nVerify ID is correct or change hostname."))
stop(paste0("Could not fetch study: ", study_id))
},
warning = function(warn) {
print(paste0("Warning fetching study with ID: ", study_id, ".\nVerify ID is correct or change hostname."))
message(paste0("Warning fetching study with ID: ", study_id, ".\nVerify ID is correct or change hostname."))
warn(paste0("Warning with study: ", study_id))
}
)
Expand Down
9 changes: 3 additions & 6 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@ See Examples below to see how to use.
combinations. See the ClinicalOmicsDB website for all options.
`cancers` can contain multiple cancers.
- `download(output_dir)` - downloads all studies from `filter()` into
`output_dir`. `output_dir` is optional, and defaults to `clindb`
`output_dir`.
- `dataframe()` - loads all the studies from `filter()` into a
list, with column `study_list` that contains the names of the
studies and `df` that contains a list of the study data information.
- `dataframe_from_id(study_id)` - loads a study with id from `study_id` into a dataframe
- `downlaod_from_id(study_id, output_dir)` - downsloads a study with id from `study_id` into a folder `output_dir`. `output_dir` defaults to `clindb`

- `download_from_id(study_id, output_dir)` - downsloads a study with id from `study_id` into a folder `output_dir`.
See the examples below for more information on how to use.

## Examples
Expand All @@ -69,12 +68,10 @@ See the examples below for more information on how to use.

Filters studies for those which used rituximab or ipilimumab then downloads them to the `studies` folder.

*Notes*: `output_dir` is optional. Defaults to `clindb`.

```{r example}
library(clinicalomicsdbR)
clinicalomicsdbR$new()$filter(drugs = c("ipilimumab", "rituximab"))$download(output_dir = "studies") # downloads all files
clinicalomicsdbR$new()$filter(drugs = c("ipilimumab", "rituximab"))$download(output_dir = tempdir()) # downloads all files
```

### Filter and Get Data Frame
Expand Down
39 changes: 19 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,15 @@ See Examples below to see how to use.
combinations. See the ClinicalOmicsDB website for all options.
`cancers` can contain multiple cancers.
- `download(output_dir)` - downloads all studies from `filter()` into
`output_dir`. `output_dir` is optional, and defaults to `clindb`
`output_dir`.
- `dataframe()` - loads all the studies from `filter()` into a list,
with column `study_list` that contains the names of the studies and
`df` that contains a list of the study data information.
- `dataframe_from_id(study_id)` - loads a study with id from `study_id`
into a dataframe
- `downlaod_from_id(study_id, output_dir)` - downsloads a study with id
from `study_id` into a folder `output_dir`. `output_dir` defaults to
`clindb`

See the examples below for more information on how to use.
- `download_from_id(study_id, output_dir)` - downsloads a study with id
from `study_id` into a folder `output_dir`. See the examples below for
more information on how to use.

## Examples

Expand All @@ -67,18 +65,16 @@ See the examples below for more information on how to use.
Filters studies for those which used rituximab or ipilimumab then
downloads them to the `studies` folder.

*Notes*: `output_dir` is optional. Defaults to `clindb`.

``` r
library(clinicalomicsdbR)

clinicalomicsdbR$new()$filter(drugs = c("ipilimumab", "rituximab"))$download(output_dir = "studies") # downloads all files
#> [1] "Filtered to 4 studies."
#> [1] "Downloading study Gide_Cell_2019_pembro_ipi.csv from https://bcm.box.com/shared/static/swf5fywqcqmf75600g7v8irt2a9agnqo.csv"
#> [1] "Downloading study VanAllen_antiCTLA4_2015.csv from https://bcm.box.com/shared/static/v0sphd7ht487qk96xbwjokgkbkjpexom.csv"
#> [1] "Downloading study Gide_Cell_2019_nivo_ipi.csv from https://bcm.box.com/shared/static/jwv108f6cy4kvyeqer95jdugla53m1zt.csv"
#> [1] "Downloading study GSE35935.csv from https://bcm.box.com/shared/static/8icr4i6gbbp6lgd01iscbss4v7lnj6c5.csv"
#> [1] "Downloaded 4 studies."
clinicalomicsdbR$new()$filter(drugs = c("ipilimumab", "rituximab"))$download(output_dir = tempdir()) # downloads all files
#> Filtered to 4 studies.
#> Downloading study Gide_Cell_2019_pembro_ipi.csv from https://bcm.box.com/shared/static/swf5fywqcqmf75600g7v8irt2a9agnqo.csv
#> Downloading study VanAllen_antiCTLA4_2015.csv from https://bcm.box.com/shared/static/v0sphd7ht487qk96xbwjokgkbkjpexom.csv
#> Downloading study Gide_Cell_2019_nivo_ipi.csv from https://bcm.box.com/shared/static/jwv108f6cy4kvyeqer95jdugla53m1zt.csv
#> Downloading study GSE35935.csv from https://bcm.box.com/shared/static/8icr4i6gbbp6lgd01iscbss4v7lnj6c5.csv
#> Downloaded 4 studies.
```

### Filter and Get Data Frame
Expand All @@ -92,11 +88,14 @@ data frame.
library(clinicalomicsdbR)

res <- clinicalomicsdbR$new()$filter(drugs = c("ipilimumab", "rituximab"))$dataframe(); # downloads all files
#> [1] "Filtered to 4 studies."
#> [1] "Getting dataframe of study Gide_Cell_2019_pembro_ipi.csv from https://bcm.box.com/shared/static/swf5fywqcqmf75600g7v8irt2a9agnqo.csv"
#> [1] "Getting dataframe of study VanAllen_antiCTLA4_2015.csv from https://bcm.box.com/shared/static/v0sphd7ht487qk96xbwjokgkbkjpexom.csv"
#> [1] "Getting dataframe of study Gide_Cell_2019_nivo_ipi.csv from https://bcm.box.com/shared/static/jwv108f6cy4kvyeqer95jdugla53m1zt.csv"
#> [1] "Getting dataframe of study GSE35935.csv from https://bcm.box.com/shared/static/8icr4i6gbbp6lgd01iscbss4v7lnj6c5.csv"
#> Filtered to 4 studies.
#> Getting dataframe of study Gide_Cell_2019_pembro_ipi.csv from https://bcm.box.com/shared/static/swf5fywqcqmf75600g7v8irt2a9agnqo.csv
#> Getting dataframe of study VanAllen_antiCTLA4_2015.csv from https://bcm.box.com/shared/static/v0sphd7ht487qk96xbwjokgkbkjpexom.csv
#> Getting dataframe of study Gide_Cell_2019_nivo_ipi.csv from https://bcm.box.com/shared/static/jwv108f6cy4kvyeqer95jdugla53m1zt.csv
#> Getting dataframe of study GSE35935.csv from https://bcm.box.com/shared/static/8icr4i6gbbp6lgd01iscbss4v7lnj6c5.csv
```

``` r

for (study in res[["study_list"]]) {
print(ncol(res[["df"]][[study]]))
Expand Down
10 changes: 6 additions & 4 deletions man/clinicalomicsdbR.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c939707

Please sign in to comment.