使用biomaRt将Ensembl ID转换为基因名称

时间:2019-11-15 10:08:25

标签: r biomart

我有一个名为kidney_ensembl的数据集,我需要将Ensembl ID转换为基因名称。

我正在尝试下面的代码,但是没有用。有人可以帮我吗?

我知道也有类似的问题,但是它们并没有帮助我。非常感谢!

converting from Ensembl gene ID's to different identifier

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

library(tidyverse)
kidney <- data.frame(gene_id = c("ENSG00000000003.10","ENSG00000000005.5",
"ENSG00000000419.8","ENSG00000000457.9","ENSG00000000460.12")
)
#kidney <- read_delim("Desktop/kidney_ensembl.txt", delim = "\t")

if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")

library("biomaRt")

mart <- useDataset("hsapiens_gene_ensembl", useMart("ensembl"))
genes <-  kidney$gene_id
gene_IDs <- getBM(filters= "ensembl_gene_id", attributes= c("ensembl_gene_id","hgnc_symbol"),
              values = genes, mart= mart)

kidney_final <- left_join(kidney, gene_IDs, by = NULL)

1 个答案:

答案 0 :(得分:0)

biomart部分起作用了,是因为您的左联接失败,因为没有公共列,gene_IDs在“ ensembl_gene_id”下具有ensembl id,而您的肾脏数据框在“ gene_id”下具有了ensembl id。

此外,您还需要检查它们是源代码还是合奏。 Gencode ID通常具有。[number],例如ENSG00000000003.10,在ensembl数据库中为ENSG00000000003。

library("biomaRt")
library("dplyr")

kidney <- data.frame(gene_id = 
c("ENSG00000000003.10","ENSG00000000005.5",
"ENSG00000000419.8","ENSG00000000457.9","ENSG00000000460.12"),
vals=runif(5)
)
#make this a character, otherwise it will throw errors with left_join
kidney$gene_id <- as.character(kidney$gene_id)
# in case it's gencode, this mostly works
#if ensembl, will leave it alone
kidney$gene_id <- sub("[.][0-9]*","",kidney$gene_id)

mart <- useDataset("hsapiens_gene_ensembl", useMart("ensembl"))
genes <-  kidney$gene_id
gene_IDs <- getBM(filters= "ensembl_gene_id", attributes= c("ensembl_gene_id","hgnc_symbol"),
              values = genes, mart= mart)

left_join(kidney, gene_IDs, by = c("gene_id"="ensembl_gene_id"))

          gene_id      vals hgnc_symbol
1 ENSG00000000003 0.2298255      TSPAN6
2 ENSG00000000005 0.4662570        TNMD
3 ENSG00000000419 0.7279107        DPM1
4 ENSG00000000457 0.3240166       SCYL3
5 ENSG00000000460 0.3038986    C1orf112