From acb37b206bc142db020f7222685a5ad17d266b1b Mon Sep 17 00:00:00 2001 From: poonchilam <43943114+chilampoon@users.noreply.github.com> Date: Fri, 8 Mar 2024 13:44:15 -0500 Subject: [PATCH] update seurat5 count matrix access --- R/access_wrappers.R | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/R/access_wrappers.R b/R/access_wrappers.R index 868df24..fe270ea 100644 --- a/R/access_wrappers.R +++ b/R/access_wrappers.R @@ -86,7 +86,13 @@ extractRawCountMatrices.Conos <- function(object, transposed=TRUE) { #' @rdname extractRawCountMatrices extractRawCountMatrices.Seurat <- function(object, transposed=TRUE) { cms <- object$sample.per.cell %>% {split(names(.), .)} %>% - lapply(function(cids) object@assays$RNA@counts[,cids]) + lapply(function(cids) { + selected.cols <- colnames(object) %in% cids + obj <- object@assays$RNA@layers$counts[, selected.cols] + colnames(obj) <- colnames(object)[selected.cols] + rownames(obj) <- rownames(object) + obj + }) if (transposed) { cms %<>% lapply(Matrix::t) } @@ -126,20 +132,23 @@ extractJointCountMatrix.Conos <- function(object, raw=TRUE) { #' @rdname extractJointCountMatrix extractJointCountMatrix.Seurat <- function(object, raw=TRUE, transposed=TRUE, sparse=TRUE) { if (raw) { - dat <- object@assays$RNA@counts + dat <- object@assays$RNA@layers$counts + colnames(dat) <- colnames(object) + rownames(dat) <- rownames(object) if (transposed){ dat %<>% Matrix::t() } return(dat) } - dat <- Seurat::GetAssayData(object, slot='scale.data', assay='RNA') + dat <- Seurat::GetAssayData(object, layer='scale.data', assay='RNA') dims <- dim(dat) dat.na <- all(dims == 1) && all(is.na(x = dat)) if (all(dims == 0) || dat.na) { - dat <- Seurat::GetAssayData(object, slot='data', assay='RNA') + dat <- Seurat::GetAssayData(object, layer='data', assay='RNA') } - + colnames(dat) <- colnames(object) + rownames(dat) <- rownames(object) if (transposed){ dat %<>% Matrix::t() }