-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update get_downloads_page_data() and add test
- Loading branch information
Showing
3 changed files
with
99 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,64 @@ | ||
#'Get Downloads Page Data | ||
#' Get Downloads Page Data | ||
#' | ||
#'@description | ||
#' - Retrieves all the files belonging to the given project_id for display on the Downloads Page | ||
#' @description Retrieves all the files belonging to the given `project_id` for | ||
#' display on the `Downloads Page` | ||
#' | ||
#'[GTEx Portal API | ||
#'documentation](https://gtexportal.org/api/v2/redoc#tag/Datasets-Endpoints/operation/get_downloads_page_data_api_v2_dataset_openAccessFilesMetadata_get) | ||
#' [GTEx Portal API | ||
#' documentation](https://gtexportal.org/api/v2/redoc#tag/Datasets-Endpoints/operation/get_downloads_page_data_api_v2_dataset_openAccessFilesMetadata_get) | ||
#' | ||
#'@inheritParams gtexr_arguments | ||
#' @details Note: The GTEx Portal API documentation states "GTEx currently has | ||
#' one project available: gtex". However, `project_id` values "adult-gtex" and | ||
#' "egtex" both return results, whereas "gtex" does not (see examples). | ||
#' | ||
#'@return A Tibble | ||
#'@export | ||
#'@family Datasets Endpoints | ||
#' @inheritParams gtexr_arguments | ||
#' | ||
#' @return A Tibble | ||
#' @export | ||
#' @family Datasets Endpoints | ||
#' | ||
#' @examples | ||
#' get_downloads_page_data() | ||
#' \dontrun{ | ||
#' # "adult-gtex" (default `project_id` value) and "egtex" both return results | ||
#' get_downloads_page_data() | ||
#' egtex <- get_downloads_page_data("egtex") | ||
#' egtex | ||
#' | ||
#' # ..."gtex" does not | ||
#' get_downloads_page_data("gtex") | ||
#' | ||
#' # get details for whole blood methylation data, including download URL | ||
#' purrr::pluck( | ||
#' egtex$children, | ||
#' 1, | ||
#' "folders", | ||
#' "Methylation - EPIC Array", | ||
#' "children", | ||
#' "folders", | ||
#' "mQTLs", | ||
#' "children", | ||
#' "files", | ||
#' "WholeBlood.mQTLs.regular.txt.gz" | ||
#' ) | ||
#' } | ||
get_downloads_page_data <- function(project_id = "adult-gtex") { | ||
gtex_query(endpoint = "dataset/openAccessFilesMetadata", | ||
return_raw = TRUE)$data |> | ||
purrr::map(tibble::as_tibble) |> | ||
dplyr::bind_rows() | ||
result <- gtex_query(endpoint = "dataset/openAccessFilesMetadata", | ||
return_raw = TRUE) | ||
|
||
result |> | ||
purrr::map(name_unnamed_items, name_item = "displayName") |> | ||
tibble::as_tibble() |> | ||
tidyr::unnest_wider("data") |> | ||
dplyr::arrange(dplyr::pick(dplyr::any_of("order"))) | ||
} | ||
|
||
name_unnamed_items <- function(x, name_item) { | ||
|
||
if (inherits(x, "list")) { | ||
if (is.null(names(x))) { | ||
names(x) <- purrr::map_chr(x, \(item) item[[name_item]]) | ||
} | ||
x <- purrr::map(x, name_unnamed_items, name_item = name_item) | ||
} | ||
|
||
return(x) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
test_that( | ||
"`get_downloads_page_data()` runs without error for `project_id` = 'gtex' (which returns no results)", | ||
{ | ||
expect_equal( | ||
with_mocked_bindings( | ||
code = get_downloads_page_data("gtex"), | ||
gtex_query = function(...) | ||
list(data = list()) | ||
), | ||
tibble::tibble() | ||
) | ||
} | ||
) |