-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add MsBackendMetaboLights import/export #20
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#' @rdname PlainTextParam | ||
setMethod("readMsObject", signature(object = "MsBackendMetaboLights", | ||
param = "PlainTextParam"), | ||
function(object, param, offline = FALSE) { | ||
fl <- file.path(param@path, "ms_backend_data.txt") | ||
if (!file.exists(fl)) | ||
stop("No 'backend_data.txt' file found in the provided path.") | ||
l2 <- readLines(fl, n = 2) | ||
if (l2[1] != "# MsBackendMetaboLights") | ||
stop("Invalid class in 'ms_backend_data.txt' file.", | ||
"Should run with object = ", l2[1]) | ||
if (length(l2) > 1L) { | ||
data <- read.table(file = fl, sep = "\t", header = TRUE) | ||
rownames(data) <- NULL | ||
slot(object, "spectraData", check = FALSE) <- DataFrame(data) | ||
MsBackendMetaboLights::mtbls_sync(object, offline = offline) | ||
} | ||
validObject(object) | ||
object | ||
}) | ||
|
||
################################################################################ | ||
## | ||
## alabaster saveObject/readObject | ||
## | ||
################################################################################ | ||
#' @rdname AlabasterParam | ||
setMethod("saveObject", "MsBackendMetaboLights", function(x, path, ...) { | ||
.save_object_spectra_data(x, path, object = "ms_backend_metabo_lights") | ||
}) | ||
|
||
#' @noRd | ||
#' | ||
#' @importFrom methods slot<- | ||
readAlabasterMsBackendMetaboLights <- function(path = character(), | ||
metadata = list(), | ||
offline = FALSE) { | ||
if (!.is_spectra_installed()) | ||
stop("Required package 'Spectra' missing. Please install ", | ||
"and try again.", call. = FALSE) | ||
if (!.is_ms_backend_metabo_lights_installed()) | ||
stop("Required package 'MsBackendMetaboLights' missing. ", | ||
"Please install and try again.", call. = FALSE) | ||
validateAlabasterMsBackendMzR(path, metadata) | ||
sdata <- altReadObject(file.path(path, "spectra_data")) | ||
pvars <- altReadObject(file.path(path, "peaks_variables")) | ||
be <- MsBackendMetaboLights::MsBackendMetaboLights() | ||
slot(be, "spectraData", check = FALSE) <- sdata | ||
slot(be, "peaksVariables", check = FALSE) <- pvars | ||
MsBackendMetaboLights::mtbls_sync(be, offline = offline) | ||
validObject(be) | ||
be | ||
} | ||
|
||
#' @rdname AlabasterParam | ||
setMethod("saveMsObject", signature(object = "MsBackendMetaboLights", | ||
param = "AlabasterParam"), | ||
function(object, param) { | ||
if (file.exists(param@path)) | ||
stop("Overwriting or saving to an existing directory is not", | ||
" supported. Please remove the directory defined with", | ||
" parameter `path` first.") | ||
saveObject(object, param@path) | ||
}) | ||
|
||
#' @rdname AlabasterParam | ||
setMethod("readMsObject", signature(object = "MsBackendMetaboLights", | ||
param = "AlabasterParam"), | ||
function(object, param, offline = FALSE) { | ||
readAlabasterMsBackendMetaboLights(path = param@path, | ||
offline = offline) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,13 +26,16 @@ | |
#' are: | ||
#' | ||
#' - `MsBackendMzR` object, defined in the | ||
#' ([Spectra](https://bioconductor.org/packages/Spectra)) package. | ||
#' [*Spectra*](https://bioconductor.org/packages/Spectra) package. | ||
#' - `MsBackendMetaboLights` object, defined in the | ||
#' [*MsBackendMetaboLights*](https://bioconductor.org/packages/MsBackendMetaboLights) | ||
#' package. | ||
#' - `Spectra` object, defined in the | ||
#' ([Spectra](https://bioconductor.org/packages/Spectra)) package. | ||
#' [*Spectra*](https://bioconductor.org/packages/Spectra) package. | ||
#' - `MsExperiment` object, defined in the | ||
#' ([MsExperiment](https://bioconductor.org/packages/MsExperiment)) package. | ||
#' [*MsExperiment*](https://bioconductor.org/packages/MsExperiment) package. | ||
#' - `XcmsExperiment` object, defined in the | ||
#' ([xcms](https://bioconductor.org/packages/xcms)) package. | ||
#' [*xcms*](https://bioconductor.org/packages/xcms) package. | ||
#' | ||
#' See their respective section below for details and formats of the | ||
#' exported files. | ||
|
@@ -48,6 +51,11 @@ | |
#' `readMsObject()` functions for other classes (such as `Spectra`, | ||
#' `MsExperiment` etc). | ||
#' | ||
#' @param offline For `readMsObject()` to load MS data as a | ||
#' `MsBackendMetaboLights()`: `logical(1)` to evaluate the local file cache | ||
#' and only load local files. Thus `offline = TRUE` does not need an active | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would avoid repetition maybe and instead maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done with the latest commit. |
||
#' internet connection, but fails if one of more files are not cached locally. | ||
#' | ||
#' @param ... Additional parameters passed down to internal functions. E.g. | ||
#' parameter `spectraPath` (see above). | ||
#' | ||
|
@@ -68,6 +76,15 @@ | |
#' named *ms_backend_data.txt*. Each row of this tab-delimited text file | ||
#' corresponds to a spectrum with its respective metadata in the columns. | ||
#' | ||
#' | ||
#' @section On-disk storage for `MsBackendMetaboLights` objects: | ||
#' | ||
#' The `MsBackendMetaboLights` extends the `MsBackendMzR` backend and hence the | ||
#' same files are stored. When a `MsBackendMetaboLights` object is restored, | ||
#' the `mtbls_sync()` function is called to check for presence of all MS data | ||
#' files and, if missing, re-download them from the *MetaboLights* repository. | ||
#' | ||
#' | ||
#' @section On-disk storage for `Spectra` objects: | ||
#' | ||
#' For `Spectra` objects, defined in the `Spectra` package, the files listed | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit confused about the
list(list())
. and then you name it 'ms_backend_mzr` into it next line ? why does it need to be a list of a list ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the particular format
saveObjectFile
want the input parameter, i.e. alist
with all optional parameters (one of them beingversion
and the name of thatlist
should be the name/type of the object. It's confusing, I agree, but I don't know how to call it differently, given that we want to support setting the type with parameterobject
of the upstream function.