## ----opts, echo = FALSE-------------------------------------------------------
suppressWarnings(library(knitr))

opts_chunk$set(tidy = FALSE, message = FALSE, warning = FALSE)

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

## ----setup--------------------------------------------------------------------
library(scToppR)
library(dplyr)
data("ifnb.de")
head(ifnb.de)

## ----filtering----------------------------------------------------------------
ifnb.de.filtered <- ifnb.de |>
    dplyr::filter(p_val_adj < 0.05, abs(avg_log2FC) > 0.3)

## ----toppFun------------------------------------------------------------------
# This is how you would run the analysis with live data (requires internet)
if (curl::has_internet()) {
    toppdata.ifnb <- toppFun(input_data = ifnb.de.filtered,
        type = "degs",
        gene_col = "gene",
        cluster_col = "celltype",
        p_val_col = "p_val_adj",
        logFC_col = "avg_log2FC"
    )
} else {
    data("toppdata.ifnb")
}
head(toppdata.ifnb)


## ----plot1, fig.dim=c(8,8)----------------------------------------------------
toppPlot(toppdata.ifnb,
    category = "GeneOntologyMolecularFunction",
    clusters = "CD8 T"
)

## ----plot_list, fig.dim=c(8,8)------------------------------------------------
plot_list <- toppPlot(toppdata.ifnb,
    category = "GeneOntologyMolecularFunction",
    clusters = NULL
)
plot_list[1]

## ----plot_save----------------------------------------------------------------
plot_list <- toppPlot(toppdata.ifnb,
    category = "GeneOntologyMolecularFunction",
    clusters = NULL,
    save = TRUE,
    save_dir = tempdir(),
    file_prefix = "GO_molecular_function"
)

## ----plot_balloon, fig.dim=c(8,5)---------------------------------------------
toppBalloon(toppdata.ifnb,
    categories = "GeneOntologyBiologicalProcess"
)

## ----plot_balloon2, fig.dim=c(8,5)--------------------------------------------
toppBalloon(toppdata.ifnb,
    categories = "Pathway"
)

## ----plot_balloon3, fig.dim=c(8,5)--------------------------------------------
toppBalloon(toppdata.ifnb,
    categories = "Pubmed"
)

## ----save---------------------------------------------------------------------
toppSave(toppdata.ifnb,
    filename = "IFNB_toppData",
    save_dir = tempdir(),
    split = TRUE,
    format = "xlsx"
)

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

