如何在R中将Ensembl ID转换为基因符号? [英] How can I convert Ensembl ID to gene symbol in R?
问题描述
我有一列包含Ensembl ID的data.frame;我想为该列的值找到相应的基因符号,并将其添加到我的数据框中的新列中. 我使用了bioMaRt,但找不到任何Ensembl ID!
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!
这是我的示例数据(df[1:2,]
):
Here is my sample data (df[1:2,]
):
row.names organism gene
41 Homo-Sapiens ENSP00000335357
115 Homo-Sapiens ENSP00000227378
我想得到这样的东西
row.names organism gene id
41 Homo-Sapiens ENSP00000335357 CDKN3
115 Homo-Sapiens ENSP00000227378 HSPA8
这是我的代码:
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)
然后我在检查G_list时得到了这个
Then I get this when I check the G_list
[1] ensembl_gene_id entrezgene description <0 rows> (or 0-length row.names)
所以我无法将G_list添加到我的df中!因为没有什么可添加的!
So I couldn't add G_list to my df! because there is nothing to add!
预先感谢
推荐答案
这是因为您在gene
列中具有的值不是基因ID,而是肽ID(它们以ENSP开头).要获取所需的信息,请尝试将ensembl_gene_id
替换为ensembl_peptide_id
:
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)
此外,您真正想要的是hgnc_symbol
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")
这篇关于如何在R中将Ensembl ID转换为基因符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!