Skip to content

Commit

Permalink
refactor: remove deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Curro Campuzano committed Jul 17, 2023
1 parent edfc834 commit bbc89e8
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 28 deletions.
14 changes: 8 additions & 6 deletions R/add_physicochemical_properties_to_HMMER_tbl.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,16 @@ add_physicochemical_properties_to_HMMER_tbl <- function(data, colname = "hits.fu
data %>%
dplyr::group_by(!!group_var) %>%
dplyr::group_split() %>%
purrr::map_dfr(function(x) {
purrr::map(\(x) {
x %>% dplyr::bind_cols(inner_function(x[[colname]][[1]]))
})
}) %>%
dplyr::bind_rows()
}

calculate_peptides <- function(y) { # nolint
Peptides::aaComp(y) %>%
purrr::map_dfr(~ {
as.data.frame(.x) %>%
purrr::map(\(x) {
as.data.frame(x) %>%
tibble::rownames_to_column("properties") %>%
dplyr::rename("Percentage" = "Mole%") %>%
dplyr::select(c("Percentage", "properties")) %>%
Expand All @@ -100,7 +101,8 @@ calculate_peptides <- function(y) { # nolint
values_from = c("Percentage")
) %>%
dplyr::mutate(
dplyr::across(where(is.numeric), ~ .x / 100)
dplyr::across(tidyselect::where(is.numeric), ~ .x / 100)
)
})
}) %>%
dplyr::bind_rows()
}
9 changes: 3 additions & 6 deletions R/add_sequences_to_hmmer_tbl.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ add_sequences_to_hmmer_tbl <- function(data, extension = "fullfasta", max_times
}
)
group_var <- rlang::sym("uuid")
data %>%
data <- data %>%
dplyr::group_by(!!group_var) %>%
dplyr::group_split() %>%
purrr::map_dfr(inner_function) %>%
delete_na_rows()
}

delete_na_rows <- function(data) {
purrr::map(inner_function) %>%
purrr::bind_rows()
data[rowSums(is.na(data)) <= nrow(data), ]
}

Expand Down
3 changes: 2 additions & 1 deletion R/add_taxa_to_hmmer_tbl.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ add_taxa_to_hmmer_tbl <- function(data, mode = "remote", rank_vc = NULL) { # nol
data %>%
dplyr::group_by(!!group_var) %>%
dplyr::group_split() %>%
purrr::map_dfr(~ purrr::possibly(inner_function, .)(.))
purrr::map(~ purrr::possibly(inner_function, .)(.)) %>%
purrr::bind_rows()
}
3 changes: 2 additions & 1 deletion R/read_hmmer_from_json.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ read_hmmer_from_json <- function(file) { # nolint
parse_results_into_tbl()
}
)
purrr::map_dfr(.x = file, .id = "file", .f = inner_function)
purrr::map(.x = file, .id = "file", .f = inner_function) %>%
dplyr::bind_rows()
}
7 changes: 3 additions & 4 deletions R/search_hmmsearch.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ search_hmmsearch <- function(aln, seqdb = "swissprot", timeout = 180, verbose =
hmmsearch <- purrr::possibly(search_in_hmmer, otherwise = NULL) # nolint
# all combinations of inputs
seq <- ifelse(is.list(aln), aln, list(aln)) %>%
purrr::map_chr(function(x) {
Biostrings::unmasked(x) %>%
format_AAStringSet_into_hmmer_string()
})
purrr::map(\(x) Biostrings::unmasked(x) %>%
format_AAStringSet_into_hmmer_string()) %>%
as.character()
tidyr::expand_grid(seq, seqdb, algorithm = "hmmsearch") %>%
dplyr::rowwise() %>%
purrr::pmap(
Expand Down
6 changes: 3 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ download_file <- function(url) { # nolint
return(temp)
}

check_if_url <- function(urls) {
purrr::map_lgl(
check_if_url <- function(urls) { # nolint
purrr::map(
urls,
purrr::possibly(
Negate(httr::http_error),
otherwise = FALSE
)
)
) %>% as.logical()
}

convert_input_seq <- function(seq) {
Expand Down
15 changes: 8 additions & 7 deletions tests/testthat/test-pairwise_aligment.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
testthat::test_that("Test that pairwise_alignment_sequence_identity works with missing values", {
phmmer_2abl$hits.fullfasta %>%
pairwise_alignment_sequence_identity() %>%
expect_snapshot_value(style = "deparse")
})
"Test that pairwise_alignment_sequence_identity works with missing values" %>%
testthat::test_that({
phmmer_2abl$hits.fullfasta %>%
pairwise_alignment_sequence_identity() %>%
expect_snapshot_value(style = "deparse")
})

testthat::test_that("Test that pairwise plots work", {
phmmer_2abl$hits.fullfasta %>%
pairwise_alignment_sequence_identity() -> data
data <- phmmer_2abl$hits.fullfasta %>%
pairwise_alignment_sequence_identity()
hist_plot <- pairwise_sequence_identity_histogram(data)
vdiffr::expect_doppelganger("Base graphics histogram", hist_plot)
heatmap_plot <- pairwise_sequence_identity_heatmap(data)
Expand Down

0 comments on commit bbc89e8

Please sign in to comment.