Skip to content

Commit

Permalink
Version 1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekGierlinski committed Jan 24, 2024
1 parent a60acee commit e61cd34
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 16 deletions.
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: fenr
Title: Fast functional enrichment for interactive applications
Version: 1.1.4
Version: 1.1.5
Authors@R: person(
given = "Marek",
family = "Gierlinski",
Expand Down Expand Up @@ -53,8 +53,7 @@ Suggests:
testthat,
knitr,
rmarkdown,
topGO,
org.Hs.eg.db
topGO
RoxygenNote: 7.2.3
VignetteBuilder: knitr
LazyData: false
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,12 @@

- Reinstated Bioplanet access, this time with graceful fail when the website is down.
- Minor code changes.

## Version 1.0.5

- Bug fix: if feature id - term id mapping is not unique (which can happen), features are duplicated in counting; fixed by `dplyr::distinct()` on mapping
- Correction in vignette: using yeast genome for `topGO`, instead of human.
- Improving test coverage
- Making tests and examples resilient to Ensembl outage.


5 changes: 3 additions & 2 deletions R/caching.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ cached_url_path <- function(rname, fpath, use_cache) {
#' This function will remove all cached data used by `fenr`. The user will be
#' prompted for confirmation. Use with caution!
#'
#' @param ask Logical, whether to ask user for confirmation.
#' @return TRUE if successfully removed.
#' @noRd
remove_cache <- function() {
remove_cache <- function(ask = TRUE) {
cache <- cache_location()
bfc <- BiocFileCache::BiocFileCache(cache, ask = FALSE)
BiocFileCache::removebfc(bfc, ask = TRUE)
BiocFileCache::removebfc(bfc, ask = ask)
}
3 changes: 2 additions & 1 deletion R/enrichment.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ prepare_for_enrichment <- function(terms, mapping, all_features = NULL,
feature_term <- mapping |>
dplyr::rename(feature_id = !!feature_name) |>
dplyr::filter(feature_id %in% all_features) |>
dplyr::select(feature_id, term_id)
dplyr::select(feature_id, term_id) |>
dplyr::distinct()

# Feature to terms hash
f2t <- feature_term |>
Expand Down
2 changes: 2 additions & 0 deletions R/go.R
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,10 @@ fetch_go_from_bm <- function(mart, use_cache = TRUE) {
#' @importFrom assertthat assert_that
#' @examples
#' # Fetch GO data from Ensembl
#' \dontrun{
#' mart <- biomaRt::useEnsembl(biomart = "ensembl", dataset = "scerevisiae_gene_ensembl")
#' go_data_ensembl <- fetch_go(mart = mart, on_error = "warn")
#' }
#' # Fetch GO data from Gene Ontology
#' go_data_go <- fetch_go(species = "sgd", on_error = "warn")
fetch_go <- function(species = NULL, mart = NULL, use_cache = TRUE, on_error = c("stop", "warn")) {
Expand Down
2 changes: 2 additions & 0 deletions man/fetch_go.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tests/testthat/test_caching.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,13 @@ test_that("Multiple entries behaviour", {
expect_equal(re_content, expected_content)
})


test_that("Clearing cache", {
remove_cache(ask = FALSE)

cache <- cache_location()
bfc <- BiocFileCache::BiocFileCache(cache, ask = FALSE)
cnt <- BiocFileCache::bfccount(bfc)

expect_equal(cnt, 0)
})
20 changes: 15 additions & 5 deletions tests/testthat/test_go.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,19 @@ test_that("GO yeast from Ensembl is correct", {
"GO:0004365", "YGR192C"
)

mart <- biomaRt::useEnsembl(biomart = "ensembl", dataset = "scerevisiae_gene_ensembl")
re <- fetch_go(mart = mart)
test_fetched_structure(re)
test_terms(re$terms, expected_terms)
test_mapping(re$mapping, expected_mapping, "ensembl_gene_id")
mart <- tryCatch(
{biomaRt::useEnsembl(biomart = "ensembl", dataset = "scerevisiae_gene_ensembl")},
error = function(cond) {
message("Biomart is not responding.")
message(conditionMessage(cond))
NULL
}
)

if(!is.null(mart)) {
re <- fetch_go(mart = mart)
test_fetched_structure(re)
test_terms(re$terms, expected_terms)
test_mapping(re$mapping, expected_mapping, "ensembl_gene_id")
}
})
15 changes: 15 additions & 0 deletions tests/testthat/test_prepare_for_enrichment.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ test_that("Expected correct output", {
})


test_that("Duplicate term-gene pairs are removed", {
extra_row <- mapping[1, ]
mapping_dup <- mapping |>
dplyr::add_row(extra_row)
td <- prepare_for_enrichment(terms, mapping_dup, feature_name = "feature_id")
returned <- td$term2feature[[extra_row$term_id]] |>
sort()
expected <- mapping |>
dplyr::filter(term_id == extra_row$term_id) |>
dplyr::pull(feature_id) |>
sort()
expect_equal(expected, returned)
})


test_that("Wrong columns in terms", {
trms <- terms |>
dplyr::rename(gobble = term_id)
Expand Down
14 changes: 9 additions & 5 deletions vignettes/fenr.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ In exploratory data analysis, one often conducts several enrichment analyses. Th
```{r topGO}
suppressPackageStartupMessages({
library(topGO)
library(org.Hs.eg.db)
})
# Preparing the gene set
Expand All @@ -171,9 +170,14 @@ gene_selection <- function(genes) {
genes > 0
}
# Mapping genes to GO
allGO2genes <- annFUN.org(whichOnto = "BP", feasibleGenes = NULL,
mapping = "org.Hs.eg.db", ID = "symbol")
# Mapping genes to GO, we use the go2gene downloaded above and convert it to a
# list
go2gene <- go$mapping |>
dplyr::select(gene_symbol, term_id) |>
dplyr::distinct() |>
dplyr::group_by(term_id) |>
dplyr::summarise(ids = list(gene_symbol)) |>
tibble::deframe()
# Setting up the GO data for analysis
go_data <- new(
Expand All @@ -182,7 +186,7 @@ go_data <- new(
allGenes = all_genes,
geneSel = gene_selection,
annot = annFUN.GO2genes,
GO2genes = allGO2genes
GO2genes = go2gene
)
# Performing the enrichment test
Expand Down

0 comments on commit e61cd34

Please sign in to comment.