I am trying to convert a list of gene names into Ensembl IDs but I'm having a bit of trouble.

I've tried using the EnsDb.Hsapiens.v86 package but I always get LRG-ID values returned as well, even when using the GeneIdFilter "startsWith" thing.
My code looks like this:

targets <- as.character(targetCSV[, 2])

targetEnsemble <- ensembldb::select(
      filter = GeneIdFilter("ENS", "startsWith"),
      keys = targets, 
      keytype = "SYMBOL", 
      columns = c("SYMBOL","GENEID"))

And for example I get back:

    SYMBOL          GENEID
1     CYR61 ENSG00000142871
2      CTGF ENSG00000118523
3    AMOTL2 ENSG00000114019
4    ANKRD1 ENSG00000148677
5    ANKRD1         LRG_379
6    IGFBP3 ENSG00000146674
7        F3 ENSG00000117525

I also tried using org.Hs.eg.db package but get a different problem where some of my genes return NA.

My code:

  mapIds(x = org.Hs.eg.db, 
     keys = targets, 
     fuzzy = TRUE,
     multiVals = first)

And this works on some but not all the genes for some reason.

[1] NA

[1] NA

[1] "ENSG00000114019"

[1] "ENSG00000148677"

[1] "ENSG00000146674"

[1] "ENSG00000117525"

If anyone can solve either of these problems that would be great, thanks in advance!

  • 1
    $\begingroup$ Have you considered just downloading a list of gene IDs and the associated gene names from Ensembl Biomart? $\endgroup$ – Devon Ryan Apr 24 at 13:54
  • $\begingroup$ Yeah but I wanted to be able to change out the genesets quickly and this just added another annoying step $\endgroup$ – Jack Henry Apr 24 at 14:08
  • 1
    $\begingroup$ There's an R package to allow fetching those programmatically from biomart. $\endgroup$ – Devon Ryan Apr 24 at 14:21

You can pull a full list of Ensembl gene IDs and MGI symbols from biomaRt in R. From there it should be easy enough to filter for the genes you want:

hsapiens_genes <- getBM(attributes = c("ensembl_gene_id", 
                        mart = useMart("ensembl", dataset = "hsapiens_gene_ensembl"))

You do not find some genes in your example because you were not using the official gene name. For example CTGF is offocially called CCN2 and with this name you will find the appropriate Ensembl gene ID in the biomaRt table. This is why I personally prefer to use gene name that are like ENSG00000118523|CCN2 in my work. That way you always have a unique identifier (the Ensembl ID) that is unambiguous and you do not run into trouble that for one gene many more or less official gene names exist.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.