R/external.R

Defines functions refseqDESeq2 refseqWGCNA

Documented in refseqDESeq2 refseqWGCNA

#' refseqWGCNA
#' 
#' @description Text mining WGCNA results
#' @details Return the list of biotext class object per cluster for the blockwise module results in WGCNA
#' 
#' @param wgcna results of blockwiseModules()
#' @param keyType key type of gene
#' @param argList argument list to pass to refseq()
#' @export
#' @examples
#' cols <- sample(c(1), 6, replace=TRUE)
#' names(cols) <- c("PNKP","ERCC2","ERCC3","IRF3","TP53","MCM6")
#' wg <- list("colors"=cols)
#' refseqWGCNA(wg, keyType="SYMBOL")
#' @return list of biotext class object
refseqWGCNA <- function(wgcna, keyType="ENSEMBL", argList=list()) {
    all_cols <- unique(wgcna$colors)
    qqcat("Processing a total of @{length(all_cols)} clusters\n")
    lapply(all_cols, function(col) {
        input <- wgcna$colors[wgcna$colors == col] |> names()
        argList[["geneList"]] <- input
        if (!("keyType" %in% names(argList))) {
            argList[["keyType"]] <- keyType
        }
        res <- try(do.call(refseq, argList))
        if ("try-error" %in% class(res)) {
            return(NA)
        } else { return(res) }
    })
}

#' refseqDESeq2
#' 
#' @description Text mining DESeq2 results
#' @details Return the biotext class object by specified filter in DESeq2 results object
#' 
#' @param res results of DESeq2::results()
#' @param condition filtering condition
#' @param keyType key type of gene
#' @param argList argument list to pass to refseq()
#' @export
#' @return list of biotext class object
refseqDESeq2 <- function(res, condition, keyType="ENSEMBL",
    argList=list()) {
    argList[["geneList"]] <- res %>%
        data.frame() %>%
        filter(!!enquo(condition)) %>%
        row.names()
    if (!("keyType" %in% names(argList))) {
        argList[["keyType"]] <- keyType
    }
    do.call(refseq, argList)
}
noriakis/wcGeneSummary documentation built on May 31, 2024, 4:42 p.m.