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

Incorporate Bioconductor recommendations #164

Open
wants to merge 10 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ renv/
renv.lock
.Rprofile
.idea

*.Rproj
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: miaViz
Title: Microbiome Analysis Plotting and Visualization
Version: 1.15.4
Version: 1.15.5
Authors@R:
c(person(given = "Tuomas", family = "Borman", role = c("aut", "cre"),
email = "[email protected]",
Expand Down Expand Up @@ -47,8 +47,6 @@ Imports:
dplyr,
ggnewscale,
ggrepel,
ggplot2,
ggraph,
ggtree,
methods,
rlang,
Expand Down Expand Up @@ -79,3 +77,6 @@ Remotes:
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
VignetteBuilder: knitr
URL: https://github.com/microbiome/miaViz
BugReports: https://github.com/microbiome/miaViz/issues

5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,13 @@ importFrom(BiocParallel,bpstop)
importFrom(DelayedArray,rowMeans)
importFrom(DelayedArray,rowSums)
importFrom(DirichletMultinomial,mixture)
importFrom(S4Vectors,SimpleList)
importFrom(S4Vectors,metadata)
importFrom(S4Vectors,unfactor)
importFrom(SingleCellExperiment,reducedDim)
importFrom(SingleCellExperiment,reducedDimNames)
importFrom(SingleCellExperiment,reducedDims)
importFrom(SummarizedExperiment,"rowData<-")
importFrom(SummarizedExperiment,assay)
importFrom(SummarizedExperiment,colData)
importFrom(SummarizedExperiment,rowData)
Expand All @@ -69,6 +73,7 @@ importFrom(ape,drop.tip)
importFrom(ape,keep.tip)
importFrom(ape,rotateConstr)
importFrom(dplyr,"%>%")
importFrom(dplyr,across)
importFrom(dplyr,all_of)
importFrom(dplyr,arrange)
importFrom(dplyr,bind_cols)
Expand Down
131 changes: 131 additions & 0 deletions R/AllGenerics.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# All generic methods are listed here

#' @rdname getNeatOrder
setGeneric("getNeatOrder", signature = c("x"),
function(x, centering = "mean", ...)
standardGeneric("getNeatOrder"))

#' @rdname plotAbundance
setGeneric("plotAbundance", signature = c("x"), function(x, ...)
standardGeneric("plotAbundance"))

#' @rdname plotAbundanceDensity
#' @export
setGeneric("plotAbundanceDensity", signature = c("x"), function(x, ...)
standardGeneric("plotAbundanceDensity"))

#' @rdname plotCCA
#' @aliases plotRDA
#' @export
setGeneric("plotCCA", signature = c("x"), function(x, ...)
standardGeneric("plotCCA"))

#' @rdname plotCCA
#' @aliases plotCCA
#' @export
setGeneric("plotRDA", signature = c("x"), function(x, ...)
standardGeneric("plotRDA"))

#' @rdname plotColTile
#' @export
setGeneric("plotColTile", signature = c("object"),
function(object, x, y, ...)
standardGeneric("plotColTile"))

#' @rdname plotColTile
#' @export
setGeneric("plotRowTile", signature = c("object"),
function(object, x, y, ...)
standardGeneric("plotRowTile"))

#' @rdname plotDMN
#' @export
setGeneric("plotDMNFit", signature = "x",
function(x, name = "DMN", type = c("laplace","AIC","BIC"), ...)
standardGeneric("plotDMNFit"))

#' @rdname plotGraph
#' @export
setGeneric("plotColGraph", signature = c("x","y"),
function(x, y, ...)
standardGeneric("plotColGraph"))

#' @rdname plotGraph
#' @export
setGeneric("plotRowGraph", signature = c("x","y"),
function(x, y, ...)
standardGeneric("plotRowGraph"))

#' @rdname plotLoadings
setGeneric("plotLoadings", signature = c("x"),
function(x, ...)
standardGeneric("plotLoadings"))

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

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

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

#' @rdname plotScree
#' @export
setGeneric("plotScree", signature = c("x"),
function(x, ...)
standardGeneric("plotScree"))

#' @rdname plotSeries
#' @export
setGeneric("plotSeries", signature = c("object"),
function(object, ...)
standardGeneric("plotSeries"))

#' @rdname plotTree
setGeneric("plotRowTree", signature = c("x"),
function(x, ...)
standardGeneric("plotRowTree"))
#' @rdname plotTree
setGeneric("plotColTree", signature = c("x"),
function(x, ...)
standardGeneric("plotColTree"))

#' @rdname treeData
setGeneric("rowTreeData", signature = c("x"),
function(x, ...)
standardGeneric("rowTreeData"))

#' @rdname treeData
setGeneric("colTreeData", signature = c("x"),
function(x, ...)
standardGeneric("colTreeData"))

#' @rdname treeData
setGeneric("rowTreeData<-", signature = c("x"),
function(x, tree.name = tree_name, tree_name = "phylo", value)
standardGeneric("rowTreeData<-"))

#' @rdname treeData
setGeneric("colTreeData<-", signature = c("x"),
function(x, tree.name = tree_name, tree_name = "phylo", value)
standardGeneric("colTreeData<-"))

#' @rdname treeData
setGeneric("combineTreeData", signature = c("x"),
function(x, other.fields = other_fields, other_fields = list())
standardGeneric("combineTreeData"))

#' @rdname treeData
setGeneric("combineTreeData", signature = c("x"),
function(x, other.fields = other_fields, other_fields = list())
standardGeneric("combineTreeData"))
42 changes: 42 additions & 0 deletions R/deprecate.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#' These functions will be deprecated. Please use other functions instead.
#'
#' @param x -
#'
#' @param ... -
#'
#' @name deprecate
NULL

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

#' @rdname deprecate
#' @export
setMethod("plotTaxaPrevalence", signature = c(x = "ANY"), function(x, ...){
.Deprecated(
old ="plotTaxaPrevalence", new = "plotRowPrevalence",
msg = paste0("The 'plotTaxaPrevalence' function is ",
"deprecated. Use 'plotRowPrevalence' instead."))
plotRowPrevalence(x, ...)
}
)

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

#' @rdname deprecate
#' @export
setMethod("plotFeaturePrevalence", signature = c(x = "ANY"), function(x, ...){
.Deprecated(
old ="plotFeaturePrevalence", new = "plotRowPrevalence",
msg = paste0("The 'plotFeaturePrevalence' function is ",
"deprecated. Use 'plotRowPrevalence' instead."))
plotRowPrevalence(x, ...)
}
)
69 changes: 32 additions & 37 deletions R/getNeatOrder.R
Original file line number Diff line number Diff line change
@@ -1,81 +1,82 @@
#' Sorting by radial theta angle
#'
#'
#' @description \code{getNeatOrder} sorts already ordinated data by the radial
#' theta angle. This method is useful for organizing data points based on their
#' angular position in a 2D space, typically after an ordination technique such
#' as PCA or NMDS has been applied.
#'
#' The function takes in a matrix of ordinated data, optionally
#' as PCA or NMDS has been applied.
#'
#' The function takes in a matrix of ordinated data, optionally
#' centers the data using specified methods (\code{mean}, \code{median}, or
#' \code{NULL}), and then calculates the angle (theta) for each point relative
#' to the centroid. The data points are then sorted based on these theta values
#' in ascending order.
#'
#' One significant application of this sorting method is in plotting heatmaps.
#' in ascending order.
#'
#' One significant application of this sorting method is in plotting heatmaps.
#' By using radial theta sorting, the relationships between data points can be
#' preserved according to the ordination method's spatial configuration, rather
#' than relying on hierarchical clustering, which may distort these
#' relationships. This approach allows for a more faithful representation of the
#' data's intrinsic structure as captured by the ordination process.
#'
#'
#' @param x A matrix containing the ordinated data to be sorted. Columns should
#' represent the principal components (PCs) and rows should represent the
#' entities being analyzed (e.g. features or samples). There should be 2 columns
#' only representing 2 PCs.
#'
#'
#' @param centering \code{Character scalar}. Specifies the method to
#' center the data. Options are \code{"mean"}, \code{"median"}, or \code{NULL}
#' if your data is already centered. (Default: \code{"mean"})
#'
#'
#' @param ... Additional arguments passed to other methods.
#'
#' @return A \code{character} vector of row indices in the sorted order.
#'
#' @details
#'
#' @details
#' It's important to note that the
#' [\pkg{sechm}](https://bioconductor.org/packages/3.18/bioc/vignettes/sechm/inst/doc/sechm.html#row-ordering)
#' package does actually have the functionality for plotting a heatmap using
#' this radial theta angle ordering, though only by using an MDS ordination.
#'
#' this radial theta angle ordering, though only by using an MDS ordination.
#'
#' That being said, the \code{getNeatOrder} function is more modular and
#' separate to the plotting, and can be applied to any kind of ordinated data
#' which can be valuable depending on the use case.
#'
#' [Rajaram & Oono (2010) NeatMap - non-clustering heat map alternatives in R](https://doi.org/10.1186/1471-2105-11-45) outlines this in more detail.
#'
#'
#' [Rajaram & Oono (2010) NeatMap - non-clustering heat map alternatives in R](https://doi.org/10.1186/1471-2105-11-45)
#' outlines this in more detail.
#'
#' @name getNeatOrder
#'
#'
#' @examples
#' # Load the required libraries and dataset
#' library(mia)
#' library(scater)
#' library(ComplexHeatmap)
#' library(circlize)
#' data(peerj13075)
#'
#'
#' # Group data by taxonomic order
#' tse <- agglomerateByRank(peerj13075, rank = "order", onRankOnly = TRUE)
#'
#'
#' # Transform the samples into relative abundances using CLR
#' tse <- transformAssay(
#' tse, assay.type = "counts", method="clr", MARGIN = "cols",
#' name="clr", pseudocount = TRUE)
#'
#'
#' # Transform the features (taxa) into zero mean, unit variance
#' # (standardize transformation)
#' tse <- transformAssay(
#' tse, assay.type="clr", method="standardize", MARGIN = "rows")
#'
#'
#' # Perform PCA using calculatePCA
#' res <- calculatePCA(tse, assay.type = "standardize", ncomponents = 10)
#'
#'
#' # Sort by radial theta and sort the original assay data
#' sorted_order <- getNeatOrder(res[, c(1,2)], centering = "mean")
#' tse <- tse[, sorted_order]
#'
#'
#' # Define the color function and cap the colors at [-5, 5]
#' col_fun <- colorRamp2(c(-5, 0, 5), c("blue", "white", "red"))
#'
#'
#' # Create the heatmap
#' heatmap <- Heatmap(assay(tse, "standardize"),
#' name = "NeatMap",
Expand All @@ -84,20 +85,14 @@
#' cluster_columns = FALSE, # Do not cluster columns
#' show_row_dend = FALSE,
#' show_column_dend = FALSE,
#' row_names_gp = gpar(fontsize = 4),
#' column_names_gp = gpar(fontsize = 6),
#' heatmap_width = unit(20, "cm"),
#' heatmap_height = unit(15, "cm")
#' row_names_gp = gpar(fontsize = 4),
#' column_names_gp = gpar(fontsize = 6),
#' heatmap_width = unit(20, "cm"),
#' heatmap_height = unit(15, "cm")
#' )
#'
#'
NULL

#' @rdname getNeatOrder
setGeneric("getNeatOrder", signature = c("x"),
function(x, centering = "mean", ...)
standardGeneric("getNeatOrder"))


# Implementation for taking in a raw matrix.
#' @rdname getNeatOrder
#' @export
Expand Down Expand Up @@ -147,7 +142,7 @@ setMethod("getNeatOrder", signature = c("matrix"),
center_fun <- switch(centering, "median" = median, "mean" = mean)
center_vals <- apply(data, 2, center_fun)
data <- scale(data, center = center_vals, scale = FALSE)
}
}
# Compute the radial theta values using the centered data
theta <- atan2(data[, 2], data[, 1])
# Set the names of theta values to the row names of the centered data and
Expand Down
Loading
Loading