diff --git a/NAMESPACE b/NAMESPACE index ceebb66..e3be17a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,6 +9,7 @@ export(mtbls_sync_data_files) exportClasses(MsBackendMetaboLights) exportMethods(backendInitialize) exportMethods(backendMerge) +exportMethods(backendRequiredSpectraVariables) importClassesFrom(Spectra,MsBackendDataFrame) importClassesFrom(Spectra,MsBackendMzR) importFrom(BiocFileCache,BiocFileCache) @@ -31,3 +32,4 @@ importMethodsFrom(ProtGenerics,backendInitialize) importMethodsFrom(ProtGenerics,dataOrigin) importMethodsFrom(Spectra,"[") importMethodsFrom(Spectra,backendInitialize) +importMethodsFrom(Spectra,backendRequiredSpectraVariables) diff --git a/R/MsBackendMetaboLights.R b/R/MsBackendMetaboLights.R index 29acad0..24e1660 100644 --- a/R/MsBackendMetaboLights.R +++ b/R/MsBackendMetaboLights.R @@ -37,6 +37,9 @@ #' and eventually synchronizes changes/updates. This can be skipped with #' `offline = TRUE` in which case only locally cached content is queried. #' +#' The `backendRequiredSpectraVariables()` function returns the names of the +#' spectra variables required for the backend to provide the MS data. +#' #' The `mtbls_sync()` function can be used to *synchronize* the local data #' cache and ensure that all data files are locally available. The function #' will check the local cache and eventually download missing data files from @@ -71,6 +74,8 @@ #' - For `MsBackendMetaboLights()`: an instance of `MsBackendMetaboLights`. #' - For `backendInitialize()`: an instance of `MsBackendMetaboLights` with #' the MS data of the specified MetaboLights data set. +#' - For `backendRequiredSpectraVariables()`: `character` with spectra +#' variables that are needed for the backend to provide the MS data. #' - For `mtbls_sync()`: the input `MsBackendMetaboLights` with the paths to #' the locally cached data files being eventually updated. #' @@ -202,6 +207,18 @@ setMethod( "supports merging, such as the 'MsBackendMemory'.") }) +#' @rdname MsBackendMetaboLights +#' +#' @importMethodsFrom Spectra backendRequiredSpectraVariables +#' +#' @exportMethod backendRequiredSpectraVariables +setMethod( + "backendRequiredSpectraVariables", "MsBackendMetaboLights", + function(object, ...) { + c(callNextMethod(), "mtbls_id", "mtbls_assay_name", + "derived_spectral_data_file") + }) + .valid_mtbls_required_columns <- function(object) { if (nrow(object@spectraData)) { if (!all(c("mtbls_id", "mtbls_assay_name", diff --git a/man/MsBackendMetaboLights.Rd b/man/MsBackendMetaboLights.Rd index b1b6889..4be53e6 100644 --- a/man/MsBackendMetaboLights.Rd +++ b/man/MsBackendMetaboLights.Rd @@ -5,6 +5,7 @@ \alias{MsBackendMetaboLights-class} \alias{backendInitialize,MsBackendMetaboLights-method} \alias{backendMerge,MsBackendMetaboLights-method} +\alias{backendRequiredSpectraVariables,MsBackendMetaboLights-method} \alias{mtbls_sync} \title{MsBackend representing MS data from MetaboLights} \usage{ @@ -21,6 +22,8 @@ MsBackendMetaboLights() \S4method{backendMerge}{MsBackendMetaboLights}(object, ...) +\S4method{backendRequiredSpectraVariables}{MsBackendMetaboLights}(object, ...) + mtbls_sync(x, offline = FALSE) } \arguments{ @@ -53,6 +56,8 @@ evaluated/loaded.} \item For \code{MsBackendMetaboLights()}: an instance of \code{MsBackendMetaboLights}. \item For \code{backendInitialize()}: an instance of \code{MsBackendMetaboLights} with the MS data of the specified MetaboLights data set. +\item For \code{backendRequiredSpectraVariables()}: \code{character} with spectra +variables that are needed for the backend to provide the MS data. \item For \code{mtbls_sync()}: the input \code{MsBackendMetaboLights} with the paths to the locally cached data files being eventually updated. } @@ -120,6 +125,9 @@ function first compares the remote file content to the locally cached files and eventually synchronizes changes/updates. This can be skipped with \code{offline = TRUE} in which case only locally cached content is queried. +The \code{backendRequiredSpectraVariables()} function returns the names of the +spectra variables required for the backend to provide the MS data. + The \code{mtbls_sync()} function can be used to \emph{synchronize} the local data cache and ensure that all data files are locally available. The function will check the local cache and eventually download missing data files from diff --git a/tests/testthat/test_MsBackendMetaboLights.R b/tests/testthat/test_MsBackendMetaboLights.R index cdc1982..c959424 100644 --- a/tests/testthat/test_MsBackendMetaboLights.R +++ b/tests/testthat/test_MsBackendMetaboLights.R @@ -41,6 +41,12 @@ test_that("backendInitialize,MsBackendMetaboLights works", { expect_equal(Spectra::rtime(res), Spectra::rtime(res_o)) }) +test_that("backendRequiredSpectraVariables,MsBackendMetaboLights works", { + expect_equal(backendRequiredSpectraVariables(MsBackendMetaboLights()), + c("dataStorage", "scanIndex", "mtbls_id", "mtbls_assay_name", + "derived_spectral_data_file")) +}) + test_that("mtbls_sync works", { expect_error(mtbls_sync(3, offline = TRUE), "'x' is expected to be")