Learn R Programming

Cardinal (version 1.4.0)

pixels-methods: Retrieve Pixel or Feature Indices Based on Metadata

Description

These are generic functions to retrieve pixel or feature row indices in an iSet-derived object's pixelData or featureData slots based on metadata variables.

Usage

"pixels"(object, ...)
"features"(object, ...)
"pixels"(object, ..., coord)
"features"(object, ..., mz)

Arguments

object
An imaging dataset object.
...
Variables that appear in pixelData(object) or featureData(object).
mz
A vector of m/z values.
coord
A list or data.frame of named pixel coordinates.

Value

A numeric vector of pixel or feature indices.

Details

It is often more convenient to specify a pixel or feature by identifying metadata such as pixel coordinates or m/z-values than by their row indices in the pixelData and featureData slots. However, many functions expect indices rather than coordinates or m/z-values. These generic functions make it easy to retrieve indices based on such metadata.

It is important to note that when passing multiple variables via ..., the 'AND' operator is used to resolve the query. However, when vectors are passed, all combinations of the given values will be used.

For convenience, MSImageSet uses a special implementation for the 'mz' variable, which uses a bisection search so that exact precision is not required when searching based on m/z-values.

See Also

PLS, OPLS, spatialShrunkenCentroids

Examples

Run this code
## Create an MSImageSet object
spectra <- matrix(1:27, nrow=3)
mz <- 101:103
coord <- expand.grid(x=1:3, y=1:3)
msset <- MSImageSet(spectra=spectra, mz=mz, coord=coord)

# Find pixel indices
pixels(msset, x=2, y=2)
pixels(msset, coord=list(x=2, y=2))
pixels(msset, coord=list(x=c(2,3), y=c(2,3)))

# Find feature indices
features(msset, mz=102)
features(msset, mz=c(101,103))
features(msset, mz=c(102.2))

Run the code above in your browser using DataLab