挑选富集分析结果 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

相关文章

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

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

SWAP作物生长模型安装教程、数据制备、敏感性分析、气候变化影响、R模型敏感性分析与贝叶斯优化、Fortran源代码分析、气候数据降尺度与变化影响分析

查看原文>>>全流程SWAP农业模型数据制备、敏感性分析及气候变化影响实践技术应用 SWAP模型是由荷兰瓦赫宁根大学开发的先进农作物模型,它综合考虑了土壤-水分-大气以及植被间的相互作用;是一种描述作物生长过程的一种机理性作物生长模型。它不但运用Richard方程,使其能够精确的模拟土壤中水分的运动,而且耦合了WOFOST作物模型使作物的生长描述更为科学。 本文让更多的科研人员和农业工作者

MOLE 2.5 分析分子通道和孔隙

软件介绍 生物大分子通道和孔隙在生物学中发挥着重要作用,例如在分子识别和酶底物特异性方面。 我们介绍了一种名为 MOLE 2.5 的高级软件工具,该工具旨在分析分子通道和孔隙。 与其他可用软件工具的基准测试表明,MOLE 2.5 相比更快、更强大、功能更丰富。作为一项新功能,MOLE 2.5 可以估算已识别通道的物理化学性质。 软件下载 https://pan.quark.cn/s/57

衡石分析平台使用手册-单机安装及启动

单机安装及启动​ 本文讲述如何在单机环境下进行 HENGSHI SENSE 安装的操作过程。 在安装前请确认网络环境,如果是隔离环境,无法连接互联网时,请先按照 离线环境安装依赖的指导进行依赖包的安装,然后按照本文的指导继续操作。如果网络环境可以连接互联网,请直接按照本文的指导进行安装。 准备工作​ 请参考安装环境文档准备安装环境。 配置用户与安装目录。 在操作前请检查您是否有 sud

线性因子模型 - 独立分量分析(ICA)篇

序言 线性因子模型是数据分析与机器学习中的一类重要模型,它们通过引入潜变量( latent variables \text{latent variables} latent variables)来更好地表征数据。其中,独立分量分析( ICA \text{ICA} ICA)作为线性因子模型的一种,以其独特的视角和广泛的应用领域而备受关注。 ICA \text{ICA} ICA旨在将观察到的复杂信号

【软考】希尔排序算法分析

目录 1. c代码2. 运行截图3. 运行解析 1. c代码 #include <stdio.h>#include <stdlib.h> void shellSort(int data[], int n){// 划分的数组,例如8个数则为[4, 2, 1]int *delta;int k;// i控制delta的轮次int i;// 临时变量,换值int temp;in

三相直流无刷电机(BLDC)控制算法实现:BLDC有感启动算法思路分析

一枚从事路径规划算法、运动控制算法、BLDC/FOC电机控制算法、工控、物联网工程师,爱吃土豆。如有需要技术交流或者需要方案帮助、需求:以下为联系方式—V 方案1:通过霍尔传感器IO中断触发换相 1.1 整体执行思路 霍尔传感器U、V、W三相通过IO+EXIT中断的方式进行霍尔传感器数据的读取。将IO口配置为上升沿+下降沿中断触发的方式。当霍尔传感器信号发生发生信号的变化就会触发中断在中断

kubelet组件的启动流程源码分析

概述 摘要: 本文将总结kubelet的作用以及原理,在有一定基础认识的前提下,通过阅读kubelet源码,对kubelet组件的启动流程进行分析。 正文 kubelet的作用 这里对kubelet的作用做一个简单总结。 节点管理 节点的注册 节点状态更新 容器管理(pod生命周期管理) 监听apiserver的容器事件 容器的创建、删除(CRI) 容器的网络的创建与删除

PostgreSQL核心功能特性与使用领域及场景分析

PostgreSQL有什么优点? 开源和免费 PostgreSQL是一个开源的数据库管理系统,可以免费使用和修改。这降低了企业的成本,并为开发者提供了一个活跃的社区和丰富的资源。 高度兼容 PostgreSQL支持多种操作系统(如Linux、Windows、macOS等)和编程语言(如C、C++、Java、Python、Ruby等),并提供了多种接口(如JDBC、ODBC、ADO.NET等

OpenCV结构分析与形状描述符(11)椭圆拟合函数fitEllipse()的使用

操作系统:ubuntu22.04 OpenCV版本:OpenCV4.9 IDE:Visual Studio Code 编程语言:C++11 算法描述 围绕一组2D点拟合一个椭圆。 该函数计算出一个椭圆,该椭圆在最小二乘意义上最好地拟合一组2D点。它返回一个内切椭圆的旋转矩形。使用了由[90]描述的第一个算法。开发者应该注意,由于数据点靠近包含的 Mat 元素的边界,返回的椭圆/旋转矩形数据