separate {tidyr}的功能是使用正则表达式分隔符将字符列分隔成多个列。给定正则表达式或字符位置向量,separate()将单个字符列转换为多个列。这个功能在生信分析中用到的频率太多了,比如TCGA的基因ID转换中ENSG00000000003.13转换成ENSG00000000003,比如对TCGA样本的ID切割等等。
separate(data, col, into, sep = “[1]+”, remove = TRUE, convert = FALSE, extra = “warn”, fill = “warn”, …)
rm(list = ls())#一键清空
library(tidyr)
library(dplyr)
library(ggplot2)```
```r
kegg <- read.csv("C:/Users/xxy/kangyuan/服务器/JZ20231023/M1 vs M2/JZ.M1.M2.high.KEGG.csv",header=TRUE)
kegg <- read.csv("C:/Users/xxy/kangyuan/服务器/JZ20231023/M1 vs M2/JZ.M1.M2.high.GO.csv",header=TRUE)```
```r
#【kegg拆分】
kegg = separate(kegg,Term, sep=":",into=c("ID","Description"))
kegg_top15 <- head(kegg,n=15)
#【go拆分】
kegg = separate(kegg,Term, sep="~",into=c("ID","Description"))
kegg_top15 <- head(kegg,n=15)```
```r#DAVID格式【表中%代表gene ratio,表需拆分!】
###DAVID_GO
kegg_plot_top15 <- ggplot(data = kegg_top15,aes(x=X.,y =Description))+
geom_point(aes(size=Count,color=-1*log10(PValue)))+
scale_color_gradient(low="green",high = "red")+
labs(color=expression(-log[10](PValue)),size="Count",x="enrichment factor",y=" GO term ")+
theme_bw()+
theme(axis.title.x = element_text(size = 10,color = "black"),
axis.title.y = element_text(size = 10,color = "black"),
axis.text.x = element_text(size=10,color = "black"),
axis.text.y = element_text(size = 10,color = "black"))
ggsave(kegg_plot_top15,width = 10,height = 10,scale = 1,filename = "JZ_M1M2_high_kegg.tiff")
ggsave(kegg_plot_top15,width = 10,height = 10,scale = 1,filename = "JZ_M1M2_high_kegg.png")
ggsave(kegg_plot_top15,width = 10,height = 10,scale = 1,filename = "JZ_M1M2_high_kegg.pdf")
###DAVID_KEGG
kegg_plot_top15 <- ggplot(data = kegg_top15,aes(x=X.,y =Description))+
geom_point(aes(size=Count,color=-1*log10(PValue)))+
scale_color_gradient(low="green",high = "red")+
labs(color=expression(-log[10](PValue)),size="Count",x="enrichment factor",y=" Pathways ")+
theme_bw()+
theme(axis.title.x = element_text(size = 15,color = "black"),
axis.title.y = element_text(size = 15,color = "black"),
axis.text.x = element_text(size=15,color = "black"),
axis.text.y = element_text(size = 15,color = "black"))
ggsave(kegg_plot_top15,width = 10,height = 10,scale = 1,filename = "JZ_M1M2_high_kegg.tiff")
ggsave(kegg_plot_top15,width = 10,height = 10,scale = 1,filename = "JZ_M1M2_high_kegg.png")
ggsave(kegg_plot_top15,width = 10,height = 10,scale = 1,filename = "JZ_M1M2_high_kegg.pdf")```
:alnum: ↩︎