-
Notifications
You must be signed in to change notification settings - Fork 3
/
README.Rmd
210 lines (156 loc) · 8.89 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
---
output: github_document
editor_options:
chunk_output_type: console
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
<!-- badges: start -->
[![R-CMD-check](https://github.com/ropensci/BaseSet/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ropensci/BaseSet/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/ropensci/BaseSet/branch/master/graph/badge.svg)](https://app.codecov.io/gh/ropensci/BaseSet?branch=master)
[![Lifecycle: maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html#maturing)
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![rOpenSci](https://badges.ropensci.org/359_status.svg)](https://github.com/ropensci/software-review/issues/359)
[![CRAN status](https://www.r-pkg.org/badges/version/BaseSet)](https://CRAN.R-project.org/package=BaseSet)
<!-- badges: end -->
# BaseSet
The goal of BaseSet is to facilitate working with sets in an efficient way.
The package implements methods to work on sets, doing intersection, union, complementary, power sets, cartesian product and other set operations in a tidy way.
The package supports [classical](https://en.wikipedia.org/wiki/Set_(mathematics)) and [fuzzy](https://en.wikipedia.org/wiki/Fuzzy_set) sets.
Fuzzy sets are similar to classical sets but there is some vagueness on the relationship between the element and the set.
It also allows to import from several formats used in the life science world.
Like the [GMT](https://software.broadinstitute.org/cancer/software/gsea/wiki/index.php/Data_formats#GMT:_Gene_Matrix_Transposed_file_format_.28.2A.gmt.29) and the [GAF](https://geneontology.org/docs/go-annotation-file-gaf-format-2.1/) or the [OBO format](https://obofoundry.org/) file for ontologies.
You can save information about the elements, sets and their relationship on the object itself.
For instance origin of the set, categorical or numeric data associated with sets...
Watch BaseSet working on the [examples](#Examples) below and in the vignettes.
You can also find [related packages](#Related-packages) and the differences with BaseSet.
If you have some questions or bugs [open an issue](https://github.com/ropensci/BaseSet/issues) (remember the [Code of Conduct](#Code-of-Conduct))
# Installation
The package depends on some packages from Bioconductor. In order to install some of its dependencies you'll need first to install `{BiocManager}`:
```{r dep, eval = FALSE}
if (!require("BiocManager")) {
install.packages("BiocManager")
}
```
You can install the latest version of BaseSet from [Github](https://github.com/ropensci/BaseSet) with:
```{r eval=FALSE}
BiocManager::install("ropensci/BaseSet",
dependencies = TRUE, build_vignettes = TRUE, force = TRUE)
```
# Examples {#Examples}
```{r include=FALSE}
library("BaseSet")
```
## Sets
We can create a set like this:
```{r TidySet}
sets <- list(A = letters[1:5], B = c("a", "f"))
sets_analysis <- tidySet(sets)
sets_analysis
```
Perform typical operations like union, intersection. You can name the resulting set or let the default name:
```{r union-intersection}
union(sets_analysis, sets = c("A", "B"))
# Or we can give a name to the new set
union(sets_analysis, sets = c("A", "B"), name = "D")
# Or the intersection
intersection(sets_analysis, sets = c("A", "B"))
# Keeping the other sets:
intersection(sets_analysis, sets = c("A", "B"), name = "D", keep = TRUE)
```
And compute size of sets among other things:
```{r set_size}
set_size(sets_analysis)
```
The elements in one set not present in other:
```{r subraction}
subtract(sets_analysis, set_in = "A", not_in = "B", keep = FALSE)
```
Or any other verb from [dplyr](https://cran.r-project.org/package=dplyr). We can add columns, filter, remove them and add information about the sets:
```{r dplyr}
library("magrittr")
set.seed(4673) # To make it reproducible in your machine
sets_enriched <- sets_analysis %>%
mutate(Keep = sample(c(TRUE, FALSE), 7, replace = TRUE)) %>%
filter(Keep == TRUE) %>%
select(-Keep) %>%
activate("sets") %>%
mutate(sets_origin = c("Reactome", "KEGG"))
sets_enriched
# Activating sets makes the verb affect only them:
elements(sets_enriched)
relations(sets_enriched)
sets(sets_enriched)
```
## Fuzzy sets
In [fuzzy sets](https://en.wikipedia.org/wiki/Fuzzy_set) the elements are vaguely related to the set by a numeric value usually between 0 and 1.
This implies that the association is not guaranteed.
```{r fuzzy}
relations <- data.frame(sets = c(rep("A", 5), "B", "B"),
elements = c("a", "b", "c", "d", "e", "a", "f"),
fuzzy = runif(7))
fuzzy_set <- tidySet(relations)
fuzzy_set
```
The equivalent operations performed on classical sets are possible with fuzzy sets:
```{r fuzzy-operations}
union(fuzzy_set, sets = c("A", "B"))
# Or we can give a name to the new set
union(fuzzy_set, sets = c("A", "B"), name = "D")
# Or the intersection
intersection(fuzzy_set, sets = c("A", "B"))
# Keeping the other sets:
intersection(fuzzy_set, sets = c("A", "B"), name = "D", keep = TRUE)
```
Assuming that the fuzzy value is a probability, we can calculate which is the probability of having several elements:
```{r prob}
# A set could be empty
set_size(fuzzy_set)
# The more probable size of the sets:
set_size(fuzzy_set) %>%
group_by(sets) %>%
filter(probability == max(probability))
# Probability of belonging to several sets:
element_size(fuzzy_set)
```
With fuzzy sets we can filter at certain levels (called alpha cut):
```{r alphaCut}
fuzzy_set %>%
filter(fuzzy > 0.5) %>%
activate("sets") %>%
mutate(sets_origin = c("Reactome", "KEGG"))
```
# Related packages {#related}
There are several other packages related to sets, which partially overlap with BaseSet functionality:
- [`{sets}`]( https://CRAN.R-project.org/package=sets)
Implements a more generalized approach, that can store functions or lists as an element of a set (while BaseSet only allows to store a character or factor), but it is harder to operate in a tidy/long way. Also the operations of intersection and union need to happen between two different objects, while a single TidySet object (the class implemented in BaseSet) can store one or thousands of sets.
- [`{GSEABase}`](https://bioconductor.org/packages/GSEABase/)
Implements a class to store sets and related information, but it doesn't allow to store fuzzy sets and it is also quite slow as it creates several classes for annotating each set.
- [`{BiocSet}`](https://bioconductor.org/packages/BiocSet/)
Implements a tidy class for sets but does not handle fuzzy sets. It also has less functionality to operate with sets, like power sets and cartesian product. BiocSet was influenced by the development of this package.
- [`{hierarchicalSets}`](https://CRAN.R-project.org/package=hierarchicalSets)
This package is focused on clustering of sets that are inside other sets and visualizations. However, BaseSet is focused on storing and manipulate sets including hierarchical sets.
- [`{set6}`](https://cran.r-project.org/package=set6)
This package implements different classes for different type of sets including fuzzy sets, conditional sets. However, it doesn't handle information associated to elements, sets or relationship.
# Why this package? {#why}
On bioinformatics when looking for the impact of an experiment enrichment methods are applied.
This involves obtaining several sets of genes from several resources and methods.
Usually these curated sets of genes are taken at face value.
However, there are several resources of sets and they [do not agree between them](https://doi.org/10.1186/1471-2105-14-112), regardless they are used without considering any uncertainty on sets composition.
Fuzzy theory has long studied sets whose elements have degrees of membership and/or uncertainty.
Therefore one way to improve the methods involve using fuzzy methods and logic on this field.
As I couldn't find any package that provided methods for this I set on creating it (after trying to [expand](https://github.com/llrs/GSEAdv) the existing one I knew).
This package is intended to be easy to use for someone who is working with collections of sets but flexible about the methods and logic it can use.
To be consistent, the standard fuzzy logic is the default but it might not be the right one for your data.
Consider changing the defaults to match with the framework the data was obtained with.
# Code of Conduct {#CoC}
Please note that this package is released with a [Contributor
Code of Conduct](https://ropensci.org/code-of-conduct/).
By contributing to this project, you agree to abide by its terms.