Seurat自带的RunPCA (pca)和RunTSNE (tsne)等数据降维方法产生的低维嵌入信息会格式化为DimReduc类,存储在DefaultAssay(scRNA)的reductions数据槽。当使用这些自带的方法时,会自动创建DimReduc类并填充到数据槽。当然我们也可以将由其它方法产生的维度信息存储到reductions数据槽中。
代码示例
创建一份自定义二维数据表
#random a cell position dataframe
mini.sc <- readRDS("seurat.rds")
cell_position <- data.frame(x=runif(n = ncol(mini.sc),min = 1,max = 2),y=runif(n = ncol(mini.sc),min = 1,max = 2))
rownames(cell_position ) <- colnames(mini.sc)
colnames(cell_position ) <- c('locus_1','locus_2')#注意维度名必须要以键名+数字的格式(key)
> cell_position
locus_1 locus_2
cell.1 1.435976 1.189780
cell.2 1.497868 1.001837
cell.3 1.691928 1.877578
cell.4 1.760313 1.134111
cell.5 1.155401 1.022741
cell.6 1.849457 1.939137
cell.7 1.946818 1.292949
cell.8 1.588419 1.164327
cell.9 1.502251 1.399103
将cell_position插入到seurat对象的reduction数据槽中
mini.sc[["cell.locus"]] <- CreateDimReducObject(embeddings = as.matrix(cell_position),key = "locus_", assay = "RNA")
#通过seurat函数DimPlot绘图
DimPlot(mini.sc,reduction = "cell.locus",group.by = "class",raster=FALSE,pt.size = 8,shape.by = "class")+
NoLegend()+
scale_x_continuous(limits = c(1,2))+scale_y_continuous(limits = c(1,2))