I gave a similar answer for human, here: Answer: Translating gene names to entrez id's

genes <- c('ENSMUSG00000031201', 'ENSMUSG00000017146',
  'ENSMUSG00000041147', 'ENSMUSG00000034218', 'ENSMUSG00000059552')
require(org.Mm.eg.db)
mapIds(
  org.Mm.eg.db,
  keys = genes,
  column = 'SYMBOL',
  keytype="ENSEMBL")

ENSMUSG00000031201 ENSMUSG00000017146 ENSMUSG00000041147 ENSMUSG00000034218 
           "Brcc3"            "Brca1"            "Brca2"              "Atm" 
ENSMUSG00000059552 
           "Trp53"

select(
  org.Mm.eg.db,
  keys = genes,
  column = c('SYMBOL', 'ENTREZID', 'ENSEMBL'),
  keytype="ENSEMBL")

             ENSEMBL SYMBOL ENTREZID
1 ENSMUSG00000031201  Brcc3   210766
2 ENSMUSG00000017146  Brca1    12189
3 ENSMUSG00000041147  Brca2    12190
4 ENSMUSG00000034218    Atm    11920
5 ENSMUSG00000059552  Trp53    22059
require(biomaRt)
ensembl <- useMart('ensembl', dataset="mmusculus_gene_ensembl")

annot <- getBM(
  attributes = c(
    'mgi_symbol',
    'external_gene_name',
    'ensembl_gene_id',
    'entrezgene_id',
    'gene_biotype'),
  filters="ensembl_gene_id",
  values = genes,
  mart = ensembl)

annot <- merge(
  x = as.data.frame(genes),
  y =  annot,
  by.y = 'ensembl_gene_id',
  all.x = T,
  by.x = 'genes')

annot
               genes mgi_symbol external_gene_name entrezgene_id   gene_biotype
1 ENSMUSG00000017146      Brca1              Brca1         12189 protein_coding
2 ENSMUSG00000031201      Brcc3              Brcc3        210766 protein_coding
3 ENSMUSG00000034218        Atm                Atm         11920 protein_coding
4 ENSMUSG00000041147      Brca2              Brca2         12190 protein_coding
5 ENSMUSG00000059552      Trp53              Trp53         22059 protein_coding

Kevin



Source link