单细胞Seurat分析基本可视化实现python版Scanpy风格

这个问题我们之前提到过,很多小伙伴可能看到某些文章中这样的可视化,很感兴趣,其实熟悉python分析的小伙伴一眼就可以看出是scanpy出图,虽然R也能实现这样的效果,但是自从我们集全了seurat转h5ad(单细胞seurat V5转V4格式及seurat转为h5ad格式),以及h5ad转seurat之后(玩转单细胞(16):Scanpy单细胞h5ad数据转化为Seurat对象),这都不是问题了,想要这种风格的作图,直接转化格式即可!

image.png

(reference:Molecular logic for cellular specializations that initiate the auditory parallel processing pathways)
这里我们首先演示直接将seurat转化为h5ad,使用scanpy作图:转化我使用的是sceasy包,很简单方便:

setwd('./data_analysis/Gene_NMF/')
# devtools::install_github("cellgeni/sceasy")
library(sceasy)
library(reticulate)
use_condaenv('sceasy')
loompy <- reticulate::import('loompy')
uterus <- readRDS("~/data_analysis/Gene_NMF/uterus.rds")
sceasy::convertFormat(uterus, from="seurat", to="anndata", outFile='uterus.h5ad')

#plot TSNE
import scanpy as sc
import anndata
#这里我seurat的数据是TSNE降维
uterus = anndata.read_h5ad('./uterus.h5ad')
sc.pl.tsne(
    uterus,
    color=["celltype"],
    frameon=False,
    ncols=1,)
image.png
#plot marker gene dotplot
#每种celltype对应的marker gene
markers = {'Smooth muscle cells':['ACTA2', 'RGS5'],
           'Macrophages':['MS4A6A','CD68','LYZ'],
           'Lymphocytes':['CCL5','STK17B','PTPRC'],
           'Stromal fibroblasts':['DCN', 'COL6A3', 'LUM'],
           'Endothelial cells':['PECAM1','PCDH17', 'VWF'],
           'Unciliated epithelial cells':['EPCAM', 'CDH1'],
           'Ciliated epithelial cells':['FOXJ1','CDHR3','DYDC2'],}

sc.pl.dotplot(uterus, markers, 'celltype',dendrogram=True)
image.png

当然了,也有小伙伴完全没有接触过python,想用R做出这样的效果,不必担心,优秀的老俊俊推出过R版的包,实现scanpy的效果。更多参数请详细阅读帮助函数。

其他优秀可视化参考:(https://github.com/junjunlab/scRNAtoolVis

#安装包
install.packages('devtools')
devtools::install_github('junjunlab/scRNAtoolVis')
library(Seurat) 
library(ggplot2)
library(dplyr)
library(scRNAtoolVis)
uterus <- readRDS("D:/KS项目/公众号文章/uterus.rds")
DefaultAssay(uterus) <- "RNA"
markers <- c("ACTA2", "RGS5", #smooth muscle cells---7, 16
             "MS4A6A", "CD68","LYZ",#macrophages---13
             "CCL5", "STK17B","PTPRC",#lymphocytes---0,3,4,5,6,14,15,17,23,18,19
             "DCN", "COL6A3", "LUM",#stromal fibroblasts---2,20
             "PECAM1","PCDH17", "VWF",#endothelial cells---8,11,22
             "EPCAM", "CDH1",#(unciliated)epithelial cells---1,9,21
             "FOXJ1","CDHR3","DYDC2")#(ciliated)epithelial cells---10,12


markers_plot <- data.frame(cluster = c(rep("Smooth muscle cells",2),
                                  rep("Macrophages",3),
                                  rep("Lymphocytes",3),
                                  rep("Stromal fibroblasts",3),
                                  rep("Endothelial cells",3),
                                  rep("Unciliated epithelial cells",2),
                                  rep("Ciliated epithelial cells",3)),
                      gene = markers)



jjDotPlot(object = uterus,
          markerGene = markers_plot,
          anno = T,
          id = 'celltype',
          textSize = 10,
          base_size= 10,
          plot.margin = c(5,3,3,3))

image.png

觉得我们分享有些用的,点个赞再走呗!

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容