% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/methods-Chromatogram.R,
%   R/methods-Chromatograms.R
\docType{methods}
\name{align,Chromatogram,Chromatogram-method}
\alias{align,Chromatogram,Chromatogram-method}
\alias{align}
\alias{align,Chromatograms,Chromatogram-method}
\title{Aligning chromatographic data}
\usage{
\S4method{align}{Chromatogram,Chromatogram}(x, y,
  method = c("matchRtime", "approx"), ...)

\S4method{align}{Chromatograms,Chromatogram}(x, y,
  method = c("matchRtime", "approx"), ...)
}
\arguments{
\item{x}{\code{\link[=Chromatogram]{Chromatogram()}} or \code{\link[=Chromatograms]{Chromatograms()}} to be aligned against \code{y}.}

\item{y}{\code{\link[=Chromatogram]{Chromatogram()}} to which \code{x} should be aligned to.}

\item{method}{\code{character(1)}}

\item{...}{additional parameters to be passed along to the alignment
functions.}
}
\value{
\code{Chromatogram} (or \code{Chromatograms}) representing \code{x} aligned
against \code{y}.
}
\description{
Align chromatogram \code{x} against chromatogram \code{y}. The resulting chromatogram
has the same length (number of data points) than \code{y} and the same retention
times thus allowing to perform any pair-wise comparisons between the
chromatograms. If \code{x} is a \code{\link[=Chromatograms]{Chromatograms()}} object, each \code{Chromatogram} in
it is aligned against \code{y}.

Parameter \code{method} allows to specify which alignment method
should be used. Currently there are the following options:
\itemize{
\item \code{method = "matchRtime"} (the default): match data points in the first
chromatogram (\code{x}) to those of the second (\code{y}) based on the difference
between their retention times: each data point in \code{x} is assigned to the
data point in \code{y} with the smallest difference in their retention times
if their difference is smaller than the minimum average difference between
retention times in \code{x} or \code{y}.
\item \code{method = "approx"}: uses the base R \code{approx} function to approximate
intensities in \code{x} to the retention times in \code{y} (using linear
interpolation). This should only be used for chromatograms that were
measured in the same measurement run (e.g. MS1 and corresponding MS2
chromatograms from SWATH experiments).
}
}
\examples{

chr1 <- Chromatogram(rtime = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
    intensity = c(3, 5, 14, 30, 24, 6, 2, 1, 1, 0))
chr2 <- Chromatogram(rtime = c(2.5, 3.42, 4.5, 5.43, 6.5),
    intensity = c(5, 12, 15, 11, 5))

plot(chr1, col = "black")
points(rtime(chr2), intensity(chr2), col = "blue", type = "l")

## Align chr2 to chr1 without interpolation
res <- align(chr2, chr1)
rtime(res)
intensity(res)
points(rtime(res), intensity(res), col = "#00ff0080", type = "l")

## Align chr2 to chr1 with interpolation
res <- align(chr2, chr1, method = "approx")
points(rtime(res), intensity(res), col = "#ff000080", type = "l")

legend("topright", col = c("black", "blue", "#00ff0080", "#ff000080"), lty = 1,
    legend = c("chr1", "chr2", "chr2 matchRtime", "chr2 approx"))

}
\author{
Johannes Rainer, Michael Witting
}
