0
$\begingroup$

Code:

coords=read.csv("coord.txt", stringsAsFactors = F, strip.white = T, header = F, sep="\t")

library(biomaRt)

mart=useMart(biomart="ENSEMBL_MART_SNP", host="grch37.ensembl.org", path="/biomart/martservice", dataset="hsapiens_snp")

coords$V1=gsub("chr","",coords$V1)

results=data.frame(matrix(ncol=5,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)}

Error:

Error in names(values) <- filters : 'names' attribute [3] must be the same length as the vector [1]

Input file:

chr1  207679307 207679307
chr1  207684192 207684192   
chr1  207685786 207685786
chr1  207685965 207685965
chr1  207692049 207692049
$\endgroup$
1
  • 1
    $\begingroup$ You're not accounting for the fact that ens might be empty for some co-ordinates. Add a check before the rbind call. Also, you may want to consider a vectorized approach instead of the loop. getBM should be able to accept a list of co-ordinates and return results that you either won't need to rbind or will need to do.call(rbind). $\endgroup$
    – Ram RS
    Aug 30 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.