Skip to content

Commit

Permalink
Add parameter groupnames to exportMetaboAnalyst
Browse files Browse the repository at this point in the history
- Add parameter groupnames to exportMetaboAnalyst to allow using m/z and
  retention times as rownames (issue #296).
- Fix bug in `show,XCMSnExp` that would lead to an error if process history is
  empty.
  • Loading branch information
jorainer committed Nov 5, 2018
1 parent de5b90b commit 1ab22f0
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 7 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: xcms
Version: 3.5.0
Date: 2018-10-26
Version: 3.5.1
Date: 2018-11-05
Title: LC/MS and GC/MS Data Analysis
Author: Colin A. Smith <csmith@scripps.edu>,
Ralf Tautenhahn <rtautenh@gmail.com>,
Expand Down
11 changes: 10 additions & 1 deletion R/functions-XCMSnExp.R
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,12 @@ overlappingFeatures <- function(x, expandMz = 0, expandRt = 0, ppm = 0) {
#' @param digits `integer(1)` defining the number of significant digits to be
#' used for numeric. The default `NULL` uses `getOption("digits")`. See
#' [format()] for more information.
#'
#' @param groupnames `logical(1)` whether row names of the resulting matrix
#' should be the feature IDs (`groupnames = FALSE`; default) or IDs that
#' are composed of the m/z and retention time of the features (in the
#' format *M<m/z>T<rt>* (`groupnames = TRUE`). See help of the [groupnames]
#' function for details.
#'
#' @param ... additional parameters to be passed to the [featureValues()]
#' function.
Expand All @@ -1821,7 +1827,8 @@ overlappingFeatures <- function(x, expandMz = 0, expandRt = 0, ppm = 0) {
#'
#' @md
exportMetaboAnalyst <- function(x, file = NULL, label,
value = "into", digits = NULL, ...) {
value = "into", digits = NULL,
groupnames = FALSE, ...) {
if (!is(x, "XCMSnExp"))
stop("'x' is supposed to be an XCMSnExp object")
fv <- featureValues(x, value = value, ...)
Expand All @@ -1831,6 +1838,8 @@ exportMetaboAnalyst <- function(x, file = NULL, label,
if (missing(label))
stop("Please provide the group assignment of the samples with the ",
"'label' parameter")
if (groupnames)
rownames(fv) <- groupnames(x)
if (length(label) == 1) {
if (any(colnames(pData(x)) == label))
label <- as.character(pData(x)[, label])
Expand Down
12 changes: 9 additions & 3 deletions R/methods-XCMSnExp.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ setMethod("show", "XCMSnExp", function(object) {
if (hasChromPeaks(object)) {
cat("Chromatographic peak detection:\n")
ph <- processHistory(object, type = .PROCSTEP.PEAK.DETECTION)
cat(" method:", .param2string(ph[[1]]@param), "\n")
if (length(ph))
cat(" method:", .param2string(ph[[1]]@param), "\n")
else cat(" unknown method.\n")
cat(" ", nrow(chromPeaks(object)), " peaks identified in ",
length(fileNames(object)), " samples.\n", sep = "")
cat(" On average ",
Expand All @@ -30,12 +32,16 @@ setMethod("show", "XCMSnExp", function(object) {
if (hasAdjustedRtime(object)) {
cat("Alignment/retention time adjustment:\n")
ph <- processHistory(object, type = .PROCSTEP.RTIME.CORRECTION)
cat(" method:", .param2string(ph[[1]]@param), "\n")
if (length(ph))
cat(" method:", .param2string(ph[[1]]@param), "\n")
else cat(" unknown method.\n")
}
if (hasFeatures(object)) {
cat("Correspondence:\n")
ph <- processHistory(object, type = .PROCSTEP.PEAK.GROUPING)
cat(" method:", .param2string(ph[[1]]@param), "\n")
if (length(ph))
cat(" method:", .param2string(ph[[1]]@param), "\n")
else cat(" unknown method.\n")
cat(" ", nrow(featureDefinitions(object)), " features identified.\n",
sep = "")
cat(" Median mz range of features: ",
Expand Down
7 changes: 7 additions & 0 deletions inst/NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Changes in version 3.5.1

- Add parameter groupval to exportMetaboAnalyst (issue #296).
- Fix bug in show,XCMSnExp that would throw an error if no process history is
present.


Changes in version 3.3.6

- Add type = "polygon" to highlightChromPeaks allowing to fill the actual
Expand Down
8 changes: 7 additions & 1 deletion man/exportMetaboAnalyst.Rd

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

4 changes: 4 additions & 0 deletions tests/testthat/test_functions-XCMSnExp.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ test_that("exportMetaboAnalyst works", {
res3 <- read.table(fl, sep = ",", row.names = 1, as.is = TRUE)
colnames(res3) <- colnames(res)
expect_equal(as.matrix(res3), res)

res <- exportMetaboAnalyst(xod_xg, label = c("a", "a", "a"),
groupnames = TRUE)
expect_equal(rownames(res), c("Sample", "Label", groupnames(xod_xg)))
})

test_that("chromPeakSpectra works", {
Expand Down

0 comments on commit 1ab22f0

Please sign in to comment.