This is a test version of Biostars. For the public version, visit https://www.biostars.org.
clusterprofiler: How to extract genes of a specific GO-term/pathway

I was wondering how to get the list of genes grouped in a particular GO-Term of Biological Pathway. I have an enrichGO output (using the clusterprofiler package). From this result, I've into a bar plot (see below). For example, my top enriched pathway is T cell activation, how do I obtain the genes which have been grouped into this pathway?

My code is taken from the clusterProfiler book:

ego2 <- enrichGO(gene         = gene.df$ENTREZID,
            OrgDb         = org.Mm.eg.db,
            keyType       = 'ENTREZID',
            ont           = "BP",
            pAdjustMethod = "BH",
            pvalueCutoff  = 0.01,
            qvalueCutoff  = 0.05)

barplot(ego2, showCategory=10)

Here are some screenshots of what my data looks like in R:

enter link description here enter image description here

clusterprofiler go-term goterm go term analysis

2 answers

ego2@result$geneID should give you a vector of strings containing the Entrez IDs for each gene in each pathway, delimited by "/". You could then split that string into a list via strsplit.

Thanks so much! This seemed to work, as I'm able to see the number of genes as well as their IDs. Is it possible to also have the name of the pathway they are involved in (right now they are numbered, where I assume pathway 1 = T cell activation) or do I just assume they are in the same order as my bar plot?

They will be ranked by p-value by default, so yes, they should match up correctly. Though you could create a named vector by assigning description as the names for your vector to make things a bit easier , i.e:

go_genes <- ego2@results$geneID
names(go_genes) <- ego2@results$description

Thank you very much!

thanks, just a short note for anyone checking this nowadays, in case this doesn't work try Description and result, apparently slight changes to words have happened:

go_genes <- ego2@result$geneID
names(go_genes) <- ego2@result$Description

see the FAQ and the examples in the clusterProfiler 4.0 article.

Log in to answer this question.