Skip to content

Commit

Permalink
feat: add backendRequiredSpectraVariables method
Browse files Browse the repository at this point in the history
  • Loading branch information
jorainer committed Oct 18, 2024
1 parent bca79ed commit d270b45
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -31,3 +32,4 @@ importMethodsFrom(ProtGenerics,backendInitialize)
importMethodsFrom(ProtGenerics,dataOrigin)
importMethodsFrom(Spectra,"[")
importMethodsFrom(Spectra,backendInitialize)
importMethodsFrom(Spectra,backendRequiredSpectraVariables)
17 changes: 17 additions & 0 deletions R/MsBackendMetaboLights.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
#'
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions man/MsBackendMetaboLights.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tests/testthat/test_MsBackendMetaboLights.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit d270b45

Please sign in to comment.