(转帖)有意思的-GO enrichment (Easier)

原文地址:https://mp.weixin.qq.com/s/cFX51WjlgS-SetbM8THqdg


上次给大家分享的绘制上下调基因GO富集图的方法好像还是比较麻烦,需要用到R和AI,还要自己调试参数,为了尽可能的方便大家,我从头用SVG写了一个脚本,你只需准备好配置文件一键即可得到你想要的图形。

首先还是讲一下配置文件的准备(这也是你唯一需要操心的地方了)。

这一次配置文件分为两个txt文档,分别存有上调和下调基因的GO富集结果,数据格式如下图所示:

(转帖)有意思的-GO enrichment (Easier)_第1张图片

左边是上调基因GO富集的结果,右边是下调基因GO富集的结果,每边1-4列分别是GO

terms, Gene number,

-log10(P-value)和fill(即第一行,作为列名),我是按的-log10(P-value)排序,选的top20的结果,这个可以自己定(但不要太多,比如top100。。。)(如果你想按照gene

number排序,只需要将第二列和第三列互换一下位置就好了,最后有演示)

颜色的选择建议使用http://colorbrewer2.org选择,具体使用方法如下:

(转帖)有意思的-GO enrichment (Easier)_第2张图片

在excel中编辑好文档后,将上下调基因GO富集结果分别复制粘贴到两个txt文档中,分别命名为up.txt,down.txt

(转帖)有意思的-GO enrichment (Easier)_第3张图片

保存好后,在同一目录下新建一个文本文档,将文末的代码复制粘贴到里面,保存,更改文件名为GO.R

(转帖)有意思的-GO enrichment (Easier)_第4张图片

然后右键,用R-studio打开,全选,Run

(转帖)有意思的-GO enrichment (Easier)_第5张图片

然后在同一目录下会生成一个GO.svg的文件,可以用Inkscape或者AI打开,直接另存为PDF即可。

然后,你就得到矢量图了

我是取得top20的,这个可以自己根据需要选择,比如我按基因数目排序选top15,换另外一种色系颜色,只需要修改配置文件就好了,不需要更改代码(知识点:配置文件是关键)。

R脚本:

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

# Author: Zhaodong Hao

# Create data: 2017-06-24

# Description: GO enrichment - 2

# Attention: you can use Inkscape or AI to open the output file (.svg) and save as a PDF file

# Contact: [email protected]

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

# set the working dictionary as the path of 'source'd file

whereFrom=sys.calls()[[1]]

# This should be an expression that looks something like

# source("pathname/myfilename.R")

whereFrom=as.character(whereFrom[2]) # get the pathname/filename

whereFrom=paste(getwd(),whereFrom,sep="/") # prefix it with the current working directory

pathnameIndex=gregexpr(".*/",whereFrom) # we want the string up to the final '/'

pathnameLength=attr(pathnameIndex[[1]],"match.length")

whereFrom=substr(whereFrom,1,pathnameLength-1)

setwd(whereFrom)

up_data_pre <- read.table("up.txt", sep = "\t")

up_data <- read.table("up.txt", sep = "\t", header = T)

colnames(up_data)

<- c(as.character(up_data_pre[1, 1]), as.character(up_data_pre[1,

2]), as.character(up_data_pre[1, 3]), as.character(up_data_pre[1, 4]))

down_data_pre <- read.table("down.txt", sep = "\t")

down_data <- read.table("down.txt", sep = "\t", header = T)

colnames(down_data)

<- c(as.character(down_data_pre[1, 1]),

as.character(down_data_pre[1, 2]), as.character(down_data_pre[1, 3]),

as.character(down_data_pre[1, 4]))

xlim_up_1 <-

ceiling(max(up_data[ ,2]) / (5 * 10 ^(nchar(ceiling(max(up_data[ ,2]))) -

2))) * (5 * 10 ^(nchar(ceiling(max(up_data[ ,2]))) - 2))

xlim_up_2

<- ceiling(max(up_data[ ,3]) / (5 * 10 ^(nchar(ceiling(max(up_data[

,3]))) - 2))) * (5 * 10 ^(nchar(ceiling(max(up_data[ ,3]))) - 2))

xlim_down_1

<- ceiling(max(down_data[ ,2]) / (5 * 10

^(nchar(ceiling(max(down_data[ ,2]))) - 2))) * (5 * 10

^(nchar(ceiling(max(down_data[ ,2]))) - 2))

xlim_down_2 <-

ceiling(max(down_data[ ,3]) / (5 * 10 ^(nchar(ceiling(max(down_data[

,3]))) - 2))) * (5 * 10 ^(nchar(ceiling(max(down_data[ ,3]))) - 2))

### rect model:

# x,y 矩形左上角点的坐标; rx,ry 圆角矩形;width,height 矩形的宽和高(从左上角的点向右向下延伸); fill 填充颜色;stroke 线的颜色;stroke-width 线的宽度;opacity 透明度

# up_data rect

for (i in 1:nrow(up_data)) {

  up_data[i, 5] <- 2.5 * 35.43307 + 1.5 * 35.43307 + (nrow(up_data[1:i,]) - 1) * (0.15 + 0.03) * 35.43307

}

names(up_data)[5] <- "y"

up_data$x <- (1.9 + 4 + 0.25) * 35.43307

for (i in 1:nrow(up_data)) {

  up_data[i, 7] <- up_data[i, 3] * (4 * 35.43307) / xlim_up_2

}

names(up_data)[7] <- "width"

up_data$rect

= paste("

width=\"", up_data$width,  "\" height=\"", 0.15 * 35.43307, "\"

style=\"fill:#", up_data$fill, "\"/>", sep = "")

# down_data rect

for (i in 1:nrow(down_data)) {

  down_data[i, 5] <- 2.5 * 35.43307 + 1.5 * 35.43307 + (nrow(down_data[1:i,]) - 1) * (0.15 + 0.03) * 35.43307

}

names(down_data)[5] <- "y"

for (i in 1:nrow(down_data)) {

  down_data[i, 6] <- (1.9 + 4 + 0.25 + 4 + 0.7 + 4) * 35.43307 - down_data[i, 3] * (4 * 35.43307) / xlim_down_2

}

names(down_data)[6] <- "x"

for (i in 1:nrow(down_data)) {

  down_data[i, 7] <- down_data[i, 3] * (4 * 35.43307) / xlim_down_2

}

names(down_data)[7] <- "width"

down_data$rect

= paste("

width=\"", down_data$width,  "\" height=\"", 0.15 * 35.43307, "\"

style=\"fill:#", down_data$fill, "\"/>", sep = "")

### polyline model:

# up_data polyline

for (i in 1:nrow(up_data)) {

  up_data[i, 9] = (1.9 + 4 + 0.25) * 35.43307 + up_data[i, 2] * (4 * 35.43307) / xlim_up_1

}

names(up_data)[9] <- "x1"

for (i in 1:nrow(up_data)) {

  up_data[i, 10] = 2.5 * 35.43307 + 1.5 * 35.43307 + 0.075 * 35.43307 + (nrow(up_data[1:i,]) - 1) * (0.15 + 0.03) * 35.43307

}

names(up_data)[10] <- "y1"

polyline_1

<- paste("

up_data$y1, sep = ""), collapse = " "), "\"

style=\"fill:white;stroke:black;stroke-width:0.8;fill-opacity:0\"/>")

# down_data polyline

for (i in 1:nrow(down_data)) {

  down_data[i, 9] = (1.9 + 4 + 0.25 + 4 + 0.7 + 4) * 35.43307 - down_data[i, 2] * (4 * 35.43307) / xlim_down_1

}

names(down_data)[9] <- "x1"

for (i in 1:nrow(down_data)) {

  down_data[i, 10] = 2.5 * 35.43307 + 1.5 * 35.43307 + 0.075 * 35.43307 + (nrow(down_data[1:i,]) - 1) * (0.15 + 0.03) * 35.43307

}

names(down_data)[10] <- "y1"

polyline_2

<- paste("

down_data$y1, sep = ""), collapse = " "), "\"

style=\"fill:white;stroke:black;stroke-width:0.8;fill-opacity:0\"/>")

polyline_left_1

<- paste("

+ max(up_data$width[1], up_data[1, 2] * (4 * 35.43307) / xlim_up_1) +

1/5 * (4 * 35.43307 - max(up_data$width[1], up_data[1, 2] * (4 *

35.43307) / xlim_up_1)), up_data$y1[1], sep = ","),

                         paste((1.9 + 4 + 0.25 + 4) * 35.43307, up_data$y1[1], sep = ","), 

                         paste((1.9 + 4 + 0.25 + 4) * 35.43307, up_data$y1[nrow(up_data)/3], sep = ","), 


                       paste((1.9 + 4 + 0.25) * 35.43307 +

max(up_data$width[nrow(up_data)/3], up_data[nrow(up_data)/3, 2] * (4 *

35.43307) / xlim_up_1) + 1/5 * (4 * 35.43307 -

max(up_data$width[nrow(up_data)/3], up_data[nrow(up_data)/3, 2] * (4 *

35.43307) / xlim_up_1)), up_data$y1[nrow(up_data)/3], sep = ","),

                         "\" style=\"fill:white;stroke:black;stroke-width:0.5;fill-opacity:0\"/>")

polyline_left_2

<- paste("

+ max(up_data$width[nrow(up_data)/3 + 1], up_data[nrow(up_data)/3 + 1,

2] * (4 * 35.43307) / xlim_up_1) + 1/5 * (4 * 35.43307 -

max(up_data$width[nrow(up_data)/3 + 1], up_data[nrow(up_data)/3 + 1, 2] *

(4 * 35.43307) / xlim_up_1)), up_data$y1[nrow(up_data)/3 + 1], sep =

","),

                         paste((1.9 + 4 + 0.25 + 4) * 35.43307, up_data$y1[nrow(up_data)/3 + 1], sep = ","), 

                         paste((1.9 + 4 + 0.25 + 4) * 35.43307, up_data$y1[nrow(up_data)/3 * 2], sep = ","), 


                       paste((1.9 + 4 + 0.25) * 35.43307 +

max(up_data$width[nrow(up_data)/3 * 2], up_data[nrow(up_data)/3 * 2, 2] *

(4 * 35.43307) / xlim_up_1) + 1/5 * (4 * 35.43307 -

max(up_data$width[nrow(up_data)/3 * 2], up_data[nrow(up_data)/3 * 2, 2] *

(4 * 35.43307) / xlim_up_1)), up_data$y1[nrow(up_data)/3 * 2], sep =

","),

                         "\" style=\"fill:white;stroke:black;stroke-width:0.5;fill-opacity:0\"/>")

polyline_left_3

<- paste("

+ max(up_data$width[nrow(up_data)/3 * 2 + 1], up_data[nrow(up_data)/3 *

2 + 1, 2] * (4 * 35.43307) / xlim_up_1) + 1/5 * (4 * 35.43307 -

max(up_data$width[nrow(up_data)/3 * 2 + 1], up_data[nrow(up_data)/3 * 2 +

1, 2] * (4 * 35.43307) / xlim_up_1)), up_data$y1[nrow(up_data)/3 * 2 +

1], sep = ","),

                         paste((1.9 + 4 + 0.25 + 4) * 35.43307, up_data$y1[nrow(up_data)/3 * 2 + 1], sep = ","), 

                         paste((1.9 + 4 + 0.25 + 4) * 35.43307, up_data$y1[nrow(up_data)/3 * 3], sep = ","), 


                       paste((1.9 + 4 + 0.25) * 35.43307 +

max(up_data$width[nrow(up_data)/3 * 3], up_data[nrow(up_data)/3 * 3, 2] *

(4 * 35.43307) / xlim_up_1) + 1/5 * (4 * 35.43307 -

max(up_data$width[nrow(up_data)/3 * 3], up_data[nrow(up_data)/3 * 3, 2] *

(4 * 35.43307) / xlim_up_1)), up_data$y1[nrow(up_data)/3 * 3], sep =

","),

                         "\" style=\"fill:white;stroke:black;stroke-width:0.5;fill-opacity:0\"/>")

polyline_right_1

<- paste("

35.43307 + 4/5 * (4 * 35.43307 - max(down_data$width[1], down_data[1,

2] * (4 * 35.43307) / xlim_down_1)), down_data$y1[1], sep = ","),

                          paste((1.9 + 4 + 0.25 + 4 + 0.7) * 35.43307, down_data$y1[1], sep = ","), 

                          paste((1.9 + 4 + 0.25 + 4 + 0.7) * 35.43307, down_data$y1[nrow(down_data)/3], sep = ","), 


                        paste((1.9 + 4 + 0.25 + 4 + 0.7) * 35.43307 +

4/5 * (4 * 35.43307 - max(down_data$width[nrow(down_data)/3],

down_data[nrow(down_data)/3, 2] * (4 * 35.43307) / xlim_down_1)),

down_data$y1[nrow(down_data)/3], sep = ","),

                          "\" style=\"fill:white;stroke:black;stroke-width:0.5;fill-opacity:0\"/>")

polyline_right_2

<- paste("

35.43307 + 4/5 * (4 * 35.43307 - max(down_data$width[nrow(up_data)/3 +

1], down_data[nrow(up_data)/3 + 1, 2] * (4 * 35.43307) / xlim_down_1)),

down_data$y1[nrow(up_data)/3 + 1], sep = ","),

                          paste((1.9 + 4 + 0.25 + 4 + 0.7) * 35.43307, down_data$y1[nrow(up_data)/3 + 1], sep = ","), 

                          paste((1.9 + 4 + 0.25 + 4 + 0.7) * 35.43307, down_data$y1[nrow(down_data)/3 * 2], sep = ","), 


                        paste((1.9 + 4 + 0.25 + 4 + 0.7) * 35.43307 +

4/5 * (4 * 35.43307 - max(down_data$width[nrow(down_data)/3 * 2],

down_data[nrow(down_data)/3 * 2, 2] * (4 * 35.43307) / xlim_down_1)),

down_data$y1[nrow(down_data)/3 * 2], sep = ","),

                          "\" style=\"fill:white;stroke:black;stroke-width:0.5;fill-opacity:0\"/>")

polyline_right_3

<- paste("

35.43307 + 4/5 * (4 * 35.43307 - max(down_data$width[nrow(up_data)/3 * 2

+ 1], down_data[nrow(up_data)/3 * 2 + 1, 2] * (4 * 35.43307) /

xlim_down_1)), down_data$y1[nrow(up_data)/3 * 2 + 1], sep = ","),

                          paste((1.9 + 4 + 0.25 + 4 + 0.7) * 35.43307, down_data$y1[nrow(up_data)/3 * 2 + 1], sep = ","), 

                          paste((1.9 + 4 + 0.25 + 4 + 0.7) * 35.43307, down_data$y1[nrow(down_data)/3 * 3], sep = ","), 


                        paste((1.9 + 4 + 0.25 + 4 + 0.7) * 35.43307 +

4/5 * (4 * 35.43307 - max(down_data$width[nrow(down_data)/3 * 3],

down_data[nrow(down_data)/3 * 3, 2] * (4 * 35.43307) / xlim_down_1)),

down_data$y1[nrow(down_data)/3 * 3], sep = ","),

                          "\" style=\"fill:white;stroke:black;stroke-width:0.5;fill-opacity:0\"/>")

### line model:

# up_data y-ticks

up_data$Y_ticks

<- paste("

x2=\"", up_data$x - 0.15 * 35.43307, "\" y2=\"", up_data$y1, "\"

style=\"stroke:black;stroke-width:0.5\"/>", sep = "")

# down_data y-ticks

down_data$Y_ticks

<- paste("

y1=\"", down_data$y1, "\" x2=\"", (17.2 + 1.9 - 4 - 0.1) * 35.43307, "\"

y2=\"", down_data$y1, "\"

style=\"stroke:black;stroke-width:0.5\"/>", sep = "")

# up_data x & -ticks_bottom

up_data_x_bottom

<- paste("

1.5 * 35.43307 + nrow(up_data) * (0.15 + 0.03) * 35.43307 + 0.03 *

35.43307, "\" x2=\"", 217.9134 + 4 * 35.43307, "\" y2=\"", 2.5 *

35.43307 + 1.5 * 35.43307 + nrow(up_data) * (0.15 + 0.03) * 35.43307 +

0.03 * 35.43307, "\" style=\"stroke:black;stroke-width:1\"/>", sep =

"")

up_data_x_ticks_bottom <- data.frame(seq(0, xlim_up_2, xlim_up_2 / 5))

up_data_x_ticks_bottom$ticks

<- paste("

up_data_x_ticks_bottom[,1] * (4 * 35.43307) / xlim_up_2, "\" y1=\"", 2.5

* 35.43307 + 1.5 * 35.43307 + nrow(up_data) * (0.15 + 0.03) * 35.43307 +

0.03 * 35.43307, "\" x2=\"", (1.9 + 4 + 0.25) * 35.43307 +

up_data_x_ticks_bottom[,1] * (4 * 35.43307) / xlim_up_2, "\" y2=\"", 2.5

* 35.43307 + 1.5 * 35.43307 + nrow(up_data) * (0.15 + 0.03) * 35.43307 +

0.15 * 35.43307 + 0.03 * 35.43307, "\"

style=\"stroke:black;stroke-width:0.5\"/>", sep = "")

# down_data x & -ticks_bottom

down_data_x_bottom

<- paste("

1.5 * 35.43307 + nrow(down_data) * (0.15 + 0.03) * 35.43307 + 0.03 *

35.43307, "\" x2=\"", 384.4488 + 4 * 35.43307, "\" y2=\"", 2.5 *

35.43307 + 1.5 * 35.43307 + nrow(down_data) * (0.15 + 0.03) * 35.43307 +

0.03 * 35.43307, "\" style=\"stroke:black;stroke-width:1\"/>", sep =

"")

down_data_x_ticks_bottom <- data.frame(seq(0, xlim_down_2, xlim_down_2 / 5))

down_data_x_ticks_bottom$ticks

<- paste("

down_data_x_ticks_bottom[,1] * (4 * 35.43307) / xlim_down_2, "\" y1=\"",

2.5 * 35.43307 + 1.5 * 35.43307 + nrow(down_data) * (0.15 + 0.03) *

35.43307 + 0.03 * 35.43307, "\" x2=\"", (17.2 + 1.9 - 4 - 0.25) *

35.43307 - down_data_x_ticks_bottom[,1] * (4 * 35.43307) / xlim_down_2,

"\" y2=\"", 2.5 * 35.43307 + 1.5 * 35.43307 + nrow(down_data) * (0.15 +

0.03) * 35.43307 + 0.15 * 35.43307 + 0.03 * 35.43307, "\"

style=\"stroke:black;stroke-width:0.5\"/>", sep = "")

# up_data x & -ticks_top

up_data_x_top

<- paste("

1.5 * 35.43307 - (0.03 + 0.03) * 35.43307, "\" x2=\"", 217.9134 + 4 *

35.43307, "\" y2=\"", 2.5 * 35.43307 + 1.5 * 35.43307 - (0.03 + 0.03) *

35.43307, "\" style=\"stroke:black;stroke-width:1\"/>", sep = "")

up_data_x_ticks_top <- data.frame(seq(0, xlim_up_1, xlim_up_1 / 5))

up_data_x_ticks_top$ticks

<- paste("

up_data_x_ticks_top[,1] * (4 * 35.43307) / xlim_up_1, "\" y1=\"", 2.5 *

35.43307 + 1.5 * 35.43307 - (0.03 + 0.03) * 35.43307, "\" x2=\"", (1.9 +

4 + 0.25) * 35.43307 + up_data_x_ticks_top[,1] * (4 * 35.43307) /

xlim_up_1, "\" y2=\"", 2.5 * 35.43307 + 1.5 * 35.43307 - (0.03 + 0.03) *

35.43307 - 0.15 * 35.43307, "\"

style=\"stroke:black;stroke-width:0.5\"/>", sep = "")

# down_data x & -ticks_top

down_data_x_top

<- paste("

1.5 * 35.43307 - (0.03 + 0.03) * 35.43307, "\" x2=\"", 384.4488 + 4 *

35.43307, "\" y2=\"", 2.5 * 35.43307 + 1.5 * 35.43307 - (0.03 + 0.03) *

35.43307, "\" style=\"stroke:black;stroke-width:1\"/>", sep = "")

down_data_x_ticks_top <- data.frame(seq(0, xlim_down_1, xlim_down_1 / 5))

down_data_x_ticks_top$ticks

<- paste("

down_data_x_ticks_top[,1] * (4 * 35.43307) / xlim_down_1, "\" y1=\"",

2.5 * 35.43307 + 1.5 * 35.43307 - (0.03 + 0.03) * 35.43307, "\" x2=\"",

(17.2 + 1.9 - 4 - 0.25) * 35.43307 - down_data_x_ticks_top[,1] * (4 *

35.43307) / xlim_down_1, "\" y2=\"", 2.5 * 35.43307 + 1.5 * 35.43307 -

(0.03 + 0.03) * 35.43307 - 0.15 * 35.43307, "\"

style=\"stroke:black;stroke-width:0.5\"/>", sep = "")

### text model

up_data_x_ticks_bottom$text

<- paste("

up_data_x_ticks_bottom[,1] * (4 * 35.43307) / xlim_up_2 -

nchar(up_data_x_ticks_bottom[,1]) * 2, "\" y=\"", 2.5 * 35.43307 + 1.5 *

35.43307 + nrow(up_data) * (0.15 + 0.03) * 35.43307 + 0.03 * 35.43307 +

0.5 * 35.43307, "\" font-family=\"Arial\" font-size=\"8\"

fill=\"black\" >", up_data_x_ticks_bottom[,1], "", sep =

"")

down_data_x_ticks_bottom$text <- paste("

(17.2 + 1.9 - 4 - 0.25) * 35.43307 - down_data_x_ticks_bottom[,1] * (4 *

35.43307) / xlim_down_2 - nchar(down_data_x_ticks_bottom[,1]) * 2, "\"

y=\"", 2.5 * 35.43307 + 1.5 * 35.43307 + nrow(down_data) * (0.15 + 0.03)

* 35.43307 + 0.03 * 35.43307 + 0.5 * 35.43307, "\"

font-family=\"Arial\" font-size=\"8\" fill=\"black\" >",

down_data_x_ticks_bottom[,1], "", sep = "")

up_data_x_ticks_top$text

<- paste("

up_data_x_ticks_top[,1] * (4 * 35.43307) / xlim_up_1 -

nchar(up_data_x_ticks_top[,1]) * 2, "\" y=\"", 2.5 * 35.43307 + 1.5 *

35.43307 - (0.03 + 0.03) * 35.43307 - 0.25 * 35.43307, "\"

font-family=\"Arial\" font-size=\"8\" fill=\"black\" >",

up_data_x_ticks_top[,1], "", sep = "")

down_data_x_ticks_top$text

<- paste("

down_data_x_ticks_top[,1] * (4 * 35.43307) / xlim_down_1 -

nchar(down_data_x_ticks_top[,1]) * 2, "\" y=\"", 2.5 * 35.43307 + 1.5 *

35.43307 - (0.03 + 0.03) * 35.43307 - 0.25 * 35.43307, "\"

font-family=\"Arial\" font-size=\"8\" fill=\"black\" >",

down_data_x_ticks_top[,1], "", sep = "")

up_data$text

<- paste("

up_data$y1 + 0.075 * 35.43307, "\" text-anchor=\"end\"

font-family=\"Arial\" font-size=\"6\" fill=\"black\" >", up_data[

,1], "", sep = "")

down_data$text <-

paste("

down_data$y1 + 0.075 * 35.43307, "\" font-family=\"Arial\"

font-size=\"6\" fill=\"black\" >", down_data[ ,1], "",

sep = "")

labels <- data.frame(paste("

0.25 + 4) * 35.43307, "\" y=\"", 2.5 * 35.43307 + 1.5 * 35.43307 +

nrow(up_data) * (0.15 + 0.03) * 35.43307 + 0.03 * 35.43307 + 1 *

35.43307, "\" text-anchor=\"end\" font-family=\"Arial\" font-size=\"8\"

fill=\"black\" >", colnames(up_data)[3], "", sep = ""),


                   paste("

35.43307, "\" y=\"", 2.5 * 35.43307 + 1.5 * 35.43307 + nrow(up_data) *

(0.15 + 0.03) * 35.43307 + 0.03 * 35.43307 + 1 * 35.43307, "\"

font-family=\"Arial\" font-size=\"8\" fill=\"black\" >",

colnames(down_data)[3], "", sep = ""),


     paste("

2.5 * 35.43307 + 1.5 * 35.43307 - (0.03 + 0.03) * 35.43307 - 0.25 *

35.43307 - 0.5 * 35.43307, "\" text-anchor=\"end\" font-family=\"Arial\"

font-size=\"8\" fill=\"black\" >", colnames(up_data)[2],

"", sep = ""),

                     paste("

x=\"", (1.9 + 4 + 0.25 + 4 + 0.7) * 35.43307, "\" y=\"", 2.5 * 35.43307 +

1.5 * 35.43307 - (0.03 + 0.03) * 35.43307 - 0.25 * 35.43307 - 0.5 *

35.43307, "\" font-family=\"Arial\" font-size=\"8\" fill=\"black\"

>", colnames(down_data)[2], "", sep = "")

)

BP

<- paste("

"\" y=\"", (up_data$y1[nrow(up_data)/3] - up_data$y1[1])/2 +

up_data$y1[1] + 0.075 * 35.43307, "\" text-anchor=\"middle\"

font-family=\"Arial\" font-size=\"8\" fill=\"black\"

>BP", sep = "")

CC <- paste("

(1.9 + 4 + 0.25 + 4 + 0.35) * 35.43307, "\" y=\"",

(up_data$y1[nrow(up_data)/3 * 2] - up_data$y1[nrow(up_data)/3])/2 +

up_data$y1[nrow(up_data)/3] + 0.075 * 35.43307, "\"

text-anchor=\"middle\" font-family=\"Arial\" font-size=\"8\"

fill=\"black\" >CC", sep = "")

MF <-

paste("

y=\"", (up_data$y1[nrow(up_data)/3 * 3] - up_data$y1[nrow(up_data)/3 *

2])/2 + up_data$y1[nrow(up_data)/3 * 2] + 0.075 * 35.43307, "\"

text-anchor=\"middle\" font-family=\"Arial\" font-size=\"8\"

fill=\"black\" >MF", sep = "")

# write .svg file

first_line <- data.frame("",

                         "

                         "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">",

                         "",

                         paste("", "\t")

)

write.table(first_line[1, 1], "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE)

write.table(first_line[1, 2], "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(first_line[1, 3], "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(first_line[1, 4], "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(first_line[1, 5], "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(up_data$rect, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(down_data$rect, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(polyline_1, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(polyline_2, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(polyline_left_1, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(polyline_left_2, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(polyline_left_3, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(polyline_right_1, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(polyline_right_2, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(polyline_right_3, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(up_data$Y_ticks, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(down_data$Y_ticks, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(up_data_x_bottom, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(up_data_x_ticks_bottom$ticks, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(down_data_x_bottom, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(down_data_x_ticks_bottom$ticks, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(up_data_x_top, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(up_data_x_ticks_top$ticks, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(down_data_x_top, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(down_data_x_ticks_top$ticks, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(up_data_x_ticks_bottom$text, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(down_data_x_ticks_bottom$text, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(up_data_x_ticks_top$text, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(down_data_x_ticks_top$text, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(up_data$text, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(down_data$text, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(labels, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(BP, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(CC, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

write.table(MF, "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

last_line <- data.frame(paste(""))

write.table(last_line[1, 1], "GO.svg", col.names = FALSE, row.names = FALSE, quote = FALSE, append = TRUE)

脚本比较长,不过你们完全不需要看,只要复制粘贴一下就OK啦

P.S. 想看懂代码的可以先学一学基础的R处理数据和SVG脚本(http://tutorials.jenkov.com/svg/index.html)。另外,百度云里面我放了R脚本和示例文件哦(链接: https://pan.baidu.com/s/1geLSbpL 密码: b7wn)。目前我测试了几次数据,只要配置文件没问题应该就没问题了,后期有问题的可以发我邮箱([email protected]),欢迎提问,共同进步!

你可能感兴趣的:((转帖)有意思的-GO enrichment (Easier))