Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cnetplot show GO terms and I would like to use description #289

Open
IrelCM opened this issue Aug 21, 2024 · 10 comments
Open

cnetplot show GO terms and I would like to use description #289

IrelCM opened this issue Aug 21, 2024 · 10 comments

Comments

@IrelCM
Copy link

IrelCM commented Aug 21, 2024

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

@guidohooiveld
Copy link

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?

@IrelCM
Copy link
Author

IrelCM commented Aug 28, 2024

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")])
})

@guidohooiveld
Copy link

... and of
y

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

Please format your code!

@guidohooiveld
Copy link

guidohooiveld commented Aug 28, 2024

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

@IrelCM
Copy link
Author

IrelCM commented Aug 28, 2024

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.

@guidohooiveld
Copy link

guidohooiveld commented Aug 28, 2024

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?

@IrelCM
Copy link
Author

IrelCM commented Aug 28, 2024

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

@IrelCM
Copy link
Author

IrelCM commented Sep 30, 2024

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

@guidohooiveld
Copy link

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

@IrelCM
Copy link
Author

IrelCM commented Oct 24, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants