-
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_linkage_disequilibrium_*() functions and add test for shar…
…ed utility function
- Loading branch information
Showing
6 changed files
with
79 additions
and
33 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,20 +1,21 @@ | ||
#'Get Linkage Disequilibrium By Variant Data | ||
#' Get Linkage Disequilibrium By Variant Data | ||
#' | ||
#'@description | ||
#' - Find linkage disequilibrium (LD) data for a given variant | ||
#' @description Find linkage disequilibrium (LD) data for a given variant | ||
#' | ||
#'[GTEx Portal API | ||
#'documentation](https://gtexportal.org/api/v2/redoc#tag/Datasets-Endpoints/operation/get_linkage_disequilibrium_by_variant_data_api_v2_dataset_ldByVariant_get) | ||
#' [GTEx Portal API | ||
#' documentation](https://gtexportal.org/api/v2/redoc#tag/Datasets-Endpoints/operation/get_linkage_disequilibrium_by_variant_data_api_v2_dataset_ldByVariant_get) | ||
#' | ||
#'@inheritParams gtexr_arguments | ||
#'@return A Tibble | ||
#'@export | ||
#'@family Datasets Endpoints | ||
#' @inheritParams gtexr_arguments | ||
#' @return A tibble. | ||
#' @export | ||
#' @family Datasets Endpoints | ||
#' | ||
#' @examples | ||
#' get_linkage_disequilibrium_by_variant_data() | ||
get_linkage_disequilibrium_by_variant_data <- function(variantId = NULL, | ||
page = 0, | ||
itemsPerPage = 250){ | ||
gtex_query(endpoint = "dataset/ldByVariant") | ||
#' get_linkage_disequilibrium_by_variant_data("chr1_159245536_C_T_b38") | ||
get_linkage_disequilibrium_by_variant_data <- function(variantId, | ||
page = 0, | ||
itemsPerPage = 250) { | ||
resp_body <- gtex_query(endpoint = "dataset/ldByVariant", return_raw = TRUE) | ||
|
||
process_resp_body_linkage_disequilibrium(resp_body) | ||
} |
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
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,17 @@ | ||
process_resp_body_linkage_disequilibrium <- function(resp_body) { | ||
paging_info_messages(resp_body) | ||
|
||
if (rlang::is_empty(resp_body$data)) { | ||
return(tibble::tibble()) | ||
} | ||
|
||
resp_body$data |> | ||
purrr::map(\(x) tibble::tibble(variants = x[[1]], ld = x[[2]])) |> | ||
dplyr::bind_rows() |> | ||
tidyr::separate_wider_delim( | ||
cols = "variants", | ||
delim = ",", | ||
names = c("variantId_1", "variantId_2") | ||
) |> | ||
dplyr::mutate("ld" = as.numeric(.data[["ld"]])) | ||
} |
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,39 @@ | ||
test_that( | ||
"`process_resp_body_linkage_disequilibrium()` handles both valid and empty responses", | ||
{ | ||
# empty response | ||
expect_equal(process_resp_body_linkage_disequilibrium(list( | ||
data = list(), | ||
paging_info = list( | ||
numberOfPages = 0, | ||
page = 0, | ||
maxItemsPerPage = 250, | ||
totalNumberOfItems = 0 | ||
) | ||
)), | ||
tibble::tibble()) | ||
|
||
# valid response (`get_linkage_disequilibrium_by_variant_data("chr1_153209639_T_C_b38")`) | ||
expect_equal( | ||
process_resp_body_linkage_disequilibrium(list( | ||
data = list( | ||
list( | ||
"chr1_153202482_C_T_b38,chr1_153209639_T_C_b38", | ||
"0.28083400000000003" | ||
) | ||
), | ||
paging_info = list( | ||
numberOfPages = 1, | ||
page = 0, | ||
maxItemsPerPage = 250, | ||
totalNumberOfItems = 162 | ||
) | ||
)), | ||
tibble::tibble( | ||
variantId_1 = "chr1_153202482_C_T_b38", | ||
variantId_2 = "chr1_153209639_T_C_b38", | ||
ld = 0.28083400000000003 # should be numeric | ||
) | ||
) | ||
} | ||
) |
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