Skip to content

Commit

Permalink
Add clean,Chromatograms (issue #354)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorainer committed Nov 7, 2018
1 parent 24a14f0 commit 9ea2c4a
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 63 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: MSnbase
Title: Base Functions and Classes for Mass Spectrometry and Proteomics
Version: 2.9.0
Version: 2.9.1
Description: MSnbase provides infrastructure for manipulation,
processing and visualisation of mass spectrometry and
proteomics data, ranging from raw to quantitative and
Expand Down
7 changes: 6 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# MSnbase 2.9

Changes in version 2.9.1
- Add clean,Chromatograms (issue #354) <2018-11-07 Wed>
- Add as,Spectra,list as,Spectra,MSnExp and as,MSnExp,Spectra (issue #370)
<2018-11-07 Wed>

Changes in version 2.9.0
- New version for Bioc 3.9 devel

Expand All @@ -20,7 +25,7 @@ Changes in version 2.7.12


Changes in version 2.7.11
- Change default for `timeDomain` in `combineSpectra` and
- Change default for `timeDomain` in `combineSpectra` and
`combineSpectraMovingWindow` to `FALSE` <2018-10-18 Thu>
- Add new spectra combination function `consensusSpectrum`
<2018-10-24 Wed>
Expand Down
8 changes: 7 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# MSnbase 2.9

## Changes in version 2.9.1
- Add clean,Chromatograms (issue
[#354](https://github.com/lgatto/MSnbase/issues/354)) <2018-11-07 Wed>
- Add as,Spectra,list as,Spectra,MSnExp and as,MSnExp,Spectra
(issue [#370](https://github.com/lgatto/MSnbase/issues/370)) <2018-11-07 Wed>

## Changes in version 2.9.0
- New version for Bioc 3.9 devel

Expand All @@ -20,7 +26,7 @@


## Changes in version 2.7.11
- Change default for `timeDomain` in `combineSpectra` and
- Change default for `timeDomain` in `combineSpectra` and
`combineSpectraMovingWindow` to `FALSE` <2018-10-18 Thu>
- Add new spectra combination function `consensusSpectrum`
<2018-10-24 Wed>
Expand Down
9 changes: 4 additions & 5 deletions R/functions-Chromatograms.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
#'
#' @param featureData either a \code{data.frame} or \code{AnnotatedDataFrame}
#' with additional information for each row of chromatograms.
#'
#'
#' @param ... Additional parameters to be passed to the
#' \code{\link[base]{matrix}} constructor, such as \code{nrow}, \code{ncol}
#' and \code{byrow}.
#'
#'
#' @rdname Chromatograms-class
Chromatograms <- function(data, phenoData, featureData, ...) {
if (missing(data))
Expand Down Expand Up @@ -112,7 +112,7 @@ Chromatograms <- function(data, phenoData, featureData, ...) {
## to the number of data points that were actually measured.
lens <- lengths(x)
maxLens <- max(lens)

ints <- rts <- matrix(NA_real_, nrow = maxLens, ncol = length(x))
for (i in seq(along = x)) {
if (lens[i]) {
Expand Down Expand Up @@ -180,7 +180,7 @@ Chromatograms <- function(data, phenoData, featureData, ...) {
#' `Chromatogram` objects in each row.
#'
#' @author Johannes Rainer
#'
#'
#' @noRd
.bin_Chromatograms <- function(object, binSize = 0.5, breaks = numeric(),
fun = max) {
Expand All @@ -196,4 +196,3 @@ Chromatograms <- function(data, phenoData, featureData, ...) {
if (validObject(object))
object
}

39 changes: 31 additions & 8 deletions R/methods-Chromatograms.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ setMethod("show", "Chromatograms", function(object) {
}
rn <- rownames(out)
out <- rbind(rep("<Chromatogram>", ncol(out)), out)
rownames(out) <- c("", rn)
rownames(out) <- c("", rn)
print(out, quote = FALSE, right = TRUE)
}
cat("phenoData with", length(varLabels(object@phenoData)), "variables\n")
Expand All @@ -55,9 +55,9 @@ setAs("matrix", "Chromatograms", function(from) {
#' object (with the exception of extracting a single element)
#' unless \code{drop = TRUE} is specified. This is different from the
#' default subsetting behaviour of \code{matrix}-like objects.
#'
#'
#' @param x For all methods: a \code{Chromatograms} object.
#'
#'
#' @param i For \code{[}: \code{numeric}, \code{logical} or \code{character}
#' defining which row(s) to extract.
#'
Expand Down Expand Up @@ -123,7 +123,7 @@ setMethod("[", "Chromatograms",
#' @param value For \code{[<-}: the replacement object(s). Can be a \code{list}
#' of \code{\link{Chromatogram}} objects or, if length of \code{i} and
#' \code{j} are 1, a single \code{\link{Chromatogram}} object.
#'
#'
#' For \code{pData<-}: a \code{data.frame} with the number of rows matching
#' the number of columns of \code{object}.
#'
Expand Down Expand Up @@ -163,7 +163,7 @@ setReplaceMethod("[", "Chromatograms",
})

#' @rdname Chromatograms-class
#'
#'
#' @description \code{plot}: plots a \code{Chromatograms} object. For each row
#' in the object one plot is created, i.e. all \code{\link{Chromatogram}}
#' objects in the same row are added to the same plot.
Expand All @@ -182,11 +182,11 @@ setReplaceMethod("[", "Chromatograms",
#' @param type For \code{plot}: the type of plot (see
#' \code{\link[graphics]{plot}} for more details. Can be either a vector
#' of length 1 or of length equal to \code{ncol(x)}.
#'
#'
#' @inheritParams Chromatogram-class
#'
#' @examples
#'
#'
#' ## Create some random Chromatogram objects
#' ints <- abs(rnorm(123, mean = 200, sd = 32))
#' ch1 <- Chromatogram(rtime = seq_along(ints), intensity = ints, mz = 231)
Expand Down Expand Up @@ -312,7 +312,7 @@ setMethod("isEmpty", "Chromatograms", function(x) {
})

#' @rdname Chromatograms-class
#'
#'
#' @description \code{featureNames}: returns the feature names of the
#' \code{Chromatograms} object.
setMethod("featureNames", "Chromatograms", function(object)
Expand Down Expand Up @@ -463,3 +463,26 @@ setMethod("polarity", "Chromatograms", function(object) {
#'
#' @rdname Chromatograms-class
setMethod("bin", "Chromatograms", .bin_Chromatograms)

#' @description
#'
#' \code{clean}: removes 0-intensity data points. Either all of them
#' (with \code{all = TRUE}) or all except those adjacent to non-zero
#' intensities (\code{all = FALSE}; default). See \code{\link{clean}}
#' documentation for more details and examples.
#'
#' @param all for \code{clean}: \code{logical(1)} whether all 0 intensities
#' should be removed (\code{all = TRUE}), or whether 0-intensities
#' adjacent to peaks should be kept (\code{all = FALSE}; default).
#'
#' @param na.rm for \code{clean}: \code{logical(1)} whether all \code{NA}
#' intensities should be removed prior to clean 0 intensity data points.
#'
#' @rdname Chromatograms-class
setMethod("clean", "Chromatograms", function(object, all = FALSE,
na.rm = FALSE) {
object@.Data <- matrix(lapply(object, clean, all = all, na.rm = na.rm),
nrow = nrow(object), dimnames = dimnames(object))
if (validObject(object))
object
})
Loading

0 comments on commit 9ea2c4a

Please sign in to comment.