打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
PySCENIC(三):pyscenic单细胞转录因子分析可视化
userphoto

2022.11.04 重庆

关注

pyscenic分析结束了,其实后期最主要的就是可视化了,与其说是可视化,其实核心是对结果的提取,因为我们最后只得到了一个文件:sce_SCENIC.loom,后期我们会出两个三个文章,用来可视化结果,或者一些比较好了可应用的思路!本节详细注释代码已上传QQ群文件!

往期内容:
PySCENIC(一):python版单细胞转录组转录因子分析
PySCENIC(二):pyscenic单细胞转录组转录因子分析

觉得小编内容有用的、有意思的,点赞、分享、关注一下呗!

1、《KS科研分享与服务》公众号有QQ交流群,但是进入门槛是20元,请考虑清楚。群里有推文的注释代码和示例数据,付费内容半价,还可以与大家交流。

2、单细胞转录组全流程代码需收费,收费代码包含公众号付费内容,也有很多新增加的内容。需进群或者需单细胞代码的小伙伴请添加作者微信了解,请备注目的,除此之外请勿添加,谢谢!

3、付费文章集合有打包价哦!

详情请联系作者:

先加载需要的R包,都加载了,没毛病。
setwd("/home/shpc_100828/Pyscenic/")#加载分析包library(SCopesce_SCENICR)library(AUCell)library(SCENIC)#可视化相关包,多加载点没毛病library(dplyr)library(KernSmooth)library(RColorBrewer)library(plotly)library(BiocParallel)library(grid)library(ComplexHeatmap)library(data.table)library(ggplot2)library(pheatmap)
将loom文件读入R,提取数据。
sce_SCENIC <- open_sce_SCENIC("sce_SCENIC.sce_SCENIC")# exprMat <- get_dgem(sce_SCENIC)#从sce_SCENIC文件提取表达矩阵# exprMat_log <- log2(exprMat+1) # log处理regulons_incidMat <- get_regulons(sce_SCENIC, column.attr.name="Regulons")regulons <- regulonsToGeneLists(regulons_incidMat)class(regulons)
regulonAUC <- get_regulons_AUC(sce_SCENIC, column.attr.name='RegulonsAUC')regulonAucThresholds <- get_regulon_thresholds(sce_SCENIC)

第一个可视化:
RSS分析,查看细胞类型特异性转录因子,需要先加载seurat对象,提取metadata信息,并进行分析!默认是点图!
human_data <- readRDS("~/Pyscenic/human_data.rds")cellinfo <- human_data@meta.data[,c('celltype','group',"nFeature_RNA","nCount_RNA")]#细胞meta信息colnames(cellinfo)=c('celltype', 'group','nGene' ,'nUMI')######计算细胞特异性TFcellTypes <-  as.data.frame(subset(cellinfo,select = 'celltype'))selectedResolution <- "celltype"sub_regulonAUC <- regulonAUC
rss <- calcRSS(AUC=getAUC(sub_regulonAUC), cellAnnotation=cellTypes[colnames(sub_regulonAUC), selectedResolution])
rss=na.omit(rss)rssPlot <- plotRSS( rss, zThreshold = 3, cluster_columns = FALSE, order_rows = TRUE, thr=0.1, varName = "cellType", col.low = '#330066', col.mid = '#66CC66',  col.high = '#FFCC33')rssPlot
我们也可以提取数据,用热图的方式呈现,这里我是用ggheatmap做的,也可以用pheatmap、complexheatmap或ggplot2做。
rss_data <- rssPlot$plot$datadevtools::install_github("XiaoLuo-boy/ggheatmap")library(ggheatmap)library(reshape2)rss_data<-dcast(rss_data,                 Topic~rss_data$cellType,                value.var = 'Z')rownames(rss_data) <- rss_data[,1]rss_data <- rss_data[,-1]colnames(rss_data)col_ann <- data.frame(group= c(rep("Neutrophil",1),                               rep("Macrophage",1),                               rep("mDC",1),                               rep("T cell",1),                               rep("Mast",1)))#列注释rownames(col_ann) <- colnames(rss_data)groupcol <- c("#D9534F", "#96CEB4", "#CBE86B", "#EDE574", "#0099CC")names(groupcol) <- c("Neutrophil","Macrophage","mDC", "T cell","Mast")col <- list(group=groupcol)
text_columns <- sample(colnames(rss_data),0)#不显示列名
p <- ggheatmap(rss_data,color=colorRampPalette(c('#1A5592','white',"#B83D3D"))(100), cluster_rows = T,cluster_cols = F,scale = "row", annotation_cols = col_ann, annotation_color = col, legendName="Relative value", text_show_cols = text_columns)p
第二个可视化:
将转录因子分析结果与seurat对象结合,可视化类似于seurat!
next_regulonAUC <- regulonAUC[,match(colnames(human_data),colnames(regulonAUC))]dim(next_regulonAUC)
regulon_AUC <- regulonAUC@NAMEShuman_data@meta.data = cbind(human_data@meta.data ,t(assay(next_regulonAUC[regulon_AUC,])))
#自己选定感兴趣的或者比较重要的转录因子,这里我是随机的TF_plot <- c("ZNF561(+)","FOXP3(+)","YY1(+)","HOXB2(+)", "TBX21(+)","TCF12(+)","STAT2(+)","SOX21(+)", "RBBP5(+)","NR2F6(+)","NELFE(+)","MAFG(+)")
DotPlot(human_data, features = TF_plot)+ theme_bw()+ theme(panel.grid = element_blank(), axis.text.x=element_text(hjust =1,vjust=1, angle = 45))+ labs(x=NULL,y=NULL)+guides(size=guide_legend(order=3))

上面我们展示的是转录因子在不同细胞的评分,按照这个道理,我们依然可以选定某种细胞,看样本间转录因子的差别!
DotPlot(human_data, features = TF_plot, group.by = 'group')+  theme_bw()+  theme(panel.grid = element_blank(),         axis.text.x=element_text(hjust =1,vjust=1, angle = 45))+  theme(legend.direction = "horizontal",         legend.position = "bottom")+  labs(x=NULL,y=NULL)
也可以是是R语言中的SCENIC的展示一样,用UMAP!
FeaturePlot(human_data, features ="FOXP3(+)")
第三个可视化:
展示转录因子平均活性!
cellsPerGroup <- split(rownames(cellTypes),                        cellTypes[,selectedResolution])regulonActivity_byGroup <- sapply(cellsPerGroup,                                  function(cells)                                   rowMeans(getAUC(sub_regulonAUC)[,cells]))
regulonActivity_byGroup_Scaled <- t(scale(t(regulonActivity_byGroup), center = T, scale=T))

regulonActivity_byGroup_Scaled=na.omit(regulonActivity_byGroup_Scaled)

hm <- draw(ComplexHeatmap::Heatmap(regulonActivity_byGroup_Scaled, name="Regulon activity", row_names_gp=grid::gpar(fontsize=6), show_row_names = F)) hm #可视化所有的TF

当然了,全部展示没有啥意义,还是可以提取数据,可视化需要的TF!
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
pyscenic的转录因子分析结果展示之各个单细胞亚群特异性激活转录因子
pySCENIC的转录因子分析及数据可视化(二)
单细胞转录组实战06: pySCENIC转录因子分析(docker)
空转 | 我,SPOTlight,用解卷积,解决空间转录组spot注释!
marker基因的表达量可视化
一文搞定单细胞基因集评分
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服