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
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.
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)
|
(in alphabetic order)
add |
For |
bins |
For |
binSize |
For |
FUN |
For |
intensity |
A numeric vector specifying the intensity values. |
main |
For |
mslevel |
For |
mz |
A numeric vector specifying the m/z values. |
mzNbin |
For |
mzBinSize |
For |
mzrange |
For |
nbin |
For |
object |
For all methods a |
return.type |
For |
rtime |
A numeric vector specifying the retention time values. |
rtNbin |
For |
rtBinSize |
For |
rtrange |
For |
value |
For |
x |
For |
xlab |
For |
ylab |
For |
... |
For For all other methods: not used. |
Refer to the method and function description above for detailed information on the returned result object.
MSdata
objects are created by the constructor function
MSdata
, or the msData
method e.g. to extract data from
an xcmsRaw
object.
An integer vector with the intensities for each m/z - retention time tuple.
A numeric vector of length 2 representing the range of intensity values.
The MS level.
A numeric vector with the m/z values.
A numeric vector of length 2 specifying the range of m/z values.
An Rle
object with the retention time values.
A numeric vector of length 2 specifying the retention time range.
Constructor method to create a new MSdata
instance.
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.
MSdata
objectExtracts a matrix with column names "rtime"
, "mz"
and
"intensity"
with all data values of the MSdata
object.
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.
Get or set the intensity values of the MSdata
object. intensity
returns the intensity values.
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)
.
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.
Get or set the mz values of the MSdata
object. mz
returns a numeric vector with the mz values.
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.
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.
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 the MSdata
object based on the probided ranges in
M/Z and/or retention time dimension. The method returns a
MSdata
object.
See plotChromatogram
below.
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.).
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.).
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.
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.
Same as the binMz
method, but for binning along the
retention time dimension.
The method returns an MSdata
object.
Johannes Rainer.
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.
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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.