挑选富集分析结果 enrichments

2024-01-12 23:36

本文主要是介绍挑选富集分析结果 enrichments,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 


#2.2挑选term---selected_clusterenrich=enrichmets[grepl(pattern = "cilium|matrix|excular|BMP|inflamm|development|muscle|vaso|pulmonary|alveoli",x = enrichmets$Description),]head(selected_clusterenrich) distinct(selected_clusterenrich)# remove duplicate rows based on Description 并且保留其他所有变量
distinct_df <- distinct(enrichmets, Description,.keep_all = TRUE)library(ggplot2)
ggplot( distinct_df %>%dplyr::filter(stringr::str_detect(pattern = "cilium|matrix|excular|BMP|inflamm|development|muscle",Description))  %>%group_by(Description) %>%add_count()  %>%dplyr::arrange(dplyr::desc(n),dplyr::desc(Description)) %>%mutate(Description =forcats:: fct_inorder(Description)), #fibri|matrix|collaaes(Cluster, Description)) +geom_point(aes(fill=p.adjust, size=Count), shape=21)+theme_bw()+theme(axis.text.x=element_text(angle=90,hjust = 1,vjust=0.5),axis.text.y=element_text(size = 12),axis.text = element_text(color = 'black', size = 12))+scale_fill_gradient(low="red",high="blue")+labs(x=NULL,y=NULL)
# coord_flip()head(enrichmets)ggplot( distinct(enrichmets,Description,.keep_all=TRUE)  %>% #  dplyr::mutate(Cluster = factor(Cluster, levels = unique(.$Cluster))) %>%dplyr::mutate(Description = factor(Description, levels = unique(.$Description))) %>%#  dplyr::group_by(Cluster)  %>%dplyr::filter(stringr::str_detect(pattern = "cilium organization|motile cilium|cilium movemen|cilium assembly|cell-matrix adhesion|extracellular matrix organization|regulation of acute inflammatory response to antigenic stimulus|collagen-containing extracellular matrix|negative regulation of BMP signaling pathway|extracellular matrix structural constituent|extracellular matrix binding|fibroblast proliferation|collagen biosynthetic process|collagen trimer|fibrillar collagen trimer|inflammatory response to antigenic stimulus|chemokine activity|chemokine production|cell chemotaxis|chemoattractant activity|NLRP3 inflammasome complex assembly|inflammatory response to wounding|Wnt signaling pathway|response to oxidative stress|regulation of vascular associated smooth muscle cell proliferation|venous blood vessel development|regulation of developmental growth|lung alveolus development|myofibril assembly|blood vessel diameter maintenance|gas transport|cell maturation|regionalization|oxygen carrier activity|oxygen binding|vascular associated smooth muscle cell proliferation",Description))     %>%#  group_by(Description) %>%add_count()  %>%dplyr::arrange(dplyr::desc(n),dplyr::desc(Description))  %>%mutate(Description =forcats:: fct_inorder(Description)), #fibri|matrix|collaaes(Cluster, y = Description)) +  #stringr:: str_wrapgeom_point(aes(fill=p.adjust, size=Count), shape=21)+theme_bw()+theme(axis.text.x=element_text(angle=90,hjust = 1,vjust=0.5),axis.text.y=element_text(size = 12),axis.text = element_text(color = 'black', size = 12))+scale_fill_gradient(low="red",high="blue")+labs(x=NULL,y=NULL)
# coord_flip()
print(getwd())p=ggplot( distinct(enrichmets,Description,.keep_all=TRUE)  %>%dplyr::mutate(Description = factor(Description, levels = unique(.$Description))) %>%  #调整terms显示顺序dplyr::filter(stringr::str_detect(pattern = "cilium organization|motile cilium|cilium movemen|cilium assembly|cell-matrix adhesion|extracellular matrix organization|regulation of acute inflammatory response to antigenic stimulus|collagen-containing extracellular matrix|negative regulation of BMP signaling pathway|extracellular matrix structural constituent|extracellular matrix binding|fibroblast proliferation|collagen biosynthetic process|collagen trimer|fibrillar collagen trimer|inflammatory response to antigenic stimulus|chemokine activity|chemokine production|cell chemotaxis|chemoattractant activity|NLRP3 inflammasome complex assembly|inflammatory response to wounding|Wnt signaling pathway|response to oxidative stress|regulation of vascular associated smooth muscle cell proliferation|venous blood vessel development|regulation of developmental growth|lung alveolus development|myofibril assembly|blood vessel diameter maintenance|gas transport|cell maturation|regionalization|oxygen carrier activity|oxygen binding|vascular associated smooth muscle cell proliferation",Description))  %>%group_by(Description) %>%add_count()  %>%dplyr::arrange(dplyr::desc(n),dplyr::desc(Description)) %>%mutate(Description =forcats:: fct_inorder(Description)), #fibri|matrix|collaaes(Cluster, y = Description)) +  #stringr:: str_wrap#scale_y_discrete(labels = function(x) stringr::str_wrap(x, width = 60)) +  #调整terms长度geom_point(aes(fill=p.adjust, size=Count), shape=21)+theme_bw()+theme(axis.text.x=element_text(angle=90,hjust = 1,vjust=0.5),axis.text.y=element_text(size = 12),axis.text = element_text(color = 'black', size = 12))+scale_fill_gradient(low="red",high="blue")+labs(x=NULL,y=NULL)
# coord_flip()
print(getwd())ggsave(filename ="~/silicosis/spatial/sp_cluster_rigions_after_harmony/enrichents12.pdf",plot = p,width = 10,height = 12,limitsize = FALSE)######展示term内所有基因,用热图展示-------#提取画图的数据p$data#提取图形中的所有基因-----
mygenes=  p$data $geneID %>% stringr::str_split(.,"/",simplify = TRUE)  %>%as.vector()   %>%unique()
frame_for_genes=p$data %>%as.data.frame() %>% dplyr::group_by(Cluster)  #后面使用split的话,必须按照分组排序
head(frame_for_genes)my_genelist=  split(frame_for_genes, frame_for_genes$Cluster, drop = TRUE)  %>%  #注意drop参数的理解lapply(function(x) select(x, geneID));my_genelistmy_genelist=  split(frame_for_genes, frame_for_genes$Cluster, drop = TRUE)  %>%  #注意drop参数的理解lapply(function(x) x$geneID);my_genelistmygenes=my_genelist %>% lapply( function(x)  {stringr::str_split(x,"/",simplify = TRUE)  %>%as.vector()   %>%unique()}   )#准备画热图,加载seurat对象
load("/home/data/t040413/silicosis/spatial_transcriptomics/silicosis_ST_harmony_SCT_r0.5.rds")
{dim(d.all)DefaultAssay(d.all)="Spatial"#visium_slides=SplitObject(object = d.all,split.by = "stim")names(d.all);dim(d.all)d.all@meta.data %>%head()head(colnames(d.all))#1 给d.all 添加meta信息------adata_obs=read.csv("~/silicosis/spatial/adata_obs.csv")head(adata_obs)mymeta=  paste0(d.all@meta.data$orig.ident,"_",colnames(d.all))  %>% gsub("-.*","",.)  # %>%  head()head(mymeta)tail(mymeta)#掉-及其之后内容adata_obs$col= adata_obs$spot_id %>% gsub("-.*","",.)    # %>%  head()head(adata_obs)rownames(adata_obs)=adata_obs$coladata_obs=adata_obs[mymeta,]head(adata_obs)identical(mymeta,adata_obs$col)d.all=AddMetaData(d.all,metadata = adata_obs)head(d.all@meta.data)}##构建画热图对象---
Idents(d.all)=d.all$clusters
a=AverageExpression(d.all,return.seurat = TRUE)
a$orig.ident=rownames(a@meta.data)
head(a@meta.data)
head(markers)rownames(a) %>%head()
head(mygenes)
table(mygenes %in% rownames(a))
DoHeatmap(a,draw.lines = FALSE, slot = 'scale.data', group.by = 'orig.ident',features = mygenes ) + ggplot2:: scale_color_discrete(name = "Identity", labels =  unique(a$orig.ident) %>%sort()  )##doheatmap做出来的图不好调整,换成heatmap自己调整p=DoHeatmap(a,draw.lines = FALSE, slot = 'scale.data', group.by = 'orig.ident',features = mygenes ) + ggplot2:: scale_color_discrete( labels =  unique(a$orig.ident) %>%sort()  ) #name = "Identity",p$data %>%head()##########这种方式容易出现bug,不建议------
if (F) {wide_data <- p$data %>% .[,-4] %>%tidyr:: pivot_wider(names_from = Cell, values_from = Expression)print(wide_data)  mydata=  wide_data %>%dplyr:: select(-Feature) %>%as.matrix()head(mydata)rownames(mydata)=wide_data$Featuremydata=mydata[,c("Bronchial zone", "Fibrogenic zone",   "Interstitial zone",  "Inflammatory zone","Vascular zone"  )]p2=pheatmap::  pheatmap(mydata, fontsize_row = 2, clustering_method = "ward.D2",#     annotation_col = wide_data$Feature,annotation_colors = c("Interstitial zone" = "red", "Bronchial zone" = "blue", "Fibrogenic zone" = "green", "Vascular zone" = "purple") ,cluster_cols = FALSE,column_order = c("Inflammatory zone", "Vascular zone"  ,"Bronchial zone", "Fibrogenic zone"   ))getwd()ggplot2::ggsave(filename = "~/silicosis/spatial/sp_cluster_rigions_after_harmony/heatmap_usingpheatmap.pdf",width = 8,height = 10,limitsize = FALSE,plot = p2)}##########建议如下方式画热图------
a$orig.ident=a@meta.data %>%rownames()
a@meta.data %>%head()
Idents(a)=a$orig.identa@assays$Spatial@scale.data  %>%head()mydata=a@assays$Spatial@scale.data
mydata=mydata[rownames(mydata) %in% (mygenes %>%unlist() %>%unique()) ,]
mydata= mydata[,c( "Fibrogenic zone",  "Inflammatory zone",   "Bronchial zone","Interstitial zone","Vascular zone"  )]
head(mydata)
p3=pheatmap::  pheatmap(mydata, fontsize_row = 2,  clustering_method = "ward.D2",#     annotation_col = wide_data$Feature,annotation_colors = c("Interstitial zone" = "red", "Bronchial zone" = "blue", "Fibrogenic zone" = "green", "Vascular zone" = "purple") ,cluster_cols = FALSE,column_order = c("Inflammatory zone", "Vascular zone"  ,"Bronchial zone", "Fibrogenic zone"   )
)getwd()
ggplot2::ggsave(filename = "~/silicosis/spatial/sp_cluster_rigions_after_harmony/heatmap_usingpheatmap2.pdf",width = 8,height = 10,limitsize = FALSE,plot = p3)#########单独画出炎症区和纤维化区---------
a@assays$Spatial@scale.data  %>%head()mydata=a@assays$Spatial@scale.data
mygenes2= my_genelist[c('Inflammatory zone','Fibrogenic zone')] %>%  unlist() %>% stringr::str_split("/",simplify = TRUE) mydata2=mydata[rownames(mydata) %in% ( mygenes2 %>%unlist() %>%unique()) ,]
mydata2= mydata2[,c( "Fibrogenic zone",  "Inflammatory zone" )]
head(mydata2)p3=pheatmap::  pheatmap(mydata2, fontsize_row = 5,  #scale = 'row',clustering_method = "ward.D2",#     annotation_col = wide_data$Feature,annotation_colors = c("Interstitial zone" = "red", "Bronchial zone" = "blue", "Fibrogenic zone" = "green", "Vascular zone" = "purple") ,cluster_cols = FALSE,column_order = c("Inflammatory zone", "Vascular zone"  ,"Bronchial zone", "Fibrogenic zone"   )
)getwd()
ggplot2::ggsave(filename = "~/silicosis/spatial/sp_cluster_rigions_after_harmony/heatmap_usingpheatmap3.pdf",width = 4,height = 8,limitsize = FALSE,plot = p3)

这篇关于挑选富集分析结果 enrichments的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/599534

相关文章

Redis主从/哨兵机制原理分析

《Redis主从/哨兵机制原理分析》本文介绍了Redis的主从复制和哨兵机制,主从复制实现了数据的热备份和负载均衡,而哨兵机制可以监控Redis集群,实现自动故障转移,哨兵机制通过监控、下线、选举和故... 目录一、主从复制1.1 什么是主从复制1.2 主从复制的作用1.3 主从复制原理1.3.1 全量复制

Redis主从复制的原理分析

《Redis主从复制的原理分析》Redis主从复制通过将数据镜像到多个从节点,实现高可用性和扩展性,主从复制包括初次全量同步和增量同步两个阶段,为优化复制性能,可以采用AOF持久化、调整复制超时时间、... 目录Redis主从复制的原理主从复制概述配置主从复制数据同步过程复制一致性与延迟故障转移机制监控与维

Redis连接失败:客户端IP不在白名单中的问题分析与解决方案

《Redis连接失败:客户端IP不在白名单中的问题分析与解决方案》在现代分布式系统中,Redis作为一种高性能的内存数据库,被广泛应用于缓存、消息队列、会话存储等场景,然而,在实际使用过程中,我们可能... 目录一、问题背景二、错误分析1. 错误信息解读2. 根本原因三、解决方案1. 将客户端IP添加到Re

Redis主从复制实现原理分析

《Redis主从复制实现原理分析》Redis主从复制通过Sync和CommandPropagate阶段实现数据同步,2.8版本后引入Psync指令,根据复制偏移量进行全量或部分同步,优化了数据传输效率... 目录Redis主DodMIK从复制实现原理实现原理Psync: 2.8版本后总结Redis主从复制实

锐捷和腾达哪个好? 两个品牌路由器对比分析

《锐捷和腾达哪个好?两个品牌路由器对比分析》在选择路由器时,Tenda和锐捷都是备受关注的品牌,各自有独特的产品特点和市场定位,选择哪个品牌的路由器更合适,实际上取决于你的具体需求和使用场景,我们从... 在选购路由器时,锐捷和腾达都是市场上备受关注的品牌,但它们的定位和特点却有所不同。锐捷更偏向企业级和专

Spring中Bean有关NullPointerException异常的原因分析

《Spring中Bean有关NullPointerException异常的原因分析》在Spring中使用@Autowired注解注入的bean不能在静态上下文中访问,否则会导致NullPointerE... 目录Spring中Bean有关NullPointerException异常的原因问题描述解决方案总结

python中的与时间相关的模块应用场景分析

《python中的与时间相关的模块应用场景分析》本文介绍了Python中与时间相关的几个重要模块:`time`、`datetime`、`calendar`、`timeit`、`pytz`和`dateu... 目录1. time 模块2. datetime 模块3. calendar 模块4. timeit

python-nmap实现python利用nmap进行扫描分析

《python-nmap实现python利用nmap进行扫描分析》Nmap是一个非常用的网络/端口扫描工具,如果想将nmap集成进你的工具里,可以使用python-nmap这个python库,它提供了... 目录前言python-nmap的基本使用PortScanner扫描PortScannerAsync异

Oracle数据库执行计划的查看与分析技巧

《Oracle数据库执行计划的查看与分析技巧》在Oracle数据库中,执行计划能够帮助我们深入了解SQL语句在数据库内部的执行细节,进而优化查询性能、提升系统效率,执行计划是Oracle数据库优化器为... 目录一、什么是执行计划二、查看执行计划的方法(一)使用 EXPLAIN PLAN 命令(二)通过 S

性能分析之MySQL索引实战案例

文章目录 一、前言二、准备三、MySQL索引优化四、MySQL 索引知识回顾五、总结 一、前言 在上一讲性能工具之 JProfiler 简单登录案例分析实战中已经发现SQL没有建立索引问题,本文将一起从代码层去分析为什么没有建立索引? 开源ERP项目地址:https://gitee.com/jishenghua/JSH_ERP 二、准备 打开IDEA找到登录请求资源路径位置