IonDb | R Documentation |
IonDb
objects extends CompDb
by allowing to store also information about
measured ions to a CompDb()
database. This information includes the type
(adduct) of the ion, it's measured (or expected) retention time for a certain
LC-MS setup and its mass-to-charge ratio.
As suggested use case, users might create (or download) a CompDb
(SQLite)
database e.g. containing compound (and eventually MS/MS spectra) annotations
from public databases such as the Human Metabolome Database (HMDB) or
MassBank. To store now measured ions (e.g. of lab-internal standards) for a
certain LC-MS setup, such a CompDb
can then be converted to an IonDb
using the IonDb()
constructor function. Ions can be subsequently added
using the insertIon()
function. In general, it is suggested to create
one IonDb
database for one specific LC-MS setup. Such an IonDb
database can then be used to match experimental m/z and retention times
against ions defined in the database (using the functionality of the
MetaboAnnotation
package).
## S4 method for signature 'IonDb'
ionVariables(object, includeId = FALSE, ...)
## S4 method for signature 'IonDb'
ions(
object,
columns = ionVariables(object),
filter,
return.type = c("data.frame", "tibble"),
...
)
## S4 method for signature 'IonDb'
insertIon(object, ions, addColumns = FALSE)
## S4 method for signature 'IonDb'
deleteIon(object, ids = integer(0), ...)
## S4 method for signature 'missing,missing'
IonDb(x, cdb, flags = SQLITE_RWC, ...)
## S4 method for signature 'CompDb,missing'
IonDb(x, cdb, ions = data.frame(), ...)
## S4 method for signature 'character,missing'
IonDb(x, cdb, flags = SQLITE_RW, ...)
## S4 method for signature 'DBIConnection,missing'
IonDb(
x,
cdb,
ions = data.frame(),
flags = SQLITE_RW,
...,
.DBNAME = character()
)
## S4 method for signature 'character,CompDb'
IonDb(x, cdb, ions = data.frame(), flags = SQLITE_RW, ...)
## S4 method for signature 'DBIConnection,CompDb'
IonDb(
x,
cdb,
ions = data.frame(),
flags = SQLITE_RW,
...,
.DBNAME = character()
)
object |
For all methods: a |
includeId |
For |
... |
additional arguments. Currently not used. |
columns |
For |
filter |
For |
return.type |
For |
ions |
for |
addColumns |
For |
ids |
For |
x |
For For all other methods: an `IonDb` object. |
cdb |
For |
flags |
For |
.DBNAME |
|
See description of the respective function.
IonDb
objects/databases A new IonDb
database can be created and initialized with data from an
existing CompDb
database by passing either the database connection
(e.g. an SQLiteConnection
) or the file path of a (to be created) SQLite
database with parameter x
to the IonDb()
function and the CompDb
object with parameter cdb
. Optional parameter ions
allows insert in
addition ion definitions (which can also be added later using
insertIon()
function calls).
An existing CompDb
can be converted to an IonDb
by passing the
CompDb()
object with parameter x
to the IonDb
function. Optional
parameter ions
allows to provide a data.frame
with ion definitions to
be inserted in to the database (which can also be added later using
insertIon()
function calls). Note that this fails if the database
connection for the CompDb
is read-only.
Previously created IonDb
databases can be loaded by passing either the
database connection (e.g. an SQLiteConnection
) or the file path of the
(SQLite) database with parameter x
to the IonDb()
function.
Annotations/compound informations can be retrieved from a IonDb
in the
same way as thay are extracted from a CompDb
. In addition, the function
ions()
allows to retrieve the specific ion information from the database.
It returns the actual data as a data.frame
(if
return.type = "data.frame"
) or a tibble::tibble()
(if return.type = "tibble"
). An ions()
call will always
return all elements from the ms_ion table (unless a filter
is used).
CompDb
)IonDb()
: connect to or create a compound/ion database.
ionVariables()
: returns all available columns/database fields for ions.
IonDb
inherits the insertCompound()
, insertSpectra()
,
deleteCompound()
and deleteSpectra()
functions from CompDb()
.
In addition, IonDb
defines the functions:
insertIon()
: adds ions to the IonDb
object. Note that insertIon()
always adds all the ions specified through the ions
parameter
and does not check if they are already in the database. To add columns
present in the submitted data.frame
to the database table set
addColumns = TRUE
(default is addColumns = FALSE
).
deleteIon()
: deletes ions from the IonDb
object by specifying
their IDs.
Like compounds()
and Spectra()
also ions()
allows 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 "1"
can for example be
retrieved by passing the filter expression filter = ~ ion_id == 1
to
the ions()
function.
Use the supportedFilters()
function on the IonDb
object to get a list of
all supported filters. See also examples below or the usage vignette for
details.
Andrea Vicini, Johannes Rainer
# We load a small compound test database based on MassBank which is
# distributed with this package.
cdb <- CompDb(system.file("sql/CompDb.MassBank.sql", package = "CompoundDb"))
cdb
# We next want to convert this CompDb into an IonDb, but the original CompDb
# database is read only, thus we have to provide the name (or connection) of
# an other database to transfer all the data from the CompDb to that.
idb <- IonDb(paste0(tempdir(), "/idb_ex.db"), cdb)
idb
# It is also possible to load a previously created IonDb passing only the
# connection to the database.
idb2 <- IonDb(paste0(tempdir(), "/idb_ex.db"))
# Ion definitions can be added to the database with the `insertIon` function
# providing a `data.frame` with ion definition. This `data.frame` is expected
# to provide the IDs of the compounds, an adduct name/definition and the
# (experimentally determined) m/z and retention time of the ion. To list
# compound IDs from the CompDb database:
head(compounds(cdb, c("compound_id", "name")))
ions = data.frame(compound_id = c("1", "1", "2", "3", "6", "35"),
ion_adduct = c("[M+H]+", "[M+Na]+", "[M+Na]+",
"[M+Na]+", "[M+2H]2+", "[M+H-NH3]+"),
ion_mz = c(179.0703, 201.0522, 201.0522,
201.0522, 253.66982, 312.0390),
ion_rt = 1:6)
# Inserting ion definitions.
idb <- insertIon(idb, ions)
idb
ions(idb, columns = c("name", "formula", "ion_adduct", "ion_mz", "ion_rt"))
## List all available ion variables
ionVariables(idb)
## Extract a data.frame with ion variables for all ions
ions(idb)
## List all database tables and their columns
tables(idb)
## Filtering the database
##
## Get all ions with an m/z between 200 and 300
res <- ions(idb, filter = ~ ion_mz > 200 & ion_mz < 300)
res
## Get all ions that have a H in their adduct definition.
res <- ions(idb, filter = IonAdductFilter("H", "contains"))
res
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.