Defines functions prepareAnnot

Documented in prepareAnnot

#' @title Prepare user-supplied mapping between CpGs and genes.
#' @description This function prepares CpG to gene mapping which will be
#' used by methylRRA and methylglm.
#' @param CpG2Gene A matrix, or a data frame or a list contains CpG to gene
#' mapping. For a matrix or data frame, 1st column should be CpG ID and 2nd
#' column should be gene name. For a list, entry names should be gene names,
#' and elements correpond to CpG IDs.
#' @param geneidtype A string. "SYMBOL", "ENSEMBL", "ENTREZID" or "REFSEQ".
#' Default is "SYMBOL".
#' @export
#' @import org.Hs.eg.db
#' @importFrom AnnotationDbi select
#' @return A data frame contains ready to use CpG to gene mapping.
#' @references Carlson M (2017). org.Hs.eg.db:
#' Genome wide annotation for Human. R package version 3.5.0.
#' @examples
#' data(CpG2Genetoy)
#' FullAnnot = prepareAnnot(CpG2Gene)
#' head(FullAnnot)

prepareAnnot <- function(CpG2Gene, geneidtype = "SYMBOL"){
    geneidtype = match.arg(
        geneidtype,c("SYMBOL", "ENSEMBL", "ENTREZID", "REFSEQ"))

            stop("CpG ID should be characters")
            stop("CpG2Gene should contain two columns")
        FullAnnot = data.frame(CpG2Gene)
    }else if(is.list(CpG2Gene)){
        FullAnnot = data.frame(
            CpG = unlist(CpG2Gene),
            gene = rep(names(CpG2Gene),vapply(CpG2Gene, length, FUN.VALUE = 0)))
        stop("CpG2Gene should be a matrix or a data frame or a list.")
    colnames(FullAnnot) = c("Name", "UCSC_RefGene_Name")

        temp = suppressMessages(
            select(org.Hs.eg.db, FullAnnot$UCSC_RefGene_Name,
                        columns = "SYMBOL",keytype = geneidtype))
        FullAnnot$UCSC_RefGene_Name = temp$SYMBOL
    rownames(FullAnnot) = FullAnnot$Name

Try the methylGSA package in your browser

Any scripts or data that you put into this service are public.

methylGSA documentation built on Nov. 8, 2020, 8:29 p.m.