Skip to content

Commit

Permalink
naming changes + if() fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
philouail committed Sep 5, 2024
1 parent 0def22a commit 069da52
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 38 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Collate:
'MsBackendMzR.R'
'MsExperiment.R'
'MsExperimentFiles.R'
'MzTabParam.R'
'Spectra.R'
'mzTabParam.R'
'XcmsExperiment.R'
'zzz.R'
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

export(AlabasterParam)
export(MetaboLightsParam)
export(MzTabParam)
export(PlainTextParam)
export(mzTabParam)
export(readObject)
exportMethods(readMsObject)
exportMethods(saveMsObject)
Expand Down
26 changes: 13 additions & 13 deletions R/MzTabParam.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @title Store xcms preprocessing results to a file in mzTab-M format.
#'
#' @name MzTabParam
#' @name mzTabParam
#'
#' @export
#'
Expand All @@ -9,7 +9,7 @@
#' @family MS object export and import formats.
#'
#' @description
#' The `saveMsObject()` and `readMsObject()` methods with the `MzTabParam`
#' The `saveMsObject()` and `readMsObject()` methods with the `mzTabParam`
#' option enable users to save/load `XcmsExperiment` objects in Mz-Tab-m
#' file format. Mainly the metadata (MTD) and Small molecule feature (SMF)
#' tables will represent the `XcmsExperiment`. More specifically, `sampleData()`
Expand All @@ -28,7 +28,7 @@
#' an error.
#'
#' @param studyId `character(1)` Will be both the `filename` of the object
#' saved in .mztabm format and the `mzTab-ID` in the file.
#' saved in mzTab-M format and the `mzTab-ID` in the file.
#'
#' @param polarity `character(1)` Describes the polarity of the experiment. Two
#' inputs are possible, "positive" (default) or "negative".
Expand All @@ -51,7 +51,7 @@
#'
#' @note
#' This function was build so that the output fit the recommendation of
#' Mz-Tab-m file format version 2.0. These can be found here:
#' mzTab-M file format version 2.0. These can be found here:
#' (http://hupo-psi.github.io/mzTab/2_0-metabolomics-release/mzTab_format_specification_2_0-M_release.html)
#'
#' @references
Expand All @@ -75,17 +75,17 @@
#' test_xcms <- loadXcmsData()
#'
#' ## Define param
#' param <- MzTabParam(studyId = "test",
#' param <- mzTabParam(studyId = "test",
#' polarity = "positive",
#' sampleDataColumn = "sample_type")
#'
#' ## Save as a .mzTabm file
#' ## Save as a mzTab-M file
#' saveMsObject(test_xcms, param)
#'
NULL

#' @noRd
setClass("MzTabParam",
setClass("mzTabParam",
slots = c(studyId = "character",
polarity = "character",
sampleDataColumn = "character",
Expand All @@ -104,29 +104,29 @@ setClass("MzTabParam",
),
validity = function(object) {
msg <- NULL
if(length(object@studyId) != 1)
if (length(object@studyId) != 1)
msg <- c("'studyId' has to be a character string of length 1")
if(length(object@polarity) != 1)
if (length(object@polarity) != 1)
msg <- c(msg, "'polarity' has to be a character string ",
"of length 1")
if(length(object@sampleDataColumn) == 0)
if (length(object@sampleDataColumn) == 0)
msg <- c(msg, "'sampleDataColumn' cannot be empty")
if (length(object@path) != 1)
msg <- c(msg, "'path' has to be a character string of ",
"length 1")
msg
})

#' @rdname MzTabParam
#' @rdname mzTabParam
#'
#' @export
MzTabParam <- function(studyId = character(),
mzTabParam <- function(studyId = character(),
polarity = c("positive", "negative"),
sampleDataColumn = character(),
path = tempdir(),
optionalFeatureColumns = character(), ...) {
polarity <- match.arg(polarity)
new("MzTabParam", studyId = studyId, polarity = polarity,
new("mzTabParam", studyId = studyId, polarity = polarity,
sampleDataColumn = sampleDataColumn, path = path,
optionalFeatureColumns = optionalFeatureColumns, dots = list(...))
}
16 changes: 9 additions & 7 deletions R/XcmsExperiment.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#' @include PlainTextParam.R
#' @include mzTabParam.R
#' @title Methods to save and load contents of a XcmsExperiment object
#'
#' @author Philippine Louail
Expand Down Expand Up @@ -136,7 +137,7 @@ setMethod("readMsObject",
################################################################################
#' @rdname AlabasterParam
setMethod("saveObject", "XcmsExperiment", function(x, path, ...) {
if(!requireNamespace("alabaster.matrix", quietly = TRUE))
if (!requireNamespace("alabaster.matrix", quietly = TRUE))
stop("Required package 'alabaster.matrix' missing. Please install and ",
"try again.", call. = FALSE)
## Save the MsExperiment part
Expand Down Expand Up @@ -190,6 +191,7 @@ setMethod("saveMsObject", signature(object = "XcmsExperiment",
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.")
Expand All @@ -205,19 +207,19 @@ setMethod("readMsObject", signature(object = "XcmsExperiment",

################################################################################
##
## MzTabParam
## mzTabParam
##
################################################################################
#' @rdname MzTabParam
#' @rdname mzTabParam
setMethod("saveMsObject",
signature(object = "XcmsExperiment",
param = "MzTabParam"),
param = "mzTabParam"),
function(object, param){
if(!param@sampleDataColumn %in% colnames(object@sampleData))
if (!param@sampleDataColumn %in% colnames(object@sampleData))
stop("'sampleDataColumn' has to correspond to column names",
"of the sampleData() table")
if(length(param@optionalFeatureColumns) != 0)
if(!param@optionalFeatureColumns %in% colnames(object@featureDefinitions))
if (length(param@optionalFeatureColumns) != 0)
if (!param@optionalFeatureColumns %in% colnames(object@featureDefinitions))
stop("'optionalFeatureColumns' have to correspond to",
"column names of the featureDefinitions() table")

Expand Down
4 changes: 2 additions & 2 deletions man/AlabasterParam.Rd

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

22 changes: 11 additions & 11 deletions man/MzTabParam.Rd

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

2 changes: 1 addition & 1 deletion man/PlainTextParam.Rd

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

4 changes: 2 additions & 2 deletions tests/testthat/test_MzTabParam.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ test_that(".mztab_study_variable_entries works", {
expect_true(length(res2) > length(res))
})

test_that("saveMsObject,MzTabParam works", {
test_that("saveMsObject,mzTabParam works", {
d <- tempdir()
p <- MzTabParam(studyId = "test_study", path = d,
p <- mzTabParam(studyId = "test_study", path = d,
sampleDataColumn = "sample_index",
optionalFeatureColumns = "peakidx")
saveMsObject(faahko, p)
Expand Down

0 comments on commit 069da52

Please sign in to comment.