montilab / hypeR

An R Package for Geneset Enrichment Workflows
https://montilab.github.io/hypeR-docs/
GNU General Public License v3.0
76 stars 11 forks source link

MSigDB C7 retrieval fails #45

Open hypercompetent opened 2 years ago

hypercompetent commented 2 years ago

Hi Monti Lab team,

Thanks for assembling this great toolkit! It's really streamlining my DEG pathway analysis.

I've run into a bug around retrieving the MSigDB C7 (Immunologic Signatures) gene sets, which I think is due to handling of categories without a subcategory.

Using "" as the subcategory for C7 doesn't work:

msigdb_imm <- msigdb_gsets("Homo sapiens", "C7", "")

Error in msigdbr(species, category, subcategory): unknown subcategory
Traceback:

1. msigdb_gsets("Homo sapiens", "C7", "")
2. msigdb_download(species, category, subcategory)
3. msigdbr(species, category, subcategory)
4. stop("unknown subcategory")

It looks like msigdbr may be expecting NA for this case where there's no subcategory. However, this leads to a new error:

msigdb_imm <- msigdb_gsets("Homo sapiens", "C7", NA)

Error in if (name == "Custom" & !quiet) warning("Describing genesets with a name will aid reproducibility"): missing value where TRUE/FALSE needed
Traceback:

1. msigdb_gsets("Homo sapiens", "C7", NA)
2. gsets$new(genesets, name = name, version = version, clean = clean)
3. initialize(...)

This can be fixed by adding is.na(subcategory) to the ifelse switch in the msigdb_gsets function. This version works:

msigdb_gsets2 <- function(species, category, subcategory = "", clean = FALSE) 
{
    genesets <- msigdb_download(species, category, subcategory)
    name <- ifelse(subcategory == "" | is.na(subcategory), category, paste(category, subcategory, sep = "."))
    version <- msigdb_version()
    gsets$new(genesets, name = name, version = version, clean = clean)
}

msigdb_imm <- msigdb_gsets2("Homo sapiens", "C7", NA)

In case it helps, I'm running hyperR v1.8.0, with msigdbr v7.5.1 .

Cheers, -Lucas Graybuck