% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/main.r
\name{deseq2_normalize}
\alias{deseq2_normalize}
\title{DESeq2 Normalization of Pseudobulk Data}
\usage{
deseq2_normalize(
  pb,
  metadata = NULL,
  deseq2_design = NULL,
  hvg = NULL,
  nvar_genes = 2000
)
}
\arguments{
\item{pb}{A gene x sample pseudobulk count matrix (Genes as rows, Samples as
columns). Must contain non-negative integer counts.}

\item{metadata}{A data.frame with sample-level metadata. Row names must
exactly match the column names of \code{pb}. The function will reorder the
metadata to match \code{pb}.}

\item{deseq2_design}{Optional: A \code{formula} object specifying the design
used by \code{DESeq2} to estimate size factors and variance for the VST.
This formula should reference columns in the \code{metadata} data frame. If
\code{NULL} (the default), the minimal design \code{~ 1} is used. Note: the
design will be considered for pseudobulk normalization as the function uses
vst(blind = FALSE, ...) internally.}

\item{hvg}{Optional character vector of gene names to use as highly variable
genes. If provided, only these genes will be returned after VST.}

\item{nvar_genes}{Number of top variable genes to select (default: 2000).
Only used if \code{hvg = NULL}; the function will select the top
\code{nvar_genes} by variance after VST.}
}
\value{
A normalized expression matrix (VST-transformed) with\
\strong{samples as columns} and \strong{genes as rows}.
}
\description{
This function normalizes a gene x sample pseudobulk count matrix using the
Variance Stabilizing Transformation (VST) from the \code{DESeq2} package. It
estimates size factors and variance for all genes, performs the VST, and then
subsets the results to include only highly variable genes (HVCs), either
specified by the user or automatically selected based on variance.
}
\details{
\strong{Note:} If \code{deseq2_design} is not specified, the VST is performed using a
minimal design formula (\code{~ 1}) for size factor and variance estimation.
}
\examples{
nrow <- 100
ncol <- 100
vals <- nrow * ncol
mat <- round(matrix(exp(rpois(vals, lambda = 3)), nrow = nrow, ncol = ncol))
rownames(mat) <- paste0("Gene", seq_len(ncol))
colnames(mat) <- paste0("Cell", seq_len(nrow))
ids <- rep(c("Sample1", "Sample2"), each = nrow / 2)
pb <- calculate_pseudobulk(count_matrix = mat, sample_ids = ids)
pb_norm <- deseq2_normalize(pb)
}
