From 3341fc15c67d2224e3d40cec717dd1b34c08a793 Mon Sep 17 00:00:00 2001 From: TuomasBorman Date: Fri, 6 Dec 2024 15:10:27 +0200 Subject: [PATCH 1/9] up --- R/convertFromPhyloseq.R | 28 ++++++++++------------------ R/convertToPhyloseq.R | 2 +- R/utils.R | 8 ++++---- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/R/convertFromPhyloseq.R b/R/convertFromPhyloseq.R index 159173233..744e3383f 100644 --- a/R/convertFromPhyloseq.R +++ b/R/convertFromPhyloseq.R @@ -38,36 +38,28 @@ convertFromPhyloseq <- function(x) { } # # Get the assay - counts <- x@otu_table@.Data + counts <- phyloseq::otu_table(x) # Check the orientation, and transpose if necessary - if( !x@otu_table@taxa_are_rows ){ + if( !phyloseq::taxa_are_rows(x) ){ counts <- t(counts) } # Create a list of assays assays <- SimpleList(counts = counts) - if(!is.null(x@tax_table@.Data)){ - rowData <- DataFrame(data.frame(x@tax_table@.Data)) - } else{ + rowData <- tryCatch(phyloseq::tax_table(x), error = function(e) NULL) |> + data.frame() |> DataFrame() + if( is.null(rowData) ){ rowData <- S4Vectors::make_zero_col_DFrame(nrow(assays$counts)) rownames(rowData) <- rownames(assays$counts) } - if(!is.null(x@sam_data)){ - colData <- DataFrame(data.frame(x@sam_data)) - } else{ + colData <- tryCatch(phyloseq::sample_data(x), error = function(e) NULL) |> + data.frame() |> DataFrame() + if( is.null(colData) ){ colData <- S4Vectors::make_zero_col_DFrame(ncol(assays$counts)) rownames(colData) <- colnames(assays$counts) } - if(!is.null(x@phy_tree)){ - rowTree <- x@phy_tree - } else { - rowTree <- NULL - } - if (!is.null(x@refseq)) { - referenceSeq <- x@refseq - } else { - referenceSeq <- NULL - } + rowTree <- tryCatch(phyloseq::phy_tree(x), error = function(e) NULL) + referenceSeq <- tryCatch(phyloseq::refseq(x), error = function(e) NULL) TreeSummarizedExperiment(assays = assays, rowData = rowData, colData = colData, diff --git a/R/convertToPhyloseq.R b/R/convertToPhyloseq.R index 8ef68fc03..321969fb2 100644 --- a/R/convertToPhyloseq.R +++ b/R/convertToPhyloseq.R @@ -122,7 +122,7 @@ setMethod("convertToPhyloseq", signature = c(x = "TreeSummarizedExperiment"), function(x, tree.name = tree_name, tree_name = "phylo", ...){ # If rowTrees exist, check tree.name - if( length(x@rowTree) > 0 ){ + if( length(rowTreeNames(x)) > 0 ){ .check_rowTree_present(tree.name, x) # Subset the data based on the tree x <- x[ rowLinks(x)$whichTree == tree.name, ] diff --git a/R/utils.R b/R/utils.R index dee2dd391..a4f17df0a 100644 --- a/R/utils.R +++ b/R/utils.R @@ -108,8 +108,8 @@ stop("'", name, "' must be a single non-empty character value.", call. = FALSE) } - if( !(tree.name %in% names(x@rowTree)) ){ - stop("'", name, "' must specify a tree from 'x@rowTree'.", + if( !(tree.name %in% rowTreeNames(x)) ){ + stop("'", name, "' must specify a tree from 'rowTreeNames(x)'.", call. = FALSE) } } @@ -120,8 +120,8 @@ stop("'", name, "' must be a single non-empty character value.", call. = FALSE) } - if( !(tree.name %in% names(x@colTree)) ){ - stop("'", name, "' must specify a tree from 'x@colTree'.", + if( !(tree.name %in% colTreeNames(x)) ){ + stop("'", name, "' must specify a tree from 'colTreeNames(x)'.", call. = FALSE) } } From fc477e924a03d7bfd45ad0571c02d6f36ddb5dbb Mon Sep 17 00:00:00 2001 From: TuomasBorman Date: Fri, 6 Dec 2024 16:28:36 +0200 Subject: [PATCH 2/9] Fix indentation --- R/addAlpha.R | 54 ++++++----- R/addDissimilarity.R | 3 +- R/calculateDMM.R | 22 ++--- R/calculateJSD.R | 14 +-- R/calculateUnifrac.R | 6 +- R/cluster.R | 10 +- R/convertToPhyloseq.R | 45 ++++----- R/decontam.R | 132 +++++++++++++------------- R/estimateDiversity.R | 10 +- R/estimateDominance.R | 6 +- R/estimateEvenness.R | 9 +- R/getPrevalence.R | 3 +- R/importHumann.R | 8 +- R/importMetaphlan.R | 39 ++++---- R/importMothur.R | 18 ++-- R/importQIIME2.R | 23 +++-- R/importTaxpasta.R | 9 +- R/mediate.R | 107 ++++++++++----------- R/mergeSEs.R | 214 +++++++++++++++++++++++------------------- R/mia.R | 75 ++++++++++----- R/rarefyAssay.R | 8 +- R/runDPCoA.R | 55 +++++------ R/runNMDS.R | 71 +++++++------- R/splitByRanks.R | 53 +++++------ R/summaries.R | 121 +++++++++++++----------- R/taxonomy.R | 22 +++-- vignettes/mia.Rmd | 81 +++++++++------- 27 files changed, 658 insertions(+), 560 deletions(-) diff --git a/R/addAlpha.R b/R/addAlpha.R index c13f9c109..56c549c09 100644 --- a/R/addAlpha.R +++ b/R/addAlpha.R @@ -24,42 +24,43 @@ #' depth i.e. the number of counts drawn from each sample. #' (Default: \code{min(colSums2(assay(x, assay.type)))}) #' -#' \item \code{tree.name}: \code{Character scalar}. Specifies which rowTree +#' \item \code{tree.name}: \code{Character scalar}. Specifies which rowTree #' will be used. ( Faith's index). (Default: \code{"phylo"}) #' -#' \item \code{node.label}: \code{Character vector} or \code{NULL} Specifies the -#' links between rows and node labels of phylogeny tree specified -#' by \code{tree.name}. If a certain row is not linked with the tree, missing -#' instance should be noted as NA. When \code{NULL}, all the rownames should +#' \item \code{node.label}: \code{Character vector} or \code{NULL} Specifies +#' the links between rows and node labels of phylogeny tree specified +#' by \code{tree.name}. If a certain row is not linked with the tree, missing +#' instance should be noted as NA. When \code{NULL}, all the rownames should #' be found from the tree. (Faith's index). (Default: \code{NULL}) #' #' \item \code{only.tips}: (Faith's index). \code{Logical scalar}. Specifies -#' whether to remove internal nodes when Faith's index is calculated. -#' When \code{only.tips=TRUE}, those rows that are not tips of tree are +#' whether to remove internal nodes when Faith's index is calculated. +#' When \code{only.tips=TRUE}, those rows that are not tips of tree are #' removed. (Default: \code{FALSE}) #' -#' \item \code{threshold}: (Coverage and all evenness indices). \code{Numeric scalar}. +#' \item \code{threshold}: (Coverage and all evenness indices). +#' \code{Numeric scalar}. #' From \code{0 to 1}, determines the threshold for coverage and evenness #' indices. When evenness indices are calculated values under or equal to #' this threshold are denoted as zeroes. For coverage index, see details. #' (Default: \code{0.5} for coverage, \code{0} for evenness indices) #' -#' \item \code{quantile}: (log modulo skewness index). \code{Numeric scalar}. -#' Arithmetic abundance classes are evenly cut up to to this quantile of the data. -#' The assumption is that abundances higher than this are not common, and they -#' are classified in their own group. (Default: \code{0.5}) +#' \item \code{quantile}: (log modulo skewness index). \code{Numeric scalar}. +#' Arithmetic abundance classes are evenly cut up to to this quantile of the +#' data. The assumption is that abundances higher than this are not common, +#' and they are classified in their own group. (Default: \code{0.5}) #' -#' \item \code{nclasses}: (log modulo skewness index). \code{Integer scalar}. -#' The number of arithmetic abundance classes from zero to the quantile cutoff +#' \item \code{nclasses}: (log modulo skewness index). \code{Integer scalar}. +#' The number of arithmetic abundance classes from zero to the quantile cutoff #' indicated by \code{quantile}. (Default: \code{50}) #' -#' \item \code{ntaxa}: (absolute and relative indices). \code{Integer scalar}. +#' \item \code{ntaxa}: (absolute and relative indices). \code{Integer scalar}. #' The n-th position of the dominant taxa to consider. (Default: \code{1}) #' -#' \item \code{aggregate}: (absolute, dbp, dmn, and relative indices). -#' \code{Logical scalar}. Aggregate the values for top members selected by -#' \code{ntaxa} or not. If \code{TRUE}, then the sum of relative abundances -#' is returned. Otherwise the relative abundance is returned for the single +#' \item \code{aggregate}: (absolute, dbp, dmn, and relative indices). +#' \code{Logical scalar}. Aggregate the values for top members selected by +#' \code{ntaxa} or not. If \code{TRUE}, then the sum of relative abundances +#' is returned. Otherwise the relative abundance is returned for the single #' taxa with the indicated rank (default: \code{aggregate = TRUE}). #' #' \item \code{detection}: (observed index). \code{Numeric scalar} Selects @@ -204,9 +205,9 @@ #' species. #' #' \item 'simpson_lambda': Simpson's (dominance) index or Simpson's lambda is -#' the sum of squared relative abundances. This index gives values in the unit interval. -#' This value equals the probability that two randomly chosen individuals -#' belongs to the +#' the sum of squared relative abundances. This index gives values in the unit +#' interval. This value equals the probability that two randomly chosen +#' individuals belongs to the #' same species. The higher the probability, the greater the dominance (See #' e.g. Simpson 1949). #' @@ -233,10 +234,13 @@ #' The available evenness indices include the following (all in lowercase): #' \itemize{ #' \item 'camargo': Camargo's evenness (Camargo 1992) -#' \item 'simpson_evenness': Simpson’s evenness is calculated as inverse Simpson diversity (1/lambda) divided by +#' \item 'simpson_evenness': Simpson’s evenness is calculated as inverse +#' Simpson diversity (1/lambda) divided by #' observed species richness S: (1/lambda)/S. -#' \item 'pielou': Pielou's evenness (Pielou, 1966), also known as Shannon or Shannon-Weaver/Wiener/Weiner -#' evenness; H/ln(S). The Shannon-Weaver is the preferred term; see Spellerberg and Fedor (2003). +#' \item 'pielou': Pielou's evenness (Pielou, 1966), also known as Shannon or +#' Shannon-Weaver/Wiener/Weiner +#' evenness; H/ln(S). The Shannon-Weaver is the preferred term; see +#' Spellerberg and Fedor (2003). #' \item 'evar': Smith and Wilson’s Evar index (Smith & Wilson 1996). #' \item 'bulla': Bulla’s index (O) (Bulla 1994). #' } diff --git a/R/addDissimilarity.R b/R/addDissimilarity.R index 326db28d4..1d91124a8 100644 --- a/R/addDissimilarity.R +++ b/R/addDissimilarity.R @@ -8,7 +8,8 @@ #' types of dissimilarities, they rely on \code{\link[vegan:vegdist]{vegdist}} #' by default. #' -#' @param x \code{\link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment}} +#' @param x +#' \code{\link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment}} #' or \code{matrix}. #' #' @param method \code{Character scalar}. Specifies which dissimilarity to diff --git a/R/calculateDMM.R b/R/calculateDMM.R index d3cca3ca0..e08f9009c 100644 --- a/R/calculateDMM.R +++ b/R/calculateDMM.R @@ -5,8 +5,8 @@ #' package #' #' @param x a numeric matrix with samples as rows or a -#' \code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}} -#' object. +#' \code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}} +#' object. #' #' @param assay.type \code{Character scalar}. Specifies the name of the #' assay used in calculation. (Default: \code{"counts"}) @@ -15,24 +15,24 @@ #' #' @param assay_name Deprecated. Use \code{assay.type} instead. #' -#' @param k \code{Numeric scalar}. The number of Dirichlet components to fit. See -#' \code{\link[DirichletMultinomial:dmn]{dmn}}. (Default: \code{1}) +#' @param k \code{Numeric scalar}. The number of Dirichlet components to fit. +#' See \code{\link[DirichletMultinomial:dmn]{dmn}}. (Default: \code{1}) #' #' @param BPPARAM A #' \code{\link[BiocParallel:BiocParallelParam-class]{BiocParallelParam}} #' object specifying whether the calculation should be parallelized. #' -#' @param transposed \code{Logical scalar}. Is \code{x} transposed with samples in rows? -#' (Default: \code{FALSE}) +#' @param transposed \code{Logical scalar}. Is \code{x} transposed with samples +#' in rows? (Default: \code{FALSE}) #' -#' @param type \code{Character scalar}. The type of measure used for the goodness of fit. One of -#' \sQuote{laplace}, \sQuote{AIC} or \sQuote{BIC}. +#' @param type \code{Character scalar}. The type of measure used for the +#' goodness of fit. One of \sQuote{laplace}, \sQuote{AIC} or \sQuote{BIC}. #' #' @param name \code{Character scalar}. The name to store the result in -#' \code{\link[SummarizedExperiment:RangedSummarizedExperiment-class]{metadata}} +#' \code{\link[SummarizedExperiment:RangedSummarizedExperiment-class]{metadata}} #' -#' @param variable \code{Character scalar}. A variable from \code{colData} to use as a -#' grouping variable. Must be a character of factor. +#' @param variable \code{Character scalar}. A variable from \code{colData} to +#' use as a grouping variable. Must be a character of factor. #' #' @param seed \code{Numeric scalar}. Random number seed. See #' \code{\link[DirichletMultinomial:dmn]{dmn}} diff --git a/R/calculateJSD.R b/R/calculateJSD.R index 19cb08413..d89fe6aec 100644 --- a/R/calculateJSD.R +++ b/R/calculateJSD.R @@ -5,7 +5,8 @@ .JSD <- function(x, y){ # Function to compute Shannon-Jensen Divergence # x and y are the frequencies for the same p categories - # Assumes relative abundance transformation already happened (for efficiency) + # Assumes relative abundance transformation already happened + # (for efficiency) # Define the mean point m <- (x+y)/2 @@ -30,7 +31,7 @@ rownames(x) <- seq_len(nrow(x)) } if(missing(chunkSize) || is.na(chunkSize) || is.null(chunkSize) || - !is.integer(chunkSize)){ + !is.integer(chunkSize)){ chunkSize <- nrow(x) } else if(length(chunkSize) != 1L) { chunkSize <- chunkSize[1L] @@ -55,10 +56,11 @@ FUN <- function(X, a, b){ .JSD(X[a,,drop=FALSE], X[b,,drop=FALSE]) } - distlist <- BiocParallel::bpmapply(FUN, A, B, - MoreArgs = list(X = x), - BPPARAM = BPPARAM, - SIMPLIFY = FALSE) + distlist <- BiocParallel::bpmapply( + FUN, A, B, + MoreArgs = list(X = x), + BPPARAM = BPPARAM, + SIMPLIFY = FALSE) distlist <- do.call(c, unname(distlist)) # reformat # initialize distmat with NAs diff --git a/R/calculateUnifrac.R b/R/calculateUnifrac.R index 634b1bc9e..b9e58c7ee 100644 --- a/R/calculateUnifrac.R +++ b/R/calculateUnifrac.R @@ -35,7 +35,8 @@ "Incompatible tree and abundance table! Please try to provide ", "'node.label'.", call. = FALSE) } - # Merge rows, so that rows that are assigned to same tree node are agglomerated + # Merge rows, so that rows that are assigned to same tree node are + # agglomerated # together. If nodeLabs were provided, merge based on those. Otherwise merge # based on rownames if( is.null(node.label) ){ @@ -67,7 +68,8 @@ return(res) } -# Aggregate matrix based on nodeLabs. At the same time, rename rows based on node.label +# Aggregate matrix based on nodeLabs. At the same time, rename rows based on +# node.label # --> each row represent specific node of tree #' @importFrom scuttle sumCountsAcrossFeatures .merge_assay_by_rows <- function(x, node.label, average = FALSE, ...){ diff --git a/R/cluster.R b/R/cluster.R index 94faeb969..46ed6a345 100644 --- a/R/cluster.R +++ b/R/cluster.R @@ -4,8 +4,8 @@ #' information in its colData or rowData #' #' @param x A -#' \code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}} -#' object. +#' \code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}} +#' object. #' #' @param by \code{Character scalar}. Determines if association is calculated #' row-wise / for features ('rows') or column-wise / for samples ('cols'). @@ -34,9 +34,9 @@ #' By default, clustering is done on the features. #' #' @return -#' \code{addCluster} returns an object of the same type as the \code{x} parameter -#' with clustering information named \code{clusters} stored in \code{colData} -#' or \code{rowData}. +#' \code{addCluster} returns an object of the same type as the \code{x} +#' parameter with clustering information named \code{clusters} stored in +#' \code{colData} or \code{rowData}. #' #' @name addCluster #' @export diff --git a/R/convertToPhyloseq.R b/R/convertToPhyloseq.R index 321969fb2..ed9a1739f 100644 --- a/R/convertToPhyloseq.R +++ b/R/convertToPhyloseq.R @@ -51,28 +51,27 @@ #' #' @export setGeneric("convertToPhyloseq", signature = c("x"), - function(x, ...) - standardGeneric("convertToPhyloseq")) + function(x, ...) + standardGeneric("convertToPhyloseq")) #' @rdname convertFromPhyloseq #' @export -setMethod("convertToPhyloseq", - signature = c(x = "SummarizedExperiment"), +setMethod("convertToPhyloseq", signature = c(x = "SummarizedExperiment"), function(x, assay.type = "counts", assay_name = NULL, ...){ # Input check .require_package("phyloseq") # Check that tse do not have zero rows if(!all(dim(x) > 0)){ stop("'x' contains zero rows. 'x' can not be converted - to a phyloseq object.", - call. = FALSE) + to a phyloseq object.", call. = FALSE) } if (!is.null(assay_name)) { - .Deprecated(old="assay_name", new="assay.type", "Now assay_name is deprecated. Use assay.type instead.") + .Deprecated(old="assay_name", new="assay.type", + "Now assay_name is deprecated. Use assay.type instead.") } - + # Check assay.type .check_assay_present(assay.type, x) @@ -91,7 +90,7 @@ setMethod("convertToPhyloseq", # If rowData includes information if(!( length(rowData(x)[,taxonomyRanks(x)]) == 0 || - is.null((rowData(x)[,taxonomyRanks(x)])) )){ + is.null((rowData(x)[,taxonomyRanks(x)])) )){ # Converts taxonomy table to characters if it's not already rowData(x) <- DataFrame(lapply(rowData(x), as.character)) # Gets the taxonomic data from rowData, and converts it to tax_table @@ -118,8 +117,7 @@ setMethod("convertToPhyloseq", #' @rdname convertFromPhyloseq #' @export -setMethod("convertToPhyloseq", - signature = c(x = "TreeSummarizedExperiment"), +setMethod("convertToPhyloseq", signature = c(x = "TreeSummarizedExperiment"), function(x, tree.name = tree_name, tree_name = "phylo", ...){ # If rowTrees exist, check tree.name if( length(rowTreeNames(x)) > 0 ){ @@ -132,7 +130,7 @@ setMethod("convertToPhyloseq", } # - # phyloseq and tree objects require nonduplicated rownames. If there are + # phyloseq and tree objects require nonduplicated rownames. If there are # duplicated rownames, they are converted so that they are unique if( any(duplicated(rownames(x))) ){ rownames(x) <- getTaxonomyLabels(x) @@ -235,24 +233,27 @@ setMethod("convertToPhyloseq", # Take only one set, if it is a list if( is_list ){ # Check referenceSeq - if( !( (.is_non_empty_string(referenceSeq) && referenceSeq %in% names(refSeqs)) || - (.is_an_integer(referenceSeq) && (referenceSeq>0 && referenceSeq<=length(refSeqs))) ) + if( !( (.is_non_empty_string(referenceSeq) && + referenceSeq %in% names(refSeqs)) || + (.is_an_integer(referenceSeq) && (referenceSeq>0 && + referenceSeq<=length(refSeqs))) ) ){ - stop("'referenceSeq' must be a non-empty single character value or an integer ", - "specifying the DNAStringSet from DNAStringSetList.", - call. = FALSE) + stop("'referenceSeq' must be a non-empty single character value ", + "or an integer ", + "specifying the DNAStringSet from DNAStringSetList.", + call. = FALSE) } # Get specified referenceSeq refSeqs <- refSeqs[[referenceSeq]] - warning("Use 'referenceSeq' to specify DNA set from DNAStringSetList. ", - "Current choice is '", referenceSeq, "'.", - call. = FALSE) + warning("Use 'referenceSeq' to specify DNA set from ", + "DNAStringSetList. ", + "Current choice is '", referenceSeq, "'.", call. = FALSE) } # Check if all rownames have referenceSeqs if( !(all(rownames(x) %in% names(refSeqs)) && all(names(refSeqs) %in% rownames(x) )) ){ - warning("referenceSeq does not match with rownames so they are discarded.", - call. = FALSE) + warning("referenceSeq does not match with rownames so they are ", + "discarded.", call. = FALSE) refSeqs <- NULL } return(refSeqs) diff --git a/R/decontam.R b/R/decontam.R index ce48b532e..11a204f5b 100644 --- a/R/decontam.R +++ b/R/decontam.R @@ -8,11 +8,12 @@ #' @inheritParams getDissimilarity #' @inheritParams getDominant #' -#' @param seqtab,x -#' a \code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}} +#' @param seqtab,x a +#' \code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}} #' #' @param name \code{Character scalar}. A name for the column of the -#' \code{colData} where results will be stored. (Default: \code{"isContaminant"}) +#' \code{colData} where results will be stored. +#' (Default: \code{"isContaminant"}) #' #' @param concentration \code{Character scalar} or \code{NULL}. Defining #' a column with numeric values from the \code{colData} to use as @@ -26,9 +27,9 @@ #' column with values interpretable as a factor from the \code{colData} to use #' as batch information. (Default: \code{NULL}) #' -#' @param detailed \code{Logical scalar}. If \code{TRUE}, the return value is a -#' data.frame containing diagnostic information on the contaminant decision. -#' If FALSE, the return value is a logical vector containing the binary +#' @param detailed \code{Logical scalar}. If \code{TRUE}, the return value is a +#' data.frame containing diagnostic information on the contaminant decision. +#' If FALSE, the return value is a logical vector containing the binary #' contaminant classifications. (Default: \code{TRUE}) #' #' @param ... arguments passed onto @@ -87,16 +88,17 @@ NULL #' @rdname isContaminant #' @export setMethod("isContaminant", signature = c(seqtab = "SummarizedExperiment"), - function(seqtab, - assay.type = assay_name, assay_name = "counts", - name = "isContaminant", - concentration = NULL, - control = NULL, - batch = NULL, - threshold = 0.1, - normalize = TRUE, - detailed = TRUE, - ...){ + function( + seqtab, + assay.type = assay_name, assay_name = "counts", + name = "isContaminant", + concentration = NULL, + control = NULL, + batch = NULL, + threshold = 0.1, + normalize = TRUE, + detailed = TRUE, + ...){ # input check .check_assay_present(assay.type, seqtab) if(!.is_a_string(name)){ @@ -113,46 +115,46 @@ setMethod("isContaminant", signature = c(seqtab = "SummarizedExperiment"), } # if(!is.null(concentration)){ - concentration <- retrieveCellInfo(seqtab, by = concentration, - search = "colData")$value + concentration <- retrieveCellInfo( + seqtab, by = concentration, search = "colData")$value if(!is.numeric(concentration)){ stop("'concentration' must define a column of colData() ", - "containing numeric values.", - call. = FALSE) + "containing numeric values.", call. = FALSE) } } if(!is.null(control)){ - control <- retrieveCellInfo(seqtab, by = control, - search = "colData")$value + control <- retrieveCellInfo( + seqtab, by = control, search = "colData")$value if(!is.logical(control)){ stop("'control' must define a column of colData() ", - "containing logical values.", - call. = FALSE) + "containing logical values.", call. = FALSE) } } if(!is.null(batch)){ - batch <- retrieveCellInfo(seqtab, by = batch, - search = "colData")$value + batch <- retrieveCellInfo( + seqtab, by = batch, search = "colData")$value batch <- factor(batch, sort(unique(batch))) } mat <- assay(seqtab,assay.type) - contaminant <- isContaminant(t(mat), - conc = concentration, - neg = control, - batch = batch, - threshold = threshold, - normalize = normalize, - detailed = detailed, - ...) + contaminant <- isContaminant( + t(mat), + conc = concentration, + neg = control, + batch = batch, + threshold = threshold, + normalize = normalize, + detailed = detailed, + ...) if(is.data.frame(contaminant)){ contaminant <- DataFrame(contaminant) } - attr(contaminant, "metadata") <- list(conc = concentration, - neg = control, - batch = batch, - threshold = threshold, - normalize = normalize, - detailed = detailed) + attr(contaminant, "metadata") <- list( + conc = concentration, + neg = control, + batch = batch, + threshold = threshold, + normalize = normalize, + detailed = detailed) contaminant } ) @@ -160,14 +162,15 @@ setMethod("isContaminant", signature = c(seqtab = "SummarizedExperiment"), #' @rdname isContaminant #' @export setMethod("isNotContaminant", signature = c(seqtab = "SummarizedExperiment"), - function(seqtab, - assay.type = assay_name, assay_name = "counts", - name = "isNotContaminant", - control = NULL, - threshold = 0.5, - normalize = TRUE, - detailed = FALSE, - ...){ + function( + seqtab, + assay.type = assay_name, assay_name = "counts", + name = "isNotContaminant", + control = NULL, + threshold = 0.5, + normalize = TRUE, + detailed = FALSE, + ...){ # input check .check_assay_present(assay.type, seqtab) if(!.is_a_string(name)){ @@ -188,24 +191,25 @@ setMethod("isNotContaminant", signature = c(seqtab = "SummarizedExperiment"), search = "colData")$value if(!is.logical(control)){ stop("'control' must define a column of colData() ", - "containing logical values.", - call. = FALSE) + "containing logical values.", call. = FALSE) } } mat <- assay(seqtab,assay.type) - not_contaminant <- isNotContaminant(t(mat), - neg = control, - threshold = threshold, - normalize = normalize, - detailed = detailed, - ...) + not_contaminant <- isNotContaminant( + t(mat), + neg = control, + threshold = threshold, + normalize = normalize, + detailed = detailed, + ...) if(is.data.frame(not_contaminant)){ not_contaminant <- DataFrame(not_contaminant) } - attr(not_contaminant, "metadata") <- list(neg = control, - threshold = threshold, - normalize = normalize, - detailed = detailed) + attr(not_contaminant, "metadata") <- list( + neg = control, + threshold = threshold, + normalize = normalize, + detailed = detailed) not_contaminant } ) @@ -213,8 +217,8 @@ setMethod("isNotContaminant", signature = c(seqtab = "SummarizedExperiment"), #' @rdname isContaminant #' @export setGeneric("addContaminantQC", signature = c("x"), - function(x, name = "isContaminant", ...) - standardGeneric("addContaminantQC")) + function(x, name = "isContaminant", ...) + standardGeneric("addContaminantQC")) #' @rdname isContaminant #' @export @@ -235,8 +239,8 @@ setMethod("addContaminantQC", signature = c("SummarizedExperiment"), #' @rdname isContaminant #' @export setGeneric("addNotContaminantQC", signature = c("x"), - function(x, name = "isNotContaminant", ...) - standardGeneric("addNotContaminantQC")) + function(x, name = "isNotContaminant", ...) + standardGeneric("addNotContaminantQC")) #' @rdname isContaminant #' @export diff --git a/R/estimateDiversity.R b/R/estimateDiversity.R index 6d9dfa5bb..5d000d4c7 100644 --- a/R/estimateDiversity.R +++ b/R/estimateDiversity.R @@ -38,10 +38,10 @@ #' #' @param tree_name Deprecated. Use \code{tree.name} instead. #' -#' @param node.label NULL or a character vector specifying the links between rows and -#' node labels of \code{tree}. If a certain row is not linked with the tree, missing -#' instance should be noted as NA. When NULL, all the rownames should be found from -#' the tree. (By default: \code{node.label = NULL}) +#' @param node.label NULL or a character vector specifying the links between +#' rows and node labels of \code{tree}. If a certain row is not linked with +#' the tree, missing instance should be noted as NA. When NULL, all the rownames +#' should be found from the tree. (By default: \code{node.label = NULL}) #' #' @param node_lab Deprecated. Use \code{node.label} instead. #' @@ -304,7 +304,7 @@ NULL # Check that node.label is NULL or it specifies links between rownames and # node labs if( !( is.null(node.label) || - is.character(node.label) && length(node.label) == nrow(x) ) ){ + is.character(node.label) && length(node.label) == nrow(x) ) ){ stop( "'node.label' must be NULL or a vector specifying links between ", "rownames and node labs of 'tree'.", diff --git a/R/estimateDominance.R b/R/estimateDominance.R index bc8a342ba..ca6ce474b 100644 --- a/R/estimateDominance.R +++ b/R/estimateDominance.R @@ -121,7 +121,8 @@ #' species. #' #' \item 'simpson_lambda': Simpson's (dominance) index or Simpson's lambda is -#' the sum of squared relative abundances. This index gives values in the unit interval. +#' the sum of squared relative abundances. This index gives values in the unit +#' interval. #' This value equals the probability that two randomly chosen individuals #' belongs to the #' same species. The higher the probability, the greater the dominance (See @@ -242,8 +243,7 @@ setGeneric( index <- match.arg(index, several.ok = TRUE) if(!.is_non_empty_character(name) || length(name) != length(index)){ stop("'name' must be a non-empty character value and have the - same length as 'index'", - call. = FALSE) + same length as 'index'", call. = FALSE) } # Check aggregate diff --git a/R/estimateEvenness.R b/R/estimateEvenness.R index cd542d021..c17d5d1f4 100644 --- a/R/estimateEvenness.R +++ b/R/estimateEvenness.R @@ -44,10 +44,13 @@ #' The available evenness indices include the following (all in lowercase): #' \itemize{ #' \item 'camargo': Camargo's evenness (Camargo 1992) -#' \item 'simpson_evenness': Simpson’s evenness is calculated as inverse Simpson diversity (1/lambda) divided by +#' \item 'simpson_evenness': Simpson’s evenness is calculated as inverse +#' Simpson diversity (1/lambda) divided by #' observed species richness S: (1/lambda)/S. -#' \item 'pielou': Pielou's evenness (Pielou, 1966), also known as Shannon or Shannon-Weaver/Wiener/Weiner -#' evenness; H/ln(S). The Shannon-Weaver is the preferred term; see Spellerberg and Fedor (2003). +#' \item 'pielou': Pielou's evenness (Pielou, 1966), also known as Shannon or +#' Shannon-Weaver/Wiener/Weiner +#' evenness; H/ln(S). The Shannon-Weaver is the preferred term; see +#' Spellerberg and Fedor (2003). #' \item 'evar': Smith and Wilson’s Evar index (Smith & Wilson 1996). #' \item 'bulla': Bulla’s index (O) (Bulla 1994). #' } diff --git a/R/getPrevalence.R b/R/getPrevalence.R index 6ccf3a850..7b0621ead 100644 --- a/R/getPrevalence.R +++ b/R/getPrevalence.R @@ -5,7 +5,8 @@ #' #' @inheritParams getDissimilarity #' -#' @param x \code{\link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment}}. +#' @param x +#' \code{\link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment}}. #' #' @param assay_name Deprecated. Use \code{assay.type} instead. #' diff --git a/R/importHumann.R b/R/importHumann.R index a08a03011..92c88703c 100644 --- a/R/importHumann.R +++ b/R/importHumann.R @@ -12,9 +12,8 @@ #' #' @param ... additional arguments: #' \itemize{ -#' \item \code{assay.type}: \code{Character scalar}. Specifies the name of the assy -#' used in calculation. -#' (Default: \code{"counts"}) +#' \item \code{assay.type}: \code{Character scalar}. Specifies the name of +#' the assay used in calculation. (Default: \code{"counts"}) #' \item \code{prefix.rm}: \code{Logical scalar}. Should #' taxonomic prefixes be removed? (Default: \code{FALSE}) #' \item \code{remove.suffix}: \code{Logical scalar}. Should @@ -140,7 +139,8 @@ importHUMAnN <- function(file, col.data = colData, colData = NULL, ...){ } # This function parses humann file and creates tse from it. -.create_tse_from_humann <- function(data, rowdata_col, assay.type = "counts", ...){ +.create_tse_from_humann <- function( + data, rowdata_col, assay.type = "counts", ...){ # Get rowdata columns rowdata_id <- unlist(lapply(rowdata_col, grep, colnames(data))) rowdata <- data[ , rowdata_id, drop = FALSE] diff --git a/R/importMetaphlan.R b/R/importMetaphlan.R index 53ebe5719..2945bff62 100644 --- a/R/importMetaphlan.R +++ b/R/importMetaphlan.R @@ -20,8 +20,8 @@ #' #' @param ... additional arguments: #' \itemize{ -#' \item \code{assay.type}: \code{Character scalar}. Specifies the name of the assay -#' used in calculation. (Default: \code{"counts"}) +#' \item \code{assay.type}: \code{Character scalar}. Specifies the name of +#' the assay used in calculation. (Default: \code{"counts"}) #' \item \code{prefix.rm}: \code{Logical scalar}. Should #' taxonomic prefixes be removed? (Default: \code{FALSE}) #' \item \code{remove.suffix}: \code{Logical scalar}. Should @@ -63,9 +63,10 @@ #' @export #' #' @references -#' Beghini F, McIver LJ, Blanco-Míguez A, Dubois L, Asnicar F, Maharjan S, Mailyan A, -#' Manghi P, Scholz M, Thomas AM, Valles-Colomer M, Weingart G, Zhang Y, Zolfo M, -#' Huttenhower C, Franzosa EA, & Segata N (2021) Integrating taxonomic, functional, +#' Beghini F, McIver LJ, Blanco-Míguez A, Dubois L, Asnicar F, Maharjan S, +#' Mailyan A, Manghi P, Scholz M, Thomas AM, Valles-Colomer M, Weingart G, +#' Zhang Y, Zolfo M, Huttenhower C, Franzosa EA, & Segata N (2021) +#' Integrating taxonomic, functional, #' and strain-level profiling of diverse microbial communities with bioBakery 3. #' \emph{eLife}. 10:e65088. doi: 10.7554/eLife.65088 #' @@ -91,7 +92,7 @@ importMetaPhlAn <- function( file, col.data = colData, colData = sample_meta, sample_meta = NULL, tree.file = phy_tree, phy_tree = NULL, ...){ - ################################ Input check ################################ + ################################ Input check ############################### if(!.is_non_empty_string(file)){ stop("'file' must be a single character value.", call. = FALSE) @@ -115,7 +116,8 @@ importMetaPhlAn <- function( rowdata_col <- c("clade_name", "ID", "_id", "taxonomy") # Read metaphlan data data <- .read_metaphlan(file, rowdata_col, ...) - # Parse data into separate tables, which include data at certain taxonomy rank + # Parse data into separate tables, which include data at certain taxonomy + # rank tables <- .parse_metaphlan(data, ...) # Create multiple SE objects at different rank from the data @@ -166,12 +168,13 @@ importMetaPhlAn <- function( # Read the table. Catch error and give more informative message table <- tryCatch( { - read.table(file, header = TRUE, comment.char = "#", check.names = FALSE) + read.table( + file, header = TRUE, comment.char = "#", check.names = FALSE) }, error = function(condition){ stop("Error while reading ", file, - "\nPlease check that the file is in merged Metaphlan file format.", - call. = FALSE) + "\nPlease check that the file is in merged Metaphlan file ", + "format.", call. = FALSE) } ) # Check that file is in right format @@ -197,8 +200,8 @@ importMetaPhlAn <- function( # Initialize result result <- TRUE - # Check rowdata column names that they contain right information, and check that - # rest of the columns represents abundances in samples. + # Check rowdata column names that they contain right information, and check + # that rest of the columns represents abundances in samples. # If these requirements are met, give FALSE. Otherwise, give TRUE. if( length(rowdata_id) > 0 && all(unlist(lapply(assay_columns, is.numeric))) ){ @@ -207,8 +210,8 @@ importMetaPhlAn <- function( return(result) } -# Get metaphlan table as input and return multiple tables which each include data at -# certain taxonomy rank +# Get metaphlan table as input and return multiple tables which each include +# data at certain taxonomy rank .parse_metaphlan <- function(table, ...){ # ID in Metaphlan v2, > 2 clade_name col <- colnames(table) %in% c("clade_name", "ID") @@ -233,8 +236,9 @@ importMetaPhlAn <- function( return(tables) } -# Get the lowest level of the string that contains multiple taxonomic levels with prefixes -# Output is single character that specifies the rank, e.g, "s" == "Species" +# Get the lowest level of the string that contains multiple taxonomic levels +# with prefixes Output is single character that specifies the rank, e.g, +# "s" == "Species" .get_lowest_taxonomic_level <- function(string){ # List all ranks and what prefix they correspond ranks <- .taxonomy_rank_prefixes @@ -245,7 +249,8 @@ importMetaPhlAn <- function( # Get the location of lowest rank lowest_level_ind <- levels[length(levels)] # Get the lowest rank that was found - lowest_level <- substr(string, start = lowest_level_ind, stop = lowest_level_ind) + lowest_level <- substr( + string, start = lowest_level_ind, stop = lowest_level_ind) # Convert prefix into full rank name lowest_level <- names(ranks[ match(lowest_level, ranks) ]) diff --git a/R/importMothur.R b/R/importMothur.R index fc364e677..ff6d7ab2b 100644 --- a/R/importMothur.R +++ b/R/importMothur.R @@ -1,7 +1,7 @@ #' Import Mothur results as a \code{TreeSummarizedExperiment} #' -#' This method creates a \code{TreeSummarizedExperiment} object from \code{Mothur} -#' files provided as input. +#' This method creates a \code{TreeSummarizedExperiment} object from +#' \code{Mothur} files provided as input. #' #' @param assay.file \code{Character scalar}. Defines the file #' path of the feature table to be imported. The File has to be in @@ -50,7 +50,8 @@ #' # Abundance table #' counts <- system.file("extdata", "mothur_example.shared", package = "mia") #' # Taxa table (in "cons.taxonomy" or "taxonomy" format) -#' taxa <- system.file("extdata", "mothur_example.cons.taxonomy", package = "mia") +#' taxa <- system.file( +#' "extdata", "mothur_example.cons.taxonomy", package = "mia") #' #taxa <- system.file("extdata", "mothur_example.taxonomy", package = "mia") #' # Sample meta data #' meta <- system.file("extdata", "mothur_example.design", package = "mia") @@ -112,9 +113,10 @@ importMothur <- function(assay.file = sharedFile, rownames(sample_meta) <- colnames(feature_tab) } - TreeSummarizedExperiment(assays = S4Vectors::SimpleList(counts = feature_tab), - rowData = taxa_tab, - colData = sample_meta) + TreeSummarizedExperiment( + assays = S4Vectors::SimpleList(counts = feature_tab), + rowData = taxa_tab, + colData = sample_meta) } # These extra information must be added to colData. Return list of assay and @@ -266,7 +268,7 @@ importMothur <- function(assay.file = sharedFile, data <- read.table(file, check.names=FALSE, header=TRUE, sep="\t", stringsAsFactors=FALSE) - # If data contains column names, and "OTU" column that includes same taxa as + # If data contains column names, and "OTU" column that includes same taxa as # feature_tab, # then it is constaxonomy file if( identical(colnames(data), columns_that_must_be_found) && @@ -282,7 +284,7 @@ importMothur <- function(assay.file = sharedFile, data <- read.table(file, check.names=FALSE, header=TRUE, sep="\t", stringsAsFactors=FALSE) - # If data contains "group" column that include sample names, then it is + # If data contains "group" column that include sample names, then it is # design file if( identical(data$group, sample_names) ){ result <- TRUE diff --git a/R/importQIIME2.R b/R/importQIIME2.R index e29e2b1b3..63ab2756e 100644 --- a/R/importQIIME2.R +++ b/R/importQIIME2.R @@ -31,8 +31,8 @@ #' #' @param featureNamesAsRefSeq Deprecated. Use \code{as.refseq} instead. #' -#' @param refseq.file \code{Character scalar} or \code{NULL}. Defines the file path of -#' the reference sequences for each feature. (Default: \code{NULL}). +#' @param refseq.file \code{Character scalar} or \code{NULL}. Defines the file +#' path of the reference sequences for each feature. (Default: \code{NULL}). #' #' @param refSeqFile Deprecated. Use \code{refseq.file} instead. #' @@ -108,7 +108,7 @@ importQIIME2 <- function(assay.file = featureTableFile, refSeqFile = NULL, tree.file = phyTreeFile, phyTreeFile = NULL, - ...) { + ...) { .require_package("yaml") # input check if(!.is_non_empty_string(assay.file)){ @@ -187,8 +187,8 @@ importQIIME2 <- function(assay.file = featureTableFile, #' table), `NewickDirectoryFormat` (phylogenetic tree ) and #' `DNASequencesDirectoryFormat` (representative sequences) are supported #' right now. -#' @param temp.dir character, a temporary directory in which the qza file will be -#' decompressed to, default `tempdir()`. +#' @param temp.dir character, a temporary directory in which the qza file will +#' be decompressed to, default `tempdir()`. #' #' @param temp Deprecated. Use \code{temp.dir} instead. #' @@ -217,7 +217,8 @@ importQIIME2 <- function(assay.file = featureTableFile, #' coldata <- coldata[match(colnames(assay), rownames(coldata)), ] #' #' # Create SE from individual files -#' se <- SummarizedExperiment(assays = list(assay), rowData = rowdata, colData = coldata) +#' se <- SummarizedExperiment( +#' assays = list(assay), rowData = rowdata, colData = coldata) #' se #' #' @importFrom utils unzip @@ -228,8 +229,8 @@ importQZA <- function(file, temp.dir = temp, temp = tempdir(), ...) { stop(file, " does not exist", call. = FALSE) } if (.get_ext(file) != "qza") { - stop("The input '", file, "' must be in `qza` format (QIIME2 Artifact)", - call. = FALSE) + stop("The input '", file, "' must be in `qza` format ", + "(QIIME2 Artifact)", call. = FALSE) } unzipped_file <- unzip(file, exdir = temp.dir) @@ -253,7 +254,8 @@ importQZA <- function(file, temp.dir = temp, temp = tempdir(), ...) { "BIOMV", "TSVTaxonomyDirectoryFormat", "NewickDirectoryFormat", "DNASequencesDirectoryFormat" ) - file <- file.path(temp.dir, uuid, "data", format_files[match(format, formats)]) + file <- file.path( + temp.dir, uuid, "data", format_files[match(format, formats)]) res <- switch ( format, @@ -299,7 +301,8 @@ importQZA <- function(file, temp.dir = temp, temp = tempdir(), ...) { featureID <- taxa_tab[,"Feature.ID"] } - taxa_tab <- .parse_taxonomy(taxa_tab, sep = "; |;", column_name = "Taxon", ...) + taxa_tab <- .parse_taxonomy( + taxa_tab, sep = "; |;", column_name = "Taxon", ...) rownames(taxa_tab) <- featureID taxa_tab$Confidence <- confidence diff --git a/R/importTaxpasta.R b/R/importTaxpasta.R index 7204b869e..b6961c780 100644 --- a/R/importTaxpasta.R +++ b/R/importTaxpasta.R @@ -21,7 +21,9 @@ #' taxonomy table be treated as taxonomy ranks? (Default: \code{FALSE}) #' } #' -#' @return A \code{\link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment}} object. +#' @return A +#' \code{\link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment}} +#' object. #' #' @examples #' @@ -52,7 +54,8 @@ importTaxpasta <- function(file, add.tree = TRUE, ...) { # Validate the input. if(!.is_non_empty_string(file) ){ - stop("'filename' must be a single non-empty character value.", call. = FALSE) + stop("'filename' must be a single non-empty character value.", + call. = FALSE) } if( !file.exists(file) ){ stop("'", file, "' not found.", call. = FALSE) @@ -75,7 +78,7 @@ importTaxpasta <- function(file, add.tree = TRUE, ...) { # Create rowData and rowTree rowData(tse) <- .create_row_data(biom, ranks) .set_ranks_based_on_rowdata(tse, ...) - if (add.tree) tse <- addHierarchyTree(tse) + if (add.tree) tse <- addHierarchyTree(tse) # Agglomerate to all existing ranks tse <- agglomerateByRanks(tse, update.tree = TRUE) } else{ diff --git a/R/mediate.R b/R/mediate.R index 61571eaad..4c5b4de49 100644 --- a/R/mediate.R +++ b/R/mediate.R @@ -4,7 +4,8 @@ #' \code{\link[mediation:mediate]{mediate}} for #' \code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}}. #' -#' @param x a \code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}}. +#' @param x a +#' \code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}}. #' #' @param outcome \code{Character scalar}. Indicates the colData variable used #' as outcome in the model. @@ -22,19 +23,19 @@ #' result in \code{reducedDims(object)} for component-wise mediation analysis. #' (Default: \code{NULL}) #' -#' @param family \code{Character scalar}. A specification for the outcome model link function. -#' (Default: \code{gaussian("identity")}) +#' @param family \code{Character scalar}. A specification for the outcome model +#' link function. (Default: \code{gaussian("identity")}) #' -#' @param covariates \code{Character scalar} or \code{character vector}. Indicates the colData -#' variables used as covariates in the model. -#' (Default: \code{NULL}) +#' @param covariates \code{Character scalar} or \code{character vector}. +#' Indicates the colData variables used as covariates in the model. +#' (Default: \code{NULL}) #' #' @param p.adj.method \code{Character scalar}. Selects adjustment method #' of p-values. Passed to `p.adjust` function. #' (Default: \code{"holm"}) #' -#' @param add.metadata \code{Logical scalar}. Should the model metadata be returned. -#' (Default: \code{FALSE}) +#' @param add.metadata \code{Logical scalar}. Should the model metadata be +#' returned. (Default: \code{FALSE}) #' #' @param verbose \code{Logical scalar}. Should execution messages be printed. #' (Default: \code{TRUE}) @@ -88,7 +89,7 @@ #' tse$bmi_group <- as.numeric(tse$bmi_group) #' #' # Analyse mediated effect of nationality on BMI via alpha diversity -#' # 100 permutations were done to speed up execution, but ~1000 are recommended +#' # 100 permutations were done to speed up execution, but ~1000 are recommended #' med_df <- getMediation(tse, #' outcome = "bmi_group", #' treatment = "nationality", @@ -108,7 +109,7 @@ #' pseudocount = 1) #' #' # Analyse mediated effect of nationality on BMI via clr-transformed features -#' # 100 permutations were done to speed up execution, but ~1000 are recommended +#' # 100 permutations were done to speed up execution, but ~1000 are recommended #' tse <- addMediation(tse, name = "assay_mediation", #' outcome = "bmi_group", #' treatment = "nationality", @@ -128,8 +129,8 @@ #' assay.type = "clr", #' ncomponents = 3) #' -#' # Analyse mediated effect of nationality on BMI via NMDS components -#' # 100 permutations were done to speed up execution, but ~1000 are recommended +#' # Analyse mediated effect of nationality on BMI via NMDS components +#' # 100 permutations were done to speed up execution, but ~1000 are recommended #' tse <- addMediation(tse, name = "reddim_mediation", #' outcome = "bmi_group", #' treatment = "nationality", @@ -149,17 +150,17 @@ NULL #' @rdname getMediation #' @export setGeneric("addMediation", signature = c("x"), - function(x, ...) standardGeneric("addMediation")) + function(x, ...) standardGeneric("addMediation")) #' @rdname getMediation #' @export #' @importFrom stats gaussian setMethod("addMediation", signature = c(x = "SummarizedExperiment"), function(x, outcome, treatment, name = "mediation", - mediator = NULL, assay.type = NULL, dimred = NULL, - family = gaussian(), covariates = NULL, p.adj.method = "holm", - add.metadata = FALSE, verbose = TRUE, ...) { - + mediator = NULL, assay.type = NULL, dimred = NULL, + family = gaussian(), covariates = NULL, p.adj.method = "holm", + add.metadata = FALSE, verbose = TRUE, ...) { + med_df <- getMediation( x, outcome, treatment, mediator, assay.type, dimred, @@ -175,7 +176,7 @@ setMethod("addMediation", signature = c(x = "SummarizedExperiment"), #' @rdname getMediation #' @export setGeneric("getMediation", signature = c("x"), - function(x, ...) standardGeneric("getMediation")) + function(x, ...) standardGeneric("getMediation")) #' @rdname getMediation #' @export @@ -183,9 +184,9 @@ setGeneric("getMediation", signature = c("x"), #' @importFrom SingleCellExperiment reducedDim reducedDimNames setMethod("getMediation", signature = c(x = "SummarizedExperiment"), function(x, outcome, treatment, - mediator = NULL, assay.type = "counts", dimred = NULL, - family = gaussian(), covariates = NULL, p.adj.method = "holm", - add.metadata = FALSE, verbose = TRUE, ...) { + mediator = NULL, assay.type = "counts", dimred = NULL, + family = gaussian(), covariates = NULL, p.adj.method = "holm", + add.metadata = FALSE, verbose = TRUE, ...) { ###################### Input check ######################## if( !outcome %in% names(colData(x)) ){ @@ -232,7 +233,7 @@ setMethod("getMediation", signature = c(x = "SummarizedExperiment"), # Use mediator for analysis mediators <- mediator mat <- NULL - + } else if( med_opts[[2]] ){ # Check that assay is in assays .check_assay_present(assay.type, x) @@ -240,7 +241,7 @@ setMethod("getMediation", signature = c(x = "SummarizedExperiment"), mat <- assay(x, assay.type) # Use assay for analysis mediators <- rownames(mat) - + } else if( med_opts[[3]] ){ # Check that reducedDim is in reducedDims if(!dimred %in% reducedDimNames(x)){ @@ -262,18 +263,18 @@ setMethod("getMediation", signature = c(x = "SummarizedExperiment"), # Set initial index i <- 0 - + for( mediator in mediators ){ - + # Update index i <- i + 1 - + if( verbose ){ message("\rMediator ", i, " out of ", length(mediators), ": ", mediator ) } - + # Run mediation analysis for current mediator med_out <- .run.mediate( x, outcome, treatment, mediator, @@ -294,34 +295,32 @@ setMethod("getMediation", signature = c(x = "SummarizedExperiment"), # Check that arguments can be passed to mediate and remove unused samples #' @importFrom stats na.omit -.check.mediate.args <- function(x, outcome, treatment, mediator, - covariates, verbose = TRUE, ...) { - +.check.mediate.args <- function( + x, outcome, treatment, mediator, covariates, verbose = TRUE, ...) { + # Create dataframe from selected columns of colData - df <- as.data.frame(colData(x)[ , names(colData(x)) %in% c(outcome, - treatment, - mediator, - covariates)]) + df <- as.data.frame(colData(x)[ , names(colData(x)) %in% c( + outcome, treatment, mediator, covariates)]) # Store kwargs into variable kwargs <- list(...) - + # Remove missing data from df df <- na.omit(df) diff <- ncol(x) - nrow(df) - + if( diff != 0 ){ # Remove missing data from se x <- x[ , rownames(df)] - + if( verbose ){ message(diff, " samples removed because of missing data.") } } - + # If boot is TRUE and treatment variable is discrete and has 3+ levels if( !is.null(kwargs[["boot"]]) && !is.numeric(df[[treatment]]) && length(unique((df[[treatment]]))) > 2 ) { - + ## if control and treat value are not specified if( any(sapply(kwargs[c("control.value", "treat.value")], is.null)) ){ stop( @@ -331,7 +330,8 @@ setMethod("getMediation", signature = c(x = "SummarizedExperiment"), } ## but if they are specified # if they appear in the treatment variable - if( !all(kwargs[c("control.value", "treat.value")] %in% unique(df[[treatment]])) ){ + if( !all(kwargs[c("control.value", "treat.value")] %in% + unique(df[[treatment]])) ){ stop( "treat.value and/or control.value not found in the levels of ", "the treatment variable.", call. = FALSE @@ -363,10 +363,11 @@ setMethod("getMediation", signature = c(x = "SummarizedExperiment"), #' @importFrom stats lm formula glm .run.mediate <- function(x, outcome, treatment, mediator = NULL, mat = NULL, family = gaussian(), covariates = NULL, ...) { - + # Create initial dataframe with outcome and treatment variables - df <- data.frame(Outcome = colData(x)[[outcome]], Treatment = colData(x)[[treatment]]) - + df <- data.frame( + Outcome = colData(x)[[outcome]], Treatment = colData(x)[[treatment]]) + if( is.null(mat) ){ # If matrix not given, fetch mediator from colData df[["Mediator"]] <- colData(x)[[mediator]] @@ -374,12 +375,12 @@ setMethod("getMediation", signature = c(x = "SummarizedExperiment"), # If matrix given, use it as mediators df[["Mediator"]] <- mat[mediator, ] } - + # Define basic formula mediation model relation_m <- "Mediator ~ Treatment" # Define basic formula outcome model relation_dv <- "Outcome ~ Treatment + Mediator" - + if( !is.null(covariates) ){ # Fetch covariates from colData and store them in dataframe @@ -410,14 +411,14 @@ setMethod("getMediation", signature = c(x = "SummarizedExperiment"), treat = "Treatment", mediator = "Mediator", covariates = covariates, ... ) - + return(med_out) } # Update list of results .update.results <- function(results, med_out, mediator) { - + # Update model variables results[["Mediator"]] <- c(results[["Mediator"]], mediator) @@ -431,17 +432,17 @@ setMethod("getMediation", signature = c(x = "SummarizedExperiment"), # Add current model to metadata results[["Model"]][[length(results[["Model"]]) + 1]] <- med_out - + return(results) } # Combine results into output dataframe .make.output <- function(results, p.adj.method, add.metadata) { - + # Create dataframe with model variables, effect sizes and p-values med_df <- do.call(data.frame, results[seq_len(length(results) - 1)]) - + # Compute adjusted p-values and add them to dataframe med_df[["ACME_pval"]] <- p.adjust( med_df[["ACME_pval"]], @@ -451,14 +452,14 @@ setMethod("getMediation", signature = c(x = "SummarizedExperiment"), med_df[["ADE_pval"]], method = p.adj.method ) - + if( add.metadata ){ # models for every mediator are saved into the metadata attribute attr(med_df, "metadata") <- results[["Model"]] } - + # Order output dataframe by ACME p-values med_df <- med_df[order(med_df[["ACME_pval"]]), ] - + return(med_df) } diff --git a/R/mergeSEs.R b/R/mergeSEs.R index abb78e279..5bdf082fb 100644 --- a/R/mergeSEs.R +++ b/R/mergeSEs.R @@ -6,22 +6,24 @@ #' @param y a \code{\link{SummarizedExperiment}} object when \code{x} is a #' \code{\link{SummarizedExperiment}} object. Disabled when \code{x} is a list. #' -#' @param join \code{Character scalar}. A value for selecting the joining method. -#' Must be 'full', 'inner', 'left', or 'right'. 'left' and 'right' are disabled -#' when more than two objects are being merged. (Default: \code{"full"}) +#' @param join \code{Character scalar}. A value for selecting the joining +#' method. Must be 'full', 'inner', 'left', or 'right'. 'left' and 'right' are +#' disabled when more than two objects are being merged. +#' (Default: \code{"full"}) #' -#' @param missing.values \code{NA}, \code{0} or \code{Character scalar}. Specifies the notation -#' of missing values. (By default: \code{NA}) +#' @param missing.values \code{NA}, \code{0} or \code{Character scalar}. +#' Specifies the notation of missing values. (By default: \code{NA}) #' #' @param missing_values Deprecated. Use \code{missing.values} instead. #' -#' @param collapse.cols \code{Logical scalar}. Determines whether to collapse identically -#' named samples to one. (Default: \code{FALSE}) +#' @param collapse.cols \code{Logical scalar}. Determines whether to collapse +#' identically named samples to one. (Default: \code{FALSE}) #' #' @param collapse_samples Deprecated. Use \code{collapse.cols} instead. #' -#' @param collapse.rows \code{Logical scalar}. Selects whether to collapse identically -#' named features to one. Since all taxonomy information is taken into account, +#' @param collapse.rows \code{Logical scalar}. Selects whether to collapse +#' identically named features to one. Since all taxonomy information is +#' taken into account, #' this concerns rownames-level (usually strain level) comparison. Often #' OTU or ASV level is just an arbitrary number series from sequencing machine #' meaning that the OTU information is not comparable between studies. With this @@ -36,9 +38,11 @@ #' @return A single \code{SummarizedExperiment} object. #' #' @details -#' This function merges multiple \code{SummarizedExperiment} objects. It combines +#' This function merges multiple \code{SummarizedExperiment} objects. It +#' combines #' \code{rowData}, \code{assays}, and \code{colData} so that the output includes -#' each unique row and column ones. The merging is done based on \code{rownames} and +#' each unique row and column ones. The merging is done based on +#' \code{rownames} and #' \code{colnames}. \code{rowTree} and \code{colTree} are preserved if linkage #' between rows/cols and the tree is found. #' @@ -50,9 +54,12 @@ #' sample. #' #' If, for example, all rows are not shared with -#' individual objects, there are missing values in \code{assays}. The notation of missing -#' can be specified with the \code{missing.values} argument. If input consists of -#' \code{TreeSummarizedExperiment} objects, also \code{rowTree}, \code{colTree}, and +#' individual objects, there are missing values in \code{assays}. +#' The notation of missing +#' can be specified with the \code{missing.values} argument. If input consists +#' of +#' \code{TreeSummarizedExperiment} objects, also \code{rowTree}, \code{colTree}, +#' and #' \code{referenceSeq} are preserved if possible. The data is preserved if #' all the rows or columns can be found from it. #' @@ -62,7 +69,8 @@ #' #' You can choose joining methods from \code{'full'}, \code{'inner'}, #' \code{'left'}, and \code{'right'}. In all the methods, all the samples are -#' included in the result object. However, with different methods, it is possible +#' included in the result object. However, with different methods, it is +#' possible #' to choose which rows are included. #' #' \itemize{ @@ -72,8 +80,10 @@ #' \item{\code{right} -- all the features of the second object} #' } #' -#' The output depends on the input. If the input contains \code{SummarizedExperiment} -#' object, then the output will be \code{SummarizedExperiment}. When all the input +#' The output depends on the input. If the input contains +#' \code{SummarizedExperiment} +#' object, then the output will be \code{SummarizedExperiment}. When all the +#' input #' objects belong to \code{TreeSummarizedExperiment}, the output will be #' \code{TreeSummarizedExperiment}. #' @@ -145,39 +155,42 @@ setMethod("mergeSEs", signature = c(x = "SimpleList"), function(x, assay.type="counts", assay_name = NULL, join = "full", missing.values = missing_values, missing_values = NA, collapse.cols = collapse_samples, collapse_samples = FALSE, - collapse.rows = collapse_features, collapse_features = TRUE, verbose = TRUE, - ... ){ + collapse.rows = collapse_features, collapse_features = TRUE, + verbose = TRUE, ... ){ ################## Input check ################## # Check the objects class <- .check_objects_and_give_class(x) - if (!is.null(assay_name) & is.null(assay.type)) { - .Deprecated(new="assay.type", old="assay_name", msg="The argument assay_name is deprecated and replace with assay.type") - assay.type <- assay_name + if (!is.null(assay_name) & is.null(assay.type)) { + .Deprecated(new="assay.type", old="assay_name", msg=paste0( + "The argument assay_name is deprecated and replace ", + "with assay.type")) + assay.type <- assay_name } else if (!is.null(assay_name) & !is.null(assay.type)) { - warning("The assay.type argument is used and assay_name is ignored") + warning("The assay.type argument is used and assay_name is ", + "ignored") } else { - # See next step + # See next step } # CHeck which assays can be found, and if any --> FALSE assay.type <- .assays_cannot_be_found(assay.type = assay.type, x) if( .is_a_bool(assay.type) && assay.type == FALSE ){ - stop("'assay.type' must specify an assay from assays. 'assay.type' ", - "cannot be found at least in one SE object.", - call. = FALSE) + stop("'assay.type' must specify an assay from assays. ", + "'assay.type' cannot be found at least in one SE object.", + call. = FALSE) } # Check join if( !(.is_a_string(join) && join %in% c("full", "inner", "left", "right") ) ){ stop("'join' must be 'full', 'inner', 'left', or 'right'.", - call. = FALSE) + call. = FALSE) } # Check if join is not available if( length(x) > 2 && join %in% c("left", "right") ){ stop("Joining method 'left' and 'right' are not available ", - "when more than two objects are being merged.", - call. = FALSE) + "when more than two objects are being merged.", + call. = FALSE) } # Is missing.values one of the allowed ones missing_values_bool <- length(missing.values) == 1L && @@ -185,23 +198,20 @@ setMethod("mergeSEs", signature = c(x = "SimpleList"), .is_a_string(missing.values) || is.na(missing.values) # If not then give error if( !missing_values_bool ){ - stop("'missing.values' must be 0, NA, or a single character value.", - call. = FALSE) + stop("'missing.values' must be 0, NA, or a single character ", + "value.", call. = FALSE) } # Check collapse.cols if( !.is_a_bool(collapse.cols) ){ - stop("'collapse.cols' must be TRUE or FALSE.", - call. = FALSE) + stop("'collapse.cols' must be TRUE or FALSE.", call. = FALSE) } # Check collapse.cols if( !.is_a_bool(collapse.rows) ){ - stop("'collapse.rows' must be TRUE or FALSE.", - call. = FALSE) + stop("'collapse.rows' must be TRUE or FALSE.", call. = FALSE) } # Check verbose if( !.is_a_bool(verbose) ){ - stop("'verbose' must be TRUE or FALSE.", - call. = FALSE) + stop("'verbose' must be TRUE or FALSE.", call. = FALSE) } ################ Input check end ################ @@ -228,7 +238,7 @@ setMethod("mergeSEs", signature = c(x = "SummarizedExperiment"), # Check y if( !(is(y, "SummarizedExperiment")) ){ stop("'y' must be a 'SummarizedExperiment' object.", - call. = FALSE) + call. = FALSE) } ################ Input check end ################ # Create a list based on TreeSEs @@ -243,12 +253,12 @@ setMethod("mergeSEs", signature = c(x = "SummarizedExperiment"), #' @rdname mergeSEs #' @export setMethod("mergeSEs", signature = c(x = "list"), - function(x, ...){ - # Convert into a list - x <- SimpleList(x) - # Call the function for list - mergeSEs(x, ...) - } + function(x, ...){ + # Convert into a list + x <- SimpleList(x) + # Call the function for list + mergeSEs(x, ...) + } ) ################################ HELP FUNCTIONS ################################ @@ -286,10 +296,11 @@ setMethod("mergeSEs", signature = c(x = "list"), args <- .get_SummarizedExperiment_data(tse = tse, assay.type = assay.type) # Get the function based on class - FUN_constructor <- switch(class, - TreeSummarizedExperiment = TreeSummarizedExperiment, - SingleCellExperiment = SingleCellExperiment, - SummarizedExperiment = SummarizedExperiment + FUN_constructor <- switch( + class, + TreeSummarizedExperiment = TreeSummarizedExperiment, + SingleCellExperiment = SingleCellExperiment, + SummarizedExperiment = SummarizedExperiment ) # Create an object tse <- do.call(FUN_constructor, args = args) @@ -305,7 +316,8 @@ setMethod("mergeSEs", signature = c(x = "list"), # Get the ith object temp <- x[[i]] # Add rownames to rowData so that full matches are found - temp <- .add_rowdata_to_rownames(temp, rownames_name = rownames_name) + temp <- .add_rowdata_to_rownames( + temp, rownames_name = rownames_name) # Modify names if specified if( !collapse.cols ){ @@ -364,8 +376,8 @@ setMethod("mergeSEs", signature = c(x = "list"), } ########################### .add_rowdata_to_rownames ########################### -# This function adds taxonomy information to rownames to enable more specific match -# between rows +# This function adds taxonomy information to rownames to enable more specific +# match between rows # Input: (Tree)SE, name of the column that is being added to rowData # Output: (Tree)SE with rownames that include all taxonomy information @@ -418,13 +430,14 @@ setMethod("mergeSEs", signature = c(x = "list"), }) rows_that_have_seqs <- unlist(rows_that_have_seqs) # Check that all the rownames are included - if( !all(rownames(tse) %in% rows_that_have_seqs) || is.null(rownames(tse)) ){ - warning("referenceSeqs do not match with the data so they are discarded.", - call. = FALSE) + if( !all(rownames(tse) %in% rows_that_have_seqs) || + is.null(rownames(tse)) ){ + warning("referenceSeqs do not match with the data so they are ", + "discarded.", call. = FALSE) return(tse) } - # Get the maximum number of DNA sets that individual TreeSE had / max number of - # sets that individual rownames set had. + # Get the maximum number of DNA sets that individual TreeSE had / max + # number of sets that individual rownames set had. max_numrow <- max(lengths(refSeqs)) # Initialize a list @@ -577,8 +590,8 @@ setMethod("mergeSEs", signature = c(x = "list"), } ############################### .get_TreeSE_args ############################### -# This function fetches TreeSummarizedExperiment specific data: rowTree, colTree, -# and referenceSeq +# This function fetches TreeSummarizedExperiment specific data: rowTree, +# colTree, and referenceSeq # Input: TreeSE and argument list # Output: An argument list @@ -679,7 +692,7 @@ setMethod("mergeSEs", signature = c(x = "list"), refSeq <- referenceSeq(tse) # Check if it is a individual set if( is(refSeq, "DNAStringSet") ){ - # Convert individual set to a list, so that all refseqs are in same + # Convert individual set to a list, so that all refseqs are in same # format refSeq <- DNAStringSetList(refSeq) } @@ -701,8 +714,9 @@ setMethod("mergeSEs", signature = c(x = "list"), ######################## .get_SummarizedExperiment_data ######################## # This function gets the desired data from one SE object and creates a list of # arguments containing the data -# Arguments of SCE and TreeSE are also fetched with this function. TreeSE-specific -# slots are collected with different function so that they are merged at the end. +# Arguments of SCE and TreeSE are also fetched with this function. +# TreeSE-specific slots are collected with different function so that they are +# merged at the end. # Input: SE # Output: A list of arguments @@ -729,7 +743,8 @@ setMethod("mergeSEs", signature = c(x = "list"), # Output: A shared class of objects .check_objects_and_give_class <- function(x){ # Allowed classes - allowed_classes <- c("TreeSummarizedExperiment", "SingleCellExperiment", "SummarizedExperiment") + allowed_classes <- c("TreeSummarizedExperiment", "SingleCellExperiment", + "SummarizedExperiment") # Get the class based on hierarchy TreeSE --> SCE --> SE # and check that objects are in correct format @@ -763,24 +778,22 @@ setMethod("mergeSEs", signature = c(x = "list"), # Check that the class matches with supported ones if( !is(x, "SummarizedExperiment") ){ stop("Input includes an object that is not 'SummarizedExperiment'.", - call. = FALSE) + call. = FALSE) } # Check that there are no object with no dimensions if( ncol(x) == 0 || nrow(x) == 0 ){ - stop("Input includes an object that has either no columns or/and no rows.", - call. = FALSE) + stop("Input includes an object that has either no columns or/and ", + "no rows.", call. = FALSE) } # Check that object has row/colnames if( is.null(rownames(x)) || is.null(colnames(x)) ){ - stop("Input includes object(s) whose rownames and/or colnames is NULL. ", - "Please add them.", - call. = FALSE) + stop("Input includes object(s) whose rownames and/or colnames is ", + "NULL. Please add them.", call. = FALSE) } # Check if the col/rownames are duplicated if( any(duplicated(rownames(x))) || any(duplicated(colnames(x))) ){ stop("Input includes object(s) whose rownames and/or colnames include ", - "duplicates. Please make them unique.", - call. = FALSE) + "duplicates. Please make them unique.", call. = FALSE) } # Get class class <- class(x) @@ -788,14 +801,16 @@ setMethod("mergeSEs", signature = c(x = "list"), } ########################### .assays_cannot_be_found ############################ -# This function checks that the assay(s) can be found from TreeSE objects of a list. +# This function checks that the assay(s) can be found from TreeSE objects of +# a list. # Input: the name of the assay and a list of TreeSE objects # Output: A list of assay.types that can be found or FALSE if any .assays_cannot_be_found <- function(assay.type, x){ # Loop through objects assays <- lapply(x, FUN = function(tse){ - # Check if the assay.types can be found. If yes, then TRUE. If not, then FALSE + # Check if the assay.types can be found. If yes, then TRUE. If not, + # then FALSE temp <- lapply(assay.type, .assay_cannot_be_found, tse = tse) # Unlist and return return( unlist(temp) ) @@ -811,22 +826,24 @@ setMethod("mergeSEs", signature = c(x = "list"), } # Give warning if assays were dropped if( length(assays) < length(assay.type) ){ - warning("The following assay(s) was not found from all the objects ", + warning("The following assay(s) was not found from all the objects ", "so it is dropped from the output: ", - paste0("'", setdiff(assay.type, assays), sep = "'", collapse = ", "), + paste0("'", setdiff(assay.type, assays), sep = "'", + collapse = ", "), call. = FALSE) } return(assays) } -############################ .assay_cannot_be_found ############################# -# This function checks that the assay can be found from TreeSE. If it can be found -# --> TRUE, if it cannot be found --> FALSE +############################ .assay_cannot_be_found ############################ +# This function checks that the assay can be found from TreeSE. If it can be +# found --> TRUE, if it cannot be found --> FALSE # Input: the name of the assay and TreSE object # Output: TRUE or FALSE .assay_cannot_be_found <- function(assay.type, tse){ - # Check if the assay.type can be found. If yes, then TRUE. If not, then FALSE + # Check if the assay.type can be found. If yes, then TRUE. If not, then + # FALSE tryCatch( { .check_assay_present(assay.type, tse) @@ -882,8 +899,8 @@ setMethod("mergeSEs", signature = c(x = "list"), # Input: Two SEs # Output: A list of arguments -.merge_SummarizedExperiments <- function(tse1, tse2, join, - assay.type, missing.values){ +.merge_SummarizedExperiments <- function( + tse1, tse2, join, assay.type, missing.values){ # Merge rowData rowdata <- .merge_rowdata(tse1, tse2, join) # Merge colData @@ -912,8 +929,8 @@ setMethod("mergeSEs", signature = c(x = "list"), # Input: Two TreeSEs, the name of the assay, joining method, value to denote # missing values, merged rowData, and merged colData # Output: Merged assay -.merge_assay <- function(tse1, tse2, assay.type, join, - missing.values, rd, cd){ +.merge_assay <- function( + tse1, tse2, assay.type, join, missing.values, rd, cd){ # Take assays assay1 <- assay(tse1, assay.type) assay2 <- assay(tse2, assay.type) @@ -970,9 +987,8 @@ setMethod("mergeSEs", signature = c(x = "list"), keep1 <- vapply(temp, function(x) !is.na(x[1]), logical(1)) # 2nd row is kept if it is not NA and the value differs from 1st row keep2 <- vapply(temp, function(x) - !is.na(x[2]) && - (is.na(x[1]) || - (!is.na(x[1]) && x[2] != x[[1]])), logical(1)) + !is.na(x[2]) && (is.na(x[1]) || + (!is.na(x[1]) && x[2] != x[[1]])), logical(1)) # Get the rows keep1 <- temp[1, keep1, drop = FALSE] keep2 <- temp[2, keep2, drop = FALSE] @@ -1111,27 +1127,27 @@ setMethod("mergeSEs", signature = c(x = "list"), classes[classes$found_both, "class.x"] != classes[ classes$found_both, "class.y"] & classes$not_na.x[ classes$found_both] & classes$not_na.y[classes$found_both] - # Add new colnames to columns. If equally named variables' classes differ - # add also class information to colnames + # Add new colnames to columns. If equally named variables' classes + # differ add also class information to colnames classes$colnames1 <- classes$rownames classes$colnames2 <- classes$rownames classes[classes$no_match, "colnames1"] <- paste0(classes[classes$no_match, "colnames1"], "_", - classes[classes$no_match, "class.x"]) + classes[classes$no_match, "class.x"]) classes[classes$no_match, "colnames2"] <- paste0(classes[classes$no_match, "colnames2"], "_", - classes[classes$no_match, "class.y"]) - # Give warning if there were missmatch between equally named variables and - # their classes + classes[classes$no_match, "class.y"]) + # Give warning if there were missmatch between equally named variables + # and their classes if( any(classes$no_match) ){ warning("Datasets include equally named variables called '", - "'but their class differ. In the output, variables are not ", - "combined and they are renamed based on their class.", - "Please check the following columns:\n", - paste0("'", paste( - classes[classes$no_match, "rownames"], collapse = "', '"), - "'"), - call. = FALSE) + "'but their class differ. In the output, variables are not ", + "combined and they are renamed based on their class.", + "Please check the following columns:\n", + paste0("'", paste( + classes[classes$no_match, "rownames"], collapse = "', '"), + "'"), + call. = FALSE) } # Add new column names to df1 colnames <- classes[classes$found1, "rownames"] diff --git a/R/mia.R b/R/mia.R index 0484d6cba..1d3ff541e 100644 --- a/R/mia.R +++ b/R/mia.R @@ -8,7 +8,8 @@ #' summarization. #' #' @name mia-package -#' @seealso \link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment} +#' @seealso +#' \link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment} "_PACKAGE" NULL @@ -61,9 +62,11 @@ NULL #' tse NULL -#' Global patterns of 16S rRNA diversity at a depth of millions of sequences per sample. +#' Global patterns of 16S rRNA diversity at a depth of millions of sequences per +#' sample. #' -#' GlobalPatterns compared the microbial communities from 25 environmental samples +#' GlobalPatterns compared the microbial communities from 25 environmental +#' samples #' and three known "mock communities" at a an average depth of 3.1 million reads #' per sample. Authors reproduced diversity patterns seen in many other #' published studies, while investigating technical bias by applying the same @@ -82,7 +85,8 @@ NULL #' \item{Final_Barcode}{final barcode (6 nucleotides)} #' \item{Barcode_truncated_plus_T}{truncated barcode with an added tyrosine #' (6 nucleotides)} -#' \item{Barcode_full_length}{complete barcode with a length of 11 nucleotides} +#' \item{Barcode_full_length}{complete barcode with a length of 11 +#' nucleotides} #' \item{SampleType}{sampling type by collection site (Soil, Feces, Skin, #' Tongue, Freshwater, Creek Freshwater, Ocean, Estuary Sediment and Mock)} #' \item{Description}{additional information (sampling location, environmental @@ -97,7 +101,8 @@ NULL #' @author Caporaso, J. G., et al. #' @references #' Caporaso, J. G., et al. (2011). -#' Global patterns of 16S rRNA diversity at a depth of millions of sequences per sample. +#' Global patterns of 16S rRNA diversity at a depth of millions of sequences per +#' sample. #' PNAS, 108, 4516-4522. \url{https://doi.org/10.1073/pnas.1000080107} NULL @@ -140,7 +145,8 @@ NULL #' Arumugam, M., et al. (2011). Enterotypes of the human gut microbiome. #' Nature, 473(7346), 174-180. \url{https://doi.org/10.1038/nature09944} #' -#' Arumugam, M., et al. (2014). Addendum: Enterotypes of the human gut microbiome. +#' Arumugam, M., et al. (2014). Addendum: Enterotypes of the human gut +#' microbiome. #' Nature 506, 516 (2014). \url{https://doi.org/10.1038/nature13075} #' #' @source \url{http://www.bork.embl.de/Docu/Arumugam_et_al_2011/downloads.html} @@ -150,7 +156,8 @@ NULL #' #' This small dataset from a human esophageal community includes 3 samples from #' 3 human adults based on biopsies analysed with 16S rDNA PCR. The 16S rRNA -#' sequence processing is provided in the mothur wiki from the link below. It was +#' sequence processing is provided in the mothur wiki from the link below. It +#' was #' converted into a TreeSummarizedExperiment from the \pkg{phyloseq} package. #' #' @format A TreeSummarizedExperiment with 58 features and 3 samples. The @@ -163,12 +170,15 @@ NULL #' @seealso \code{\link{mia-datasets}} #' @author Pei et al. \email{zhiheng.pei@@med.nyu.edu}. #' @references -#' Pei, Z., Bini, E. J., Yang, L., Zhou, M., Francois, F., & Blaser, M. J. (2004). +#' Pei, Z., Bini, E. J., Yang, L., Zhou, M., Francois, F., & Blaser, M. J. +#' (2004). #' Bacterial biota in the human distal esophagus. -#' Proceedings of the National Academy of Sciences of the United States of America, 101(12), 4250-4255. +#' Proceedings of the National Academy of Sciences of the United States of +#' America, 101(12), 4250-4255. #' \url{https://doi.org/10.1073/pnas.0306398101} #' -#' McMurdie, J. & Holmes, S. (2013) \emph{phyloseq}: An R Package for reproducible interactive analysis +#' McMurdie, J. & Holmes, S. (2013) \emph{phyloseq}: An R Package for +#' reproducible interactive analysis #' and graphics of microbiome census data. PLoS ONE. 8(4):e61217. #' \url{https://doi.org/10.1371/journal.pone.0061217} #' @@ -237,9 +247,11 @@ NULL #' @author Potbhare, R., et al. #' @references #' Potbhare, R., RaviKumar, A., Munukka, E., Lahti, L., & Ashma, R. (2022). -#' Skin microbiota diversity among genetically unrelated individuals of Indian origin. +#' Skin microbiota diversity among genetically unrelated individuals of Indian +#' origin. #' PeerJ, 10, e13075. \url{https://doi.org/10.7717/peerj.13075} -#' Supplemental information includes OTU table and taxonomy table publicly-accessible from: +#' Supplemental information includes OTU table and taxonomy table +#' publicly-accessible from: #' \url{https://www.doi.org/10.7717/peerj.13075/supp-1} #' \url{https://www.doi.org/10.7717/peerj.13075/supp-2} NULL @@ -254,9 +266,12 @@ NULL #' common for all experiments (microbiota, metabolites, biomarkers) and is #' described below. #' -#' @format A MultiAssayExperiment with 3 experiments (microbiota, metabolites and -#' biomarkers). rowData of the microbiota experiment contains taxonomic information -#' at Phylum, Class, Order, Family, Genus, Species and OTU levels. The metabolites +#' @format A MultiAssayExperiment with 3 experiments (microbiota, metabolites +#' and +#' biomarkers). rowData of the microbiota experiment contains taxonomic +#' information +#' at Phylum, Class, Order, Family, Genus, Species and OTU levels. The +#' metabolites #' and biomarkers experiments contain 38 NMR metabolites and 39 biomarkers, #' respectively. The colData includes: #' @@ -313,7 +328,8 @@ NULL #' @author A.C. Tengeler, et al. #' @references #' Tengeler, A.C., Dam, S.A., Wiesmann, M. et al. -#' Gut microbiota from persons with attention-deficit/hyperactivity disorder affects the brain in mice. +#' Gut microbiota from persons with attention-deficit/hyperactivity disorder +#' affects the brain in mice. #' Microbiome 8, 44 (2020). \url{https://doi.org/10.1186/s40168-020-00816-x} #' #' Supplemental information includes Home-cage activity, methods, results and imaging parameters and publicly-accessible from: @@ -323,14 +339,18 @@ NULL #' NULL -#' Fecal microbiota samples from 589 patients across different colorectal cancer stages +#' Fecal microbiota samples from 589 patients across different colorectal +#' cancer stages #' #' The study combined Quantitative Microbiome Profiling (QMP) with #' extensive patient phenotyping from a group of 589 colorectal cancer (CRC) #' patients, advanced adenoma (AA) patients, and healthy controls. -#' By implementing confounder control and quantitative profiling methods, the study -#' was able to reveal potential misleading associations between microbial markers -#' and colorectal cancer development that were driven by other factors like intestinal +#' By implementing confounder control and quantitative profiling methods, +#' the study +#' was able to reveal potential misleading associations between microbial +#' markers +#' and colorectal cancer development that were driven by other factors like +#' intestinal #' inflammation, rather than the cancer diagnosis itself. #' #' @format A TreeSummarizedExperiment with 676 features and 589 samples. @@ -338,9 +358,11 @@ NULL #' #' \describe{ #' \item{sampleID}{(character) Sample ID from the corresponding study} -#' \item{diagnosis}{(factor) Diagnosis type, with possible values: "ADE" (advanced adenoma), +#' \item{diagnosis}{(factor) Diagnosis type, with possible values: "ADE" +#' (advanced adenoma), #' "CRC" (colorectal cancer), "CTL" (control)} -#' \item{colonoscopy}{(factor) Colonoscopy result, with possible values: "FIT_Positive", +#' \item{colonoscopy}{(factor) Colonoscopy result, with possible values: +#' "FIT_Positive", #' "familial_risk_familial_CRC_FCC", "familial_risk_no", "abdomil_complaints"} #' } #' @@ -352,9 +374,12 @@ NULL #' @author #' Shadman Ishraq #' @references -#' Raúl Y. Tito, Sara Verbandt, Marta Aguirre Vazquez, Leo Lahti, Chloe Verspecht, Verónica Lloréns-Rico, Sara Vieira-Silva, -#' Janine Arts, Gwen Falony, Evelien Dekker, Joke Reumers, Sabine Tejpar & Jeroen Raes (2024). -#' Microbiome confounders and quantitative profiling challenge predicted microbial targets in colorectal cancer development. +#' Raúl Y. Tito, Sara Verbandt, Marta Aguirre Vazquez, Leo Lahti, Chloe +#' Verspecht, Verónica Lloréns-Rico, Sara Vieira-Silva, +#' Janine Arts, Gwen Falony, Evelien Dekker, Joke Reumers, Sabine Tejpar & +#' Jeroen Raes (2024). +#' Microbiome confounders and quantitative profiling challenge predicted +#' microbial targets in colorectal cancer development. #' Nature Medicine,30, 1339-1348. #' \url{https://doi.org/10.1038/s41591-024-02963-2} #' diff --git a/R/rarefyAssay.R b/R/rarefyAssay.R index 1c5a152a9..66e540561 100644 --- a/R/rarefyAssay.R +++ b/R/rarefyAssay.R @@ -48,7 +48,7 @@ #' #' Weiss S, Xu ZZ, Peddada S, Amir A, Bittinger K, Gonzalez A, Lozupone C, #' Zaneveld JR, Vázquez-Baeza Y, Birmingham A, Hyde ER. Normalization and -#' microbial differential abundance strategies depend upon data characteristics. +#' microbial differential abundance strategies depend upon data characteristics. #' Microbiome. 2017 Dec;5(1):1-8. #' #' @return \code{rarefyAssay} return \code{x} with subsampled data. @@ -56,9 +56,9 @@ #' @name rarefyAssay #' #' @examples -#' # When samples in TreeSE are less than specified sample, they will be removed. -#' # If after subsampling features are not present in any of the samples, -#' # they will be removed. +#' # When samples in TreeSE are less than specified sample, they will be +#' # removed. If after subsampling features are not present in any of the +#' # samples, they will be removed. #' data(GlobalPatterns) #' tse <- GlobalPatterns #' set.seed(123) diff --git a/R/runDPCoA.R b/R/runDPCoA.R index 710624e7d..c972f9695 100644 --- a/R/runDPCoA.R +++ b/R/runDPCoA.R @@ -15,26 +15,27 @@ #' @param y a \code{dist} or a symmetric \code{matrix} compatible with #' \code{ade4:dpcoa} #' -#' @param ncomponents \code{Numeric scalar}. Indicates the number of DPCoA dimensions -#' to obtain. (Default: \code{2}) +#' @param ncomponents \code{Numeric scalar}. Indicates the number of DPCoA +#' dimensions to obtain. (Default: \code{2}) #' -#' @param ntop \code{Numeric scalar}. Specifies the number of features with the highest -#' variances to use for dimensionality reduction. Alternatively \code{NULL}, -#' if all features should be used. (Default: \code{NULL}) +#' @param ntop \code{Numeric scalar}. Specifies the number of features with the +#' highest variances to use for dimensionality reduction. Alternatively +#' \code{NULL}, if all features should be used. (Default: \code{NULL}) #' -#' @param subset.row \code{Character Vector}. Specifies the subset of features to use for -#' dimensionality reduction. This can be a character vector of row names, an -#' integer vector of row indices or a logical vector. (Default: \code{NULL}) +#' @param subset.row \code{Character Vector}. Specifies the subset of features +#' to use for dimensionality reduction. This can be a character vector of row +#' names, an integer vector of row indices or a logical vector. +#' (Default: \code{NULL}) #' #' @param subset_row Deprecated. Use \code{subset.row} instead. #' -#' @param scale \code{Logical scalar}. Should the expression values be standardized? -#' (Default: \code{FALSE}) +#' @param scale \code{Logical scalar}. Should the expression values be +#' standardized? (Default: \code{FALSE}) #' #' @param name \code{Character scalar}. A name for the column of the #' \code{colData} where results will be stored. (Default: \code{"DPCoA"}) #' -#' @param altexp \code{Character scalar} or \code{integer scalar}. Specifies an +#' @param altexp \code{Character scalar} or \code{integer scalar}. Specifies an #' alternative experiment containing the input data. (Default: \code{NULL}) #' #' @param exprs_values Deprecated. Use \code{assay.type} instead. @@ -81,24 +82,24 @@ NULL #' @export #' @rdname runDPCoA setGeneric("getDPCoA", signature = c("x", "y"), - function(x, y, ...) - standardGeneric("getDPCoA")) + function(x, y, ...) standardGeneric("getDPCoA")) -.calculate_dpcoa <- function(x, y, ncomponents = 2, ntop = NULL, - subset.row = subset_row, subset_row = NULL, scale = FALSE, - transposed = FALSE, ...) +.calculate_dpcoa <- function( + x, y, ncomponents = 2, ntop = NULL, + subset.row = subset_row, subset_row = NULL, scale = FALSE, + transposed = FALSE, ...) { .require_package("ade4") # input check # Check ncomponents if( !(.is_an_integer(ncomponents) && ncomponents > 0) ){ - stop("'ncomponents' must be a single integer value specifying the number ", - "of DPCoA dimensions.", call. = FALSE) + stop("'ncomponents' must be a single integer value specifying the ", + "number of DPCoA dimensions.", call. = FALSE) } # Check ntop if( !(is.null(ntop) || (.is_an_integer(ntop) && ntop > 0)) ){ - stop("'ntop' must be NULL or a single integer value specifying the number ", - "of features with the highest variance.", call. = FALSE) + stop("'ntop' must be NULL or a single integer value specifying the ", + "number of features with the highest variance.", call. = FALSE) } y <- as.matrix(y) if(length(unique(dim(y))) != 1L){ @@ -107,15 +108,15 @@ setGeneric("getDPCoA", signature = c("x", "y"), # # Get NAs. ade4:dpcoa lead to an error if there are any NAs if( any( is.na(x) ) ){ - stop("'x' includes NAs. Please try to convert them into numeric values.", - call. = FALSE) + stop("'x' includes NAs. Please try to convert them into numeric ", + "values.", call. = FALSE) } if(!transposed) { if(is.null(ntop)){ ntop <- nrow(x) } - x <- .get_mat_for_reddim(x, subset_row = subset.row, ntop = ntop, - scale = scale) + x <- .get_mat_for_reddim( + x, subset_row = subset.row, ntop = ntop, scale = scale) } y <- y[colnames(x), colnames(x), drop = FALSE] if(nrow(y) != ncol(x)){ @@ -160,8 +161,8 @@ setMethod("getDPCoA", signature = c("TreeSummarizedExperiment","missing"), # Select only those features that are in the rowTree whichTree <- rowLinks(x)[ , "whichTree"] == tree.name if( any(!whichTree) ){ - warning("Not all rows were present in the rowTree specified by 'tree.name'.", - "'x' is subsetted.", call. = FALSE) + warning("Not all rows were present in the rowTree specified by ", + "'tree.name'. 'x' is subsetted.", call. = FALSE) # Subset the data x <- x[ whichTree, ] } @@ -196,7 +197,7 @@ addDPCoA <- function(x, ..., altexp = NULL, name = "DPCoA"){ # Check name if( !.is_a_string(name) ){ stop("'name' must be a single character value specifying a name of ", - "reducedDim where the result will be stored.", call. = FALSE) + "reducedDim where the result will be stored.", call. = FALSE) } reducedDim(x, name) <- getDPCoA(y, ...) x diff --git a/R/runNMDS.R b/R/runNMDS.R index bd5ca3c4e..1e849c9e9 100644 --- a/R/runNMDS.R +++ b/R/runNMDS.R @@ -9,15 +9,15 @@ #' @details #' For \code{addNMDS} a \linkS4class{SingleCellExperiment} #' -#' @param keep.dist \code{Logical scalar}. Indicates whether the \code{dist} object -#' calculated by \code{FUN} should be stored as \sQuote{dist} attribute of -#' the matrix returned/stored by \code{getNMDS}/ \code{addNMDS}. (Default: -#' \code{FALSE}) +#' @param keep.dist \code{Logical scalar}. Indicates whether the \code{dist} +#' object calculated by \code{FUN} should be stored as \sQuote{dist} attribute +#' of the matrix returned/stored by \code{getNMDS}/ \code{addNMDS}. (Default: +#' \code{FALSE}) #' #' @param keep_dist Deprecated. Use \code{keep.dist} instead. #' -#' @param FUN \code{Function} or \code{Character scalar}. A value with a function -#' name returning a \code{\link[stats:dist]{dist}} object +#' @param FUN \code{Function} or \code{Character scalar}. A value with a +#' function name returning a \code{\link[stats:dist]{dist}} object #' #' @param nmds.fun \code{Character scalar}. A value to choose the scaling #' implementation, either \dQuote{isoMDS} for @@ -32,8 +32,8 @@ #' @param ... additional arguments to pass to \code{FUN} and #' \code{nmds.fun}. #' -#' @param dimred \code{Character scalar} or \code{integer scalar}. Specifies the existing dimensionality -#' reduction results to use. +#' @param dimred \code{Character scalar} or \code{integer scalar}. Specifies +#' the existing dimensionality reduction results to use. #' #' @param ndimred \code{integer vector}. Specifies the dimensions to use if #' dimred is specified. @@ -99,9 +99,10 @@ setGeneric("getNMDS", function(x, ...) standardGeneric("getNMDS")) } .format_nmds <- function(nmds, nmds.fun, sample_names){ - ans <- switch(nmds.fun, - "isoMDS" = .format_nmds_isoMDS(nmds), - "monoMDS" = .format_nmds_monoMDS(nmds)) + ans <- switch( + nmds.fun, + "isoMDS" = .format_nmds_isoMDS(nmds), + "monoMDS" = .format_nmds_monoMDS(nmds)) rownames(ans) <- sample_names ans } @@ -111,15 +112,17 @@ setGeneric("getNMDS", function(x, ...) standardGeneric("getNMDS")) } .get_nmds_args_monoMDS <- function(args){ - args[c("model","threshold","maxit","weakties","stress","scaling","pc", - "smin","sfgrmin","sratmax")] + args[c( + "model","threshold","maxit","weakties","stress","scaling","pc", + "smin","sfgrmin","sratmax")] } .get_nmds_args <- function(nmds.fun, ...){ args <- list(...) - args <- switch(nmds.fun, - "isoMDS" = .get_nmds_args_isoMDS(args), - "monoMDS" = .get_nmds_args_monoMDS(args)) + args <- switch( + nmds.fun, + "isoMDS" = .get_nmds_args_isoMDS(args), + "monoMDS" = .get_nmds_args_monoMDS(args)) args <- args[!vapply(args,is.null,logical(1))] args } @@ -127,29 +130,29 @@ setGeneric("getNMDS", function(x, ...) standardGeneric("getNMDS")) #' @importFrom MASS isoMDS #' @importFrom stats cmdscale #' @importFrom vegan vegdist monoMDS -.calculate_nmds <- function(x, FUN = vegdist, - nmds.fun = nmdsFUN, - nmdsFUN = c("isoMDS","monoMDS"), - ncomponents = 2, ntop = 500, subset.row = subset_row, - subset_row = NULL, scale = FALSE, transposed = FALSE, - keep.dist = keep_dist, - keep_dist = FALSE, ...){ +.calculate_nmds <- function( + x, FUN = vegdist, + nmds.fun = nmdsFUN, + nmdsFUN = c("isoMDS","monoMDS"), + ncomponents = 2, ntop = 500, subset.row = subset_row, + subset_row = NULL, scale = FALSE, transposed = FALSE, + keep.dist = keep_dist, + keep_dist = FALSE, ...){ nmds.fun <- match.arg(nmds.fun) nmdsArgs <- .get_nmds_args(nmds.fun, ...) if(!transposed) { - x <- .get_mat_for_reddim(x, subset_row = subset.row, ntop = ntop, - scale = scale) + x <- .get_mat_for_reddim( + x, subset_row = subset.row, ntop = ntop, scale = scale) } x <- as.matrix(x) sample_names <- rownames(x) - sample_dist <- do.call(FUN, - c(list(x), - list(...))) + sample_dist <- do.call( + FUN, c(list(x), list(...))) attributes(sample_dist) <- attributes(sample_dist)[c("class","Size")] y <- cmdscale(sample_dist, k = ncomponents) - ans <- do.call(nmds.fun, - c(list(sample_dist, y = y, k = ncomponents), - nmdsArgs)) + ans <- do.call( + nmds.fun, + c(list(sample_dist, y = y, k = ncomponents), nmdsArgs)) ans <- .format_nmds(ans, nmds.fun, sample_names) if (keep.dist) { attr(ans,"dist") <- sample_dist @@ -166,7 +169,7 @@ setMethod("getNMDS", "ANY", .calculate_nmds) #' @export setMethod("getNMDS", "SummarizedExperiment", function(x, ..., assay.type = assay_name, assay_name = exprs_values, - exprs_values = "counts", FUN = vegdist) { + exprs_values = "counts", FUN = vegdist) { .calculate_nmds(assay(x, assay.type), FUN = FUN, ...) } ) @@ -177,8 +180,8 @@ setMethod("getNMDS", "SingleCellExperiment", function(x, ..., assay.type = assay_name, assay_name = exprs_values, exprs_values = "counts", dimred = NULL, ndimred = n_dimred, n_dimred = NULL, FUN = vegdist){ - mat <- .get_mat_from_sce(x, exprs_values = assay.type, - dimred = dimred, n_dimred = ndimred) + mat <- .get_mat_from_sce( + x, exprs_values = assay.type, dimred = dimred, n_dimred = ndimred) getNMDS(mat, transposed = !is.null(dimred), FUN = FUN,...) } ) diff --git a/R/splitByRanks.R b/R/splitByRanks.R index e767cd0e8..83cb000ab 100644 --- a/R/splitByRanks.R +++ b/R/splitByRanks.R @@ -1,6 +1,7 @@ #' Agglomerate a \code{SummarizedExperiment} based on several taxonomic ranks #' -#' \code{agglomerateByRanks} takes a \code{SummarizedExperiment}, splits it along the +#' \code{agglomerateByRanks} takes a \code{SummarizedExperiment}, splits it +#' along the #' taxonomic ranks, aggregates the data per rank, converts the input to a #' \code{SingleCellExperiment} objects and stores the aggregated data as #' alternative experiments. \code{unsplitByRanks} takes these alternative @@ -9,8 +10,8 @@ #' #' @inheritParams getPrevalence #' -#' @param ranks \code{Character vector}. Defines taxonomic ranks. Must all be values -#' of \code{taxonomyRanks()} function. +#' @param ranks \code{Character vector}. Defines taxonomic ranks. Must all be +#' values of \code{taxonomyRanks()} function. #' #' @param keep.dimred \code{Logical scalar}. Should the #' \code{reducedDims(x)} be transferred to the result? Please note, that this @@ -42,7 +43,8 @@ #' \code{rowLinks} are not valid anymore. #' #' @details -#' \code{agglomerateByRanks} will use by default all available taxonomic ranks, but +#' \code{agglomerateByRanks} will use by default all available taxonomic ranks, +#' but #' this can be controlled by setting \code{ranks} manually. \code{NA} values #' are removed by default, since they would not make sense, if the result #' should be used for \code{unsplitByRanks} at some point. The input data @@ -54,8 +56,9 @@ #' specify from which alternative experiment this originates from. This can also #' be used for \code{\link[SingleCellExperiment:splitAltExps]{splitAltExps}} to #' split the result along the same factor again. The input data from the base -#' objects is not returned, only the data from the \code{altExp()}. Be aware that -#' changes to \code{rowData} of the base object are not returned, whereas only +#' objects is not returned, only the data from the \code{altExp()}. Be aware +#' that +#' changes to \code{rowData} of the base object are not returned, whereas only #' the \code{colData} of the base object is kept. #' #' @name agglomerate-methods @@ -80,10 +83,8 @@ NULL #' @rdname agglomerate-methods #' @export -setGeneric("agglomerateByRanks", - signature = "x", - function(x, ...) - standardGeneric("agglomerateByRanks")) +setGeneric("agglomerateByRanks", signature = "x", + function(x, ...) standardGeneric("agglomerateByRanks")) .norm_args_for_split_by_ranks <- function(na.rm, ...){ args <- list(...) @@ -97,8 +98,7 @@ setGeneric("agglomerateByRanks", .split_by_ranks <- function(x, ranks, args){ # input check if(!.is_non_empty_character(ranks)){ - stop("'ranks' must be character vector.", - call. = FALSE) + stop("'ranks' must be character vector.", call. = FALSE) } if(nrow(x) == 0L){ stop("'x' has nrow(x) == 0L.",call. = FALSE) @@ -169,10 +169,8 @@ splitByRanks <- function(x, ...){ #' @rdname agglomerate-methods #' @export -setGeneric("unsplitByRanks", - signature = "x", - function(x, ...) - standardGeneric("unsplitByRanks")) +setGeneric("unsplitByRanks", signature = "x", + function(x, ...) standardGeneric("unsplitByRanks")) #' @importFrom SingleCellExperiment reducedDims @@ -180,8 +178,8 @@ setGeneric("unsplitByRanks", .unsplit_by <- function(x, ses, keep.dimred, ...){ class_x <- class(x) # - args <- list(assays = .unsplit_assays(ses), - colData = colData(x)) + args <- list( + assays = .unsplit_assays(ses), colData = colData(x)) if(keep.dimred){ args$reducedDims <- reducedDims(x) } @@ -218,11 +216,11 @@ setMethod("unsplitByRanks", signature = c(x = "SingleCellExperiment"), keep_reducedDims = FALSE, ...){ # input check if(!.is_a_bool(keep.dimred)){ - stop("'keep.dimred' must be TRUE or FALSE.", call. = FALSE) + stop("'keep.dimred' must be TRUE or FALSE.", call. = FALSE) } # - .unsplit_by_ranks(x, ranks = ranks, keep.dimred = keep.dimred, - ...) + .unsplit_by_ranks( + x, ranks = ranks, keep.dimred = keep.dimred, ...) } ) @@ -261,10 +259,11 @@ setMethod("unsplitByRanks", signature = c(x = "TreeSummarizedExperiment"), #' @importFrom SummarizedExperiment assayNames assay .unsplit_assays <- function(ses, MARGIN = 1L) { assay.types <- unique(unlist(lapply(ses, assayNames))) - combined <- lapply(assay.types, - .combine_assays, - ses = ses, - MARGIN = MARGIN) + combined <- lapply( + assay.types, + .combine_assays, + ses = ses, + MARGIN = MARGIN) names(combined) <- assay.types combined } @@ -290,9 +289,7 @@ setMethod("unsplitByRanks", signature = c(x = "TreeSummarizedExperiment"), } # If TreeSEs that were combined had names, add names to rowData if( !is.null(names(ses)) ){ - tl <- mapply(rep, - names(ses), - vapply(ses,nrow,integer(1))) + tl <- mapply(rep, names(ses), vapply(ses,nrow,integer(1))) tl <- unlist(unname(tl)) rd[["taxonomicLevel"]] <- factor(tl, unique(tl)) } diff --git a/R/summaries.R b/R/summaries.R index eef3d6ef7..d9a493655 100644 --- a/R/summaries.R +++ b/R/summaries.R @@ -5,16 +5,17 @@ #' #' @inheritParams getPrevalence #' -#' @param top \code{Numeric scalar}. Determines how many top taxa to return. Default is -#' to return top five taxa. (Default: \code{5}) +#' @param top \code{Numeric scalar}. Determines how many top taxa to return. +#' Default is to return top five taxa. (Default: \code{5}) #' -#' @param method \code{Character scalar}. Specify the method to determine top taxa. Either -#' sum, mean, median or prevalence. (Default: \code{"mean"}) +#' @param method \code{Character scalar}. Specify the method to determine top +#' taxa. Either sum, mean, median or prevalence. (Default: \code{"mean"}) #' #' @param ... Additional arguments passed, e.g., to getPrevalence: #' \itemize{ #' \item \code{sort}: \code{Logical scalar}. Specify -#' whether to sort taxa in alphabetical order or not. Enabled in functions +#' whether to sort taxa in alphabetical order or not. Enabled in +#' functions #' \code{getUnique}, and \code{getTop}. #' (Default: \code{FALSE}) #' \item \code{na.rm}: \code{Logical scalar}. Specify @@ -25,7 +26,8 @@ #' #' @details #' The \code{getTop} extracts the most \code{top} abundant \dQuote{FeatureID}s -#' in a \code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}} +#' in a +#' \code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}} #' object. #' #' The \code{getUnique} is a basic function to access different taxa at a @@ -89,10 +91,10 @@ NULL #' @rdname summaries #' @export setGeneric("getTop", signature = "x", - function(x, top= 5L, method = c("mean","sum","median"), - assay.type = assay_name, assay_name = "counts", - na.rm = TRUE, ...) - standardGeneric("getTop")) + function( + x, top= 5L, method = c("mean","sum","median"), + assay.type = assay_name, assay_name = "counts", na.rm = TRUE, ...) + standardGeneric("getTop")) .check_max_taxa <- function(x, top, assay.type){ if(!is.numeric(top) || as.integer(top) != top){ @@ -110,9 +112,10 @@ setGeneric("getTop", signature = "x", #' #' @export setMethod("getTop", signature = c(x = "SummarizedExperiment"), - function(x, top = 5L, method = c("mean","sum","median","prevalence"), - assay.type = assay_name, assay_name = "counts", - na.rm = TRUE, ...){ + function( + x, top = 5L, method = c("mean","sum","median","prevalence"), + assay.type = assay_name, assay_name = "counts", + na.rm = TRUE, ...){ # input check method <- match.arg(method, c("mean","sum","median","prevalence")) # check max taxa @@ -121,15 +124,16 @@ setMethod("getTop", signature = c(x = "SummarizedExperiment"), .check_assay_present(assay.type, x) # if(method == "prevalence"){ - taxs <- getPrevalence(assay(x, assay.type), sort = TRUE, - include.lowest = TRUE, ...) + taxs <- getPrevalence( + assay(x, assay.type), sort = TRUE, include.lowest = TRUE, ...) # If there are taxa with prevalence of 0, remove them taxs <- taxs[ taxs > 0 ] } else { - taxs <- switch(method, - mean = rowMeans2(assay(x, assay.type), na.rm = na.rm), - sum = rowSums2(assay(x, assay.type), na.rm = na.rm), - median = rowMedians(assay(x, assay.type)), na.rm = na.rm) + taxs <- switch( + method, + mean = rowMeans2(assay(x, assay.type), na.rm = na.rm), + sum = rowSums2(assay(x, assay.type), na.rm = na.rm), + median = rowMedians(assay(x, assay.type)), na.rm = na.rm) names(taxs) <- rownames(assay(x)) taxs <- sort(taxs,decreasing = TRUE) } @@ -142,18 +146,16 @@ setMethod("getTop", signature = c(x = "SummarizedExperiment"), #' @rdname summaries #' -#' @param rank \code{Character scalar}. Defines a taxonomic rank. Must be a value of -#' the output of \code{taxonomyRanks()}. (Default: \code{NULl}) +#' @param rank \code{Character scalar}. Defines a taxonomic rank. Must be a +#' value of the output of \code{taxonomyRanks()}. (Default: \code{NULl}) #' #' @return #' The \code{getUnique} returns a vector of unique taxa present at a #' particular rank #' #' @export -setGeneric("getUnique", - signature = c("x"), - function(x, ...) - standardGeneric("getUnique")) +setGeneric("getUnique", signature = c("x"), + function(x, ...) standardGeneric("getUnique")) #' @rdname summaries #' @export @@ -173,7 +175,8 @@ setMethod("getUnique", signature = c(x = "SummarizedExperiment"), #' overview. Must be one of the column names of \code{colData}. #' #' @param name \code{Character scalar}. A name for the column of the -#' \code{colData} where results will be stored. (Default: \code{"dominant_taxa"}) +#' \code{colData} where results will be stored. +#' (Default: \code{"dominant_taxa"}) #' #' @param ... Additional arguments passed on to \code{agglomerateByRank()} when #' \code{rank} is specified for \code{summarizeDominance}. @@ -186,13 +189,14 @@ setMethod("getUnique", signature = c(x = "SummarizedExperiment"), #' #' #' @return -#' The \code{summarizeDominance} returns an overview in a tibble. It contains dominant taxa -#' in a column named \code{*name*} and its abundance in the data set. +#' The \code{summarizeDominance} returns an overview in a tibble. It contains +#' dominant taxa in a column named \code{*name*} and its abundance in the data +#' set. #' #' @export setGeneric("summarizeDominance",signature = c("x"), - function(x, group = NULL, name = "dominant_taxa", ...) - standardGeneric("summarizeDominance")) + function(x, group = NULL, name = "dominant_taxa", ...) + standardGeneric("summarizeDominance")) #' @rdname summaries @@ -204,29 +208,35 @@ setMethod("summarizeDominance", signature = c(x = "SummarizedExperiment"), if(!is.null(group)){ if(isFALSE(any(group %in% colnames(colData(x))))){ stop("'group' variable must be in colnames(colData(x))", - call. = FALSE) + call. = FALSE) } } # name check if(!.is_non_empty_string(name)){ stop("'name' must be a non-empty single character value.", - call. = FALSE) + call. = FALSE) } # Adds dominant taxa to colData dominant_taxa <- getDominant(x, ...) data <- colData(x) - # If the length of dominant taxa is not equal to number of rows, then add rows + # If the length of dominant taxa is not equal to number of rows, then + # add rows # because there are multiple dominant taxa if(length(unlist(dominant_taxa)) > nrow(data) ){ # Get the order order <- unique(names(dominant_taxa)) - # there are multiple dominant taxa in one sample (counts are equal), length - # of dominant is greater than rows in colData. --> create a list that contain + # there are multiple dominant taxa in one sample + # (counts are equal), length + # of dominant is greater than rows in colData. --> create a list + # that contain # dominant taxa, and is as long as there are rows in colData - dominant_taxa_list <- split(dominant_taxa, rep(names(dominant_taxa), lengths(dominant_taxa)) ) + dominant_taxa_list <- split( + dominant_taxa, + rep(names(dominant_taxa), lengths(dominant_taxa)) ) # Order the data dominant_taxa_list <- dominant_taxa_list[order] - data <- data[rep(seq_len(nrow(data)), lengths(dominant_taxa_list)), ] + data <- data[ + rep(seq_len(nrow(data)), lengths(dominant_taxa_list)), ] } # Add dominant taxa to data colname <- "dominant_taxa" @@ -247,8 +257,8 @@ setMethod("summarizeDominance", signature = c(x = "SummarizedExperiment"), data <- as.data.frame(data) # # If there are multiple dominant taxa in one sample, the column is a list. - # # Convert it so that there are multiple rows for sample and each row contains - # # one dominant taxa. + # # Convert it so that there are multiple rows for sample and each row + # contains one dominant taxa. if( is.list(data[[colname]]) ){ # Get dominant taxa as a vector dominant_taxa <- unlist(data[[colname]]) @@ -294,7 +304,8 @@ setMethod("summarizeDominance", signature = c(x = "SummarizedExperiment"), #' @rdname summaries #' #' @param object A -#' \code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}} object. +#' \code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}} +#' object. #' #' @param assay.type \code{Character scalar}. Specifies the name of the #' assay used in calculation. (Default: \code{"counts"}) @@ -339,12 +350,13 @@ setMethod("summary", signature = c(object = "SummarizedExperiment"), .get_summary_col_data <- function(x, assay.type){ # should check and extract assay assay.x <- .get_assay(x, assay.type) - summary_col_data <- tibble(total_counts = sum(colSums2(assay.x)), - min_counts = min(colSums2(assay.x)), - max_counts = max(colSums2(assay.x)), - median_counts = median(colSums2(assay.x)), - mean_counts = mean(colSums2(assay.x)), - stdev_counts = sd(colSums2(assay.x))) + summary_col_data <- tibble( + total_counts = sum(colSums2(assay.x)), + min_counts = min(colSums2(assay.x)), + max_counts = max(colSums2(assay.x)), + median_counts = median(colSums2(assay.x)), + mean_counts = mean(colSums2(assay.x)), + stdev_counts = sd(colSums2(assay.x))) return(summary_col_data) } @@ -354,9 +366,10 @@ setMethod("summary", signature = c(object = "SummarizedExperiment"), # Should check and extract assay # Internal from agglomerateByRanks assay.x <- .get_assay(x, assay.type) - summary_row_data <- tibble(total = nrow(assay.x), - singletons = .get_singletons(assay.x), - per_sample_avg = mean(colSums2(assay.x != 0))) + summary_row_data <- tibble( + total = nrow(assay.x), + singletons = .get_singletons(assay.x), + per_sample_avg = mean(colSums2(assay.x != 0))) return(summary_row_data) } @@ -373,8 +386,7 @@ setMethod("summary", signature = c(object = "SummarizedExperiment"), assay.x <- .get_assay(x, assay.type) if(any(colSums2(assay.x) < 1) | any(colSums2(assay.x) < 0)){ stop("There are samples that sum to 1 or less counts. ", - "Try to supply raw counts", - call. = FALSE) + "Try to supply raw counts", call. = FALSE) } } @@ -404,9 +416,8 @@ setMethod("summary", signature = c(object = "SummarizedExperiment"), assay.x <- .get_assay(x, assay.type) if(any(is.na(assay.x))) { stop("There are samples with NAs in 'assay': ", assay.type, - " . This function is limited to sequencing data only. ", - "Where raw counts do not usually have NAs. ", - "Try to supply raw counts", - call. = FALSE) + " . This function is limited to sequencing data only. ", + "Where raw counts do not usually have NAs. ", + "Try to supply raw counts", call. = FALSE) } } diff --git a/R/taxonomy.R b/R/taxonomy.R index 4acbdd96f..43f4253d8 100644 --- a/R/taxonomy.R +++ b/R/taxonomy.R @@ -221,7 +221,7 @@ setMethod("taxonomyRankEmpty", signature = c(x = "SummarizedExperiment"), setGeneric("checkTaxonomy", signature = "x", function(x, ...) - standardGeneric("checkTaxonomy")) + standardGeneric("checkTaxonomy")) #' @rdname taxonomy-methods #' @aliases checkTaxonomy @@ -246,11 +246,12 @@ setTaxonomyRanks <- function(ranks) { ranks <- tolower(ranks) # Check if rank is a character vector with length >= 1 if (!is.character(ranks) || length(ranks) < 1 - || any(ranks == "" | ranks == " " | ranks == "\t" | ranks == "-" | ranks == "_") + || any(ranks == "" | ranks == " " | ranks == "\t" | ranks == "-" | + ranks == "_") || any(grepl("\\s{2,}", ranks))) { stop("Input 'rank' should be a character vector with non-empty strings, - no spaces, tabs, hyphens, underscores, and non-continuous spaces." - , call. = FALSE) + no spaces, tabs, hyphens, underscores, and non-continuous spaces.", + call. = FALSE) } #Replace default value of mia::TAXONOMY_RANKS assignInMyNamespace("TAXONOMY_RANKS", ranks) @@ -313,13 +314,14 @@ setGeneric("getTaxonomyLabels", #' @aliases checkTaxonomy #' @export setMethod("getTaxonomyLabels", signature = c(x = "SummarizedExperiment"), - function(x, empty.fields = c(NA, "", " ", "\t", "-", "_"), with.rank = with_rank, - with_rank = FALSE, make.unique = make_unique, make_unique = TRUE, + function(x, empty.fields = c(NA, "", " ", "\t", "-", "_"), + with.rank = with_rank, + with_rank = FALSE, make.unique = make_unique, make_unique = TRUE, resolve.loops = resolve_loops, resolve_loops = FALSE, ...){ # input check if(nrow(x) == 0L){ stop("No data available in `x` ('x' has nrow(x) == 0L.)", - call. = FALSE) + call. = FALSE) } if(ncol(rowData(x)) == 0L){ stop("rowData needs to be populated.", call. = FALSE) @@ -327,7 +329,7 @@ setMethod("getTaxonomyLabels", signature = c(x = "SummarizedExperiment"), .check_for_taxonomic_data_order(x) if(!is.character(empty.fields) || length(empty.fields) == 0L){ stop("'empty.fields' must be a character vector with one or ", - "more values.", call. = FALSE) + "more values.", call. = FALSE) } if(!.is_a_bool(with.rank)){ stop("'with.rank' must be TRUE or FALSE.", call. = FALSE) @@ -458,7 +460,7 @@ setMethod("getTaxonomyLabels", signature = c(x = "SummarizedExperiment"), #' #' Please note that a hierarchy tree is not an actual phylogenetic tree. #' A phylogenetic tree represents evolutionary relationships among features. -#' On the other hand, a hierarchy tree organizes species into a hierarchical +#' On the other hand, a hierarchy tree organizes species into a hierarchical #' structure based on their taxonomic ranks. #' #' @return @@ -655,7 +657,7 @@ setMethod("mapTaxonomy", signature = c(x = "SummarizedExperiment"), } if(!is.null(from) && !is.null(to)){ if(from == to){ - stop("'from' and 'to' must be different values.", call. = FALSE) + stop("'from' and 'to' must be different values.", call. = FALSE) } } if(!.is_a_bool(use.grepl)){ diff --git a/vignettes/mia.Rmd b/vignettes/mia.Rmd index da7bfd655..790bcbf82 100644 --- a/vignettes/mia.Rmd +++ b/vignettes/mia.Rmd @@ -18,10 +18,11 @@ bibliography: references.bib --- ```{r, echo=FALSE} -knitr::opts_chunk$set(cache = FALSE, - fig.width = 9, - message = FALSE, - warning = FALSE) +knitr::opts_chunk$set( + cache = FALSE, + fig.width = 9, + message = FALSE, + warning = FALSE) ``` `mia` implements tools for microbiome analysis based on the @@ -143,14 +144,15 @@ settings different number of rows will be returned. ```{r} x1 <- agglomerateByRank(tse, rank = "Species", empty.rm = TRUE) -altExp(tse,"species") <- agglomerateByRank(tse, rank = "Species", empty.rm = FALSE) +altExp(tse,"species") <- agglomerateByRank( + tse, rank = "Species", empty.rm = FALSE) dim(x1) dim(altExp(tse,"species")) ``` -For convenience the function `agglomerateByRanks` is available, which agglomerates -data on all `ranks` selected. By default all available ranks will be used. -The output is compatible to be stored as alternative experiments. +For convenience the function `agglomerateByRanks` is available, which +agglomerates data on all `ranks` selected. By default all available ranks will +be used. The output is compatible to be stored as alternative experiments. ```{r} tse <- agglomerateByRanks(tse) @@ -170,9 +172,10 @@ taxa_res <- resolveLoop(as.data.frame(taxa)) taxa_tree <- toTree(data = taxa_res) taxa_tree$tip.label <- getTaxonomyLabels(altExp(tse,"Species")) rowNodeLab <- getTaxonomyLabels(altExp(tse,"Species"), make.unique = FALSE) -altExp(tse,"Species") <- changeTree(altExp(tse,"Species"), - rowTree = taxa_tree, - rowNodeLab = rowNodeLab) +altExp(tse,"Species") <- changeTree( + altExp(tse,"Species"), + rowTree = taxa_tree, + rowNodeLab = rowNodeLab) ``` ## Transformation of assay data @@ -194,19 +197,24 @@ Sub-sampling to equal number of counts per sample. Also known as rarefying. ```{r} data(GlobalPatterns, package = "mia") -tse.subsampled <- rarefyAssay(GlobalPatterns, - sample = 60000, - name = "subsampled", - replace = TRUE, - seed = 1938) +tse.subsampled <- rarefyAssay( + GlobalPatterns, + sample = 60000, + name = "subsampled", + replace = TRUE, + seed = 1938) tse.subsampled ``` -Alternatively, one can save both original TreeSE and subsampled TreeSE within a MultiAssayExperiment object. + +Alternatively, one can save both original TreeSE and subsampled TreeSE within a +MultiAssayExperiment object. + ```{r} library(MultiAssayExperiment) -mae <- MultiAssayExperiment(c("originalTreeSE" = GlobalPatterns, - "subsampledTreeSE" = tse.subsampled)) +mae <- MultiAssayExperiment( + c("originalTreeSE" = GlobalPatterns, + "subsampledTreeSE" = tse.subsampled)) mae ``` @@ -235,18 +243,19 @@ Beta diversity indices are used to describe inter-sample connections. Technically they are calculated as `dist` object and reduced dimensions can be extracted using `cmdscale`. This is wrapped up in the `runMDS` function of the `scater` package, but can be easily used to calculated beta diversity -indices using the established functions from the `vegan` package or any other +indices using the established functions from the `vegan` package or any other package using comparable inputs. ```{r} library(scater) -altExp(tse,"Genus") <- runMDS(altExp(tse,"Genus"), - FUN = vegan::vegdist, - method = "bray", - name = "BrayCurtis", - ncomponents = 5, - assay.type = "counts", - keep_dist = TRUE) +altExp(tse,"Genus") <- runMDS( + altExp(tse,"Genus"), + FUN = getDissimilarity, + method = "bray", + name = "BrayCurtis", + ncomponents = 5, + assay.type = "counts", + keep_dist = TRUE) ``` JSD and UniFrac are implemented in `mia` as well. `getJSD` can be used @@ -306,10 +315,11 @@ assay(tse[,'CC1'], "counts") |> head() ```{r} data(esophagus, package = "mia") -top_taxa <- getTop(esophagus, - method = "mean", - top = 5, - assay.type = "counts") +top_taxa <- getTop( + esophagus, + method = "mean", + top = 5, + assay.type = "counts") top_taxa ``` @@ -319,10 +329,11 @@ To generate tidy data as used and required in most of the tidyverse, `meltAssay` can be used. A `data.frame` in the long format will be returned. ```{r} -molten_data <- meltAssay(tse, - assay.type = "counts", - add.row = TRUE, - add.col = TRUE +molten_data <- meltAssay( + tse, + assay.type = "counts", + add.row = TRUE, + add.col = TRUE ) molten_data ``` From 9930f57c1283fd2bd2dc1b0ee89fbe24fa936477 Mon Sep 17 00:00:00 2001 From: TuomasBorman Date: Fri, 6 Dec 2024 17:27:55 +0200 Subject: [PATCH 3/9] Move all generics to own file --- NAMESPACE | 13 +- R/AllGenerics.R | 362 +++++++++++++++++++++++++++++++ R/addAlpha.R | 20 -- R/addDissimilarity.R | 12 - R/addDivergence.R | 15 -- R/addLDA.R | 10 - R/addNMF.R | 10 - R/agglomerate.R | 11 - R/calculateDMM.R | 36 --- R/cluster.R | 10 - R/convertFromBIOM.R | 10 +- R/convertToPhyloseq.R | 7 +- R/decontam.R | 12 - R/estimateDominance.R | 14 -- R/getCrossAssociation.R | 5 - R/getDominant.R | 14 -- R/getPERMANOVA.R | 8 - R/getPrevalence.R | 43 +--- R/mediate.R | 10 - R/meltAssay.R | 5 - R/mergeSEs.R | 10 - R/rarefyAssay.R | 8 - R/runCCA.R | 17 -- R/runDPCoA.R | 5 - R/runNMDS.R | 6 - R/splitByRanks.R | 11 - R/splitOn.R | 14 -- R/subset.R | 2 - R/summaries.R | 30 +-- R/taxonomy.R | 43 ---- R/transformCounts.R | 6 - man/GlobalPatterns.Rd | 12 +- man/HintikkaXOData.Rd | 9 +- man/Tengeler2020.Rd | 3 +- man/Tito2024QMP.Rd | 27 ++- man/addAlpha.Rd | 30 +-- man/addCluster.Rd | 8 +- man/addDivergence.Rd | 8 +- man/addLDA.Rd | 6 +- man/addNMF.Rd | 6 +- man/agglomerate-methods.Rd | 38 ++-- man/agglomerateByPrevalence.Rd | 2 +- man/calculateDMN.Rd | 56 ++--- man/convertFromPhyloseq.Rd | 11 +- man/enterotype.Rd | 3 +- man/esophagus.Rd | 12 +- man/getCrossAssociation.Rd | 2 +- man/getDissimilarity.Rd | 10 +- man/getDominant.Rd | 8 +- man/getMediation.Rd | 33 +-- man/getPERMANOVA.Rd | 2 +- man/getPrevalence.Rd | 52 ++--- man/hierarchy-tree.Rd | 12 +- man/importBIOM.Rd | 20 +- man/importHUMAnN.Rd | 5 +- man/importMetaPhlAn.Rd | 11 +- man/importMothur.Rd | 7 +- man/importQIIME2.Rd | 11 +- man/importTaxpasta.Rd | 4 +- man/isContaminant.Rd | 42 ++-- man/meltSE.Rd | 2 +- man/mergeSEs.Rd | 46 ++-- man/peerj13075.Rd | 6 +- man/rarefyAssay.Rd | 8 +- man/runCCA.Rd | 6 +- man/runDPCoA.Rd | 27 +-- man/runNMDS.Rd | 41 ++-- man/splitOn.Rd | 8 +- man/{summaries.Rd => summary.Rd} | 60 ++--- man/taxonomy-methods.Rd | 30 +-- man/transformAssay.Rd | 2 +- pkgdown/_pkgdown.yml | 2 +- 72 files changed, 764 insertions(+), 703 deletions(-) create mode 100644 R/AllGenerics.R rename man/{summaries.Rd => summary.Rd} (88%) diff --git a/NAMESPACE b/NAMESPACE index 771585489..cd2d427f5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,12 +4,14 @@ export("relabundance<-") export(IdTaxaToDataFrame) export(ZTransform) export(addAlpha) +export(addCCA) export(addCluster) export(addContaminantQC) export(addDPCoA) export(addDissimilarity) export(addDivergence) export(addDominant) +export(addHierarchyTree) export(addLDA) export(addMediation) export(addNMDS) @@ -17,6 +19,7 @@ export(addNMF) export(addNotContaminantQC) export(addPerSampleDominantFeatures) export(addPerSampleDominantTaxa) +export(addRDA) export(addTaxonomyTree) export(agglomerateByPrevalence) export(agglomerateByRank) @@ -32,6 +35,7 @@ export(calculateNMDS) export(calculateOverlap) export(calculateRDA) export(calculateUnifrac) +export(checkTaxonomy) export(cluster) export(convertFromBIOM) export(convertFromDADA2) @@ -48,6 +52,7 @@ export(estimateFaith) export(estimateRichness) export(full_join) export(getBestDMNFit) +export(getCCA) export(getCrossAssociation) export(getDMN) export(getDPCoA) @@ -56,18 +61,20 @@ export(getDivergence) export(getDominant) export(getExperimentCrossAssociation) export(getExperimentCrossCorrelation) +export(getHierarchyTree) export(getLDA) export(getMediation) export(getNMDS) export(getNMF) export(getPrevalence) -export(getPrevalent) export(getPrevalentAbundance) export(getPrevalentFeatures) export(getPrevalentTaxa) +export(getRDA) export(getRare) export(getRareFeatures) export(getRareTaxa) +export(getTaxonomyLabels) export(getTaxonomyRanks) export(getTop) export(getTopFeatures) @@ -97,6 +104,7 @@ export(makeTreeSEFromPhyloseq) export(makeTreeSummarizedExperimentFromBiom) export(makeTreeSummarizedExperimentFromDADA2) export(makeTreeSummarizedExperimentFromPhyloseq) +export(mapTaxonomy) export(meltAssay) export(meltSE) export(mergeCols) @@ -137,6 +145,9 @@ export(subsetFeatures) export(subsetSamples) export(subsetTaxa) export(summarizeDominance) +export(summary) +export(taxonomyRankEmpty) +export(taxonomyRanks) export(taxonomyTree) export(testExperimentCrossAssociation) export(testExperimentCrossCorrelation) diff --git a/R/AllGenerics.R b/R/AllGenerics.R new file mode 100644 index 000000000..43bb89ac0 --- /dev/null +++ b/R/AllGenerics.R @@ -0,0 +1,362 @@ +# This file contains all the generics + +#' @rdname addAlpha +#' @export +setGeneric( + "addAlpha", signature = c("x"), + function( + x, assay.type = "counts", + index = c( + "coverage_diversity", "fisher_diversity", "faith_diversity", + "gini_simpson_diversity", "inverse_simpson_diversity", + "log_modulo_skewness_diversity", "shannon_diversity", + "absolute_dominance", "dbp_dominance", + "core_abundance_dominance", "gini_dominance", + "dmn_dominance", "relative_dominance", + "simpson_lambda_dominance", "camargo_evenness", + "pielou_evenness", "simpson_evenness", + "evar_evenness", "bulla_evenness", "ace_richness", + "chao1_richness", "hill_richness", "observed_richness"), + name = index, niter = NULL, ...) + standardGeneric("addAlpha")) + +#' @rdname getDissimilarity +#' @export +setGeneric( + "addDissimilarity", signature = c("x"), function(x, method, ...) + standardGeneric("addDissimilarity")) + +#' @rdname getDissimilarity +#' @export +setGeneric( + "getDissimilarity", signature = c("x"), function(x, method, ...) + standardGeneric("getDissimilarity")) + + +#' @rdname addDivergence +#' @export +setGeneric( + "addDivergence",signature = c("x"), + function(x, name = "divergence", ...) + standardGeneric("addDivergence")) + +#' @rdname addDivergence +#' @export +setGeneric("getDivergence", signature = c("x"), + function( + x, assay.type = assay_name, assay_name = "counts", reference = "median", + method = "bray", ...) + standardGeneric("getDivergence")) + +#' @rdname addLDA +#' @export +setGeneric( + "getLDA", signature = c("x"), function(x, ...) standardGeneric("getLDA")) + +#' @rdname addLDA +#' @export +setGeneric( + "addLDA", signature = c("x"), function(x, ...) standardGeneric("addLDA")) + +#' @rdname addNMF +#' @export +setGeneric( + "getNMF", signature = c("x"), function(x, ...) standardGeneric("getNMF")) + +#' @rdname addNMF +#' @export +setGeneric( + "addNMF", signature = c("x"), function(x, ...) standardGeneric("addNMF")) + +#' @rdname agglomerate-methods +#' @export +setGeneric("agglomerateByRank", signature = "x", function(x, ...) + standardGeneric("agglomerateByRank")) + +#' @rdname agglomerate-methods +#' @aliases agglomerateByVariable +#' @export +setGeneric("agglomerateByVariable", signature = "x", function(x, ...) + standardGeneric("agglomerateByVariable")) + +#' @rdname calculateDMN +#' @export +setGeneric("calculateDMN", signature = c("x"), function(x, ...) + standardGeneric("calculateDMN")) + +#' @rdname addCluster +#' @export +setGeneric("addCluster", signature = c("x"), + function( + x, BLUSPARAM, assay.type = assay_name, + assay_name = "counts", by = MARGIN, MARGIN = "rows", full = FALSE, + name = "clusters", clust.col = "clusters", ...) + standardGeneric("addCluster")) + +#' @rdname importBIOM +#' @export +setGeneric("convertToBIOM", signature = c("x"), + function( + x, assay.type = "counts", ...) + standardGeneric("convertToBIOM")) + +#' @rdname convertFromPhyloseq +#' @export +setGeneric("convertToPhyloseq", signature = c("x"), function(x, ...) + standardGeneric("convertToPhyloseq")) + +#' @rdname isContaminant +#' @export +setGeneric("addContaminantQC", signature = c("x"), + function(x, name = "isContaminant", ...) + standardGeneric("addContaminantQC")) + +#' @rdname isContaminant +#' @export +setGeneric("addNotContaminantQC", signature = c("x"), + function(x, name = "isNotContaminant", ...) + standardGeneric("addNotContaminantQC")) + +#' @rdname getCrossAssociation +#' @export +setGeneric("getCrossAssociation", signature = c("x"), function(x, ...) + standardGeneric("getCrossAssociation")) + +#' @rdname getDominant +#' @export +setGeneric("getDominant",signature = c("x"), + function(x, assay.type = assay_name, assay_name = "counts", + group = rank, rank = NULL, other.name = "Other", n = NULL, + complete = TRUE, ...) + standardGeneric("getDominant")) + +#' @rdname getDominant +#' @export +setGeneric("addDominant", signature = c("x"), + function(x, name = "dominant_taxa", other.name = "Other", n = NULL, ...) + standardGeneric("addDominant")) + +#' @rdname getPERMANOVA +setGeneric("getPERMANOVA", signature = c("x"), function(x, ...) + standardGeneric("getPERMANOVA")) + +#' @rdname getPERMANOVA +setGeneric("addPERMANOVA", signature = c("x"), function(x, ...) + standardGeneric("addPERMANOVA")) + +#' @rdname getPrevalence +setGeneric("getPrevalence", signature = "x", function(x, ...) + standardGeneric("getPrevalence")) + +#' @rdname getPrevalence +setGeneric("getPrevalent", signature = "x", function(x, ...) + standardGeneric("getPrevalent")) + +#' @rdname getPrevalence +#' @export +setGeneric("getRare", signature = "x", function(x, ...) + standardGeneric("getRare")) + +#' @rdname getPrevalence +#' @export +setGeneric("subsetByPrevalent", signature = "x", function(x, ...) + standardGeneric("subsetByPrevalent")) + +#' @rdname getPrevalence +#' @export +setGeneric("subsetByRare", signature = "x", function(x, ...) + standardGeneric("subsetByRare")) + +#' @rdname getPrevalence +#' @export +setGeneric("getPrevalentAbundance", signature = "x", + function(x, assay.type = assay_name, assay_name = "relabundance", ...) + standardGeneric("getPrevalentAbundance")) + +#'@rdname agglomerateByPrevalence +#' @export +setGeneric("agglomerateByPrevalence", signature = "x", function(x, ...) + standardGeneric("agglomerateByPrevalence")) + +#' @rdname getMediation +#' @export +setGeneric("addMediation", signature = c("x"), function(x, ...) + standardGeneric("addMediation")) + +#' @rdname getMediation +#' @export +setGeneric("getMediation", signature = c("x"), function(x, ...) + standardGeneric("getMediation")) + +#' @rdname meltSE +#' @export +setGeneric("meltSE", signature = "x", function(x, ...) + standardGeneric("meltSE")) + +#' @rdname mergeSEs +#' @export +setGeneric("mergeSEs", signature = c("x"), function(x, ... ) + standardGeneric("mergeSEs")) + +#' @rdname rarefyAssay +#' @export +setGeneric("rarefyAssay", signature = c("x"), + function( + x, assay.type = assay_name, assay_name = "counts", + sample = min_size, min_size = min(colSums2(assay(x))), + replace = TRUE, name = "subsampled", verbose = TRUE, ...) + standardGeneric("rarefyAssay")) + +#' @rdname runCCA +#' @export +setGeneric("getCCA", signature = c("x"), function(x, ...) + standardGeneric("getCCA")) + +#' @rdname runCCA +#' @export +setGeneric("addCCA", signature = c("x"), function(x, ...) + standardGeneric("addCCA")) + +#' @rdname runCCA +#' @export +setGeneric("getRDA", signature = c("x"), function(x, ...) + standardGeneric("getRDA")) + +#' @rdname runCCA +#' @export +setGeneric("addRDA", signature = c("x"), function(x, ...) + standardGeneric("addRDA")) + +#' @export +#' @rdname runDPCoA +setGeneric("getDPCoA", signature = c("x", "y"), function(x, y, ...) + standardGeneric("getDPCoA")) + +#' @rdname runNMDS +#' @export +setGeneric("getNMDS", function(x, ...) standardGeneric("getNMDS")) + +#' @rdname agglomerate-methods +#' @export +setGeneric("agglomerateByRanks", signature = "x", function(x, ...) + standardGeneric("agglomerateByRanks")) + +#' @rdname agglomerate-methods +#' @export +setGeneric("unsplitByRanks", signature = "x", function(x, ...) + standardGeneric("unsplitByRanks")) + +#' @rdname splitOn +#' @export +setGeneric("splitOn", signature = "x", function(x, ...) + standardGeneric("splitOn")) + +#' @rdname splitOn +#' @export +setGeneric("unsplitOn", signature = c("x"), function(x, ...) + standardGeneric("unsplitOn")) + +#' @rdname summary +#' @export +setGeneric("summarizeDominance",signature = c("x"), + function(x, group = NULL, name = "dominant_taxa", ...) + standardGeneric("summarizeDominance")) + +#' @rdname summary +#' @export +setGeneric("getUnique", signature = c("x"), function(x, ...) + standardGeneric("getUnique")) + +#' @rdname summary +#' @export +setGeneric("getTop", signature = "x", + function( + x, top= 5L, method = c("mean","sum","median"), + assay.type = assay_name, assay_name = "counts", na.rm = TRUE, ...) + standardGeneric("getTop")) + +#' @rdname taxonomy-methods +#' @export +setGeneric("taxonomyRanks", signature = c("x"), function(x) + standardGeneric("taxonomyRanks")) + +#' @rdname taxonomy-methods +#' @export +setGeneric("taxonomyRankEmpty", signature = "x", + function( + x, rank = taxonomyRanks(x)[1L], + empty.fields = c(NA, "", " ", "\t", "-", "_")) + standardGeneric("taxonomyRankEmpty")) + +#' @rdname taxonomy-methods +#' @export +setGeneric("checkTaxonomy", signature = "x", function(x, ...) + standardGeneric("checkTaxonomy")) + +#' @rdname taxonomy-methods +#' @export +setGeneric("getTaxonomyLabels", signature = "x", function(x, ...) + standardGeneric("getTaxonomyLabels")) + +#' @rdname taxonomy-methods +#' @export +setGeneric("mapTaxonomy", signature = "x", function(x, ...) + standardGeneric("mapTaxonomy")) + +#' @rdname hierarchy-tree +#' @export +setGeneric("getHierarchyTree", signature = "x", function(x, ...) + standardGeneric("getHierarchyTree")) + +#' @rdname hierarchy-tree +#' @export +setGeneric("addHierarchyTree", signature = "x", function(x, ...) + standardGeneric("addHierarchyTree")) + +#' @rdname transformAssay +#' @export +setGeneric("transformAssay", signature = c("x"), function(x, ...) + standardGeneric("transformAssay")) + +#' @rdname calculateDMN +#' @export +setGeneric("getDMN", signature = "x", function(x, name = "DMN", ...) + standardGeneric("getDMN")) + +#' @rdname calculateDMN +#' @export +setGeneric("bestDMNFit", signature = "x", + function(x, name = "DMN", type = c("laplace","AIC","BIC"), ...) + standardGeneric("bestDMNFit")) + +#' @rdname calculateDMN +#' @export +setGeneric("calculateDMNgroup", signature = c("x"), function(x, ...) + standardGeneric("calculateDMNgroup")) + +#' @rdname calculateDMN +#' @export +setGeneric("performDMNgroupCV", signature = c("x"), function(x, ...) + standardGeneric("performDMNgroupCV")) + +#' @rdname calculateDMN +#' @export +setGeneric("getBestDMNFit", signature = "x", + function(x, name = "DMN", type = c("laplace","AIC","BIC"), ...) + standardGeneric("getBestDMNFit")) + +NULL +setGeneric( + ".estimate_dominance", signature = c("x"), + function(x, ...) standardGeneric(".estimate_dominance")) + +NULL +setGeneric( + ".estimate_dominance",signature = c("x"), + function( + x, assay.type = assay_name, assay_name = "counts", + index = c( + "absolute", "dbp", "core_abundance", "gini", "dmn", "relative", + "simpson_lambda"), + ntaxa = 1, aggregate = TRUE, name = index, BPPARAM = SerialParam(), ...) + standardGeneric(".estimate_dominance")) diff --git a/R/addAlpha.R b/R/addAlpha.R index 56c549c09..6e84fa05e 100644 --- a/R/addAlpha.R +++ b/R/addAlpha.R @@ -435,26 +435,6 @@ #' @export NULL -#' @rdname addAlpha -#' @export -setGeneric( - "addAlpha", signature = c("x"), - function( - x, assay.type = "counts", - index = c( - "coverage_diversity", "fisher_diversity", "faith_diversity", - "gini_simpson_diversity", "inverse_simpson_diversity", - "log_modulo_skewness_diversity", "shannon_diversity", - "absolute_dominance", "dbp_dominance", - "core_abundance_dominance", "gini_dominance", - "dmn_dominance", "relative_dominance", - "simpson_lambda_dominance", "camargo_evenness", - "pielou_evenness", "simpson_evenness", - "evar_evenness", "bulla_evenness", "ace_richness", - "chao1_richness", "hill_richness", "observed_richness"), - name = index, niter = NULL, ...) - standardGeneric("addAlpha")) - #' @rdname addAlpha #' @export setMethod("addAlpha", signature = c(x = "SummarizedExperiment"), diff --git a/R/addDissimilarity.R b/R/addDissimilarity.R index 1d91124a8..725d57f93 100644 --- a/R/addDissimilarity.R +++ b/R/addDissimilarity.R @@ -156,12 +156,6 @@ #' NULL -#' @rdname getDissimilarity -#' @export -setGeneric( - "addDissimilarity", signature = c("x"), function(x, method, ...) - standardGeneric("addDissimilarity")) - #' @rdname getDissimilarity #' @export setMethod( @@ -175,12 +169,6 @@ setMethod( } ) -#' @rdname getDissimilarity -#' @export -setGeneric( - "getDissimilarity", signature = c("x"), function(x, method, ...) - standardGeneric("getDissimilarity")) - #' @rdname getDissimilarity #' @export setMethod( diff --git a/R/addDivergence.R b/R/addDivergence.R index 3e9f3a16d..c0a2e09b9 100644 --- a/R/addDivergence.R +++ b/R/addDivergence.R @@ -69,13 +69,6 @@ #' NULL -#' @rdname addDivergence -#' @export -setGeneric( - "addDivergence",signature = c("x"), - function(x, name = "divergence", ...) - standardGeneric("addDivergence")) - #' @rdname addDivergence #' @export setMethod("addDivergence", signature = c(x="SummarizedExperiment"), @@ -94,14 +87,6 @@ setMethod("addDivergence", signature = c(x="SummarizedExperiment"), } ) -#' @rdname addDivergence -#' @export -setGeneric("getDivergence", signature = c("x"), - function( - x, assay.type = assay_name, assay_name = "counts", reference = "median", - method = "bray", ...) - standardGeneric("getDivergence")) - #' @rdname addDivergence #' @export setMethod("getDivergence", signature = c(x="SummarizedExperiment"), diff --git a/R/addLDA.R b/R/addLDA.R index 0111d3f2f..e00c8d46e 100644 --- a/R/addLDA.R +++ b/R/addLDA.R @@ -64,16 +64,6 @@ #' plot(tab[["k"]], tab[["perplexity"]], xlab = "k", ylab = "perplexity") NULL -#' @rdname addLDA -#' @export -setGeneric( - "getLDA", signature = c("x"), function(x, ...) standardGeneric("getLDA")) - -#' @rdname addLDA -#' @export -setGeneric( - "addLDA", signature = c("x"), function(x, ...) standardGeneric("addLDA")) - #' @export #' @rdname addLDA setMethod("getLDA", "SummarizedExperiment", diff --git a/R/addNMF.R b/R/addNMF.R index 1bf9bb29e..3f0c82ea8 100644 --- a/R/addNMF.R +++ b/R/addNMF.R @@ -80,16 +80,6 @@ #' NULL -#' @rdname addNMF -#' @export -setGeneric( - "getNMF", signature = c("x"), function(x, ...) standardGeneric("getNMF")) - -#' @rdname addNMF -#' @export -setGeneric( - "addNMF", signature = c("x"), function(x, ...) standardGeneric("addNMF")) - #' @export #' @rdname addNMF setMethod("getNMF", "SummarizedExperiment", diff --git a/R/agglomerate.R b/R/agglomerate.R index 78f183af7..442968e2f 100644 --- a/R/agglomerate.R +++ b/R/agglomerate.R @@ -224,11 +224,6 @@ #' NULL -#' @rdname agglomerate-methods -#' @export -setGeneric("agglomerateByRank", signature = "x", function(x, ...) - standardGeneric("agglomerateByRank")) - #' @rdname agglomerate-methods #' @export setMethod( @@ -360,12 +355,6 @@ setMethod("agglomerateByRank", signature = c(x = "SummarizedExperiment"), } ) -#' @rdname agglomerate-methods -#' @aliases agglomerateByVariable -#' @export -setGeneric("agglomerateByVariable", signature = "x", function(x, ...) - standardGeneric("agglomerateByVariable")) - #' @rdname agglomerate-methods #' @aliases agglomerateByVariable #' @export diff --git a/R/calculateDMM.R b/R/calculateDMM.R index e08f9009c..4fe554218 100644 --- a/R/calculateDMM.R +++ b/R/calculateDMM.R @@ -97,12 +97,6 @@ #' bestModel@mixture$Weight NULL -#' @rdname calculateDMN -#' @export -setGeneric("calculateDMN", signature = c("x"), - function(x, ...) - standardGeneric("calculateDMN")) - #' @importFrom DirichletMultinomial dmn #' @importFrom stats runif .calculate_DMN <- function(x, k = 1, BPPARAM = SerialParam(), @@ -189,12 +183,6 @@ runDMN <- function(x, name = "DMN", ...){ fit_FUN } -#' @rdname calculateDMN -#' @export -setGeneric("getDMN", signature = "x", - function(x, name = "DMN", ...) - standardGeneric("getDMN")) - #' @rdname calculateDMN #' @importFrom DirichletMultinomial laplace AIC BIC #' @export @@ -214,12 +202,6 @@ setMethod("getDMN", signature = c(x = "SummarizedExperiment"), which.min(fit) } -#' @rdname calculateDMN -#' @export -setGeneric("bestDMNFit", signature = "x", - function(x, name = "DMN", type = c("laplace","AIC","BIC"), ...) - standardGeneric("bestDMNFit")) - #' @rdname calculateDMN #' @importFrom DirichletMultinomial laplace AIC BIC #' @export @@ -237,12 +219,6 @@ setMethod("bestDMNFit", signature = c(x = "SummarizedExperiment"), } ) -#' @rdname calculateDMN -#' @export -setGeneric("getBestDMNFit", signature = "x", - function(x, name = "DMN", type = c("laplace","AIC","BIC"), ...) - standardGeneric("getBestDMNFit")) - #' @rdname calculateDMN #' @importFrom DirichletMultinomial laplace AIC BIC #' @export @@ -261,12 +237,6 @@ setMethod("getBestDMNFit", signature = c(x = "SummarizedExperiment"), ################################################################################ # DMN group -#' @rdname calculateDMN -#' @export -setGeneric("calculateDMNgroup", signature = c("x"), - function(x, ...) - standardGeneric("calculateDMNgroup")) - #' @importFrom DirichletMultinomial dmngroup #' @importFrom stats runif .calculate_DMNgroup <- function(x, variable, k = 1, @@ -308,12 +278,6 @@ setMethod("calculateDMNgroup", signature = c(x = "SummarizedExperiment"), ################################################################################ # DMN group cross validations -#' @rdname calculateDMN -#' @export -setGeneric("performDMNgroupCV", signature = c("x"), - function(x, ...) - standardGeneric("performDMNgroupCV")) - #' @importFrom DirichletMultinomial cvdmngroup #' @importFrom stats runif .perform_DMNgroup_cv <- function(x, variable, k = 1, diff --git a/R/cluster.R b/R/cluster.R index 46ed6a345..8be7c27cd 100644 --- a/R/cluster.R +++ b/R/cluster.R @@ -59,16 +59,6 @@ #' NULL -#' @rdname addCluster -#' @export -setGeneric("addCluster", signature = c("x"), - function( - x, BLUSPARAM, assay.type = assay_name, - assay_name = "counts", by = MARGIN, MARGIN = "rows", full = FALSE, - name = "clusters", clust.col = "clusters", ...) - standardGeneric("addCluster")) - - #' @rdname addCluster #' @export #' @importFrom bluster clusterRows diff --git a/R/convertFromBIOM.R b/R/convertFromBIOM.R index 94b91a96d..4d73d62b5 100644 --- a/R/convertFromBIOM.R +++ b/R/convertFromBIOM.R @@ -254,16 +254,8 @@ convertFromBIOM <- function( #' #' @param ... Additional arguments. Not used currently. #' -#' -#' @export -setGeneric( - "convertToBIOM", signature = c("x"), - function( - x, assay.type = "counts", ...) - standardGeneric("convertToBIOM")) - -#' @rdname importBIOM #' @export +#' setMethod( "convertToBIOM", signature = c(x = "SummarizedExperiment"), function(x, assay.type = "counts", ...){ diff --git a/R/convertToPhyloseq.R b/R/convertToPhyloseq.R index ed9a1739f..bceec92fa 100644 --- a/R/convertToPhyloseq.R +++ b/R/convertToPhyloseq.R @@ -27,7 +27,7 @@ #' \code{convertToPhyloseq} returns an object of class #' \code{\link[phyloseq:phyloseq-class]{phyloseq}} #' -#' @rdname convertFromPhyloseq +#' @name convertFromPhyloseq #' @export #' #' @examples @@ -50,10 +50,7 @@ #' phy2 #' #' @export -setGeneric("convertToPhyloseq", signature = c("x"), - function(x, ...) - standardGeneric("convertToPhyloseq")) - +NULL #' @rdname convertFromPhyloseq #' @export diff --git a/R/decontam.R b/R/decontam.R index 11a204f5b..40c15cbf5 100644 --- a/R/decontam.R +++ b/R/decontam.R @@ -214,12 +214,6 @@ setMethod("isNotContaminant", signature = c(seqtab = "SummarizedExperiment"), } ) -#' @rdname isContaminant -#' @export -setGeneric("addContaminantQC", signature = c("x"), - function(x, name = "isContaminant", ...) - standardGeneric("addContaminantQC")) - #' @rdname isContaminant #' @export setMethod("addContaminantQC", signature = c("SummarizedExperiment"), @@ -236,12 +230,6 @@ setMethod("addContaminantQC", signature = c("SummarizedExperiment"), } ) -#' @rdname isContaminant -#' @export -setGeneric("addNotContaminantQC", signature = c("x"), - function(x, name = "isNotContaminant", ...) - standardGeneric("addNotContaminantQC")) - #' @rdname isContaminant #' @export setMethod("addNotContaminantQC", signature = c("SummarizedExperiment"), diff --git a/R/estimateDominance.R b/R/estimateDominance.R index ca6ce474b..489aed246 100644 --- a/R/estimateDominance.R +++ b/R/estimateDominance.R @@ -215,20 +215,6 @@ #' NULL -setGeneric( - ".estimate_dominance", signature = c("x"), - function(x, ...) standardGeneric(".estimate_dominance")) - -setGeneric( - ".estimate_dominance",signature = c("x"), - function( - x, assay.type = assay_name, assay_name = "counts", - index = c( - "absolute", "dbp", "core_abundance", "gini", "dmn", "relative", - "simpson_lambda"), - ntaxa = 1, aggregate = TRUE, name = index, BPPARAM = SerialParam(), ...) - standardGeneric(".estimate_dominance")) - .estimate_dominance <- function( x, assay.type = assay_name, assay_name = "counts", index = c( diff --git a/R/getCrossAssociation.R b/R/getCrossAssociation.R index 118a04e5b..1c32a8b11 100644 --- a/R/getCrossAssociation.R +++ b/R/getCrossAssociation.R @@ -230,11 +230,6 @@ #' NULL -#' @rdname getCrossAssociation -#' @export -setGeneric("getCrossAssociation", signature = c("x"), - function(x, ...) standardGeneric("getCrossAssociation")) - #' @rdname getCrossAssociation #' @export setMethod("getCrossAssociation", signature = c(x = "MultiAssayExperiment"), diff --git a/R/getDominant.R b/R/getDominant.R index 54b9788e0..243666051 100644 --- a/R/getDominant.R +++ b/R/getDominant.R @@ -73,14 +73,6 @@ #' colData(x) NULL -#' @rdname getDominant -#' @export -setGeneric("getDominant",signature = c("x"), - function(x, assay.type = assay_name, assay_name = "counts", - group = rank, rank = NULL, other.name = "Other", n = NULL, - complete = TRUE, ...) - standardGeneric("getDominant")) - #' @rdname getDominant #' @importFrom IRanges relist #' @export @@ -169,12 +161,6 @@ setMethod("getDominant", signature = c(x = "SummarizedExperiment"), } ) -#' @rdname getDominant -#' @export -setGeneric("addDominant", signature = c("x"), - function(x, name = "dominant_taxa", other.name = "Other", n = NULL, ...) - standardGeneric("addDominant")) - #' @rdname getDominant #' @export setMethod("addDominant", signature = c(x = "SummarizedExperiment"), diff --git a/R/getPERMANOVA.R b/R/getPERMANOVA.R index d92c79602..2a2d489c2 100644 --- a/R/getPERMANOVA.R +++ b/R/getPERMANOVA.R @@ -113,14 +113,6 @@ #' NULL -#' @rdname getPERMANOVA -setGeneric("getPERMANOVA", signature = c("x"), function(x, ...) - standardGeneric("getPERMANOVA")) - -#' @rdname getPERMANOVA -setGeneric("addPERMANOVA", signature = c("x"), function(x, ...) - standardGeneric("addPERMANOVA")) - #' @export #' @rdname getPERMANOVA setMethod("getPERMANOVA", "SingleCellExperiment", function(x, ...){ diff --git a/R/getPrevalence.R b/R/getPrevalence.R index 7b0621ead..fd244138f 100644 --- a/R/getPrevalence.R +++ b/R/getPrevalence.R @@ -171,12 +171,6 @@ #' NULL -#' @rdname getPrevalence -#' @export -setGeneric("getPrevalence", signature = "x", - function(x, ...) - standardGeneric("getPrevalence")) - #' @rdname getPrevalence #' @export setMethod("getPrevalence", signature = c(x = "ANY"), function( @@ -240,7 +234,7 @@ setMethod("getPrevalence", signature = c(x = "SummarizedExperiment"), } ) ############################# getPrevalent ################################# -#' @rdname getPrevalence +#' @name getPrevalence #' #' @param prevalence Prevalence threshold (in 0 to 1). The #' required prevalence is strictly greater by default. To include the @@ -253,9 +247,7 @@ setMethod("getPrevalence", signature = c(x = "SummarizedExperiment"), #' @aliases getPrevalent #' #' @export -setGeneric("getPrevalent", signature = "x", - function(x, ...) - standardGeneric("getPrevalent")) +NULL .norm_rownames <- function(x){ if(is.null(rownames(x))){ @@ -318,7 +310,6 @@ setGeneric("getPrevalent", signature = "x", unique(taxa) } - #' @rdname getPrevalence #' @export setMethod("getPrevalent", signature = c(x = "ANY"), @@ -341,15 +332,13 @@ setMethod("getPrevalent", signature = c(x = "SummarizedExperiment"), ############################# getRare ###################################### -#' @rdname getPrevalence +#' @name getPrevalence #' #' @details #' \code{getRare} returns complement of \code{getPrevalent}. #' #' @export -setGeneric("getRare", signature = "x", - function(x, ...) - standardGeneric("getRare")) +NULL .get_rare_indices <- function(x, ...){ indices <- .get_prevalent_indices(x = x, ...) @@ -398,12 +387,6 @@ setMethod("getRare", signature = c(x = "SummarizedExperiment"), ############################# subsetByPrevalent ############################ -#' @rdname getPrevalence -#' @export -setGeneric("subsetByPrevalent", signature = "x", - function(x, ...) - standardGeneric("subsetByPrevalent")) - #' @rdname getPrevalence #' @export setMethod("subsetByPrevalent", signature = c(x = "SummarizedExperiment"), @@ -434,12 +417,6 @@ setMethod("subsetByPrevalent", signature = c(x = "TreeSummarizedExperiment"), ############################# subsetByRare ################################# -#' @rdname getPrevalence -#' @export -setGeneric("subsetByRare", signature = "x", - function(x, ...) - standardGeneric("subsetByRare")) - #' @rdname getPrevalence #' @export setMethod("subsetByRare", signature = c(x = "SummarizedExperiment"), @@ -470,12 +447,6 @@ setMethod("subsetByRare", signature = c(x = "TreeSummarizedExperiment"), ############################# getPrevalentAbundance ############################ -#' @rdname getPrevalence -#' @export -setGeneric("getPrevalentAbundance", signature = "x", - function(x, assay.type = assay_name, assay_name = "relabundance", ...) - standardGeneric("getPrevalentAbundance")) - #' @rdname getPrevalence #' @export setMethod("getPrevalentAbundance", signature = c(x = "ANY"), @@ -507,7 +478,7 @@ setMethod("getPrevalentAbundance", signature = c(x = "SummarizedExperiment"), #' Agglomerate data based on population prevalence #' -#' @rdname agglomerateByPrevalence +#' @name agglomerateByPrevalence #' #' @inheritParams agglomerateByRank #' @@ -551,9 +522,7 @@ setMethod("getPrevalentAbundance", signature = c(x = "SummarizedExperiment"), #' assay(tse)[,1:5] #' #' @export -setGeneric("agglomerateByPrevalence", signature = "x", - function(x, ...) - standardGeneric("agglomerateByPrevalence")) +NULL #' @rdname agglomerateByPrevalence #' @export diff --git a/R/mediate.R b/R/mediate.R index 4c5b4de49..44f8aab02 100644 --- a/R/mediate.R +++ b/R/mediate.R @@ -147,11 +147,6 @@ #' NULL -#' @rdname getMediation -#' @export -setGeneric("addMediation", signature = c("x"), - function(x, ...) standardGeneric("addMediation")) - #' @rdname getMediation #' @export #' @importFrom stats gaussian @@ -173,11 +168,6 @@ setMethod("addMediation", signature = c(x = "SummarizedExperiment"), } ) -#' @rdname getMediation -#' @export -setGeneric("getMediation", signature = c("x"), - function(x, ...) standardGeneric("getMediation")) - #' @rdname getMediation #' @export #' @importFrom stats gaussian diff --git a/R/meltAssay.R b/R/meltAssay.R index a41cb0c47..ffb808b84 100644 --- a/R/meltAssay.R +++ b/R/meltAssay.R @@ -70,11 +70,6 @@ #' molten_tse NULL -#' @rdname meltSE -#' @export -setGeneric("meltSE", signature = "x", function(x, ...) - standardGeneric("meltSE")) - #' @rdname meltSE #' #' @export diff --git a/R/mergeSEs.R b/R/mergeSEs.R index 5bdf082fb..9d7f0a87d 100644 --- a/R/mergeSEs.R +++ b/R/mergeSEs.R @@ -137,16 +137,6 @@ #' NULL - - -################################### Generic #################################### - -#' @rdname mergeSEs -#' @export -setGeneric("mergeSEs", signature = c("x"), - function(x, ... ) - standardGeneric("mergeSEs")) - ###################### Function for SimpleList of TreeSEs ###################### #' @rdname mergeSEs diff --git a/R/rarefyAssay.R b/R/rarefyAssay.R index 66e540561..72a1680c5 100644 --- a/R/rarefyAssay.R +++ b/R/rarefyAssay.R @@ -69,14 +69,6 @@ #' NULL -#' @rdname rarefyAssay -#' @export -setGeneric("rarefyAssay", signature = c("x"), function( - x, assay.type = assay_name, assay_name = "counts", - sample = min_size, min_size = min(colSums2(assay(x))), - replace = TRUE, name = "subsampled", verbose = TRUE, ...) - standardGeneric("rarefyAssay")) - #' @importFrom SummarizedExperiment assay assay<- #' @importFrom DelayedMatrixStats colSums2 rowSums2 #' @rdname rarefyAssay diff --git a/R/runCCA.R b/R/runCCA.R index e6400b1fb..e20f891d9 100644 --- a/R/runCCA.R +++ b/R/runCCA.R @@ -164,23 +164,6 @@ #' NULL -#' @rdname runCCA -setGeneric("getCCA", signature = c("x"), function(x, ...) - standardGeneric("getCCA")) - -#' @rdname runCCA -setGeneric("addCCA", signature = c("x"), function(x, ...) - standardGeneric("addCCA")) - -#' @rdname runCCA -setGeneric("getRDA", signature = c("x"), function(x, ...) - standardGeneric("getRDA")) - -#' @rdname runCCA -setGeneric("addRDA", signature = c("x"), function(x, ...) - standardGeneric("addRDA")) - - ############################# Exported CCA methods ############################# #' @export diff --git a/R/runDPCoA.R b/R/runDPCoA.R index c972f9695..94b02abd6 100644 --- a/R/runDPCoA.R +++ b/R/runDPCoA.R @@ -79,11 +79,6 @@ #' plotReducedDim(esophagus, "DPCoA") NULL -#' @export -#' @rdname runDPCoA -setGeneric("getDPCoA", signature = c("x", "y"), - function(x, y, ...) standardGeneric("getDPCoA")) - .calculate_dpcoa <- function( x, y, ncomponents = 2, ntop = NULL, subset.row = subset_row, subset_row = NULL, scale = FALSE, diff --git a/R/runNMDS.R b/R/runNMDS.R index 1e849c9e9..b47ab9211 100644 --- a/R/runNMDS.R +++ b/R/runNMDS.R @@ -78,12 +78,6 @@ #' reducedDims(esophagus) NULL - -#' @rdname runNMDS -#' @export -setGeneric("getNMDS", function(x, ...) standardGeneric("getNMDS")) - - .format_nmds_isoMDS <- function(nmds){ ans <- nmds$points attr(ans, "Stress") <- nmds$stress diff --git a/R/splitByRanks.R b/R/splitByRanks.R index 83cb000ab..4908bd6b4 100644 --- a/R/splitByRanks.R +++ b/R/splitByRanks.R @@ -81,11 +81,6 @@ #' NULL -#' @rdname agglomerate-methods -#' @export -setGeneric("agglomerateByRanks", signature = "x", - function(x, ...) standardGeneric("agglomerateByRanks")) - .norm_args_for_split_by_ranks <- function(na.rm, ...){ args <- list(...) if(missing(na.rm)){ @@ -167,12 +162,6 @@ splitByRanks <- function(x, ...){ ################################################################################ # unsplitByRanks -#' @rdname agglomerate-methods -#' @export -setGeneric("unsplitByRanks", signature = "x", - function(x, ...) standardGeneric("unsplitByRanks")) - - #' @importFrom SingleCellExperiment reducedDims #' @importFrom SummarizedExperiment colData .unsplit_by <- function(x, ses, keep.dimred, ...){ diff --git a/R/splitOn.R b/R/splitOn.R index 6dd1f7bdb..9b54573e1 100644 --- a/R/splitOn.R +++ b/R/splitOn.R @@ -91,13 +91,6 @@ #' NULL -#' @rdname splitOn -#' @export -setGeneric("splitOn", - signature = "x", - function(x, ...) - standardGeneric("splitOn")) - # This function collects group (grouping variable), by, and # use.names and returns them as a list. .norm_args_for_split_by <- function( @@ -307,13 +300,6 @@ setMethod("splitOn", signature = c(x = "TreeSummarizedExperiment"), ################################################################################ # unsplitOn -#' @rdname splitOn -#' @export -setGeneric("unsplitOn", - signature = c("x"), - function(x, ...) - standardGeneric("unsplitOn")) - # Perform the unsplit .list_unsplit_on <- function( ses, update.tree = FALSE, by = MARGIN, MARGIN = NULL, ...){ diff --git a/R/subset.R b/R/subset.R index 2ae173417..b045e0b9c 100644 --- a/R/subset.R +++ b/R/subset.R @@ -9,5 +9,3 @@ } return(list(rows = rows, columns = columns)) } - - diff --git a/R/summaries.R b/R/summaries.R index d9a493655..13a0c88ed 100644 --- a/R/summaries.R +++ b/R/summaries.R @@ -40,7 +40,7 @@ #' @seealso #' \code{\link[=getPrevalence]{getPrevalent}} #' -#' @name summaries +#' @name summary #' #' @examples #' data(GlobalPatterns) @@ -88,14 +88,6 @@ #' NULL -#' @rdname summaries -#' @export -setGeneric("getTop", signature = "x", - function( - x, top= 5L, method = c("mean","sum","median"), - assay.type = assay_name, assay_name = "counts", na.rm = TRUE, ...) - standardGeneric("getTop")) - .check_max_taxa <- function(x, top, assay.type){ if(!is.numeric(top) || as.integer(top) != top){ stop("'top' must be integer value", call. = FALSE) @@ -105,7 +97,7 @@ setGeneric("getTop", signature = "x", } } -#' @rdname summaries +#' @rdname summary #' #' @importFrom DelayedMatrixStats rowSums2 rowMeans2 rowMedians #' @importFrom utils head @@ -144,7 +136,7 @@ setMethod("getTop", signature = c(x = "SummarizedExperiment"), } ) -#' @rdname summaries +#' @name summary #' #' @param rank \code{Character scalar}. Defines a taxonomic rank. Must be a #' value of the output of \code{taxonomyRanks()}. (Default: \code{NULl}) @@ -154,10 +146,9 @@ setMethod("getTop", signature = c(x = "SummarizedExperiment"), #' particular rank #' #' @export -setGeneric("getUnique", signature = c("x"), - function(x, ...) standardGeneric("getUnique")) +NULL -#' @rdname summaries +#' @rdname summary #' @export setMethod("getUnique", signature = c(x = "SummarizedExperiment"), function(x, rank = NULL, ...){ @@ -169,7 +160,7 @@ setMethod("getUnique", signature = c(x = "SummarizedExperiment"), } ) -#' @rdname summaries +#' @name summary #' #' @param group With group, it is possible to group the observations in an #' overview. Must be one of the column names of \code{colData}. @@ -194,12 +185,9 @@ setMethod("getUnique", signature = c(x = "SummarizedExperiment"), #' set. #' #' @export -setGeneric("summarizeDominance",signature = c("x"), - function(x, group = NULL, name = "dominant_taxa", ...) - standardGeneric("summarizeDominance")) - +NULL -#' @rdname summaries +#' @rdname summary #' @export setMethod("summarizeDominance", signature = c(x = "SummarizedExperiment"), function(x, group = NULL, name = "dominant_taxa", ...){ @@ -301,7 +289,7 @@ setMethod("summarizeDominance", signature = c(x = "SummarizedExperiment"), return(tallied_data) } -#' @rdname summaries +#' @rdname summary #' #' @param object A #' \code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}} diff --git a/R/taxonomy.R b/R/taxonomy.R index 43f4253d8..364f89f92 100644 --- a/R/taxonomy.R +++ b/R/taxonomy.R @@ -165,11 +165,6 @@ getTaxonomyRankPrefixes <- function() { #' recognized. In functions this is used as case insensitive. TAXONOMY_RANKS <- names(.taxonomy_rank_prefixes) -#' @rdname taxonomy-methods -setGeneric("taxonomyRanks", signature = c("x"), - function(x) - standardGeneric("taxonomyRanks")) - #' @rdname taxonomy-methods #' #' @importFrom SummarizedExperiment rowData @@ -182,13 +177,6 @@ setMethod("taxonomyRanks", signature = c(x = "SummarizedExperiment"), } ) -#' @rdname taxonomy-methods -setGeneric("taxonomyRankEmpty", - signature = "x", - function(x, rank = taxonomyRanks(x)[1L], - empty.fields = c(NA, "", " ", "\t", "-", "_")) - standardGeneric("taxonomyRankEmpty")) - #' @rdname taxonomy-methods #' @aliases taxonomyRankEmpty #' @@ -217,12 +205,6 @@ setMethod("taxonomyRankEmpty", signature = c(x = "SummarizedExperiment"), } ) -#' @rdname taxonomy-methods -setGeneric("checkTaxonomy", - signature = "x", - function(x, ...) - standardGeneric("checkTaxonomy")) - #' @rdname taxonomy-methods #' @aliases checkTaxonomy #' @export @@ -303,13 +285,6 @@ getTaxonomyRanks <- function() { } } - -#' @rdname taxonomy-methods -setGeneric("getTaxonomyLabels", - signature = "x", - function(x, ...) - standardGeneric("getTaxonomyLabels")) - #' @rdname taxonomy-methods #' @aliases checkTaxonomy #' @export @@ -486,12 +461,6 @@ setMethod("getTaxonomyLabels", signature = c(x = "SummarizedExperiment"), #' tse NULL -#' @rdname hierarchy-tree -setGeneric("getHierarchyTree", - signature = "x", - function(x, ...) - standardGeneric("getHierarchyTree")) - #' @rdname hierarchy-tree #' @aliases getHierarchyTree #' @export @@ -555,12 +524,6 @@ setMethod("getHierarchyTree", signature = c(x = "SummarizedExperiment"), } ) -#' @rdname hierarchy-tree -setGeneric("addHierarchyTree", - signature = "x", - function(x, ...) - standardGeneric("addHierarchyTree")) - #' @rdname hierarchy-tree #' @export setMethod("addHierarchyTree", signature = c(x = "SummarizedExperiment"), @@ -579,12 +542,6 @@ setMethod("addHierarchyTree", signature = c(x = "SummarizedExperiment"), } ) -#' @rdname taxonomy-methods -setGeneric("mapTaxonomy", - signature = "x", - function(x, ...) - standardGeneric("mapTaxonomy")) - #' @importFrom BiocGenerics %in% grepl .get_taxa_row_match <- function(taxa, td, from, use.grepl = FALSE){ if(is.na(taxa)){ diff --git a/R/transformCounts.R b/R/transformCounts.R index dfa9cb158..f41413174 100644 --- a/R/transformCounts.R +++ b/R/transformCounts.R @@ -158,12 +158,6 @@ #' NULL -#' @rdname transformAssay -#' @export -setGeneric("transformAssay", signature = c("x"), - function(x, ...) - standardGeneric("transformAssay")) - #' @rdname transformAssay #' @export setMethod("transformAssay", signature = c(x = "SummarizedExperiment"), diff --git a/man/GlobalPatterns.Rd b/man/GlobalPatterns.Rd index c9baced62..4be45c72c 100644 --- a/man/GlobalPatterns.Rd +++ b/man/GlobalPatterns.Rd @@ -3,7 +3,8 @@ \docType{data} \name{GlobalPatterns} \alias{GlobalPatterns} -\title{Global patterns of 16S rRNA diversity at a depth of millions of sequences per sample.} +\title{Global patterns of 16S rRNA diversity at a depth of millions of sequences per +sample.} \format{ A TreeSummarizedExperiment with 19216 features and 26 samples. The rowData contains taxonomic information at Kingdom, Phylum, Class, Order, @@ -15,7 +16,8 @@ Family, Genus and Species levels. The colData includes: \item{Final_Barcode}{final barcode (6 nucleotides)} \item{Barcode_truncated_plus_T}{truncated barcode with an added tyrosine (6 nucleotides)} -\item{Barcode_full_length}{complete barcode with a length of 11 nucleotides} +\item{Barcode_full_length}{complete barcode with a length of 11 +nucleotides} \item{SampleType}{sampling type by collection site (Soil, Feces, Skin, Tongue, Freshwater, Creek Freshwater, Ocean, Estuary Sediment and Mock)} \item{Description}{additional information (sampling location, environmental @@ -26,7 +28,8 @@ factors and study type)} data(GlobalPatterns) } \description{ -GlobalPatterns compared the microbial communities from 25 environmental samples +GlobalPatterns compared the microbial communities from 25 environmental +samples and three known "mock communities" at a an average depth of 3.1 million reads per sample. Authors reproduced diversity patterns seen in many other published studies, while investigating technical bias by applying the same @@ -37,7 +40,8 @@ converted to \code{TreeSummarizedExperiment}. } \references{ Caporaso, J. G., et al. (2011). -Global patterns of 16S rRNA diversity at a depth of millions of sequences per sample. +Global patterns of 16S rRNA diversity at a depth of millions of sequences per +sample. PNAS, 108, 4516-4522. \url{https://doi.org/10.1073/pnas.1000080107} } \seealso{ diff --git a/man/HintikkaXOData.Rd b/man/HintikkaXOData.Rd index f115e63a1..ecc683054 100644 --- a/man/HintikkaXOData.Rd +++ b/man/HintikkaXOData.Rd @@ -5,9 +5,12 @@ \alias{HintikkaXOData} \title{Multiomics dataset from 40 rat samples} \format{ -A MultiAssayExperiment with 3 experiments (microbiota, metabolites and -biomarkers). rowData of the microbiota experiment contains taxonomic information -at Phylum, Class, Order, Family, Genus, Species and OTU levels. The metabolites +A MultiAssayExperiment with 3 experiments (microbiota, metabolites +and +biomarkers). rowData of the microbiota experiment contains taxonomic +information +at Phylum, Class, Order, Family, Genus, Species and OTU levels. The +metabolites and biomarkers experiments contain 38 NMR metabolites and 39 biomarkers, respectively. The colData includes: diff --git a/man/Tengeler2020.Rd b/man/Tengeler2020.Rd index 35cb74fff..991b3f2ee 100644 --- a/man/Tengeler2020.Rd +++ b/man/Tengeler2020.Rd @@ -30,7 +30,8 @@ microbiota from individuals with and without ADHD. } \references{ Tengeler, A.C., Dam, S.A., Wiesmann, M. et al. -Gut microbiota from persons with attention-deficit/hyperactivity disorder affects the brain in mice. +Gut microbiota from persons with attention-deficit/hyperactivity disorder +affects the brain in mice. Microbiome 8, 44 (2020). \url{https://doi.org/10.1186/s40168-020-00816-x} Supplemental information includes Home-cage activity, methods, results and imaging parameters and publicly-accessible from: diff --git a/man/Tito2024QMP.Rd b/man/Tito2024QMP.Rd index 129fa5a42..9801314b0 100644 --- a/man/Tito2024QMP.Rd +++ b/man/Tito2024QMP.Rd @@ -3,16 +3,19 @@ \docType{data} \name{Tito2024QMP} \alias{Tito2024QMP} -\title{Fecal microbiota samples from 589 patients across different colorectal cancer stages} +\title{Fecal microbiota samples from 589 patients across different colorectal +cancer stages} \format{ A TreeSummarizedExperiment with 676 features and 589 samples. The rowData contains species. The colData includes: \describe{ \item{sampleID}{(character) Sample ID from the corresponding study} -\item{diagnosis}{(factor) Diagnosis type, with possible values: "ADE" (advanced adenoma), +\item{diagnosis}{(factor) Diagnosis type, with possible values: "ADE" +(advanced adenoma), "CRC" (colorectal cancer), "CTL" (control)} -\item{colonoscopy}{(factor) Colonoscopy result, with possible values: "FIT_Positive", +\item{colonoscopy}{(factor) Colonoscopy result, with possible values: +"FIT_Positive", "familial_risk_familial_CRC_FCC", "familial_risk_no", "abdomil_complaints"} } } @@ -23,15 +26,21 @@ data(Tito2024QMP) The study combined Quantitative Microbiome Profiling (QMP) with extensive patient phenotyping from a group of 589 colorectal cancer (CRC) patients, advanced adenoma (AA) patients, and healthy controls. -By implementing confounder control and quantitative profiling methods, the study -was able to reveal potential misleading associations between microbial markers -and colorectal cancer development that were driven by other factors like intestinal +By implementing confounder control and quantitative profiling methods, +the study +was able to reveal potential misleading associations between microbial +markers +and colorectal cancer development that were driven by other factors like +intestinal inflammation, rather than the cancer diagnosis itself. } \references{ -Raúl Y. Tito, Sara Verbandt, Marta Aguirre Vazquez, Leo Lahti, Chloe Verspecht, Verónica Lloréns-Rico, Sara Vieira-Silva, -Janine Arts, Gwen Falony, Evelien Dekker, Joke Reumers, Sabine Tejpar & Jeroen Raes (2024). -Microbiome confounders and quantitative profiling challenge predicted microbial targets in colorectal cancer development. +Raúl Y. Tito, Sara Verbandt, Marta Aguirre Vazquez, Leo Lahti, Chloe +Verspecht, Verónica Lloréns-Rico, Sara Vieira-Silva, +Janine Arts, Gwen Falony, Evelien Dekker, Joke Reumers, Sabine Tejpar & +Jeroen Raes (2024). +Microbiome confounders and quantitative profiling challenge predicted +microbial targets in colorectal cancer development. Nature Medicine,30, 1339-1348. \url{https://doi.org/10.1038/s41591-024-02963-2} } diff --git a/man/addAlpha.Rd b/man/addAlpha.Rd index a8b8bfbee..0a0bcfe84 100644 --- a/man/addAlpha.Rd +++ b/man/addAlpha.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/addAlpha.R +% Please edit documentation in R/AllGenerics.R, R/addAlpha.R \name{addAlpha} \alias{addAlpha} \alias{addAlpha,SummarizedExperiment-method} @@ -60,8 +60,8 @@ depth i.e. the number of counts drawn from each sample. \item \code{tree.name}: \code{Character scalar}. Specifies which rowTree will be used. ( Faith's index). (Default: \code{"phylo"}) -\item \code{node.label}: \code{Character vector} or \code{NULL} Specifies the -links between rows and node labels of phylogeny tree specified +\item \code{node.label}: \code{Character vector} or \code{NULL} Specifies +the links between rows and node labels of phylogeny tree specified by \code{tree.name}. If a certain row is not linked with the tree, missing instance should be noted as NA. When \code{NULL}, all the rownames should be found from the tree. (Faith's index). (Default: \code{NULL}) @@ -71,16 +71,17 @@ whether to remove internal nodes when Faith's index is calculated. When \code{only.tips=TRUE}, those rows that are not tips of tree are removed. (Default: \code{FALSE}) -\item \code{threshold}: (Coverage and all evenness indices). \code{Numeric scalar}. +\item \code{threshold}: (Coverage and all evenness indices). +\code{Numeric scalar}. From \code{0 to 1}, determines the threshold for coverage and evenness indices. When evenness indices are calculated values under or equal to this threshold are denoted as zeroes. For coverage index, see details. (Default: \code{0.5} for coverage, \code{0} for evenness indices) \item \code{quantile}: (log modulo skewness index). \code{Numeric scalar}. -Arithmetic abundance classes are evenly cut up to to this quantile of the data. -The assumption is that abundances higher than this are not common, and they -are classified in their own group. (Default: \code{0.5}) +Arithmetic abundance classes are evenly cut up to to this quantile of the +data. The assumption is that abundances higher than this are not common, +and they are classified in their own group. (Default: \code{0.5}) \item \code{nclasses}: (log modulo skewness index). \code{Integer scalar}. The number of arithmetic abundance classes from zero to the quantile cutoff @@ -242,9 +243,9 @@ dominant species and \eqn{N_{tot}} is the sum of absolute abundances of all species. \item 'simpson_lambda': Simpson's (dominance) index or Simpson's lambda is -the sum of squared relative abundances. This index gives values in the unit interval. -This value equals the probability that two randomly chosen individuals -belongs to the +the sum of squared relative abundances. This index gives values in the unit +interval. This value equals the probability that two randomly chosen +individuals belongs to the same species. The higher the probability, the greater the dominance (See e.g. Simpson 1949). @@ -272,10 +273,13 @@ By default, this function returns all indices. The available evenness indices include the following (all in lowercase): \itemize{ \item 'camargo': Camargo's evenness (Camargo 1992) -\item 'simpson_evenness': Simpson’s evenness is calculated as inverse Simpson diversity (1/lambda) divided by +\item 'simpson_evenness': Simpson’s evenness is calculated as inverse +Simpson diversity (1/lambda) divided by observed species richness S: (1/lambda)/S. -\item 'pielou': Pielou's evenness (Pielou, 1966), also known as Shannon or Shannon-Weaver/Wiener/Weiner -evenness; H/ln(S). The Shannon-Weaver is the preferred term; see Spellerberg and Fedor (2003). +\item 'pielou': Pielou's evenness (Pielou, 1966), also known as Shannon or +Shannon-Weaver/Wiener/Weiner +evenness; H/ln(S). The Shannon-Weaver is the preferred term; see +Spellerberg and Fedor (2003). \item 'evar': Smith and Wilson’s Evar index (Smith & Wilson 1996). \item 'bulla': Bulla’s index (O) (Bulla 1994). } diff --git a/man/addCluster.Rd b/man/addCluster.Rd index 4df17ee46..0d69d1891 100644 --- a/man/addCluster.Rd +++ b/man/addCluster.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/cluster.R +% Please edit documentation in R/AllGenerics.R, R/cluster.R \name{addCluster} \alias{addCluster} \alias{addCluster,SummarizedExperiment-method} @@ -61,9 +61,9 @@ Must be \code{'rows'} or \code{'cols'}.} \item{...}{Additional parameters to use altExps for example} } \value{ -\code{addCluster} returns an object of the same type as the \code{x} parameter -with clustering information named \code{clusters} stored in \code{colData} -or \code{rowData}. +\code{addCluster} returns an object of the same type as the \code{x} +parameter with clustering information named \code{clusters} stored in +\code{colData} or \code{rowData}. } \description{ This function returns a \code{SummarizedExperiment} with clustering diff --git a/man/addDivergence.Rd b/man/addDivergence.Rd index 714bf0a7a..65e0ebbf7 100644 --- a/man/addDivergence.Rd +++ b/man/addDivergence.Rd @@ -1,16 +1,14 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/addDivergence.R +% Please edit documentation in R/AllGenerics.R, R/addDivergence.R \name{addDivergence} \alias{addDivergence} -\alias{addDivergence,SummarizedExperiment-method} \alias{getDivergence} +\alias{addDivergence,SummarizedExperiment-method} \alias{getDivergence,SummarizedExperiment-method} \title{Estimate divergence} \usage{ addDivergence(x, name = "divergence", ...) -\S4method{addDivergence}{SummarizedExperiment}(x, name = "divergence", ...) - getDivergence( x, assay.type = assay_name, @@ -20,6 +18,8 @@ getDivergence( ... ) +\S4method{addDivergence}{SummarizedExperiment}(x, name = "divergence", ...) + \S4method{getDivergence}{SummarizedExperiment}( x, assay.type = assay_name, diff --git a/man/addLDA.Rd b/man/addLDA.Rd index 636bde675..584c7932e 100644 --- a/man/addLDA.Rd +++ b/man/addLDA.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/addLDA.R -\name{addLDA} -\alias{addLDA} +% Please edit documentation in R/AllGenerics.R, R/addLDA.R +\name{getLDA} \alias{getLDA} +\alias{addLDA} \alias{getLDA,SummarizedExperiment-method} \alias{addLDA,SummarizedExperiment-method} \title{Latent Dirichlet Allocation} diff --git a/man/addNMF.Rd b/man/addNMF.Rd index 8fb746631..fa9d6a17c 100644 --- a/man/addNMF.Rd +++ b/man/addNMF.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/addNMF.R -\name{addNMF} -\alias{addNMF} +% Please edit documentation in R/AllGenerics.R, R/addNMF.R +\name{getNMF} \alias{getNMF} +\alias{addNMF} \alias{getNMF,SummarizedExperiment-method} \alias{addNMF,SummarizedExperiment-method} \title{Non-negative Matrix Factorization} diff --git a/man/agglomerate-methods.Rd b/man/agglomerate-methods.Rd index 78e3f47db..252e6cf8b 100644 --- a/man/agglomerate-methods.Rd +++ b/man/agglomerate-methods.Rd @@ -1,26 +1,33 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/agglomerate.R, R/splitByRanks.R -\name{agglomerate-methods} -\alias{agglomerate-methods} +% Please edit documentation in R/AllGenerics.R, R/agglomerate.R, +% R/splitByRanks.R +\name{agglomerateByRank} \alias{agglomerateByRank} +\alias{agglomerateByVariable} +\alias{agglomerateByRanks} +\alias{unsplitByRanks} +\alias{agglomerate-methods} \alias{agglomerateByRank,TreeSummarizedExperiment-method} \alias{agglomerateByRank,SingleCellExperiment-method} \alias{agglomerateByRank,SummarizedExperiment-method} -\alias{agglomerateByVariable} \alias{agglomerateByVariable,TreeSummarizedExperiment-method} \alias{agglomerateByVariable,SummarizedExperiment-method} -\alias{agglomerateByRanks} \alias{agglomerateByRanks,SummarizedExperiment-method} \alias{agglomerateByRanks,SingleCellExperiment-method} \alias{agglomerateByRanks,TreeSummarizedExperiment-method} \alias{splitByRanks} -\alias{unsplitByRanks} \alias{unsplitByRanks,SingleCellExperiment-method} \alias{unsplitByRanks,TreeSummarizedExperiment-method} \title{Agglomerate data using taxonomic information or other grouping} \usage{ agglomerateByRank(x, ...) +agglomerateByVariable(x, ...) + +agglomerateByRanks(x, ...) + +unsplitByRanks(x, ...) + \S4method{agglomerateByRank}{TreeSummarizedExperiment}( x, rank = taxonomyRanks(x)[1], @@ -47,8 +54,6 @@ agglomerateByRank(x, ...) ... ) -agglomerateByVariable(x, ...) - \S4method{agglomerateByVariable}{TreeSummarizedExperiment}( x, by, @@ -61,8 +66,6 @@ agglomerateByVariable(x, ...) \S4method{agglomerateByVariable}{SummarizedExperiment}(x, by, group = f, f, ...) -agglomerateByRanks(x, ...) - \S4method{agglomerateByRanks}{SummarizedExperiment}( x, ranks = taxonomyRanks(x), @@ -89,8 +92,6 @@ agglomerateByRanks(x, ...) splitByRanks(x, ...) -unsplitByRanks(x, ...) - \S4method{unsplitByRanks}{SingleCellExperiment}( x, ranks = taxonomyRanks(x), @@ -158,8 +159,8 @@ returned unchanged.} \item{mergeTree}{Deprecated. Use \code{update.tree} instead.} -\item{ranks}{\code{Character vector}. Defines taxonomic ranks. Must all be values -of \code{taxonomyRanks()} function.} +\item{ranks}{\code{Character vector}. Defines taxonomic ranks. Must all be +values of \code{taxonomyRanks()} function.} \item{na.rm}{\code{Logical scalar}. Should NA values be omitted? (Default: \code{TRUE})} @@ -214,7 +215,8 @@ retained as defined by \code{archetype}. agglomerated, i.e. summed up. If the assay contains values other than counts or absolute values, this can lead to meaningless values being produced. -\code{agglomerateByRanks} takes a \code{SummarizedExperiment}, splits it along the +\code{agglomerateByRanks} takes a \code{SummarizedExperiment}, splits it +along the taxonomic ranks, aggregates the data per rank, converts the input to a \code{SingleCellExperiment} objects and stores the aggregated data as alternative experiments. \code{unsplitByRanks} takes these alternative @@ -235,7 +237,8 @@ argument lets the user select how to preserve row or column data. For merge data of assays the function from \code{scuttle} are used. -\code{agglomerateByRanks} will use by default all available taxonomic ranks, but +\code{agglomerateByRanks} will use by default all available taxonomic ranks, +but this can be controlled by setting \code{ranks} manually. \code{NA} values are removed by default, since they would not make sense, if the result should be used for \code{unsplitByRanks} at some point. The input data @@ -247,7 +250,8 @@ so that no ambiguous data is created. In additional, a column specify from which alternative experiment this originates from. This can also be used for \code{\link[SingleCellExperiment:splitAltExps]{splitAltExps}} to split the result along the same factor again. The input data from the base -objects is not returned, only the data from the \code{altExp()}. Be aware that +objects is not returned, only the data from the \code{altExp()}. Be aware +that changes to \code{rowData} of the base object are not returned, whereas only the \code{colData} of the base object is kept. } diff --git a/man/agglomerateByPrevalence.Rd b/man/agglomerateByPrevalence.Rd index 26495b8af..bd9e99777 100644 --- a/man/agglomerateByPrevalence.Rd +++ b/man/agglomerateByPrevalence.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/getPrevalence.R +% Please edit documentation in R/AllGenerics.R, R/getPrevalence.R \name{agglomerateByPrevalence} \alias{agglomerateByPrevalence} \alias{agglomerateByPrevalence,SummarizedExperiment-method} diff --git a/man/calculateDMN.Rd b/man/calculateDMN.Rd index 579453602..b0e1e635f 100644 --- a/man/calculateDMN.Rd +++ b/man/calculateDMN.Rd @@ -1,26 +1,36 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/calculateDMM.R +% Please edit documentation in R/AllGenerics.R, R/calculateDMM.R \name{calculateDMN} \alias{calculateDMN} +\alias{getDMN} +\alias{bestDMNFit} +\alias{calculateDMNgroup} +\alias{performDMNgroupCV} +\alias{getBestDMNFit} \alias{calculateDMN,ANY-method} \alias{calculateDMN,SummarizedExperiment-method} \alias{runDMN} -\alias{getDMN} \alias{getDMN,SummarizedExperiment-method} -\alias{bestDMNFit} \alias{bestDMNFit,SummarizedExperiment-method} -\alias{getBestDMNFit} \alias{getBestDMNFit,SummarizedExperiment-method} -\alias{calculateDMNgroup} \alias{calculateDMNgroup,ANY-method} \alias{calculateDMNgroup,SummarizedExperiment-method} -\alias{performDMNgroupCV} \alias{performDMNgroupCV,ANY-method} \alias{performDMNgroupCV,SummarizedExperiment-method} \title{Dirichlet-Multinomial Mixture Model: Machine Learning for Microbiome Data} \usage{ calculateDMN(x, ...) +getDMN(x, name = "DMN", ...) + +bestDMNFit(x, name = "DMN", type = c("laplace", "AIC", "BIC"), ...) + +calculateDMNgroup(x, ...) + +performDMNgroupCV(x, ...) + +getBestDMNFit(x, name = "DMN", type = c("laplace", "AIC", "BIC"), ...) + \S4method{calculateDMN}{ANY}( x, k = 1, @@ -40,20 +50,12 @@ calculateDMN(x, ...) runDMN(x, name = "DMN", ...) -getDMN(x, name = "DMN", ...) - \S4method{getDMN}{SummarizedExperiment}(x, name = "DMN") -bestDMNFit(x, name = "DMN", type = c("laplace", "AIC", "BIC"), ...) - \S4method{bestDMNFit}{SummarizedExperiment}(x, name = "DMN", type = c("laplace", "AIC", "BIC")) -getBestDMNFit(x, name = "DMN", type = c("laplace", "AIC", "BIC"), ...) - \S4method{getBestDMNFit}{SummarizedExperiment}(x, name = "DMN", type = c("laplace", "AIC", "BIC")) -calculateDMNgroup(x, ...) - \S4method{calculateDMNgroup}{ANY}( x, variable, @@ -72,8 +74,6 @@ calculateDMNgroup(x, ...) ... ) -performDMNgroupCV(x, ...) - \S4method{performDMNgroupCV}{ANY}( x, variable, @@ -99,8 +99,14 @@ object.} \item{...}{optional arguments not used.} -\item{k}{\code{Numeric scalar}. The number of Dirichlet components to fit. See -\code{\link[DirichletMultinomial:dmn]{dmn}}. (Default: \code{1})} +\item{name}{\code{Character scalar}. The name to store the result in +\code{\link[SummarizedExperiment:RangedSummarizedExperiment-class]{metadata}}} + +\item{type}{\code{Character scalar}. The type of measure used for the +goodness of fit. One of \sQuote{laplace}, \sQuote{AIC} or \sQuote{BIC}.} + +\item{k}{\code{Numeric scalar}. The number of Dirichlet components to fit. +See \code{\link[DirichletMultinomial:dmn]{dmn}}. (Default: \code{1})} \item{BPPARAM}{A \code{\link[BiocParallel:BiocParallelParam-class]{BiocParallelParam}} @@ -116,17 +122,11 @@ assay used in calculation. (Default: \code{"counts"})} \item{exprs_values}{Deprecated. Use \code{assay.type} instead.} -\item{transposed}{\code{Logical scalar}. Is \code{x} transposed with samples in rows? -(Default: \code{FALSE})} - -\item{name}{\code{Character scalar}. The name to store the result in -\code{\link[SummarizedExperiment:RangedSummarizedExperiment-class]{metadata}}} - -\item{type}{\code{Character scalar}. The type of measure used for the goodness of fit. One of -\sQuote{laplace}, \sQuote{AIC} or \sQuote{BIC}.} +\item{transposed}{\code{Logical scalar}. Is \code{x} transposed with samples +in rows? (Default: \code{FALSE})} -\item{variable}{\code{Character scalar}. A variable from \code{colData} to use as a -grouping variable. Must be a character of factor.} +\item{variable}{\code{Character scalar}. A variable from \code{colData} to +use as a grouping variable. Must be a character of factor.} } \value{ \code{calculateDMN} and \code{getDMN} return a list of \code{DMN} objects, diff --git a/man/convertFromPhyloseq.Rd b/man/convertFromPhyloseq.Rd index 413546afe..00d0f3e3f 100644 --- a/man/convertFromPhyloseq.Rd +++ b/man/convertFromPhyloseq.Rd @@ -1,16 +1,17 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/convertFromPhyloseq.R, R/convertToPhyloseq.R -\name{convertFromPhyloseq} -\alias{convertFromPhyloseq} +% Please edit documentation in R/AllGenerics.R, R/convertFromPhyloseq.R, +% R/convertToPhyloseq.R +\name{convertToPhyloseq} \alias{convertToPhyloseq} +\alias{convertFromPhyloseq} \alias{convertToPhyloseq,SummarizedExperiment-method} \alias{convertToPhyloseq,TreeSummarizedExperiment-method} \title{Create a \code{TreeSummarizedExperiment} object from a phyloseq object} \usage{ -convertFromPhyloseq(x) - convertToPhyloseq(x, ...) +convertFromPhyloseq(x) + \S4method{convertToPhyloseq}{SummarizedExperiment}(x, assay.type = "counts", assay_name = NULL, ...) \S4method{convertToPhyloseq}{TreeSummarizedExperiment}(x, tree.name = tree_name, tree_name = "phylo", ...) diff --git a/man/enterotype.Rd b/man/enterotype.Rd index 14b83f379..debeb2325 100644 --- a/man/enterotype.Rd +++ b/man/enterotype.Rd @@ -43,7 +43,8 @@ converted into a TreeSummarizedExperiment from the \pkg{phyloseq} package. Arumugam, M., et al. (2011). Enterotypes of the human gut microbiome. Nature, 473(7346), 174-180. \url{https://doi.org/10.1038/nature09944} -Arumugam, M., et al. (2014). Addendum: Enterotypes of the human gut microbiome. +Arumugam, M., et al. (2014). Addendum: Enterotypes of the human gut +microbiome. Nature 506, 516 (2014). \url{https://doi.org/10.1038/nature13075} } \seealso{ diff --git a/man/esophagus.Rd b/man/esophagus.Rd index 12eb74c44..5e3e2e096 100644 --- a/man/esophagus.Rd +++ b/man/esophagus.Rd @@ -17,16 +17,20 @@ data(esophagus) \description{ This small dataset from a human esophageal community includes 3 samples from 3 human adults based on biopsies analysed with 16S rDNA PCR. The 16S rRNA -sequence processing is provided in the mothur wiki from the link below. It was +sequence processing is provided in the mothur wiki from the link below. It +was converted into a TreeSummarizedExperiment from the \pkg{phyloseq} package. } \references{ -Pei, Z., Bini, E. J., Yang, L., Zhou, M., Francois, F., & Blaser, M. J. (2004). +Pei, Z., Bini, E. J., Yang, L., Zhou, M., Francois, F., & Blaser, M. J. +(2004). Bacterial biota in the human distal esophagus. -Proceedings of the National Academy of Sciences of the United States of America, 101(12), 4250-4255. +Proceedings of the National Academy of Sciences of the United States of +America, 101(12), 4250-4255. \url{https://doi.org/10.1073/pnas.0306398101} -McMurdie, J. & Holmes, S. (2013) \emph{phyloseq}: An R Package for reproducible interactive analysis +McMurdie, J. & Holmes, S. (2013) \emph{phyloseq}: An R Package for +reproducible interactive analysis and graphics of microbiome census data. PLoS ONE. 8(4):e61217. \url{https://doi.org/10.1371/journal.pone.0061217} } diff --git a/man/getCrossAssociation.Rd b/man/getCrossAssociation.Rd index 7f28d86b7..35e5ce865 100644 --- a/man/getCrossAssociation.Rd +++ b/man/getCrossAssociation.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/getCrossAssociation.R +% Please edit documentation in R/AllGenerics.R, R/getCrossAssociation.R \name{getCrossAssociation} \alias{getCrossAssociation} \alias{getCrossAssociation,MultiAssayExperiment-method} diff --git a/man/getDissimilarity.Rd b/man/getDissimilarity.Rd index 90b5769db..41cdfb8b3 100644 --- a/man/getDissimilarity.Rd +++ b/man/getDissimilarity.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/addDissimilarity.R -\name{getDissimilarity} -\alias{getDissimilarity} +% Please edit documentation in R/AllGenerics.R, R/addDissimilarity.R +\name{addDissimilarity} \alias{addDissimilarity} +\alias{getDissimilarity} \alias{addDissimilarity,SummarizedExperiment-method} \alias{getDissimilarity,SummarizedExperiment-method} \alias{getDissimilarity,TreeSummarizedExperiment-method} @@ -11,10 +11,10 @@ \usage{ addDissimilarity(x, method, ...) -\S4method{addDissimilarity}{SummarizedExperiment}(x, method = "bray", name = method, ...) - getDissimilarity(x, method, ...) +\S4method{addDissimilarity}{SummarizedExperiment}(x, method = "bray", name = method, ...) + \S4method{getDissimilarity}{SummarizedExperiment}( x, method = "bray", diff --git a/man/getDominant.Rd b/man/getDominant.Rd index 7007da0c0..7bc0c93b7 100644 --- a/man/getDominant.Rd +++ b/man/getDominant.Rd @@ -1,9 +1,9 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/getDominant.R +% Please edit documentation in R/AllGenerics.R, R/getDominant.R \name{getDominant} \alias{getDominant} -\alias{getDominant,SummarizedExperiment-method} \alias{addDominant} +\alias{getDominant,SummarizedExperiment-method} \alias{addDominant,SummarizedExperiment-method} \title{Get dominant taxa} \usage{ @@ -19,6 +19,8 @@ getDominant( ... ) +addDominant(x, name = "dominant_taxa", other.name = "Other", n = NULL, ...) + \S4method{getDominant}{SummarizedExperiment}( x, assay.type = assay_name, @@ -31,8 +33,6 @@ getDominant( ... ) -addDominant(x, name = "dominant_taxa", other.name = "Other", n = NULL, ...) - \S4method{addDominant}{SummarizedExperiment}( x, name = "dominant_taxa", diff --git a/man/getMediation.Rd b/man/getMediation.Rd index e5519e161..f46a3b15d 100644 --- a/man/getMediation.Rd +++ b/man/getMediation.Rd @@ -1,14 +1,16 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/mediate.R -\name{getMediation} -\alias{getMediation} +% Please edit documentation in R/AllGenerics.R, R/mediate.R +\name{addMediation} \alias{addMediation} +\alias{getMediation} \alias{addMediation,SummarizedExperiment-method} \alias{getMediation,SummarizedExperiment-method} \title{Perform mediation analysis} \usage{ addMediation(x, ...) +getMediation(x, ...) + \S4method{addMediation}{SummarizedExperiment}( x, outcome, @@ -25,8 +27,6 @@ addMediation(x, ...) ... ) -getMediation(x, ...) - \S4method{getMediation}{SummarizedExperiment}( x, outcome, @@ -43,7 +43,8 @@ getMediation(x, ...) ) } \arguments{ -\item{x}{a \code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}}.} +\item{x}{a +\code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}}.} \item{...}{additional parameters that can be passed to \code{\link[mediation:mediate]{mediate}}.} @@ -67,19 +68,19 @@ feature-wise mediation analysis. (Default: \code{"counts"})} result in \code{reducedDims(object)} for component-wise mediation analysis. (Default: \code{NULL})} -\item{family}{\code{Character scalar}. A specification for the outcome model link function. -(Default: \code{gaussian("identity")})} +\item{family}{\code{Character scalar}. A specification for the outcome model +link function. (Default: \code{gaussian("identity")})} -\item{covariates}{\code{Character scalar} or \code{character vector}. Indicates the colData -variables used as covariates in the model. +\item{covariates}{\code{Character scalar} or \code{character vector}. +Indicates the colData variables used as covariates in the model. (Default: \code{NULL})} \item{p.adj.method}{\code{Character scalar}. Selects adjustment method of p-values. Passed to \code{p.adjust} function. (Default: \code{"holm"})} -\item{add.metadata}{\code{Logical scalar}. Should the model metadata be returned. -(Default: \code{FALSE})} +\item{add.metadata}{\code{Logical scalar}. Should the model metadata be +returned. (Default: \code{FALSE})} \item{verbose}{\code{Logical scalar}. Should execution messages be printed. (Default: \code{TRUE})} @@ -130,7 +131,7 @@ tse <- agglomerateByRank(tse, rank = "Phylum") tse$bmi_group <- as.numeric(tse$bmi_group) # Analyse mediated effect of nationality on BMI via alpha diversity -# 100 permutations were done to speed up execution, but ~1000 are recommended +# 100 permutations were done to speed up execution, but ~1000 are recommended med_df <- getMediation(tse, outcome = "bmi_group", treatment = "nationality", @@ -150,7 +151,7 @@ tse <- transformAssay(tse, pseudocount = 1) # Analyse mediated effect of nationality on BMI via clr-transformed features -# 100 permutations were done to speed up execution, but ~1000 are recommended +# 100 permutations were done to speed up execution, but ~1000 are recommended tse <- addMediation(tse, name = "assay_mediation", outcome = "bmi_group", treatment = "nationality", @@ -170,8 +171,8 @@ tse <- runMDS(tse, name = "MDS", assay.type = "clr", ncomponents = 3) -# Analyse mediated effect of nationality on BMI via NMDS components -# 100 permutations were done to speed up execution, but ~1000 are recommended +# Analyse mediated effect of nationality on BMI via NMDS components +# 100 permutations were done to speed up execution, but ~1000 are recommended tse <- addMediation(tse, name = "reddim_mediation", outcome = "bmi_group", treatment = "nationality", diff --git a/man/getPERMANOVA.Rd b/man/getPERMANOVA.Rd index 3544e58c6..3184aa511 100644 --- a/man/getPERMANOVA.Rd +++ b/man/getPERMANOVA.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/getPERMANOVA.R +% Please edit documentation in R/AllGenerics.R, R/getPERMANOVA.R \name{getPERMANOVA} \alias{getPERMANOVA} \alias{addPERMANOVA} diff --git a/man/getPrevalence.Rd b/man/getPrevalence.Rd index a7414df2f..c2ebad48d 100644 --- a/man/getPrevalence.Rd +++ b/man/getPrevalence.Rd @@ -1,28 +1,43 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/getPrevalence.R +% Please edit documentation in R/AllGenerics.R, R/getPrevalence.R \name{getPrevalence} \alias{getPrevalence} +\alias{getPrevalent} +\alias{getRare} +\alias{subsetByPrevalent} +\alias{subsetByRare} +\alias{getPrevalentAbundance} \alias{getPrevalence,ANY-method} \alias{getPrevalence,SummarizedExperiment-method} -\alias{getPrevalent} \alias{getPrevalent,ANY-method} \alias{getPrevalent,SummarizedExperiment-method} -\alias{getRare} \alias{getRare,ANY-method} \alias{getRare,SummarizedExperiment-method} -\alias{subsetByPrevalent} \alias{subsetByPrevalent,SummarizedExperiment-method} \alias{subsetByPrevalent,TreeSummarizedExperiment-method} -\alias{subsetByRare} \alias{subsetByRare,SummarizedExperiment-method} \alias{subsetByRare,TreeSummarizedExperiment-method} -\alias{getPrevalentAbundance} \alias{getPrevalentAbundance,ANY-method} \alias{getPrevalentAbundance,SummarizedExperiment-method} \title{Calculation prevalence information for features across samples} \usage{ getPrevalence(x, ...) +getPrevalent(x, ...) + +getRare(x, ...) + +subsetByPrevalent(x, ...) + +subsetByRare(x, ...) + +getPrevalentAbundance( + x, + assay.type = assay_name, + assay_name = "relabundance", + ... +) + \S4method{getPrevalence}{ANY}( x, detection = 0, @@ -41,8 +56,6 @@ getPrevalence(x, ...) ... ) -getPrevalent(x, ...) - \S4method{getPrevalent}{ANY}( x, prevalence = 50/100, @@ -60,8 +73,6 @@ getPrevalent(x, ...) ... ) -getRare(x, ...) - \S4method{getRare}{ANY}( x, prevalence = 50/100, @@ -79,25 +90,14 @@ getRare(x, ...) ... ) -subsetByPrevalent(x, ...) - \S4method{subsetByPrevalent}{SummarizedExperiment}(x, rank = NULL, ...) \S4method{subsetByPrevalent}{TreeSummarizedExperiment}(x, update.tree = FALSE, ...) -subsetByRare(x, ...) - \S4method{subsetByRare}{SummarizedExperiment}(x, rank = NULL, ...) \S4method{subsetByRare}{TreeSummarizedExperiment}(x, update.tree = FALSE, ...) -getPrevalentAbundance( - x, - assay.type = assay_name, - assay_name = "relabundance", - ... -) - \S4method{getPrevalentAbundance}{ANY}( x, assay.type = assay_name, @@ -124,6 +124,11 @@ and \code{subsetByRare} additional parameters passed to \code{getPrevalent} }} +\item{assay.type}{\code{Character scalar}. Specifies which assay to use for +calculation. (Default: \code{"counts"})} + +\item{assay_name}{Deprecated. Use \code{assay.type} instead.} + \item{detection}{\code{Numeric scalar}. Detection threshold for absence/presence. If \code{as_relative = FALSE}, it sets the counts threshold for a taxon to be considered present. @@ -141,11 +146,6 @@ detection and prevalence cutoffs be included? (Default: \code{FALSE})} \item{na.rm}{\code{Logical scalar}. Should NA values be omitted? (Default: \code{TRUE})} -\item{assay.type}{\code{Character scalar}. Specifies which assay to use for -calculation. (Default: \code{"counts"})} - -\item{assay_name}{Deprecated. Use \code{assay.type} instead.} - \item{rank}{\code{Character scalar}. Defines a taxonomic rank. Must be a value of \code{taxonomyRanks()} function.} diff --git a/man/hierarchy-tree.Rd b/man/hierarchy-tree.Rd index 68f873314..2b7fd8a8b 100644 --- a/man/hierarchy-tree.Rd +++ b/man/hierarchy-tree.Rd @@ -1,19 +1,19 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/taxonomy.R -\name{hierarchy-tree} -\alias{hierarchy-tree} +% Please edit documentation in R/AllGenerics.R, R/taxonomy.R +\name{getHierarchyTree} \alias{getHierarchyTree} -\alias{getHierarchyTree,SummarizedExperiment-method} \alias{addHierarchyTree} +\alias{hierarchy-tree} +\alias{getHierarchyTree,SummarizedExperiment-method} \alias{addHierarchyTree,SummarizedExperiment-method} \title{Calculate hierarchy tree} \usage{ getHierarchyTree(x, ...) -\S4method{getHierarchyTree}{SummarizedExperiment}(x, ...) - addHierarchyTree(x, ...) +\S4method{getHierarchyTree}{SummarizedExperiment}(x, ...) + \S4method{addHierarchyTree}{SummarizedExperiment}(x, ...) } \arguments{ diff --git a/man/importBIOM.Rd b/man/importBIOM.Rd index ed7da8d9f..ef2cf2bc4 100644 --- a/man/importBIOM.Rd +++ b/man/importBIOM.Rd @@ -1,13 +1,15 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/convertFromBIOM.R -\name{importBIOM} +% Please edit documentation in R/AllGenerics.R, R/convertFromBIOM.R +\name{convertToBIOM} +\alias{convertToBIOM} \alias{importBIOM} \alias{convertFromBIOM} -\alias{convertToBIOM} \alias{convertToBIOM,SummarizedExperiment-method} \title{Convert a \code{TreeSummarizedExperiment} object to/from \sQuote{BIOM} results} \usage{ +convertToBIOM(x, assay.type = "counts", ...) + importBIOM(file, ...) convertFromBIOM( @@ -21,16 +23,17 @@ convertFromBIOM( ... ) -convertToBIOM(x, assay.type = "counts", ...) - \S4method{convertToBIOM}{SummarizedExperiment}(x, assay.type = "counts", ...) } \arguments{ -\item{file}{BIOM file location} +\item{x}{\code{\link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment}}} + +\item{assay.type}{\code{Character scaler}. The name of assay. +(Default: \code{"counts"})} \item{...}{Additional arguments. Not used currently.} -\item{x}{\code{\link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment}}} +\item{file}{BIOM file location} \item{prefix.rm}{\code{Logical scalar}. Should taxonomic prefixes be removed? The prefixes is removed only from detected @@ -50,9 +53,6 @@ some taxonomic character naming artifacts, should they be removed. (default (Default: \code{FALSE})} \item{remove.artifacts}{Deprecated. Use \code{artifact.rm} instead.} - -\item{assay.type}{\code{Character scaler}. The name of assay. -(Default: \code{"counts"})} } \value{ \code{convertFromBIOM} returns an object of class diff --git a/man/importHUMAnN.Rd b/man/importHUMAnN.Rd index c40cca1b7..d60f75e38 100644 --- a/man/importHUMAnN.Rd +++ b/man/importHUMAnN.Rd @@ -16,9 +16,8 @@ path of the sample metadata file. The file must be in \code{tsv} format \item{...}{additional arguments: \itemize{ -\item \code{assay.type}: \code{Character scalar}. Specifies the name of the assy -used in calculation. -(Default: \code{"counts"}) +\item \code{assay.type}: \code{Character scalar}. Specifies the name of +the assay used in calculation. (Default: \code{"counts"}) \item \code{prefix.rm}: \code{Logical scalar}. Should taxonomic prefixes be removed? (Default: \code{FALSE}) \item \code{remove.suffix}: \code{Logical scalar}. Should diff --git a/man/importMetaPhlAn.Rd b/man/importMetaPhlAn.Rd index 6b192d43d..86187e671 100644 --- a/man/importMetaPhlAn.Rd +++ b/man/importMetaPhlAn.Rd @@ -24,8 +24,8 @@ path of the phylogenetic tree. \item{...}{additional arguments: \itemize{ -\item \code{assay.type}: \code{Character scalar}. Specifies the name of the assay -used in calculation. (Default: \code{"counts"}) +\item \code{assay.type}: \code{Character scalar}. Specifies the name of +the assay used in calculation. (Default: \code{"counts"}) \item \code{prefix.rm}: \code{Logical scalar}. Should taxonomic prefixes be removed? (Default: \code{FALSE}) \item \code{remove.suffix}: \code{Logical scalar}. Should @@ -78,9 +78,10 @@ altExp(tse, "phylum") } \references{ -Beghini F, McIver LJ, Blanco-Míguez A, Dubois L, Asnicar F, Maharjan S, Mailyan A, -Manghi P, Scholz M, Thomas AM, Valles-Colomer M, Weingart G, Zhang Y, Zolfo M, -Huttenhower C, Franzosa EA, & Segata N (2021) Integrating taxonomic, functional, +Beghini F, McIver LJ, Blanco-Míguez A, Dubois L, Asnicar F, Maharjan S, +Mailyan A, Manghi P, Scholz M, Thomas AM, Valles-Colomer M, Weingart G, +Zhang Y, Zolfo M, Huttenhower C, Franzosa EA, & Segata N (2021) +Integrating taxonomic, functional, and strain-level profiling of diverse microbial communities with bioBakery 3. \emph{eLife}. 10:e65088. doi: 10.7554/eLife.65088 } diff --git a/man/importMothur.Rd b/man/importMothur.Rd index 8c4b41df1..a02d04019 100644 --- a/man/importMothur.Rd +++ b/man/importMothur.Rd @@ -39,8 +39,8 @@ A object } \description{ -This method creates a \code{TreeSummarizedExperiment} object from \code{Mothur} -files provided as input. +This method creates a \code{TreeSummarizedExperiment} object from +\code{Mothur} files provided as input. } \details{ Results exported from Mothur can be imported as a @@ -52,7 +52,8 @@ Results exported from Mothur can be imported as a # Abundance table counts <- system.file("extdata", "mothur_example.shared", package = "mia") # Taxa table (in "cons.taxonomy" or "taxonomy" format) -taxa <- system.file("extdata", "mothur_example.cons.taxonomy", package = "mia") +taxa <- system.file( + "extdata", "mothur_example.cons.taxonomy", package = "mia") #taxa <- system.file("extdata", "mothur_example.taxonomy", package = "mia") # Sample meta data meta <- system.file("extdata", "mothur_example.design", package = "mia") diff --git a/man/importQIIME2.Rd b/man/importQIIME2.Rd index 0c1d89590..4cfe7f076 100644 --- a/man/importQIIME2.Rd +++ b/man/importQIIME2.Rd @@ -49,8 +49,8 @@ sequences will not be set.} \item{featureNamesAsRefSeq}{Deprecated. Use \code{as.refseq} instead.} -\item{refseq.file}{\code{Character scalar} or \code{NULL}. Defines the file path of -the reference sequences for each feature. (Default: \code{NULL}).} +\item{refseq.file}{\code{Character scalar} or \code{NULL}. Defines the file +path of the reference sequences for each feature. (Default: \code{NULL}).} \item{refSeqFile}{Deprecated. Use \code{refseq.file} instead.} @@ -74,8 +74,8 @@ table), \code{NewickDirectoryFormat} (phylogenetic tree ) and \code{DNASequencesDirectoryFormat} (representative sequences) are supported right now.} -\item{temp.dir}{character, a temporary directory in which the qza file will be -decompressed to, default \code{tempdir()}.} +\item{temp.dir}{character, a temporary directory in which the qza file will +be decompressed to, default \code{tempdir()}.} \item{temp}{Deprecated. Use \code{temp.dir} instead.} } @@ -136,7 +136,8 @@ coldata[, 1] <- NULL coldata <- coldata[match(colnames(assay), rownames(coldata)), ] # Create SE from individual files -se <- SummarizedExperiment(assays = list(assay), rowData = rowdata, colData = coldata) +se <- SummarizedExperiment( + assays = list(assay), rowData = rowdata, colData = coldata) se } diff --git a/man/importTaxpasta.Rd b/man/importTaxpasta.Rd index c3aaeb796..2ffe80a6e 100644 --- a/man/importTaxpasta.Rd +++ b/man/importTaxpasta.Rd @@ -22,7 +22,9 @@ taxonomy table be treated as taxonomy ranks? (Default: \code{FALSE}) }} } \value{ -A \code{\link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment}} object. +A +\code{\link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment}} +object. } \description{ Import taxpasta-specific BIOM results to diff --git a/man/isContaminant.Rd b/man/isContaminant.Rd index 14a1825e9..7eda678cd 100644 --- a/man/isContaminant.Rd +++ b/man/isContaminant.Rd @@ -1,15 +1,19 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/decontam.R -\name{isContaminant} +% Please edit documentation in R/AllGenerics.R, R/decontam.R +\name{addContaminantQC} +\alias{addContaminantQC} +\alias{addNotContaminantQC} \alias{isContaminant} \alias{isContaminant,SummarizedExperiment-method} \alias{isNotContaminant,SummarizedExperiment-method} -\alias{addContaminantQC} \alias{addContaminantQC,SummarizedExperiment-method} -\alias{addNotContaminantQC} \alias{addNotContaminantQC,SummarizedExperiment-method} \title{decontam functions} \usage{ +addContaminantQC(x, name = "isContaminant", ...) + +addNotContaminantQC(x, name = "isNotContaminant", ...) + \S4method{isContaminant}{SummarizedExperiment}( seqtab, assay.type = assay_name, @@ -36,25 +40,31 @@ ... ) -addContaminantQC(x, name = "isContaminant", ...) - \S4method{addContaminantQC}{SummarizedExperiment}(x, name = "isContaminant", ...) -addNotContaminantQC(x, name = "isNotContaminant", ...) - \S4method{addNotContaminantQC}{SummarizedExperiment}(x, name = "isNotContaminant", ...) } \arguments{ -\item{seqtab, x}{a \code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}}} +\item{name}{\code{Character scalar}. A name for the column of the +\code{colData} where results will be stored. +(Default: \code{"isContaminant"})} + +\item{...}{\itemize{ +\item for \code{isContaminant}/ \code{isNotContaminant}: arguments +passed on to \code{\link[decontam:isContaminant]{decontam:isContaminant}} +or \code{\link[decontam:isNotContaminant]{decontam:isNotContaminant}} +\item for \code{addContaminantQC}/\code{addNotContaminantQC}: arguments +passed on to \code{isContaminant}/ \code{isNotContaminant} +}} + +\item{seqtab, x}{a +\code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}}} \item{assay.type}{\code{Character scalar}. Specifies which assay to use for calculation. (Default: \code{"counts"})} \item{assay_name}{Deprecated. Use \code{assay.type} instead.} -\item{name}{\code{Character scalar}. A name for the column of the -\code{colData} where results will be stored. (Default: \code{"isContaminant"})} - \item{concentration}{\code{Character scalar} or \code{NULL}. Defining a column with numeric values from the \code{colData} to use as concentration information. (Default: \code{NULL})} @@ -79,14 +89,6 @@ as batch information. (Default: \code{NULL})} data.frame containing diagnostic information on the contaminant decision. If FALSE, the return value is a logical vector containing the binary contaminant classifications. (Default: \code{TRUE})} - -\item{...}{\itemize{ -\item for \code{isContaminant}/ \code{isNotContaminant}: arguments -passed on to \code{\link[decontam:isContaminant]{decontam:isContaminant}} -or \code{\link[decontam:isNotContaminant]{decontam:isNotContaminant}} -\item for \code{addContaminantQC}/\code{addNotContaminantQC}: arguments -passed on to \code{isContaminant}/ \code{isNotContaminant} -}} } \value{ for \code{isContaminant}/ \code{isNotContaminant} a \code{DataFrame} diff --git a/man/meltSE.Rd b/man/meltSE.Rd index fedabd56d..28aa29f5e 100644 --- a/man/meltSE.Rd +++ b/man/meltSE.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/meltAssay.R +% Please edit documentation in R/AllGenerics.R, R/meltAssay.R \name{meltSE} \alias{meltSE} \alias{meltSE,SummarizedExperiment-method} diff --git a/man/mergeSEs.Rd b/man/mergeSEs.Rd index 5b76bd0b6..3102f7820 100644 --- a/man/mergeSEs.Rd +++ b/man/mergeSEs.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/mergeSEs.R +% Please edit documentation in R/AllGenerics.R, R/mergeSEs.R \name{mergeSEs} \alias{mergeSEs} \alias{mergeSEs,SimpleList-method} @@ -38,22 +38,24 @@ calculation. (Default: \code{"counts"})} \item{assay_name}{Deprecated. Use \code{assay.type} instead.} -\item{join}{\code{Character scalar}. A value for selecting the joining method. -Must be 'full', 'inner', 'left', or 'right'. 'left' and 'right' are disabled -when more than two objects are being merged. (Default: \code{"full"})} +\item{join}{\code{Character scalar}. A value for selecting the joining +method. Must be 'full', 'inner', 'left', or 'right'. 'left' and 'right' are +disabled when more than two objects are being merged. +(Default: \code{"full"})} -\item{missing.values}{\code{NA}, \code{0} or \code{Character scalar}. Specifies the notation -of missing values. (By default: \code{NA})} +\item{missing.values}{\code{NA}, \code{0} or \code{Character scalar}. +Specifies the notation of missing values. (By default: \code{NA})} \item{missing_values}{Deprecated. Use \code{missing.values} instead.} -\item{collapse.cols}{\code{Logical scalar}. Determines whether to collapse identically -named samples to one. (Default: \code{FALSE})} +\item{collapse.cols}{\code{Logical scalar}. Determines whether to collapse +identically named samples to one. (Default: \code{FALSE})} \item{collapse_samples}{Deprecated. Use \code{collapse.cols} instead.} -\item{collapse.rows}{\code{Logical scalar}. Selects whether to collapse identically -named features to one. Since all taxonomy information is taken into account, +\item{collapse.rows}{\code{Logical scalar}. Selects whether to collapse +identically named features to one. Since all taxonomy information is +taken into account, this concerns rownames-level (usually strain level) comparison. Often OTU or ASV level is just an arbitrary number series from sequencing machine meaning that the OTU information is not comparable between studies. With this @@ -76,9 +78,11 @@ A single \code{SummarizedExperiment} object. Merge SE objects into single SE object. } \details{ -This function merges multiple \code{SummarizedExperiment} objects. It combines +This function merges multiple \code{SummarizedExperiment} objects. It +combines \code{rowData}, \code{assays}, and \code{colData} so that the output includes -each unique row and column ones. The merging is done based on \code{rownames} and +each unique row and column ones. The merging is done based on +\code{rownames} and \code{colnames}. \code{rowTree} and \code{colTree} are preserved if linkage between rows/cols and the tree is found. @@ -90,9 +94,12 @@ with \code{collapse.cols = TRUE} when equally named samples describe the same sample. If, for example, all rows are not shared with -individual objects, there are missing values in \code{assays}. The notation of missing -can be specified with the \code{missing.values} argument. If input consists of -\code{TreeSummarizedExperiment} objects, also \code{rowTree}, \code{colTree}, and +individual objects, there are missing values in \code{assays}. +The notation of missing +can be specified with the \code{missing.values} argument. If input consists +of +\code{TreeSummarizedExperiment} objects, also \code{rowTree}, \code{colTree}, +and \code{referenceSeq} are preserved if possible. The data is preserved if all the rows or columns can be found from it. @@ -102,7 +109,8 @@ that rows and columns are matching, respectively. You can choose joining methods from \code{'full'}, \code{'inner'}, \code{'left'}, and \code{'right'}. In all the methods, all the samples are -included in the result object. However, with different methods, it is possible +included in the result object. However, with different methods, it is +possible to choose which rows are included. \itemize{ @@ -112,8 +120,10 @@ to choose which rows are included. \item{\code{right} -- all the features of the second object} } -The output depends on the input. If the input contains \code{SummarizedExperiment} -object, then the output will be \code{SummarizedExperiment}. When all the input +The output depends on the input. If the input contains +\code{SummarizedExperiment} +object, then the output will be \code{SummarizedExperiment}. When all the +input objects belong to \code{TreeSummarizedExperiment}, the output will be \code{TreeSummarizedExperiment}. } diff --git a/man/peerj13075.Rd b/man/peerj13075.Rd index de905c2a3..f1658c823 100644 --- a/man/peerj13075.Rd +++ b/man/peerj13075.Rd @@ -31,9 +31,11 @@ association of skin microbiota with individual’s geographical location. } \references{ Potbhare, R., RaviKumar, A., Munukka, E., Lahti, L., & Ashma, R. (2022). -Skin microbiota diversity among genetically unrelated individuals of Indian origin. +Skin microbiota diversity among genetically unrelated individuals of Indian +origin. PeerJ, 10, e13075. \url{https://doi.org/10.7717/peerj.13075} -Supplemental information includes OTU table and taxonomy table publicly-accessible from: +Supplemental information includes OTU table and taxonomy table +publicly-accessible from: \url{https://www.doi.org/10.7717/peerj.13075/supp-1} \url{https://www.doi.org/10.7717/peerj.13075/supp-2} } diff --git a/man/rarefyAssay.Rd b/man/rarefyAssay.Rd index 5ffb2a3bc..4f973ec87 100644 --- a/man/rarefyAssay.Rd +++ b/man/rarefyAssay.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/rarefyAssay.R +% Please edit documentation in R/AllGenerics.R, R/rarefyAssay.R \name{rarefyAssay} \alias{rarefyAssay} \alias{rarefyAssay,SummarizedExperiment-method} @@ -80,9 +80,9 @@ To maintain the reproducibility, please define the seed using set.seed() before implement this function. } \examples{ -# When samples in TreeSE are less than specified sample, they will be removed. -# If after subsampling features are not present in any of the samples, -# they will be removed. +# When samples in TreeSE are less than specified sample, they will be +# removed. If after subsampling features are not present in any of the +# samples, they will be removed. data(GlobalPatterns) tse <- GlobalPatterns set.seed(123) diff --git a/man/runCCA.Rd b/man/runCCA.Rd index 1fd0057f2..4f7ae0511 100644 --- a/man/runCCA.Rd +++ b/man/runCCA.Rd @@ -1,11 +1,11 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/runCCA.R -\name{runCCA} -\alias{runCCA} +% Please edit documentation in R/AllGenerics.R, R/runCCA.R +\name{getCCA} \alias{getCCA} \alias{addCCA} \alias{getRDA} \alias{addRDA} +\alias{runCCA} \alias{calculateCCA} \alias{getCCA,ANY-method} \alias{getCCA,SummarizedExperiment-method} diff --git a/man/runDPCoA.Rd b/man/runDPCoA.Rd index e74e92259..b23ba0b89 100644 --- a/man/runDPCoA.Rd +++ b/man/runDPCoA.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/runDPCoA.R -\name{runDPCoA} -\alias{runDPCoA} +% Please edit documentation in R/AllGenerics.R, R/runDPCoA.R +\name{getDPCoA} \alias{getDPCoA} +\alias{runDPCoA} \alias{getDPCoA,ANY,ANY-method} \alias{getDPCoA,TreeSummarizedExperiment,missing-method} \alias{calculateDPCoA} @@ -47,21 +47,22 @@ runDPCoA(x, ...) \item{...}{Currently not used.} -\item{ncomponents}{\code{Numeric scalar}. Indicates the number of DPCoA dimensions -to obtain. (Default: \code{2})} +\item{ncomponents}{\code{Numeric scalar}. Indicates the number of DPCoA +dimensions to obtain. (Default: \code{2})} -\item{ntop}{\code{Numeric scalar}. Specifies the number of features with the highest -variances to use for dimensionality reduction. Alternatively \code{NULL}, -if all features should be used. (Default: \code{NULL})} +\item{ntop}{\code{Numeric scalar}. Specifies the number of features with the +highest variances to use for dimensionality reduction. Alternatively +\code{NULL}, if all features should be used. (Default: \code{NULL})} -\item{subset.row}{\code{Character Vector}. Specifies the subset of features to use for -dimensionality reduction. This can be a character vector of row names, an -integer vector of row indices or a logical vector. (Default: \code{NULL})} +\item{subset.row}{\code{Character Vector}. Specifies the subset of features +to use for dimensionality reduction. This can be a character vector of row +names, an integer vector of row indices or a logical vector. +(Default: \code{NULL})} \item{subset_row}{Deprecated. Use \code{subset.row} instead.} -\item{scale}{\code{Logical scalar}. Should the expression values be standardized? -(Default: \code{FALSE})} +\item{scale}{\code{Logical scalar}. Should the expression values be +standardized? (Default: \code{FALSE})} \item{transposed}{\code{Logical scalar}. Specifies if x is transposed with cells in rows. (Default: \code{FALSE})} diff --git a/man/runNMDS.Rd b/man/runNMDS.Rd index 5bc68600d..8c8689b16 100644 --- a/man/runNMDS.Rd +++ b/man/runNMDS.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/runNMDS.R -\name{runNMDS} -\alias{runNMDS} +% Please edit documentation in R/AllGenerics.R, R/runNMDS.R +\name{getNMDS} \alias{getNMDS} +\alias{runNMDS} \alias{getNMDS,ANY-method} \alias{getNMDS,SummarizedExperiment-method} \alias{getNMDS,SingleCellExperiment-method} @@ -61,8 +61,8 @@ runNMDS(x, ...) \item{...}{additional arguments to pass to \code{FUN} and \code{nmds.fun}.} -\item{FUN}{\code{Function} or \code{Character scalar}. A value with a function -name returning a \code{\link[stats:dist]{dist}} object} +\item{FUN}{\code{Function} or \code{Character scalar}. A value with a +function name returning a \code{\link[stats:dist]{dist}} object} \item{nmds.fun}{\code{Character scalar}. A value to choose the scaling implementation, either \dQuote{isoMDS} for @@ -71,28 +71,29 @@ implementation, either \dQuote{isoMDS} for \item{nmdsFUN}{Deprecated. Use \code{nmds.fun} instead.} -\item{ncomponents}{\code{Numeric scalar}. Indicates the number of DPCoA dimensions -to obtain. (Default: \code{2})} +\item{ncomponents}{\code{Numeric scalar}. Indicates the number of DPCoA +dimensions to obtain. (Default: \code{2})} -\item{ntop}{\code{Numeric scalar}. Specifies the number of features with the highest -variances to use for dimensionality reduction. Alternatively \code{NULL}, -if all features should be used. (Default: \code{NULL})} +\item{ntop}{\code{Numeric scalar}. Specifies the number of features with the +highest variances to use for dimensionality reduction. Alternatively +\code{NULL}, if all features should be used. (Default: \code{NULL})} -\item{subset.row}{\code{Character Vector}. Specifies the subset of features to use for -dimensionality reduction. This can be a character vector of row names, an -integer vector of row indices or a logical vector. (Default: \code{NULL})} +\item{subset.row}{\code{Character Vector}. Specifies the subset of features +to use for dimensionality reduction. This can be a character vector of row +names, an integer vector of row indices or a logical vector. +(Default: \code{NULL})} \item{subset_row}{Deprecated. Use \code{subset.row} instead.} -\item{scale}{\code{Logical scalar}. Should the expression values be standardized? -(Default: \code{FALSE})} +\item{scale}{\code{Logical scalar}. Should the expression values be +standardized? (Default: \code{FALSE})} \item{transposed}{\code{Logical scalar}. Specifies if x is transposed with cells in rows. (Default: \code{FALSE})} -\item{keep.dist}{\code{Logical scalar}. Indicates whether the \code{dist} object -calculated by \code{FUN} should be stored as \sQuote{dist} attribute of -the matrix returned/stored by \code{getNMDS}/ \code{addNMDS}. (Default: +\item{keep.dist}{\code{Logical scalar}. Indicates whether the \code{dist} +object calculated by \code{FUN} should be stored as \sQuote{dist} attribute +of the matrix returned/stored by \code{getNMDS}/ \code{addNMDS}. (Default: \code{FALSE})} \item{keep_dist}{Deprecated. Use \code{keep.dist} instead.} @@ -104,8 +105,8 @@ calculation. (Default: \code{"counts"})} \item{exprs_values}{Deprecated. Use \code{assay.type} instead.} -\item{dimred}{\code{Character scalar} or \code{integer scalar}. Specifies the existing dimensionality -reduction results to use.} +\item{dimred}{\code{Character scalar} or \code{integer scalar}. Specifies +the existing dimensionality reduction results to use.} \item{ndimred}{\code{integer vector}. Specifies the dimensions to use if dimred is specified.} diff --git a/man/splitOn.Rd b/man/splitOn.Rd index dc4deceae..f44156dfb 100644 --- a/man/splitOn.Rd +++ b/man/splitOn.Rd @@ -1,11 +1,11 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/splitOn.R +% Please edit documentation in R/AllGenerics.R, R/splitOn.R \name{splitOn} \alias{splitOn} +\alias{unsplitOn} \alias{splitOn,SummarizedExperiment-method} \alias{splitOn,SingleCellExperiment-method} \alias{splitOn,TreeSummarizedExperiment-method} -\alias{unsplitOn} \alias{unsplitOn,list-method} \alias{unsplitOn,SimpleList-method} \alias{unsplitOn,SingleCellExperiment-method} @@ -14,6 +14,8 @@ grouping variable} \usage{ splitOn(x, ...) +unsplitOn(x, ...) + \S4method{splitOn}{SummarizedExperiment}(x, group = f, f = NULL, ...) \S4method{splitOn}{SingleCellExperiment}(x, group = f, f = NULL, ...) @@ -27,8 +29,6 @@ splitOn(x, ...) ... ) -unsplitOn(x, ...) - \S4method{unsplitOn}{list}(x, update.tree = update_rowTree, update_rowTree = FALSE, ...) \S4method{unsplitOn}{SimpleList}(x, update.tree = update_rowTree, update_rowTree = FALSE, ...) diff --git a/man/summaries.Rd b/man/summary.Rd similarity index 88% rename from man/summaries.Rd rename to man/summary.Rd index 7874cd78a..74857c894 100644 --- a/man/summaries.Rd +++ b/man/summary.Rd @@ -1,16 +1,20 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/summaries.R -\name{summaries} -\alias{summaries} +% Please edit documentation in R/AllGenerics.R, R/summaries.R +\name{summarizeDominance} +\alias{summarizeDominance} +\alias{getUnique} \alias{getTop} +\alias{summary} \alias{getTop,SummarizedExperiment-method} -\alias{getUnique} \alias{getUnique,SummarizedExperiment-method} -\alias{summarizeDominance} \alias{summarizeDominance,SummarizedExperiment-method} \alias{summary,SummarizedExperiment-method} \title{Summarizing microbiome data} \usage{ +summarizeDominance(x, group = NULL, name = "dominant_taxa", ...) + +getUnique(x, ...) + getTop( x, top = 5L, @@ -31,12 +35,8 @@ getTop( ... ) -getUnique(x, ...) - \S4method{getUnique}{SummarizedExperiment}(x, rank = NULL, ...) -summarizeDominance(x, group = NULL, name = "dominant_taxa", ...) - \S4method{summarizeDominance}{SummarizedExperiment}(x, group = NULL, name = "dominant_taxa", ...) \S4method{summary}{SummarizedExperiment}(object, assay.type = assay_name, assay_name = "counts") @@ -44,11 +44,21 @@ summarizeDominance(x, group = NULL, name = "dominant_taxa", ...) \arguments{ \item{x}{\code{\link[TreeSummarizedExperiment:TreeSummarizedExperiment-class]{TreeSummarizedExperiment}}.} -\item{top}{\code{Numeric scalar}. Determines how many top taxa to return. Default is -to return top five taxa. (Default: \code{5})} +\item{group}{With group, it is possible to group the observations in an +overview. Must be one of the column names of \code{colData}.} + +\item{name}{\code{Character scalar}. A name for the column of the +\code{colData} where results will be stored. +(Default: \code{"dominant_taxa"})} + +\item{...}{Additional arguments passed on to \code{agglomerateByRank()} when +\code{rank} is specified for \code{summarizeDominance}.} -\item{method}{\code{Character scalar}. Specify the method to determine top taxa. Either -sum, mean, median or prevalence. (Default: \code{"mean"})} +\item{top}{\code{Numeric scalar}. Determines how many top taxa to return. +Default is to return top five taxa. (Default: \code{5})} + +\item{method}{\code{Character scalar}. Specify the method to determine top +taxa. Either sum, mean, median or prevalence. (Default: \code{"mean"})} \item{assay.type}{\code{Character scalar}. Specifies the name of the assay used in calculation. (Default: \code{"counts"})} @@ -58,20 +68,12 @@ assay used in calculation. (Default: \code{"counts"})} \item{na.rm}{\code{Logical scalar}. Should NA values be omitted? (Default: \code{TRUE})} -\item{...}{Additional arguments passed on to \code{agglomerateByRank()} when -\code{rank} is specified for \code{summarizeDominance}.} - -\item{rank}{\code{Character scalar}. Defines a taxonomic rank. Must be a value of -the output of \code{taxonomyRanks()}. (Default: \code{NULl})} - -\item{group}{With group, it is possible to group the observations in an -overview. Must be one of the column names of \code{colData}.} - -\item{name}{\code{Character scalar}. A name for the column of the -\code{colData} where results will be stored. (Default: \code{"dominant_taxa"})} +\item{rank}{\code{Character scalar}. Defines a taxonomic rank. Must be a +value of the output of \code{taxonomyRanks()}. (Default: \code{NULl})} \item{object}{A -\code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}} object.} +\code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}} +object.} } \value{ The \code{getTop} returns a vector of the most \code{top} abundant @@ -80,8 +82,9 @@ The \code{getTop} returns a vector of the most \code{top} abundant The \code{getUnique} returns a vector of unique taxa present at a particular rank -The \code{summarizeDominance} returns an overview in a tibble. It contains dominant taxa -in a column named \code{*name*} and its abundance in the data set. +The \code{summarizeDominance} returns an overview in a tibble. It contains +dominant taxa in a column named \code{*name*} and its abundance in the data +set. The \code{summary} returns a list with two \code{tibble}s } @@ -91,7 +94,8 @@ functions are available. } \details{ The \code{getTop} extracts the most \code{top} abundant \dQuote{FeatureID}s -in a \code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}} +in a +\code{\link[SummarizedExperiment:SummarizedExperiment-class]{SummarizedExperiment}} object. The \code{getUnique} is a basic function to access different taxa at a diff --git a/man/taxonomy-methods.Rd b/man/taxonomy-methods.Rd index 3617c6e2b..6b10c0f33 100644 --- a/man/taxonomy-methods.Rd +++ b/man/taxonomy-methods.Rd @@ -1,48 +1,50 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/taxonomy.R -\name{taxonomy-methods} -\alias{taxonomy-methods} +% Please edit documentation in R/AllGenerics.R, R/taxonomy.R +\name{taxonomyRanks} \alias{taxonomyRanks} -\alias{taxonomyRanks,SummarizedExperiment-method} \alias{taxonomyRankEmpty} -\alias{taxonomyRankEmpty,SummarizedExperiment-method} \alias{checkTaxonomy} +\alias{getTaxonomyLabels} +\alias{mapTaxonomy} +\alias{taxonomy-methods} +\alias{taxonomyRanks,SummarizedExperiment-method} +\alias{taxonomyRankEmpty,SummarizedExperiment-method} \alias{checkTaxonomy,SummarizedExperiment-method} \alias{setTaxonomyRanks} \alias{getTaxonomyRanks} -\alias{getTaxonomyLabels} \alias{getTaxonomyLabels,SummarizedExperiment-method} -\alias{mapTaxonomy} \alias{mapTaxonomy,SummarizedExperiment-method} \alias{IdTaxaToDataFrame} \title{Functions for accessing taxonomic data stored in \code{rowData}.} \usage{ taxonomyRanks(x) -\S4method{taxonomyRanks}{SummarizedExperiment}(x) - taxonomyRankEmpty( x, rank = taxonomyRanks(x)[1L], empty.fields = c(NA, "", " ", "\\t", "-", "_") ) +checkTaxonomy(x, ...) + +getTaxonomyLabels(x, ...) + +mapTaxonomy(x, ...) + +\S4method{taxonomyRanks}{SummarizedExperiment}(x) + \S4method{taxonomyRankEmpty}{SummarizedExperiment}( x, rank = taxonomyRanks(x)[1], empty.fields = c(NA, "", " ", "\\t", "-", "_") ) -checkTaxonomy(x, ...) - \S4method{checkTaxonomy}{SummarizedExperiment}(x) setTaxonomyRanks(ranks) getTaxonomyRanks() -getTaxonomyLabels(x, ...) - \S4method{getTaxonomyLabels}{SummarizedExperiment}( x, empty.fields = c(NA, "", " ", "\\t", "-", "_"), @@ -55,8 +57,6 @@ getTaxonomyLabels(x, ...) ... ) -mapTaxonomy(x, ...) - \S4method{mapTaxonomy}{SummarizedExperiment}( x, taxa = NULL, diff --git a/man/transformAssay.Rd b/man/transformAssay.Rd index 3e50dec52..5f38cbf75 100644 --- a/man/transformAssay.Rd +++ b/man/transformAssay.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/transformCounts.R +% Please edit documentation in R/AllGenerics.R, R/transformCounts.R \name{transformAssay} \alias{transformAssay} \alias{transformAssay,SummarizedExperiment-method} diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index c5521f7b5..66733cd87 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -41,7 +41,7 @@ reference: - contents: - getPrevalence - getPrevalentAbundance - - summaries + - summary - getDominant - title: Data loading - contents: From 59f7ac2208cda9a8276067562b723c29391f87f7 Mon Sep 17 00:00:00 2001 From: TuomasBorman Date: Sat, 7 Dec 2024 21:52:21 +0200 Subject: [PATCH 4/9] up --- R/convertToPhyloseq.R | 4 ++-- R/estimateDiversity.R | 3 +-- R/getCrossAssociation.R | 14 +++++++------- R/importHumann.R | 4 ++-- R/importMetaphlan.R | 8 ++++---- R/mediate.R | 7 ++++--- R/utils.R | 2 +- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/R/convertToPhyloseq.R b/R/convertToPhyloseq.R index bceec92fa..b10104aa2 100644 --- a/R/convertToPhyloseq.R +++ b/R/convertToPhyloseq.R @@ -78,7 +78,7 @@ setMethod("convertToPhyloseq", signature = c(x = "SummarizedExperiment"), rownames(x) <- getTaxonomyLabels(x) } # List of arguments - args = list() + args <- list() # Gets the abundance data from assay, and converts it to otu_table otu_table <- as.matrix(assay(x, assay.type)) otu_table <- phyloseq::otu_table(otu_table, taxa_are_rows = TRUE) @@ -138,7 +138,7 @@ setMethod("convertToPhyloseq", signature = c(x = "TreeSummarizedExperiment"), # and/or sample_data obj <- callNextMethod() # List of arguments - args = list() + args <- list() # Adds to the list of arguments, if 'obj' is not a phyloseq object # i.e. is an otu_table if(!is(obj,"phyloseq")){ diff --git a/R/estimateDiversity.R b/R/estimateDiversity.R index 5d000d4c7..b15a430c9 100644 --- a/R/estimateDiversity.R +++ b/R/estimateDiversity.R @@ -248,8 +248,7 @@ NULL index_string <- paste0( "'", paste0(supported_index, collapse = "', '"), "'") if ( !all(index %in% supported_index) || !(length(index) > 0)) { - stop("'", paste0( - "'index' must be from the following options: '", index_string), + stop("'index' must be from the following options: '", index_string, "'", call. = FALSE) } # Check name diff --git a/R/getCrossAssociation.R b/R/getCrossAssociation.R index 1c32a8b11..3e6550601 100644 --- a/R/getCrossAssociation.R +++ b/R/getCrossAssociation.R @@ -960,7 +960,7 @@ setMethod("getCrossAssociation", signature = "SummarizedExperiment", else if( ncol(correlations_and_p_values) == 2 ){ colnames(correlations_and_p_values) <- c("cor", "pval") } else{ - stop("Unexpected error occurred during calculation.",call. = FALSE) + stop("Unexpected problem occurred during calculation.", call. = FALSE) } # If assays were identical, and duplicate variable pairs were dropped @@ -1130,9 +1130,9 @@ setMethod("getCrossAssociation", signature = "SummarizedExperiment", do.call(association.fun, args = c(list(feature_mat), list(...))) }, error = function(cond) { - stop("Error occurred during calculation. Check, e.g., that ", + stop("Something went wrong during calculation. Check, e.g., that ", "'association.fun' fulfills requirements. 'association.fun' ", - "threw a following error:\n", cond, + "threw a following message:\n", cond, call. = FALSE) }) } else { @@ -1141,9 +1141,9 @@ setMethod("getCrossAssociation", signature = "SummarizedExperiment", association.fun, args = c(list(feature_mat), list(...))) ) }, error = function(cond) { - stop("Error occurred during calculation. Check, e.g., that ", + stop("Something went wrong during calculation. Check, e.g., that ", "'association.fun' fulfills requirements. 'association.fun' ", - "threw a following error:\n", cond, call. = FALSE) + "threw a following message:\n", cond, call. = FALSE) }) } @@ -1263,7 +1263,7 @@ setMethod("getCrossAssociation", signature = "SummarizedExperiment", t(tmp), use="pairwise.complete.obs")))$order }, error = function(cond) { - stop("Error occurred during sorting. Possible reason is that ", + stop("Something went wrong during sorting. Possible reason is that ", "correlation matrix includes NAs. Try with 'sort = FALSE'.", call. = FALSE) } @@ -1273,7 +1273,7 @@ setMethod("getCrossAssociation", signature = "SummarizedExperiment", tmp, use="pairwise.complete.obs")))$order }, error = function(cond) { - stop("Error occurred during sorting. Possible reason is that ", + stop("Something went wrong during sorting. Possible reason is that ", "correlation matrix includes NAs. Try with 'sort = FALSE'.", call. = FALSE) } diff --git a/R/importHumann.R b/R/importHumann.R index 92c88703c..e008d2a28 100644 --- a/R/importHumann.R +++ b/R/importHumann.R @@ -114,7 +114,7 @@ importHUMAnN <- function(file, col.data = colData, colData = NULL, ...){ read.delim(file, check.names = FALSE) }, error = function(condition){ - stop("Error while reading ", file, + stop("Cannot read the file: ", file, "\nPlease check that the file is in merged HUMAnN file ", "format.", call. = FALSE) } @@ -131,7 +131,7 @@ importHUMAnN <- function(file, col.data = colData, colData = NULL, ...){ rownames(table) <- table[, 1] # Check that file is in right format if( .check_metaphlan(table, rowdata_col) ){ - stop("Error while reading ", file, + stop("Cannot read the file: ", file, "\nPlease check that the file is in merged HUMAnN file format.", call. = FALSE) } diff --git a/R/importMetaphlan.R b/R/importMetaphlan.R index 2945bff62..0e4259895 100644 --- a/R/importMetaphlan.R +++ b/R/importMetaphlan.R @@ -172,14 +172,14 @@ importMetaPhlAn <- function( file, header = TRUE, comment.char = "#", check.names = FALSE) }, error = function(condition){ - stop("Error while reading ", file, + stop("Cannot read the file: ", file, "\nPlease check that the file is in merged Metaphlan file ", "format.", call. = FALSE) } ) # Check that file is in right format if( .check_metaphlan(table, rowdata_col) ){ - stop("Error while reading ", file, + stop("Cannot read the file: ", file, "\nPlease check that the file is in merged Metaphlan file format.", call. = FALSE) } @@ -216,7 +216,7 @@ importMetaPhlAn <- function( # ID in Metaphlan v2, > 2 clade_name col <- colnames(table) %in% c("clade_name", "ID") if( sum(col) != 1 ){ - stop("Error in parsing Metaphlan file.", call. = FALSE) + stop("Cannot parse Metaphlan file.", call. = FALSE) } # Get the lowest level of each row @@ -227,7 +227,7 @@ importMetaPhlAn <- function( # at specific rank tables <- split(table, levels) # Get the order - metaphlan_tax = names(.taxonomy_rank_prefixes) + metaphlan_tax <- names(.taxonomy_rank_prefixes) indices <- match(tolower(metaphlan_tax), tolower(names(tables))) # Remove NAs which occurs if rank is not included indices <- indices[!is.na(indices)] diff --git a/R/mediate.R b/R/mediate.R index 44f8aab02..299f8dad9 100644 --- a/R/mediate.R +++ b/R/mediate.R @@ -266,7 +266,7 @@ setMethod("getMediation", signature = c(x = "SummarizedExperiment"), } # Run mediation analysis for current mediator - med_out <- .run.mediate( + med_out <- .run_mediate( x, outcome, treatment, mediator, family = family, mat = mat, covariates = covariates, ... @@ -312,7 +312,8 @@ setMethod("getMediation", signature = c(x = "SummarizedExperiment"), length(unique((df[[treatment]]))) > 2 ) { ## if control and treat value are not specified - if( any(sapply(kwargs[c("control.value", "treat.value")], is.null)) ){ + if( any(vapply(kwargs[c("control.value", "treat.value")], + is.null, logical(1))) ){ stop( "Too many treatment levels. Consider specifing a treat.value ", "and a control.value", call. = FALSE @@ -351,7 +352,7 @@ setMethod("getMediation", signature = c(x = "SummarizedExperiment"), # Run mediation analysis #' @importFrom mediation mediate #' @importFrom stats lm formula glm -.run.mediate <- function(x, outcome, treatment, mediator = NULL, mat = NULL, +.run_mediate <- function(x, outcome, treatment, mediator = NULL, mat = NULL, family = gaussian(), covariates = NULL, ...) { # Create initial dataframe with outcome and treatment variables diff --git a/R/utils.R b/R/utils.R index a4f17df0a..f739b7ba3 100644 --- a/R/utils.R +++ b/R/utils.R @@ -505,7 +505,7 @@ taxa_split <- taxa_split[taxa_prefixes_match] # if(length(unique(lengths(taxa_split))) != 1L){ - stop("Internal error. Something went wrong while splitting taxonomic ", + stop("Something went wrong while splitting taxonomic ", "levels. Please check that 'sep' is correct.", call. = FALSE) } taxa_tab <- DataFrame(as.matrix(taxa_split)) From 1a6a7aba8c3d79c51fcc8aec3091ee7dc50fd23c Mon Sep 17 00:00:00 2001 From: TuomasBorman Date: Sat, 7 Dec 2024 22:14:19 +0200 Subject: [PATCH 5/9] up --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 48466d6ae..0c8b0f452 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: mia Type: Package -Version: 1.15.6 +Version: 1.15.7 Authors@R: c(person(given = "Tuomas", family = "Borman", role = c("aut", "cre"), email = "tuomas.v.borman@utu.fi", From ea6c4f585fb0095327e61015cd59da8ecb03d25f Mon Sep 17 00:00:00 2001 From: TuomasBorman Date: Sat, 7 Dec 2024 22:16:39 +0200 Subject: [PATCH 6/9] up --- R/AllGenerics.R | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/R/AllGenerics.R b/R/AllGenerics.R index 43bb89ac0..7103d0a47 100644 --- a/R/AllGenerics.R +++ b/R/AllGenerics.R @@ -346,13 +346,11 @@ setGeneric("getBestDMNFit", signature = "x", standardGeneric("getBestDMNFit")) NULL -setGeneric( - ".estimate_dominance", signature = c("x"), +setGeneric(".estimate_dominance", signature = c("x"), function(x, ...) standardGeneric(".estimate_dominance")) NULL -setGeneric( - ".estimate_dominance",signature = c("x"), +setGeneric(".estimate_dominance",signature = c("x"), function( x, assay.type = assay_name, assay_name = "counts", index = c( From 447073754f4318e3af56103a51f906b6aaf457bb Mon Sep 17 00:00:00 2001 From: TuomasBorman Date: Sun, 8 Dec 2024 06:57:12 +0200 Subject: [PATCH 7/9] up --- R/convertFromPhyloseq.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/convertFromPhyloseq.R b/R/convertFromPhyloseq.R index 744e3383f..d435608ed 100644 --- a/R/convertFromPhyloseq.R +++ b/R/convertFromPhyloseq.R @@ -48,13 +48,13 @@ convertFromPhyloseq <- function(x) { rowData <- tryCatch(phyloseq::tax_table(x), error = function(e) NULL) |> data.frame() |> DataFrame() - if( is.null(rowData) ){ + if( nrow(rowData) == 0L ){ rowData <- S4Vectors::make_zero_col_DFrame(nrow(assays$counts)) rownames(rowData) <- rownames(assays$counts) } colData <- tryCatch(phyloseq::sample_data(x), error = function(e) NULL) |> data.frame() |> DataFrame() - if( is.null(colData) ){ + if( nrow(colData) == 0L ){ colData <- S4Vectors::make_zero_col_DFrame(ncol(assays$counts)) rownames(colData) <- colnames(assays$counts) } From 11dd88001e67e6ee4f3577dba77ab3073b555d2f Mon Sep 17 00:00:00 2001 From: TuomasBorman Date: Wed, 15 Jan 2025 09:44:53 +0200 Subject: [PATCH 8/9] up --- R/AllGenerics.R | 2 +- R/summaries.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/AllGenerics.R b/R/AllGenerics.R index 7103d0a47..1df43adbe 100644 --- a/R/AllGenerics.R +++ b/R/AllGenerics.R @@ -271,7 +271,7 @@ setGeneric("getUnique", signature = c("x"), function(x, ...) #' @export setGeneric("getTop", signature = "x", function( - x, top= 5L, method = c("mean","sum","median"), + x, top= 5L, method = c("mean", "sum", "median"), assay.type = assay_name, assay_name = "counts", na.rm = TRUE, ...) standardGeneric("getTop")) diff --git a/R/summaries.R b/R/summaries.R index 13a0c88ed..8eb54df68 100644 --- a/R/summaries.R +++ b/R/summaries.R @@ -105,7 +105,7 @@ NULL #' @export setMethod("getTop", signature = c(x = "SummarizedExperiment"), function( - x, top = 5L, method = c("mean","sum","median","prevalence"), + x, top = 5L, method = c("mean", "sum", "median", "prevalence"), assay.type = assay_name, assay_name = "counts", na.rm = TRUE, ...){ # input check From 4e0b85152b571c28f8ab3dd9aed5bfa2c50dc0d8 Mon Sep 17 00:00:00 2001 From: TuomasBorman Date: Wed, 15 Jan 2025 15:22:13 +0200 Subject: [PATCH 9/9] up --- R/convertFromBIOM.R | 1 - R/convertToPhyloseq.R | 9 ++++----- R/importTaxpasta.R | 2 +- R/mediate.R | 21 +-------------------- R/mergeSEs.R | 2 -- 5 files changed, 6 insertions(+), 29 deletions(-) diff --git a/R/convertFromBIOM.R b/R/convertFromBIOM.R index 4d73d62b5..9e68d6eee 100644 --- a/R/convertFromBIOM.R +++ b/R/convertFromBIOM.R @@ -255,7 +255,6 @@ convertFromBIOM <- function( #' @param ... Additional arguments. Not used currently. #' #' @export -#' setMethod( "convertToBIOM", signature = c(x = "SummarizedExperiment"), function(x, assay.type = "counts", ...){ diff --git a/R/convertToPhyloseq.R b/R/convertToPhyloseq.R index b10104aa2..45630c37c 100644 --- a/R/convertToPhyloseq.R +++ b/R/convertToPhyloseq.R @@ -236,15 +236,14 @@ setMethod("convertToPhyloseq", signature = c(x = "TreeSummarizedExperiment"), referenceSeq<=length(refSeqs))) ) ){ stop("'referenceSeq' must be a non-empty single character value ", - "or an integer ", - "specifying the DNAStringSet from DNAStringSetList.", - call. = FALSE) + "or an integer specifying the DNAStringSet from ", + "DNAStringSetList.", call. = FALSE) } # Get specified referenceSeq refSeqs <- refSeqs[[referenceSeq]] warning("Use 'referenceSeq' to specify DNA set from ", - "DNAStringSetList. ", - "Current choice is '", referenceSeq, "'.", call. = FALSE) + "DNAStringSetList. Current choice is '", referenceSeq, "'.", + call. = FALSE) } # Check if all rownames have referenceSeqs if( !(all(rownames(x) %in% names(refSeqs)) && diff --git a/R/importTaxpasta.R b/R/importTaxpasta.R index b6961c780..b86c81bdd 100644 --- a/R/importTaxpasta.R +++ b/R/importTaxpasta.R @@ -78,7 +78,7 @@ importTaxpasta <- function(file, add.tree = TRUE, ...) { # Create rowData and rowTree rowData(tse) <- .create_row_data(biom, ranks) .set_ranks_based_on_rowdata(tse, ...) - if (add.tree) tse <- addHierarchyTree(tse) + if (add.tree) tse <- addHierarchyTree(tse) # Agglomerate to all existing ranks tse <- agglomerateByRanks(tse, update.tree = TRUE) } else{ diff --git a/R/mediate.R b/R/mediate.R index 299f8dad9..808feb741 100644 --- a/R/mediate.R +++ b/R/mediate.R @@ -223,7 +223,6 @@ setMethod("getMediation", signature = c(x = "SummarizedExperiment"), # Use mediator for analysis mediators <- mediator mat <- NULL - } else if( med_opts[[2]] ){ # Check that assay is in assays .check_assay_present(assay.type, x) @@ -231,7 +230,6 @@ setMethod("getMediation", signature = c(x = "SummarizedExperiment"), mat <- assay(x, assay.type) # Use assay for analysis mediators <- rownames(mat) - } else if( med_opts[[3]] ){ # Check that reducedDim is in reducedDims if(!dimred %in% reducedDimNames(x)){ @@ -253,36 +251,29 @@ setMethod("getMediation", signature = c(x = "SummarizedExperiment"), # Set initial index i <- 0 - for( mediator in mediators ){ - # Update index i <- i + 1 - if( verbose ){ message("\rMediator ", i, " out of ", length(mediators), ": ", mediator - ) + ) } - # Run mediation analysis for current mediator med_out <- .run_mediate( x, outcome, treatment, mediator, family = family, mat = mat, covariates = covariates, ... ) - # Update list of results results <- .update.results(results, med_out, mediator) } - # Combine results into dataframe med_df <- .make.output(results, p.adj.method, add.metadata) return(med_df) } ) - # Check that arguments can be passed to mediate and remove unused samples #' @importFrom stats na.omit .check.mediate.args <- function( @@ -354,7 +345,6 @@ setMethod("getMediation", signature = c(x = "SummarizedExperiment"), #' @importFrom stats lm formula glm .run_mediate <- function(x, outcome, treatment, mediator = NULL, mat = NULL, family = gaussian(), covariates = NULL, ...) { - # Create initial dataframe with outcome and treatment variables df <- data.frame( Outcome = colData(x)[[outcome]], Treatment = colData(x)[[treatment]]) @@ -373,10 +363,8 @@ setMethod("getMediation", signature = c(x = "SummarizedExperiment"), relation_dv <- "Outcome ~ Treatment + Mediator" if( !is.null(covariates) ){ - # Fetch covariates from colData and store them in dataframe df <- cbind(df, colData(x)[covariates]) - # Add covariate to formula of mediation model relation_m <- paste( relation_m, "+", @@ -402,32 +390,25 @@ setMethod("getMediation", signature = c(x = "SummarizedExperiment"), treat = "Treatment", mediator = "Mediator", covariates = covariates, ... ) - return(med_out) } # Update list of results .update.results <- function(results, med_out, mediator) { - # Update model variables results[["Mediator"]] <- c(results[["Mediator"]], mediator) - # Update stats of ACME (average causal mediation effect) results[["ACME_estimate"]] <- c(results[["ACME_estimate"]], med_out$d.avg) results[["ACME_pval"]] <- c(results[["ACME_pval"]], med_out$d.avg.p) - # Update stats of ADE (average direct effect) results[["ADE_estimate"]] <- c(results[["ADE_estimate"]], med_out$z.avg) results[["ADE_pval"]] <- c(results[["ADE_pval"]], med_out$z.avg.p) - # Add current model to metadata results[["Model"]][[length(results[["Model"]]) + 1]] <- med_out - return(results) } - # Combine results into output dataframe .make.output <- function(results, p.adj.method, add.metadata) { diff --git a/R/mergeSEs.R b/R/mergeSEs.R index 9d7f0a87d..8e8263b84 100644 --- a/R/mergeSEs.R +++ b/R/mergeSEs.R @@ -158,8 +158,6 @@ setMethod("mergeSEs", signature = c(x = "SimpleList"), } else if (!is.null(assay_name) & !is.null(assay.type)) { warning("The assay.type argument is used and assay_name is ", "ignored") - } else { - # See next step } # CHeck which assays can be found, and if any --> FALSE assay.type <- .assays_cannot_be_found(assay.type = assay.type, x)