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

deprecate Taxa names -> Features #91

Merged
merged 25 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
4 changes: 3 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(plotCCA)
export(plotColGraph)
export(plotColTile)
export(plotDMNFit)
export(plotFeaturePrevalence)
export(plotPrevalence)
export(plotPrevalentAbundance)
export(plotRDA)
Expand All @@ -23,6 +24,7 @@ exportMethods(plotColGraph)
exportMethods(plotColTile)
exportMethods(plotColTree)
exportMethods(plotDMNFit)
exportMethods(plotFeaturePrevalence)
exportMethods(plotPrevalence)
exportMethods(plotPrevalentAbundance)
exportMethods(plotRDA)
Expand Down Expand Up @@ -74,7 +76,7 @@ importFrom(dplyr,ungroup)
importFrom(ggnewscale,new_scale)
importFrom(ggnewscale,new_scale_colour)
importFrom(ggnewscale,new_scale_fill)
importFrom(ggplot2,aes_string)
importFrom(ggplot2,aes)
importFrom(ggplot2,coord_flip)
importFrom(ggplot2,element_blank)
importFrom(ggplot2,element_text)
Expand Down
14 changes: 7 additions & 7 deletions R/plotAbundance.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
#' # Getting top taxa on a Phylum level
#' se <- transformAssay(se, method="relabundance")
#' se_phylum <- agglomerateByRank(se, rank ="Phylum", onRankOnly=TRUE)
#' top_taxa <- getTopTaxa(se_phylum,top = 5, assay.type = "relabundance")
#' top_taxa <- getTopFeatures(se_phylum,top = 5, assay.type = "relabundance")
#'
#' # Renaming the "Phylum" rank to keep only top taxa and the rest to "Other"
#' phylum_renamed <- lapply(rowData(se)$Phylum,
Expand Down Expand Up @@ -274,7 +274,7 @@ MELT_VALUES <- "Value"
data <- data %>%
as.data.frame() %>%
mutate(rank = factor(rowData(x)[,rank], unique(rowData(x)[,rank]))) %>%
pivot_longer(cols = !.data$rank,
pivot_longer(cols = !rank,
names_to = MELT_NAME,
values_to = MELT_VALUES) %>%
mutate(!!sym(MELT_NAME) := factor(!!sym(MELT_NAME), unique(!!sym(MELT_NAME)))) %>%
Expand All @@ -292,7 +292,7 @@ MELT_VALUES <- "Value"
lvl <- lvl[order(lvl)]
} else if(order_rank_by %in% c("abund","revabund")){
o <- data %>%
select(!.data$X) %>%
select(!.data$X) %>%
group_by(.data$colour_by) %>%
summarize(sum = sum(.data$Y))
decreasing <- ifelse(order_rank_by == "abund",TRUE,FALSE)
Expand All @@ -304,7 +304,7 @@ MELT_VALUES <- "Value"
}
data$colour_by <- factor(data$colour_by, lvl)
data <- data[order(data$colour_by),]
#

data
}

Expand Down Expand Up @@ -424,7 +424,7 @@ MELT_VALUES <- "Value"
point_alpha = 1,
point_size = 2){
# start plotting
plot_out <- ggplot(object, aes_string(x="X", y="Y")) +
plot_out <- ggplot(object, aes(x=.data[["X"]], y=.data[["Y"]])) +
xlab(xlab) +
ylab(ylab)
# either bar or point plot
Expand Down Expand Up @@ -471,7 +471,7 @@ MELT_VALUES <- "Value"
plot_out
}

#' @importFrom ggplot2 ggplot aes_string labs geom_point geom_raster
#' @importFrom ggplot2 ggplot aes labs geom_point geom_raster
.feature_plotter <- function(feature_data,
name,
xlab,
Expand All @@ -485,7 +485,7 @@ MELT_VALUES <- "Value"
feature_data$Y <- ""
colour_by <- unique(feature_data$feature_name)
}
feature_plot_out <- ggplot(feature_data, aes_string(x="X", y="Y")) +
feature_plot_out <- ggplot(feature_data, aes(x=.data[["X"]], y=.data[["Y"]])) +
labs(x = xlab, y = name)
if(length(unique(feature_data$Y)) == 1L){
feature_out <- .get_bar_args(colour_by,
Expand Down
4 changes: 2 additions & 2 deletions R/plotAbundanceDensity.R
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ setMethod("plotAbundanceDensity", signature = c(object = "SummarizedExperiment")
# Gets the assay
mat <- assay(object, assay.type, withDimnames = TRUE)
# Gets the most abundant taxa
top_taxa <- getTopTaxa(object, top = n, assay.type = assay.type)
top_taxa <- getTopFeatures(object, top = n, assay.type = assay.type)
# Subsets abundance table by taking taxa of highest abundance
mat <- mat[top_taxa, , drop=FALSE]
# enable conversion to data.frame for non-matrix assays, e.g. sparseMatrices
Expand Down Expand Up @@ -282,7 +282,7 @@ setMethod("plotAbundanceDensity", signature = c(object = "SummarizedExperiment")
scales_free = TRUE,
angle_x_text = TRUE){
# start plotting
plot_out <- ggplot(density_data, aes_string(x="X")) +
plot_out <- ggplot(density_data, aes(x=.data[["X"]])) +
xlab(xlab) +
ylab(ylab)
# Layout can be "density", "jitter", or "point"
Expand Down
3 changes: 1 addition & 2 deletions R/plotCCA.R
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ setMethod("plotRDA", signature = c(object = "matrix"),
parse.labels = TRUE, vec.text = TRUE, repel.labels = TRUE, add.ellipse = TRUE,
position = NULL, nudge_x = NULL, nudge_y = NULL, direction = "both",
max.overlaps = 10, check_overlap = FALSE, ...){

# Get the scatter plot
plot <- plot_data[["plot"]]
# Add ellipse
Expand All @@ -517,7 +516,7 @@ setMethod("plotRDA", signature = c(object = "matrix"),
aes(x = .data[[xvar]], y = .data[[yvar]],
color = .data[[colour_var]], fill = after_scale(color)),
geom = "polygon", alpha = ellipse.alpha,
size = ellipse.linewidth, linetype = ellipse.linetype)
linewidth = ellipse.linewidth, linetype = ellipse.linetype)
} else if ( add.ellipse %in% c("color", "colour") ){
plot <- plot +
stat_ellipse(data = data,
Expand Down
4 changes: 2 additions & 2 deletions R/plotDMN.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ setGeneric("plotDMNFit", signature = "x",

#' @rdname plotDMN
#' @importFrom DirichletMultinomial mixture
#' @importFrom ggplot2 ggplot aes_string geom_point geom_line theme_bw labs
#' @importFrom ggplot2 ggplot aes geom_point geom_line theme_bw labs
#' @export
setMethod("plotDMNFit", signature = c(x = "SummarizedExperiment"),
function(x, name = "DMN", type = c("laplace","AIC","BIC")){
Expand All @@ -62,7 +62,7 @@ setMethod("plotDMNFit", signature = c(x = "SummarizedExperiment"),
#
k <- vapply(dmn, function(d){ncol(mixture(d))}, numeric(1))
fit <- vapply(dmn, fit_FUN, numeric(1))
ggplot(data.frame(k = k, fit = fit), aes_string(x = k, y = fit)) +
ggplot(data.frame(k = k, fit = fit), aes(x = k, y = fit)) +
geom_point() +
geom_line() +
theme_bw() +
Expand Down
5 changes: 3 additions & 2 deletions R/plotGraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,11 @@ setMethod("plotRowGraph",

#' @importFrom tidyr drop_na
.add_graph_labels <- function(plot_out, show_label){
label <- NULL # disable note: no global binding for variable
if(show_label){
label_data <- plot_out$data %>% drop_na(.data$label)
label_data <- plot_out$data %>% drop_na(label)
plot_out <- plot_out +
geom_node_label(mapping = aes_string(label = "label"),
geom_node_label(mapping = aes(label = .data[["label"]]),
data = label_data,
repel = TRUE,
max.overlaps = 100)
Expand Down
42 changes: 30 additions & 12 deletions R/plotPrevalence.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#' Plot prevalence information
#'
#' \code{plotPrevalence} and \code{plotTaxaPrevalence} visualize prevalence
#' \code{plotPrevalence} and \code{plotFeaturePrevalence} visualize prevalence
#' information.
#'
#' Whereas \code{plotPrevalence} produces a line plot, \code{plotTaxaPrevalence}
#' Whereas \code{plotPrevalence} produces a line plot, \code{plotFeaturePrevalence}
#' returns a heatmap.
#'
#' @param x a
Expand Down Expand Up @@ -100,14 +100,14 @@
#' plotPrevalence(GlobalPatterns, rank = "Phylum") + scale_x_log10()
#'
#' # plotting prevalence per taxa for different detection thresholds as heatmap
#' plotTaxaPrevalence(GlobalPatterns, rank = "Phylum")
#' plotFeaturePrevalence(GlobalPatterns, rank = "Phylum")
#'
#' # by default a continuous scale is used for different detection levels,
#' # but this can be adjusted
#' plotTaxaPrevalence(GlobalPatterns, rank = "Phylum",
#' plotFeaturePrevalence(GlobalPatterns, rank = "Phylum",
#' detections = c(0, 0.001, 0.01, 0.1, 0.2))
#'
#' # point layout for plotTaxaPrevalence can be used to visualize by additional
#' # point layout for plotFeaturePrevalence can be used to visualize by additional
#' # information
#' plotPrevalentAbundance(GlobalPatterns, rank = "Family",
#' colour_by = "Phylum") +
Expand Down Expand Up @@ -337,16 +337,17 @@ setMethod("plotPrevalentAbundance", signature = c(x = "SummarizedExperiment"),
}

################################################################################
# plotTaxaPrevalence
# plotFeaturePrevalence

#' @rdname plotPrevalence
#' @aliases plotTaxaPrevalence
#' @export
setGeneric("plotTaxaPrevalence", signature = c("x"),
function(x, ...) standardGeneric("plotTaxaPrevalence"))
setGeneric("plotFeaturePrevalence", signature = c("x"),
function(x, ...) standardGeneric("plotFeaturePrevalence"))

#' @rdname plotPrevalence
#' @export
setMethod("plotTaxaPrevalence", signature = c(x = "SummarizedExperiment"),
setMethod("plotFeaturePrevalence", signature = c(x = "SummarizedExperiment"),
function(x,
rank = taxonomyRanks(x)[1L],
assay.type = assay_name, assay_name = "counts",
Expand Down Expand Up @@ -444,7 +445,7 @@ setMethod("plotTaxaPrevalence", signature = c(x = "SummarizedExperiment"),
lvls <- rownames(ans)[order(rowSums(ans))]
ans$ID <- rownames(mat)[rowSums(f) != 0]
ans <- ans %>%
pivot_longer(!.data$ID,
pivot_longer(!ID,
names_to = "detection",
values_to = "prevalence")
colnames(ans) <- c("Y","X","colour_by")
Expand Down Expand Up @@ -474,7 +475,7 @@ setMethod("plotTaxaPrevalence", signature = c(x = "SummarizedExperiment"),
line_alpha = 1,
line_type = NULL,
line_size = 1){
plot_out <- ggplot(plot_data, aes_string(x = "X", y = "Y")) +
plot_out <- ggplot(plot_data, aes(x = .data[["X"]], y = .data[["Y"]])) +
labs(x = xlab, y = ylab)
if(layout == "line"){
point_args <- .get_point_args(colour_by = colour_by, shape_by = NULL,
Expand All @@ -485,7 +486,7 @@ setMethod("plotTaxaPrevalence", signature = c(x = "SummarizedExperiment"),
size_by = NULL,
alpha = line_alpha,
linetype = line_type,
size = line_size)
linewidth = line_size)
himmil marked this conversation as resolved.
Show resolved Hide resolved
point_args$args$mapping$group <- sym("colour_by")
line_args$args$mapping$group <- sym("colour_by")
plot_out <- plot_out +
Expand Down Expand Up @@ -542,3 +543,20 @@ setMethod("plotTaxaPrevalence", signature = c(x = "SummarizedExperiment"),
angle_x_text = FALSE)
plot_out
}

#' @rdname plotPrevalence
#' @aliases plotFeaturePrevalence
#' @export
setGeneric("plotTaxaPrevalence", signature = c("x"),
function(x, ...)
standardGeneric("plotTaxaPrevalence"))

#' @rdname plotPrevalence
#' @aliases plotFeaturePrevalence
#' @export
setMethod("plotTaxaPrevalence", signature = c(x = "ANY"),
function(x, ...){
.Deprecated(old ="plotTaxaPrevalence", new = "plotFeaturePrevalence", msg = "The 'plotTaxaPrevalence' function is deprecated. Use 'plotFeaturePrevalence' instead.")
plotFeaturePrevalence(x, ...)
}
)
12 changes: 6 additions & 6 deletions R/plotSeries.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
#' # Plots 2 most abundant taxa, which are colored by their family
#' plotSeries(object,
#' x = "DAY_ORDER",
#' y = getTopTaxa(object, 2),
#' y = getTopFeatures(object, 2),
#' colour_by = "Family")
#'
#' # Counts relative abundances
Expand All @@ -82,7 +82,7 @@
#' # In addition to 'colour_by' and 'linetype_by', 'size_by' can also be used to group taxa.
#' plotSeries(object,
#' x = "DAY_ORDER",
#' y = getTopTaxa(object, 5),
#' y = getTopFeatures(object, 5),
#' colour_by = "Family",
#' size_by = "Phylum",
#' assay.type = "counts")
Expand Down Expand Up @@ -304,7 +304,7 @@ setMethod("plotSeries", signature = c(object = "SummarizedExperiment"),
}
# Creates a "draft" of a plot
plot_out <- ggplot(plot_data,
aes_string(x = "X", y = "Y")) +
aes(x = .data[["X"]], y = .data[["Y"]])) +
labs(x = xlab, y = ylab)
# if sd column is present add a ribbon
if(!is.null(plot_data$sd)){
Expand All @@ -313,13 +313,13 @@ setMethod("plotSeries", signature = c(object = "SummarizedExperiment"),
plot_out <- plot_out +
do.call(geom_ribbon, ribbon_args$args)
}
# Fetches arguments fpr geom_line
# Fetches arguments for geom_line
line_args <- .get_line_args(colour_by = colour_by,
linetype_by = linetype_by,
size_by = size_by,
alpha = line_alpha,
linetype = line_type,
size = line_width)
linewidth = line_width)
himmil marked this conversation as resolved.
Show resolved Hide resolved
# Adds arguments to the plot
plot_out <- plot_out +
do.call(geom_line, line_args$args)
Expand Down Expand Up @@ -359,7 +359,7 @@ setMethod("plotSeries", signature = c(object = "SummarizedExperiment"),
guide_args$linetype <- guide_legend(title = linetype_by)
}
if (!is.null(size_by)) {
guide_args$size <- guide_legend(title = size_by)
guide_args$linewidth <- guide_legend(title = size_by)
himmil marked this conversation as resolved.
Show resolved Hide resolved
}
if (length(guide_args)) {
plot_out <- plot_out + do.call(guides, guide_args)
Expand Down
4 changes: 2 additions & 2 deletions R/plotTree.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
#' log(rowData(altExp(GlobalPatterns,"Genus"))$mean)
#' rowData(altExp(GlobalPatterns,"Genus"))$detected <-
#' rowData(altExp(GlobalPatterns,"Genus"))$detected / 100
#' top_genus <- getTopTaxa(altExp(GlobalPatterns,"Genus"),
#' top_genus <- getTopFeatures(altExp(GlobalPatterns,"Genus"),
#' method="mean",
#' top=100L,
#' assay.type="counts")
Expand Down Expand Up @@ -149,7 +149,7 @@
#' # please note that the original tree of GlobalPatterns is dropped by
#' # unsplitByRanks
#' altExps(GlobalPatterns) <- splitByRanks(GlobalPatterns)
#' top_phyla <- getTopTaxa(altExp(GlobalPatterns,"Phylum"),
#' top_phyla <- getTopFeatures(altExp(GlobalPatterns,"Phylum"),
#' method="mean",
#' top=10L,
#' assay.type="counts")
Expand Down
2 changes: 1 addition & 1 deletion R/treeData.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ setMethod("rowTreeData", signature = c(x = "TreeSummarizedExperiment"),
DEFAULT_TREE_DATA_COLS <- c("parent","node","branch.length","label")
.clean_tree_data <- function(tree_data){
tree_data %>%
select(DEFAULT_TREE_DATA_COLS)
select(all_of(DEFAULT_TREE_DATA_COLS))
himmil marked this conversation as resolved.
Show resolved Hide resolved
}

#' @rdname treeData
Expand Down
Loading
Loading