YuLab-SMU / clusterProfiler

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

problem in run compareCluster #669

Open gongxin8888 opened 7 months ago

gongxin8888 commented 7 months ago

Hi Dr. Yu,

Here is my code:

Serumenricher <- compareCluster(geneCluster=Serum, fun=enricher, pvalueCutoff = 1, minGSSize = 4, maxGSSize = 500, pAdjustMethod="BH", TERM2GENE=path2comp, TERM2NAME=path2Names );

Serum is a list of KEGG ID List of 7 $ blue : chr [1:20] "C16325" "C16353" "C11045" "D02381" ... $ black : chr [1:6] "D07176" "C06869" "D07614" "C01921" ... $ red : chr [1:7] "C01801" "C00486" "C02237" "C00078" ... $ brown : chr [1:12] "C16651" "C16366" "C00486" "C00486" ... $ turquoise: chr [1:19] "C01089" "C03601" "C00114" "D07690" ... $ green : chr [1:17] "C00300" "C00791" "D03600" "C17935" ... $ yellow : chr [1:12] "C11993" "C00939" "C07597" "C07597" ..

It failed with the following errors::

Error in fun(i, ...) : could not find function "fun"

Any suggestion?

Thanks

GongXin

Prerequisites

Describe your issue

Ask in the right place

guidohooiveld commented 7 months ago

Does it work with the example code (since your code as such is not reproducible)? What is your sessionInfo()?

> library(clusterProfiler)
> data(gcSample)
> xx <- compareCluster(gcSample, fun=enrichKEGG,
+                      organism="hsa", pvalueCutoff=0.05)
> xx
#
# Result of Comparing 8 gene clusters 
#
#.. @fun         enrichKEGG 
#.. @geneClusters       List of 8
 $ X1: chr [1:216] "4597" "7111" "5266" "2175" ...
 $ X2: chr [1:805] "23450" "5160" "7126" "26118" ...
 $ X3: chr [1:392] "894" "7057" "22906" "3339" ...
 $ X4: chr [1:838] "5573" "7453" "5245" "23450" ...
 $ X5: chr [1:929] "5982" "7318" "6352" "2101" ...
 $ X6: chr [1:585] "5337" "9295" "4035" "811" ...
 $ X7: chr [1:582] "2621" "2665" "5690" "3608" ...
 $ X8: chr [1:237] "2665" "4735" "1327" "3192" ...
#...Result      'data.frame':   76 obs. of  12 variables:
 $ Cluster    : Factor w/ 8 levels "X1","X2","X3",..: 2 2 2 3 3 3 4 4 4 4 ...
 $ category   : chr  "Human Diseases" "Human Diseases" "Cellular Processes" "Environmental Information Processing" ...
 $ subcategory: chr  "Infectious disease: viral" "Immune disease" "Cell growth and death" "Signaling molecules and interaction" ...
 $ ID         : chr  "hsa05169" "hsa05340" "hsa04110" "hsa04512" ...
 $ Description: chr  "Epstein-Barr virus infection" "Primary immunodeficiency" "Cell cycle" "ECM-receptor interaction" ...
 $ GeneRatio  : chr  "23/406" "8/406" "18/406" "9/193" ...
 $ BgRatio    : chr  "202/8662" "38/8662" "157/8662" "89/8662" ...
 $ pvalue     : num  6.83e-05 3.07e-04 3.83e-04 1.53e-04 3.29e-04 ...
 $ p.adjust   : num  0.0214 0.0399 0.0399 0.0362 0.0362 ...
 $ qvalue     : num  0.0199 0.0372 0.0372 0.0335 0.0335 ...
 $ geneID     : chr  "4067/3383/7128/1869/890/1871/578/864/637/9641/6891/355/9134/5971/916/956/6850/7187/3551/919/4734/958/6772" "100/6891/3932/973/916/925/958/64421" "991/1869/890/1871/701/990/10926/9088/8317/9700/9134/1029/2810/699/11200/23594/8555/4173" "7057/3339/1299/3695/1101/3679/3910/3696/3693" ...
 $ Count      : int  23 8 18 9 17 19 17 10 22 19 ...
#.. number of enriched terms found for each gene cluster:
#..   X1: 0 
#..   X2: 3 
#..   X3: 3 
#..   X4: 22 
#..   X5: 10 
#..   X6: 1 
#..   X7: 17 
#..   X8: 20 
#
#...Citation
T Wu, E Hu, S Xu, M Chen, P Guo, Z Dai, T Feng, L Zhou, 
W Tang, L Zhan, X Fu, S Liu, X Bo, and G Yu. 
clusterProfiler 4.0: A universal enrichment tool for interpreting omics data. 
The Innovation. 2021, 2(3):100141 

>
gongxin8888 commented 7 months ago

Hi Guido,

It does work with the following example but not with fun = enricher. I found alternative where I created a customized function with enricher. With that function, it works for me.

Thanks and have a great day!

GongXin

From: Guido Hooiveld @.> Date: Thursday, February 22, 2024 at 2:05 AM To: YuLab-SMU/clusterProfiler @.> Cc: Yu, Gongxin @.>, Author @.> Subject: [EXTERNAL] [MARKETING] Re: [YuLab-SMU/clusterProfiler] problem in run compareCluster (Issue #669)

Does it work with the example code (since your code as such is not reproducible)? What is your sessionInfo()?

library(clusterProfiler)

data(gcSample)

xx <- compareCluster(gcSample, fun=enrichKEGG,

xx

#

Result of Comparing 8 gene clusters

#

.. @fun enrichKEGG

.. @geneClusters List of 8

$ X1: chr [1:216] "4597" "7111" "5266" "2175" ...

$ X2: chr [1:805] "23450" "5160" "7126" "26118" ...

$ X3: chr [1:392] "894" "7057" "22906" "3339" ...

$ X4: chr [1:838] "5573" "7453" "5245" "23450" ...

$ X5: chr [1:929] "5982" "7318" "6352" "2101" ...

$ X6: chr [1:585] "5337" "9295" "4035" "811" ...

$ X7: chr [1:582] "2621" "2665" "5690" "3608" ...

$ X8: chr [1:237] "2665" "4735" "1327" "3192" ...

...Result 'data.frame': 76 obs. of 12 variables:

$ Cluster : Factor w/ 8 levels "X1","X2","X3",..: 2 2 2 3 3 3 4 4 4 4 ...

$ category : chr "Human Diseases" "Human Diseases" "Cellular Processes" "Environmental Information Processing" ...

$ subcategory: chr "Infectious disease: viral" "Immune disease" "Cell growth and death" "Signaling molecules and interaction" ...

$ ID : chr "hsa05169" "hsa05340" "hsa04110" "hsa04512" ...

$ Description: chr "Epstein-Barr virus infection" "Primary immunodeficiency" "Cell cycle" "ECM-receptor interaction" ...

$ GeneRatio : chr "23/406" "8/406" "18/406" "9/193" ...

$ BgRatio : chr "202/8662" "38/8662" "157/8662" "89/8662" ...

$ pvalue : num 6.83e-05 3.07e-04 3.83e-04 1.53e-04 3.29e-04 ...

$ p.adjust : num 0.0214 0.0399 0.0399 0.0362 0.0362 ...

$ qvalue : num 0.0199 0.0372 0.0372 0.0335 0.0335 ...

$ geneID : chr "4067/3383/7128/1869/890/1871/578/864/637/9641/6891/355/9134/5971/916/956/6850/7187/3551/919/4734/958/6772" "100/6891/3932/973/916/925/958/64421" "991/1869/890/1871/701/990/10926/9088/8317/9700/9134/1029/2810/699/11200/23594/8555/4173" "7057/3339/1299/3695/1101/3679/3910/3696/3693" ...

$ Count : int 23 8 18 9 17 19 17 10 22 19 ...

.. number of enriched terms found for each gene cluster:

.. X1: 0

.. X2: 3

.. X3: 3

.. X4: 22

.. X5: 10

.. X6: 1

.. X7: 17

.. X8: 20

#

...Citation

T Wu, E Hu, S Xu, M Chen, P Guo, Z Dai, T Feng, L Zhou,

W Tang, L Zhan, X Fu, S Liu, X Bo, and G Yu.

clusterProfiler 4.0: A universal enrichment tool for interpreting omics data.

The Innovation. 2021, 2(3):100141

— Reply to this email directly, view it on GitHubhttps://clicktime.symantec.com/15uBY59P1XknJ2h1XxDBg?h=3NwhEW4cTh29LHWJy6FoU6bSGd6OaiJo5FGJpbfodJA=&u=https://github.com/YuLab-SMU/clusterProfiler/issues/669%23issuecomment-1958828750, or unsubscribehttps://clicktime.symantec.com/15uBcuLfU9SNhyWw5WcLJ?h=ZtNZrpbmKFShDmL967bWnQic1Bek6T43y6v8u65cLeM=&u=https://github.com/notifications/unsubscribe-auth/BGJSULBROUYKEEI2KRHCLP3YU3U4BAVCNFSM6AAAAABDRPQ3X6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJYHAZDQNZVGA. You are receiving this because you authored the thread.Message ID: @.***>

This message (including any attachments) is intended only for the use of the individual or entity to which it is addressed and may contain information that is non-public, proprietary, privileged, confidential, and exempt from disclosure under applicable law or may constitute as attorney work product. If you are not the intended recipient, you are hereby notified that any use, dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this communication in error, notify us immediately by telephone and (i) destroy this message if a facsimile or (ii) delete this message immediately if this is an electronic communication. Thank you.

guidohooiveld commented 7 months ago

Happy to hear you got it somehow working, but to show for the record/archive thatcompareCluster also works with the generic function enricher:

> library(clusterProfiler)
> 
> ## load some example data
> data(gcSample)
> 
> ## manually download KEGG data; to be used as input for TERM2GENE and TERM2NAME
> kegg.data <- download_KEGG(species="hsa", keggType = "KEGG", keyType = "kegg")
Reading KEGG annotation online: "https://rest.kegg.jp/link/hsa/pathway"...
Reading KEGG annotation online: "https://rest.kegg.jp/list/pathway/hsa"...
> gene.sets <- kegg.data$KEGGPATHID2EXTID; colnames(gene.sets) <- c("PathwayID","GeneID")
> set.names <- kegg.data$KEGGPATHID2NAME; colnames(set.names) <- c("PathwayID","Description")
> 
> ## run compareCluster with generic function enricher
> yy <- compareCluster(geneClusters = gcSample,
+                      fun = "enricher",
+                      minGSSize = 10,
+                      maxGSSize = 500,
+                      pvalueCutoff = 1,
+                      pAdjustMethod = "BH",
+                      TERM2GENE = gene.sets[, c("PathwayID","GeneID") ], #proper order columns
+                      TERM2NAME = set.names[, c("PathwayID","Description") ]
+                      )
> 
> ## check
> yy
#
# Result of Comparing 8 gene clusters 
#
#.. @fun         enricher 
#.. @geneClusters       List of 8
 $ X1: chr [1:216] "4597" "7111" "5266" "2175" ...
 $ X2: chr [1:805] "23450" "5160" "7126" "26118" ...
 $ X3: chr [1:392] "894" "7057" "22906" "3339" ...
 $ X4: chr [1:838] "5573" "7453" "5245" "23450" ...
 $ X5: chr [1:929] "5982" "7318" "6352" "2101" ...
 $ X6: chr [1:585] "5337" "9295" "4035" "811" ...
 $ X7: chr [1:582] "2621" "2665" "5690" "3608" ...
 $ X8: chr [1:237] "2665" "4735" "1327" "3192" ...
#...Result      'data.frame':   226 obs. of  10 variables:
 $ Cluster    : Factor w/ 8 levels "X1","X2","X3",..: 1 1 1 2 2 2 2 2 2 2 ...
 $ ID         : chr  "hsa04061" "hsa05146" "hsa04060" "hsa05169" ...
 $ Description: chr  "Viral protein interaction with cytokine and cytokine receptor" "Amoebiasis" "Cytokine-cytokine receptor interaction" "Epstein-Barr virus infection" ...
 $ GeneRatio  : chr  "6/103" "6/103" "10/103" "23/406" ...
 $ BgRatio    : chr  "100/8661" "102/8661" "297/8661" "202/8661" ...
 $ pvalue     : num  1.18e-03 1.31e-03 2.72e-03 6.84e-05 3.08e-04 ...
 $ p.adjust   : num  0.1283 0.1283 0.1778 0.0214 0.04 ...
 $ qvalue     : num  0.1206 0.1206 0.1671 0.0199 0.0373 ...
 $ geneID     : chr  "6364/3559/2921/8793/3576/6374" "7850/2921/6317/3576/1281/22798" "7850/653/6364/3559/3595/2921/8793/10663/3576/6374" "4067/3383/7128/1869/890/1871/578/864/637/9641/6891/355/9134/5971/916/956/6850/7187/3551/919/4734/958/6772" ...
 $ Count      : int  6 6 10 23 8 18 22 13 12 14 ...
#.. number of enriched terms found for each gene cluster:
#..   X1: 3 
#..   X2: 20 
#..   X3: 5 
#..   X4: 76 
#..   X5: 48 
#..   X6: 4 
#..   X7: 36 
#..   X8: 34 
#
#...Citation
T Wu, E Hu, S Xu, M Chen, P Guo, Z Dai, T Feng, L Zhou, 
W Tang, L Zhan, X Fu, S Liu, X Bo, and G Yu. 
clusterProfiler 4.0: A universal enrichment tool for interpreting omics data. 
The Innovation. 2021, 2(3):100141 

> 
gongxin8888 commented 7 months ago

Thanks very much, Guido.

From: Guido Hooiveld @.> Date: Friday, February 23, 2024 at 3:27 AM To: YuLab-SMU/clusterProfiler @.> Cc: Yu, Gongxin @.>, Author @.> Subject: [EXTERNAL] [MARKETING] Re: [YuLab-SMU/clusterProfiler] problem in run compareCluster (Issue #669)

Happy to hear you got it somehow working, but to show for the record/archive that compareCluster also works with the generic function enricher:

library(clusterProfiler)

load some example data

data(gcSample)

manually download KEGG data; to be used as input for TERM2GENE and TERM2NAME

kegg.data <- download_KEGG(species="hsa", keggType = "KEGG", keyType = "kegg")

Reading KEGG annotation online: "https://clicktime.symantec.com/15tpP1jeVTHfBythNbPJs?h=BvATC_yQZMgUbXgJSVTTYf9I6zuqB-DfSvLHI1bdQ9Q=&u=https://rest.kegg.jp/link/hsa/pathway"...

Reading KEGG annotation online: "https://clicktime.symantec.com/15tpTqvvx4yFbvicv9nTV?h=gyLsJHDvW1i_tvMDv-e_jIqbdEUXLf48ayKIJRXZzyA=&u=https://rest.kegg.jp/list/pathway/hsa"...

gene.sets <- kegg.data$KEGGPATHID2EXTID; colnames(gene.sets) <- c("PathwayID","GeneID")

set.names <- kegg.data$KEGGPATHID2NAME; colnames(set.names) <- c("PathwayID","Description")

run compareCluster with generic function enricher

yy <- compareCluster(geneClusters = gcSample,

check

yy

#

Result of Comparing 8 gene clusters

#

.. @fun enricher

.. @geneClusters List of 8

$ X1: chr [1:216] "4597" "7111" "5266" "2175" ...

$ X2: chr [1:805] "23450" "5160" "7126" "26118" ...

$ X3: chr [1:392] "894" "7057" "22906" "3339" ...

$ X4: chr [1:838] "5573" "7453" "5245" "23450" ...

$ X5: chr [1:929] "5982" "7318" "6352" "2101" ...

$ X6: chr [1:585] "5337" "9295" "4035" "811" ...

$ X7: chr [1:582] "2621" "2665" "5690" "3608" ...

$ X8: chr [1:237] "2665" "4735" "1327" "3192" ...

...Result 'data.frame': 226 obs. of 10 variables:

$ Cluster : Factor w/ 8 levels "X1","X2","X3",..: 1 1 1 2 2 2 2 2 2 2 ...

$ ID : chr "hsa04061" "hsa05146" "hsa04060" "hsa05169" ...

$ Description: chr "Viral protein interaction with cytokine and cytokine receptor" "Amoebiasis" "Cytokine-cytokine receptor interaction" "Epstein-Barr virus infection" ...

$ GeneRatio : chr "6/103" "6/103" "10/103" "23/406" ...

$ BgRatio : chr "100/8661" "102/8661" "297/8661" "202/8661" ...

$ pvalue : num 1.18e-03 1.31e-03 2.72e-03 6.84e-05 3.08e-04 ...

$ p.adjust : num 0.1283 0.1283 0.1778 0.0214 0.04 ...

$ qvalue : num 0.1206 0.1206 0.1671 0.0199 0.0373 ...

$ geneID : chr "6364/3559/2921/8793/3576/6374" "7850/2921/6317/3576/1281/22798" "7850/653/6364/3559/3595/2921/8793/10663/3576/6374" "4067/3383/7128/1869/890/1871/578/864/637/9641/6891/355/9134/5971/916/956/6850/7187/3551/919/4734/958/6772" ...

$ Count : int 6 6 10 23 8 18 22 13 12 14 ...

.. number of enriched terms found for each gene cluster:

.. X1: 3

.. X2: 20

.. X3: 5

.. X4: 76

.. X5: 48

.. X6: 4

.. X7: 36

.. X8: 34

#

...Citation

T Wu, E Hu, S Xu, M Chen, P Guo, Z Dai, T Feng, L Zhou,

W Tang, L Zhan, X Fu, S Liu, X Bo, and G Yu.

clusterProfiler 4.0: A universal enrichment tool for interpreting omics data.

The Innovation. 2021, 2(3):100141

— Reply to this email directly, view it on GitHubhttps://clicktime.symantec.com/15tpDMM5aDvUN6ErHUb1d?h=lXlIhAVFsDV9FcWoTSrRgv9GXCqfgeMLPu4llmIqe2U=&u=https://github.com/YuLab-SMU/clusterProfiler/issues/669%23issuecomment-1960910360, or unsubscribehttps://clicktime.symantec.com/15tpJBYN2qc4n34mq2zAF?h=m9VBvawBx_BfclpIE-sJEcGQvxo8jaF4n0SsOZ4ACNw=&u=https://github.com/notifications/unsubscribe-auth/BGJSULCOOYZBQGSAYTQCOJ3YVBHG3AVCNFSM6AAAAABDRPQ3X6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRQHEYTAMZWGA. You are receiving this because you authored the thread.Message ID: @.***>

This message (including any attachments) is intended only for the use of the individual or entity to which it is addressed and may contain information that is non-public, proprietary, privileged, confidential, and exempt from disclosure under applicable law or may constitute as attorney work product. If you are not the intended recipient, you are hereby notified that any use, dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this communication in error, notify us immediately by telephone and (i) destroy this message if a facsimile or (ii) delete this message immediately if this is an electronic communication. Thank you.