This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to apply enrichGO over a list

Hi all!

I have a list of 16 elements each containing DEx genes between our control and experimental groups

list of DEGs

I would like to do enrichment analysis using enrichGO function from clusterProfiler for each (total 16). How can I apply enrichGO function on each of these from the list (using lapply or for loop in R) so I don't have to do it individually 16 times.

The goal is to get a new list with 16 elements each containing enrichGO results for each of the elements from DEG list.

Can someone help with the code?

Thank you!!

enrichgo clusterprofiler loop r

1 answer

Using for loop:

GOres = list() # define an empty list to store the for loop output from each interation
for(i in 1:length(DEG)) {
  GOres[[i]] = enrichGO(gene          = DEG[[i]],
                        universe      = allExpressedGene, #provide all genes with expression in your experiment/or skip this
                        OrgDb         = org.Hs.eg.db, # assumed the data is coming from human
                        ont           = "CC", # check other options like MF and BP 
                        pAdjustMethod = "BH",
                        pvalueCutoff  = 0.01,
                        qvalueCutoff  = 0.05,
                        readable      = TRUE)
}

Thank you very much!

Log in to answer this question.