| Title: | NoSQL-based Mass Spectrometry Data Backend |
|---|---|
| Description: | Mass spectrometry (MS) data backend for data storage in NoSQL MongoDB dagabases. Objects from this package expand the data storage and handling infrastructure of the Spectra Bioconductor package. This package adds support to store and retrieve MS data from MongoDB databases. |
| Authors: | Ahlam Mentag [aut] (ORCID: <https://orcid.org/0009-0008-5438-7067>), Johannes Rainer [aut, cre] (ORCID: <https://orcid.org/0000-0002-6977-7147>) |
| Maintainer: | Johannes Rainer <[email protected]> |
| License: | GPL-3 |
| Version: | 0.97.4 |
| Built: | 2026-07-23 11:08:30 UTC |
| Source: | https://github.com/rformassspectrometry/msbackendmongodb |
Creates connections to required MongoDb collections used by the MsBackendMongoDb.
connectMsBackendMongoDb( db = "spectra_db", url = "mongodb://localhost", clean = FALSE )connectMsBackendMongoDb( db = "spectra_db", url = "mongodb://localhost", clean = FALSE )
db |
|
url |
|
clean |
|
A named list() of mongo connection objects.
Ahlam Mentag
Spectra MS backend storing data in a MongoDb databaseMsBackendMongoDb is an implementation of the Spectra::MsBackend() class
for Spectra::Spectra() objects, storing and retrieving MS data from a
MongoDb database.
This backend allows read-only access to spectra and peaks stored in MongoDb, but supports temporary modifications of spectra variables via caching.
## S4 method for signature 'MsBackendMongoDb' show(object) ## S4 method for signature 'MsBackendMongoDb' backendInitialize(object, dbcon, data, ...) ## S4 method for signature 'MsBackendMongoDb' dataStorage(object) ## S4 method for signature 'MsBackendMongoDb' peaksData(object, columns = c("mz", "intensity")) ## S4 method for signature 'MsBackendMongoDb' peaksVariables(object) ## S4 method for signature 'MsBackendMongoDb' mz(object) ## S4 replacement method for signature 'MsBackendMongoDb' mz(object) <- value ## S4 method for signature 'MsBackendMongoDb' intensity(object) ## S4 replacement method for signature 'MsBackendMongoDb' intensity(object) <- value ## S4 method for signature 'MsBackendMongoDb' spectraNames(object) ## S4 replacement method for signature 'MsBackendMongoDb' spectraNames(object) <- value ## S4 method for signature 'MsBackendMongoDb' spectraData(object, columns = spectraVariables(object)) ## S4 method for signature 'MsBackendMongoDb' x[i, j, ..., drop = FALSE] ## S4 method for signature 'MsBackendMongoDb,ANY' extractByIndex(object, i) ## S4 method for signature 'MsBackendMongoDb' reset(object) ## S4 method for signature 'MsBackendMongoDb' supportsSetBackend(object, ...)## S4 method for signature 'MsBackendMongoDb' show(object) ## S4 method for signature 'MsBackendMongoDb' backendInitialize(object, dbcon, data, ...) ## S4 method for signature 'MsBackendMongoDb' dataStorage(object) ## S4 method for signature 'MsBackendMongoDb' peaksData(object, columns = c("mz", "intensity")) ## S4 method for signature 'MsBackendMongoDb' peaksVariables(object) ## S4 method for signature 'MsBackendMongoDb' mz(object) ## S4 replacement method for signature 'MsBackendMongoDb' mz(object) <- value ## S4 method for signature 'MsBackendMongoDb' intensity(object) ## S4 replacement method for signature 'MsBackendMongoDb' intensity(object) <- value ## S4 method for signature 'MsBackendMongoDb' spectraNames(object) ## S4 replacement method for signature 'MsBackendMongoDb' spectraNames(object) <- value ## S4 method for signature 'MsBackendMongoDb' spectraData(object, columns = spectraVariables(object)) ## S4 method for signature 'MsBackendMongoDb' x[i, j, ..., drop = FALSE] ## S4 method for signature 'MsBackendMongoDb,ANY' extractByIndex(object, i) ## S4 method for signature 'MsBackendMongoDb' reset(object) ## S4 method for signature 'MsBackendMongoDb' supportsSetBackend(object, ...)
object |
A |
dbcon |
|
data |
Optional |
... |
Additional arguments passed internally |
columns |
|
value |
Replacement values for setter functions |
x |
for |
i |
|
j |
|
drop |
|
Depends on the method. See individual function documentation.
New backend objects can be created using:
con <- connectMsBackendMongoDb(db = <database name>, url = <db url>) backend <- backendInitialize(MsBackendMongoDb(), dbcon = con)
dbcon: A list of MongoDb collections (e.g. from mongolite::mongo()) as
created by the connectMsBackendMongoDb().
backendInitialize(): populates the object with spectrum IDs and caches
metadata. If data is provided, it can insert data into the collection.
peaksData(object, columns = c("mz", "intensity")): returns a list of
matrices containing the peak data for each spectrum.
peaksVariables(object): returns available columns for peaksData.
intensity(object), mz(object): return SimpleList objects with numeric
intensity or m/z values for each spectrum.
spectraData(object, columns): returns a DataFrame with requested
spectrum metadata columns.
spectraNames(object): returns spectrum_id values as character.
intensity<- and mz<- are not supported.
spectraNames<- is not supported.
[i] and extractByIndex(object, i) subset the backend by spectrum
indices. Original data in the database is never changed.
reset(object) restores the backend to its original state, removing
subsetting and cached variables.
dataStorage(object) returns a string describing the MongoDb collections
used by the backend.
Internally, the backend stores:
spectraIds: integer vector of spectrum IDs
dbcon: MongoDb connection(s)
.collections: list of collection names
peak_fun: function used to fetch peak data
localData: cached spectrum variables
nspectra: total number of spectra
Data access functions use peak_fun to fetch peaks on demand.
MsBackendMongoDb keeps a connection to a MongoDb collection(s) and fetches
spectra and peaks data on demand. By storing only the primary keys
(spectrum_id) in memory, it ensures minimal memory usage, while peaks and
metadata are fetched dynamically.
The backend inherits from Spectra::MsBackendCached() and supports temporary
modification of spectra variables via the $<- operator. Original data in
the database cannot be changed (intensities and m/z values are read-only).
Ahlam Mentag
## Start a MongoDB for the example; this requires the *mongod* binary of ## a MongoDB server installation to be present in the System's path. ## We use a specific temporary folder for the database that we can remove ## later safely d <- file.path(tempdir(), "test_example") start_mongodb() ## Loading test data files from MsDataHub library(Spectra) library(MsDataHub) fls <- c(X20171016_POOL_POS_1_105.134.mzML(), X20171016_POOL_POS_3_105.134.mzML()) ## Load the data as a `Spectra` object s <- Spectra(fls) ## Connect to the MongoDB database mcon <- connectMsBackendMongoDb( db = "ms_backend_mongodb", url = "mongodb://localhost:27017", clean = TRUE) ## Change the backend of the `Spectra` object to `MsBackendMongoDb`: store ## all MS data into the MongoDB mng <- setBackend(s, backend = MsBackendMongoDb(), dbcon = mcon) mng ## Get the *m/z* values from the data mz(mng) ## Stopping the MongoDB and removing the directory stop_mongodb() unlink(d, recursive = TRUE)## Start a MongoDB for the example; this requires the *mongod* binary of ## a MongoDB server installation to be present in the System's path. ## We use a specific temporary folder for the database that we can remove ## later safely d <- file.path(tempdir(), "test_example") start_mongodb() ## Loading test data files from MsDataHub library(Spectra) library(MsDataHub) fls <- c(X20171016_POOL_POS_1_105.134.mzML(), X20171016_POOL_POS_3_105.134.mzML()) ## Load the data as a `Spectra` object s <- Spectra(fls) ## Connect to the MongoDB database mcon <- connectMsBackendMongoDb( db = "ms_backend_mongodb", url = "mongodb://localhost:27017", clean = TRUE) ## Change the backend of the `Spectra` object to `MsBackendMongoDb`: store ## all MS data into the MongoDB mng <- setBackend(s, backend = MsBackendMongoDb(), dbcon = mcon) mng ## Get the *m/z* values from the data mz(mng) ## Stopping the MongoDB and removing the directory stop_mongodb() unlink(d, recursive = TRUE)
The start_mongodb() and stop_mongodb() functions start and stop a
MongoDB database using the mongod system call. These functions require
an installation of the MongoDB server and the mongod binary to be present
in the System path.
start_mongodb( cmd = "mongod", dbpath = file.path(tempdir(), "mongo"), logpath = file.path(tempdir(), "mongo.log") ) stop_mongodb(cmd = "mongod", dbpath = file.path(tempdir(), "mongo"))start_mongodb( cmd = "mongod", dbpath = file.path(tempdir(), "mongo"), logpath = file.path(tempdir(), "mongo.log") ) stop_mongodb(cmd = "mongod", dbpath = file.path(tempdir(), "mongo"))
cmd |
|
dbpath |
|
logpath |
|
start_mongodb() and stop_mongodb() don't return any value, but
throw an error if the system2 call did not return 0.
## Start a MongoDB service with the database location in *test_mongo* in ## the System's temporary folder. start_mongodb(dbpath = file.path(tempdir(), "test_mongo")) ## Stop the MongoDB stop_mongodb(dbpath = file.path(tempdir(), "test_mongo")) ## Remove the database unlink(file.path(tempdir(), "test_mongo"), recursive = TRUE)## Start a MongoDB service with the database location in *test_mongo* in ## the System's temporary folder. start_mongodb(dbpath = file.path(tempdir(), "test_mongo")) ## Stop the MongoDB stop_mongodb(dbpath = file.path(tempdir(), "test_mongo")) ## Remove the database unlink(file.path(tempdir(), "test_mongo"), recursive = TRUE)