R/x2y.R

Defines functions seekX2Y

Documented in seekX2Y

# Install Package: Ctrl + Shift + B
# devtools::document()

#' Conversion between different genes IDs within the same species
#'
#' #' Imports:
#' AnnotationDbi,
#' org.Hs.eg.db,
#' org.Mm.eg.db,
#'
#' @param x vector of characters, the gene IDs of the type 'xtype'
#' @param xtype character, indicating the gene ID type of the input 'x', e.g. "ENTREZID", "SYMBOL", etc.
#' @param ytype character, indicating the desired gene ID type for the output, e.g. "ENTREZID", "SYMBOL", etc.
#' @param species character, specifying the species, must be either "human" or "mouse"
#' @return a vector of characters, the gene IDs of the output type 'ytype'
#' @details calls mapIds from the AnnotationDbi package. Option multivals is set to "first"
#' @examples
#' myGenes <- c("KRT83","CD80","SLC14A1")
#' seekX2Y(myGenes, "SYMBOL", "ENTREZID", "human")
seekX2Y <- function(x, xtype, ytype, species){
  x[is.na(x) | x %in% ""] <- "unknown"
  if(species %in% "human"){
    x1 <- AnnotationDbi::mapIds(org.Hs.eg.db::org.Hs.eg.db,keys=x,column=ytype,keytype=xtype,multiVals="first")
  }else if(species %in% "mouse"){
    x1 <- AnnotationDbi::mapIds(org.Mm.eg.db::org.Mm.eg.db,keys=x,column=ytype,keytype=xtype,multiVals="first")
  }
  #names(x1)[is.na(names(x1))] <- "_"
  x1
}
Solatar/seeqR documentation built on Feb. 19, 2021, 8:07 p.m.