Title: | Set Operations for Many Sets |
---|---|
Description: | Set operations for many sets. The base functions for set operations in R can be used for only two sets. This package uses 'purr' to find the union, intersection and difference of three or more sets. This package also provides functions for pairwise set operations among several sets. Further, based on 'ggplot2' and 'ggforce', a Venn diagram can be drawn for two or three sets. For bigger data sets, a clustered heatmap showing presence/absence of the elements of the sets can be drawn based on the 'pheatmap' package. Finally, enrichment test can be applied to two sets whether an overlap is statistically significant or not. |
Authors: | Turgut Yigit Akyol [aut, cre] |
Maintainer: | Turgut Yigit Akyol <[email protected]> |
License: | GPL-3 |
Version: | 1.1.0 |
Built: | 2024-11-24 04:10:37 UTC |
Source: | https://github.com/cran/RVenn |
discern_pairs
returns the pairwise differences of the sets in a
Venn
object.
## S4 method for signature 'Venn' discern_pairs(venn, slice = "all")
## S4 method for signature 'Venn' discern_pairs(venn, slice = "all")
venn |
(Required) A |
slice |
(Optional) The names or the indices of sets of interest. Default is "all", meaning the pairwise differences will be calculated for all the sets. |
A list showing the pairwise differences of the sets.
venn = Venn(list(letters[1:10], letters[3:12], letters[6:15], letters[9:18])) discern_pairs(venn) discern_pairs(venn, slice = 1:3)
venn = Venn(list(letters[1:10], letters[3:12], letters[6:15], letters[9:18])) discern_pairs(venn) discern_pairs(venn, slice = 1:3)
discern
returns the difference between two group of sets selected from
a Venn
object. If multiple sets are chosen for the slices, union of
those sets will be used.
## S4 method for signature 'Venn' discern(venn, slice1, slice2 = "all")
## S4 method for signature 'Venn' discern(venn, slice1, slice2 = "all")
venn |
(Required) A |
slice1 |
(Required) The name or the index of the set of interest. Multiple sets can be selected. |
slice2 |
(Optional) The name or the index of the set of interest. Multiple sets can be selected. Default is all the sets except the sets of slice1. |
A vector showing the difference between slice1 and slice2.
venn = Venn(list(letters[1:10], letters[3:12], letters[6:15])) discern(venn, slice1 = 1) discern(venn, slice1 = c(1, 2), slice2 = 3)
venn = Venn(list(letters[1:10], letters[3:12], letters[6:15])) discern(venn, slice1 = 1) discern(venn, slice1 = c(1, 2), slice2 = 3)
Calculate the p-value of occurrence of an overlap between two sets by chance.
## S4 method for signature 'Venn' enrichment_test(venn, set1, set2, univ = "all", n = 10000, seed = 42)
## S4 method for signature 'Venn' enrichment_test(venn, set1, set2, univ = "all", n = 10000, seed = 42)
venn |
(Required) A |
set1 |
(Required) The name or the index of the set of interest. |
set2 |
(Required) The name or the index of the set to be checked whether
enriched in |
univ |
(Optional) Population size. Default is "all", implying the union
of all the sets in the |
n |
(Optional) Number of randomly generated sets. Default is 10,000 and minimum is 1,000. |
seed |
(Optional) An integer passed to set.seed function. It is used to fix a seed for reproducibly random number generation. Default is 42. |
This type of analysis can also be performed by hypergeometric test or
Fisher's exact test. Here, the approach is similar to that described in
(Austin et
al., 2016). Briefly, the test is based on randomly generation of sets with
equal size to set1
from the background (universal) set. After creating
n (default is 10,000) random sets, the overlap between these and set2
is calculated to make a null distribution. When this distribution is true,
the probability of seeing an overlap at least as extreme as what was observed
(overlap between set1
and set2
) will be returned as the
p-value.
Returns a list containing the probability (Significance) of occurrence of an overlap between two sets by chance and the number of occurrences (Overlap_Counts) in randomly generated sets.
set1 = c(1:20, letters[1:10]) set2 = letters[-26] univ = unique(c(set1, set2, 21:200)) venn = Venn(list(set1, set2, univ)) e = enrichment_test(venn, 1, 2) e$Significance
set1 = c(1:20, letters[1:10]) set2 = letters[-26] univ = unique(c(set1, set2, 21:200)) venn = Venn(list(set1, set2, univ)) e = enrichment_test(venn, 1, 2) e$Significance
Draw the Venn diagram for 2 or 3 sets.
## S4 method for signature 'Venn' ggvenn(venn = "Venn", slice = "all", fill = c("gold", "dodgerblue3", "deeppink"), alpha = 0.5, thickness = 1.5)
## S4 method for signature 'Venn' ggvenn(venn = "Venn", slice = "all", fill = c("gold", "dodgerblue3", "deeppink"), alpha = 0.5, thickness = 1.5)
venn |
(Required) A |
slice |
(Optional) The names or the indices of the sets of interest.
Default is "all", which is for the cases the |
fill |
(Optional) Fill color of the sets. |
alpha |
(Optional) Opacity of the fill colors. Default is 0.5 in the range of (0, 0.5). |
thickness |
(Optional) Stroke size of the sets. |
This function is based on the packages 'ggplot2' and 'ggforce.' It
has been designed for 2 or 3 sets because Venn diagrams are terrible for
showing the interactions of 4 or more sets. If you need to visualize such
interactions, consider using setmap
.
The function returns the plot in ggplot2 style.
venn = Venn(list(letters[1:10], letters[3:12], letters[6:15])) ggvenn(venn) ggvenn(venn, slice = c(1, 2), thickness = 0, alpha = 0.3)
venn = Venn(list(letters[1:10], letters[3:12], letters[6:15])) ggvenn(venn) ggvenn(venn, slice = c(1, 2), thickness = 0, alpha = 0.3)
overlap_pairs
returns the pairwise intersections of the sets in a
Venn
object.
## S4 method for signature 'Venn' overlap_pairs(venn, slice = "all")
## S4 method for signature 'Venn' overlap_pairs(venn, slice = "all")
venn |
(Required) A |
slice |
(Optional) The names or the indices of sets of interest. Default is "all", meaning the pairwise intersections will be calculated for all the sets. |
A list showing the pairwise intersections of the sets.
venn = Venn(list(letters[1:10], letters[3:12], letters[6:15], letters[9:18])) overlap_pairs(venn) overlap_pairs(venn, slice = 1:3)
venn = Venn(list(letters[1:10], letters[3:12], letters[6:15], letters[9:18])) overlap_pairs(venn) overlap_pairs(venn, slice = 1:3)
overlap
returns the same elements of the sets in a Venn
object.
## S4 method for signature 'Venn' overlap(venn, slice = "all")
## S4 method for signature 'Venn' overlap(venn, slice = "all")
venn |
(Required) A |
slice |
(Optional) The names or the indices of sets of interest. Default is "all", meaning the intersection will be calculated for all the sets. |
A vector showing the intersection of the sets.
venn = Venn(list(letters[1:10], letters[3:12], letters[6:15])) overlap(venn) overlap(venn, slice = c(1, 2))
venn = Venn(list(letters[1:10], letters[3:12], letters[6:15])) overlap(venn) overlap(venn, slice = c(1, 2))
RVenn
: A package for set operations for many sets.Set operations for many sets. The base functions for set operations in R can be used for only two sets. This package uses 'purr' to find the union, intersection and difference of three or more sets. This package also provides functions for pairwise set operations among several sets. Further, based on 'ggplot2' and 'ggforce', a Venn diagram can be drawn for two or three sets. For bigger data sets, a clustered heatmap showing presence/absence of the elements of the sets can be drawn based on the 'pheatmap' package. Finally, enrichment test can be applied to two sets whether an overlap is statistically significant or not.
This function is based on the package 'pheatmap'. ggvenn
function is useful for 2-3 sets, if you need to show interactions between
many sets, you can show the presence/absence of the elements among all the
sets and cluster both the sets and the elements based on Jaccard distances.
## S4 method for signature 'Venn' setmap(venn, slice = "all", element_clustering = TRUE, set_clustering = TRUE, method = "average", legend = TRUE, title = NA, element_fontsize = 10, set_fontsize = 10)
## S4 method for signature 'Venn' setmap(venn, slice = "all", element_clustering = TRUE, set_clustering = TRUE, method = "average", legend = TRUE, title = NA, element_fontsize = 10, set_fontsize = 10)
venn |
(Required) A |
slice |
(Optional) The names or the indices of sets of interest. Default is "all", meaning the union will be calculated for all the sets. |
element_clustering |
(Optional) Boolean values determining if elements should be clustered. |
set_clustering |
(Optional) Boolean values determining if sets should be clustered. |
method |
(Optional) Clustering method used. Accepts the same values as
|
legend |
(Optional) Boolean values determining if the legend should be drawn. |
title |
(Optional) Title of the heatmap. |
element_fontsize |
(Optional) Font size of the elements. |
set_fontsize |
(Optional) Font size of the sets. |
Presence/absence heatmap of the sets.
venn = Venn(list(letters[1:10], letters[3:12], letters[6:15], letters[9:16], letters[15:25], letters[12:20])) setmap(venn) setmap(venn, slice = 1:4, element_clustering = FALSE, set_clustering = FALSE)
venn = Venn(list(letters[1:10], letters[3:12], letters[6:15], letters[9:16], letters[15:25], letters[12:20])) setmap(venn) setmap(venn, slice = 1:4, element_clustering = FALSE, set_clustering = FALSE)
unite_pairs
returns the pairwise unions of the sets in a Venn
object.
## S4 method for signature 'Venn' unite_pairs(venn, slice = "all")
## S4 method for signature 'Venn' unite_pairs(venn, slice = "all")
venn |
(Required) A |
slice |
(Optional) The names or the indices of sets of interest. Default is "all", meaning the pairwise intersections will be calculated for all the sets. |
A list showing the pairwise unions of the sets.
venn = Venn(list(letters[1:10], letters[3:12], letters[6:15], letters[9:18])) unite_pairs(venn) unite_pairs(venn, slice = 1:3)
venn = Venn(list(letters[1:10], letters[3:12], letters[6:15], letters[9:18])) unite_pairs(venn) unite_pairs(venn, slice = 1:3)
unite
returns the union of the sets in a Venn
object.
## S4 method for signature 'Venn' unite(venn, slice = "all")
## S4 method for signature 'Venn' unite(venn, slice = "all")
venn |
(Required) A |
slice |
(Optional) The names or the indices of sets of interest. Default is "all", meaning the union will be calculated for all the sets. |
A vector showing the union of the sets.
venn = Venn(list(letters[1:10], letters[3:12], letters[6:15])) unite(venn) unite(venn, slice = c(1, 2))
venn = Venn(list(letters[1:10], letters[3:12], letters[6:15])) unite(venn) unite(venn, slice = c(1, 2))
An S4 class to represent multiple sets.
sets
A list
object containing vectors in the same type.
names
The names of the sets
if it has names. If the list
doesn't have names, the sets will be named as "Set_1", "Set_2", "Set_3" and
so on.
Venn
object.Venn
builds a Venn
object from a list.
## S4 method for signature 'ANY' Venn(sets)
## S4 method for signature 'ANY' Venn(sets)
sets |
(Required) A list containing vectors in the same class. If a vector contains duplicates they will be discarded. If the list doesn't have names the sets will be named as "Set_1", "Set_2", "Set_3" and so on. |
A Venn
object.
venn = Venn(list(letters[1:10], letters[3:12], letters[6:15])) print(venn)
venn = Venn(list(letters[1:10], letters[3:12], letters[6:15])) print(venn)