0
$\begingroup$

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)
$\endgroup$
-1
$\begingroup$

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

$\endgroup$
2
  • $\begingroup$ Sorry, could give me some example codes? $\endgroup$
    – user224050
    Oct 9 '20 at 22:30
  • $\begingroup$ 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. $\endgroup$
    – user438383
    Oct 10 '20 at 13:15

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.