Learn R Programming

MALDIquant (version 1.4)

determineWarpingFunctions: Determine warping functions of MassPeaks objects.

Description

This function determines a warping function for a list of AbstractMassObject objects (warping is also known as phase correction/spectra alignment).

Usage

determineWarpingFunctions(l, reference, tolerance=0.002,
                          warpingFunction=.warpingFunctionLowess,
                          plot=FALSE, plotInteractive=FALSE, ...)

Arguments

l
list, list of MassPeaks objects.
reference
MassPeaks, reference object to which the samples (l) should be aligned. If missing referencePeaks is used.
tolerance
double, maximal deviation of a peak position (mass) to be considered as identical.
warpingFunction
function, general warping function which is used to align sample and reference MassPeaks objects.
plot
logical, if TRUE a warping plot is drawn for each sample.
plotInteractive
logical, if FALSE a non-interactive device (e.g. pdf) is used for warping plots.
...
arguments to be passed to warpingFunction

Value

  • Returns a list of individual warping functions.

code

x

cr

## e.g. warping function to fit a 2nd order polynomial quadraticWarp <- function(x, d, ...) { l <- lm(y ~ x1+x2, data=list(x1=x, x2=x*x, y=d), ...); co <- coef(l); return(function(x) { return (co[1]+x*co[2]+x*x*co[3]) }); } plotInteractive: If plot is TRUE a lot of output is created (each sample in l gets its own plot). That's why an non-interactive devices is recommended: ## create a device pdf() ## calculate warping functions w <- determineWarpingFunctions(p, plot=TRUE) ## close device dev.off();

Details

warpingFunction: determineWarpingFunctions estimates a warping function to overcome the difference between mass in reference and in the current sample. To calculate the differences each reference peak would match with the highest sample peak in the nearer neighborhood (defined by mass of reference peak*tolerance). MALDIquant uses a lowess-based warping function as default one. It could easily replaced by an own warping function. At least three arguments are needed:
  • x:double, the original (not warped) mass of the sampleMassPeaksobject.
d: double, the difference of the sample and the reference mass. ...: further arguments (e.g. iter for lowess)

References

See website: http://strimmerlab.org/software/maldiquant/

See Also

referencePeaks, warpMassPeaks, warpMassSpectra, MassPeaks

Examples

Run this code
## load library
library("MALDIquant");

## create a reference MassPeaks object
r <- createMassPeaks(mass=1:5, intensity=1:5);

## create test samples
p <- list(createMassPeaks(mass=((1:5)*1.01), intensity=1:5),
          createMassPeaks(mass=((1:5)*0.99), intensity=1:5));

## create a simple (in other cases useless ) warping function 
simpleWarp <- function(x, d, ...) { return(function(x){return(d)}); }

## create an interactive device with 2 rows
par(mfrow=c(2, 1));
## calculate warping function (using simpleWarp as basic warping function)
## and show warping plot
w <- determineWarpingFunctions(p, tolerance=0.02, warpingFunction=simpleWarp,
                               plot=TRUE, plotInteractive=TRUE);
par(mfrow=c(1, 1));

## w contains the individual warping functions
warpedPeaks <- warpMassPeaks(p, w);

## compare results
all(mass(r) == mass(warpedPeaks[[1]])); # TRUE
all(mass(r) == mass(warpedPeaks[[2]])); # TRUE



## realistic example

## load example data
data("fiedler2009subset", package="MALDIquant");

## running typical workflow

## transform intensities
t<- transformIntensity(fiedler2009subset, fun=sqrt);

## smoothing function
movingAvg <- function(y) {
    return(filter(y, rep(1, 5)/5, sides=2));
}

## smooth spectra
s <- transformIntensity(t, fun=movingAvg);

## baseline correction
b <- removeBaseline(s);

## detect peaks
peaks <- detectPeaks(b);

## create an interactive device with 2 rows
par(mfrow=c(2, 1));
## calculate warping functions (using lowess based basic function [default])
w <- determineWarpingFunctions(peaks, plot=TRUE, plotInteractive=TRUE);
par(mfrow=c(1, 1));

Run the code above in your browser using DataLab