diff --git a/DESCRIPTION b/DESCRIPTION index e370ec7e..9741c4f0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: xcms -Version: 4.3.1 +Version: 4.3.2 Title: LC-MS and GC-MS Data Analysis Description: Framework for processing and visualization of chromatographically separated and single-spectra mass spectral data. Imports from AIA/ANDI NetCDF, @@ -65,7 +65,6 @@ Imports: MsExperiment (>= 1.5.4), Spectra (>= 1.13.7), progress, - jsonlite, RColorBrewer, MetaboCoreUtils (>= 1.11.2) Suggests: @@ -93,7 +92,7 @@ URL: https://github.com/sneumann/xcms BugReports: https://github.com/sneumann/xcms/issues/new VignetteBuilder: knitr biocViews: ImmunoOncology, MassSpectrometry, Metabolomics -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Encoding: UTF-8 Collate: 'AllGenerics.R' @@ -104,11 +103,9 @@ Collate: 'MPI.R' 'MsExperiment-functions.R' 'MsExperiment.R' - 'XcmsExperiment.R' - 'PlainTextParam.R' - 'RDataParam.R' 'XcmsExperiment-functions.R' 'XcmsExperiment-plotting.R' + 'XcmsExperiment.R' 'c.R' 'cwTools.R' 'databases.R' diff --git a/NAMESPACE b/NAMESPACE index 3b122388..50756901 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -72,6 +72,7 @@ importMethodsFrom("MSnbase", "intensity", "mz", "rtime", "fileNames", "fromFile" importFrom("MSnbase", "as.data.frame.Spectrum", "Chromatogram", "MChromatograms", "MSpectra", "requiredFvarLabels", "selectFeatureData") + export( "etg", "medianFilter", @@ -254,7 +255,8 @@ export( "loadXcmsData", "matchLamasChromPeaks", "summarizeLamaMatch", - "matchedRtimes" + "matchedRtimes", + "XcmsExperiment" ) ## New analysis methods @@ -566,7 +568,7 @@ importMethodsFrom("Spectra", "precursorMz") importMethodsFrom("Spectra", "$") importMethodsFrom("Spectra", "uniqueMsLevels") importMethodsFrom("Spectra", "backendBpparam") -importFrom("Spectra", "MsBackendMemory") +importFrom("Spectra", "MsBackendMemory", "filterEmptySpectra") ## MsExperiment things importClassesFrom("MsExperiment", "MsExperiment") @@ -590,13 +592,6 @@ exportMethods("filterMzRange") exportMethods("fromFile") exportMethods("fileNames") -## saving xcms objects things -importFrom("jsonlite", "serializeJSON", "write_json", "unserializeJSON", - "read_json") -export("RDataParam") -export("PlainTextParam") -exportMethods("storeResults") - ## filtering features things importFrom("MetaboCoreUtils", "rowRsd", "rowDratio", "rowPercentMissing", "rowBlank", "mclosest") diff --git a/NEWS.md b/NEWS.md index ecb3f7b3..a678609b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,10 @@ # xcms 4.3 +## Changes in version 4.3.2 + +- Remove data/results import/export functionality as it is being developed in + the *MsIO* package. + ## Changes in version 4.3.1 - Support excluding samples or sample groups from defining features with diff --git a/R/AllGenerics.R b/R/AllGenerics.R index fbf47a96..72a0aeb9 100644 --- a/R/AllGenerics.R +++ b/R/AllGenerics.R @@ -2051,61 +2051,6 @@ setGeneric("stitch.xml", function(object, lockMass) standardGeneric("stitch.xml" setGeneric("stitch.netCDF", function(object, lockMass) standardGeneric("stitch.netCDF")) setGeneric("stitch.netCDF.new", function(object, lockMass) standardGeneric("stitch.netCDF.new")) -#' @title Save xcms result objects in a specified format -#' -#' @description -#' -#' The `storeResults` function saves an `object` resulting from processing with -#' the `xcms` package (mainly `XcmsExperiment`). Multiple formats for storing -#' and exporting are available and can be defined by the `param` argument. -#' -#' Supported `param` objects are: -#' -#' - [`RDataParam`]: Save in an .RData format file. The name of the file can be -#' specified in the `fileName` argument. -#' -#' - [`PlainTextParam`]: Store `MsExperiment` and `XcmsExperiment` objects as a -#' folder of plain text files, folder path defined in the `path` argument. -#' -#' - `MzTabMParam`: Save in MzTab format (to be defined). -#' -#' For specific examples, see the help pages of the individual parameter classes -#' listed above. -#' -#' @param object `MsExperiment` or `XcmsExperiment` The data object that needs -#' to be saved. -#' -#' @param param The parameter object selecting and configuring the format for -#' saving. It can be one of the following classes: [`RDataParam`], -#' [`PlainTextParam`], or `MzTabMParam`. -#' -#' @param ... Optional parameters. -#' -#' @name storeResults -#' -#' @author Philippine Louail -#' -#' @examples -#' -#' ## Load a test data set with detected peaks -#' library(xcms) -#' library(MsExperiment) -#' faahko_sub <- loadXcmsData("faahko_sub2") -#' -#' ## Set up parameter to save as .RData file -#' param <- RDataParam(fileName = "example_xcms_results") -#' -#' ## save as .RData -#' storeResults(object = faahko_sub, param = param) -#' -#' ## Set up parameter to save as a collection of plain text file -#' param <- PlainTextParam(path = "test/path/") -#' -#' ## Save as a collection of plain text files -#' storeResults(object = faahko_sub, param = param) -#' -#' @md -setGeneric("storeResults", function(object, param, ...) standardGeneric("storeResults")) setGeneric("subset<-", function(object, value) standardGeneric("subset<-")) setGeneric("subsetAdjust", function(object, ...) standardGeneric("subsetAdjust")) setGeneric("subsetAdjust<-", function(object, value) standardGeneric("subsetAdjust<-")) diff --git a/R/PlainTextParam.R b/R/PlainTextParam.R deleted file mode 100644 index 4eabe7b8..00000000 --- a/R/PlainTextParam.R +++ /dev/null @@ -1,226 +0,0 @@ -#' @include XcmsExperiment.R - -#' @title Store contents of `MsExperiment` and `XcmsExperiment` objects as -#' plain text files -#' -#' @name PlainTextParam -#' -#' @export -#' -#' @family xcms result export formats. -#' -#' @description -#' The `PlainTextParam` class and method enable users to save `MsExperiment` or -#' `XcmsExperiment` objects as collections of plain text files in a specified -#' folder. Note that, while for all xcms results within the `XcmsExperiment` can -#' and will be exported, the full raw MS data (of the object's `Spectra` object) -#' will currently not be exported in plain text format. For `Spectra` using the -#' [MsBackendMzR()] backend, the names of the raw data files will however be -#' exported (which enables to *restore* the full `Spectra` respectively -#' `MsExperiment` objects). -#' -#' For an `MsExperiment` object, the exported files include: -#' -#' - The [sampleData()] stored as a text file named *sample_data.txt*. -#' -#' - The [fileNames()] of the *Spectra* object stored in a tabular format in a -#' text file named *spectra_files.txt*.The file names will only be exported if -#' the `Spectra` object uses a [MsBackendMzR()] backend. For other backends no -#' information on raw spectra data is currently exported with `PlainTextParam`. -#' -#' - Processing queue of the `Spectra` object, ensuring that any spectra data -#' modifications are retained. It is stored in a `json` file named -#' *spectra_processing_queue.json*. -#' -#' For an `XcmsExperiment` object, the exported files are the same as those -#' for an `MsExperiment` object, with the addition of the following: -#' -#' - The [processHistory()] information of the object, stored in a `json` file -#' named *process_history.json*. -#' -#' - The chromatographic peak information obtained with [chromPeaks()] and -#' [chromPeaksData()], stored in tabular format in the text files -#' *chrom_peaks.txt* and *chrom_peak_data.txt* respectively. -#' -#' - The retention time information obtained with [adjustedRtime()] stored -#' in the text file named *rtime_adjusted.txt*. -#' -#' - The [featureDefinitions()] stored in a text file named -#' *feature_definitions.txt*. Additionally, a second file named -#' *feature_peak_index.txt* is generated to connect the features' definitions -#' with their names. -#' -#' This `param` class and method are part of the possible dispatch of the -#' generic function `storeResults`. The folder will be created by calling -#' `storeResults`. If the folder already exists, previous exports in that -#' folder might get overwritten. -#' -#' @param path for `PlainTextParam` `character(1)`, defining where the files are -#' going to be stored. The default will be `tempdir()`. -#' -#' @inheritParams storeResults -#' -#' @return for `PlainTextParam`: a `PlainTextParam` class. `storeResults` does -#' not return anything but saves the object to collections of different plain -#' text files to a folder. -#' -#' @author Philippine Louail, Johannes Rainer. -#' -#' @importFrom jsonlite serializeJSON write_json unserializeJSON read_json -#' -#' @examples -#' ## Load test data set of class `MsExperiment` -#' library(MsExperiment) -#' fls <- dir(system.file("sciex", package = "msdata"), full.names = TRUE) -#' pd <- data.frame(file = basename(fls), -#' sample = c("POOL_1", "POOL_2"), -#' injection_index = c(1, 19), -#' group = "POOL") -#' rownames(pd) <- c("1", "2") -#' mse <- readMsExperiment(fls, sampleData = pd) -#' -#' ## Define param -#' pth = file.path(tempdir(), "test") -#' param <- PlainTextParam(path = pth) -#' -#' ## Save as a collection of plain text files -#' storeResults(object = mse, param = param) -#' -#' ## Load a test data set with detected peaks, of class `XcmsExperiment` -#' faahko_sub <- loadXcmsData("faahko_sub2") -#' -#' ## Define param -#' pth = file.path(tempdir(), "test") -#' param <- PlainTextParam(path = pth) -#' -#' ## Save as a collection of plain text files -#' storeResults(object = faahko_sub, param = param) -#' -NULL - -#' @noRd -setClass("PlainTextParam", - slots = c(path = "character"), - contains = "Param", - prototype = prototype( - path = character()), - validity = function(object) { - msg <- NULL - if (length(object@path) != 1) - msg <- c("'path' has to be a character string of length 1") - msg - }) - -#' @rdname PlainTextParam -#' -#' @export -PlainTextParam <- function(path = tempdir()) { - new("PlainTextParam", path = path) -} - - -#' @rdname PlainTextParam -setMethod("storeResults", - signature(object = "MsExperiment", - param = "PlainTextParam"), - function(object, param){ - dir.create(path = param@path, recursive = TRUE, showWarnings = TRUE) - .store_msexperiment(x = object, path = param@path) - } -) - - -#' @noRd -.store_msexperiment <- function(x, path = tempdir()) { - .export_sample_data(as.data.frame(sampleData(x)), - file.path(path, "sample_data.txt")) - .export_spectra_files(x, path = path) - .export_spectra_processing_queue(spectra(x), path = path) -} - -#' Sample data -#' @noRd -.export_sample_data <- function(x, file = tempfile()) { - write.table(x, file = file) -} - -#' Spectra file -#' @noRd -.export_spectra_files <- function(x, path = character()) { - s <- spectra(x) - if (!inherits(s@backend, "MsBackendMzR")) - warning("Spectra data will not be exported, backend need to be of ", - "class 'MsBackendMzR'") - else { - fls <- fileNames(x) - write.table(fls, file = file.path(path, "spectra_files.txt"), - row.names = FALSE, col.names = FALSE) - } -} - -#' Processing queue -#' @param x `Spectra` -#' -#' @noRd -.export_spectra_processing_queue <- function(x, path = character()) { - pq <- x@processingQueue - if (length(pq)) - write_json(serializeJSON(pq), - file.path(path, "spectra_processing_queue.json")) -} - - -#' @rdname PlainTextParam -setMethod("storeResults", - signature(object = "XcmsExperiment", - param = "PlainTextParam"), - function(object, param){ - callNextMethod() - .store_xcmsexperiment(x = object, path = param@path) - } -) - -#' @noRd -.store_xcmsexperiment <- function(x, path = tempdir()) { - .export_process_history(x, path = path) - if (hasChromPeaks(x)) - .export_chrom_peaks(x, path) - if (hasAdjustedRtime(x)) - .export_adjusted_rtime(x, path) - if (hasFeatures(x)) - .export_features(x, path) -} - -#' Processing history -#' @noRd -.export_process_history <- function(x, path = character()) { - ph <- processHistory(x) - write_json(serializeJSON(ph), file.path(path, "process_history.json")) -} - -#' Chromatographic peaks -#' @noRd -.export_chrom_peaks <- function(x, path = character()) { - write.table(chromPeaks(x), file = file.path(path, "chrom_peaks.txt")) - write.table(as.data.frame(chromPeakData(x)), - file = file.path(path, "chrom_peak_data.txt")) -} - -#' Retention times -#' @noRd -.export_adjusted_rtime <- function(x, path = character()) { - write.table(adjustedRtime(x), file = file.path(path, "rtime_adjusted.txt"), - row.names = FALSE, col.names = FALSE) -} - -#' Features -#' @noRd -.export_features <- function(x, path = character()) { - fts <- featureDefinitions(x) - pkidx <- data.frame( - feature_index = rep(seq_len(nrow(fts)), lengths(fts$peakidx)), - peak_index = unlist(fts$peakidx, use.names = FALSE)) - fts$peakidx <- NA - write.table(fts, file = file.path(path, "feature_definitions.txt")) - write.table(pkidx, file = file.path(path, "feature_peak_index.txt")) -} diff --git a/R/RDataParam.R b/R/RDataParam.R deleted file mode 100644 index 59a7db86..00000000 --- a/R/RDataParam.R +++ /dev/null @@ -1,66 +0,0 @@ -#' @title Store `XcmsExperiment` object as .RData file -#' -#' @name RDataParam -#' -#' @export -#' -#' @family xcms result export formats. -#' -#' @description -#' The `RDataParam` class and method allow users to save an `XcmsExperiment` -#' object as an .RData file with a chosen filename. The object gets exported -#' using [`save()`] function. This `param` class and method are part of the -#' possible dispatch of the generic function `storeResults`. -#' -#' @param fileName for `RDataParam` `character(1)`, defining the file name. The -#' default will be `tempfile()`. -#' -#' @inheritParams storeResults -#' -#' @return for `RDataParam`: a `RDataParam` class. `storeResults` does not -#' return anything but saves the object to a RData file. -#' -#' @author Philippine Louail -#' -#' @examples -#' -#' ## Load a test data set with detected peaks -#' faahko_sub <- loadXcmsData("faahko_sub2") -#' -#' ## Define param -#' param <- RDataParam(fileName = "example_xcms_object") -#' -#' ## Save as RData -#' storeResults(object = faahko_sub, param = param) -#' -NULL - -#' @noRd -setClass("RDataParam", - slots = c(fileName = "character"), - contains = "Param", - prototype = prototype( - fileName = character()), - validity = function(object) { - msg <- NULL - if (length(object@fileName) != 1) - msg <- c("'fileName' has to be a character string of length 1") - msg - }) - -#' @rdname RDataParam -#' -#' @export -RDataParam <- function(fileName = tempfile()) { - new("RDataParam", fileName = fileName) -} - -#' @rdname RDataParam -setMethod("storeResults", - signature(object = "XcmsExperiment", - param = "RDataParam"), - function(object, param){ - save(object, file = param@fileName) - } - ) - diff --git a/R/XcmsExperiment-functions.R b/R/XcmsExperiment-functions.R index e2b2957d..7117e8e3 100644 --- a/R/XcmsExperiment-functions.R +++ b/R/XcmsExperiment-functions.R @@ -1134,3 +1134,8 @@ featureArea <- function(object, mzmin = min, mzmax = max, rtmin = min, object@chromPeaks else chromPeaks(object@msFeatureData) } + +#' function to create an empty `XcmsExperiment` object +XcmsExperiment <- function() { + as(MsExperiment(), "XcmsExperiment") +} diff --git a/R/XcmsExperiment-plotting.R b/R/XcmsExperiment-plotting.R index ed16537b..e55d659e 100644 --- a/R/XcmsExperiment-plotting.R +++ b/R/XcmsExperiment-plotting.R @@ -437,6 +437,9 @@ setMethod( #' #' @importFrom grDevices n2mfrow #' +#' @importFrom Spectra filterEmptySpectra +#' +#' #' @export #' #' @author Johannes Rainer diff --git a/R/XcmsExperiment.R b/R/XcmsExperiment.R index 356edbce..b540334b 100644 --- a/R/XcmsExperiment.R +++ b/R/XcmsExperiment.R @@ -1450,7 +1450,9 @@ setMethod("dropAdjustedRtime", "XcmsExperiment", function(object) { #' @rdname XcmsExperiment setMethod("hasAdjustedRtime", "MsExperiment", function(object) { - any(spectraVariables(spectra(object)) == "rtime_adjusted") + if (length(spectra(object))) + any(spectraVariables(spectra(object)) == "rtime_adjusted") + else FALSE }) #' @rdname XcmsExperiment diff --git a/man/PlainTextParam.Rd b/man/PlainTextParam.Rd deleted file mode 100644 index 8bd80648..00000000 --- a/man/PlainTextParam.Rd +++ /dev/null @@ -1,114 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/PlainTextParam.R -\name{PlainTextParam} -\alias{PlainTextParam} -\alias{storeResults,MsExperiment,PlainTextParam-method} -\alias{storeResults,XcmsExperiment,PlainTextParam-method} -\title{Store contents of `MsExperiment` and `XcmsExperiment` objects as -plain text files} -\usage{ -PlainTextParam(path = tempdir()) - -\S4method{storeResults}{MsExperiment,PlainTextParam}(object, param) - -\S4method{storeResults}{XcmsExperiment,PlainTextParam}(object, param) -} -\arguments{ -\item{path}{for `PlainTextParam` `character(1)`, defining where the files are -going to be stored. The default will be `tempdir()`.} - -\item{object}{\code{MsExperiment} or \code{XcmsExperiment} The data object that needs -to be saved.} - -\item{param}{The parameter object selecting and configuring the format for -saving. It can be one of the following classes: \code{\link{RDataParam}}, -\code{\link{PlainTextParam}}, or \code{MzTabMParam}.} -} -\value{ -for `PlainTextParam`: a `PlainTextParam` class. `storeResults` does -not return anything but saves the object to collections of different plain -text files to a folder. -} -\description{ -The `PlainTextParam` class and method enable users to save `MsExperiment` or -`XcmsExperiment` objects as collections of plain text files in a specified -folder. Note that, while for all xcms results within the `XcmsExperiment` can -and will be exported, the full raw MS data (of the object's `Spectra` object) -will currently not be exported in plain text format. For `Spectra` using the -[MsBackendMzR()] backend, the names of the raw data files will however be -exported (which enables to *restore* the full `Spectra` respectively -`MsExperiment` objects). - -For an `MsExperiment` object, the exported files include: - -- The [sampleData()] stored as a text file named *sample_data.txt*. - -- The [fileNames()] of the *Spectra* object stored in a tabular format in a -text file named *spectra_files.txt*.The file names will only be exported if -the `Spectra` object uses a [MsBackendMzR()] backend. For other backends no -information on raw spectra data is currently exported with `PlainTextParam`. - -- Processing queue of the `Spectra` object, ensuring that any spectra data -modifications are retained. It is stored in a `json` file named -*spectra_processing_queue.json*. - -For an `XcmsExperiment` object, the exported files are the same as those -for an `MsExperiment` object, with the addition of the following: - -- The [processHistory()] information of the object, stored in a `json` file -named *process_history.json*. - -- The chromatographic peak information obtained with [chromPeaks()] and -[chromPeaksData()], stored in tabular format in the text files -*chrom_peaks.txt* and *chrom_peak_data.txt* respectively. - -- The retention time information obtained with [adjustedRtime()] stored -in the text file named *rtime_adjusted.txt*. - -- The [featureDefinitions()] stored in a text file named -*feature_definitions.txt*. Additionally, a second file named -*feature_peak_index.txt* is generated to connect the features' definitions -with their names. - -This `param` class and method are part of the possible dispatch of the -generic function `storeResults`. The folder will be created by calling -`storeResults`. If the folder already exists, previous exports in that -folder might get overwritten. -} -\examples{ -## Load test data set of class `MsExperiment` -library(MsExperiment) -fls <- dir(system.file("sciex", package = "msdata"), full.names = TRUE) -pd <- data.frame(file = basename(fls), - sample = c("POOL_1", "POOL_2"), - injection_index = c(1, 19), - group = "POOL") -rownames(pd) <- c("1", "2") -mse <- readMsExperiment(fls, sampleData = pd) - -## Define param -pth = file.path(tempdir(), "test") -param <- PlainTextParam(path = pth) - -## Save as a collection of plain text files -storeResults(object = mse, param = param) - -## Load a test data set with detected peaks, of class `XcmsExperiment` -faahko_sub <- loadXcmsData("faahko_sub2") - -## Define param -pth = file.path(tempdir(), "test") -param <- PlainTextParam(path = pth) - -## Save as a collection of plain text files -storeResults(object = faahko_sub, param = param) - -} -\seealso{ -Other xcms result export formats.: -\code{\link{RDataParam}} -} -\author{ -Philippine Louail, Johannes Rainer. -} -\concept{xcms result export formats.} diff --git a/man/RDataParam.Rd b/man/RDataParam.Rd deleted file mode 100644 index 617c3dc9..00000000 --- a/man/RDataParam.Rd +++ /dev/null @@ -1,52 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/RDataParam.R -\name{RDataParam} -\alias{RDataParam} -\alias{storeResults,XcmsExperiment,RDataParam-method} -\title{Store `XcmsExperiment` object as .RData file} -\usage{ -RDataParam(fileName = tempfile()) - -\S4method{storeResults}{XcmsExperiment,RDataParam}(object, param) -} -\arguments{ -\item{fileName}{for `RDataParam` `character(1)`, defining the file name. The -default will be `tempfile()`.} - -\item{object}{\code{MsExperiment} or \code{XcmsExperiment} The data object that needs -to be saved.} - -\item{param}{The parameter object selecting and configuring the format for -saving. It can be one of the following classes: \code{\link{RDataParam}}, -\code{\link{PlainTextParam}}, or \code{MzTabMParam}.} -} -\value{ -for `RDataParam`: a `RDataParam` class. `storeResults` does not -return anything but saves the object to a RData file. -} -\description{ -The `RDataParam` class and method allow users to save an `XcmsExperiment` -object as an .RData file with a chosen filename. The object gets exported -using [`save()`] function. This `param` class and method are part of the -possible dispatch of the generic function `storeResults`. -} -\examples{ - -## Load a test data set with detected peaks -faahko_sub <- loadXcmsData("faahko_sub2") - -## Define param -param <- RDataParam(fileName = "example_xcms_object") - -## Save as RData -storeResults(object = faahko_sub, param = param) - -} -\seealso{ -Other xcms result export formats.: -\code{\link{PlainTextParam}} -} -\author{ -Philippine Louail -} -\concept{xcms result export formats.} diff --git a/man/XcmsExperiment.Rd b/man/XcmsExperiment.Rd index f7676365..f05d094d 100644 --- a/man/XcmsExperiment.Rd +++ b/man/XcmsExperiment.Rd @@ -1,7 +1,7 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/AllGenerics.R, R/MsExperiment.R, -% R/XcmsExperiment.R, R/XcmsExperiment-functions.R, -% R/XcmsExperiment-plotting.R, R/methods-XCMSnExp.R +% R/XcmsExperiment-functions.R, R/XcmsExperiment-plotting.R, +% R/XcmsExperiment.R, R/methods-XCMSnExp.R \name{filterFeatureDefinitions} \alias{filterFeatureDefinitions} \alias{filterRt,MsExperiment-method} @@ -16,6 +16,8 @@ \alias{polarity,MsExperiment-method} \alias{filterIsolationWindow,MsExperiment-method} \alias{chromatogram,MsExperiment-method} +\alias{featureArea} +\alias{plot,MsExperiment,missing-method} \alias{XcmsExperiment} \alias{XcmsExperiment-class} \alias{show,XcmsExperiment-method} @@ -48,8 +50,6 @@ \alias{chromatogram,XcmsExperiment-method} \alias{processHistory,XcmsExperiment-method} \alias{filterFile,XcmsExperiment-method} -\alias{featureArea} -\alias{plot,MsExperiment,missing-method} \title{Next Generation \code{xcms} Result Object} \usage{ filterFeatureDefinitions(object, ...) @@ -88,6 +88,17 @@ filterFeatureDefinitions(object, ...) BPPARAM = bpparam() ) +featureArea( + object, + mzmin = min, + mzmax = max, + rtmin = min, + rtmax = max, + features = character() +) + +\S4method{plot}{MsExperiment,missing}(x, y, msLevel = 1L, peakCol = "#ff000060", ...) + \S4method{[}{XcmsExperiment,ANY,ANY,ANY}(x, i, j, ..., drop = TRUE) \S4method{filterIsolationWindow}{XcmsExperiment}(object, mz = numeric()) @@ -193,17 +204,6 @@ filterFeatureDefinitions(object, ...) keepFeatures = FALSE, ... ) - -featureArea( - object, - mzmin = min, - mzmax = max, - rtmin = min, - rtmax = max, - features = character() -) - -\S4method{plot}{MsExperiment,missing}(x, y, msLevel = 1L, peakCol = "#ff000060", ...) } \arguments{ \item{object}{An \code{XcmsExperiment} object.} @@ -272,8 +272,39 @@ type of the returned object. Currently only \item{BPPARAM}{For \code{chromatogram}: parallel processing setup. Defaults to \code{BPPARAM = bpparam()}. See \code{\link[=bpparam]{bpparam()}} for more information.} +\item{mzmin}{For \code{featureArea}: function to calculate the \code{"mzmin"} of +a feature based on the \code{"mzmin"} values of the individual +chromatographic peaks assigned to that feature. Defaults to +\code{mzmin = min}.} + +\item{mzmax}{For \code{featureArea}: function to calculate the \code{"mzmax"} of +a feature based on the \code{"mzmax"} values of the individual +chromatographic peaks assigned to that feature. Defaults to +\code{mzmax = max}.} + +\item{rtmin}{For \code{featureArea}: function to calculate the \code{"rtmin"} of +a feature based on the \code{"rtmin"} values of the individual +chromatographic peaks assigned to that feature. Defaults to +\code{rtmin = min}.} + +\item{rtmax}{For \code{featureArea}: function to calculate the \code{"rtmax"} of +a feature based on the \code{"rtmax"} values of the individual +chromatographic peaks assigned to that feature. Defaults to +\code{rtmax = max}.} + +\item{features}{For \code{filterFeatureDefinitions} and \code{featureArea}: \code{logical}, +\code{integer} or \code{character} defining the features to keep or from which +to extract the feature area, respectively. See function description +for more information.} + \item{x}{An \code{XcmsExperiment} object.} +\item{y}{For \code{plot}: should not be defined as it is not supported.} + +\item{peakCol}{For \code{plot}: defines the border color of the rectangles +indicating the identified chromatographic peaks. Only a single color +is supported. Defaults to `peakCol = "#ff000060".} + \item{i}{For \code{[}: \code{integer} or \code{logical} defining the samples/files to subset.} @@ -335,11 +366,6 @@ For \code{filterChromPeaks}: currently only \code{method = "keep"} is supported. retention times should be returned. The default is to return adjusted retention times, if available.} -\item{features}{For \code{filterFeatureDefinitions} and \code{featureArea}: \code{logical}, -\code{integer} or \code{character} defining the features to keep or from which -to extract the feature area, respectively. See function description -for more information.} - \item{intensity}{For \code{featureValues}: \code{character(1)} specifying the name of the column in the \code{chromPeaks(objects)} matrix containing the intensity value of the peak that should be used for the conflict @@ -370,32 +396,6 @@ also parameter \code{type} below for additional information.} \item{keepFeatures}{for most subsetting functions (\code{[}, \code{filterFile}): \code{logical(1)}: wheter eventually present feature definitions should be retained in the returned (filtered) object.} - -\item{mzmin}{For \code{featureArea}: function to calculate the \code{"mzmin"} of -a feature based on the \code{"mzmin"} values of the individual -chromatographic peaks assigned to that feature. Defaults to -\code{mzmin = min}.} - -\item{mzmax}{For \code{featureArea}: function to calculate the \code{"mzmax"} of -a feature based on the \code{"mzmax"} values of the individual -chromatographic peaks assigned to that feature. Defaults to -\code{mzmax = max}.} - -\item{rtmin}{For \code{featureArea}: function to calculate the \code{"rtmin"} of -a feature based on the \code{"rtmin"} values of the individual -chromatographic peaks assigned to that feature. Defaults to -\code{rtmin = min}.} - -\item{rtmax}{For \code{featureArea}: function to calculate the \code{"rtmax"} of -a feature based on the \code{"rtmax"} values of the individual -chromatographic peaks assigned to that feature. Defaults to -\code{rtmax = max}.} - -\item{y}{For \code{plot}: should not be defined as it is not supported.} - -\item{peakCol}{For \code{plot}: defines the border color of the rectangles -indicating the identified chromatographic peaks. Only a single color -is supported. Defaults to `peakCol = "#ff000060".} } \description{ The \code{XcmsExperiment} is a data container for \code{xcms} preprocessing results diff --git a/man/storeResults.Rd b/man/storeResults.Rd deleted file mode 100644 index e943c993..00000000 --- a/man/storeResults.Rd +++ /dev/null @@ -1,58 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/AllGenerics.R -\name{storeResults} -\alias{storeResults} -\title{Save xcms result objects in a specified format} -\usage{ -storeResults(object, param, ...) -} -\arguments{ -\item{object}{\code{MsExperiment} or \code{XcmsExperiment} The data object that needs -to be saved.} - -\item{param}{The parameter object selecting and configuring the format for -saving. It can be one of the following classes: \code{\link{RDataParam}}, -\code{\link{PlainTextParam}}, or \code{MzTabMParam}.} - -\item{...}{Optional parameters.} -} -\description{ -The \code{storeResults} function saves an \code{object} resulting from processing with -the \code{xcms} package (mainly \code{XcmsExperiment}). Multiple formats for storing -and exporting are available and can be defined by the \code{param} argument. - -Supported \code{param} objects are: -\itemize{ -\item \code{\link{RDataParam}}: Save in an .RData format file. The name of the file can be -specified in the \code{fileName} argument. -\item \code{\link{PlainTextParam}}: Store \code{MsExperiment} and \code{XcmsExperiment} objects as a -folder of plain text files, folder path defined in the \code{path} argument. -\item \code{MzTabMParam}: Save in MzTab format (to be defined). -} - -For specific examples, see the help pages of the individual parameter classes -listed above. -} -\examples{ - -## Load a test data set with detected peaks -library(xcms) -library(MsExperiment) -faahko_sub <- loadXcmsData("faahko_sub2") - -## Set up parameter to save as .RData file -param <- RDataParam(fileName = "example_xcms_results") - -## save as .RData -storeResults(object = faahko_sub, param = param) - -## Set up parameter to save as a collection of plain text file -param <- PlainTextParam(path = "test/path/") - -## Save as a collection of plain text files -storeResults(object = faahko_sub, param = param) - -} -\author{ -Philippine Louail -} diff --git a/tests/testthat/test_PlainTextParam.R b/tests/testthat/test_PlainTextParam.R deleted file mode 100644 index caaffe1c..00000000 --- a/tests/testthat/test_PlainTextParam.R +++ /dev/null @@ -1,34 +0,0 @@ -xmse_full <- loadXcmsData("xmse") - -test_that("storeResults,PlainTextParam,MsExperiment works", { - pth <- file.path(tempdir(), "test") - param <- PlainTextParam(path = pth) - param2 <- PlainTextParam() - expect_false(is.null(param2)) - expect_error(new("PlainTextParam", path = c(tempdir(), tempdir()))) - mse <- filterMzRange(mse, c(200, 500)) - storeResults(mse, param = param) - expect_true(dir.exists(pth)) - expect_true(file.exists(file.path(param@path, "sample_data.txt"))) - expect_true(file.exists(file.path(param@path, "spectra_files.txt"))) - expect_true(file.exists(file.path(param@path, "spectra_processing_queue.json"))) -}) - -test_that("storeResults,PlainTextParam,XcmsExperiment works", { - pth = file.path(tempdir(), "test") - param <- PlainTextParam(path = pth) - param2 <- PlainTextParam() - expect_false(is.null(param2)) - mse <- filterMzRange(xmse_full, c(200, 500)) - storeResults(xmse_full, param = param) - expect_true(dir.exists(pth)) - expect_true(file.exists(file.path(param@path, "sample_data.txt"))) - expect_true(file.exists(file.path(param@path, "spectra_files.txt"))) - expect_true(file.exists(file.path(param@path, "spectra_processing_queue.json"))) - expect_true(file.exists(file.path(param@path, "process_history.json"))) - expect_true(file.exists(file.path(param@path, "chrom_peaks.txt"))) - expect_true(file.exists(file.path(param@path, "chrom_peak_data.txt"))) - expect_true(file.exists(file.path(param@path, "rtime_adjusted.txt"))) - expect_true(file.exists(file.path(param@path, "feature_definitions.txt"))) - expect_true(file.exists(file.path(param@path, "feature_peak_index.txt"))) -}) diff --git a/tests/testthat/test_XcmsExperiment.R b/tests/testthat/test_XcmsExperiment.R index d538a762..a63bf85f 100644 --- a/tests/testthat/test_XcmsExperiment.R +++ b/tests/testthat/test_XcmsExperiment.R @@ -1413,17 +1413,6 @@ test_that("setAs,XcmsExperiment,xcmsSet works", { expect_equal(peaks(res), chromPeaks(xmseg)) }) -test_that("storeResults,RDataParam works", { - param <- RDataParam(fileName = "test") - param2 <- RDataParam() - expect_false(is.null(param2)) - storeResults(xmse, param = param) - expect_true(file.exists("test")) - load("test") - expect_s4_class(object, "XcmsExperiment") - expect_equal(object, xmse) -}) - test_that("fillChromPeaks,XcmsExperiment works with verboseBetaColumns", { p <- CentWaveParam(noise = 10000, snthresh = 40, prefilter = c(3, 10000), verboseBetaColumns = TRUE)