-
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.
- Loading branch information
Curro Campuzano
committed
Jul 19, 2023
1 parent
bbc89e8
commit 084b7cf
Showing
4 changed files
with
108 additions
and
23 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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
hmmer_request <- function( | ||
algo, ..., seq = NULL, hmmdb = NULL, seqdb = NULL, max_tries = 5) { | ||
if (length(c(seqdb, hmmdb)) != 1) { | ||
stop("You must specify either a seqdb or a hmmdb, not both.") | ||
} | ||
body <- list( | ||
..., | ||
seq = seq, | ||
hmmdb = hmmdb, | ||
seqdb = seqdb | ||
) |> | ||
purrr::compact() | ||
|
||
user_agent_string <- "HMMERutils (https://github.com/currocam/HMMERutils)" | ||
httr2::request("https://www.ebi.ac.uk/Tools/hmmer/search") |> | ||
httr2::req_user_agent(user_agent_string) |> | ||
httr2::req_headers("Accept" = "application/json") |> | ||
httr2::req_url_path_append(algo) |> | ||
httr2::req_retry(max_tries = max_tries) |> | ||
httr2::req_body_json(body) | ||
} | ||
|
||
resp_get_uuid <- function(req) { | ||
purrr::chuck(req, "url") |> | ||
stringr::str_split("/") |> | ||
purrr::chuck(1, 7) | ||
} | ||
|
||
req_perform_custom <- function(r) { | ||
response <- httr2::req_perform(r, path = tempfile()) | ||
Sys.sleep(15) | ||
response | ||
} | ||
|
||
|
||
multi_req_perform_custom <- function(requests) { | ||
f <- purrr::possibly(req_perform_custom, otherwise = NULL, quiet = FALSE) | ||
responses <- purrr::map(requests, f) | ||
names(responses) <- purrr::map(responses, "url") |> as.character() | ||
responses | ||
} | ||
|
||
add_fullfasta <- function(data, uuid) { | ||
fasta <- uuid |> | ||
create_download_url_for_hmmer("fullfasta") |> | ||
download_file() |> | ||
Biostrings::readAAStringSet() | ||
tibble::tibble(hits.name = names(fasta), hits.fullfasta = as.character(fasta)) |> | ||
dplyr::full_join(data, by = "hits.name") | ||
} |
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,19 @@ | ||
# base request works | ||
|
||
Code | ||
hmmer_request(algo = "phmmer", seq = "AAACATT", seqdb = "swissprot") | ||
Message <cliMessage> | ||
<httr2_request> | ||
POST https://www.ebi.ac.uk/Tools/hmmer/search/phmmer | ||
Headers: | ||
* Accept: 'application/json' | ||
Body: json encoded data | ||
Options: | ||
* useragent: 'HMMERutils (http://github.com/currocam/HMMERutils/)' | ||
Policies: | ||
* retry_max_tries: 5 | ||
|
||
# base request fails when both seqdb and hmmdb | ||
|
||
You must specify either a seqdb or a hmmdb, not both. | ||
|
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,9 @@ | ||
test_that("base request works", { | ||
hmmer_request(algo = "phmmer", seq = "AAACATT", seqdb = "swissprot") |> | ||
testthat::expect_snapshot() | ||
}) | ||
|
||
test_that("base request fails when both seqdb and hmmdb", { | ||
hmmer_request(algo = "phmmer", seq = "AAACATT",hmmdb = "pfam", seqdb = "swissprot") |> | ||
testthat::expect_snapshot_error() | ||
}) |