diff --git a/DESCRIPTION b/DESCRIPTION index 226f6c5..76da68f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: MsBackendSql Title: SQL-based Mass Spectrometry Data Backend -Version: 1.7.1 +Version: 1.7.2 Authors@R: c(person(given = "Johannes", family = "Rainer", email = "Johannes.Rainer@eurac.edu", diff --git a/NAMESPACE b/NAMESPACE index 6c563d7..2f7e6e5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -81,6 +81,7 @@ importMethodsFrom(ProtGenerics,backendMerge) importMethodsFrom(ProtGenerics,centroided) importMethodsFrom(ProtGenerics,dataOrigin) importMethodsFrom(ProtGenerics,dataStorage) +importMethodsFrom(ProtGenerics,extractByIndex) importMethodsFrom(ProtGenerics,filterDataOrigin) importMethodsFrom(ProtGenerics,filterMsLevel) importMethodsFrom(ProtGenerics,filterPrecursorMzRange) @@ -95,7 +96,6 @@ importMethodsFrom(ProtGenerics,spectraNames) importMethodsFrom(ProtGenerics,tic) importMethodsFrom(ProtGenerics,uniqueMsLevels) importMethodsFrom(Spectra,backendBpparam) -importMethodsFrom(Spectra,extractByIndex) importMethodsFrom(Spectra,reset) importMethodsFrom(Spectra,show) importMethodsFrom(Spectra,spectraData) diff --git a/NEWS.md b/NEWS.md index 53e5cc1..2d1ff5c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,10 @@ # MsBackendSql 1.7 +## Changes in 1.7.2 + +- Import `extractByIndex` from *ProtGenerics*. +- Add missing links in documentation. + ## Changes in 1.7.1 - Complete unit tests to cover all code lines. @@ -146,4 +151,4 @@ ## Changes in 0.0.2 -- First full implementation of `MsBackendSql`. \ No newline at end of file +- First full implementation of `MsBackendSql`. diff --git a/R/MsBackendOfflineSql.R b/R/MsBackendOfflineSql.R index d899d65..4f1a198 100644 --- a/R/MsBackendOfflineSql.R +++ b/R/MsBackendOfflineSql.R @@ -36,23 +36,23 @@ #' #' @param drv A *DBI* database driver object (such as `SQLite()` from the #' `RSQLite` package or `MariaDB()` from the `RMariaDB` package). See -#' [dbConnect()] for more information. +#' [DBI::dbConnect()] for more information. #' #' @param dbname `character(1)` with the name of the database. Passed directly -#' to [dbConnect()]. +#' to [DBI::dbConnect()]. #' #' @param user `character(1)` with the user name for the database. Passed -#' directly to [dbConnect()]. +#' directly to [DBI::dbConnect()]. #' #' @param password `character(1)` with the password for the database. Note #' that this password is stored (unencrypted) within the object. Passed -#' directly to [dbConnect()]. +#' directly to [DBI::dbConnect()]. #' #' @param host `character(1)` with the host running the database. Passed -#' directly to [dbConnect()]. +#' directly to [DBI::dbConnect()]. #' #' @param port `integer(1)` with the port number (optional). Passed directly to -#' [dbConnect()]. +#' [DBI::dbConnect()]. #' #' @param ... ignored. #' diff --git a/R/MsBackendSql.R b/R/MsBackendSql.R index 0742b82..4eac9ba 100644 --- a/R/MsBackendSql.R +++ b/R/MsBackendSql.R @@ -22,17 +22,17 @@ #' #' @description #' -#' The `MsBackendSql` is an implementation for the [MsBackend()] class for -#' [Spectra()] objects which stores and retrieves MS data from a SQL database. -#' New databases can be created from raw MS data files using +#' The `MsBackendSql` is an implementation for the [Spectra::MsBackend()] class +#' for [Spectra::Spectra()] objects which stores and retrieves MS data from a +#' SQL database. New databases can be created from raw MS data files using #' `createMsBackendSqlDatabase()`. #' #' @details #' #' The `MsBackendSql` class is principally a *read-only* backend but by -#' extending the [MsBackendCached()] backend from the `Spectra` package it -#' allows changing and adding (**temporarily**) spectra variables **without** -#' changing the original data in the SQL database. +#' extending the [Spectra::MsBackendCached()] backend from the `Spectra` +#' package it allows changing and adding (**temporarily**) spectra variables +#' **without** changing the original data in the SQL database. #' #' @note #' @@ -40,7 +40,8 @@ #' with the data and hence does not support saving/loading of a backend to #' disk (e.g. using `save` or `saveRDS`). Also, for the same reason, the #' `MsBackendSql` does not support parallel processing. The `backendBpparam()` -#' method for `MsBackendSql` will thus always return a [SerialParam()] object. +#' method for `MsBackendSql` will thus always return a +#' [BiocParallel::SerialParam()] object. #' #' The [MsBackendOfflineSql()] could be used as an alternative as it supports #' saving/loading the data to/from disk and supports also parallel processing. @@ -53,7 +54,7 @@ #' `backendInitialize()` and providing all data with parameter `data`. In #' addition it is possible to create a database from a `Spectra` object #' changing its backend to a `MsBackendSql` or `MsBackendOfflineSql` using -#' the [setBackend()] function. +#' the [Spectra::setBackend()] function. #' Existing SQL databases (created previously with #' `createMsBackendSqlDatabase()` or `backendInitialize()` with the `data` #' parameter) can be loaded using the *conventional* way to create/initialize @@ -128,8 +129,9 @@ #' would return a `Spectra` object that uses a `MsBackendSql`). #' #' - `backendBpparam()`: whether a `MsBackendSql` supports parallel processing. -#' Takes a `MsBackendSql` and a parallel processing setup (see [bpparam()] -#' for details) as input and always returns a [SerialParam()] since +#' Takes a `MsBackendSql` and a parallel processing setup (see +#' [BiocParallel::bpparam()] for details) as input and always returns a +#' [BiocParallel::SerialParam()] since #' `MsBackendSql` does **not** support parallel processing. #' #' - `dbconn()`: returns the connection to the database. @@ -150,8 +152,8 @@ #' splitted using e.g. `split()`. #' #' In addition, `MsBackendSql` supports all other filtering methods available -#' through [MsBackendCached()]. Implementation of filter functions optimized -#' for `MsBackendSql` objects are: +#' through [Spectra::MsBackendCached()]. Implementation of filter functions +#' optimized for `MsBackendSql` objects are: #' #' - `filterDataOrigin()`: filter the object retaining spectra with `dataOrigin` #' spectra variable values matching the provided ones with parameter @@ -185,7 +187,7 @@ #' The functions listed here are specifically implemented for `MsBackendSql`. #' In addition, `MsBackendSql` inherits and supports all data accessor, #' filtering functions and data manipulation functions from -#' [MsBackendCached()]. +#' [Spectra::MsBackendCached()]. #' #' - `$`, `$<-`: access or set (add) spectra variables in `object`. Spectra #' variables added or modified using the `$<-` are *cached* locally within @@ -237,11 +239,11 @@ #' guarantees a minimal memory footpring of the object. Still, depending of #' the number of spectra in the database, this `integer` vector might become #' very large. Any data access will involve SQL calls to retrieve the data -#' from the database. By extending the [MsBackendCached()] object from the -#' `Spectra` package, the `MsBackendSql` supports to (temporarily, i.e. for -#' the duration of the R session) add or modify spectra variables. These are -#' however stored in a `data.frame` within the object thus increasing the -#' memory demand of the object. +#' from the database. By extending the [Spectra::MsBackendCached()] object +#' from the `Spectra` package, the `MsBackendSql` supports to (temporarily, +#' i.e. for the duration of the R session) add or modify spectra variables. +#' These are however stored in a `data.frame` within the object thus +#' increasing the memory demand of the object. #' #' @param backend For `createMsBackendSqlDatabase()`: MS backend that can be #' used to import MS data from the raw files specified with @@ -254,7 +256,7 @@ #' the default). #' #' @param BPPARAM for `backendBpparam()`: `BiocParallel` parallel processing -#' setup. See [bpparam()] for more information. +#' setup. See [BiocParallel::bpparam()] for more information. #' #' @param chunksize For `createMsBackendSqlDatabase()`: `integer(1)` defining #' the number of input that should be processed per iteration. With @@ -532,7 +534,7 @@ setMethod("[", "MsBackendSql", function(x, i, j, ..., drop = FALSE) { #' @rdname MsBackendSql #' -#' @importMethodsFrom Spectra extractByIndex +#' @importMethodsFrom ProtGenerics extractByIndex #' #' @export setMethod("extractByIndex", c("MsBackendSql", "ANY"), function(object, i) { diff --git a/man/MsBackendOfflineSql.Rd b/man/MsBackendOfflineSql.Rd index 330cc1e..0d1829f 100644 --- a/man/MsBackendOfflineSql.Rd +++ b/man/MsBackendOfflineSql.Rd @@ -25,23 +25,23 @@ MsBackendOfflineSql() \item{drv}{A \emph{DBI} database driver object (such as \code{SQLite()} from the \code{RSQLite} package or \code{MariaDB()} from the \code{RMariaDB} package). See -\code{\link[=dbConnect]{dbConnect()}} for more information.} +\code{\link[DBI:dbConnect]{DBI::dbConnect()}} for more information.} \item{dbname}{\code{character(1)} with the name of the database. Passed directly -to \code{\link[=dbConnect]{dbConnect()}}.} +to \code{\link[DBI:dbConnect]{DBI::dbConnect()}}.} \item{user}{\code{character(1)} with the user name for the database. Passed -directly to \code{\link[=dbConnect]{dbConnect()}}.} +directly to \code{\link[DBI:dbConnect]{DBI::dbConnect()}}.} \item{password}{\code{character(1)} with the password for the database. Note that this password is stored (unencrypted) within the object. Passed -directly to \code{\link[=dbConnect]{dbConnect()}}.} +directly to \code{\link[DBI:dbConnect]{DBI::dbConnect()}}.} \item{host}{\code{character(1)} with the host running the database. Passed -directly to \code{\link[=dbConnect]{dbConnect()}}.} +directly to \code{\link[DBI:dbConnect]{DBI::dbConnect()}}.} \item{port}{\code{integer(1)} with the port number (optional). Passed directly to -\code{\link[=dbConnect]{dbConnect()}}.} +\code{\link[DBI:dbConnect]{DBI::dbConnect()}}.} \item{data}{For \code{backendInitialize()}: optional \code{DataFrame} with the full spectra data that should be inserted into a (new) \code{MsBackendSql} diff --git a/man/MsBackendSql.Rd b/man/MsBackendSql.Rd index d8a3c53..d25dc7f 100644 --- a/man/MsBackendSql.Rd +++ b/man/MsBackendSql.Rd @@ -222,29 +222,30 @@ should be returned (\code{initial = TRUE}, the default) or whether it should be calculated on the spectras' intensities (\code{initial = FALSE}).} \item{BPPARAM}{for \code{backendBpparam()}: \code{BiocParallel} parallel processing -setup. See \code{\link[=bpparam]{bpparam()}} for more information.} +setup. See \code{\link[BiocParallel:register]{BiocParallel::bpparam()}} for more information.} } \value{ See documentation of respective function. } \description{ -The \code{MsBackendSql} is an implementation for the \code{\link[=MsBackend]{MsBackend()}} class for -\code{\link[=Spectra]{Spectra()}} objects which stores and retrieves MS data from a SQL database. -New databases can be created from raw MS data files using +The \code{MsBackendSql} is an implementation for the \code{\link[Spectra:MsBackend]{Spectra::MsBackend()}} class +for \code{\link[Spectra:Spectra]{Spectra::Spectra()}} objects which stores and retrieves MS data from a +SQL database. New databases can be created from raw MS data files using \code{createMsBackendSqlDatabase()}. } \details{ The \code{MsBackendSql} class is principally a \emph{read-only} backend but by -extending the \code{\link[=MsBackendCached]{MsBackendCached()}} backend from the \code{Spectra} package it -allows changing and adding (\strong{temporarily}) spectra variables \strong{without} -changing the original data in the SQL database. +extending the \code{\link[Spectra:MsBackendCached]{Spectra::MsBackendCached()}} backend from the \code{Spectra} +package it allows changing and adding (\strong{temporarily}) spectra variables +\strong{without} changing the original data in the SQL database. } \note{ The \code{MsBackendSql} backend keeps an (open) connection to the SQL database with the data and hence does not support saving/loading of a backend to disk (e.g. using \code{save} or \code{saveRDS}). Also, for the same reason, the \code{MsBackendSql} does not support parallel processing. The \code{backendBpparam()} -method for \code{MsBackendSql} will thus always return a \code{\link[=SerialParam]{SerialParam()}} object. +method for \code{MsBackendSql} will thus always return a +\code{\link[BiocParallel:SerialParam-class]{BiocParallel::SerialParam()}} object. The \code{\link[=MsBackendOfflineSql]{MsBackendOfflineSql()}} could be used as an alternative as it supports saving/loading the data to/from disk and supports also parallel processing. @@ -258,7 +259,7 @@ using the \code{createMsBackendSqlDatabase()} function or using \code{backendInitialize()} and providing all data with parameter \code{data}. In addition it is possible to create a database from a \code{Spectra} object changing its backend to a \code{MsBackendSql} or \code{MsBackendOfflineSql} using -the \code{\link[=setBackend]{setBackend()}} function. +the \code{\link[Spectra:Spectra]{Spectra::setBackend()}} function. Existing SQL databases (created previously with \code{createMsBackendSqlDatabase()} or \code{backendInitialize()} with the \code{data} parameter) can be loaded using the \emph{conventional} way to create/initialize @@ -330,8 +331,9 @@ connection to an \strong{empty} database would store the full spectra data from the \code{Spectra} object \code{sps} into the specified database and would return a \code{Spectra} object that uses a \code{MsBackendSql}). \item \code{backendBpparam()}: whether a \code{MsBackendSql} supports parallel processing. -Takes a \code{MsBackendSql} and a parallel processing setup (see \code{\link[=bpparam]{bpparam()}} -for details) as input and always returns a \code{\link[=SerialParam]{SerialParam()}} since +Takes a \code{MsBackendSql} and a parallel processing setup (see +\code{\link[BiocParallel:register]{BiocParallel::bpparam()}} for details) as input and always returns a +\code{\link[BiocParallel:SerialParam-class]{BiocParallel::SerialParam()}} since \code{MsBackendSql} does \strong{not} support parallel processing. \item \code{dbconn()}: returns the connection to the database. } @@ -354,8 +356,8 @@ mostly used for combining \code{MsBackendSql} objects that were previously splitted using e.g. \code{split()}. In addition, \code{MsBackendSql} supports all other filtering methods available -through \code{\link[=MsBackendCached]{MsBackendCached()}}. Implementation of filter functions optimized -for \code{MsBackendSql} objects are: +through \code{\link[Spectra:MsBackendCached]{Spectra::MsBackendCached()}}. Implementation of filter functions +optimized for \code{MsBackendSql} objects are: \itemize{ \item \code{filterDataOrigin()}: filter the object retaining spectra with \code{dataOrigin} spectra variable values matching the provided ones with parameter @@ -384,7 +386,7 @@ on the provided MS level(s) returning all spectra from other MS levels. The functions listed here are specifically implemented for \code{MsBackendSql}. In addition, \code{MsBackendSql} inherits and supports all data accessor, filtering functions and data manipulation functions from -\code{\link[=MsBackendCached]{MsBackendCached()}}. +\code{\link[Spectra:MsBackendCached]{Spectra::MsBackendCached()}}. \itemize{ \item \code{$}, \verb{$<-}: access or set (add) spectra variables in \code{object}. Spectra variables added or modified using the \verb{$<-} are \emph{cached} locally within @@ -429,11 +431,11 @@ spectra stored in the SQL database. Keeping only these \code{integer} in memory guarantees a minimal memory footpring of the object. Still, depending of the number of spectra in the database, this \code{integer} vector might become very large. Any data access will involve SQL calls to retrieve the data -from the database. By extending the \code{\link[=MsBackendCached]{MsBackendCached()}} object from the -\code{Spectra} package, the \code{MsBackendSql} supports to (temporarily, i.e. for -the duration of the R session) add or modify spectra variables. These are -however stored in a \code{data.frame} within the object thus increasing the -memory demand of the object. +from the database. By extending the \code{\link[Spectra:MsBackendCached]{Spectra::MsBackendCached()}} object +from the \code{Spectra} package, the \code{MsBackendSql} supports to (temporarily, +i.e. for the duration of the R session) add or modify spectra variables. +These are however stored in a \code{data.frame} within the object thus +increasing the memory demand of the object. } \examples{ diff --git a/tests/testthat/test_MsBackendOfflineSql.R b/tests/testthat/test_MsBackendOfflineSql.R index 1ce6cb4..76178ea 100644 --- a/tests/testthat/test_MsBackendOfflineSql.R +++ b/tests/testthat/test_MsBackendOfflineSql.R @@ -331,3 +331,12 @@ test_that("setBackend,Spectra,MsBackendOfflineSql works", { expect_equal(msLevel(ref), msLevel(res)) unlink(dbf) }) + +test_that("filterRt,MsBackendOfflineSql works properly", { + ref <- Spectra(c(mm14_file, mm8_file)) + dbname_test <- tempfile() + res <- setBackend(ref, MsBackendOfflineSql(), drv = SQLite(), + dbname = dbname_test) + expect_output(show(ref), "MsBackendMzR") + expect_output(show(res), "MsBackendOfflineSql") +})