# 2.A: Enrichr & rbioapi

#### Moosa Rezwani

#### 2025-02-07

# 1 Introduction

Enrichr is a popular gene-set enrichment analysis tool developed in the Ma’ayan Lab.

# 2 Gene set library concept in Enrichr

Directly quoting from Enrichr’s help page:

> A gene set library is a set of related gene sets or enrichment terms […] These libraries have been constructed from many sources such as published studies and major biological and biomedical online databases. Others have been created for and only available through Enrichr.

> (source: https://maayanlab.cloud/Enrichr/help#background)

To get a list of the available libraries in Enrichr, use:

    enrichr_libs <- rba_enrichr_libs()

In the returned data frame, you can find the names of available Enrichr libraries in “libraryName” column. As you will see in the following sections, you can use these names to request an enrichment analysis based on the selected library or libraries.

# 3 Enrichment analysis using Enrichr

To perform enrichment analysis on your gene-set with Enrichr using rbioapi, you can take two approaches. We will begin with the simple one. But first, we create a vector of genes’ NCBI IDs to use as the input example in this article.

    # Create a vector with our genes' NCBI IDs
    genes <- c(
      "p53", "BRCA1", "cdk2", "Q99835", "CDC42","CDK1","KIF23","PLK1",
      "RAC2","RACGAP1","RHOA","RHOB", "PHF14", "RBM3", "MSL1"
    )

## 3.1 Approach 1: Using the one-step Wrapper function

The only required input for this function is to simply supply your gene-set as a character vector. Optionally you can also select one or more libraries. Please see `rba_enrichr()` function’s manual for more details on the arguments.

    # Request the enrichment analysis
    results_all <- rba_enrichr(gene_list = genes)

Note that the default value for the argument `gene_set_library` in the rba_enrichr function is “all”. This means that if you call the function as above, all of the Enrichr libraries will be used for the enrichment analysis of your uploaded gene list. In this case, you will have a named list, where each of its elements is a dataframe containing your genes’ analysis results using that Enrichr library.

Alternatively, you can use the `gene_set_library` argument to specify the library (or libraries) to use. Here we demonstrate using “MSigDB_Hallmark_2020” library:

    # Request the enrichment analysis by a specific library
    results_msig_hallmark <- rba_enrichr(
      gene_list = genes,
      gene_set_library = "MSigDB_Hallmark_2020",
      progress_bar = FALSE # to avoid printing issues in the vignette
    )

When supplying the `gene_set_library` argument, rbioapi assumes you are entering a regex pattern. You can disable this by setting `regex_library_name` to `FALSE`. However, this feature is useful if you need -for example- partial matches in the library names. Suppose you want to perform the enrichment analysis on every library available in Enrichr that contains the name “MSig”. You can do the following:

    # Request the enrichment analysis
    results_msig <- rba_enrichr(
      gene_list = genes,
      gene_set_library = "msig",
      regex_library_name = TRUE,
      progress_bar = FALSE # to avoid printing issues in the vignette
    )

    # You can drop `regex_library_name = TRUE`, as it is TRUE by default.

Note that when only one Enrichr library is selected, a data frame with enrichment analysis result will be returned.

    str(results_msig_hallmark)
    #> 'data.frame':    18 obs. of  9 variables:
    #>  $ Term                : chr  "Mitotic Spindle" "G2-M Checkpoint" "E2F Targets" "Apoptosis" ...
    #>  $ Overlap             : chr  "5/199" "4/200" "4/200" "3/161" ...
    #>  $ P.value             : num  2.57e-07 1.22e-05 1.22e-05 2.17e-04 2.74e-03 ...
    #>  $ Adjusted.P.value    : num  4.62e-06 7.29e-05 7.29e-05 9.76e-04 9.87e-03 ...
    #>  $ Old.P.value         : int  0 0 0 0 0 0 0 0 0 0 ...
    #>  $ Old.Adjusted.P.value: int  0 0 0 0 0 0 0 0 0 0 ...
    #>  $ Odds.Ratio          : num  51 36.7 36.7 31.4 29.7 ...
    #>  $ Combined.Score      : num  774 416 416 265 175 ...
    #>  $ Genes               : chr  "CDC42;RACGAP1;PLK1;CDK1;KIF23" "RACGAP1;PLK1;CDK1;KIF23" "RACGAP1;PLK1;CDK1;BRCA1" "CDK2;BRCA1;RHOB" ...

But when multiple libraries have been selected, the function’s output will be a list where each element is a data frame corresponding to one of the selected libraries.

    str(results_msig, 1)
    #> List of 3
    #>  $ MSigDB_Computational       :'data.frame': 195 obs. of  9 variables:
    #>  $ MSigDB_Oncogenic_Signatures:'data.frame': 26 obs. of  9 variables:
    #>  $ MSigDB_Hallmark_2020       :'data.frame': 18 obs. of  9 variables:

## 3.2 Approach 2: Going step-by-step

`rba_enrichr()` is a wrapper function. It internally executes a sequence of functions necessary to run your analysis. Alternatively, you could go step by step. We demonstrate these steps in this section.

First, you need to retrieve the list of available Enrichr libraries. This step is optional. You can skip it if you already know the name of your desired libraries or if you want to run the analysis over every available library.

    # Get a list of available Enrichr libraries
    libs <- rba_enrichr_libs(store_in_options = TRUE)

Now, you need to upload your genes list to Enrichr. By this, an identifier will be assigned to your submitted list, which is needed for the next step.

    # Submit your gene-set to enrichr
    list_id <- rba_enrichr_add_list(gene_list = genes)

From the returned response, we need the numeric ID in the “userListId” element.

    str(list_id)
    #> List of 2
    #>  $ shortId   : chr "673476dc549e0c06d7ad07e1667b99b6"
    #>  $ userListId: int 87900696

Finally, we are ready to submit the enrichment analysis request to Enrichr. Same as explained above for the wrapper function `rba_enrichr()`, we can supply the “gene_set_library” argument in different ways. Here we will only select the “Table_Mining_of_CRISPR_Studies” library:

    # Request the analysis
    results_crispr <- rba_enrichr_enrich(
      user_list_id = list_id$userListId,
      gene_set_library = "Table_Mining_of_CRISPR_Studies"
    )

# 4 Working with Other Species

Enrichr also provides libraries for model organisms. The following functions have an `organism` argument that allows you to perform the analysis on species other than humans:

1. `rba_enrichr()`

2. `rba_enrichr_enrich()`

3. `rba_enrichr_gene_map()`

4. `rba_enrichr_libs()`

The available options for the organism argument are human”, (H. sapiens & M. musculus), fly” (D. melanogaster), “yeast” (S. cerevisiae), “worm” (C. elegans), and “fish” (D. rerio).

# 5 Providing background gene list

For human and mouse, Enrichr also support the use of background gene list. The background gene list will be used to compute the results statistics.

If using the one-step wrapper `rba_enrichr()` (Approach 1), Everything is handled under the hood; simply supply your background gene with the `background_genes` parameter.

    # Assume we have the background genes in the variable my_background_genes
    results_msig <- rba_enrichr(
      gene_list = genes,
      background_genes = my_background_genes,
      regex_library_name = TRUE
    )

If you choose to follow the step-by-step approach, please note that Enrichr relies on an API back-end called speedrichr to handle analysis with a background gene list. Therefore, when performing an analysis with background gene list, you must explicitly upload the target gene list to speedrichr. . Later steps will automatically interact with speedrichr as long as the relevant parameters for the background genes are specified.

    # Assume we have the background genes in the variable my_background_genes

    # Create a vector with our genes' NCBI IDs
    genes <- c(
      "p53", "BRCA1", "cdk2", "Q99835", "CDC42","CDK1","KIF23","PLK1",
      "RAC2","RACGAP1","RHOA","RHOB", "PHF14", "RBM3", "MSL1"
    )

    # Step 1: Upload the target gene list to speedrichr
    # Note: Ensure `speedrichr = TRUE` is specified. Otherwise, it will not be
    #       possible to use the background gene list later.
    list_id_spdr <- rba_enrichr_add_list(
      gene_list = genes,
      speedrichr = TRUE
    )

    # Step 2: Upload the background gene list
    # Assume we have the background genes in the variable my_background_genes
    background_id <- rba_enrichr_add_background(background_genes = my_background_genes)

    # Step 3: Submit the enrichment analysis and retrieve the results
    go_results <- rba_enrichr_enrich(
      user_list_id = list_id_spdr$userListId,
      background_id = background_id$backgroundid,
      gene_set_library = "GO"
    )

# 6 See also in Functions’ manuals

Some rbioapi Enrichr functions were not covered in this vignette, be sure to check their manuals:

- `rba_enrichr_gene_map()`

- `rba_enrichr_view_list()`

# 7 How to Cite?

To cite Enrichr (Please see https://maayanlab.cloud/Enrichr/help#terms):

- Chen, E.Y., Tan, C.M., Kou, Y. et al. Enrichr: interactive and collaborative HTML5 gene list enrichment analysis tool. Bioinformatics 14, 128 (2013). https://doi.org/10.1186/1471-2105-14-128

- Maxim V. Kuleshov, Matthew R. Jones, Andrew D. Rouillard, Nicolas F. Fernandez, Qiaonan Duan, Zichen Wang, Simon Koplev, Sherry L. Jenkins, Kathleen M. Jagodnik, Alexander Lachmann, Michael G. McDermott, Caroline D. Monteiro, Gregory W. Gundersen, Avi Ma’ayan, Enrichr: a comprehensive gene set enrichment analysis web server 2016 update, Nucleic Acids Research, Volume 44, Issue W1, 8 July 2016, Pages W90–W97, https://doi.org/10.1093/nar/gkw377

- Xie, Z., Bailey, A., Kuleshov, M. V., Clarke, D. J. B., Evangelista, J. E., Jenkins, S. L., Lachmann, A., Wojciechowicz, M. L., Kropiwnicki, E., Jagodnik, K. M., Jeon, M., & Ma’ayan, A. (2021). Gene set knowledge discovery with Enrichr. Current Protocols, 1, e90. doi: 10.1002/cpz1.90

To cite rbioapi:

- Moosa Rezwani, Ali Akbar Pourfathollah, Farshid Noorbakhsh, rbioapi: user-friendly R interface to biologic web services’ API, Bioinformatics, Volume 38, Issue 10, 15 May 2022, Pages 2952–2953, https://doi.org/10.1093/bioinformatics/btac172

# 8 Over-representation analysis Using Other Services

Other services supported by rbioapi also provide Over-representation analysis tools. Please see the vignette article Do with rbioapi: Over-Representation (Enrichment) Analysis in R (link to the documentation site) for an in-depth review.

# 9 Links

- This article in rbioapi documentation site

- Functions references in rbioapi documentation site

- rbioapi vignette index

# 10 Session info

    #> R version 4.4.2 (2024-10-31 ucrt)
    #> Platform: x86_64-w64-mingw32/x64
    #> Running under: Windows 11 x64 (build 26100)
    #>
    #> Matrix products: default
    #>
    #>
    #> locale:
    #> [1] LC_COLLATE=C
    #> [2] LC_CTYPE=English_United States.utf8
    #> [3] LC_MONETARY=English_United States.utf8
    #> [4] LC_NUMERIC=C
    #> [5] LC_TIME=English_United States.utf8
    #>
    #> time zone: Europe/Brussels
    #> tzcode source: internal
    #>
    #> attached base packages:
    #> [1] stats     graphics  grDevices utils     datasets  methods   base
    #>
    #> other attached packages:
    #> [1] rbioapi_0.8.2
    #>
    #> loaded via a namespace (and not attached):
    #>  [1] digest_0.6.37     R6_2.5.1          fastmap_1.2.0     xfun_0.50
    #>  [5] magrittr_2.0.3    cachem_1.1.0      knitr_1.49        htmltools_0.5.8.1
    #>  [9] png_0.1-8         rmarkdown_2.29    lifecycle_1.0.4   DT_0.33
    #> [13] cli_3.6.3         grid_4.4.2        sass_0.4.9        jquerylib_0.1.4
    #> [17] compiler_4.4.2    httr_1.4.7        rstudioapi_0.17.1 tools_4.4.2
    #> [21] curl_6.1.0        evaluate_1.0.3    bslib_0.8.0       yaml_2.3.10
    #> [25] htmlwidgets_1.6.4 rlang_1.1.4       jsonlite_1.8.9    crosstalk_1.2.1