## ----opts, include = FALSE----------------------------------------------------
knitr::opts_chunk$set(
    collapse = TRUE,
    comment = "#>"
)

## ----installation, eval=FALSE-------------------------------------------------
# if (!requireNamespace("BiocManager", quietly = TRUE)) {
#     install.packages("BiocManager")
# }
# BiocManager::install("scToppR")

## ----setup--------------------------------------------------------------------
library(scToppR)
data("pbmc.markers")
head(pbmc.markers)

## ----toppFun_1----------------------------------------------------------------
# This is how you would run the analysis with live data (requires internet)
if (curl::has_internet()) {
     toppdata.pbmc <- toppFun(
        input_data = pbmc.markers,
        type = "degs",
        topp_categories = NULL,
        cluster_col = "cluster",
        gene_col = "gene",
        p_val_col = "p_val_adj",
        logFC_col = "avg_log2FC"
    )
} else {
   data("toppdata.pbmc")
}

head(toppdata.pbmc)

## ----topp_cats----------------------------------------------------------------
get_ToppCats()

## ----toppData_structure-------------------------------------------------------
# Examine the structure of the results
str(toppdata.pbmc)
cat("Number of enriched terms:", nrow(toppdata.pbmc), "\n")
cat("Categories analyzed:", length(unique(toppdata.pbmc$Category)), "\n")
cat("Clusters analyzed:", length(unique(toppdata.pbmc$Cluster)), "\n")

## ----toppPlot_1---------------------------------------------------------------
plots <- toppPlot(toppdata.pbmc,
    category = "GeneOntologyMolecularFunction",
    clusters = NULL
)
plots[1]

## ----toppBalloon--------------------------------------------------------------
toppBalloon(toppdata.pbmc, categories = "GeneOntologyMolecularFunction")

## ----save---------------------------------------------------------------------
tmpdir <- tempdir()
toppSave(toppdata.pbmc, filename = "PBMC", save_dir = tmpdir, split = TRUE, format = "xlsx")

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

