Search code examples
rbioinformaticsvenn-diagramrna-seqvenn

Extract values from each region of a venn diagram


enter image description here

I have 6 lists. Each contains genes of interest from a given condition. These six lists were then used to make a venn diagram in r using the venn package.

The venn diagram is precisely what I want, but now I would like to produce a list of genes from each section of the venn diagram. how do I do this? i.e. how do I figure out what genes from my lists comprise the 1251 genes that are present in each list/condition?

library(venn)

venn_list_no <- list(pt_v_lb = rownames(pt_v_lb_no), lbdm_v_lb = rownames(lbdm_v_lb_no), ptdm_v_lb = rownames(ptdm_v_lb_no), lbdm_v_pt = rownames(lbdm_v_pt_no), ptdm_v_pt = rownames(ptdm_v_pt_no), ptdm_v_lbdm = rownames(ptdm_v_lbdm_no))

venn(venn_list_no, zcolor = "style", ggplot = T, opacity = 0.2, box = F)+
  theme()

Solution

  • I have had a look at the package source and I cannot see any documented function to extract the elements in a region. In fact, the venn function does not return anything, so there is nothing you can check. You might want to try my nVennR package for that. At this time it is not available in CRAN, but you can install it from Github with devtools::install_github("vqf/nVennR"). An example:

    >library(nVennR)
    >myV <- plotVenn(list(set1=c(1, 2, 3), set2=c(2, 3, 4), set3=c(3, 4, 5, 'a', 'b'), set4=c(5, 6, 1, 4)))
    

    enter image description here

    >getVennRegion(myV, c('set2', 'set3', 'set4'))
    [1] 4
    
    >getVennRegion(myV, c('set3'))
    [1] "a" "b"
    
    >listVennRegions(myV)
    $`0, 0, 0, 1 (set4)`
    [1] 6
    
    $`0, 0, 1, 0 (set3)`
    [1] "a" "b"
    
    $`0, 0, 1, 1 (set3, set4)`
    [1] 5
    
    $`0, 1, 1, 1 (set2, set3, set4)`
    [1] 4
    
    $`1, 0, 0, 1 (set1, set4)`
    [1] 1
    
    $`1, 1, 0, 0 (set1, set2)`
    [1] 2
    
    $`1, 1, 1, 0 (set1, set2, set3)`
    [1] "3"
    

    You can see more examples at the vignette.