YuLab-SMU / clusterProfiler

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

Is it possible to generate a cnetplot from a compareCluster result object? #301

Closed sarahalshammery closed 2 years ago

sarahalshammery commented 3 years ago

Hello,

I've been using clusterProfiler to identify enriched pathways in my data and it's been working quite well (minus a lot of troubleshooting).. I've had this problem for a while in which I can't produce a barplot/cnet plot of my compareCluster results. I did look into the cnetplot function and I can see that a compareClusterResult can be an input.. however I am getting errors as you can see below.

cnetplot
standardGeneric for "cnetplot" defined from package "enrichplot"

function (x, showCategory = 5, foldChange = NULL, layout = "kk", 
    ...) 
Methods may be defined for arguments: x, showCategory, foldChange, layout
Use  showMethods("cnetplot")  for currently available ones.
showMethods(cnetplot)
Function: cnetplot (package enrichplot)
x="compareClusterResult"
x="enrichResult"
x="gseaResult"

When I use the enrichGO/enrichKEGG/enrichPathway functions, I get different results from when I use the compareCluster function with fun =enrichGO/enrichKEGG/enrichPathway. Example of the reactome work where I'm making comparisons by direction (i.e 'up' or 'down') using the compareCluster function and then using the same objects but through the enrichPathway function. The compareCluster gives me 27 enriched pathways, while the enrichPathway gives 860 enriched pathways.... When I try to generate a cnetplot using the compareCluster results, it won't work.

my_reac<-compareCluster(ENTREZID~direction,data=mygenes,fun="enrichPathway",
                       pvalueCutoff = 0.05,universe=tt$ENTREZID,readable=T)
cnetplot(my_reac)
Error in sum(y_union[ii, 9]) : invalid 'type' (character) of argument
cnetplot(my_reac@compareClusterResult)
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘cnetplot’ for signature ‘"data.frame"’
----second using the enrichPathway function
newallreac <- enrichPathway(mygenes$ENTREZID, organism = "human", pvalueCutoff = 0.05,
                           pAdjustMethod = "BH", universe=tt$ENTREZID,readable = T)

I have tried the reinstalling, updating packages etc. Nothing works. I have searched and didn't find anyone having the same problem as me so I thought I'd give this a try.

Thank you all in advance.

huerqiang commented 3 years ago

Please provide your complete code and data, I will find out where the problem is.

sarahalshammery commented 3 years ago

Please provide your complete code and data, I will find out where the problem is.

Hello Huerqiang, thank you for the help. I am unsure of how to provide such large and confidential data. The code above is all the code used for this. I can provide context for my data objects used above. mygenes object <- has all of my differentially expressed genes following edgeR differential gene expression tt$ENTREZID <- a vector of the Entrezid from my universe (all genes in the experiment) Again here is the code for the reactome enrichment analysis (which works and produces a compareCluster result)

my_reac<-compareCluster(ENTREZID~direction,data=mygenes,fun="enrichPathway",
                       pvalueCutoff = 0.05,universe=tt$ENTREZID,readable=T)

I can also plot this using the dotplot function, however when I try to plot using cnetplot function it gives the error.

cnetplot(my_reac)
Error in sum(y_union[ii, 9]) : invalid 'type' (character) of argument

The cnetplots work completely fine using an enrichResult object.

I would appreciate any advise on how to proceed. Thank you.

huerqiang commented 3 years ago

You can send the data to my email 13766876214@163.com.

zofieLin commented 3 years ago

Hi, I also have a problem in generating a cnetplot from a compareCluster result, also same error with emapplot.

cnetplot(cgo, showCategory = 5, foldChange = NULL, layout = "kk")
Error in (function (classes, fdef, mtable)  : unable to find an inherited method for function ‘cnetplot’ for signature ‘"compareClusterResult"’

But it runs well with enrichGO result. Here are my codes for enrichGO and compareCluster:

ego <- enrichGO(gene$ENTREZID, OrgDb = org.Hs.eg.db, ont = "BP", pAdjustMethod = "BH", pvalueCutoff = 1, qvalueCutoff = 1, keyType = "ENTREZID", readable = TRUE)    
cgo <- compareCluster(geneCluster = com, fun = "enrichGO", OrgDb = org.Hs.eg.db, ont = "BP", pAdjustMethod = "BH", pvalueCutoff = 1, qvalueCutoff = 1, keyType = "ENTREZID", readable = TRUE)

image

Thanks!

huerqiang commented 3 years ago

@zofieLin

Prerequisites

Describe you issue

Ask in right place

VictorGoitea commented 3 years ago

I observed exactly the same problem when I try to make a cnetplot from compareClusterResult:

sigDGE_entrez_DownUp <- tibble(Entrez = sigDGE$entrezgene_id, group = sigDGE$Down_Up) %>% dplyr::filter(!is.na(Entrez) & !duplicated(Entrez)) %>% as.data.frame() dim(sigDGE_entrez_DownUp) [1] 376 2

kk_DownUp <- compareCluster(Entrez~group, data = sigDGE_entrez_DownUp, fun = "enrichKEGG", organism = 'mmu', universe = bckg_entrez, pvalueCutoff = 0.05, pAdjustMethod = "BH")

kk_DownUp@readable <- F kk_DownUp_read <- setReadable(kk_DownUp, OrgDb = org.Mm.eg.db, keyType = "ENTREZID") dim(as.data.frame(kk_DownUp_read)) [1] 8 11

enrichplot::cnetplot(kk_DownUp_read, layout = "kk")

Error in sum(y_union[ii, 9]) : invalid 'type' (character) of argument

huerqiang commented 3 years ago

@VictorGoitea Please use the latest version of enrichplot in github.

VictorGoitea commented 3 years ago

You are right, I'm sorry, I was using clusterProfiler 3.16 and I see this was fixed in the last version 3.18... Thanks @huerqiang

sarahalshammery commented 3 years ago

Hello, Thank you @huerqiang for all of your help with this issue.

However, i've also noticed that the cnetplots made with a compareCluster result will not colour the genes even when supplied with a sorted gene vector object as in 3.1 input here

I've tested this using the same data where the cnetplots will not colour if the input is a compareClusterResult but will colour if the input is an enrichResult object.

Would appreciate any help regarding this.

zahramesri commented 3 years ago

@sarahalshammery how did you end up fixing this issue? I have similar problem and do not seem to find the solution. Thanks

sarahalshammery commented 3 years ago

@sarahalshammery how did you end up fixing this issue? I have similar problem and do not seem to find the solution. Thanks

Hi Zahra, Unfortunately, I couldn't find a solution, and didn't get a reply to I just didn't go ahead with the cnet plots. if you find a solution please let me know as well!

zahramesri commented 3 years ago

Thank you for your response. May I ask what alternative you chose?

Best, Zahra

On Tue, May 25, 2021 at 6:43 PM sarahalshammery @.***> wrote:

@sarahalshammery https://github.com/sarahalshammery how did you end up fixing this issue? I have similar problem and do not seem to find the solution. Thanks

Hi Zahra, Unfortunately, I couldn't find a solution, and didn't get a reply to I just didn't go ahead with the cnet plots. if you find a solution please let me know as well!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/YuLab-SMU/clusterProfiler/issues/301#issuecomment-848393485, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUGRVMETFTMH6WTRJW6BXBTTPRG3RANCNFSM4TQMWLVQ .

-- Zahra Mesrizadeh Graduate Student, Bioengineering University of California, San Diego