R/utils.R

Defines functions convert_input_seq check_if_url download_file

# Download a file using a temp file (it should work in every OS).
#
# @param url a string with an URL.
download_file <- function(url) {
    temp <- tempfile()
    url %>% utils::download.file(temp, mode = "wb", method = "libcurl")
    return(temp)
}

check_if_url <- function(urls) {
    purrr::map_lgl(
        urls,
        purrr::possibly(
            Negate(httr::http_error),
            otherwise = FALSE
        )
    )
}

convert_input_seq <- function(seq) {
    seq <- as.character(seq)
    if (all(file.exists(seq)) || all(check_if_url(seq))) {
        seq <- Biostrings::readAAStringSet(seq)
    }
    as.character(seq)
}
currocam/utilsHMMER documentation built on Feb. 19, 2023, 9:54 p.m.