YuLab-SMU / clusterProfiler

:bar_chart: A universal enrichment tool for interpreting omics data
https://yulab-smu.top/biomedical-knowledge-mining-book/
967 stars 246 forks source link

compareCluster does not give a warning/message that numeric universe is ignored for fun = "enrichGO" #654

Open IwanParf opened 6 months ago

IwanParf commented 6 months ago

Dear clusterProfiler developers, thank you for this great tool! I noticed an inconsistent behaviour between calling enrichGO directly and within compareCluster. when I do enrichGO and provide universe in numeric format, the tests are calculated and at the end I get a message, that universe was ignored due to being numeric (universe is not in character and will be ignored...) (As a side note, one could simply do as.character in the function call to avoid this problem altogether?)

My problem now is that when I call enrichGO within compareCluster, I do not get this warning/message, which leads to different results of course.

Here's a minimal example:

library(clusterProfiler)
library(tidyverse)
library(org.Hs.eg.db)

genes <- as.data.frame(org.Hs.egSYMBOL) %>% pull(gene_id) %>% .[1:100]
universe <- as.data.frame(org.Hs.egSYMBOL) %>% pull(gene_id) %>% .[1:1000]
test <- enrichGO(genes, OrgDb = org.Hs.eg.db, ont = "BP", universe = as.numeric(universe))

This generates test and gives a warning/message: universe is not in character and will be ignored...

test@result$BgRatio[1]

This prints the background ratio of the first gene set: 10/18903 , i.e. the universe (which is max 1000 entries) was ignored and replaced by all genes in org.Hs.eg.db

test2 <- compareCluster(
geneClusters = list(genes = genes), # usually, it makes no sense to run compareCluster with only one entry in the list but this is for the sake of the example
fun = "enrichGO",
OrgDb = org.Hs.eg.db,
universe = as.numeric(universe),
ont = "BP")

This time no warning/message!

test2@compareClusterResult$BgRatio[1] Again, this prints the background ratio of the first gene set: 10/18903 , i.e. the universe (which is max 1000 entries) was ignored and replaced by all genes in org.Hs.eg.db without a warning.

When I do the above steps with plain universe without as.numeric(), universe is accepted and used as background.

Can the message/warning be preserved in the internal call of enrichGO and still pasted to the console, or the universe be converted to character by default to prevent this problem in the first place?