enrichplot icon indicating copy to clipboard operation
enrichplot copied to clipboard

Dotplot of compareCluster enrichGO ALL ontology [fixing & enhancement]

Open gaospecial opened this issue 2 years ago • 4 comments

This is for https://github.com/YuLab-SMU/clusterProfiler/issues/482

When fortify compareClusterResult that frome enrichGO() and ontology = "all", the cluster of data is wrong assigned. And this should be a bug.

I, therefore, fixed this bug,

        if (class(result$GeneRatio) == "character" && grep("/", result$GeneRatio[1])) {
            gsize <- as.numeric(sub("/\\d+$", "", as.character(result$GeneRatio)))
            gcsize <- as.numeric(sub("^\\d+/", "", as.character(result$GeneRatio)))
            result$GeneRatio <- gsize/gcsize
            if (("ONTOLOGY" %in% colnames(result)) && (length(unique(result$ONTOLOGY)) > 1)){
                # do nothing
            } else {
                cluster <- paste(as.character(result$Cluster),"\n", "(", gcsize, ")",
                                 sep="")
                lv <- unique(cluster)[order(as.numeric(unique(result$Cluster)))]
                result$Cluster <- factor(cluster, levels = lv)
            }
        }

and further adjust the corresponding dotplot method to plot a satisfactory figure.

    # show multiply GO enrichment result in separate panels
    if ("ONTOLOGY" %in% colnames(df) && length(unique(df$ONTOLOGY)) > 1){
        p = p + facet_grid(
            ONTOLOGY ~ .,
            scales = "free",
            space = "free"
        )
    }

While run the following example.

data(geneList, package="DOSE")
mydf <- data.frame(Entrez=names(geneList), FC=geneList)
mydf <- mydf[abs(mydf$FC) > 1,]
mydf$group <- "upregulated"
mydf$group[mydf$FC < 0] <- "downregulated"
mydf$othergroup <- "A"
mydf$othergroup[abs(mydf$FC) > 2] <- "B"


library(org.Hs.eg.db)
formula_res <- compareCluster(Entrez~group+othergroup, data=mydf, fun="enrichGO", OrgDb = org.Hs.eg.db, ont = "ALL")
dotplot(formula_res, label_format = 60)

It will give:

image

gaospecial avatar Jun 30 '22 01:06 gaospecial

春晖哥,我觉得您对fortify.compareClusterResult的处理方式很不错。

p = p + facet_grid(
            ONTOLOGY ~ .,
            scales = "free",
            space = "free"
        )

这一句是否有必要?我感觉把是否分面由用户自行处理比较合适。

huerqiang avatar Jul 10 '22 15:07 huerqiang

春晖哥,我觉得您对fortify.compareClusterResult的处理方式很不错。

p = p + facet_grid(
            ONTOLOGY ~ .,
            scales = "free",
            space = "free"
        )

这一句是否有必要?我感觉把是否分面由用户自行处理比较合适。

从设计理念上讲,去掉比较合适;从对用户友好上讲,留着也未尝不可。请老板 @GuangchuangYu 定夺吧。

gaospecial avatar Jul 13 '22 09:07 gaospecial

I also met the bug when I did compareCluster fun = enrichGO ont = "ALL", and I have read the code for the bug, but I have some trouble to apply it myself. Could you explain how to fix it in detail? Should I modify the R Package or create an R script?

Linclesimple avatar Jul 19 '22 14:07 Linclesimple

I also met the bug when I did compareCluster fun = enrichGO ont = "ALL", and I have read the code for the bug, but I have some trouble to apply it myself. Could you explain how to fix it in detail? Should I modify the R Package or create an R script?

I solved this problem by replacing the dotplot.R and mothed-fortify.R files in enrichplot-master.zip and installing enrichplot package in again. Thanks for your code!

Linclesimple avatar Jul 20 '22 06:07 Linclesimple

FYI, I will comment out the facet code.

GuangchuangYu avatar Aug 20 '22 07:08 GuangchuangYu