Learn R Programming

An R interface to the Enrichr database

Wajid Jawaid 2025-02-02

Installation

enrichR can be installed from Github or from CRAN.

Github

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 et al. 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)
#> Welcome to enrichR
#> Checking connections ...
#> Enrichr ... Connection is Live!
#> FlyEnrichr ... Connection is Live!
#> WormEnrichr ... Connection is Live!
#> YeastEnrichr ... Connection is Live!
#> FishEnrichr ... Connection is Live!
#> OxEnrichr ... Connection is Live!

listEnrichrSites()
#> Enrichr ... Connection is Live!
#> FlyEnrichr ... Connection is Live!
#> WormEnrichr ... Connection is Live!
#> YeastEnrichr ... Connection is Live!
#> FishEnrichr ... Connection is Live!
#> OxEnrichr ... Connection is Live!

setEnrichrSite("Enrichr") # Human genes
#> Connection changed to https://maayanlab.cloud/Enrichr/
#> Connection is Live!

Select gene-set libraries

List all available databases from Enrichr.

dbs <- listEnrichrDbs()
head(dbs)
geneCoveragegenesPerTermlibraryNamenumTermsappytercategoryId
13362275Genome_Browser_PWMs615ea115789fcbf12797fd692cec6df0ab4dbc79c6a1
278841284TRANSFAC_and_JASPAR_PWMs3267d42eb43a64a4e3b20d721fc7148f685b53b6b301
600277Transcription_Factor_PPIs290849f222220618e2599d925b6b51868cf1dab37631
471721370ChEA_20133537ebe772afb55b63b41b79dd8d06ea0fdd9fa26307
47107509Drug_Perturbations_from_GEO_2014701ad270a6876534b7cb063e004289dcd4d3164f3427
214933713ENCODE_TF_ChIP-seq_2014498497787ebc418d308045efb63b8586f10c526af517

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)
#> [1] 375
head(input)
#> [1] "Nsun3"    "Polrmt"   "Nlrx1"    "Sfxn5"    "Zc3h12c"  "Slc25a39"

enriched <- enrichr(input, dbs)
#> Uploading data to Enrichr... Done.
#>   Querying GO_Molecular_Function_2023... Done.
#>   Querying GO_Cellular_Component_2023... Done.
#>   Querying GO_Biological_Process_2023... Done.
#> Parsing results... Done.

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

head(enriched[["GO_Biological_Process_2023"]])
TermOverlapP.valueAdjusted.P.valueOld.P.valueOld.Adjusted.P.valueOdds.RatioCombined.ScoreGenes
Mitochondrial Transcription (GO:0006390)3/120.00126850.71239250017.577061117.23788TFAM;POLRMT;TFB1M
Alpha-Amino Acid Metabolic Process (GO:1901605)4/290.00199370.7123925008.45283052.55773SRR;ALDH6A1;KMO;GNMT
Protein Transmembrane Import Into Intracellular Organelle (GO:0044743)4/320.00288820.7123925007.54601544.12249DNAJC19;TIMM44;TRIM37;PEX1
Neutrophil Degranulation (GO:0043312)2/50.00337740.71239250035.070599199.57464VAMP8;STXBP2
Medium-Chain Fatty Acid Biosynthetic Process (GO:0051792)2/50.00337740.71239250035.070599199.57464ABHD3;OXSM
Mitochondrial RNA Metabolic Process (GO:0000959)3/200.00588190.7123925009.30170847.77237TFAM;POLRMT;TFB1M

With background

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

# Load example background
data(background)
length(background)
#> [1] 20625
head(background)
#> [1] "A1BG"     "A2M"      "NAT1"     "NAT2"     "SERPINA3" "AADAC"

enriched2 <- enrichr(input, dbs, background = background)
#> Uploading data to Speedrichr...
#>  - Your gene set... Done.
#>  - Your background... Done.
#> Getting enrichment results...
#>  - GO_Molecular_Function_2023... Done.
#>  - GO_Cellular_Component_2023... Done.
#>  - GO_Biological_Process_2023... Done.
#> Parsing results... Done.

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

head(enriched2[["GO_Biological_Process_2023"]])
TermRankP.valueAdjusted.P.valueOld.P.valueOld.Adjusted.P.valueOdds.RatioCombined.ScoreGenes
Mitochondrial Transcription (GO:0006390)10.00037110.2405150027.116000214.19193TFAM;POLRMT;TFB1M
Alpha-Amino Acid Metabolic Process (GO:1901605)20.00041450.2405150013.057671101.69976SRR;ALDH6A1;KMO;GNMT
Protein Transmembrane Import Into Intracellular Organelle (GO:0044743)30.00060970.2405150011.65691386.29136DNAJC19;TIMM44;TRIM37;PEX1
Monocarboxylic Acid Biosynthetic Process (GO:0072330)40.00121760.240515006.81653245.74506ALDH1A3;SRR;SCP2;OXSM;MCAT
Neutrophil Degranulation (GO:0043312)50.00146630.2405150054.031872352.55862VAMP8;STXBP2
Medium-Chain Fatty Acid Biosynthetic Process (GO:0051792)60.00146630.2405150054.031872352.55862ABHD3;OXSM

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.

enriched3 <- enrichr(input, dbs, background = background, include_overlap = TRUE)
#> Uploading data to Speedrichr...
#>  - Your gene set... Done.
#>  - Your background... Done.
#> Getting enrichment results...
#>  - GO_Molecular_Function_2023... Done.
#>    - Download GMT file... Done.
#>  - GO_Cellular_Component_2023... Done.
#>    - Download GMT file... Done.
#>  - GO_Biological_Process_2023... Done.
#>    - Download GMT file... Done.
#> Parsing results... Done.

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

head(enriched3[["GO_Biological_Process_2023"]])
TermOverlapP.valueAdjusted.P.valueOld.P.valueOld.Adjusted.P.valueOdds.RatioCombined.ScoreGenes
Mitochondrial Transcription (GO:0006390)3/120.00037110.2405150027.116000214.19193TFAM;POLRMT;TFB1M
Alpha-Amino Acid Metabolic Process (GO:1901605)4/290.00041450.2405150013.057671101.69976SRR;ALDH6A1;KMO;GNMT
Protein Transmembrane Import Into Intracellular Organelle (GO:0044743)4/320.00060970.2405150011.65691386.29136DNAJC19;TIMM44;TRIM37;PEX1
Monocarboxylic Acid Biosynthetic Process (GO:0072330)5/650.00121760.240515006.81653245.74506ALDH1A3;SRR;SCP2;OXSM;MCAT
Neutrophil Degranulation (GO:0043312)2/50.00146630.2405150054.031872352.55862VAMP8;STXBP2
Medium-Chain Fatty Acid Biosynthetic Process (GO:0051792)2/50.00146630.2405150054.031872352.55862ABHD3;OXSM

Visualise results

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

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

Kuleshov, Maxim V., Matthew R. Jones, Andrew D. Rouillard, Nicolas F. Fernandez, Qiaonan Duan, Zichen Wang, Simon Koplev, et al. 2016. “Enrichr: A Comprehensive Gene Set Enrichment Analysis Web Server 2016 Update.” Nucleic Acids Res 44 (Web Server issue): W90–97. https://doi.org/10.1093/nar/gkw377.

Copy Link

Version

Install

install.packages('enrichR')

Monthly Downloads

5,574

Version

3.4

License

GPL (>= 2)

Maintainer

Wajid Jawaid

Last Published

February 2nd, 2025

Functions in enrichR (3.4)

input

Example input genes
getEnrichr

Helper function for HTTP methods GET and POST
enrichr

Gene enrichment using Enrichr
genes790

790 gene symbols
.proxyOpts

Internal function to check RCurlOptions
.onAttach

onLoad hook to setup package options
.read_gmt

Download and parse GMT files from Enrichr
.formatGenes

FormatGenes
background

Example background genes
.add_background

Upload background list using Speedrichr API
.get_backgroundenrich

Get enrichment result using Speedrichr API
enrichR-package

enrichR package
setEnrichrSite

Set Enrichr Website
.add_list

Upload gene list using Speedrichr API
listEnrichrSites

List Enrichr Websites
.enrichment_prep_df

Given a Enrichr output, order and subset criteria, returns a data frame accordingly
listEnrichrDbs

Look up available databases on Enrichr
printEnrich

printEnrich
plotEnrich

plotEnrich