Seurat Object
Purpose
This page is for learning how to inspect and access a Seurat object.
The goal is not to run a full workflow yet. The goal is to know where common information lives: assays, counts, metadata, identities, and reductions.
Basic Checks
Start with the object itself:
class(seu)
## [1] "Seurat"
## attr(,"package")
## [1] "SeuratObject"
seu
## An object of class Seurat
## 22305 features across 22177 samples within 1 assay
## Active assay: RNA (22305 features, 0 variable features)
## 1 layer present: countsFor a deeper but noisy look:
str(seu, max.level = 2)Common questions:
- How many cells are in the object?
- How many features are in the active assay?
- Which assays are present?
- Has the object already been normalized, clustered, or embedded?
Assays
Assays store different data modalities or feature spaces.
Common assays:
RNASCTADTintegrated
Check assays:
Seurat::Assays(seu)
Seurat::DefaultAssay(seu)Common assay data slots:
counts: raw count matrixdata: normalized expressionscale.data: scaled expression
Metadata
Cell metadata are stored in seu@meta.data.
Inspect metadata:
metadata <- seu[[]]
head(metadata)
colnames(metadata)
dim(metadata)seu[[]] is a convenient Seurat shortcut for extracting cell metadata.
Access one metadata column:
table(seu$sample_id)
table(seu$condition)Add metadata:
seu$sample_id <- "sample_A"
seu$condition <- "control"What to remember:
- Rows of
meta.dataare cells. - Row names should match cell names.
- Metadata should preserve sample, condition, patient, and batch information.
Cells And Features
Cells are columns in the expression matrix. Features are rows, usually genes for the RNA assay.
Check cell names:
cells <- colnames(seu)
length(cells)
head(cells)Check feature names:
features <- rownames(seu)
length(features)
head(features)
sample(features, 10)Check object dimensions:
dim(seu)What to remember:
colnames(seu)gives cell barcodes or cell names.rownames(seu)gives feature names in the active assay.- For scRNA-seq, features are usually genes.
- Sampling feature names helps check naming style, such as gene symbols, Ensembl IDs, upper case, or lower case.
- Cell names must stay unique after merging samples.
Idents
Idents() stores the active identity class. It is often used by plotting and differential expression functions.
Check active identities:
Seurat::Idents(seu)
table(Seurat::Idents(seu))Set active identities from metadata:
Seurat::Idents(seu) <- "seurat_clusters"What to remember:
Idents()is not the same thing as metadata, but it is often derived from a metadata column.- Before marker or differential expression functions, check what the active identity is.
Counts And Expression
Extract raw counts:
counts <- Seurat::GetAssayData(
object = seu,
assay = "RNA",
slot = "counts"
)Extract normalized expression:
data <- Seurat::GetAssayData(
object = seu,
assay = "RNA",
slot = "data"
)Check matrix dimensions:
dim(counts)
counts[1:5, 1:5]What to remember:
- Rows are genes or features.
- Columns are cells.
countsshould be raw counts.datais usually normalized expression if normalization has been run.
Reductions
Dimensionality reductions are stored in the object after PCA, UMAP, t-SNE, or integration workflows.
Check reductions:
Seurat::Reductions(seu)Extract embeddings:
pca_embeddings <- Seurat::Embeddings(seu, reduction = "pca")
umap_embeddings <- Seurat::Embeddings(seu, reduction = "umap")Check dimensions:
dim(pca_embeddings)
head(umap_embeddings)Note
For these practice notes, Seurat object is the default working object for basic inspection, metadata handling, plotting, merging, and early workflow steps.
Other object systems such as SingleCellExperiment and AnnData can have their own pages later.