欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

用于 STRING 分析的蛋白质相互作用网络 (PPI) R 语言可视化

最编程 2024-04-15 15:51:22
...
使用STRING构建蛋白互作网络(PPI)

STRING 链接 https://string-db.org/ 数据集我使用R语言包clusterProfiler中经常用作示例的基因列表 获取gene symbol的代码

library(clusterProfiler)
help(package="clusterProfiler")
library(DOSE)
data(geneList)
geneList
genelist<-names(geneList)[1:30]
gene.df<-bitr(genelist,fromType = "ENTREZID",
              toType = "SYMBOL",OrgDb = "org.Hs.eg.db")
gene.df
write.table(gene.df$SYMBOL,file="../../PPI_pra_example_gene_symbol.txt",
            row.names = F,quote = F,col.names = F)

将gene symbol上传到 STRING网站 得到结果

image.png

但是现在我想编辑这个图像,所以我就可以下载文件

image.png

通常可以把这个文件导入到Cytoscape软件里进行可视化,但是我昨天试了一下,没有找到批量分组添加颜色的办法,比如这个30个基因是我转录组差异分析得到的结果,其中10个上调表达基因,20个下调表达基因。我想给上调基因添加红色,下调基因添加蓝色。我不知道Cytoscape是否可以实现,反正我现在还不知道怎么实现。

下面记录自己用R语言的ggraph包的实现过程

准备数据
  • 基因列表文件 PPI_pra_example_gene_symbol.txt
  • PPI分析结果文件 string_interactions.tsv

初步结果

library(ggraph)
help(package="ggraph")
library(igraph)
nodes<-read.csv("../../PPI_pra_example_gene_symbol.txt",header=F)
links<-read.table("../../string_interactions.tsv",header=F,sep="t")
nodes
links
net<-graph_from_data_frame(d=links,vertices=nodes,directed = T)
plot(net)
ggraph(net,layout = "linear",circular=T)+
  geom_edge_link(color="blue")+
  geom_node_point(size=10,color="red",alpha=0.5)+
  theme_void()

image.png

image.png

ggraph(net,layout = "kk")+
  geom_edge_link(color="blue")+
  geom_node_point(size=10,color="red",alpha=0.5)+
  theme_void()

几个layout比较下来还是layout="kk"好看一点。

接下来试着添加基因名字并按照上调和下调添加颜色
library(ggraph)
help(package="ggraph")
library(igraph)
nodes<-read.csv("../../PPI_pra_example_gene_symbol.txt",header=F)
links<-read.table("../../string_interactions.tsv",header=F,sep="t")
nodes
links
nodes$Name<-nodes$V1
nodes$Group<-c(rep("Up",10),rep("Down",20))
net<-graph_from_data_frame(d=links,vertices=nodes,directed = T)
ggraph(net,layout = "kk")+
  geom_edge_link()+
  geom_node_point(size=10,aes(color=Group))+
  geom_node_text(aes(label=Name))+
  theme_void()

image.png

以上用到的数据大家可以自己准备,或者在我的公众号留言就可以了。