diff --git a/NEWS.md b/NEWS.md index 8af2018..290cb23 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,8 @@ # dreamlet 1.1.17 - - bug fix in `plotPCA()` + - new functionality in `plotPCA()` and `outlierByAssay()` + - works on any `list`, not just `dreamletProcessedData` + - allows outlier analysis on residuals # dreamlet 1.1.16 - Feb 8, 2024 diff --git a/R/dreamletProcessedData.R b/R/dreamletProcessedData.R index 913e870..146bcbd 100644 --- a/R/dreamletProcessedData.R +++ b/R/dreamletProcessedData.R @@ -448,3 +448,4 @@ setMethod( list(assayLevel = df, geneLevel = df2) } ) + diff --git a/R/outlier.R b/R/outlier.R index 4fd8e18..9966f2a 100644 --- a/R/outlier.R +++ b/R/outlier.R @@ -92,11 +92,16 @@ outlier <- function(data, robust = FALSE, ...) { #' @export outlierByAssay = function(object, assays = assayNames(object), nPC=2, robust = FALSE, ...){ - stopifnot(is(object, "dreamletProcessedData")) + stopifnot(is(object, "list")) df = lapply(assays, function(id){ # get normalized expression - Y <- assay(object, id)$E + # Y <- assay(object, id)$E + if( is(object[[id]], "EList") ){ + Y <- object[[id]]$E + }else{ + Y <- object[[id]] + } # PCA # dcmp <- prcomp(scale(t(Y))) diff --git a/R/plotPCA.R b/R/plotPCA.R index 08e6d35..c62971e 100644 --- a/R/plotPCA.R +++ b/R/plotPCA.R @@ -8,7 +8,7 @@ setGeneric("plotPCA", BiocGenerics::plotPCA) #' #' Compute PCA of gene expression for an assay, and plot samples coloring by outlier score #' -#' @param object \code{dreamletProcessedData} from \code{processAssays()} +#' @param object \code{dreamletProcessedData} from \code{processAssays()} or a \code{list} from \code{residuals()} #' @param assays assays / cell types to analyze #' @param nPC number of PCs to uses for outlier score with \code{outlier()} #' @param robust use robust covariance method, defaults to \code{FALSE} @@ -20,7 +20,7 @@ setGeneric("plotPCA", BiocGenerics::plotPCA) #' #' @name plotPCA #' @rdname plotPCA -#' @aliases plotPCA plotPCA,dreamletProcessedData-method +#' @aliases plotPCA plotPCA,list-method #' @examples #' library(muscat) #' library(SingleCellExperiment) @@ -39,13 +39,26 @@ setGeneric("plotPCA", BiocGenerics::plotPCA) #' res.proc <- processAssays(pb, ~group_id) #' #' # PCA to identify outliers -#' plotPCA( res.proc, "CD14+ Monocytes") +#' # from normalized expression +#' plotPCA( res.proc, c("B cells", "CD14+ Monocytes")) +#' +#' # Run on regression residuals +#' #----------------------------- +#' +#' # Regression analysis +#' fit = dreamlet(res.proc, ~ group_id) +#' +#' # Extract regression residuals +#' residsObj = residuals(fit) +#' +#' # PCA on residuals +#' plotPCA( residsObj, c("B cells", "CD14+ Monocytes")) # #' @seealso \code{outlierByAssay()} #' @export -setMethod("plotPCA", signature(object="dreamletProcessedData"), function(object, assays = assayNames(object), nPC=2, robust = FALSE, ..., maxOutlierZ=20, nrow=2, size=2, fdr.cutoff=0.05){ +setMethod("plotPCA", signature(object="list"), function(object, assays = names(object), nPC=2, robust = FALSE, ..., maxOutlierZ=20, nrow=2, size=2, fdr.cutoff=0.05){ - stopifnot(all(assays %in% assayNames(object))) + stopifnot(all(assays %in% names(object))) PC1 <- PC2 <- z <- pValue <- FDR <- NULL @@ -64,3 +77,10 @@ setMethod("plotPCA", signature(object="dreamletProcessedData"), function(object, }) + + + + + + + diff --git a/docs/404.html b/docs/404.html index d073ab9..6812b2a 100644 --- a/docs/404.html +++ b/docs/404.html @@ -31,7 +31,7 @@ dreamlet - 1.1.16 + 1.1.17