\name{DeCorrelateChannels} 

\alias{DeCorrelateChannels}
\alias{DeCorrelateChannels,array-method}
\alias{DeCorrelateChannels,SolexaIntensity-method}
\alias{OptimizeAngle}
\alias{OptimizeAngle,SolexaIntensity-method}
\alias{DeCorrelateCycles}
\alias{DeCorrelateCycles}
\alias{DeCorrelateCycles,array-method}
\alias{DeCorrelateCycles,SolexaIntensity-method}
\alias{OptimizeRate}
\alias{OptimizeRate,SolexaIntensity-method}
\alias{TileNormalize}
\alias{TileNormalize,RolexaRun-method}
\title{Correct for global correlations and biases}
\description{Functions to correct for global correlations between color
  channels or between successive sequencing cycles}
\usage{
\S4method{DeCorrelateChannels}{SolexaIntensity}(int,cycles=seq(1,dim(int)[3],by=1),theta=matrix(rep(c(0.8806742,1.3727418,0.883865,1.545728),length(cycles)),ncol=4,byrow=TRUE))
\S4method{DeCorrelateChannels}{array}(int,cycles=seq(1,dim(int)[3],by=1),theta=matrix(rep(c(0.8806742,1.3727418,0.883865,1.545728),length(cycles)),ncol=4,byrow=TRUE))
DeCorrelateChannels(int,...)
\S4method{OptimizeAngle}{SolexaIntensity}(int,cycles=seq(1,dim(int)[3],by=1),...)
OptimizeAngle(int,...)
\S4method{DeCorrelateCycles}{SolexaIntensity}(int,ncycles=dim(int)[3],rate=1.8e-2)
\S4method{DeCorrelateCycles}{array}(int,ncycles=dim(int)[3],rate=1.8e-2)
DeCorrelateCycles(int,...)
\S4method{OptimizeRate}{SolexaIntensity}(int,ncycles=dim(int)[3],...)
OptimizeRate(int,...)
\S4method{TileNormalize}{RolexaRun}(run=Rolexa.env,int,cycles=seq(1,dim(int)[3],by=1))
TileNormalize(run,...)
}
\arguments{
  \item{run}{a \code{\link[=RolexaRun-class]{RolexaRun}} object defining the run parameters}
  \item{int}{a \code{\link[ShortRead:SolexaIntensity-class]{SolexaIntensity}}
    object or an array}
  \item{cycles, ncycles}{the cycles or the number of cycles (starting
    from 1) to apply the correction to}
  \item{theta}{a \code{length(cycles)*4} matrix with four angles per cycle defining the
    coordinate changes}
  \item{rate}{the rate of nucleotide mis-incorporation at each cycle}
  \item{\dots}{additional arguments passed to \code{\link{optim}}}
}
\details{\code{DeCorrelateChannels} applies to coordinate transforms:
  one transforming the axes 1,2 to the axes with angles
  \code{theta[,1:2]} relative to axis 1, and similarly with axes 3,4
  and angles \code{theta[,3:4]}. These angles can be calculated with
  \code{OptimizeAngle} which minimizes the correlations between channel
  1 and 2, and between channel 3 and 4, for each
  cycle. \code{DeCorrelateCycles} assumes that at each cycles, a
  fraction \code{rate} of sequences fail to incorporate any nucleotides
  and therefore the sequence lengths at each colony display a binomial
  distribution which is corrected for by taking into account the
  intensity measured at previous cycles.  \code{OptimizeRate} calculates
  a rate that minimizes correlations between consecutives cycles.

  \code{TileNormalize} estimates the local trend by \code{\link{loess}} fitting
  of the model \code{int ~ x+y} and substracts it from the intensity
  matrix.
}
\value{\code{TileNormalize}, \code{DeCorrelateChannels} and \code{DeCorrelateCycles} return an
  object of the same type as \code{int} corrected for spurious
  correlations. \code{OptimizeAngle} returns an \code{length(cycles)*4}
  matrix and \code{OptimizeRate} returns a single positive real
  number.}
\references{Probabilistic base calling of Solexa sequencing data,
  BMC Bioinformatics 2008, 9:431}
\author{Jacques Rougemont, Arnaud Amzallag, Christian Iseli, Laurent Farinelli, Ioannis Xenarios, Felix Naef}
\seealso{TileNormalize}
\examples{
path = SolexaPath(system.file("extdata", package="ShortRead"))
rolenv = SetModel(idsep="_")
int = readIntensities(path,pattern="s_1_0001",withVariability=FALSE)
%\dontrun{
int1 = DeCorrelateChannels(int=int,cycles=1:5,theta=OptimizeAngle(int=int,cycles=1:5))
int2 = DeCorrelateCycles(int=int1,ncycles=5,rate=OptimizeRate(int=int1))
int3 = TileNormalize(run=rolenv,int=int,cycles=1)
seq = CombineReads(run=rolenv,path=path,pattern="s_1_0001_seq*")
PlotCycles(run=rolenv,int=int3,seq=seq,cycles=1:4)
}
\keyword{multivariate}
\keyword{regression}
\keyword{loess}
%