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) peak_list <- list.files("../testdata", "peak", full.names = T, recursive = T) %>% purrr::discard(~stringr::str_detect(string = .x, pattern = "bed")) %>% purrr::set_names(c("PeakX", "PeakY")) %>% purrr::map(~read.delim(.x)) ggUpsetPeaks(peak_list)
Last updated: r Sys.Date()
plotmics
# load plotmics library(plotmics)
ggUpsetPeaks()
ggUpsetPeaks()
draws an UpSet plot with the intersections between different sets of peaks using the function getVennCounts()
(which calls ChIPpeakAnno::makeVennDiagram()
), builds each part of the plot separatelly using ggplot2
and puts all plots together using patchwork
.
Look at the patchwork
package documentation
Look at the makeVennDiagram()
function documentation
As input, ggUpsetPeaks()
takes a named list of data frames with the columns seqnames
, start
and end
.
# read the peak annotation into a list peak_list <- list.files("../testdata", "peak", full.names = T, recursive = T) %>% purrr::discard(~stringr::str_detect(string = .x, pattern = "bed")) %>% purrr::set_names(c("PeakX", "PeakY")) %>% purrr::map(~read.delim(.x)) peak_list[[1]][1:5, 1:7]
getVennCounts()
getVennCounts()
calls ChIPpeakAnno::makeVennDiagram()
, retrieves the Venn counts (number of overlaps between different sets of peaks) and builds a matrix of the peaks present in each set.
venn_counts <- getVennCounts(peak_list)
venn_counts$vennCounts # PeakX PeakY Counts # [1,] 0 0 0 # [2,] 0 1 70 # [3,] 1 0 977 # [4,] 1 1 23 # attr(,"class") # [1] "VennCounts"
venn_counts$matrix[1:5,] # peak PeakX PeakY # peak1 0 1 # peak2 0 1 # peak3 0 1 # peak4 0 1 # peak5 0 1
ggUpsetPeaks()
calls the function getVennCounts()
and builds the UpSet plot of the peaks using the Venn counts.
As mentioned, ChIPpeakAnno::makeVennDiagram()
is called inside getVennCounts()
. This function may have a unexpected outputs when considering the number of overlaps to build the intersection between different sets of regions. Considering the following example:
ggVennCounts()
we would get 1 unique region from A, one unique region from B and 2 intersections. The sum of any of them is not the total size of A or B.ggUpsetPeaks(peak_list)
ggUpsetPeaks(peak_list, conds = c("Condition_1", "Condition_2"))
#ggUpsetPeaks(peak_list, conds = c("Condition_1", "Condition_2"), conds_order = c("Condition_2", "Condition_1"))
ggUpsetPeaks(peak_list, order_by_freq = F)
ggUpsetPeaks(peak_list, num_size = 10)
ggUpsetPeaks(peak_list, title = "This is a title", subtitle = "This is a subtitle", caption = "This is a caption", )
Since ggUpsetPeaks()
outputs a ggplot2
- and patchwork
-based UpSet plot, it can be further customized with scales
or theme
and using the patchwork
syntax.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.