\Header{spotMerge}{Averaging of spot replicas}
\keyword{utilities}{spotMerge}
\begin{Description}\relax
The mean of replicated spots with identical number of replicas is
calculated for each channel separately
(note: \code{spotMerge} does require an equal number of replicas).
All other spots need to be eliminated with the help of the
argument \code{spotsToBeRemoved}.
The mean is calculated for the expression levels
\code{exprs} of the \code{exprSetRGObject} and for the
\code{intensities} and \code{weights} of the \code{arrayDataObject}.
Any existing \code{se.exprs}-\code{matrix}
as part of \code{exprSetRGObject} is discarded.
The standard deviation of the spot merge operation for the expression
values is returned as \code{se.exprs}.
The corresponding rows of \code{spotAttr} in \code{arrayDataObject}
are concatenated and form a single row of respectively more columns.
\end{Description}
\begin{Usage}
\begin{verbatim}spotMerge(exprSetRGObject, arrayDataObject, spotIdentifier="Name", spotsToBeRemoved=c("Blank"))\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{arrayDataObject}] object of type \code{\Link{arrayData}};
required; default: missing
\item[\code{exprSetRGObject}] object of type \code{\Link{exprSetRG}};
required; default: missing
\item[\code{spotIdentifier}] character string; required; default: "Name" 
\item[\code{spotsToBeRemoved}] vector of character strings,
all spots which match the strings are removed from 
the analysis before merging; required; default: \code{c("Blank")}
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\end{Details}
\begin{Value}
A list containing the "merged" \code{exprSetRGObject} and
\code{arrayDataObject}.
\end{Value}
\begin{Author}\relax
Andreas Buness <a.buness@dkfz.de>
\end{Author}
\begin{SeeAlso}\relax
\code{\Link{processArrayData}},
\code{\Link{slideMerge}},
\code{\Link{exprSetRG-class}},
\code{\Link{arrayData-class}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}

    intensities <- array(data=runif(600),dim=c(100,2,3))
    dimnames(intensities) <- list(NULL, c("green","red"), NULL)
    spotAttr <- data.frame(Name=I(rep(c("x","y","k","l","z"),20)),
                           Zahl=rep(c(1,2,3,4,5),20),
                           Index=c(1:100))
    arrayDataObject <- new("arrayData", intensities=intensities, weights=intensities[,1,],
                           spotAttr=spotAttr, hybAttrList=NULL)
    indGreen=1:3
    indRed=4:6
    channels <- matrix( c(indGreen,indRed), nrow=length(indGreen), byrow=FALSE )
    colnames(channels) <- c("green","red")
    exprMatrix <- matrix(data=1,nrow=100,ncol=6,byrow=FALSE)
    pD <- data.frame(matrix(0,nrow=6,ncol=1))
    exprSetRGObject <- new("exprSetRG", exprs=exprMatrix, se.expr=exprMatrix,
                              phenoData=new("phenoData",
                                pData= pD,varLabels=list(rep("varLabel1",1))),
                              channels=channels)
    resultList <- spotMerge(arrayDataObject=arrayDataObject,exprSetRGObject=exprSetRGObject, spotsToBeRemoved=c("x","z"))
    resultExprSetRG <- resultList[["exprSetRGObject"]]
    stopifnot( dim(exprs(resultExprSetRG))[1] == 3 )
    stopifnot( dim(exprs(resultExprSetRG))[2] == 6 )
    stopifnot(all(exprs(resultExprSetRG) == 1))
    stopifnot((all(se.exprs(resultExprSetRG) == 0)))
    resultArrayData <- resultList[["arrayDataObject"]]
    stopifnot( all(getIntensities(resultArrayData)[,1,] == getWeights(resultArrayData)) )
    nameColumns <- grep("Name", colnames(getSpotAttr(resultArrayData)))
    zahlColumns <- grep("Zahl", colnames(getSpotAttr(resultArrayData)))
    stopifnot( getSpotAttr(resultArrayData)[1,nameColumns] == rep ("y", 20 ) )
    stopifnot( getSpotAttr(resultArrayData)[1,zahlColumns] == rep (2, 20 ) )


    

        \end{ExampleCode}
\end{Examples}

