% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/computeSpikeFactors.R
\name{computeSpikeFactors}
\alias{computeSpikeFactors}
\title{Normalization with spike-in counts}
\usage{
computeSpikeFactors(x, spikes, assay.type = "counts")
}
\arguments{
\item{x}{A \linkS4class{SingleCellExperiment} object containing spike-in transcripts in an \code{\link{altExps}} entry.

Support for spike-in transcripts in the rows of \code{x} itself is deprecated.}

\item{spikes}{String or integer scalar specifying the alternative experiment containing the spike-in transcripts.}

\item{assay.type}{A string indicating which assay contains the counts.}
}
\value{
A modified \code{x} is returned, containing spike-in-derived size factors for all cells in \code{\link{sizeFactors}}.
}
\description{
Compute size factors based on the coverage of spike-in transcripts.
}
\details{
The spike-in size factor for each cell is computed from the sum of all spike-in counts in each cell.
This aims to scale the counts to equalize spike-in coverage between cells,
thus removing differences in coverage due to technical effects like capture or amplification efficiency.

Spike-in normalization can be helpful for preserving changes in total RNA content between cells, if this is of interest.
Such changes would otherwise be lost when normalizing with methods that assume a non-DE majority.
Indeed, spike-in normalization is the only available approach if a majority of genes are DE between two cell types or states.

Size factors are computed by applying \code{\link{librarySizeFactors}} to the spike-in count matrix.
This ensures that the mean of all size factors is unity for standardization purposes,
if one were to compare expression values normalized with sets of size factors (e.g., in \code{\link[scran]{modelGeneVarWithSpikes}}).

Users who want the spike-in size factors without returning a SingleCellExperiment object can simply call
\code{\link{librarySizeFactors}(\link{altExp}(x, spikes))}, which gives the same result.
}
\examples{
library(scuttle)
sce <- mockSCE()
sce <- computeSpikeFactors(sce, "Spikes")
summary(sizeFactors(sce))

}
\references{
Lun ATL, McCarthy DJ and Marioni JC (2016). 
A step-by-step workflow for low-level analysis of single-cell RNA-seq data with Bioconductor.
\emph{F1000Res.} 5:2122
}
\seealso{
\code{\link{altExps}}, for the concept of alternative experiments.

\code{\link{librarySizeFactors}}, for how size factors are derived from library sizes.
}
\author{
Aaron Lun
}
