> 技术文档 > 自用-Seurat V5 提取表达矩阵、亚群_seurat getassaydata assay =

自用-Seurat V5 提取表达矩阵、亚群_seurat getassaydata assay =


1. 提取counts/data数据

整理下最近学到的提取counts/data矩阵的方法

1.1 提取counts

sce_counts=LayerData(sce, assay=\"RNA\", layer=\'counts\')sce_counts=as.data.frame(sce_counts)sce_counts=GetAssayData(sce, assay=\"RNA\", layer=\'counts\')sce_counts=as.data.frame(sce_counts)#保存用write.table()

1.2 提取data

expr=LayerData(sce, assay=\"RNA\", layer=\'data\')expr=as.data.frame(expr)expr=GetAssayData(sce, assay=\"RNA\", layer=\'counts\')expr=as.data.frame(expr)

2. 提取亚群

## 如果是要提取亚群做注释,提取counts矩阵重新走流程sce <- readRDS(\"./source/sce.celltype.rds\")Idents(sce) <- \"celltype\"macro=subset(sce,idents=c(\"Macrophage\"))table(macro@meta.data$celltype)## 使用提取的细胞构建新的Seurat对象macro_sce <- CreateSeuratObject(counts = GetAssayData(macro, assay=\"RNA\", layer=\'counts\'), meta.data = macro@meta.data)## 后续:标准化、归一化、高变基因、pcamacro_sce % FindVariableFeatures() %>% ScaleData() %>% RunPCA(verbose=FALSE)

3. cluster平均表达量–AverageExpression

av_sce=AverageExpression(sce, assays = \"RNA\", group.by = \"seurat_clusters\")av_sce=as.data.frame(av_sce$RNA)av_sce

4. Pseudobulk–AggregateExpression

av_sce <- AggregateExpression(sce, assay = \"RNA\",group.by = \"seurat_clusters\")av_sce <- AggregateExpression(sce, assay = \"RNA\",group.by = \"group\",)av_sce <- AggregateExpression(sce, assay = \"RNA\",group.by = c(\"group\",\"orig.ident\"))av_sce=as.data.frame(av_sce$RNA)av_sce