% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/remove_batcheffect.R
\name{remove_batcheffect}
\alias{remove_batcheffect}
\title{Removing Batch Effect from Expression Sets}
\usage{
remove_batcheffect(
  eset1,
  eset2,
  eset3 = NULL,
  id_type = "ensembl",
  data_type = c("array", "count", "tpm"),
  cols = "normal",
  palette = "jama",
  log2 = TRUE,
  check_eset = TRUE,
  adjust_eset = TRUE,
  repel = FALSE,
  path = NULL
)
}
\arguments{
\item{eset1}{First expression set (matrix or data frame with genes as rows).}

\item{eset2}{Second expression set.}

\item{eset3}{Optional third expression set. Use `NULL` if not available.}

\item{id_type}{Type of gene ID in expression sets (e.g., `"ensembl"`,
`"symbol"`). Required for count data normalization.}

\item{data_type}{Type of data: `"array"`, `"count"`, or `"tpm"`.
Default is `"array"`.}

\item{cols}{Color scale for PCA plot. Default is `"normal"`.}

\item{palette}{Color palette for PCA plot. Default is `"jama"`.}

\item{log2}{Whether to perform log2 transformation. Default is `TRUE`.
Ignored for count data.}

\item{check_eset}{Whether to check expression sets for errors.
Default is `TRUE`.}

\item{adjust_eset}{Whether to adjust expression sets by removing problematic
features. Default is `TRUE`.}

\item{repel}{Whether to add repelling labels to PCA plot. Default is `FALSE`.}

\item{path}{Directory where results should be saved. Default is `NULL`
(display only).}
}
\value{
Expression matrix after batch correction.
}
\description{
Removes batch effects from expression datasets using sva::ComBat (for
microarray/TPM data) or sva::ComBat_seq (for RNA-seq count data). Generates
PCA plots to visualize data before and after correction.
}
\examples{
# Simulate data
set.seed(123)
sim_eset1 <- matrix(rnorm(100 * 5, mean = 10, sd = 2), 100, 5)
sim_eset2 <- matrix(rnorm(100 * 5, mean = 12, sd = 2), 100, 5)
rownames(sim_eset1) <- rownames(sim_eset2) <- paste0("Gene", 1:100)
colnames(sim_eset1) <- paste0("S1_", 1:5)
colnames(sim_eset2) <- paste0("S2_", 1:5)

# Run batch correction
if (requireNamespace("sva", quietly = TRUE) && requireNamespace("BiocParallel", quietly = TRUE)) {
  eset_corrected <- remove_batcheffect(sim_eset1, sim_eset2, data_type = "tpm")
  if (!is.null(eset_corrected)) head(eset_corrected)
}
}
\references{
Zhang Y, et al. ComBat-seq: batch effect adjustment for RNA-seq count data.
NAR Genomics and Bioinformatics. 2020;2(3):lqaa078.
doi:10.1093/nargab/lqaa078

Leek JT, et al. The sva package for removing batch effects and other
unwanted variation in high-throughput experiments. Bioinformatics.
2012;28(6):882-883.
}
\author{
Dongqiang Zeng
}
