wjawaid / enrichR

An R interface to enrichR
77 stars 18 forks source link

Background is not referenced in the package description #81

Open SaraAlidadiani opened 1 month ago

SaraAlidadiani commented 1 month ago

Hello,

I am using Enrichr in "R" for my pathway analysis. It is not references in the package description https://cran.r-project.org/web/packages/enrichR/enrichR.pdf how to define the background in R.

Is it possible to share how we can provide background to do enrichR pathway analysis in R and add this option in the documentation, please?

I am writing the code that I used, but I couldn't figure out how to add the list of my background genes.

# reading the file
options(stringsAsFactors = FALSE)
genes <- read.csv("list_of_significant_genes.csv")
background <- read.csv("list_of_Background_genes.csv") #I don't know how to use my background list

genes_path <- genes$hgnc_symbol
background_genes <- background$hgnc_symbol
websiteLive <- getOption("enrichR.live")

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

#Then find the list of all available databases from Enrichr.

if (websiteLive) dbs <- listEnrichrDbs()

if (websiteLive) head(dbs)

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

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

#Now view the results table.

if (websiteLive) enriched[["GO_Biological_Process_2023"]]
 version  R version 4.4.0 (2024-04-24)

Thanks you!

ycl6 commented 1 month ago

Hi @SaraAlidadiani There's a discussion about this in https://github.com/wjawaid/enrichR/issues/67. Short answer is, the current stable version of enrichR doesn't have the option to add background genes in the enrichment analysis.

You can do this on the Enrichr website https://maayanlab.cloud/Enrichr/, or you can follow #67 on how to install and use a revised version of enrichR (PR https://github.com/wjawaid/enrichR/pull/72) that supports a background.

SaraAlidadiani commented 1 month ago

Thank you for your prompt response. Following the https://github.com/wjawaid/enrichR/issues/67 I could use background. Could you also please share how we can visualize the pathways with this one? I couldn't use the same way for visualization when I was using the enrichR package without a background version. Many thanks!

ycl6 commented 1 month ago

Hi @SaraAlidadiani The colname of the output is probably slightly different, that could be the reason why the existing plot function is not recognise the input format. I'll have a look in the next week or so and suggest a fix.

ycl6 commented 1 month ago

Hi @SaraAlidadiani

I have just tested the plotEnrich function, it is working with results from both with and without background.

library(enrichR)
#> Welcome to enrichR
#> Checking connection ...
#> Enrichr ... Connection is Live!
#> FlyEnrichr ... Connection is Live!
#> WormEnrichr ... Connection is Live!
#> YeastEnrichr ... Connection is Live!
#> FishEnrichr ... Connection is Live!
#> OxEnrichr ... Connection is Live!

# Load example input genes
data(input)

# Load example background
data(background)

my_dbs <- c("KEGG_2019_Mouse","WikiPathways_2019_Mouse")

# No background
enriched1 <- enrichr(input, databases = my_dbs)
#> Uploading data to Enrichr... Done.
#>   Querying KEGG_2019_Mouse... Done.
#>   Querying WikiPathways_2019_Mouse... Done.
#> Parsing results... Done.

# Show KEGG_2019_Mouse results in enriched1 
plotEnrich(enriched1[[1]], showTerms = 20, numChar = 40, y = "Count", orderBy = "P.value")


# With background
enriched2 <- enrichr(input, databases = my_dbs, background = background)
#> Uploading data to Speedrichr...
#>  - Your gene set... Done.
#>  - Your background... Done.
#> Getting enrichment results...
#>  - KEGG_2019_Mouse... Done.
#>  - WikiPathways_2019_Mouse... Done.
#> Parsing results... Done.

# Show KEGG_2019_Mouse results in enriched2
plotEnrich(enriched2[[1]], showTerms = 20, numChar = 40, y = "Count", orderBy = "P.value")

Created on 2024-10-28 with reprex v2.1.1

SaraAlidadiani commented 1 month ago

Thank you so much @ycl6, for checking and for your consideration. If I want to reference it, should I use the same reference as Kuleshov M V., Jones MR, Rouillard AD, et al. Enrichr: a comprehensive gene set enrichment analysis web server 2016 update. Nucleic Acids Res. 2016;44(W1):W90-W97. doi:10.1093/NAR/GKW377?

Thank you so much!

ycl6 commented 1 month ago

Hi @SaraAlidadiani Hope the plot function is working for you.

If you have used the Enrichr web service, you can cite the paper and its website (https://maayanlab.cloud/Enrichr/). If you use the R package, you can use the package website (https://cran.r-project.org/package=enrichR or https://github.com/wjawaid/enrichR) in your reference.

As the background version hasn't been implemented officially to the main enrichR package, you may want to add the following link https://github.com/ycl6/enrichR/tree/add-background

SaraAlidadiani commented 2 weeks ago

Thank you, @ycl6 , yes, the plot function works nicely. I am also trying to use another plot for visualization but I have some problems with it. in the documention it mentioned ## S4 method for signature 'enrichResultList'

dotplot(object, x = "GeneRatio", color = "p.adjust",
showCategory = 10, size = NULL, split = NULL, font.size = 12)

But if I use it :

> dotplot(
+   enriched3,
+   x = "GeneRatio",
+   color = "p.adjust",
+   showCategory = 10)
Error: unable to find an inherited method for function ‘dotplot’ for signature ‘object = "list"’

> class(enriched3)
[1] "list"

I also think the problem can be with defining the x vaiable as well.

I would really appreciate if you can let me know what I am doing wrong. Many thanks!

ycl6 commented 2 weeks ago

Hi @SaraAlidadiani

The enrichR R package doesn't have this function (i.e. a function to create dot plot).

I did a Google search, it seems you are referring to the dotplot function from the enrichplot R package. The dotplot function can take in an enrichResultList object that is created by the enricher function from the clusterProfiler R package.

https://github.com/YuLab-SMU/enrichplot/blob/015b6d6cd7f8df67487c9edc02d6c3b94871f8e8/R/dotplot.R#L70-L85

If you like to perform enrichment analysis and create dot plots from the results, you can use clusterProfiler instead. It is a well developed and maintained R package. https://github.com/YuLab-SMU/clusterProfiler https://yulab-smu.top/biomedical-knowledge-mining-book/