-
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.