# Too slow issue of BioMart

I am using library(biomaRt) in R to annotate SNP rsid. It takes too much time for only 1000 SNPs....... I would like to know how I can run this code faster.

 coords<-data
coords$$chr_name<-coords$$chromosome
coords$$start<-coords$$position
coords$$end<-coords$$position
coords<-coords%>%dplyr::select(chr_name,start,end)
mart=useMart(biomart="ENSEMBL_MART_SNP", host="grch37.ensembl.org",
path="/biomart/martservice", dataset="hsapiens_snp")
results=data.frame(matrix(ncol=4,nrow=0))
for (i in seq (1,nrow(coords)))
{
ens=getBM(attributes = c('refsnp_id','allele','chrom_start','chrom_strand'),
filters = c('chr_name','start','end'), values = as.list(coords[i,]), mart = mart)
results=rbind(results,ens)}


I am using the following code, but still not working......

coords$$newposition<-paste0(coords$$chromosome,":",coords$$position) coords$$chromosomal_region<-paste0(coords$$newposition,":",coords$$position)
coords<-coords\$chromosomal_region
res<-getBM(attributes = c('refsnp_id','allele','chrom_start','chrom_strand'),
filters = 'chromosomal_region',
values = coords,
mart = mart)


Don't run getBM 1000 times. It can handle whole vectors, and get you all your results at once.

• Sorry, could give me some example codes? Oct 9 '20 at 22:30
• vectorising the function is a good idea and would speed up the process. It would be nice if @swbarnes2 gave a less terse answer with e.g some example code on how to achieve it. Oct 10 '20 at 13:15