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

CC BY-SA 4.0
2020-10-09T22:30:44.330Z
Sorry, could give me some example codes?
user224050
CC BY-SA 4.0
2020-10-10T13:15:36.723Z
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.
user438383
CC BY-SA 4.0
2020-10-09T21:08:18.503Z
2020-10-09T21:08:18.503Z
swbarnes2
<p>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.</p>
<pre><code> coords&lt;-data
 coords<span class="math-container">$chr_name&lt;-coords$</span>chromosome
 coords<span class="math-container">$start&lt;-coords$</span>position
 coords<span class="math-container">$end&lt;-coords$</span>position
 coords&lt;-coords%&gt;%dplyr::select(chr_name,start,end)
 mart=useMart(biomart=&quot;ENSEMBL_MART_SNP&quot;, host=&quot;grch37.ensembl.org&quot;,     
 path=&quot;/biomart/martservice&quot;, dataset=&quot;hsapiens_snp&quot;)
 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)}
</code></pre>
<p>I am using the following code, but still not working......</p>
<pre><code>coords<span class="math-container">$newposition&lt;-paste0(coords$</span>chromosome,&quot;:&quot;,coords<span class="math-container">$position)
coords$</span>chromosomal_region&lt;-paste0(coords<span class="math-container">$newposition,":",coords$</span>position)
coords&lt;-coords$chromosomal_region
res&lt;-getBM(attributes = c('refsnp_id','allele','chrom_start','chrom_strand'), 
   filters = 'chromosomal_region', 
   values = coords, 
   mart = mart)
</code></pre>

CC BY-SA 4.0
2023-01-13T07:51:25.483Z
I am also facing the same issue. I have 5600 SNPs and even after vectorization, I am facing the same timeout problem even for 500 SNPs.
Jyoti Sharma 
<r><biomart>
Too slow issue of BioMart
# Too slow issue of BioMart

(Asked by: username_0 on 2020-10-09)

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)

**Tags:** r, biomart
> **Comments:**
> **username_1**: I am also facing the same issue. I have 5600 SNPs and even after vectorization, I am facing the same timeout problem even for 500 SNPs.  

---

## 1 answers

### Answer by username_2 on 2020-10-09. Score: 1

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

> **Comments:**
> **username_0**: Sorry, could give me some example codes?  
> **username_3**: 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.  

---

