## ----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------------------------------------------------------
# Real call (slow on the Bioconductor build machine):
# gsea_pathwaysets <- build_gsea_pathways(
#   species = "HS", auto_select = c("H", "C2:CP:REACTOME", "C5:GO:BP")
# )
# For the vignette we load a pre-computed lightweight pathway object instead:
data(gsea_pathwaysets_toy, package = "GSEAlens")
gsea_pathwaysets <- gsea_pathwaysets_toy

## ----setup-gsea-env-----------------------------------------------------------
# limma-voom workflow (needs the DGEList because fit alone lacks raw counts)
gseadata_limmavoom <- setup_gsea_env(fit = fit, pathway_obj = gsea_pathwaysets, expr_data = gsea_limma_voom_data)
# DESeq2 SummarizedExperiment workflow
gseadata_se <- setup_gsea_env(fit = dds_se, pathway_obj = gsea_pathwaysets)
# DESeq2 Count matrix workflow
gseadata_dds <- setup_gsea_env(fit = dds, pathway_obj = gsea_pathwaysets)

## ----batch-calc-limma, eval=FALSE---------------------------------------------
# # Write vignette outputs to a temporary directory to avoid polluting the
# # Bioconductor build machine's working directory.
# out_dir <- tempdir()
# # limma-voom workflow
# gsea_res_limmavoom <- batch_calc_gsea(gseadata_limmavoom,
#                                                  custom_series_name = "limmavoom_data",
#                                                  output_dir = out_dir,
#                                                  workers = 2,
#                                                  force = TRUE)
# # DESeq2 SummarizedExperiment workflow
# 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 workflow
# 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/")
# # Or read the RDS directly:
# # gsea_res <- readRDS("/path/of/your/file/")

## ----launch-app, eval=FALSE---------------------------------------------------
# # Basic launch
# launch_gsea_app(gsea_res)
# # With explicit pathway annotations:
# # launch_gsea_app(gsea_res, addition_data = "pathway_annotations.csv")

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

