Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
948 views
in Technique[技术] by (71.8m points)

dataframe - How can I convert Ensembl ID to gene symbol in R?

I have a data.frame containing Ensembl IDs in one column; I would like to find corresponding gene symbols for the values of that column and add them to a new column in my data frame. I used bioMaRt but It couldn't find any of the Ensembl IDs!

Here is my sample data (df[1:2,]):

row.names organism    gene
41  Homo-Sapiens ENSP00000335357
115 Homo-Sapiens ENSP00000227378

and I want to get something like this

row.names organism    gene         id
41  Homo-Sapiens ENSP00000335357   CDKN3
115 Homo-Sapiens ENSP00000227378   HSPA8

and here is my code:

library('biomaRt')
mart <- useDataset("hsapiens_gene_ensembl", useMart("ensembl"))
genes <- df$genes
df$id <- NA
G_list <- getBM(filters= "ensembl_gene_id", attributes= c("ensembl_gene_id",
"entrezgene", "description"),values=genes,mart= mart)

Then I get this when I check the G_list

[1] ensembl_gene_id entrezgene      description  <0 rows> (or 0-length row.names)

So I couldn't add G_list to my df! because there is nothing to add!

Thanks in Advance,

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is because the values you have in your gene column are not gene ids, they are peptide id (they start with ENSP). To get the info you need, try replacing ensembl_gene_id by ensembl_peptide_id:

G_list <- getBM(filters = "ensembl_peptide_id", 
                attributes = c("ensembl_peptide_id", "entrezgene", "description"),
                values = genes, mart = mart)

Also, what you are really looking for is the hgnc_symbol

Here is the total code to get your output:

library('biomaRt')
mart <- useDataset("hsapiens_gene_ensembl", useMart("ensembl"))
genes <- df$genes
df<-df[,-4]
G_list <- getBM(filters= "ensembl_peptide_id", attributes= c("ensembl_peptide_id","hgnc_symbol"),values=genes,mart= mart)
merge(df,G_list,by.x="gene",by.y="ensembl_peptide_id")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...