MSdata-class: Simple MS data object

Description Usage Arguments Value Objects of the class Slots Constructors and alike Accessing data of an MSdata object Data visualizations Data manipulations Author(s) References See Also Examples

Description

The MSdata is a simple object to store intensity values for m/z - retention time tuples from a complete or only a subset of an MS run.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
## S4 method for signature 'MSdata'
as.matrix(x, ...)

## S4 method for signature 'MSdata'
binMz(object, FUN=max, bins=NULL, nbin=NULL,
                         binSize=NULL)

## S4 method for signature 'MSdata'
binMzRtime(object, FUN=max, mzNbin=NULL,
          mzBinSize=NULL, rtNbin=NULL, rtBinSize=NULL)

## S4 method for signature 'MSdata'
binRtime(object, FUN=max, bins=NULL, nbin=NULL,
                            binSize=NULL)

## S4 method for signature 'MSdata'
chromatogram(object, FUN=max, bins=NULL,
                                    nbin=NULL, binSize=NULL, add=FALSE,
                                    main=paste(format(mzrange(object),
                                    2), collapse="-"),
              xlab="Retention time", ylab="Intensity", ...)

## S4 method for signature 'MSdata'
getChromatogram(object, FUN=max, bins=NULL,
                                   nbin=NULL, binSize=NULL, ...)

## S4 method for signature 'MSdata'
getSpectrum(object, FUN=max, bins=NULL,
                               nbin=NULL, binSize=NULL, ...)

## S4 method for signature 'MSdata'
intensity(object)

## S4 replacement method for signature 'MSdata'
intensity(object) <- value

## S4 method for signature 'MSdata'
intrange(object)

## S4 method for signature 'MSdata'
mapMatrix(object)

MSdata(mz, rtime, intensity, mslevel=1)

## S4 method for signature 'xcmsRaw'
msData(object, mzrange=NULL, rtrange=NULL, ...)

## S4 method for signature 'MSdata'
mz(object)

## S4 replacement method for signature 'MSdata'
mz(object) <- value

## S4 method for signature 'MSdata'
mzrange(object)

## S4 method for signature 'MSdata'
plotChromatogram(object, FUN=max, bins=NULL,
                                    nbin=NULL, binSize=NULL, add=FALSE,
                                    main=paste(format(mzrange(object),
                                    2), collapse="-"),
              xlab="Retention time", ylab="Intensity", ...)

## S4 method for signature 'MSdata'
plotSpectrum(object, FUN=max, bins=NULL,
                                nbin=NULL, binSize=NULL, add=FALSE,
                                main=paste(format(rtrange(object),
                                    2), collapse="-"),
              xlab="M/Z", ylab="Intensity", ...)

## S4 method for signature 'MSdata'
rtime(object, return.type="numeric")

## S4 replacement method for signature 'MSdata'
rtime(object) <- value

## S4 method for signature 'MSdata'
rtrange(object)

## S4 method for signature 'MSdata'
subset(x, mzrange=NULL, rtrange=NULL)

Arguments

(in alphabetic order)

add

For plotChromatogram and plotSpectrum: if the plot should be added to an existing plot.

bins

For getChromatogram, getSpectrum, plotChromatogram, plotSpectrum, binMz and binRtime: Numeric vector specifying the bins to bin the retention time. See getChromatogram method description for details on the binning.

binSize

For getChromatogram, getSpectrum, plotChromatogram, plotSpectrum, binMz and binRtime: Numeric (length 1) specifying the bin width/size. See getChromatogram method description for details on the binning.

FUN

For getChromatogram, getSpectrum, plotChromatogram, plotSpectrum, binMz, binMzRtime and binRtime: function that should be used to aggregate intensities within a bin. By default the largest intensity within a bin is selected. See getChromatogram method description for details on the binning.

intensity

A numeric vector specifying the intensity values.

main

For plotChromatogram and plotSpectrum: the title for the plot.

mslevel

For MSdata: the MS level.

mz

A numeric vector specifying the m/z values.

mzNbin

For binMzRtime: numeric (length 1) specifying the number of bins to bin the M/Z range. See also argument bin.

mzBinSize

For binMzRtime: numeric (length 1) specifying the size of the bins along M/Z range. See also argument binSize.

mzrange

For msData and subset: a numeric of length 2 specifying the range of m/z values to be extracted from the object.

nbin

For getChromatogram, getSpectrum, plotChromatogram, plotSpectrum, binMz and binRtime: numeric (length 1) specifying the number of bins in which the retention time range (or M/Z range) should be binned. See getChromatogram method description for details on the binning.

object

For all methods a MSdata object.

return.type

For rtime: either "numeric" or "Rle" to return the retention time as a numeric vector, or as a Rle object.

rtime

A numeric vector specifying the retention time values.

rtNbin

For binMzRtime: numeric (length 1) specifying the number of bins to bin the retention time range. See also argument bin.

rtBinSize

For binMzRtime: numeric (length 1) specifying the size of the bins along retention time range. See also argument binSize.

rtrange

For msData and subset: a numeric of length 2 specifying the retention time range to be extracted from the object.

value

For intensity<-, mz<- and rtime<-, a numeric vector with the intensity, mz or retention time values, respectively.

x

For as.matrix and subset: a MSdata object.

xlab

For plotChromatogram and plotSpectrum: the label for the x-axis.

ylab

For plotChromatogram and plotSpectrum: the label for the y-axis.

...

For plotChromatogram and plotSpectrum: additional graphical properties to be passed to the plot function.

For all other methods: not used.

Value

Refer to the method and function description above for detailed information on the returned result object.

Objects of the class

MSdata objects are created by the constructor function MSdata, or the msData method e.g. to extract data from an xcmsRaw object.

Slots

intensity

An integer vector with the intensities for each m/z - retention time tuple.

intrange

A numeric vector of length 2 representing the range of intensity values.

mslevel

The MS level.

mz

A numeric vector with the m/z values.

mzrange

A numeric vector of length 2 specifying the range of m/z values.

rtime

An Rle object with the retention time values.

rtrange

A numeric vector of length 2 specifying the retention time range.

Constructors and alike

MSdata

Constructor method to create a new MSdata instance.

msData

Extract MS data from an xcmsRaw object and return the values as a MSdata object. Arguments mzrange and rtrange allow to define the data sub-set to be extracted. If not specified, the method will extract the full data.

Accessing data of an MSdata object

as.matrix

Extracts a matrix with column names "rtime", "mz" and "intensity" with all data values of the MSdata object.

getChromatogram

Extracts the chromatogram from the MSdata (i.e. intensities along the retention time dimension). The method returns a numeric matrix with two columns, "rtime" and "intensity", the rows being ordered increasingly by retention time.

Since the MSdata is in principle 3-dimensional (intensities in the m/z - rt space), values have to be aggregated in the m/z dimension. By default the method only aggregates intensities along the m/z dimension with the same retention time value. Specifying either one of bins, nbin and binSize it is in addition possible to bin the retention times into discrete, equal spaced, bins. Thus, all intensities falling into one bin (i.e. retention time within the bin and all intensities along the m/z dimension present in the MSdata) are aggregated using the function FUN, which by default just selects the maximal signal in each bin.

The binning in rt-dimension is performed as follows: if nbins is specified, the range of retention times (rtrange) is split into nbins equal sized bins and all intensities with an retention time within a certain bin are aggregated (including all in m/z dimension; within mzrange). For binSize, the range is split into bins with the width/size binSize. Argument bins allows to define the bins externally and thus ensure an identical binning e.g. across MSdata objects from different samples.

How the aggregation of intensity values along the m/z range (and eventually also for retention times within the same retention time bin) is performed can be specified with the FUN argument. By default, the maximal signal is selected (i.e. FUN=max). For a MSdata object representing a full MS run, this would correspond to a base peak chromatogram (BPC), while using FUN=sum would result in an total ion chromatogram (TIC) [Smith 2014].

getSpectrum Extracts the spectrum from the MSdata (i.e. intensities along the M/Z dimension, usually for a single retention time or a small retention time range). The method returns a numeric matrix with two columns, "mz" and "intensity" with the rows being increasingly ordered by the mz value.

By default, the method aggregates all intensity values along the retention time dimension (available in the MSdata object) for a single M/Zvalue. The argument FUN allows to specify the function that should be used to aggregate intensities. In addition, the arguments bins, nbin and binSize allow to bin M/Z values and thus to aggregate also intensity values of M/Z values falling within a certain bin. See the documentation of the getChromatogram method above for more details.

intensity, intensity<-

Get or set the intensity values of the MSdata object. intensity returns the intensity values.

intrange

Get the intensity value range. Returns a numeric vector of length 2. For an empty MSdata object without data points it returns c(NA, NA).

mapMatrix

Extract the MS data as a two-dimensional matrix, columns being the (discrete) retention time of each measurement, rows its M/Z value. The method returns a sparse matrix from the Matrix package with not-present intentensity values encoded by a 0 (i.e. if for a specific retention time - M/Z tuple no intensity is available/was measured). The sparseness of the data matrix might be reduced by performing first a binning in M/Z, retention time or both dimensions.

The rownames of the matrix represent the M/Z intensities, the column names the retention time values.

mz, mz<-

Get or set the mz values of the MSdata object. mz returns a numeric vector with the mz values.

mzrange

Get the m/z value range of the MSdata object. Returns a numeric vector of 2 or c(NA, NA) if the object is empty.

rtime, rtime<-

Get or set the retention times of the MSdata object. Depending on the return.type argument, the retention time is returned as a numeric vector or as an Rle object.

rtrange

Get the retention time range of the MSdata object. Returns a numeric vector of 2 or c(NA, NA) if the object is empty.

subset

Subset the MSdata object based on the probided ranges in M/Z and/or retention time dimension. The method returns a MSdata object.

Data visualizations

chromatogram

See plotChromatogram below.

plotChromatogram

The method plots the chromatogram of an MSdata object which is internally extracted by the getChromatogram method (refer to the description of that function for the data binning etc.).

plotSpectrum

The method plots the spectrum of an MSdata object which is internally extracted by the getSpectrum method (refer to the description of that function for the data binning etc.).

Data manipulations

binMz

This method cuts the M/Z range of an MSdata object in equal spaced bins and aggregates all intensity values with an M/Z value falling within the bin and the same retention time.

For details on the method arguments and the binning see the help for the getChromatogram method.

The method returns an MSdata object.

binMzRtime

This method performs a binning first in M/Z dimension followed by a retention time binning.

For details on binning see the getChromatogram method.

The method returns a MSdata object with the data binned both on M/Z and retention time dimension.

binRtime

Same as the binMz method, but for binning along the retention time dimension.

The method returns an MSdata object.

Author(s)

Johannes Rainer.

References

Smith R, Mathis AD, Ventura D and Prince JT. (2014) Proteomics, lipidomics, metabolomics: a mess spectrometry tutorial from a computer scientists's point of view. BMC Bioinformatics, 15(Suppl 7):59.

See Also

xcmsRaw, MSslice

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
## Load the faahKO package with the test data for the xcms package.
library(faahKO)
xset <- faahko

## Get the raw data for the first sample.
xraw <- getXcmsRaw(xset, 1)

## Define a data sub-set and extract the corresponding values.
rtr <- c(2600, 2670)
mzr <- c(300, 400)
mssub <- msData(xraw, rtrange=rtr, mzrange=mzr)

## Get the mz value and retention time range
mzrange(mssub)
rtrange(mssub)

## The actual retention time range is different from the specifyed
## range as it depends on the acutally measured scan times.

## Get the intensity range
intrange(mssub)

## Get mz values, retention times and intensities.
head(mz(mssub))
head(rtime(mssub))
head(intensity(mssub))

## Extract a matrix with the full data.
head(as.matrix(mssub))


## Extracting the chromatogram from an MSdata.
## Defining the mz and rt ranges. These correspond approx. to the
## peak in the xcms vignette (Figure 4).
mzr <- c(302, 302.5)
rtr <- c(2500, 2700)
msd <- msData(xraw, rtrange=rtr, mzrange=mzr)

## How many data points do we have?
length(rtime(msd))
## Hom many unique retention times?
length(unique(rtime(msd)))
## Thus, we have some intensities with the same retention time (but different
## m/z).

####-------------
## Extracting the chromatogram.
chr <- getChromatogram(msd)
nrow(chr)
## By default, the method aggregates intensities with identical retention time.

## Plotting the chromatogram
plotChromatogram(msd, type="l")

## Next we extract a chromatogram with binning on the retention time. Thus we
## set to split the retention time range into 50 equal spaced bins and to aggregate
## the intensities within each of the bins. As aggregation function we use "max", i.e.
## we select the maximal intensity for each bin.
chr2 <- getChromatogram(msd, FUN=max, nbin=50)
nrow(chr2)

## Adding that chromatogram to the existing plot.
plotChromatogram(msd, FUN=max, nbin=50, add=TRUE, col="blue", type="b")

## Generating the base peak chromatogram (BPC) and the total ion chromatogram (TIC)
fulld <- msData(xraw)
par(mfrow=c(1, 2))
plotChromatogram(fulld, FUN=max, type="l", main="BPC")
plotChromatogram(fulld, FUN=sum, type="l", main="TIC")


####-------------
## Extract a spectrum.
## Similar to the getChromatogram example above we can simply extract a
## spectrum using the getSpectrum method.
spc <- getSpectrum(msd)
nrow(spc)
## The spectrum for this peak is rather small, which is not surprising, since
## we restricted the m/z range. To get the spectrum for the compound corresponding
## to the peak, we restrict a narrow retention time range around the peak, and a
## larget mz range.
rtr <- c(2560, 2640)
mzr <- c(300, 330)
## Get the "slice" of MS data defined by this ranges
msd <- msData(xraw, mzrange=mzr, rtrange=rtr)

## Get the (unbinned) spectrum; intensities with the same m/z but different
## retention times are aggregated (i.e. the maximal signal is taken).
spc <- getSpectrum(msd)
nrow(spc)

## Next we plot the chromatogram and the spectrum for the MS data slice.
par(mfrow=c(1, 2))
plotChromatogram(msd, type="l")
plotSpectrum(msd, type="l")

## Extract the data as a two-dimensional matrix.
mapM <- mapMatrix(msd)
dim(mapM)
head(mapM)

####-------------
##  Data manipulations

## We process the MSdata object from above and aggregate values falling into
## the same bin on M/Z dimension. We define a binSize of 1, thus, the maximum
## of all signal values with the same retention time falling into the same bin
## will be returned in the resulting MSdata object. Note that this binning is
## rather crude and we should use this only e.g. for plotting purposes, i.e. to
## reduce the data points to plot.
msd

msdBinned <- binMz(msd, binSize=1)
msdBinned

length(unique(mz(msd)))
length(unique(mz(msdBinned)))

## Plot the spectrum and the chromatogram of both.
par(mfrow=c(1, 2))
plotSpectrum(msd, type="l")
plotSpectrum(msdBinned, type="l", add=TRUE, col="blue")
plotChromatogram(msd, type="l")
plotChromatogram(msdBinned, type="l", add=TRUE, col="blue", lty=2)

## The same way we perform the binning in retention time axis.
msdBinned <- binRtime(msd, binSize=5)
length(unique(rtime(msd)))
length(unique(rtime(msdBinned)))

## Plot the spectrum and the chromatogram of both.
par(mfrow=c(1, 2))
plotSpectrum(msd, type="l")
plotSpectrum(msdBinned, type="l", add=TRUE, col="blue", lty=2)
plotChromatogram(msd, type="l")
plotChromatogram(msdBinned, type="l", add=TRUE, col="blue", lty=2)

## Next we bin the data in both dimensions.
binBoth <- binMzRtime(msd, mzNbin=20, rtBinSize=5)
binBoth

jotsetung/xcmsExtensions documentation built on May 19, 2019, 9:42 p.m.