CompDb: Simple compound (metabolite) databases

Description Usage Arguments Details Retrieve annotations from the database Filtering the database Author(s) See Also Examples

View source: R/CompDb.R

Description

CompDb objects provide access to general (metabolite) compound annotations along with metadata information such as the annotation's source, date and release version. The data is stored internally in a database (usually an SQLite database).

CompDb constructs a CompDb object by connecting to the provided database file.

hasMsMsSpectra returns TRUE if MS/MS spectrum data is available in the database and FALSE otherwise.

src_compdb provides access to the CompDb's database via the functionality from the dplyr/dbplyr package.

tables returns a named list (names being table names) with the fields/columns from each table in the database.

dbconn returns the connection (DBIConnection) to the database.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
show(object)

CompDb(x, flags = RSQLite::SQLITE_RO)

hasMsMsSpectra(x)

compounds(x, columns, filter, return.type = c("data.frame", "tibble"), ...)

src_compdb(x)

tables(x)

## S4 method for signature 'CompDb'
dbconn(x)

## S4 method for signature 'CompDb'
Spectra(object, columns, filter, ...)

## S4 method for signature 'CompDb'
supportedFilters(object)

Arguments

x

For CompDb: character(1) with the file name of the SQLite compound database. Alternatively it is possible to provide the connection to the database with parameter x.

For all other methods: a `CompDb` object.
flags

flags passed to the SQLite database connection. See SQLite(). Defaults to read-only, i.e. RSQLite::SQLITE_RO.

columns

For compounds, Spectra: character with the names of the database columns that should be retrieved. Use tables() for a list of available column names.

filter

For compounds and Spectra: filter expression or AnnotationFilter() defining a filter to be used to retrieve specific elements from the database.

return.type

For compounds: either "data.frame" or "tibble" to return the result as a data.frame() or tibble(), respectively.

...

additional arguments. Currently not used.

object

For all methods: a CompDb object.

Details

CompDb objects should be created using the constructor function CompDb providing the name of the (SQLite) database file providing the compound annotation data.

Retrieve annotations from the database

Annotations/compound informations can be retrieved from a CompDb database with the compounds and Spectra functions:

Filtering the database

Data access methods such as compounds and Spectra allow to filter the results using specific filter classes and expressions. Filtering uses the concepts from Bioconductor's AnnotationFilter package. All information for a certain compound with the ID "HMDB0000001" can for example be retrieved by passing the filter expression filter = ~ compound_id == "HMDB0000001" to the compounds function.

Use the supportedFilters passing the CompDb object as an argument to get a list of all supported filters.

Author(s)

Johannes Rainer

See Also

createCompDb() for the function to create a SQLite compound database.

CompoundIdFilter() for filters that can be used on the CompDb database.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
## Create a small CompDb from a provided HMDB subset
cmps <- compound_tbl_sdf(system.file("sdf/HMDB_sub.sdf.gz",
    package = "CompoundDb"))
metad <- data.frame(name = c("source", "url", "source_version",
    "source_date", "organism"),
    value = c("sub_HMDB", "http://www.hmdb.ca", "4", "2017", "Hsapiens"),
    stringsAsFactors = FALSE)

## Load also MS/MS spectra from HMDB xml files
xml_path <- system.file("xml", package = "CompoundDb")
spctra <- msms_spectra_hmdb(xml_path)

## Create the SQLite database:
db_file <- createCompDb(cmps, metadata = metad, msms_spectra = spctra,
    path = tempdir())

## Create a CompDb object
cmp_db <- CompDb(db_file)
cmp_db

## List all tables in the database and their columns
tables(cmp_db)

## Extract a data.frame with the id, name and inchi of all compounds
compounds(cmp_db, columns = c("compound_id", "compound_name", "inchi"))

## Add also the synonyms (aliases) for the compounds. This will cause the
## tables compound and synonym to be joined. The elements of the compound_id
## and compound_name are now no longer unique
res <- compounds(cmp_db, columns = c("compound_id", "compound_name", "synonym"))
head(res)

## Extract spectra for a specific HMDB compound.
sps <- Spectra(cmp_db, filter = ~ compound_id == "HMDB0000001")
sps

## Using return.type = "tibble" the result will be returned as a "tibble"
compounds(cmp_db, return.type = "tibble")

## Use the CompDb in a dplyr setup
library(dplyr)
src_cmp <- src_compdb(cmp_db)
src_cmp

## Get a tbl for the compound table
cmp_tbl <- tbl(src_cmp, "compound")

## Extract the id, name and inchi
cmp_tbl %>% select(compound_id, compound_name, inchi) %>% collect()

michaelwitting/CompoundDb documentation built on April 29, 2020, 8:42 p.m.