enrichplot icon indicating copy to clipboard operation
enrichplot copied to clipboard

cnetplot show GO terms and I would like to use description

Open IrelCM opened this issue 1 year ago • 9 comments

Hello, I'm trying to plot a list of my results of enrichment analysis but my plot show GO terms and I would like to show description. If I plot just one element of my list there is no problem to show the description

EnrichR.KO # the list with all enrichment results cnetplot(EnrichR.KO, circular = T, showCategory = 9) Enrichment1

Testing with the first element of the list

cnetplot(EnrichR.KO[[1]], node_label = "category") Enrichment2

Note: I didn't use setReadable() because there is no db for my organism (Phaeodactylum tricornutum).

Could you help me please ? Thank you. Irelka

IrelCM avatar Aug 21 '24 17:08 IrelCM

Since apparently there is no OrgDb for your organism available, could you show the code you used to generate your results? Thus how as EnrichR.KO been generated?

You likely used the generic function enricher, but did not include the argument TERM2NAME?

guidohooiveld avatar Aug 28 '24 13:08 guidohooiveld

Mylist.annot is a list of DE genes for a specific time. EnrichR.KO is a list of enrichment (ORA) results for each time.

EnrichR.KO <- lapply(mylist.annot, function(i) { #output: vector of genes i <- i[,"Gene stable ID"] # Not necessary to rank

#Enrichment analysis y <- enricher( gene = i, pvalueCutoff = 0.05, pAdjustMethod = "BH", universe = mart_export$Gene stable ID, minGSSize = 10, maxGSSize = 500, qvalueCutoff = 0.2, gson = NULL, TERM2GENE = mart_export.GO[,c("GO term accession","Gene stable ID")], TERM2NAME = mart_export.GO[,c("GO term accession", "GO term name")]) })

IrelCM avatar Aug 28 '24 14:08 IrelCM

... and of y

and as.data.frame(y)[1:5,] ??

Please format your code!

guidohooiveld avatar Aug 28 '24 14:08 guidohooiveld

BTW, it works in my hands...

See below for some reproducible code mimicking what you try to achieve, and I would suggest you compare it with what you use as inputs.


> ## load required libaries
> library(clusterProfiler)
> library(enrichplot)
> library(org.Hs.eg.db)
> library(GO.db)
> 
> ## using the example dataset.
> data(geneList, package="DOSE")
> genes <- names(geneList)[abs(geneList) > 2]
> 
> ## create TERM2GENE and TERM2NAME for GO
> ## code is based on clusterProfiler code
> ## https://github.com/YuLab-SMU/clusterProfiler/blob/b24be8c372f947ed79f8f42c1a7f6624c14fb125/R/enrichGO.R#L156
> 
>  
> ## set GO category to be analyzed,
> ## i.e. 'BP', 'CC', 'MF', or 'ALL'
> 
> ont <- "BP"  ##limit sets to GO-BP
> 
> goterms <- AnnotationDbi::Ontology(GO.db::GOTERM)
> if (ont != "ALL") {goterms <- goterms[goterms == ont]}
> 
> term2gene.go <- AnnotationDbi::mapIds(org.Hs.eg.db, keys=names(goterms),
+                                       column="ENTREZID", keytype="GOALL", multiVals='list')
'select()' returned 1:many mapping between keys and columns
> term2gene.go <- stack(term2gene.go)
> term2gene.go <- term2gene.go[!is.na(term2gene.go[,"values"]),] [,c(2,1)]
> colnames(term2gene.go) <- c("from","to")
> 
> term2name.go <- Term(GOTERM)[ names(goterms) ]
> term2name.go <- data.frame("from"=names(term2name.go), "to"=term2name.go)
> 
> head(term2gene.go)
        from   to
2 GO:0000002  142
3 GO:0000002  291
4 GO:0000002 1763
5 GO:0000002 1890
6 GO:0000002 2021
7 GO:0000002 3980
> head(term2name.go)
                 from                               to
GO:0000001 GO:0000001        mitochondrion inheritance
GO:0000002 GO:0000002 mitochondrial genome maintenance
GO:0000003 GO:0000003                     reproduction
GO:0000011 GO:0000011              vacuole inheritance
GO:0000012 GO:0000012       single strand break repair
GO:0000017 GO:0000017        alpha-glucoside transport
> 
> ## run enricher
> res <- enricher(gene = genes,
+                 pvalueCutoff = 0.05,
+                 pAdjustMethod = "BH",
+                 universe = names(geneList),
+                 minGSSize = 10,
+                 maxGSSize = 500,
+                 qvalueCutoff = 0.2,
+                 gson = NULL,
+                 TERM2GENE = term2gene.go,
+                 TERM2NAME = term2name.go)
> 
> cnetplot(res, circular = TRUE, showCategory = 9)
Warning message:
ggrepel: 3 unlabeled data points (too many overlaps). Consider increasing max.overlaps 
> 

image

guidohooiveld avatar Aug 28 '24 14:08 guidohooiveld

y is the result of each enrichment, if I take the first time and as.data.frame(y)[1:5,] image

According to your last answer: For me it works too if I run only one element of my list of enrichments but if I use my entire list because I want to know the descriptions shared between times it doesn't work. It use GO terms and not the description.

IrelCM avatar Aug 28 '24 14:08 IrelCM

So it seems your problem is not directly related to enrichplot...

Yet, it is not clear to me what exactly you try to achieve. To increase your chance of getting more feedback I suggest your provide some reproducible code that illustrates your goal (and problem!). To do so you maybe could use my example code as starting point?

guidohooiveld avatar Aug 28 '24 15:08 guidohooiveld

Thank you for the idea, I will use your code and I will back (after holidays :) )

IrelCM avatar Aug 28 '24 15:08 IrelCM

Hello ! I run my example with your data and I have the same problem, I want to show description not GO terms. When I use cnetplot with an enrichment result there is no problem but if I use cnetplot with a list of enrichment results there in no more description but GO terms and this what I want to avoid.

using the example dataset.

data(geneList, package="DOSE") genes <- names(geneList)[abs(geneList) > 2.5]

genes2 <- names(geneList)[abs(geneList) > 3]

run enricher

res <- enricher(gene = genes, pvalueCutoff = 0.05, pAdjustMethod = "BH", universe = names(geneList), minGSSize = 10, maxGSSize = 500, qvalueCutoff = 0.2, gson = NULL, TERM2GENE = term2gene.go, TERM2NAME = term2name.go)

res2 <- enricher(gene = genes2, pvalueCutoff = 0.05, pAdjustMethod = "BH", universe = names(geneList), minGSSize = 10, maxGSSize = 500, qvalueCutoff = 0.2, gson = NULL, TERM2GENE = term2gene.go, TERM2NAME = term2name.go)

both <- list(res, res2) names(both) <- c("res", "res2")

cnetplot(both, showCategory = 9)

Both

IrelCM avatar Sep 30 '24 13:09 IrelCM

I realize that you updated this thread few weeks ago, but I hope my reply is still useful.

It looks to me that you forgot to include the merge_result step...

Using the code from your previous post, until the generation of res and res2:

## first replace entrezid with symbols (to increase readability)
res <- setReadable(res, OrgDb="org.Hs.eg.db", keyType="ENTREZID")
res2 <- setReadable(res2, OrgDb="org.Hs.eg.db", keyType="ENTREZID")

## prepare input list
both <- list("res"=res, "res2"=res2)

## you did not include this step
both <- merge_result(both)

## run just to be sure  
both <- pairwise_termsim(both)

## set arguments
cex.params = list(category_node=0.5, category_label=1.5, gene_node=0.2, gene_label=1)
## make cnetplot and store in object p
p <- cnetplot(both, showCategory = 2, cex.params=cex.params)
print(p)

image

> ## Note that the position of the text 'gene number' is weird.
> ## To correct this, remove the layer with this text from p,
> ## and add ii using the correct coordinates.
> 
> ## which layer contains 'gene number'?
> p$layers
[[1]]
mapping: edge_alpha = ~I(alpha), x = ~x, y = ~y, xend = ~xend, yend = ~yend, group = ~edge.id 
geom_edge_path: arrow = NULL, lineend = butt, linejoin = round, linemitre = 1, interpolate = FALSE, label_colour = black, label_alpha = 1, label_parse = FALSE, check_overlap = FALSE, angle_calc = rot, force_flip = TRUE, label_dodge = NULL, label_push = NULL, na.rm = FALSE
stat_edge_link: n = 100, na.rm = FALSE
position_identity 

[[2]]
mapping: r = ~radius, alpha = ~I(alpha), x0 = ~x, y0 = ~y, r0 = 0, fill = ~type, amount = ~value, group = ~.group.id 
geom_arc_bar: expand = 0, radius = 0
stat_pie: na.rm = FALSE, n = 360
position_identity 

[[3]]
mapping: r = ~radius, alpha = ~I(alpha), x0 = ~x, y0 = ~y, r0 = 0, fill = ~type, amount = ~value, group = ~.group.id 
geom_arc_bar: expand = 0, radius = 0
stat_pie: na.rm = FALSE, n = 360
position_identity 

[[4]]
mapping: x0 = ~x, y0 = ~y, r0 = ~r, r = ~r, start = ~start, end = ~end 
geom_arc_bar: expand = 0, radius = 0
stat_arc_bar: na.rm = FALSE, n = 360
position_identity 

[[5]]
mapping: xend = ~sign(x, maxr * 1.5), yend = ~y + r, x = ~x, y = ~y + r 
geom_segment: arrow = NULL, arrow.fill = NULL, lineend = butt, linejoin = round, na.rm = FALSE
stat_identity: na.rm = FALSE
position_identity 

[[6]]
mapping: label = ~label, x = ~sign(x, maxr * 1.6), y = ~y + r 
geom_text: parse = FALSE, check_overlap = FALSE, size.unit = mm, na.rm = FALSE
stat_identity: na.rm = FALSE
position_identity 

[[7]]
mapping: x = ~x, y = ~y 
geom_text: na.rm = FALSE
stat_identity: na.rm = FALSE
position_identity 

[[8]]
mapping: label = ~name, x = ~x, y = ~y 
geom_text_repel: parse = FALSE, na.rm = FALSE
stat_filter: na.rm = FALSE
position_identity 

[[9]]
mapping: label = ~name, x = ~x, y = ~y 
geom_text_repel: parse = FALSE, na.rm = FALSE
stat_filter: na.rm = FALSE
position_identity 

> 
> ## look for the most simple layer; this is layer 7.
> ## to remove this layer, set to NULL
> p$layers[[7]] <- NULL
> 
> ## add
> p2 <- p +  ggplot2::annotate("text", x=min(p$data$x), y=min(p$data$y) - 0.5, label = "gene number")
> print(p2)
> 

image

guidohooiveld avatar Oct 23 '24 13:10 guidohooiveld

It's always useful, thank you very much. Indeed, using merge_result it works !
<3

IrelCM avatar Oct 24 '24 14:10 IrelCM