Skip to content

Commit

Permalink
assay_name switch (#341)
Browse files Browse the repository at this point in the history
* ok

* sync

* snc

* removed shortcut transformation examples

* deprecating ZTransform and relAbundanceCounts

* final fixes

* news
  • Loading branch information
antagomir committed Mar 10, 2023
1 parent 0b0c1ee commit 4d7d2ce
Show file tree
Hide file tree
Showing 68 changed files with 853 additions and 841 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
@@ -1,6 +1,6 @@
Package: mia
Type: Package
Version: 1.7.8
Version: 1.7.9
Authors@R:
c(person(given = "Felix G.M.", family = "Ernst", role = c("aut"),
email = "felix.gm.ernst@outlook.com",
Expand Down
4 changes: 3 additions & 1 deletion NEWS
Expand Up @@ -60,6 +60,8 @@ Changes in version 1.5.x
+ calculateUnifrac bugfix

Changes in version 1.7.x
+ Deprecated assay_name arguments, replaced with assay.type
+ Removed abund_values argument
+ makePhyloseqFromTreeSE: added option for choosing a tree from multiple rowTrees
+ mergeSEs: match rows based on all available taxonomy level data on rowData
+ mergeSEs: fix bug related to equally named variables that are different class
Expand All @@ -69,5 +71,5 @@ Changes in version 1.7.x
+ calculateUnifrac: subset tree based on data
+ agglomerateByRank: take into account multiple trees
+ loadFromBiom: name columns of rowData based on prefixes
+ Deprecate transformSamples, *Features, relabundance
+ Deprecate transformSamples, *Features, relabundance, ZTransform, relAbundanceCounts
+ mergeSEs: faster tree merging
20 changes: 10 additions & 10 deletions R/calculateDMM.R
Expand Up @@ -8,16 +8,16 @@
#' \code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}}
#' object.
#'
#' @param assay_name a single \code{character} value for specifying which
#' @param assay.type a single \code{character} value for specifying which
#' assay to use for calculation.
#'
#' @param exprs_values a single \code{character} value for specifying which
#' assay to use for calculation.
#' (Please use \code{assay_name} instead.)
#' (Please use \code{assay.type} instead.)
#'
#' @param abund_values a single \code{character} value for specifying which
#' @param assay_name a single \code{character} value for specifying which
#' assay to use for calculation.
#' (Please use \code{assay_name} instead. At some point \code{abund_values}
#' (Please use \code{assay.type} instead. At some point \code{assay_name}
#' will be disabled.)
#'
#' @param k the number of Dirichlet components to fit. See
Expand Down Expand Up @@ -141,9 +141,9 @@ setMethod("calculateDMN", signature = c(x = "ANY"), .calculate_DMN)
#' @rdname calculateDMN
#' @export
setMethod("calculateDMN", signature = c(x = "SummarizedExperiment"),
function(x, assay_name = abund_values, abund_values = exprs_values, exprs_values = "counts",
function(x, assay.type = assay_name, assay_name = exprs_values, exprs_values = "counts",
transposed = FALSE, ...){
mat <- assay(x, assay_name)
mat <- assay(x, assay.type)
if(!transposed){
mat <- t(mat)
}
Expand Down Expand Up @@ -276,9 +276,9 @@ setMethod("calculateDMNgroup", signature = c(x = "ANY"), .calculate_DMNgroup)
#' @export
setMethod("calculateDMNgroup", signature = c(x = "SummarizedExperiment"),
function(x, variable,
assay_name = abund_values, abund_values = exprs_values, exprs_values = "counts",
assay.type = assay_name, assay_name = exprs_values, exprs_values = "counts",
transposed = FALSE, ...){
mat <- assay(x, assay_name)
mat <- assay(x, assay.type)
if(!transposed){
mat <- t(mat)
}
Expand Down Expand Up @@ -327,9 +327,9 @@ setMethod("performDMNgroupCV", signature = c(x = "ANY"), .perform_DMNgroup_cv)
#' @export
setMethod("performDMNgroupCV", signature = c(x = "SummarizedExperiment"),
function(x, variable,
assay_name = abund_values, abund_values = exprs_values, exprs_values = "counts",
assay.type = assay_name, assay_name = exprs_values, exprs_values = "counts",
transposed = FALSE, ...){
mat <- assay(x, assay_name)
mat <- assay(x, assay.type)
if(!transposed){
mat <- t(mat)
}
Expand Down
12 changes: 6 additions & 6 deletions R/calculateJSD.R
Expand Up @@ -7,16 +7,16 @@
#' @param x a numeric matrix or a
#' \code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}}.
#'
#' @param assay_name a single \code{character} value for specifying which
#' @param assay.type a single \code{character} value for specifying which
#' assay to use for calculation.
#'
#' @param exprs_values a single \code{character} value for specifying which
#' assay to use for calculation.
#' (Please use \code{assay_name} instead.)
#' (Please use \code{assay.type} instead.)
#'
#' @param abund_values a single \code{character} value for specifying which
#' @param assay_name a single \code{character} value for specifying which
#' assay to use for calculation.
#' (Please use \code{assay_name} instead. At some point \code{abund_values}
#' (Please use \code{assay.type} instead. At some point \code{assay_name}
#' will be disabled.)
#'
#' @param transposed Logical scalar, is x transposed with cells in rows?
Expand Down Expand Up @@ -85,9 +85,9 @@ setMethod("calculateJSD", signature = c(x = "ANY"),
#'
#' @export
setMethod("calculateJSD", signature = c(x = "SummarizedExperiment"),
function(x, assay_name = abund_values, abund_values = exprs_values,
function(x, assay.type = assay_name, assay_name = exprs_values,
exprs_values = "counts", transposed = FALSE, ...){
mat <- assay(x, assay_name)
mat <- assay(x, assay.type)
if(!transposed){
mat <- t(mat)
}
Expand Down
18 changes: 9 additions & 9 deletions R/calculateOverlap.R
Expand Up @@ -8,13 +8,13 @@
#' \code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}}
#' object containing a tree.
#'
#' @param assay_name A single character value for selecting the
#' @param assay.type A single character value for selecting the
#' \code{\link[SummarizedExperiment:SummarizedExperiment-class]{assay}}
#' to calculate the overlap.
#'
#' @param abund_values a single \code{character} value for specifying which
#' @param assay_name a single \code{character} value for specifying which
#' assay to use for calculation.
#' (Please use \code{assay_name} instead. At some point \code{abund_values}
#' (Please use \code{assay.type} instead. At some point \code{assay_name}
#' will be disabled.)
#'
#' @param detection A single numeric value for selecting detection threshold for
Expand Down Expand Up @@ -53,7 +53,7 @@
#' overlap
#'
#' # Store result to reducedDim
#' tse <- runOverlap(tse, assay_name = "relabundance", name = "overlap_between_samples")
#' tse <- runOverlap(tse, assay.type = "relabundance", name = "overlap_between_samples")
#' head(reducedDims(tse)$overlap_between_samples)
#'
NULL
Expand All @@ -62,18 +62,18 @@ NULL
#' @rdname calculateOverlap
#' @export
setGeneric("calculateOverlap", signature = c("x"),
function(x, assay_name = abund_values, abund_values = "counts",
function(x, assay.type = assay_name, assay_name = "counts",
detection = 0, ...)
standardGeneric("calculateOverlap"))

#' @rdname calculateOverlap
#' @export
setMethod("calculateOverlap", signature = c(x = "SummarizedExperiment"),
function(x, assay_name = abund_values, abund_values = "counts",
function(x, assay.type = assay_name, assay_name = "counts",
detection = 0, ...){
############################# INPUT CHECK ##############################
# Check assay_name
.check_assay_present(assay_name, x)
# Check assay.type
.check_assay_present(assay.type, x)
# Check detection
if (!.is_numeric_string(detection)) {
stop("'detection' must be a single numeric value or coercible to ",
Expand All @@ -83,7 +83,7 @@ setMethod("calculateOverlap", signature = c(x = "SummarizedExperiment"),
detection <- as.numeric(detection)
########################### INPUT CHECK END ############################
# Get assay
assay <- assay(x, assay_name)
assay <- assay(x, assay.type)

# All the sample pairs
sample_pairs <- as.matrix(expand.grid(colnames(x), colnames(x)))
Expand Down
16 changes: 8 additions & 8 deletions R/calculateUnifrac.R
Expand Up @@ -26,16 +26,16 @@
#' The length must equal the number of rows/columns of \code{x}. Furthermore, all the
#' node labs must be present in \code{tree}.
#'
#' @param assay_name a single \code{character} value for specifying which
#' @param assay.type a single \code{character} value for specifying which
#' assay to use for calculation.
#'
#' @param exprs_values a single \code{character} value for specifying which
#' assay to use for calculation.
#' (Please use \code{assay_name} instead.)
#' (Please use \code{assay.type} instead.)
#'
#' @param abund_values a single \code{character} value for specifying which
#' @param assay_name a single \code{character} value for specifying which
#' assay to use for calculation.
#' (Please use \code{assay_name} instead. At some point \code{abund_values}
#' (Please use \code{assay.type} instead. At some point \code{assay_name}
#' will be disabled.)
#'
#' @param tree_name a single \code{character} value for specifying which
Expand Down Expand Up @@ -146,11 +146,11 @@ setMethod("calculateUnifrac", signature = c(x = "ANY", tree = "phylo"),
setMethod("calculateUnifrac",
signature = c(x = "TreeSummarizedExperiment",
tree = "missing"),
function(x, assay_name = abund_values, abund_values = exprs_values, exprs_values = "counts",
function(x, assay.type = assay_name, assay_name = exprs_values, exprs_values = "counts",
tree_name = "phylo", transposed = FALSE, ...){
# Check assay_name and get assay
.check_assay_present(assay_name, x)
mat <- assay(x, assay_name)
# Check assay.type and get assay
.check_assay_present(assay.type, x)
mat <- assay(x, assay.type)
if(!transposed){
# Check tree_name
.check_rowTree_present(tree_name, x)
Expand Down
18 changes: 9 additions & 9 deletions R/decontam.R
Expand Up @@ -8,13 +8,13 @@
#' @param seqtab,x
#' a \code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}}
#'
#' @param assay_name A single character value for selecting the
#' @param assay.type A single character value for selecting the
#' \code{\link[SummarizedExperiment:SummarizedExperiment-class]{assay}}
#' to use.
#'
#' @param abund_values a single \code{character} value for specifying which
#' @param assay_name a single \code{character} value for specifying which
#' assay to use for calculation.
#' (Please use \code{assay_name} instead. At some point \code{abund_values}
#' (Please use \code{assay.type} instead. At some point \code{assay_name}
#' will be disabled.)
#'
#' @param name A name for the column of the colData in which the contaminant
Expand Down Expand Up @@ -89,7 +89,7 @@ NULL
#' @export
setMethod("isContaminant", signature = c(seqtab = "SummarizedExperiment"),
function(seqtab,
assay_name = abund_values, abund_values = "counts",
assay.type = assay_name, assay_name = "counts",
name = "isContaminant",
concentration = NULL,
control = NULL,
Expand All @@ -99,7 +99,7 @@ setMethod("isContaminant", signature = c(seqtab = "SummarizedExperiment"),
detailed = TRUE,
...){
# input check
.check_assay_present(assay_name, seqtab)
.check_assay_present(assay.type, seqtab)
if(!.is_a_string(name)){
stop("'name' must be single character value.",call. = FALSE)
}
Expand Down Expand Up @@ -136,7 +136,7 @@ setMethod("isContaminant", signature = c(seqtab = "SummarizedExperiment"),
search = "colData")$value
batch <- factor(batch, sort(unique(batch)))
}
mat <- assay(seqtab,assay_name)
mat <- assay(seqtab,assay.type)
contaminant <- isContaminant(t(mat),
conc = concentration,
neg = control,
Expand All @@ -162,15 +162,15 @@ setMethod("isContaminant", signature = c(seqtab = "SummarizedExperiment"),
#' @export
setMethod("isNotContaminant", signature = c(seqtab = "SummarizedExperiment"),
function(seqtab,
assay_name = abund_values, abund_values = "counts",
assay.type = assay_name, assay_name = "counts",
name = "isNotContaminant",
control = NULL,
threshold = 0.5,
normalize = TRUE,
detailed = FALSE,
...){
# input check
.check_assay_present(assay_name, seqtab)
.check_assay_present(assay.type, seqtab)
if(!.is_a_string(name)){
stop("'name' must be single character value.",call. = FALSE)
}
Expand All @@ -193,7 +193,7 @@ setMethod("isNotContaminant", signature = c(seqtab = "SummarizedExperiment"),
call. = FALSE)
}
}
mat <- assay(seqtab,assay_name)
mat <- assay(seqtab,assay.type)
not_contaminant <- isNotContaminant(t(mat),
neg = control,
threshold = threshold,
Expand Down
18 changes: 9 additions & 9 deletions R/dominantTaxa.R
Expand Up @@ -8,13 +8,13 @@
#' \code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}}
#' object.
#'
#' @param assay_name A single character value for selecting the
#' @param assay.type A single character value for selecting the
#' \code{\link[SummarizedExperiment:SummarizedExperiment-class]{assay}}
#' to use for identifying dominant taxa.
#'
#' @param abund_values a single \code{character} value for specifying which
#' @param assay_name a single \code{character} value for specifying which
#' assay to use for calculation.
#' (Please use \code{assay_name} instead. At some point \code{abund_values}
#' (Please use \code{assay.type} instead. At some point \code{assay_name}
#' will be disabled.)
#'
#' @param rank A single character defining a taxonomic rank. Must be a value of
Expand Down Expand Up @@ -63,7 +63,7 @@ NULL
#' @aliases perSampleDominantFeatures
#' @export
setGeneric("perSampleDominantTaxa",signature = c("x"),
function(x, assay_name = abund_values, abund_values = "counts",
function(x, assay.type = assay_name, assay_name = "counts",
rank = NULL, ...)
standardGeneric("perSampleDominantTaxa"))

Expand All @@ -72,11 +72,11 @@ setGeneric("perSampleDominantTaxa",signature = c("x"),
#' @importFrom IRanges relist
#' @export
setMethod("perSampleDominantTaxa", signature = c(x = "SummarizedExperiment"),
function(x, assay_name = abund_values, abund_values = "counts",
function(x, assay.type = assay_name, assay_name = "counts",
rank = NULL, ...){
# Input check
# Check assay_name
.check_assay_present(assay_name, x)
# Check assay.type
.check_assay_present(assay.type, x)
# rank check
if(!is.null(rank)){
if(!.is_a_string(rank)){
Expand All @@ -89,10 +89,10 @@ setMethod("perSampleDominantTaxa", signature = c(x = "SummarizedExperiment"),
# taxonomic rank that is specified by user.
if (!is.null(rank)) {
x <- agglomerateByRank(x, rank, ...)
mat <- assay(x, assay_name)
mat <- assay(x, assay.type)
} # Otherwise, if "rank" is NULL, abundances are stored without ranking
else {
mat <- assay(x, assay_name)
mat <- assay(x, assay.type)
}
# apply() function finds the indices of taxa's that has the highest
# abundance.
Expand Down
16 changes: 8 additions & 8 deletions R/estimateDivergence.R
Expand Up @@ -4,12 +4,12 @@
#'
#' @param x a \code{\link{SummarizedExperiment}} object.
#'
#' @param assay_name the name of the assay used for calculation of the
#' @param assay.type the name of the assay used for calculation of the
#' sample-wise estimates.
#'
#' @param abund_values a single \code{character} value for specifying which
#' @param assay_name a single \code{character} value for specifying which
#' assay to use for calculation.
#' (Please use \code{assay_name} instead. At some point \code{abund_values}
#' (Please use \code{assay.type} instead. At some point \code{assay_name}
#' will be disabled.)
#'
#' @param name a name for the column of the colData the results should be
Expand Down Expand Up @@ -83,21 +83,21 @@ NULL
#' @rdname estimateDivergence
#' @export
setGeneric("estimateDivergence",signature = c("x"),
function(x, assay_name = abund_values, abund_values = "counts",
function(x, assay.type = assay_name, assay_name = "counts",
name = "divergence", reference = "median",
FUN = vegan::vegdist, method = "bray", ...)
standardGeneric("estimateDivergence"))

#' @rdname estimateDivergence
#' @export
setMethod("estimateDivergence", signature = c(x="SummarizedExperiment"),
function(x, assay_name = abund_values, abund_values = "counts",
function(x, assay.type = assay_name, assay_name = "counts",
name = "divergence", reference = "median",
FUN = vegan::vegdist, method = "bray", ...){

################### Input check ###############
# Check assay_name
.check_assay_present(assay_name, x)
# Check assay.type
.check_assay_present(assay.type, x)
# Check name
if(!.is_non_empty_character(name) || length(name) != 1L){
stop("'name' must be a non-empty character value.",
Expand Down Expand Up @@ -125,7 +125,7 @@ setMethod("estimateDivergence", signature = c(x="SummarizedExperiment"),
}

################# Input check end #############
divergence <- .calc_reference_dist(mat = assay(x, assay_name),
divergence <- .calc_reference_dist(mat = assay(x, assay.type),
reference = reference,
FUN = FUN,
method = method, ...)
Expand Down

0 comments on commit 4d7d2ce

Please sign in to comment.