Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed order_rank_by to order.rows.by with deprecation #125

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
changed order_rank_by to order.rows.by with deprecation
Insaynoah committed May 29, 2024

Unverified

This user has not yet uploaded their public signing key.
commit 179e2073738d640f01da4ab593616dd2d33493c3
20 changes: 13 additions & 7 deletions R/plotAbundance.R
Original file line number Diff line number Diff line change
@@ -149,7 +149,8 @@ setMethod("plotAbundance", signature = c("SummarizedExperiment"),
function(x,
rank = taxonomyRanks(x)[1],
features = NULL,
order_rank_by = c("name","abund","revabund"),
order.rows.by = c("name", "abund","revabund"),
order_rank_by = order.rows.by,
order_sample_by = NULL,
decreasing = TRUE,
use_relative = TRUE,
@@ -159,6 +160,10 @@ setMethod("plotAbundance", signature = c("SummarizedExperiment"),
scales = "fixed",
assay.type = assay_name, assay_name = "counts",
...){
# Deprecation check
.Deprecated(old = "order_rank_by", new = "order.rows.by",
"The order_rank_by argument is deprecated.
Please use order.rows.by instead.")
# input checks
if(nrow(x) == 0L){
stop("No data to plot. nrow(x) == 0L.", call. = FALSE)
@@ -187,14 +192,14 @@ setMethod("plotAbundance", signature = c("SummarizedExperiment"),
.check_taxonomic_rank(rank, x)
.check_for_taxonomic_data_order(x)
layout <- match.arg(layout, c("bar","point"))
order_rank_by <- match.arg(order_rank_by, c("name","abund","revabund"))
order.rows.by <- match.arg(order.rows.by, c("name","abund","revabund"))
.check_abund_plot_args(one_facet = one_facet,
ncol = ncol)
if( !is.null(features) ){
features <- match.arg(features, colnames(colData(x)))
}
########################### INPUT CHECK END ###########################
abund_data <- .get_abundance_data(x, rank, assay.type, order_rank_by,
abund_data <- .get_abundance_data(x, rank, assay.type, order.rows.by,
use_relative)
order_sample_by <- .norm_order_sample_by(order_sample_by,
unique(abund_data$colour_by),
@@ -253,7 +258,8 @@ MELT_VALUES <- "Value"
#' @importFrom tidyr pivot_longer nest unnest
#' @importFrom tibble rownames_to_column
#' @importFrom purrr map
.get_abundance_data <- function(x, rank, assay.type, order_rank_by = "name",
.get_abundance_data <- function(x, rank, assay.type, order.rows.by = "name",
order_rank_by = order.rows.by,
use_relative = TRUE){
data <- assay(x, assay.type, withDimnames = TRUE)
if(use_relative){
@@ -287,15 +293,15 @@ MELT_VALUES <- "Value"
X = MELT_NAME,
Y = MELT_VALUES)
# order values
if(order_rank_by == "name"){
if(order.rows.by == "name"){
lvl <- levels(data$colour_by)
lvl <- lvl[order(lvl)]
} else if(order_rank_by %in% c("abund","revabund")){
} else if(order.rows.by %in% c("abund","revabund")){
o <- data %>%
select(!.data$X) %>%
group_by(.data$colour_by) %>%
summarize(sum = sum(.data$Y))
decreasing <- ifelse(order_rank_by == "abund",TRUE,FALSE)
decreasing <- ifelse(order.rows.by == "abund",TRUE,FALSE)
lvl <- o[order(o$sum, decreasing = decreasing),] %>%
pull(.data$colour_by) %>%
as.character()
6 changes: 3 additions & 3 deletions tests/testthat/test-2plotAbundance.R
Original file line number Diff line number Diff line change
@@ -18,13 +18,13 @@ test_that("plot abundance", {
expect_true(is.factor(actual$X))
expect_true(is.numeric(actual$Y))
expect_error(miaViz:::.get_abundance_data(x,"Phylum","counts",
order_rank_by = "meep"))
order.rows.by = "meep"))
actual2 <- miaViz:::.get_abundance_data(x,"Phylum","counts",
order_rank_by = "abund")
order.rows.by = "abund")
expect_equal(as.character(actual[1,1,drop=TRUE]),"ABY1_OD1")
expect_equal(as.character(actual2[1,1,drop=TRUE]),"Proteobacteria")
actual3 <- miaViz:::.get_abundance_data(x,"Phylum","counts",
order_rank_by = "abund",
order.rows.by = "abund",
use_relative = FALSE)
expect_true(max(actual3$Y) > 1)
# .norm_order_sample_by