Skip to content

Instantly share code, notes, and snippets.

@dyndna
Created April 29, 2016 23:22
Show Gist options
  • Save dyndna/632059043663e257070548b08236de75 to your computer and use it in GitHub Desktop.
Save dyndna/632059043663e257070548b08236de75 to your computer and use it in GitHub Desktop.
Convert between Ensembl gene ID and Entrez gene id/symbol
#### Get gene annotations ####
# By Michael Love, http://www.bioconductor.org/help/workflows/rnaseqGene/
library("AnnotationDbi")
library("org.Hs.eg.db")
columns(org.Hs.eg.db)
convertIDs <- function( ids, from, to, db, ifMultiple=c("putNA", "useFirst")) {
stopifnot( inherits( db, "AnnotationDb" ) )
ifMultiple <- match.arg( ifMultiple )
suppressWarnings( selRes <- AnnotationDbi::select(
db, keys=ids, keytype=from, columns=c(from,to) ) )
if ( ifMultiple == "putNA" ) {
duplicatedIds <- selRes[ duplicated( selRes[,1] ), 1 ]
selRes <- selRes[ ! selRes[,1] %in% duplicatedIds, ]
}
return( selRes[ match( ids, selRes[,1] ), 2 ] )
}
# Example:
#res$hgnc_symbol <- convertIDs(row.names(res), "ENSEMBL", "SYMBOL", org.Hs.eg.db)
#res$entrezgene <- convertIDs(row.names(res), "ENSEMBL", "ENTREZID", org.Hs.eg.db)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment