generate venn diagram in R

Our DGE project report provide a differently expressing genes list which is infered using DEGseq. When I was trying to follow the analysis pipline, I found that DEGseq has a so simple document that I cannot even figure out how to apply the function in my work, then I turn to DESeq, which provide a very good document with explanation of options and typical cases. Now I have to DG(Different Gene)lists: one from NOvogene, another is mine(generated by DESeq). Some genes are the same in them, while some not. My goal is to identify the same and plot a venn diagram. Here is the outline:

  • idnetify the same genes, calculate the number of same and different genes.
  • draw a venn diagram in R to display above result.

DEGseq list has 2k+ genes, and my DESeq list has 1230 genes, obviously I need a quick script to compare each gene in DESeq and remember the number of genes in both.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import sys



dfgnlist1 = sys.argv[1]

dfgnlist2 = sys.argv[2]

with open(dfgnlist2, 'r') as deg:

dfgn2 = deg.readlines()

with open(dfgnlist1,'r') as de:

dfgn1 =de.readlines()
i = 0

j = 0

for g in dfgn1:

if g in dfgn2:

with open("samegenes.txt",'a') as samegenes:

samegenes.write(g)

i += 1

else:

with open("dfgenes.txt",'a') as dfgenes:

dfgenes.write(g)

j += 1
print '========'

print i, 'same genes'

print j, 'different genes'

Now I the number, time to fire up R and begin ploting. There are at least two ways to plot venn diagram, let us begin with a simpler one:

1
2
3
4
5
6
7
require(venneuler)

v <- venneuler(c(DEGseq=2635, DESeq=1230, "DEGseq&DESeq"=967))

plot(v)

dev.copy2pdf(file="secVenneuler.pdf")

Need no extra comments, just so intuitive. Cannot wait to dive in? ok, here it is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
require(VennDiagram)

venn.plot <- draw.pairwise.venn(

1230,2635,967, c("DESeq", "DEGseq"), #first for DESeq, second for DEGseq DEGseq, and third is num that both have.
#The last vector specify circle lables.

fill = c("green",'red'),

alpha = c(0.5,0.5),

cex = 2, lty = 2) #lty for circles line type

dev.copy2pdf(file='sec6VennDiagram.pdf')

There are more options and more functions in VennDiagram, check out the help manual if you want.