-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reinstating Bioplanet with a graceful fail
- Loading branch information
1 parent
1e39d2b
commit bd42aae
Showing
10 changed files
with
122 additions
and
4 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
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
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,48 @@ | ||
#' URL of Bioplanet pathway file | ||
#' | ||
#' @return A string with URL. | ||
#' @noRd | ||
get_bioplanet_pathway_file <- function() { | ||
getOption("BIOPLANET_PATHWAY_FILE", "https://tripod.nih.gov/bioplanet/download/pathway.csv") | ||
} | ||
|
||
#' Get functional term data from BioPlanet | ||
#' | ||
#' Download term information (term ID and name) and gene-pathway mapping | ||
#' (NCBI gene ID, gene symbol and pathway ID) from BioPlanet. | ||
#' | ||
#' @param use_cache Logical, if TRUE, the remote file will be cached locally. | ||
#' @param on_error A character vector specifying the error handling method. It | ||
#' can take values `"stop"` or `"warn"`. The default is `"stop"`. `"stop"` | ||
#' will halt the function execution and throw an error, while `"warn"` will | ||
#' issue a warning and return `NULL`. | ||
#' @return A list with \code{terms} and \code{mapping} tibbles. | ||
#' @export | ||
#' @examples | ||
#' bioplanet_data <- fetch_bp(on_error = "warn") | ||
fetch_bp <- function(use_cache = TRUE, on_error = c("stop", "warn")) { | ||
on_error <- match.arg(on_error) | ||
|
||
# Binding variables from non-standard evaluation locally | ||
PATHWAY_ID <- PATHWAY_NAME <- GENE_ID <- GENE_SYMBOL <- NULL | ||
|
||
pathway_file <- get_bioplanet_pathway_file() | ||
if(!assert_url_path(pathway_file, on_error)) | ||
return(NULL) | ||
|
||
lpath <- cached_url_path("bioplanet_pathway", pathway_file, use_cache) | ||
paths <- readr::read_csv(lpath, show_col_types = FALSE) | ||
|
||
terms <- paths |> | ||
dplyr::select(term_id = PATHWAY_ID, term_name = PATHWAY_NAME) |> | ||
dplyr::distinct() | ||
|
||
mapping <- paths |> | ||
dplyr::select(term_id = PATHWAY_ID, ncbi_id = GENE_ID, gene_symbol = GENE_SYMBOL) |> | ||
dplyr::distinct() | ||
|
||
list( | ||
terms = terms, | ||
mapping = mapping | ||
) | ||
} |
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
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,31 @@ | ||
expected_mapping <- tibble::tribble( | ||
~term_id, ~gene_symbol, | ||
"bioplanet_1025", "CDK1", | ||
"bioplanet_120", "IL1A", | ||
"bioplanet_1755", "RPL6", | ||
"bioplanet_1121", "POLR1A" | ||
) | ||
|
||
test_that("Bioplanet mapping makes sense", { | ||
bp <- fetch_bp(on_error = "warn") | ||
if(!is.null(bp)) { | ||
expect_is(bp, "list") | ||
expect_setequal(names(bp), c("terms", "mapping")) | ||
mapping <- bp$mapping | ||
|
||
merged <- expected_mapping |> | ||
dplyr::left_join(mapping, by = c("term_id", "gene_symbol")) |> | ||
tidyr::drop_na() | ||
|
||
expect_equal(nrow(expected_mapping), nrow(merged)) | ||
} | ||
}) | ||
|
||
|
||
test_that("Expected behaviour from a non-responsive server", { | ||
httr2::with_mocked_responses( | ||
mock = mocked_500, | ||
code = { | ||
test_unresponsive_server(fetch_bp, use_cache = FALSE) | ||
}) | ||
}) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.