% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sig_gsea.R
\name{sig_gsea}
\alias{sig_gsea}
\title{Perform Gene Set Enrichment Analysis (GSEA)}
\usage{
sig_gsea(
  deg,
  genesets = NULL,
  path = NULL,
  gene_symbol = "symbol",
  logfc = "log2FoldChange",
  org = c("hsa", "mus"),
  msigdb = TRUE,
  category = "H",
  subcategory = NULL,
  palette_bar = "jama",
  palette_gsea = 2,
  cols_gsea = NULL,
  cols_bar = NULL,
  show_bar = 10,
  show_col = FALSE,
  show_plot = FALSE,
  show_gsea = 8,
  show_path_n = 20,
  plot_single_sig = FALSE,
  project = "custom_sig",
  minGSSize = 10,
  maxGSSize = 500,
  verbose = TRUE,
  seed = FALSE,
  fig.type = "pdf",
  print_bar = TRUE
)
}
\arguments{
\item{deg}{Data frame containing differential expression results with gene symbols
and log fold changes.}

\item{genesets}{List of custom gene sets for enrichment analysis. If `NULL`,
MSigDB gene sets are used based on `org` and `category`. Default is `NULL`.}

\item{path}{Character string specifying the directory path for saving results.
Default is `NULL`.}

\item{gene_symbol}{Character string specifying the column name in `deg`
containing gene symbols. Default is `"symbol"`.}

\item{logfc}{Character string specifying the column name in `deg` containing
log fold change values. Default is `"log2FoldChange"`.}

\item{org}{Character string specifying the organism. Options are `"hsa"`
(Homo sapiens) or `"mus"` (Mus musculus). Default is `"hsa"`.}

\item{msigdb}{Logical indicating whether to use MSigDB gene sets. Default is
`TRUE`.}

\item{category}{Character string specifying the MSigDB category (e.g., `"H"`
for Hallmark, `"C2"` for curated gene sets). Default is `"H"`.}

\item{subcategory}{Character string specifying the MSigDB subcategory to filter
gene sets. Default is `NULL`.}

\item{palette_bar}{Character string or integer specifying the color palette for
bar plots. Default is `"jama"`.}

\item{palette_gsea}{Integer specifying the color palette for GSEA plots. Default
is `2`.}

\item{cols_gsea}{Character vector specifying custom colors for GSEA enrichment
plots. If `NULL`, colors are automatically generated. Default is `NULL`.}

\item{cols_bar}{Character vector specifying custom colors for the enrichment
bar plot. If `NULL`, colors are automatically generated. Default is `NULL`.}

\item{show_bar}{Integer specifying the number of top enriched gene sets to display
in the bar plot. Default is `10`.}

\item{show_col}{Logical indicating whether to display color names in the bar plot.
Default is `FALSE`.}

\item{show_plot}{Logical indicating whether to display GSEA enrichment plots.
Default is `FALSE`.}

\item{show_gsea}{Integer specifying the number of top significant gene sets for
which to generate GSEA plots. Default is `8`.}

\item{show_path_n}{Integer specifying the number of pathways to display in GSEA
plots. Default is `20`.}

\item{plot_single_sig}{Logical indicating whether to generate separate plots for
each significant gene set. Default is `TRUE`.}

\item{project}{Character string specifying the project name for output files.
Default is `"custom_sig"`.}

\item{minGSSize}{Integer specifying the minimum gene set size for analysis.
Default is `10`.}

\item{maxGSSize}{Integer specifying the maximum gene set size for analysis.
Default is `500`.}

\item{verbose}{Logical indicating whether to display progress messages. Default
is `TRUE`.}

\item{seed}{Logical indicating whether to set a random seed for reproducibility.
Default is `FALSE`.}

\item{fig.type}{Character string specifying the file format for saving plots
(e.g., `"pdf"`, `"png"`). Default is `"pdf"`.}

\item{print_bar}{Logical indicating whether to save and print the bar plot.
Default is `TRUE`.}
}
\value{
List containing:
\describe{
  \item{up}{Data frame of up-regulated enriched gene sets}
  \item{down}{Data frame of down-regulated enriched gene sets}
  \item{all}{Complete GSEA results}
  \item{plot_top}{GSEA enrichment plot for top gene sets}
}
}
\description{
Conducts Gene Set Enrichment Analysis to identify significantly enriched gene sets
from differential gene expression data. Supports MSigDB gene sets or custom gene
signatures, and generates comprehensive visualizations and statistical results.
}
\examples{
set.seed(123)
genes <- c(
  "TP53", "BRCA1", "EGFR", "MYC", "KRAS", "PTEN", "APC", "RB1",
  "CDKN2A", "VHL", "ATM", "ATR", "CHEK2", "PALB2", "RAD51", "MDM2",
  "CDK4", "CDK6", "CCND1", "CCNE1", "CDK2", "E2F1", "E2F2", "E2F3",
  "ARF1", "ARF3", "ARF4", "ARF5", "ARF6", "GSK3B", "AKT1", "AKT2",
  "PIK3CA", "PIK3CB", "PIK3CD", "PIK3CG", "PIK3R1", "PIK3R2", "PIK3R3"
)
deg <- data.frame(
  symbol = genes,
  log2FoldChange = rnorm(length(genes), mean = 0, sd = 2),
  padj = runif(length(genes), 0, 0.1)
)
signature <- list(
  DNA_Repair = c(
    "TP53", "BRCA1", "ATM",
    "ATR", "CHEK2", "PALB2", "RAD51"
  ),
  Cell_Cycle = c(
    "TP53", "MYC",
    "RB1", "CDKN2A", "CDK4",
    "CDK6", "CCND1", "CCNE1",
    "CDK2", "E2F1", "E2F2", "E2F3"
  ),
  PI3K_AKT = c(
    "AKT1", "AKT2",
    "PIK3CA", "PIK3CB", "PIK3CD",
    "PIK3CG", "PIK3R1", "PIK3R2", "PIK3R3"
  )
)
\donttest{
res <- sig_gsea(
  deg = deg,
  genesets = signature,
  path = tempdir(),
  show_plot = FALSE,
  print_bar = FALSE
)
print(names(res))
}
}
\author{
Dongqiang Zeng
}
