Looping in R to perform a GSEA analysis
1
0
Entering edit mode
6 months ago

Hi!

I need to run a GSEA analysis on distinct lists of pre-ranked DEG, as well as diverse lists of gene sets obtained from MSigDB. To run the analysis using one pre-ranked list and one gene set, the code is:

fgsea_results <- fgsea(kegg.db, #Gene set
                                   b, #List of pre-ranked DEG
                                   minSize = 15, 
                                   maxSize = 500, 
                                   nPerm = 10000
                                   )

To follow good practices in code writing and, also, for avoid DRY I figured out that I need to build a for loop to run the analysis in all my pre-ranked lists or the gene sets. A first attempt to build a for loop was the next

for (samples in c(a, b, c, d)) {
   fgsea(kegg.db, #Gene set
             samples, #List of pre-ranked DEG
             minSize = 15, 
             maxSize = 500, 
             nPerm = 10000
              )}

However, there's something I missed cause result was not successful. I need your help to solve this issue.

Best regards! Rodolfo

RNA-Seq GSEA loops R • 343 views
ADD COMMENT
0
Entering edit mode

fgsea_results <- fgsea(kegg.db, #Gene set b, #List of pre-ranked DEG minSize = 15, maxSize = 500, nPerm = 10000 )

Here, would you tell me please how to create kegg.db? I mean how to retrieve pathways for given differentially expressed gene?

ADD REPLY
0
Entering edit mode

Please make comments with ADD REPLY. You can download KEGG pathways e.g. from MSigDB as gmt files and then read these into R with fgsea:: gmtPathways().

ADD REPLY
2
Entering edit mode
6 months ago
ATpoint 49k

If you c() lists then you concat them together. By the way c is an unfortunate variable name because there is a function called c().

Try:

for (samples in c("a", "b", "c", "d")) {
   fgsea(kegg.db,
         get(samples), 
         minSize = 15, 
         maxSize = 500, 
         nPerm = 10000)
}
ADD COMMENT
0
Entering edit mode

Thanks for your help and suggestions! It worked fine.

ADD REPLY

Login before adding your answer.

Traffic: 2049 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6