## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)

## ----install-package, eval=FALSE----------------------------------------------
# if (!requireNamespace("BiocManager", quietly = TRUE))
#     install.packages("BiocManager")
# BiocManager::install("GSEAlens")

## ----install-github, eval=FALSE-----------------------------------------------
# if (!requireNamespace("pak", quietly = TRUE))
#     install.packages("pak")
# pak::pkg_install("DDL095/GSEAlens")

## ----setup-environment, results='hide'----------------------------------------
library(GSEAlens)
library(airway)

## ----load-prepared-objects----------------------------------------------------
data(preprocessed_limma, package = "GSEAlens")
preproc_limma         <- preprocessed_limma
fit                   <- preproc_limma$fit
gsea_limma_voom_data  <- preproc_limma$gsea_limma_voom_data
data(preprocessed_dds_se, package = "GSEAlens")
dds_se <- preprocessed_dds_se
data(preprocessed_dds, package = "GSEAlens")
dds <- preprocessed_dds

## ----build-gsea-pathways, eval=FALSE------------------------------------------
# # 实际调用（在 Bioconductor 构建机上较慢，因需加载多个 MSigDB 集合；编译时跳过）
# # gsea_pathwaysets <- build_gsea_pathways(
# #   species = "HS", auto_select = c("H", "C2:CP:REACTOME", "C5:GO:BP")
# # )

## ----load-precomputed-pathways------------------------------------------------
# 为加速 vignette 编译，此处加载预计算的轻量级基因集对象
# （Hallmark + KEGG_LEGACY，共 236 条通路）。
# 重新生成方法见 inst/scripts/make_gsea_pathwaysets_toy.R。
data(gsea_pathwaysets_toy, package = "GSEAlens")
gsea_pathwaysets <- gsea_pathwaysets_toy

## ----setup-gsea-limma---------------------------------------------------------
gseadata_limmavoom <- setup_gsea_env(fit = fit,pathway_obj = gsea_pathwaysets,expr_data = gsea_limma_voom_data)

## ----setup-gsea-se------------------------------------------------------------
gseadata_se <- setup_gsea_env(fit = dds_se,pathway_obj = gsea_pathwaysets)

## ----setup-gsea-dds-----------------------------------------------------------
gseadata_dds <- setup_gsea_env(fit = dds,pathway_obj = gsea_pathwaysets)

## ----batch-calc-gsea, eval=FALSE----------------------------------------------
# # 将 vignette 输出写入临时目录，避免污染 Bioconductor 构建机器的工作目录。
# out_dir <- tempdir()
# # limma-voom 流程
# gsea_res_limmavoom <- batch_calc_gsea(gseadata_limmavoom,
#                                                  custom_series_name = "limmavoom_data",
#                                                  output_dir = out_dir,
#                                                  workers = 2,  # 根据比对数量和电脑性能调整
#                                                  force = TRUE)
# # DESeq2 SummarizedExperiment 流程
# gsea_res_se <- batch_calc_gsea(gseadata_se,
#                                           custom_series_name = "dds_se_data",
#                                           output_dir = out_dir,
#                                           workers = 2,
#                                           force = TRUE)
# # DESeq2 Count matrix 流程
# gsea_res_dds <- batch_calc_gsea(gseadata_dds,
#                                            custom_series_name = "dds_data",
#                                            output_dir = out_dir,
#                                            workers = 2,
#                                            force = TRUE)

## ----import-capsule, eval=FALSE-----------------------------------------------
# gsea_res <- import_gsea_capsule("/path/to/your/files/")
# # 或者直接读取 RDS 文件：
# # gsea_res <- readRDS("/path/of/your/file/")

## ----launch-app, eval=FALSE---------------------------------------------------
# launch_gsea_app(gsea_res)

## ----launch-app-with-data, eval=FALSE-----------------------------------------
# launch_gsea_app(gsea_res, addition_data = "pathway_annotations.csv")

## ----sessionInfo--------------------------------------------------------------
sessionInfo()

