How to get the list of common genes from a VennDiagram?
1
5
Entering edit mode
4.3 years ago
WUSCHEL ▴ 750

**Package ‘![VennDiagram][1]’.** How can I get the list of common objects in each combination?

For e.g. what are the common 44 Genes in interset (similar image got from online)?

venn

I have used below scripts

Overlap <- calculate.overlap(x = list(BB, BB, BRR))

Overlap[[1]]

But in this method, I can not find the list of 1761, 466 genes

how these numbers are given?

Even when I tried Overlap$a5 , Overlap$a7, etc this also not given some of the values correctly?

Could someone help me?

RNA-Seq R • 9.6k views
ADD COMMENT
1
Entering edit mode

Provide example data, calculate.overlap does exactly what you need, try the examples from the manuals. Also, why BB is repeated twice?

If you need just the overlap of genes from 3 sets, try:

intersect(intersect(1:4, 2:5), 3:7)
# [1] 3 4

Or more generic solution:

Reduce(intersect, list(1:4, 2:5, 3:7))
# [1] 3 4
ADD REPLY
4
Entering edit mode
4.3 years ago

From what I can tell, the as are distributed from top left to right, to bottom. i.e. a1 = 1761 a2=126 a3=466 a4=64 a5=44 a6=27 a7=366

This is based on: enter image description here

> library("VennDiagram")
> 
> gene_list = paste0("GENE", 1:1000)
> 
> studies = list( S1=sample(gene_list, 700, replace = FALSE),
+                 S2=sample(gene_list, 700, replace = FALSE),
+                 S3=sample(gene_list, 700, replace = FALSE) )
> 
> ol = calculate.overlap(x = studies)
> ol_size=sapply(ol, length)
> 
> 
> venn.diagram(
+   x = studies,
+   euler.d = TRUE,
+   filename = "Euler_3set_scaled.tiff",
+   cex = 2.5,
+   cat.cex = 2.5,
+   cat.pos = 0
+ );
[1] 1
> # Get the 63
> length( setdiff(studies$S1, union(studies$S2, studies$S3)) )
[1] 63
> # Confirm order
> ol_size
 a5  a2  a4  a6  a1  a3  a7 
351 143 143 134  63  72  72

And it matches the order from a1 to a7 going left-right, top-bottom.

If you want to be sure of what you're getting, you can use set operators like I did with setdiff() and union().

ADD COMMENT
1
Entering edit mode

Probably, this is another way:

t=get.venn.partitions(studies, keep.elements = T, force.unique = T)
t$..values..[1] # To get all common genes
t$..set..
[1] "S1∩S2∩S3"     "(S2∩S3)∖(S1)" "(S1∩S3)∖(S2)" "(S3)∖(S1∪S2)"
[5] "(S1∩S2)∖(S3)" "(S2)∖(S1∪S3)" "(S1)∖(S2∪S3)"

 ol_size
 a5  a2  a4  a6  a1  a3  a7 
338 148 154 145  60  69  63 
 lengths(t$..values..[1])
  1 
338

OP can edit this code for better. Remove lengths to print the gene list:

> for (length in (1:length(t$..set..))) {
+     print (paste(t$..set..[length], lengths(t$..values..[length])), sep="\t")
+ }
[1] "S1∩S2∩S3 338"
[1] "(S2∩S3)∖(S1) 145"
[1] "(S1∩S3)∖(S2) 154"
[1] "(S3)∖(S1∪S2) 63"
[1] "(S1∩S2)∖(S3) 148"
[1] "(S2)∖(S1∪S3) 69"
[1] "(S1)∖(S2∪S3) 60"
ADD REPLY

Login before adding your answer.

Traffic: 1649 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6