R: Function to estimate the approximate local minima and maxima...
mcaPeaks
R Documentation
Function to estimate the approximate local minima and maxima of melting
curve data.
Description
The mcaPeaks() is used to estimate the approximate local minima and
maxima of melting curve data. This can be useful to define a temperature
range for melting curve analysis, quality control of the melting curve or to
define a threshold of peak heights. Melting curves may consist of multiple
significant and insignificant melting peaks. mcaPeaks() uses
estimated the temperatures and fluorescence values of the local minima and
maxima. The original data remain unchanged and only the approximate local
minima and maxima are returned. mcaPeaks() takes modified code
proposed earlier by Brian Ripley
(https://stat.ethz.ch/pipermail/r-help/2002-May/021934.html).
Usage
mcaPeaks(x, y, span = 3)
Arguments
x
x is the column of a data frame for the temperature.
y
y is the column of a data frame for the fluorescence values.
span
span is used to adjust the window span.
Value
p.min
returns a data.frame with the temperatures ("T
(minima)") and the fluorescence ("F (minima)") for the local minima of the
processed data.
p.max
returns a data.frame with the temperatures ("T
(minima)") and the fluorescence ("F (minima)") for the local maxima of the
processed data.
Author(s)
Stefan Roediger
See Also
mcaSmoother, smooth.spline
Examples
# First Example
data(DMP)
# Smooth and Min-Max normalize melting curve data with mcaSmoother()
tmp <- mcaSmoother(DMP[, 1], DMP[,6], minmax = TRUE, n = 2)
# Extract the first derivative melting curve data
tmp.d <- diffQ(tmp, verbose = TRUE)$xy
# Determine the approximate local minima and maxima of a curve
peak.val <-mcaPeaks(tmp.d[, 1], tmp.d[, 2])
peak.val
# Plot the first derivative melting curve
# Add a horizontal line and points for the approximate local minima
# and maxima to the plot
plot(tmp.d, type = "l",
main = "Show the approximate local minima and maxima of a curve")
abline(h = 0)
points(peak.val$p.min, col = 1, pch = 19)
points(peak.val$p.max, col = 2, pch = 19)
legend(25, 0.08, c("Minima", "Maxima"), col = c(1,2), pch = c(19,19))
# Second example
# Signifcant peaks can be distinguished by peak hight
plot(tmp.d, type = "l",
main = "Show the approximate local minima and maxima of a curve")
abline(h = 0)
points(peak.val$p.min, col = 1, pch = 19)
points(peak.val$p.max, col = 2, pch = 19)
legend(25, 0.08, c("Minima", "Maxima"), col = c(1,2), pch = c(19,19))
# Test which local maxima peak is above the median + 3 * Median Absolute
# Add a threshold (th) line to the plot
th.max <- median(peak.val$p.max[, 2]) + 3 * mad(peak.val$p.max[, 2])
abline(h = th.max, col = 3)
# add the approximate temperatures of the local minima and
# maxima to the plot
T.val <- c(peak.val$p.min[, 1], peak.val$p.max[, 1])
text(T.val, rep(-0.05, length(T.val)), round(T.val,0))
# Use a temperature range from the plot to calculate the Tm of
# the maximum Trange is used between 37 and 74 degree Celsius
tmp <- mcaSmoother(DMP[, 1], DMP[, 6], minmax = TRUE, Trange = c(37,74),
n = 2)
# Tm 48.23, fluoTm 0.137
diffQ(tmp, fct = max, plot = TRUE)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(MBmca)
Loading required package: robustbase
Loading required package: chipPCR
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/MBmca/mcaPeaks.Rd_%03d_medium.png", width=480, height=480)
> ### Name: mcaPeaks
> ### Title: Function to estimate the approximate local minima and maxima of
> ### melting curve data.
> ### Aliases: mcaPeaks
> ### Keywords: peaks smooth
>
> ### ** Examples
>
> # First Example
> data(DMP)
> # Smooth and Min-Max normalize melting curve data with mcaSmoother()
> tmp <- mcaSmoother(DMP[, 1], DMP[,6], minmax = TRUE, n = 2)
>
> # Extract the first derivative melting curve data
> tmp.d <- diffQ(tmp, verbose = TRUE)$xy
>
> # Determine the approximate local minima and maxima of a curve
> peak.val <-mcaPeaks(tmp.d[, 1], tmp.d[, 2])
> peak.val
$p.min
T (minima) F (minima)
1 28.94040 -0.011610998
2 37.38411 -0.013745315
3 74.63576 -0.102263937
4 88.54305 0.002692206
5 93.50993 0.020221280
$p.max
T (maxima) F (maxima)
1 23.47682 0.00629218
2 32.41722 0.00930521
3 48.31126 0.12742407
4 86.05960 0.01137595
5 91.52318 0.02360325
>
> # Plot the first derivative melting curve
> # Add a horizontal line and points for the approximate local minima
> # and maxima to the plot
> plot(tmp.d, type = "l",
+ main = "Show the approximate local minima and maxima of a curve")
> abline(h = 0)
> points(peak.val$p.min, col = 1, pch = 19)
> points(peak.val$p.max, col = 2, pch = 19)
> legend(25, 0.08, c("Minima", "Maxima"), col = c(1,2), pch = c(19,19))
>
> # Second example
> # Signifcant peaks can be distinguished by peak hight
> plot(tmp.d, type = "l",
+ main = "Show the approximate local minima and maxima of a curve")
> abline(h = 0)
> points(peak.val$p.min, col = 1, pch = 19)
> points(peak.val$p.max, col = 2, pch = 19)
> legend(25, 0.08, c("Minima", "Maxima"), col = c(1,2), pch = c(19,19))
>
> # Test which local maxima peak is above the median + 3 * Median Absolute
> # Add a threshold (th) line to the plot
> th.max <- median(peak.val$p.max[, 2]) + 3 * mad(peak.val$p.max[, 2])
> abline(h = th.max, col = 3)
>
> # add the approximate temperatures of the local minima and
> # maxima to the plot
> T.val <- c(peak.val$p.min[, 1], peak.val$p.max[, 1])
> text(T.val, rep(-0.05, length(T.val)), round(T.val,0))
>
> # Use a temperature range from the plot to calculate the Tm of
> # the maximum Trange is used between 37 and 74 degree Celsius
>
> tmp <- mcaSmoother(DMP[, 1], DMP[, 6], minmax = TRUE, Trange = c(37,74),
+ n = 2)
> # Tm 48.23, fluoTm 0.137
> diffQ(tmp, fct = max, plot = TRUE)
Calculated Tm: 48.22581
Signal height at calculated Tm: 0.1372889
>
>
>
>
>
> dev.off()
null device
1
>