1 Introduction

biodbChebi is a biodb extension package that implements a connector to the ChEBI database (Degtyarenko et al. 2007; Hastings et al. 2012).

2 Installation

Install using Bioconductor:

if (!requireNamespace("BiocManager", quietly=TRUE))
    install.packages("BiocManager")
BiocManager::install('biodbChebi')

3 Initialization

The first step in using biodbChebi, is to create an instance of the biodb class BiodbMain from the main biodb package. This is done by calling the constructor of the class:

mybiodb <- biodb::newInst()

During this step the configuration is set up, the cache system is initialized and extension packages are loaded.

We will see at the end of this vignette that the biodb instance needs to be terminated with a call to the terminate() method.

4 Creating a connector to ChEBI database

In biodb the connection to a database is handled by a connector instance that you can get from the factory. biodbChebi implements a connector to a local database, thus when creating an instance you must provide a URL that points to your database:

chebi <- mybiodb$getFactory()$createConn('chebi')
## Loading required package: biodbChebi

5 Requesting entries

Using accession numbers, we request entries from ChEBI:

entries <- chebi$getEntry(c('2528', '17053', '15440'))

6 Get entry fields

Getting the values of entry fields are done using getFieldValue() method. Here we retrieve the SMILE field of the first entry from the ChEBI entries obtained previously:

entries[[1]]$getFieldValue('smiles')
## [1] "CC(C)CC[C@@H](O)[C@](C)(O)[C@H]1CC[C@@]2(O)C3=CC(=O)[C@@H]4C[C@@H](O)[C@@H](O)C[C@]4(C)[C@H]3[C@H](O)C[C@]12C"

7 Get data frame

We can convert an entry into a data frame:

entries[[1]]$getFieldsAsDataframe()
##   accession charge  formula
## 1      2528      0 C27H44O7
##                                                                                                                                                                                                                      inchi
## 1 InChI=1S/C27H44O7/c1-14(2)6-7-22(32)26(5,33)21-8-9-27(34)16-11-17(28)15-10-18(29)19(30)12-24(15,3)23(16)20(31)13-25(21,27)4/h11,14-15,18-23,29-34H,6-10,12-13H2,1-5H3/t15-,18+,19-,20+,21-,22+,23+,24-,25+,26+,27+/m0/s1
##                      inchikey kegg.compound.id molecular.mass monoisotopic.mass
## 1 LQGNCUXDDPRDJH-UKTRSHMFSA-N           C08811        480.635          480.3087
##             name n.stars
## 1 Ajugasterone C       2
##                                                                                                          smiles
## 1 CC(C)CC[C@@H](O)[C@](C)(O)[C@H]1CC[C@@]2(O)C3=CC(=O)[C@@H]4C[C@@H](O)[C@@H](O)C[C@]4(C)[C@H]3[C@H](O)C[C@]12C
##   chebi.id
## 1     2528

Building a data frame for a list of entries is also possible:

mybiodb$entriesToDataframe(entries, fields=c('accession', 'formula',
    'molecular.mass', 'inchikey', 'kegg.compound.id'))
##   accession  formula molecular.mass                    inchikey
## 1      2528 C27H44O7       480.6350 LQGNCUXDDPRDJH-UKTRSHMFSA-N
## 2     17053  C4H7NO4       133.1027 CKLJMWTZIZZHCS-REOHCLBHSA-N
## 3     15440   C30H50       410.7300 YYGNTYWPHWGJRM-AAJYLUCBSA-N
##   kegg.compound.id
## 1           C08811
## 2           C00049
## 3           C00751

8 Search by name and mass

Searching by name and/or mass is done through the searchCompound().

Searching by name:

chebi$searchCompound(name='aspartic', max.results=3)
## Warning: `searchCompound()` was deprecated in biodb 1.0.0.
## ℹ Please use `searchForEntries()` instead.
## [1] "22660"  "74653"  "136722"

Searching by mass:

chebi$searchCompound(mass=133, mass.field='molecular.mass', mass.tol=0.3,
    max.results=3)
## [1] "30514" "37130" "49547"

Searching by name and mass:

ids <- chebi$searchCompound(name='aspartic', mass=133,
    mass.field='molecular.mass', mass.tol=0.3, max.results=3)

Display results in data frame:

mybiodb$entriesToDataframe(chebi$getEntry(ids), fields=c('accession',
    'molecular.mass', 'name'))
##   accession molecular.mass
## 1     22660       133.1027
## 2     17053       133.1027
## 3     17364       133.1027
##                                                                                                                              name
## 1      aspartic acid;(+-)-Aspartic acid;(R,S)-Aspartic acid;2-aminobutanedioic acid;Asp;D;DL-Aminosuccinic acid;DL-Asparagic acid
## 2 L-aspartic acid;(S)-2-aminobutanedioic acid;(S)-2-aminosuccinic acid;2-Aminosuccinic acid;Asp;ASPARTIC ACID;D;L-Asparaginsaeure
## 3                 D-aspartic acid;(R)-2-aminobutanedioic acid;(R)-2-aminosuccinic acid;aspartic acid D-form;D-Asparaginsaeure;DAS

9 Convert CAS IDs

Converting CAS IDs to ChEBI IDs:

chebi$convCasToChebi(c('87605-72-9', '51-41-2'))
## [1] "10000" "18357"

If more than one ChEBI ID is found for a CAS ID, then a list of character vectors is returned:

chebi$convCasToChebi('14215-68-0')
## [[1]]
## [1] "40356" "28037"

This behaviour can be made the default one by setting simplify parameter to FALSE.

10 Convert InChI

The method is similar to convCasToChebi().

Converting InChI to ChEBI IDs:

chebi$convInchiToChebi('InChI=1S/C8H11NO3/c9-4-8(12)5-1-2-6(10)7(11)3-5/h1-3,8,10-12H,4,9H2/t8-/m0/s1')
## [1] "18357"

You can also use an InChI key:

chebi$convInchiToChebi('MBDOYVRWFFCFHM-SNAWJCMRSA-N')
## [1] "28913"

11 Closing biodb instance

Do not forget to terminate your biodb instance once you are done with it:

mybiodb$terminate()
## INFO  [16:57:01.440] Closing BiodbMain instance...
## INFO  [16:57:01.442] Connector "chebi" deleted.

12 Session information

sessionInfo()
## R version 4.2.1 (2022-06-23)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.5 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.16-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.16-bioc/R/lib/libRlapack.so
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_GB              LC_COLLATE=C              
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] biodbChebi_1.4.0 BiocStyle_2.26.0
## 
## loaded via a namespace (and not attached):
##  [1] progress_1.2.2      tidyselect_1.2.0    xfun_0.34          
##  [4] bslib_0.4.0         vctrs_0.5.0         generics_0.1.3     
##  [7] htmltools_0.5.3     BiocFileCache_2.6.0 yaml_2.3.6         
## [10] utf8_1.2.2          blob_1.2.3          XML_3.99-0.12      
## [13] rlang_1.0.6         jquerylib_0.1.4     pillar_1.8.1       
## [16] withr_2.5.0         glue_1.6.2          DBI_1.1.3          
## [19] rappdirs_0.3.3      bit64_4.0.5         dbplyr_2.2.1       
## [22] lifecycle_1.0.3     plyr_1.8.7          stringr_1.4.1      
## [25] memoise_2.0.1       evaluate_0.17       knitr_1.40         
## [28] fastmap_1.1.0       curl_4.3.3          fansi_1.0.3        
## [31] biodb_1.6.0         Rcpp_1.0.9          openssl_2.0.4      
## [34] filelock_1.0.2      BiocManager_1.30.19 cachem_1.0.6       
## [37] jsonlite_1.8.3      bit_4.0.4           chk_0.8.1          
## [40] askpass_1.1         hms_1.1.2           digest_0.6.30      
## [43] stringi_1.7.8       bookdown_0.29       dplyr_1.0.10       
## [46] cli_3.4.1           tools_4.2.1         magrittr_2.0.3     
## [49] sass_0.4.2          RSQLite_2.2.18      tibble_3.1.8       
## [52] crayon_1.5.2        pkgconfig_2.0.3     ellipsis_0.3.2     
## [55] prettyunits_1.1.1   assertthat_0.2.1    rmarkdown_2.17     
## [58] httr_1.4.4          lgr_0.4.4           R6_2.5.1           
## [61] compiler_4.2.1

References

Degtyarenko, Kirill, Paula de Matos, Marcus Ennis, Janna Hastings, Martin Zbinden, Alan McNaught, Rafael Alcántara, Michael Darsow, Mickaël Guedj, and Michael Ashburner. 2007. “ChEBI: A Database and Ontology for Chemical Entities of Biological Interest.” Nucleic Acids Research 36 (suppl_1): D344–D350. https://doi.org/10.1093/nar/gkm791.

Hastings, Janna, Paula de Matos, Adriano Dekker, Marcus Ennis, Bhavana Harsha, Namrata Kale, Venkatesh Muthukrishnan, et al. 2012. “The ChEBI reference database and ontology for biologically relevant chemistry: enhancements for 2013.” Nucleic Acids Research 41 (D1): D456–D463. https://doi.org/10.1093/nar/gks1146.