We are hiring ! See our job offers.
swh:1:snp:0c004a03453a29b80f921a24433f7e780b9ceb53
Raw File
Tip revision: fc1777a6ebdabf2ea4e225a2337f0d9f9ae151a8 authored by Alexey Sergushichev on 08 April 2021, 15:17:58 UTC
Update .travis.yml
Tip revision: fc1777a
fgseaTool.R
availableFGSEADatabases <- function () {
    cacheDir <- getOption("phantasusCacheDir")

    dbDir <- file.path(cacheDir, 'fgsea')
    metaFile <- file.path(dbDir, 'fgsea.txt')
    meta = read.table(metaFile, header = TRUE, sep = '\t')

    return (jsonlite::toJSON(meta))
}

FGSEAmeta <- function (cacheDir) {
    dbDir <- file.path(cacheDir, 'fgsea')
    if (!dir.exists(dbDir)) {
        return()
    }

    metaFile <- file.path(dbDir, 'fgsea.txt')
    columnFiles <- list.files(dbDir, '*.rds', full.names = FALSE)
    message('Populating FGSEA pathway meta')
    if (file.exists(metaFile)) {
        meta = read.table(metaFile, header = TRUE, sep = '\t')
    } else {
        meta = data.frame(matrix(ncol=2,nrow=0), stringsAsFactors = FALSE)
    }
    colnames(meta) <- c('FILE', 'HINT')

    for(file in columnFiles) {
        if (nrow(meta[meta$FILE == file,]) == 0) {
            meta[nrow(meta) + 1, ] <- c(file, file)
        }
    }

    write.table(meta, file=metaFile, quote=FALSE, sep='\t', row.names = FALSE)
}

performFGSEA <- function (dbName, ranks) {
    cacheDir <- getOption("phantasusCacheDir")

    dbDir <- file.path(cacheDir, 'fgsea')
    dbFile <- file.path(dbDir, dbName)
    if (!file.exists(dbFile)) {
        stop('Invalid DB name supplied')
    }

    db <- readRDS(dbFile)
    pathways <- lapply(lapply(split(db, db$pathName), '[[', 'geneID'), as.character)
    rranks <- ranks$ranks
    names(rranks) <- ranks$genes

    assign('db', db, envir = parent.frame())

    return (jsonlite::toJSON(fgseaMultilevel(pathways,
                                             rranks,
                                             sampleSize = 101,
                                             absEps = 1e-10,
                                             minSize = 15,
                                             maxSize = 500,
                                             nproc = 1)
                             , digits = NA
                             , na="string"))
}

queryPathway <- function (dbName, pathwayName) {
    cacheDir <- getOption("phantasusCacheDir")

    dbDir <- file.path(cacheDir, 'fgsea')
    dbFile <- file.path(dbDir, dbName)
    if (!file.exists(dbFile)) {
        stop('Invalid DB name supplied')
    }

    db <- readRDS(dbFile)
    filteredDb <- db[db$pathName == pathwayName,]

    jsonlite::toJSON(list(geneID = filteredDb$geneID, geneSymbol = filteredDb$geneSymbol))
}
back to top