From 3b07d27e021fd748881a53173e8fe8e55a75d73f Mon Sep 17 00:00:00 2001 From: vertesy Date: Wed, 4 Dec 2024 17:49:08 +0100 Subject: [PATCH] bf addMetaFraction --- R/Seurat.Utils.Metadata.R | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/R/Seurat.Utils.Metadata.R b/R/Seurat.Utils.Metadata.R index f05cc4a..147dd74 100644 --- a/R/Seurat.Utils.Metadata.R +++ b/R/Seurat.Utils.Metadata.R @@ -526,6 +526,13 @@ addMetaFraction <- function( layer = "data", gene.set = FALSE, verbose = TRUE) { + stopifnot( + is(obj, "Seurat"), + is.character(col.name), is.character(assay), is.character(layer), + is.logical(gene.set), is.logical(verbose), + assay %in% Assays(obj), layer %in% Layers(obj) + ) + message("Should rather use the default `Seurat::PercentageFeatureSet`") message("Assay: ", assay) message("Layer: ", layer) @@ -535,7 +542,7 @@ addMetaFraction <- function( if (!isFALSE(gene.set) && !isFALSE(gene.symbol.pattern) && verbose) print("Both gene.set AND gene.symbol.pattern are defined. Only using gene.set.") # if (!isFALSE(gene.set)) geneset <- check.genes(genes = gene.set, obj = obj) - total_expr <- Matrix::colSums(GetAssayData(object = obj)) + total_expr <- Matrix::colSums(GetAssayData(object = obj, assay = assay, layer = layer)) all.genes <- Features(obj, assay = assay) genes.matching <- if (!isFALSE(gene.set)) {