Skip to content

Commit

Permalink
Support rarefaction in unifrac (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
TuomasBorman authored Feb 4, 2025
1 parent c6e75ad commit 676c69d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: mia
Type: Package
Version: 1.15.20
Version: 1.15.21
Authors@R:
c(person(given = "Tuomas", family = "Borman", role = c("aut", "cre"),
email = "[email protected]",
Expand Down
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,4 @@ Changes in version 1.15.x
+ Add addPrevalence function that adds results of getPrevalence to rowData
+ Added support for dimred to getCrossAssociation
+ Add wrapper for PhILR transformation
+ Support rarefaction when applying unifrac
15 changes: 14 additions & 1 deletion R/addDissimilarity.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#' \item \code{dis.fun}: \code{Character scalar}. Specifies the dissimilarity
#' function to be used.
#'
#' \item \code{transf}: \code{Function}. Specifies the optional
#' transformation applied before calculating the dissimilarity matrix.
#'
#' \item \code{tree.name}: (Unifrac) \code{Character scalar}. Specifies the
#' name of the tree from \code{rowTree(x)} that is used in calculation.
#' Disabled when \code{tree} is specified. (Default: \code{"phylo"})
Expand Down Expand Up @@ -171,6 +174,15 @@
#' res <- getDissimilarity(tse, method = "bray", assay.type = "relabundance")
#' as.matrix(res)[1:6, 1:6]
#'
#' # If applying rarefaction, the input must be count matrix and transformation
#' # method specified in function call (Note: increase niter)
#' rclr <- function(x){
#' vegan::decostand(x, method="rclr")
#' }
#' res <- getDissimilarity(
#' tse, method = "euclidean", transf = rclr, niter = 2L)
#' as.matrix(res)[1:6, 1:6]
#'
NULL

#' @rdname getDissimilarity
Expand Down Expand Up @@ -238,6 +250,7 @@ setMethod(
args <- .get_tree_args(
x, method = method, assay.type = assay.type,
transposed = transposed, ...)
args <- c(args, list(niter = niter))
} else{
# For other cases, do not fetch tree data from TreeSE
mat <- assay(x, assay.type)
Expand Down Expand Up @@ -301,7 +314,7 @@ setMethod(
}
}
# Initialize an argument list
args <- c(list(mat), list(...))
args <- c(list(x = mat), list(...))
# If rarefaction is specified, calculate dissimilarity with vegan::avgdist
# function that utilizes the specified dissimilarity function. Otherwise,
# call the specified function directly.
Expand Down
12 changes: 12 additions & 0 deletions man/getDissimilarity.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 676c69d

Please sign in to comment.