This is a test version of Biostars. For the public version, visit https://www.biostars.org.
problems annotating genes using org.Hs.eg.db

I am trying to use org.Hs.eg.db to annotate gene IDs extracted from calling genes on a TxDB as such

genes <- genes(TxDb.Hsapiens.UCSC.hg38.knownGene)
overlaps <-  join_overlap_left_directedmycoords.gr, genes)
gene_result = as(overlaps, "data.frame")

I used this code taken directly from here https://www.bioconductor.org/packages/release/bioc/vignettes/AnnotationDbi/inst/doc/IntroToAnnotationPackages.pdf

annots <- select(org.Hs.eg.db, keys=gene_result$gene_id,
             columns=c("SYMBOL","GENENAME"), keytype="ENTREZID")

But I get the following error message

Error in UseMethod("select_") : no applicable method for 'select_' applied to an object of class "c('OrgDb', 'AnnotationDb', 'envRefClass', '.environment', 'refClass', 'environment', 'refObject', 'AssayData')"

Any help or an alternate method would be appreciated.

r

What is the output of str(gene_result)?

It's a data frame made from a GRanges object

gene_result = as(overlaps, "data.frame") #convert GRanges object to data frame

problem fixed via other comment, thanks for your help anyway!

1 answer

There are a few common packages with the select function, so try to explicitly state the correct namespace so R knows what library to use.

annots <- AnnotationDbi::select(
  org.Hs.eg.db, keys=gene_result$gene_id,
  columns=c("SYMBOL","GENENAME"), keytype="ENTREZID"
)

This fixed it, thanks! I thought this might be the problem since dplyr uses "select" as well. I did not know how to specify functions to packages, this is good knowledge.

I should probably have included all the packages I was using, but the interface here only allows me to add one line of code at a time (or I don't know how to add multiple lines), so I only included what I thought was essential.

Moved to an answer. Please upvote / Accept.

Log in to answer this question.