AnnotationDbi报错:输入的ENSEMBL键无效问题求助
Hey there! Let's walk through fixing those two errors you ran into when converting ENSEMBL IDs to gene symbols with AnnotationDbi. Both issues boil down to how you're passing the keys parameter—let's break it down step by step.
First Error: object 'GeneNameEnsembl' not found
This error pops up because you haven't defined the GeneNameEnsembl variable yet. The keys argument expects a vector of actual ENSEMBL gene IDs, not just a variable name you haven't set up.
For example, if you have a list of mouse ENSEMBL IDs, you need to first store them in GeneNameEnsembl like this:
# Replace these with your actual ENSEMBL IDs GeneNameEnsembl <- c("ENSMUSG00000000001", "ENSMUSG00000000003", "ENSMUSG00000000028")
Second Error: None of the keys entered are valid keys for 'ENSEMBL'
When you changed keys=GeneNameEnsembl to keys='GeneNameEnsembl', you told R to treat the string literal "GeneNameEnsembl" as an ENSEMBL ID—which it's not! Valid ENSEMBL IDs for mice start with ENSMUSG followed by numbers, so R can't find a match in the annotation database.
Full Working Code
Here's the complete, corrected workflow to get your gene symbols:
First, make sure you have the required annotation package installed and loaded (since you're working with mouse data, we use
org.Mm.eg.db):# Install the package if you haven't already if (!require("org.Mm.eg.db")) { BiocManager::install("org.Mm.eg.db") } library(org.Mm.eg.db)Define your ENSEMBL ID vector:
# Replace with your actual list of ENSEMBL IDs GeneNameEnsembl <- c("ENSMUSG00000000001", "ENSMUSG00000000003", "ENSMUSG00000000028")Run the conversion:
GeneNameSymbol <- AnnotationDbi::select(org.Mm.eg.db, keys = GeneNameEnsembl, columns = 'SYMBOL', keytype = 'ENSEMBL')
Quick Tip
If you ever want to check what valid ENSEMBL IDs look like for your organism, you can run this to see a few examples:
# View the first 5 valid mouse ENSEMBL IDs head(keys(org.Mm.eg.db, keytype = "ENSEMBL"))
内容的提问来源于stack exchange,提问作者Maryam

