Annotation Dbi Error: unable to find an inherited method for function 'x' for signature "MaskedBSgenome"
1
0
Entering edit mode
Erica • 0
@0be5bf17
Last seen 13 months ago
United States

I am trying to use AnnotationDbi to map Ensembl IDs to GeneIDs for an RNAseq experiment, but I keep coming up with an error.

Starting from a new R session, I install and load the genome package.

>BiocManager::install("BSgenome.Hsapiens.UCSC.hg19")
>library(BSgenome.Hsapiens.UCSC.hg19)
> ls("package:BSgenome.Hsapiens.UCSC.hg19")
[1] "BSgenome.Hsapiens.UCSC.hg19"

However, when I try to see what keytypes or columns are available, I get an error:

> keytypes(BSgenome.Hsapiens.UCSC.hg19)
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function 'keytypes' for signature '"BSgenome"'

> AnnotationDbi::columns(BSgenome.Hsapiens.UCSC.hg19)
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function 'columns' for signature '"BSgenome"'

I cannot proceed with mapping the GeneIDs if the keys and columns functions do not work. Is there something I'm missing? Any advice would be greatly appreciated!

>sessionInfo( )
R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8    LC_MONETARY=English_United States.utf8 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

attached base packages:
[1] stats4    stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] AnnotationDbi_1.60.0                       Biobase_2.58.0                             BSgenome.Hsapiens.UCSC.hg19.masked_1.3.993
 [4] BSgenome.Hsapiens.UCSC.hg19_1.4.3          BSgenome_1.66.3                            rtracklayer_1.58.0                        
 [7] Biostrings_2.66.0                          XVector_0.38.0                             GenomicRanges_1.50.2                      
[10] GenomeInfoDb_1.34.9                        IRanges_2.32.0                             S4Vectors_0.36.1                          
[13] BiocGenerics_0.44.0                       

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.10                 locfit_1.5-9.7              lattice_0.20-45             Rsamtools_2.14.0            png_0.1-8                  
 [6] utf8_1.2.3                  R6_2.5.1                    RSQLite_2.2.20              httr_1.4.7                  ggplot2_3.4.2              
[11] pillar_1.9.0                zlibbioc_1.44.0             rlang_1.1.1                 rstudioapi_0.15.0           annotate_1.76.0            
[16] blob_1.2.4                  Matrix_1.5-3                BiocParallel_1.32.5         geneplotter_1.76.0          RCurl_1.98-1.10            
[21] bit_4.0.5                   munsell_0.5.0               DelayedArray_0.23.2         compiler_4.2.2              pkgconfig_2.0.3            
[26] tidyselect_1.2.0            KEGGREST_1.38.0             SummarizedExperiment_1.28.0 tibble_3.2.1                GenomeInfoDbData_1.2.9     
[31] codetools_0.2-19            matrixStats_0.63.0          XML_3.99-0.13               fansi_1.0.4                 crayon_1.5.2               
[36] dplyr_1.1.2                 GenomicAlignments_1.34.1    bitops_1.0-7                grid_4.2.2                  xtable_1.8-4               
[41] gtable_0.3.4                lifecycle_1.0.3             DBI_1.1.3                   magrittr_2.0.3              scales_1.2.1               
[46] cli_3.6.0                   cachem_1.0.6                vctrs_0.6.3                 generics_0.1.3              rjson_0.2.21               
[51] restfulr_0.0.15             RColorBrewer_1.1-3          tools_4.2.2                 bit64_4.0.5                 glue_1.6.2                 
[56] DESeq2_1.38.3               MatrixGenerics_1.10.0       parallel_4.2.2              fastmap_1.1.0               yaml_2.3.7                 
[61] colorspace_2.1-0            BiocManager_1.30.21         memoise_2.0.1               BiocIO_1.8.0
BSgenome.Hsapiens.UCSC.hg19 AnnotationDbi • 1.5k views
ADD COMMENT
2
Entering edit mode
@james-w-macdonald-5106
Last seen 13 hours ago
United States

The BSgenome packages provide information about the genome itself (e.g., the sequences), which doesn't include annotations for the genes. For mapping between annotations, you want either an OrgDb or an EnsDb object.

These days, a GeneID is colloquially inferred to be an NCBI Gene ID (what used to be called an Entrez Gene ID in the olden days). If that is what you want to do, I would caution against it. But maybe what you really want is the HUGO symbol? In which case you can use an EnsDb. This can be a bit tricky since Ensembl updates things relatively often, so you may have to search a bit to get the right one. I usually do something like this:

> library(AnnotationHub)

> hub <- AnnotationHub()
  |===========================| 100%

snapshotDate(): 2023-04-25
> query(hub, c("homo sapiens","ensdb"))
AnnotationHub with 25 records
# snapshotDate(): 2023-04-25
# $dataprovider: Ensembl
# $species: Homo sapiens
# $rdataclass: EnsDb
# additional mcols():
#   taxonomyid, genome,
#   description,
#   coordinate_1_based,
#   maintainer, rdatadateadded,
#   preparerclass, tags,
#   rdatapath, sourceurl,
#   sourcetype 
# retrieve records with, e.g.,
#   'object[["AH53211"]]' 


  AH53211  |
  AH53715  |
  AH56681  |
  AH57757  |
  AH60773  |
  ...       
  AH100643 |
  AH104864 |
  AH109336 |
  AH109606 |
  AH113665 |
           title                   
  AH53211  Ensembl 87 EnsDb for ...
  AH53715  Ensembl 88 EnsDb for ...
  AH56681  Ensembl 89 EnsDb for ...
  AH57757  Ensembl 90 EnsDb for ...
  AH60773  Ensembl 91 EnsDb for ...
  ...      ...                     
  AH100643 Ensembl 106 EnsDb for...
  AH104864 Ensembl 107 EnsDb for...
  AH109336 Ensembl 108 EnsDb for...
  AH109606 Ensembl 109 EnsDb for...
  AH113665 Ensembl 110 EnsDb for...

## lots of versions here. Let's try 106
## here I am pretending I have a bunch of Ensembl Gene IDs, but in fact I do not
## for sake of argument, let's say you have a vector of all your Ensembl Gene IDs in an object called 'ensgids'
> ens106 <- hub[["AH100643"]]
> all(ensgids %in% keys(ens106))
## if TRUE, then continue. If not, do something like
> setdiff(ensgids, keys(ens106))
## and search for a few of those IDs on ensembl.org to see what version they come from.
## once you have that sorted, it's simple
## here I just fake up some IDs for an example
> ensgids <- head(keys(ens106))
> select(ens106, ensgids, "GENENAME","GENEID")
           GENEID GENENAME
1 ENSG00000000003   TSPAN6
2 ENSG00000000005     TNMD
3 ENSG00000000419     DPM1
4 ENSG00000000457    SCYL3
5 ENSG00000000460 C1orf112
6 ENSG00000000938      FGR
ADD COMMENT
0
Entering edit mode

Yes, I meant I wanted to generate the HUGO symbols for each gene, so I'll go ahead and use EnsDb. I am getting the same error when I use this database though. It installs fine, but I cannot use arguments such as 'select' or 'keys' etc.

> library(AnnotationHub)

> hub <- AnnotationHub()
snapshotDate(): 2022-10-31

> query(hub, c("homo sapiens", "ensdb"))
AnnotationHub with 24 records
# snapshotDate(): 2023-04-25
# $dataprovider: Ensembl
# $species: Homo sapiens
# $rdataclass: EnsDb
# additional mcols(): taxonomyid, genome, description, coordinate_1_based, maintainer, rdatadateadded, preparerclass, tags,
#   rdatapath, sourceurl, sourcetype 
# retrieve records with, e.g., 'object[["AH53211"]]' 

  AH53211  | Ensembl 87 EnsDb for Homo Sapiens 
  AH53715  | Ensembl 88 EnsDb for Homo Sapiens 
  AH56681  | Ensembl 89 EnsDb for Homo Sapiens 
  AH57757  | Ensembl 90 EnsDb for Homo Sapiens 
  AH60773  | Ensembl 91 EnsDb for Homo Sapiens 

  AH98047  | Ensembl 105 EnsDb for Homo sapiens
  AH100643 | Ensembl 106 EnsDb for Homo sapiens
  AH104864 | Ensembl 107 EnsDb for Homo sapiens
  AH109336 | Ensembl 108 EnsDb for Homo sapiens
  AH109606 | Ensembl 109 EnsDb for Homo sapiens

> ens106 <- hub[["AH100643"]]

> ensgids <- head(keys(ens106))

> select(ens106, ensgids, "GENENAME", "GENEID")
Error in UseMethod("select") : 
  no applicable method for 'select' applied to an object of class "EnsDb"
ADD REPLY
0
Entering edit mode

It looks like you loaded some tidyverse package(s) after having loaded AnnotationHub. In which case you will have to use the qualified name of the function.

> hub <- AnnotationHub()
snapshotDate(): 2023-04-25
> ens106 <- hub[["AH100643"]]
loading from cache
require("ensembldb")
Warning messages:
1: package 'IRanges' was built under R version 4.3.1 
2: package 'GenomeInfoDb' was built under R version 4.3.1 
3: package 'GenomicFeatures' was built under R version 4.3.1 
4: package 'AnnotationDbi' was built under R version 4.3.1 
> ensgids <- head(keys(ens106))
> select(ens106, ensgids, "ENTREZID","GENEID")
           GENEID ENTREZID
1 ENSG00000000003     7105
2 ENSG00000000005    64102
3 ENSG00000000419     8813
4 ENSG00000000457    57147
5 ENSG00000000460    55732
6 ENSG00000000938     2268


> library(tidyverse)

## after 
> select(ens106, ensgids, "ENTREZID","GENEID")
Error in UseMethod("select") : 
  no applicable method for 'select' applied to an object of class "EnsDb"

## use qualified name of the function
> ensembldb::select(ens106, ensgids, "ENTREZID","GENEID")
           GENEID ENTREZID
1 ENSG00000000003     7105
2 ENSG00000000005    64102
3 ENSG00000000419     8813
4 ENSG00000000457    57147
5 ENSG00000000460    55732
6 ENSG00000000938     2268
ADD REPLY
0
Entering edit mode

This worked, thank you!

ADD REPLY

Login before adding your answer.

Traffic: 811 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6