Question: Looping in R to perform a GSEA analysis
0
gravatar for rodolfo.peacewalker
4 weeks ago by
rodolfo.peacewalker0 wrote:

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

gsea rna-seq R loops • 111 views
ADD COMMENTlink written 4 weeks ago by rodolfo.peacewalker0
1
gravatar for ATpoint
4 weeks ago by
ATpoint42k
Germany
ATpoint42k wrote:

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 COMMENTlink modified 4 weeks ago • written 4 weeks ago by ATpoint42k

Thanks for your help and suggestions! It worked fine.

ADD REPLYlink written 4 weeks ago by rodolfo.peacewalker0
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1327 users visited in the last hour