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

fix issue 88 plotAbundance rank #113

Merged
merged 25 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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
26 changes: 10 additions & 16 deletions R/plotAbundance.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ setGeneric("plotAbundance", signature = c("x"),
}
}


#' @rdname plotAbundance
#' @importFrom scater plotExpression
#' @importFrom ggplot2 facet_wrap
Expand All @@ -164,36 +163,31 @@ setMethod("plotAbundance", signature = c("SummarizedExperiment"),
stop("No data to plot. nrow(x) == 0L.", call. = FALSE)
}
.check_assay_present(assay.type, x)
# if rank is set to NULL, default to plotExpression
if(is.null(rank)){
plot <- plotExpression(x, features = features,
exprs_values = assay.type,
one_facet = one_facet,
ncol = ncol, scales = scales, ...)
ylab <- gsub("Expression","Abundance",plot$labels$y)
plot <- plot +
ylab(ylab)
return(plot)
}
############################# INPUT CHECK #############################
if(!.is_non_empty_string(rank)){
stop("'rank' must be an non empty single character value.",
if(!.is_non_empty_string(rank) && !is.null(rank)){
stop("'rank' must be an non empty single character value or NULL.",
call. = FALSE)
}
if(!.is_a_bool(use_relative)){
stop("'use_relative' must be TRUE or FALSE.",
call. = FALSE)
}
.check_taxonomic_rank(rank, x)
if(!is.null(rank)){
.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"))
.check_abund_plot_args(one_facet = one_facet,
ncol = ncol)
if( !is.null(features) ){
if( !is.null(features) & !is.null(rank) ){
Insaynoah marked this conversation as resolved.
Show resolved Hide resolved
TuomasBorman marked this conversation as resolved.
Show resolved Hide resolved
features <- match.arg(features, colnames(colData(x)))
}
########################### INPUT CHECK END ###########################
if(is.null(rank)){
rank <- "Feature"
rowData(x)[[ rank ]] <- rownames(x)
}
abund_data <- .get_abundance_data(x, rank, assay.type, order_rank_by,
use_relative)
order_sample_by <- .norm_order_sample_by(order_sample_by,
Expand Down
21 changes: 13 additions & 8 deletions vignettes/miaViz.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,25 @@ BiocManager::install("miaViz")

```{r setup, message=FALSE}
library(miaViz)
library(scater)
data(GlobalPatterns, package = "mia")
```

# Abundance plotting

in contrast to other fields of sequencing based fields of research for which
In contrast to other fields of sequencing based fields of research for which
expression of genes is usually studied, microbiome research uses the more
term ~Abundance~ to described the numeric data measured and analyzed.
Technically, especially in context of `SummarizedExperiment` objects, there is
no difference. Therefore `plotExpression` can be used to plot `Abundance` data.

`plotAbundance` can be used as well and as long as `rank` is set `NULL`, it
behaves as `plotExpression`.
no difference. Therefore `plotExpression` can be used to plot `Abundance` data of a particular feature.

```{r}
plotAbundance(GlobalPatterns, rank = NULL,
plotExpression(GlobalPatterns,
features = "549322", assay.type = "counts")
```

However, if the `rank` is set not `NULL` a bar plot is returned. At the same
time the `features` argument can be set to `NULL` (default).
On the other hand, plotAbundance can be used to plot abundance by `rank`. A bar plot is returned showing the relative abundance within each sample for a given `rank`. At the same
time the `features` argument can be set to `NULL` (default).

```{r}
GlobalPatterns <- transformAssay(GlobalPatterns, method = "relabundance")
Expand All @@ -70,6 +68,13 @@ GlobalPatterns <- transformAssay(GlobalPatterns, method = "relabundance")
plotAbundance(GlobalPatterns, rank = "Kingdom", assay.type = "relabundance")
```

If `rank`is set to null however then the bars will be colored by each individual taxon. Please note that if you're doing this make sure to agglomerate your data to a certain taxonomic hand before plotting.

```{r}
GlobalPatterns.agglomerated <- agglomerateByRank(GlobalPatterns, 'Kingdom')
plotAbundance(GlobalPatterns.agglomerated, rank = NULL, assay.type = "relabundance")
```

With subsetting to selected features the plot can be fine tuned.

```{r}
Expand Down
Loading