This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Using biomaRt to find the nearest upstream/ downstream gene from an Ensembl ID

I have a bunch of Ensembl Transcript IDs (ENST....) and I'd like to know their nearest upstream and downstream genes. I've used the getBM function but I've not found the attributes I'm looking for. Can anyone suggest any other ways to do this? Or if I've missed a way to do this in biomaRt?

Thanks

biomart ensembl

1 answer

biomaRt is not the best tool for this query; there is no attribute that will directly return the information you want.

One approach would be to retrieve the chromosome, transcript start, transcript end and strand of the ENST ID, then use the chromosomal_region filter to query for genes. For example:

library(biomaRt)
mart.hs <- useMart("ensembl", "hsapiens_gene_ensembl")

enst <- getBM(attributes = c("ensembl_transcript_id", "chromosome_name", "transcript_start", "transcript_end", "strand"), filters = "ensembl_transcript_id", values = "ENST00000520959", mart = mart.hs)

# query for gene IDs 50 kbp upstream
region <- paste(enst$chromosome_name, enst$transcript_start - 50000, enst$transcript_start, enst$strand, sep = ":")

getBM(attributes = "ensembl_gene_id", filters = "chromosomal_region", values = region, mart = mart.hs)

  ensembl_gene_id
1 ENSG00000104613
2 ENSG00000175445

In this case ENSG00000175445 is the gene for the ENST and ENSG00000104613 is upstream.

But there are better tools for this purpose; search this site or look at the similar posts on the right of this page, especially Find Nearest Gene Upstream Using Mysql And Perl Program.

That's the style of solution I was leaning to. Good to know I hadn't missed any simple attributes!

Quite an elegant solution even though not designed for the purpose, thanks!

Log in to answer this question.