An R interface to the Enrichr database

Installation

enrichR can be installed from Github or from CRAN.

Github

websiteLive <- TRUE
library(devtools)
install_github("wjawaid/enrichR")

CRAN

The package can be downloaded from CRAN using:

install.packages("enrichR")

Usage example

enrichR provides an interface to the Enrichr database [@kuleshov_enrichr:_2016] hosted at https://maayanlab.cloud/Enrichr/.

By default human genes are selected otherwise select your organism of choice. (This functionality was contributed by Alexander Blume)

Initialising connection to Enrichr website

library(enrichR)

websiteLive <- getOption("enrichR.live")

if (websiteLive) {
    listEnrichrSites()
    setEnrichrSite("Enrichr") # Human genes
}

Select gene-set libraries

List all available databases from Enrichr.

if (websiteLive) {
    dbs <- listEnrichrDbs()
    head(dbs)
}

Select the 2023 GO databases.

dbs <- c("GO_Molecular_Function_2023", "GO_Cellular_Component_2023", 
     "GO_Biological_Process_2023")

Perform analysis

Without background

Query with enrichr() using example genes available from the package.

# Load example input genes
data(input)
length(input)
head(input)

if (websiteLive) {
    enriched <- enrichr(input, dbs)
}

Now view the "GO_Biological_Process_2023" results from the enriched object.

if (websiteLive) head(enriched[["GO_Biological_Process_2023"]])
success <- websiteLive & (length(enriched) >= 3)
success <- success & all(dim(enriched[["GO_Biological_Process_2023"]]) > 2)
if (success) {
    x <- head(enriched[["GO_Biological_Process_2023"]])
    x[,1] <- gsub(":", "&#58;", x[,1])
    knitr::kable(x)
}

With background

You can now add background genes when using enrichr().

# Load example background
data(background)
length(background)
head(background)

if (websiteLive) {
    enriched2 <- enrichr(input, dbs, background = background)
}

Now view the "GO_Biological_Process_2023" results from the enriched2 object.

if (websiteLive) head(enriched2[["GO_Biological_Process_2023"]])
success <- websiteLive & (length(enriched2) >= 3)
success <- success & all(dim(enriched2[["GO_Biological_Process_2023"]]) > 2)
if (success) {
    x <- head(enriched2[["GO_Biological_Process_2023"]])
    x[,1] <- gsub(":", "&#58;", x[,1])
    knitr::kable(x)
}

By default, the results table from analysis with a background does not have the 'Overlap' column. We can calculate the annotated genes in each term from GMT files and replace the 'Rank' column with 'Overlap' by setting include_overlap = TRUE.

if (websiteLive) {
    # Replace 'Rank' with 'Overlap' column, calculated with GMT files
    enriched3 <- enrichr(input, dbs, background = background, include_overlap = TRUE)
}

Now view the "GO_Biological_Process_2023" results from the enriched3 object.

success <- (length(enriched3) >= 3) & all(dim(enriched3[["GO_Biological_Process_2023"]]) > 2)
if (success) {
    x <- head(enriched3[["GO_Biological_Process_2023"]])
    x[,1] <- gsub(":", "&#58;", x[,1])
    knitr::kable(x)
}

Visualise results

Plot the "GO_Biological_Process_2023" results. (Plotting function contributed by I-Hsuan Lin)

if (websiteLive) {
    plotEnrich(enriched[["GO_Biological_Process_2023"]], showTerms = 20, numChar = 40, 
           y = "Count", orderBy = "P.value")
}

Export results

Export Enrichr results as text or Excel files. By default (i.e. outFile = "txt"), the results from all the selected databases are saved into individual text files. When using outFile = "excel", the results are saved into worksheets in a single Excel 2007 (XLSX) file. (Print function contributed by I-Hsuan Lin and Kai Hu)

# To text files
printEnrich(enriched)

# To Excel
printEnrich(enriched, outFile = "excel")

Using enrichR behind a proxy

If your computer is behind an HTTP or HTTPS proxy, you can set the RCurl Proxy options explicitly using RCurlOptions and enrichR will use the provided settings to connect to the Enrichr database via httr::use_proxy().

For example:

options(RCurlOptions = list(proxy = 'http://ip_or_url',
                            proxyusername = 'myuser',
                            proxypassword = 'mypwd',
                            proxyport = 'port_num',
                            proxyauth = 'basic'))

References



Try the enrichR package in your browser

Any scripts or data that you put into this service are public.

enrichR documentation built on April 4, 2025, 1:07 a.m.