MSslice-class: MS data subsets of several samples

Description Usage Arguments Value Objects of the class Slots Extends Constructors and alike Accessing and subsetting Data visualizations Data manipulations Author(s) See Also Examples

Description

Sub-sets of an MS run across several samples can be stored in a MSslice object. Such a slice of the MS data is defined by an m/z and a retention time range in each sample. The actual data of the slice in each sample is stored as MSdata object, i.e. as intensities for each mz/rt tuple measured in a sample. Depending on the measurements, the actual mz/rt ranges in each individual MSdata can be slightly different, but all are within the mz and rt range of the MSslice object (that can be returned by the mzrange and rtrange method).

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
82
83
84
85
86
## S4 method for signature 'MSslice'
assayData(object)

## S4 replacement method for signature 'MSslice'
assayData(object) <- value

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

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

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

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

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

## S4 method for signature 'MSslice'
length(x)

MSslice(x, ...)

## S4 method for signature 'MSslice'
msData(object, ...)

## S4 method for signature 'list'
msSlice(object, ...)

## S4 method for signature 'MSdata'
msSlice(object, ...)

## S4 method for signature 'xcmsSet'
msSlice(object, mzrange=NULL, rtrange=NULL,
                            rt="corrected", BPPARAM=MulticoreParam())

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

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

## S4 method for signature 'MSslice'
names(x)

## S4 replacement method for signature 'MSslice'
names(x) <- value

## S4 method for signature 'MSslice'
phenoData(object)

## S4 replacement method for signature 'MSslice'
phenoData(object) <- value

## S4 method for signature 'MSslice'
pData(object)

## S4 replacement method for signature 'MSslice'
pData(object) <- value

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

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

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

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

Arguments

(in alphabetic order)

bins

For getChromatogram, getSpectrum, plotChromatogram, plotSpectrum, binMz and binRtime: numeric vector specifying the bins to bin the retention time. See getChromatogram method description for MSdata objects for more 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 MSdata objects for more 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 MSdata objects for more details on the binning.

BPPARAM

Parallel processing parameters; see bpparam for more information. Note that parallel processing will most likely not work with the snow, thus, on Windows machines there will no parallel processing be available.

col

For plotChromatogram and plotSpectrum: a single color or vector specifying colors for each sample/MSdata object in the MSslice.

lty

For plotChromatogram and plotSpectrum: a numeric specifying the line type for each sample/MSdata object in the MSslice; if lty has length of 1, this line type will be used for all lines.

main

For plotChromatogram and plotSpectrum: the title of the plot.

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

A numeric vector defining the m/z-value range of the slice.

nbin

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

object

For msSlice: either a list of MSdata objects, an xcmsSet or xcmsRaw object.

For all other methods a MSslice object.

rt

For msSlice: either "raw" or "corrected" to specify whether the raw or retention-time corrected scan times should be used.

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

A numeric vector defining the retention time range of the slice.

value

For names: a character vector (length matching the number of MSdata objects in the @assayData slot) specifying names of the individual objects.

For assayData: a MSdata object or a list of such objects.

For phenoData: a data.frame or AnnotatedDataFrame providing the phenotypic annotation of the samples (covariates etc).

For pData: a data.frame providing the phenotypic annotation of the samples.

x

For length, names and subset: an MSslice object.

For MSslice: a MSdata or a list of MSdata objects.

xlab

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

ylab

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

...

For MSslice: additional arguments passed to the constructor (i.e. experimentData or phenoData).

For plotChromatogram: additional graphical parameters to be passed down to the base plot function.

Ignored for all other methods.

Value

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

Objects of the class

While MSslice objects can be created by the constructor function MSslice the default way to create such an object is by using the msSlice method on an xcmsSet (or xcmsRaw) object.

Slots

assayData

A list of MSdata objects.

experimentData

Object of class MIAPE containing details of experimental methods.

mzrange

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

phenoData

An AnnoatedDataFrame providing the sample description.

rtrange

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

Extends

Class "Versioned" defined in the Biobase package, directly.

Constructors and alike

MSslice

Constructor method to create a new MSslice instance accepting either a list of MSdata objects or a single MSdata object. All additional arguments (e.g. phenoData, experimentData) are directly passed to the "new" call.

msSlice

Extract an msSlice object from an xcmsRaw or xcmsSet object. The latter (i.e. extraction from an xcmsSet object) is the default constructor that will be mostly used. It allows to extract intensity values for the m/z and rt range that defines the slice of MS data from each individual sample. The result is returned as an MSslice object. If multiple mz and rt ranges are specified (i.e. arguments mzrange and rtrange are 2-column matrices, each row specifying a different range) the result will be returned as an MSsliceList object.

Note that the mzrange and rtrange of each of the extracted MSdata for each sample will be slightly different, but all are within the mzrange and rtrange of the MSslice object.

If object is an MSdata object it wraps that into an MSslice object.

Accessing and subsetting

assayData,assayData<-

Get and set the assay data (i.e. the list of internal MSdata objects). This method is the same than the msData method.

getChromatogram

Extracts a numeric matrix with the chromatogram (i.e. intensities along the retention time dimension) for each of the MSdata object and hence samples of the MSslice object. The rownames of the matrix represent the (unique) retention times and each column contains the spectrum of one sample/MSdata object (i.e. the intensities aggregated in m/z direction for the respective retention time using the aggregation function specified with argument FUN).

In the default settings, without specifying any of the arguments bins, nbin or binSize, the method returns a matrix with one row for each unique retention time across all of the samples. Each row will only contain a numeric value for a sample in which a signal was measured for that specific retention time. In most instances it will be better to specify nbin or binSize, to bin values also along the retention time dimension. Ideally, the binning should not be too coarse, but also not too detailed (in which case the matrix will again be relatively sparse); a binning with a binSize=1 (i.e. one second), or slightly smaller, might be OK in most instances.

For more details on the binning see the help for the getChromatogram method of MSdata objects.

getSpectrum

Extracts a numeric matrix with the spectrum (i.e. intensities along the M/Z dimension) for each of the MSdata objects and hence samples of the MSslice object. The rownames of the matrix represent the distinct M/Z values and columns the individual samples. For more details (e.g. also on binning etc) see the help of the getChromatogram method above.

intrange

Get the range of intensity values of the slice. This represents the range of values across all samples (i.e. all MSdata objects within the MSslice). Returns a numeric of length 2, or c(NA, NA) if the object is empty (or the internal MSdata object(s) don't contain any data).

length

Get the length of the object, i.e. the number of MSdata object stored within the object.

msData

Get the list of MSdata objects.

mzrange

Get the m/z value range of the slice. This represents the range of values across all samples (i.e. all MSdata objects within the MSslice). Returns a numeric of length 2, or c(NA, NA) if the object is empty (or the internal MSdata object(s) don't contain any data).

names,names<-

Get and set the names of the MSdata objects.

object[i]

Subsets the MSslice object object and returns an MSslice object with only the elements selected by i. i can be an integer vector or a character vector, if names are available in object.

object[[i]]

Extract e single MSdata object from the MSslice object.

phenoData,phenoData<-,pData,pData<-

Get and set the pheno data, i.e. the AnnotatedDataFrame providing the sample annotation (phenotypic information and covariates). Each row describing one sample each column representing one covariate. The ordering is assumed to be identical to the ordering of the MSdata objects in the assayData slot.

The pData method accesses the same slot, but returns (and accepts) a data.frame.

rtrange

Get the retention time range of the slice. This represents the range of values across all samples (i.e. all MSdata objects within the MSslice). Returns a numeric of length 2, or c(NA, NA) if the object is empty (or the internal MSdata object(s) don't contain any data).

subset

Subset the MSslice based on the specified M/Z and retention time ranges. The method returns a MSslice object.

Data visualizations

plotChromatogram

Plots the chromatogram of the rt-m/z slice across all of the MSdata objects (i.e. samples). The arguments col and lty can be used to use a different color for each line (i.e. sample) or a different line type. See description of the getChromatogram for details on the other parameters.

plotSpectrum

Plots the spectrum; see help of plotChromatogram above.

Data manipulations

binMz

This method cuts the M/Z range of an MSslice 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 MSslice 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 MSslice 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 MSslice object.

Author(s)

Johannes Rainer.

See Also

xcmsSet, xcmsRaw, MSdata, MSsliceList

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
## Load the faahKO package with the test data for the xcms package.
library(faahKO)
xset <- faahko

## Define a data sub-set and extract the corresponding values from
## the xcmsSet object. This will extract the intensity values of the
## defined slice from each individual sample.
rtr <- c(2600, 2670)
mzr <- c(300, 400)
mss <- msSlice(xset, rtrange=rtr, mzrange=mzr)

## Access the phenoData
phenoData(mss)

## Access individual columns using the $ method
mss$class

## Get the number of samples
length(mss)

## We don't have any names yet
names(mss)
## Setting the names using the ones provided by the sampnames method of the
## xcmsSet object.
names(mss) <- sampnames(xset)
names(mss)

## Subset to samples with name starting with wt
mssSub <- mss[grep(names(mss), pattern="^wt")]
names(mssSub)

## Extract a single MSdata object
mssSub[["wt18"]]

## Get the mz, rt and intensity range. This corresponds to the range of
## values of the slice across all samples.
mzrange(mss)
rtrange(mss)
intrange(mss)

## Extract the list of MSdata objects
msData(mss)

## Extract the chromatogram of a m/z-rt slice across all samples.
## Defining the mz and rt ranges for the peak in the xcms
## vignette (Figure 4).
mzr <- c(302, 302.5)
rtr <- c(2500, 2700)
mss <- msSlice(xset, rtrange=rtr, mzrange=mzr)

## We're getting a sparse matrix if we're not binning along the rt-dimension,
## since the retention times of the individual data points are slightly different
## between the samples:
head(getChromatogram(mss))

## We're next binning the values in retention time-bins of size 1 (1 second). By default
## (with FUN=max), the maximal signal is used for each bin.
chrM <- getChromatogram(mss, binSize=1)
dim(chrM)
head(chrM)

## We can also create an image from this matrix. Each column represents the chromatogram
## from one sample, each row one retention time bin with the intensity being color coded.
image(t(chrM))

## Next we plot the chromatogram of the slice across all samples.
## Without any binning:
plotChromatogram(mss, col="#00000080", type="l")

## And with binning.
plotChromatogram(mss, binSize=1, col="#00000080", type="l")

## Extracting the full MS data from the xcmsSet to create base peak chromatogram (BPC)
## and total ion chromatogram (TIC) plot of all samples.
msFull <- msSlice(xset)

## Base peak chromatogram with 1 second binning
plotChromatogram(msFull, binSize=1, col="#00000080", type="l")

## Total ion chromatogram with 1 second binning
plotChromatogram(msFull, FUN=sum, binSize=1, col="#00000080", type="l")

## Extending the M/Z range of the slice and extracting and plotting also the spectrum.
mzr <- c(300, 303)
mss <- msSlice(xset, rtrange=rtr, mzrange=mzr)

## Get the spectrum without binning:
head(getSpectrum(mss))

## We can also extract a slice from an xcmsRaw object, which will then
## contain the data only of that individual sample. Without specifying an
## mzrange and rtrange we extract the full data.
msSlice(getXcmsRaw(xset, 1))

par(mfrow=c(1, 2))
plotChromatogram(mss, binSize=1, col="#00000080", type="l")
plotSpectrum(mss, col="#00000040", type="h")

## Or from an MSdata object; extracting first a MSdata object containing
## the *full* MS data from a single file and creating then an MSslice object
## from that.
msd <- msData(getXcmsRaw(xset, 1))
msSlice(msd)

## Extracting the MSdata from the second sample and passing both to the
## MSslice constructor to generate a two-sample MSslice object.
msd2 <- msData(getXcmsRaw(xset, 2))
MSslice(list(msd, msd2))


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

## We bin the MSslice object in 5 second retention time bins along the
## retention time dimension. Each MSdata object within the MSslice is
## binned in the same bins.
mssB <- binRtime(mss, binSize=5)
mss
mssB

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