# Load the library
library(biomaRt)
# Define biomart object
mart <- useMart(biomart="ensembl", dataset="hsapiens_gene_ensembl")
# Gives a list of all possible annotations; Currently there are 1668 listed
listAttributes(mart)
# Gives a list of all filters or criteria to search by; Currently there are 333 listed
# I chose to filter by: chromosome_name, start, end
listFilters(mart)
# Read in tab-delimited file with three columns: chromosome number, start position and end position
positions <- read.table("positions.txt")
# Extract HGNC gene symbol
results <- getBM(attributes = c("hgnc_symbol", "chromosome_name", "start_position", "end_position"), filters = c("chromosome_name", "start", "end"), values = list(positions[,1], positions[,2], positions[,3]), mart = mart)
thank you, very helpful!
ReplyDeleteYou're welcome! Glad you found it useful.
DeleteHi! Is it possible to do the reverse? To get chromosomal positions from a list of gene names/symbols
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI got the following error while trying to use the 'getBM' command -
ReplyDeleteQuery ERROR: caught BioMart::Exception::Database: Error during query execution: Got a packet bigger than 'max_allowed_packet' bytes
>
Can you give an idea for solving this problem ?