# An introduction to biodbHmdb

Pierrick Roger

#### 25 November 2021

#### Package

biodbHmdb 1.0.3

# 1 Introduction

biodbHmdb is a biodb extension package that implements a connector to HMDB Metabolites.

We present here the different ways to search for HMDB (Wishart et al. 2012) entries with this package.

Note that the whole HMDB is downloaded locally by biodb and stored on disk, since this is the only way to access HMDB programmatically. Any search on HMDB is hence currently run on the local machine.

# 2 Installation

Install using Bioconductor:

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

# 3 Initialization

The first step in using biodbHmdb, 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 HMDB Metabolites

In biodb the connection to a database is handled by a connector instance that you can get from the factory. biodbHmdb implements a connector to a remote database. Here is the code to instantiate a connector:

    conn <- mybiodb$getFactory()$createConn('hmdb.metabolites')

    ## Loading required package: biodbHmdb

For this vignette, we will avoid the downloading of the full HMDB Metabolites database, and use instead an extract containing a few entries:

    dbExtract <- system.file("extdata", 'generated', "hmdb_extract.zip",
        package="biodbHmdb")
    conn$setPropValSlot('urls', 'db.zip.url', dbExtract)

# 5 Accessing entries

To get the number of entries stored inside the database, run:

    conn$getNbEntries()

    ## INFO  [10:59:08.347] Create cache folder "C:\Users\biocbuild\AppData\Local/R/cache/R/biodb/hmdb.metabolites-9e094cf1e5980f9ac69d952373fb6d34" for "hmdb.metabolites-9e094cf1e5980f9ac69d952373fb6d34".
    ## INFO  [10:59:08.425] Downloading whole database of hmdb.metabolites.
    ## INFO  [10:59:08.440] Downloading HMDB metabolite database at "C:/Users/biocbuild/bbs-3.14-bioc/tmpdir/Rtmpaqfawv/Rinst29742ab929de/biodbHmdb/extdata/generated/hmdb_extract.zip" ...
    ## INFO  [10:59:08.643] Extract whole database of hmdb.metabolites.
    ## INFO  [10:59:08.643] Extracting content of downloaded',
    ##                     ' HMDB metabolite database...

    ## [1] 2

To get some of the first entry IDs (accession numbers) from the database, run:

    ids <- conn$getEntryIds(2)
    ids

    ## [1] "HMDB0000001" "HMDB0000002"

To retrieve entries, use:

    entries <- conn$getEntry(ids)
    entries

    ## [[1]]
    ## Biodb HMDB Metabolites entry instance HMDB0000001.
    ##
    ## [[2]]
    ## Biodb HMDB Metabolites entry instance HMDB0000002.

To convert a list of entries into a dataframe, run:

    x <- mybiodb$entriesToDataframe(entries, compute=FALSE)
    x

    ##     accession average.mass   cas.id chebi.id chemspider.id kegg.compound.id
    ## 1 HMDB0000001     169.1811 332-80-9    50599         83153           C01152
    ## 2 HMDB0000002      74.1249 109-76-2    15725           415           C00986
    ##   ncbi.pubchem.comp.id                                     comp.iupac.name.syst
    ## 1                92105 (2S)-2-amino-3-(1-methyl-1H-imidazol-4-yl)propanoic acid
    ## 2                  428                                      propane-1,3-diamine
    ##   comp.iupac.name.trad   formula
    ## 1    1 methylhistidine C7H11N3O2
    ## 2 Î±,Ï‰-propanediamine   C3H10N2
    ##                                                                                     inchi
    ## 1 InChI=1S/C7H11N3O2/c1-10-3-5(9-4-10)2-6(8)7(11)12/h3-4,6H,2,8H2,1H3,(H,11,12)/t6-/m0/s1
    ## 2                                                      InChI=1S/C3H10N2/c4-2-1-3-5/h1-5H2
    ##                      inchikey monoisotopic.mass
    ## 1 BRMWTNUJHUMWMS-LURJTMIESA-N          169.0851
    ## 2 XFNJVJPLKCPIBV-UHFFFAOYSA-N           74.0844
    ##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              name
    ## 1 1-Methylhistidine;(2S)-2-Amino-3-(1-methyl-1H-imidazol-4-yl)propanoic acid;Pi-methylhistidine;(2S)-2-Amino-3-(1-methyl-1H-imidazol-4-yl)propanoate;1 Methylhistidine;1-Methyl histidine;1-Methyl-histidine;1-Methyl-L-histidine;1-MHis;1-N-Methyl-L-histidine;L-1-Methylhistidine;N1-Methyl-L-histidine;1-Methylhistidine dihydrochloride;Renal disease;Nephropathy;Non-insulin-dependent diabetes mellitus;Niddm;Adult-onset diabetes;Striated muscle;Fecal;Stool;Faecal;Faeces;Csf;Cytoplasma
    ## 2                                                             1,3-Diaminopropane;1,3-Propanediamine;1,3-Propylenediamine;Propane-1,3-diamine;tn;Trimethylenediamine;1,3-diamino-N-Propane;1,3-Trimethylenediamine;3-Aminopropylamine;a,W-Propanediamine;Trimethylenediamine hydrochloride;Trimethylenediamine dihydrochloride;1,3-Diaminepropane;Leukaemia;Digestion;Flora;Gramineae;Papilionoideae;Legume;Soy;Soya;Soybean;Soya bean;Cucurbits;Gourds;Fauna;Fecal;Stool;Faecal;Faeces;Cytoplasma
    ##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         description
    ## 1 1-Methylhistidine, also known as 1-MHis, belongs to the class of organic compounds known as histidine and derivatives. Histidine and derivatives are compounds containing cysteine or a derivative thereof resulting from a reaction of cysteine at the amino group or the carboxy group, or from the replacement of any hydrogen of glycine by a heteroatom. 1-Methylhistidine is derived mainly from the anserine of dietary flesh sources, especially poultry. The enzyme, carnosinase, splits anserine into beta-alanine and 1-MHis. High levels of 1-MHis tend to inhibit the enzyme carnosinase and increase anserine levels. Conversely, genetic variants with deficient carnosinase activity in plasma show increased 1-MHis excretions when they consume a high meat diet. Reduced serum carnosinase activity is also found in patients with Parkinson's disease and multiple sclerosis and patients following a cerebrovascular accident. Vitamin E deficiency can lead to 1-methylhistidinuria from increased oxidative effects in skeletal muscle. 1-Methylhistidine is a biomarker for the consumption of meat, especially red meat.
    ## 2                                                                                                                                                                                                                                                          1,3-Diaminopropane, also known as DAP or trimethylenediamine, belongs to the class of organic compounds known as monoalkylamines. These are organic compounds containing a primary aliphatic amine group. 1,3-Diaminopropane is a stable, flammable, and highly hygroscopic fluid. It is a polyamine that is normally quite toxic if swallowed, inhaled, or absorbed through the skin. It is a catabolic byproduct of spermidine. It is also a precursor in the enzymatic synthesis of beta-alanine. 1,3-Diaminopropane is involved in the arginine/proline metabolic pathways and the beta-alanine metabolic pathway. 1,3-Diaminopropane has been detected, but not quantified in, several different foods, such as cassava, shiitakes, oyster mushrooms, muscadine grapes, and cinnamons. This could make 1,3-diaminopropane a potential biomarker for the consumption of these foods.
    ##                        smiles              comp.super.class hmdb.metabolites.id
    ## 1 CN1C=NC(C[C@H](N)C(O)=O)=C1 Organic acids and derivatives         HMDB0000001
    ## 2                       NCCCN    Organic nitrogen compounds         HMDB0000002

# 6 Searching by name

We use here the generic biodb method `searchForEntries()` to search for entries by name:

    id <- conn$searchForEntries(list(name='1-Methylhistidine'), max.results=1)
    id

    ## [1] "HMDB0000001"

We limit the search result to one entry with the `max.results` field.

The first parameter is the filtering criterion, expressed as a list whose single key (in our case) is the biodb field on which we want to filter. The value is the text we want to search for. See the documentation of `searchForEntries()` inside `?biodb::BiodbConn`.

We could also use several strings to search for, in which case an entry will be matched if its field value contains all the specified strings:

    conn$searchForEntries(list(name=c('propanoic', 'acid')), max.results=1)

    ## [1] "HMDB0000001"

To look at the values of the entry, you may convert it to a data frame:

    entryDf <- conn$getEntry(id)$getFieldsAsDataframe(fields=c('accession', 'name'))

See table 1 for the content of this data frame.

Table 1: The entry returned when searching by name.
accession | name
--- | ---
HMDB0000001 | 1-Methylhistidine;(2S)-2-Amino-3-(1-methyl-1H-imidazol-4-yl)propanoic acid;Pi-methylhistidine;(2S)-2-Amino-3-(1-methyl-1H-imidazol-4-yl)propanoate;1 Methylhistidine;1-Methyl histidine;1-Methyl-histidine;1-Methyl-L-histidine;1-MHis;1-N-Methyl-L-histidine;L-1-Methylhistidine;N1-Methyl-L-histidine;1-Methylhistidine dihydrochloride;Renal disease;Nephropathy;Non-insulin-dependent diabetes mellitus;Niddm;Adult-onset diabetes;Striated muscle;Fecal;Stool;Faecal;Faeces;Csf;Cytoplasma

# 7 Searching inside the “description” field

Searching inside the `description` field can be done in the same way as for the `name` field. Here is a search with multiple strings to match:

    id <- conn$searchForEntries(list(description=c('Parkinson', 'sclerosis')), max.results=1)
    id

    ## [1] "HMDB0000001"

Again, you can look at the values of the entry through a data frame:

    entryDf <- conn$getEntry(id)$getFieldsAsDataframe(fields=c('accession', 'name', 'description'))

See table 2 for the content of this data frame.

Table 2: The entry returned when searching by description.
accession | name | description
--- | --- | ---
HMDB0000001 | 1-Methylhistidine;(2S)-2-Amino-3-(1-methyl-1H-imidazol-4-yl)propanoic acid;Pi-methylhistidine;(2S)-2-Amino-3-(1-methyl-1H-imidazol-4-yl)propanoate;1 Methylhistidine;1-Methyl histidine;1-Methyl-histidine;1-Methyl-L-histidine;1-MHis;1-N-Methyl-L-histidine;L-1-Methylhistidine;N1-Methyl-L-histidine;1-Methylhistidine dihydrochloride;Renal disease;Nephropathy;Non-insulin-dependent diabetes mellitus;Niddm;Adult-onset diabetes;Striated muscle;Fecal;Stool;Faecal;Faeces;Csf;Cytoplasma | 1-Methylhistidine, also known as 1-MHis, belongs to the class of organic compounds known as histidine and derivatives. Histidine and derivatives are compounds containing cysteine or a derivative thereof resulting from a reaction of cysteine at the amino group or the carboxy group, or from the replacement of any hydrogen of glycine by a heteroatom. 1-Methylhistidine is derived mainly from the anserine of dietary flesh sources, especially poultry. The enzyme, carnosinase, splits anserine into beta-alanine and 1-MHis. High levels of 1-MHis tend to inhibit the enzyme carnosinase and increase anserine levels. Conversely, genetic variants with deficient carnosinase activity in plasma show increased 1-MHis excretions when they consume a high meat diet. Reduced serum carnosinase activity is also found in patients with Parkinson’s disease and multiple sclerosis and patients following a cerebrovascular accident. Vitamin E deficiency can lead to 1-methylhistidinuria from increased oxidative effects in skeletal muscle. 1-Methylhistidine is a biomarker for the consumption of meat, especially red meat.

# 8 Closing biodb instance

When done with your biodb instance you have to terminate it, in order to ensure release of resources (file handles, database connection, etc):

    mybiodb$terminate()

    ## INFO  [10:59:13.284] Closing BiodbMain instance...
    ## INFO  [10:59:13.315] Connector "hmdb.metabolites" deleted.

# 9 Session information

    sessionInfo()

    ## R version 4.1.2 (2021-11-01)
    ## Platform: x86_64-w64-mingw32/x64 (64-bit)
    ## Running under: Windows Server 2012 R2 x64 (build 9600)
    ##
    ## Matrix products: default
    ##
    ## locale:
    ## [1] LC_COLLATE=C
    ## [2] LC_CTYPE=English_United States.1252
    ## [3] LC_MONETARY=English_United States.1252
    ## [4] LC_NUMERIC=C
    ## [5] LC_TIME=English_United States.1252
    ##
    ## attached base packages:
    ## [1] stats     graphics  grDevices utils     datasets  methods   base
    ##
    ## other attached packages:
    ## [1] biodbHmdb_1.0.3  BiocStyle_2.22.0
    ##
    ## loaded via a namespace (and not attached):
    ##  [1] progress_1.2.2      tidyselect_1.1.1    xfun_0.28
    ##  [4] bslib_0.3.1         purrr_0.3.4         vctrs_0.3.8
    ##  [7] generics_0.1.1      htmltools_0.5.2     BiocFileCache_2.2.0
    ## [10] yaml_2.2.1          utf8_1.2.2          blob_1.2.2
    ## [13] XML_3.99-0.8        rlang_0.4.12        jquerylib_0.1.4
    ## [16] pillar_1.6.4        withr_2.4.2         glue_1.5.0
    ## [19] DBI_1.1.1           rappdirs_0.3.3      bit64_4.0.5
    ## [22] dbplyr_2.1.1        lifecycle_1.0.1     plyr_1.8.6
    ## [25] stringr_1.4.0       memoise_2.0.0       evaluate_0.14
    ## [28] knitr_1.36          fastmap_1.1.0       curl_4.3.2
    ## [31] fansi_0.5.0         highr_0.9           biodb_1.2.1
    ## [34] Rcpp_1.0.7          openssl_1.4.5       filelock_1.0.2
    ## [37] BiocManager_1.30.16 cachem_1.0.6        jsonlite_1.7.2
    ## [40] bit_4.0.4           hms_1.1.1           chk_0.7.0
    ## [43] askpass_1.1         digest_0.6.28       stringi_1.7.5
    ## [46] bookdown_0.24       dplyr_1.0.7         tools_4.1.2
    ## [49] magrittr_2.0.1      sass_0.4.0          RSQLite_2.2.8
    ## [52] tibble_3.1.6        crayon_1.4.2        pkgconfig_2.0.3
    ## [55] ellipsis_0.3.2      prettyunits_1.1.1   assertthat_0.2.1
    ## [58] rmarkdown_2.11      httr_1.4.2          lgr_0.4.3
    ## [61] R6_2.5.1            compiler_4.1.2

# References

Wishart, David S., Timothy Jewison, An Chi Guo, Michael Wilson, Craig Knox, Yifeng Liu, Yannick Djoumbou, et al. 2012. “HMDB 3.0—The Human Metabolome Database in 2013.” Nucleic Acids Research 41 (D1): D801–D807. https://doi.org/10.1093/nar/gks1065.