knitr::opts_chunk$set(echo = TRUE, fig.align = "center", fig.width = 4, fig.height = 4, 
                      warning = FALSE, error = FALSE, message = FALSE)
devtools::load_all("..")
library(dplyr)
library(purrr)
library(patchwork)

peak_list <- list.files("../testdata", "regions", full.names = T, recursive = T) %>%
  purrr::discard(~stringr::str_detect(string = .x, pattern = "tsv")) %>%
  purrr::set_names(c("PeakX", "PeakY")) 

Last updated: r Sys.Date()


Load plotmics

# load plotmics
library(plotmics)

Run ggVennBed()

ggVennBed() draws an Venn diagram plot with the intersections of two BED files (A and B). It counts the number of unique regions in A and B, as well as the regions from A intersecting with B and viceversa. It uses the function ggvenn() from the ggvenn package, and the function bt.intersect() from the bedtoolsr package.

Look at the ggvenn package documentation.

Look at the bedtoolsr package documentation.

Required input

As input, ggVennBed() takes two data frames in BED format or the paths to two BED-like files.

# Example input. 
regionsX_path = "../testdata/regionsX.bed"
regionsY_path = "../testdata/regionsY.bed"

regionsX = read.delim(regionsX_path, header = F)
regionsY = read.delim(regionsY_path, header = F)

head(regionsX)

Default run

You can run ggVennBed using the paths to two BED files:

ggVennBed(a = regionsX_path,  b = regionsY_path)

Or use two different data frames in BED-like format:

ggVennBed(a = regionsX,  b = regionsY)

Specify strandedness

By default, ggVennBed() intersects the regions with the same strandedness (bedtools intersect -s -u -a regionA -b regionB). To change this behaviour, change stranded to FALSE or NULL.

ggVennBed(a = regionsX,  b = regionsY, stranded = TRUE) + ggtitle("Intersection with the same strandednes") +
ggVennBed(a = regionsX,  b = regionsY, stranded = FALSE) + ggtitle("Intersection regardless the strand")

Customize plot

ggVennBed(a = regionsX,  b = regionsY, title = "This is a title", title_size = 15, title_face = "bold")

ggVennBed(a = regionsX,  b = regionsY, title = "This is a title", subtitle = "This is a subtitle")
ggVennBed(a = regionsX,  b = regionsY, title = "This is a title", subtitle = "This is a subtitle", subtitle_size = 15, subtitle_face = "bold")

ggVennBed(a = regionsX,  b = regionsY, color = c("red", "green"))
ggVennBed(a = regionsX,  b = regionsY, color = c("red", "green"), alpha = 0.2)

ggVennBed(a = regionsX,  b = regionsY, labsize = 10)

ggVennBed(a = regionsX,  b = regionsY, setnames = c("RegionX", "RegionsY"))
ggVennBed(a = regionsX,  b = regionsY, setnames = c("RegionX", "RegionsY"), namesize = 10)

Further costumization

Since ggVennBed() outputs a ggvenn-based Venn diagram and ggvenn is based in ggplot2, it can be further customized with scales, theme, etc...



amitjavilaventura/seqViewR documentation built on Nov. 21, 2023, 10:12 a.m.