% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/calculateNormFactors.R
\name{nfLogMedianOfRatios,matrix-method}
\alias{nfLogMedianOfRatios,matrix-method}
\alias{nfLogMedianOfRatios}
\alias{nfLogMedianOfRatios,SummarizedExperiment-method}
\alias{nfLogMedianOfRatios,QFeatures-method}
\title{Methods to calculate log-scale normalization factors using
the median-of-ratios method}
\usage{
\S4method{nfLogMedianOfRatios}{matrix}(object, na.rm = TRUE)

\S4method{nfLogMedianOfRatios}{SummarizedExperiment}(object, i, na.rm = TRUE)

\S4method{nfLogMedianOfRatios}{QFeatures}(object, i, na.rm = TRUE)
}
\arguments{
\item{object}{\code{matrix}, \code{SummarizedExperiment} or
\code{QFeatures} object.}

\item{na.rm}{Logical; indicates if missing values are to be removed.
Default is \code{TRUE} as missing values typically occur in proteomics data.}

\item{i}{An integer or character specifying which assay to use,
only needed when object is \code{SummarizedExperiment} or \code{QFeatures}}
}
\value{
A numeric vector of log2-scale normalization factors,
one per sample (column).
}
\description{
Computes sample-specific normalization factors on the log2 scale
using a median-of-ratios approach similar to that used in DESeq2 for bulk
RNA-seq data.

The method proceeds as follows:
\enumerate{
\item A pseudo-reference sample is constructed as the row-wise mean of the
log2 intensities (equivalent to the log2-transformed geometric mean).
\item For each sample, log2 ratios relative to pseudo-reference are computed.
\item The normalization factor for each sample is obtained as the median of
these log2 ratios (column-wise median).
}
}
\details{
This implementation assumes that the assay values are already on the log scale.
The normalization factors are computed on the log scale.
}
\examples{
# Load example data
# The data are a Feature object with containing
# a SummarizedExperiment named "peptide" with MaxQuant peptide intensities
# The data are a subset of spike-in the human-ecoli study
# The variable condition in the colData of the Feature object
# contains information on the spike in condition a-e (from low to high)
data(pe)

###############################
### Example on QFeatures object
###############################

data(pe)

# Calculate log2 norm factor
nf_log <- nfLogMedianOfRatios(pe, i="peptide")
nf_log

# Normalise peptide level data
pe <- sweep(pe, 
    MARGIN = 2, 
    STATS = nf_log, 
    i = "peptide", 
    name = "peptide_norm")
    
# Evaluate normalisation
par(mfrow=c(1,2))
boxplot(assay(pe,"peptide"))
boxplot(assay(pe,"peptide_norm"))

###############################
### Example on SummarizedExperiment object
###############################

data(pe)

# Extract a summarised experiment from QFeatures object pe
se <- getWithColData(pe, i="peptide")

# Calculate log2 norm factor
nf_log <- nfLogMedianOfRatios(se, i=1)
nf_log

# Normalise peptide level data and store it as a new assay in
# the SummarizedExperiment object
assays(se)[["peptide_norm"]] <- sweep(assay(se), 
    MARGIN = 2, 
    STATS = nf_log) 
    
# Also give first assay a name     
assayNames(se)[1] <- "peptide"

# Evaluate normalisation
par(mfrow=c(1,2))
boxplot(assay(se,"peptide"))
boxplot(assay(se,"peptide_norm"))

###############################
### Example on matrix object
###############################

data(pe)

mat <- assay(pe,"peptide")

nf <- nfLogMedianOfRatios(mat)
nf

# Normalise peptide level data
matnorm <- sweep(mat, 
    MARGIN = 2, 
    STATS = nf_log) 
# Evaluate normalisation
par(mfrow=c(1,2))
boxplot(mat)
boxplot(matnorm)

}
\references{
Love, M.I., Huber, W., Anders, S. (2014). Moderated estimation of fold change
and dispersion for RNA-seq data with DESeq2. Genome Biology, 15(12), 550.
}
