Skip to content

Instantly share code, notes, and snippets.

@sirusb
Last active December 12, 2015 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirusb/4761150 to your computer and use it in GitHub Desktop.
Save sirusb/4761150 to your computer and use it in GitHub Desktop.
These R code snippets are used to convert between Entrez and Ensembl IDs using biomart web-service. it just exploits the functionalities offered by the biomaRt package. The code is implemented to call the Biomart web-service each time. you can make it more general by calling the first four lines separatly and just passing the "hsp" variable to f…
#Usage example:
#EntrezID<-c("2114","9757","5886","9373","6921","4088","7006","6196","10054","10945")
#EnsemblID<-EntrezToEnsembl(EntrezID)
EntrezToEnsembl<-function(EntrezID){
require(biomaRt);
ensemble<-useMart("ensembl");
hsp<-useDataset(mart=ensemble,dataset="hsapiens_gene_ensembl");
ids<-getBM(filters= "entrezgene",
attributes= c("entrezgene","ensembl_gene_id", "external_gene_id","description"),
values= EntrezID, mart= hsp);
return(ids);
}
#Usage example:
#EnsemblID<-c("ENSG00000164548","ENSG00000118515","ENSG00000105705","ENSG00000177414","ENSG00000108179")
#EntrezID<-EnsemblToEntrez(EnsemblID)
EnsemblToEntrez<-function(EnsemblIDs){
require(biomaRt)
ensemble<-useMart("ensembl")
hsp<-useDataset(mart=ensemble,dataset="hsapiens_gene_ensembl")
ids<-getBM(filters= "ensembl_gene_id",
attributes= c("ensembl_gene_id", "external_gene_id", "entrezgene", "description"),
values= EnsemblIDs, mart= hsp)
return(ids)
}
EntrezToHGNC<-function(EntrezID){
require(biomaRt);
ensemble<-useMart("ensembl");
hsp<-useDataset(mart=ensemble,dataset="hsapiens_gene_ensembl");
ids<-getBM(filters= "entrezgene",
attributes= c("entrezgene","hgnc_id", "hgnc_symbol","description"),
values= EntrezID, mart= hsp);
return(ids);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment