% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/convertPCsToSCE.R
\name{convertPCsToSCE}
\alias{convertPCsToSCE}
\title{Convert corrected PCs to a SingleCellExperiment}
\usage{
convertPCsToSCE(
  corrected.df,
  pc.info,
  assay.name = "reconstructed",
  dimred.name = "corrected"
)
}
\arguments{
\item{corrected.df}{A \linkS4class{DataFrame} containing a nested matrix of low-dimensional \code{corrected} values and a vector of \code{batch} identities.
Typically produced from \code{\link{reducedMNN}}.}

\item{pc.info}{A list containing PCA statistics, in particular a \code{rotation} matrix.
Typically obtained from the \code{\link{metadata}} of the output from \code{\link{multiBatchPCA}}.}

\item{assay.name}{String specifying the name of the assay to use to store the corrected expression values.}

\item{dimred.name}{String containing the name fo the \code{\link{reducedDims}} to store the low-dimensional corrected values.
Set to \code{NULL} to avoid storing these.}
}
\value{
A \linkS4class{SingleCellExperiment} containing a \linkS4class{LowRankMatrix} with the corrected per-gene expression values.
The \code{\link{colData}} contains the batch identities, the \code{\link{rowData}} contains the rotation matrix,
and the \code{\link{reducedDims}} contains the low-dimensional corrected values (if \code{dimred.name} is not \code{NULL}).
All additional metadata from \code{corrected.df} and \code{pc.info} is stored in \code{\link{metadata}}.
}
\description{
Convert low-dimensional corrected PCs to a \linkS4class{SingleCellExperiment} containing corrected expression values.
This is a low-level function and most users should not need to call it.
}
\details{
The corrected expression values are obtained by simply taking the crossproduct of the corrected PCs with the rotation matrix.
This reverses the original projection to PC space while retaining the effect of the correction.
These values are best used for visualization; 
the low-dimensional corrected coordinates are more efficient for per-cell operations like clustering,
while the original uncorrected expression values are safer to interpret for per-gene analyses.
}
\examples{
B1 <- matrix(rnorm(10000), nrow=50) # Batch 1
B2 <- matrix(rnorm(10000), nrow=50) # Batch 2

# Equivalent to fastMNN().
cB1 <- cosineNorm(B1)
cB2 <- cosineNorm(B2)
pcs <- multiBatchPCA(cB1, cB2)
mnn.out <- reducedMNN(pcs[[1]], pcs[[2]])

sce <- convertPCsToSCE(mnn.out, metadata(pcs))
sce

}
\seealso{
\code{\link{reducedMNN}}, to compute \code{corrected.df}; and \code{\link{multiBatchPCA}}, to compute \code{pc.info}.

\code{\link{fastMNN}}, which uses this function to obtain low-rank corrected values.
}
\author{
Aaron Lun
}
