Skip to contents

Extract the count matrix from a Seurat object, compatible with both v4 and v5. Uses v4 methods by default, falling back to v5 if necessary.

Usage

ExtractSeuratData(
  object,
  assay = NULL,
  slot = c("counts", "data", "scale.data"),
  layer = NULL
)

Arguments

object

A Seurat object.

assay

Character. Name of the assay to use. Default is NULL (uses default assay).

slot

Character. Slot to extract. One of "counts", "data", or "scale.data". Default is "counts".

layer

Character. For Seurat v5, the layer name. Default is NULL.

Value

A matrix (sparse or dense) containing the expression data.

Details

This function prioritizes Seurat v4 compatibility. For v4 objects, it uses GetAssayData() with the slot argument. For v5 objects, it attempts to use the same method first, then falls back to layer-based access if needed.

Examples

if (FALSE) { # \dontrun{
# Extract counts from default assay
counts <- ExtractSeuratData(seurat_obj)

# Extract normalized data from RNA assay
data <- ExtractSeuratData(seurat_obj, assay = "RNA", slot = "data")
} # }