Description Usage Arguments Details Retrieve annotations from the database Filtering the database Author(s) See Also Examples
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.
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)
|
x |
For For all other methods: a `CompDb` object. |
flags |
flags passed to the SQLite database connection.
See |
columns |
For |
filter |
For |
return.type |
For |
... |
additional arguments. Currently not used. |
object |
For all methods: a |
CompDb objects should be created using the constructor function
CompDb providing the name of the (SQLite) database file providing
the compound annotation data.
Annotations/compound informations can be retrieved from a CompDb database
with the compounds and Spectra functions:
compounds extracts compound data from the CompDb object. In contrast
to src_compdb it returns the actual data as a data.frame (if
return.type = "data.frame") or a tibble::tibble() (if
return.type = "tibble"). A compounds call will always return all
elements from the compound table (unless a filter is used). Also, the
result data.frame will always contain the compound identifier in column
"compound_id".
Spectra extract spectra from the database and returns them as a
Spectra() object from the Spectra package. Additional annotations
requested with the columns parameter are added as additional spectra
variables.
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.
Johannes Rainer
createCompDb() for the function to create a SQLite compound database.
CompoundIdFilter() for filters that can be used on the CompDb database.
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()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.