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
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4c6f361
deprecate Taxa names -> Features
himmil Sep 7, 2023
377eaaa
Merge branch 'microbiome:master' into master
himmil Sep 19, 2023
ccf3940
Merge branch 'microbiome:master' into master
himmil Oct 16, 2023
aed7b93
Merge branch 'master' into master
himmil Oct 17, 2023
fe2ec44
deprecated Taxa names and ggplot and tidyr args
himmil Oct 17, 2023
32a51c8
Merge branch 'master' of https://github.com/himmil/miaViz
himmil Oct 17, 2023
4766d29
Merge branch 'microbiome:master' into master
himmil Oct 17, 2023
9920988
Merge branch 'master' of https://github.com/himmil/miaViz
himmil Oct 17, 2023
2a4fb21
.data deprecated in tidyselect
himmil Oct 17, 2023
25f3c2e
deprecated aes_string
himmil Oct 17, 2023
641f863
deprecated ggplot and tidyr args and code consistency
himmil Oct 18, 2023
4dce786
fix .get_abundance_data
himmil Oct 18, 2023
796bf84
restore aes_args
himmil Oct 18, 2023
d0365e7
restore .data
himmil Oct 18, 2023
9f48a5b
fix aes_string
himmil Oct 19, 2023
683732c
add disable note
himmil Oct 19, 2023
2c36e4a
documentation update
himmil Oct 19, 2023
7341f6c
\U2012 mismatch in code and docs
himmil Oct 19, 2023
612df34
disable notes and code documentation mismatch
himmil Oct 19, 2023
74c12fb
fix disable notes
himmil Oct 19, 2023
454df97
fix disable notes
himmil Oct 19, 2023
daa9c58
documentation update
himmil Oct 19, 2023
a51a087
fix list
himmil Oct 19, 2023
ee3dc3b
Merge branch 'master' into master
himmil Nov 27, 2023
c54d4fa
Merge branch 'master' into master
TuomasBorman Dec 5, 2023
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
@@ -5,6 +5,7 @@ export(plotCCA)
export(plotColGraph)
export(plotColTile)
export(plotDMNFit)
export(plotFeaturePrevalence)
export(plotPrevalence)
export(plotPrevalentAbundance)
export(plotRDA)
@@ -23,6 +24,7 @@ exportMethods(plotColGraph)
exportMethods(plotColTile)
exportMethods(plotColTree)
exportMethods(plotDMNFit)
exportMethods(plotFeaturePrevalence)
exportMethods(plotPrevalence)
exportMethods(plotPrevalentAbundance)
exportMethods(plotRDA)
@@ -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)
14 changes: 7 additions & 7 deletions R/plotAbundance.R
Original file line number Diff line number Diff line change
@@ -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,
@@ -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)))) %>%
@@ -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)
@@ -304,7 +304,7 @@ MELT_VALUES <- "Value"
}
data$colour_by <- factor(data$colour_by, lvl)
data <- data[order(data$colour_by),]
#

data
}

@@ -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
@@ -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,
@@ -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,
4 changes: 2 additions & 2 deletions R/plotAbundanceDensity.R
Original file line number Diff line number Diff line change
@@ -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
@@ -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"
3 changes: 1 addition & 2 deletions R/plotCCA.R
Original file line number Diff line number Diff line change
@@ -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
@@ -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,
4 changes: 2 additions & 2 deletions R/plotDMN.R
Original file line number Diff line number Diff line change
@@ -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")){
@@ -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() +
5 changes: 3 additions & 2 deletions R/plotGraph.R
Original file line number Diff line number Diff line change
@@ -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)
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
@@ -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") +
@@ -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",
@@ -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")
@@ -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,
@@ -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)
point_args$args$mapping$group <- sym("colour_by")
line_args$args$mapping$group <- sym("colour_by")
plot_out <- plot_out +
@@ -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
@@ -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
@@ -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")
@@ -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)){
@@ -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)
# Adds arguments to the plot
plot_out <- plot_out +
do.call(geom_line, line_args$args)
@@ -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)
}
if (length(guide_args)) {
plot_out <- plot_out + do.call(guides, guide_args)
4 changes: 2 additions & 2 deletions R/plotTree.R
Original file line number Diff line number Diff line change
@@ -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")
@@ -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")
2 changes: 1 addition & 1 deletion R/treeData.R
Original file line number Diff line number Diff line change
@@ -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))
}

#' @rdname treeData
Loading