Skip to content

Commit

Permalink
making compatible with older versions of dplyr (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheridar authored Aug 29, 2023
2 parents 4f27269 + f76c26b commit 1120310
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion R/calc-gene-usage.R
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ plot_gene_pairs <- function(input, data_col, chains, cluster_col = NULL,
n_lab_dat$legend <- n_lab_dat$axis <- n_lab_dat$corner

if ((!is.null(grp_col) || !is.null(clst_col)) && identical(method, "bar")) {
n_lab_dat$axis <- dplyr::rename(df_in, .n = .data$freq)
n_lab_dat$axis <- dplyr::rename(df_in, .n = "freq")
}

# Set common arguments
Expand Down
29 changes: 18 additions & 11 deletions R/import-vdj.R
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ import_vdj <- function(input = NULL, vdj_dir = NULL, prefix = "",
# contigs that did not have any mutations will have NAs
indel_ctigs <- purrr::map(
indel_ctigs,
~ mutate(.x, dplyr::across(all_of(indel_cols), tidyr::replace_na, 0))
~ mutate(.x, dplyr::across(all_of(indel_cols), ~ tidyr::replace_na(.x, 0)))
)

contigs <- indel_ctigs
Expand Down Expand Up @@ -932,11 +932,11 @@ import_vdj <- function(input = NULL, vdj_dir = NULL, prefix = "",

# Get the full length sequence of the vdj region with and without c region
vdj_coords <- vdj_coords %>%
dplyr::mutate(new_len = ifelse(seg == "c", 0, len)) %>%
dplyr::group_by(contig_id) %>%
dplyr::mutate(full_len = sum(len),
full_len_vdj = sum(new_len)) %>%
dplyr::select(!new_len)
dplyr::mutate(new_len = ifelse(.data$seg == "c", 0, .data$len)) %>%
dplyr::group_by(.data$contig_id) %>%
dplyr::mutate(full_len = sum(.data$len),
full_len_vdj = sum(.data$new_len)) %>%
dplyr::select(!"new_len")

mut_coords <- dplyr::mutate(
mut_coords,
Expand All @@ -962,10 +962,17 @@ import_vdj <- function(input = NULL, vdj_dir = NULL, prefix = "",
# some annotations overlap each other! Example: AAACCTGAGAACTGTA-1_contig_1
# left_join + mutate is much faster than valr::bed_intersect, probably due
# to the extreme number of "chromosomes"
vdj_muts <- dplyr::left_join(
mut_coords, vdj_coords, by = "contig_id", suffix = c("", ".seg"),
relationship = "many-to-many"
)
if (utils::packageVersion("dplyr") > "1.1.1") {
# relationship argument gained in 1.1.1 https://dplyr.tidyverse.org/news/index.html
vdj_muts <- dplyr::left_join(
mut_coords, vdj_coords, by = "contig_id", suffix = c("", ".seg"),
relationship = "many-to-many"
)
} else {
vdj_muts <- dplyr::left_join(
mut_coords, vdj_coords, by = "contig_id", suffix = c("", ".seg")
)
}

vdj_muts <- dplyr::filter(
vdj_muts, .data$start < .data$end.seg & .data$end > .data$start.seg
Expand Down Expand Up @@ -1028,7 +1035,7 @@ import_vdj <- function(input = NULL, vdj_dir = NULL, prefix = "",
sum_column <- "full_len"
} else {
all_muts <- all_muts %>%
dplyr::filter(seg != "c")
dplyr::filter(.data$seg != "c")
sum_column <- "full_len_vdj"
}

Expand Down

0 comments on commit 1120310

Please sign in to comment.