How to replace Gene Symbols with Ensembl ID?
1
0
Entering edit mode
2.1 years ago

I want to replace the gene_symbols of my data frame with the Ensembl ID.

library(biomaRt)

genes <- rownames(exp.kirp)

ensembl <- useMart("ensembl", dataset="hsapiens_gene_ensembl")

g_list <- getBM(attributes = c('ensembl_gene_id','hgnc_symbol', 
                               filters='hgnc_symbol',values=genes,
                               mart=ensembl))

Traceback:

Error in martCheck(mart) : 
  You must provide a valid Mart object. To create a Mart object use the function: useMart.  Check ?useMart for more information.

Sample data:

> dput(exp.kirp[1:10,1:10])
structure(list(TCGA.2K.A9WE.01A = c(201.3304, 4.1094, 0.5137, 
81.9109, 0, 20899.5608, 1326.8268, 13.8693, 0, 1083.8577), TCGA.2Z.A9J1.01A = c(34.1519, 
37.1701, 0, 122.4433, 0, 5456.0922, 2339.2393, 7.9296, 0, 1169.124
), TCGA.2Z.A9J2.01A = c(45.8403, 17.345, 0, 184.9223, 0, 4954.3084, 
976.2745, 0, 0, 1277.3338), TCGA.2Z.A9J3.01A = c(26.0224, 10.1339, 
11.9435, 187.0069, 0, 1151.2088, 1001.8096, 39.0879, 0, 937.7488
), TCGA.2Z.A9J5.01A = c(255.3725, 36.8627, 3.1373, 118.8157, 
0, 13154.1333, 1324.7059, 6.2745, 0, 1367.8431), TCGA.2Z.A9J6.01A = c(35.1924, 
99.4503, 0.4998, 121.8191, 0, 4201.5892, 1808.096, 45.4773, 0, 
1283.8581), TCGA.2Z.A9J7.01A = c(123.7406, 4.755, 0, 152.2335, 
2.1133, 1999.8732, 1551.1821, 20.0766, 0, 1404.3059), TCGA.2Z.A9J8.01A = c(12.2705, 
42.0701, 0, 242.3773, 0.3339, 4089.1853, 964.6077, 34.3907, 0, 
995.9933), TCGA.2Z.A9J9.01A = c(66.4361, 0.374, 0, 53.1638, 0.374, 
29835.2992, 1418.1002, 22.8123, 0.7479, 624.1586), TCGA.2Z.A9JD.01A = c(8.916, 
19.1909, 0, 407.1369, 0, 1979.1183, 1784.751, 2.5934, 0, 729.2531
)), row.names = c("A1BG", "A1CF", "A2BP1", "A2LD1", "A2ML1", 
"A2M", "A4GALT", "A4GNT", "AAA1", "AAAS"), class = "data.frame")
r biomart • 868 views
ADD COMMENT
1
Entering edit mode

What is the error message that appears after ensembl <- useMart("ensembl", dataset="hsapiens_gene_ensembl"); the ensembl variable isn't being set, so there has to be an error.

ADD REPLY
0
Entering edit mode
2.1 years ago
nhaus ▴ 420

You closed the bracket at the wrong position. This code should do what you want:

ensembl = useEnsembl(
  biomart = "genes",
  dataset = "hsapiens_gene_ensembl",
  GRCh = 37,
  verbose = T
)

ensembl <- useDataset(dataset = "hsapiens_gene_ensembl", mart = ensembl)

g_list <- getBM(attributes = c('ensembl_gene_id','hgnc_symbol'), 
                               filters='hgnc_symbol',values=your_genes,
                               mart=ensembl)
ADD COMMENT

Login before adding your answer.

Traffic: 1819 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6