Seurat对象
- 查看seurat对象的结构:
str(object)
- seurat对象的元信息:
object@meta.data
- 指定使用的idents:
Idents(object) <- "seurat_clusters"
- 指定使用的assay:
DefaultAssay(object) <- "SCT"
获取基因
rownames(object)
获取细胞
- 全部细胞:
colnames(object)
/Cells(object)
/rownames(object@meta.data)
- 指定细胞:
rownames(object@meta.data)[which(object@meta.data$seurat_clusters %in% clusters)]
WhichCells(object, idents = c(1, 2, 3))
/WhichCells(object, expression = gene > 0, slot = "counts")
获取Seurat子集
subset(object, cells = cells)
subset(object, idents = c(1, 2, 3))
(取反: invert = TRUE)subset(object, gene > 0, slot = "counts")
object[, object@meta.data$seurat_clusters %in% clusters]
获取表达信息
FetchData(object, c(genetable$gene, "clustertype", "majortype"))
GetAssayData(object, assay = 'RNA', slot = "counts")
as.matrix(object@assays$RNA@counts)
获取降维坐标信息
Embeddings(object = object[["umap"]])
细胞identity
- 获取identity:
Idents(object)
- 根据细胞设置identity:
Idents(object, cells = cells) <- 'Astrocyte'
- 修改idents名字:
RenameIdents(object, '0' = 'A', '1' = 'B')
- 设置细胞identity:
SetIdent(object, cells = cells, value = 'A') StashIdent(object, save.name = 'idents')
(将细胞identity添加到元信息)
计算细胞数目/比例
- 总细胞数:
nrow(object@meta.data)
- 每个群细胞数目:
table(Idents(object))
/table(object$RNA_snn_res.0.8)
- 每个群细胞比例:
prop.table(table(Idents(object)))
/prop.table(table(object$RNA_snn_res.0.8))