Created
April 29, 2016 23:22
-
-
Save dyndna/632059043663e257070548b08236de75 to your computer and use it in GitHub Desktop.
Convert between Ensembl gene ID and Entrez gene id/symbol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### 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