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

Calculate binary Jaccard by default #709

Merged
merged 3 commits into from
Mar 13, 2025
Merged
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 DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: mia
Type: Package
Version: 1.15.30
Version: 1.15.31
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 @@ -172,3 +172,4 @@ Changes in version 1.15.x
+ getReducedDimAttribute: function for fetching elements from attributes of reducedDim
+ Improve decontam functions
+ Support precalculated dissimilarity matrix in dbRDA
+ Calculate standard, binary Jaccard index by default
16 changes: 14 additions & 2 deletions R/addDissimilarity.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
#' Defines detection threshold for absence/presence of features. Feature that
#' has abundance under threshold in either of samples, will be discarded when
#' evaluating overlap between samples. (Default: \code{0})
#'
#' \item \code{binary}: \code{Logical scalar}. Whether to perform
#' presence/absence transformation before dissimilarity calculation. For
#' Jaccard index the default is \code{TRUE}. For other dissimilarity metrics,
#' please see \code{\link[vegan:vegdist]{vegdist}}.
#' }
#'
#' @return
Expand Down Expand Up @@ -300,6 +305,8 @@ setMethod(
stop("'sample' must be an integer.", call. = FALSE)
}
#
# Initialize an argument list
args <- c(list(x = mat), list(...))
# If the dissimilarity function is not specified, get default choice
if( is.null(dis.fun) ){
if( method %in% c("overlap") ){
Expand All @@ -310,10 +317,15 @@ setMethod(
dis.fun <- .get_jsd
} else{
dis.fun <- vegdist
# If binary was not specified and user wants to calculate Jaccard
# index, we default the binary to TRUE as the standard Jaccard is
# calculated from presence/absence table. FALSE is the defualt in
# vegan: https://github.com/vegandevs/vegan/issues/153
if( method %in% c("jaccard") && !"binary" %in% names(args) ){
args[["binary"]] <- TRUE
}
}
}
# Initialize an argument 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 R/runCCA.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@
#' \item \code{subset.result}: \code{Logical result}. Specifies whether to
#' subset \code{x} to match the result if some samples were removed during
#' calculation. (Default: \code{TRUE})
#'
#' \item \code{binary}: \code{Logical scalar}. Whether to perform
#' presence/absence transformation before dissimilarity calculation. For
#' Jaccard index the default is \code{TRUE}. For other dissimilarity metrics,
#' please see \code{\link[vegan:vegdist]{vegdist}}.
#' }
#'
#' @details
Expand Down Expand Up @@ -550,6 +555,13 @@ setMethod("addRDA", "SingleCellExperiment",
# dissimilarity metric
if( ord.method == "RDA" ){
args <- c(args, list(distance = method))
# If binary was not specified and user wants to calculate Jaccard
# index, we default the binary to TRUE as the standard Jaccard is
# calculated from presence/absence table. FALSE is the defualt in
# vegan: https://github.com/vegandevs/vegan/issues/153
if( method %in% c("jaccard") && !"binary" %in% names(args) ){
args[["binary"]] <- TRUE
}
}
# Perform CCA or RDA
ord_FUN <- if (ord.method == "CCA") cca else dbrda
Expand Down
5 changes: 5 additions & 0 deletions man/getDissimilarity.Rd

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

5 changes: 5 additions & 0 deletions man/runCCA.Rd

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

Loading