R/anncpg.R

Defines functions ann.cpg

Documented in ann.cpg

#' Annotate CpGs
#'
#' Provides annotation for the CpGs of a data.frame.
#' @param cpgs data.frame including the probe identifiers as row names.
#' @param array Type of Illumina methylation array: EPIC or 450k.
#' @param what What to annotate. Four options: all, gene, island, or short.
#' @examples 
#' array <- "EPIC"
#' what <- "short"
#' @export
ann.cpg <- function(cpgs, array, what="all"){
  if(array=="EPIC"){
    ann <- minfi::getAnnotation(IlluminaHumanMethylationEPICanno.ilm10b4.hg19::IlluminaHumanMethylationEPICanno.ilm10b4.hg19)
  } else if(array=="450k"){
    ann <- minfi::getAnnotation(IlluminaHumanMethylation450kanno.ilmn12.hg19::IlluminaHumanMethylation450kanno.ilmn12.hg19)
  } else{
    stop(paste0(array," is not a valid array type."))
  }
  if(what=="all"){
    return(cbind(cpgs,ann[match(rownames(cpgs),ann$Name), ])) 
  } else if(what=="gene"){
    gene_ann <- c("chr", "pos", "strand", "UCSC_RefGene_Name", "UCSC_RefGene_Accession", "UCSC_RefGene_Group")
    return(cbind(cpgs,ann[match(rownames(beta_values),ann$Name), gene_ann]))
  } else if(what=="island"){
    island_ann <- c("chr", "pos", "strand","Relation_to_Island", "Islands_Name")
    return(cbind(cpgs,ann[match(rownames(beta_values),ann$Name), island_ann]))
  } else if(what=="short"){
    short_ann <- c("chr", "pos", "strand", "UCSC_RefGene_Name", "UCSC_RefGene_Accession", "UCSC_RefGene_Group", "Relation_to_Island", "Islands_Name")
    return(cbind(cpgs,ann[match(rownames(beta_values),ann$Name), short_ann]))
  } else{
    stop(paste0(what," is not a valid option. Please select one between: all/short/gene/island."))
  }
}
raulsanzr/methtools documentation built on June 30, 2022, 5:58 p.m.