2
$\begingroup$

I have a matrix with ensemblIds which I am trying to convert to gene symbols using BioMart. Some of the ensemblIds will not be mapped, so I need to subset the rows of the matrix. It seems like BioMart adds one ensemblId or at least I see one more result ultimately than should be. Here is what I am trying to do:

library(dplyr)
library(tibble)
ids <- rownames(mtx_combined)
mart <- useDataset("mmusculus_gene_ensembl", useMart("ensembl"))
list <- getBM(filters= "ensembl_gene_id", attributes= c("ensembl_gene_id",
                           "mgi_symbol","description"),values=ids,mart= mart)
mtx_mapped <- as.matrix(as.data.frame(mtx_combined) %>% 
rownames_to_column("gene") %>%
filter(rownames(mtx_combined) %in% list$ensembl_gene_id) %>%
column_to_rownames("gene"))

rownames(mtx_mapped) <- list$mgi_symbol   //Fails 

Length of the returned list is 18337, number of rows in the initial matrix is 18376. After subsetting I expect to get 18337 rows, but getting one less - 18336. What am I doing wrong here?

$\endgroup$
1
  • $\begingroup$ What is the extra line? Just print them out and see. Could it be adding a header, for example? $\endgroup$
    – terdon
    May 2 '18 at 8:58
6
$\begingroup$

There’s no 1:1 mapping between the IDs of different database schemas. As a consequence, some Ensembl gene IDs map to multiple MGI symbols, or to none (and vice versa).

Therefore, you can’t assume that the number of result rows will be equal to the number of query IDs.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.