diff --git a/DESCRIPTION b/DESCRIPTION index 06de519c6..3e7621905 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 = "tuomas.v.borman@utu.fi", diff --git a/NEWS b/NEWS index 342f6d804..d3f3cf24e 100644 --- a/NEWS +++ b/NEWS @@ -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 diff --git a/R/addDissimilarity.R b/R/addDissimilarity.R index 414d1981c..a9c4a9789 100644 --- a/R/addDissimilarity.R +++ b/R/addDissimilarity.R @@ -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 @@ -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") ){ @@ -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. diff --git a/R/runCCA.R b/R/runCCA.R index 8a261ba5a..91333e530 100644 --- a/R/runCCA.R +++ b/R/runCCA.R @@ -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 @@ -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 diff --git a/man/getDissimilarity.Rd b/man/getDissimilarity.Rd index 9a9427e39..e9427e40b 100644 --- a/man/getDissimilarity.Rd +++ b/man/getDissimilarity.Rd @@ -87,6 +87,11 @@ Specifies whether the calculation should be parallelized. 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}}. }} \item{name}{\code{Character scalar}. The name to be used to store the result diff --git a/man/runCCA.Rd b/man/runCCA.Rd index df388a166..a0c0ede12 100644 --- a/man/runCCA.Rd +++ b/man/runCCA.Rd @@ -103,6 +103,11 @@ permutations for significance testing in \code{vegan::anova.cca}. \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}}. }} \item{formula}{\code{formula}. If \code{x} is a