This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Iterate with getBM(bioMart package) for GO annotation

I am trying to use the getBM function for a list of dataframes(or datasets if you prefer) (genes2peaks) and use only a list of gene_ids from there and get the GO annotations for each dataset separately in a new list, but I get only annotations for the final dataset in my list!

I also retrieve the correct dataset argument for the useMart function from a list I have made (samples.annotationsnew$biomart)!

Can somebody identify any the problem in that iteration?

library(biomaRt)
GOannotations<-list()
for (i in nrow(samples.annotationsnew)){
  mart <- useMart(biomart = "ensembl", dataset = samples.annotationsnew$biomart[i])
  values <- genes2peaks[[i]]$feature
  GOannotations[[i]] <- getBM(attributes = c("ensembl_gene_id", "go_id","name_1006"), filters = "ensembl_gene_id",values = values, mart = mart)
}

Thanks in advance!

getbm gene-ontology iteration

1 answer

You want

for (i in 1:nrow(samples.annotationsnew)){

rather than

for (i in nrow(samples.annotationsnew)){

As an aside, it's generally best to avoid for loops in R for performance reasons (though in cases like this I doubt that will be an issue).

Log in to answer this question.