--- title: "scToppR with differential expression, Airway dataset" package: "`r pkg_ver('scToppR')`" output: BiocStyle::html_document: toc: true toc_depth: 2 vignette: > %\VignetteIndexEntry{2. Introduction to scToppR using the Airway dataset} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r opts, echo = FALSE} suppressWarnings(library(knitr)) opts_chunk$set(tidy = FALSE, message = FALSE, warning = FALSE) ``` # Introduction scToppR is a package that allows seamless, workflow-based interaction with ToppGene, a portal for gene enrichment analysis. Researchers can use scToppR to directly query ToppGene's databases and conduct analysis with a few lines of code. scToppR's availability on Bioconductor ensures easy installation and integration with other Bioconductor workflows, allowing researchers to incorporate functional enrichment analysis from ToppGene into their existing pipelines. The use of data from ToppGene is governed by their Terms of Use: https://toppgene.cchmc.org/navigation/termsofuse.jsp This vignette shows the use of scToppR within a differential expression workflow. Using the 'airway' dataset, we'll perform a quick differential expression analysis using DESeq2. With the list of differentially expressed genes, we can easily use scToppR. # Installation ```{r installation, eval=FALSE} if (!requireNamespace("BiocManager", quietly = TRUE)) { install.packages("BiocManager") } BiocManager::install("scToppR") ``` # Load Data and Perform Differential Expression Analysis ```{r setup} library(scToppR) suppressMessages({ library(airway) library(DESeq2) }) data("airway") se <- airway rownames(se) <- rowData(se)$gene_name dds <- DESeqDataSet(se, design = ~ cell + dex) smallestGroupSize <- 3 keep <- rowSums(counts(dds) >= 10) >= smallestGroupSize dds <- dds[keep, ] dds <- DESeq(dds) res <- results(dds) # add the gene names as a column in the results res$gene <- rownames(res) # add cluster column - here, with this bulk RNAseq data, we will only have 1 cluster res$cluster <- "cluster0" ``` # Using scToppR with Differential Expression Results With these results, we will use scToppR to querry the ToppGene database for all categories for each cluster using the toppFun() function. This function requires users to specify the columns in their dataset. ```{r toppFun} # This is how you would run the analysis with live data (requires internet) if (curl::has_internet()) { toppdata.airway <- toppFun(res, type = "degs", gene_col = "gene", cluster_col = "cluster", p_val_col = "padj", logFC_col = "log2FoldChange" ) } else { data("toppdata.airway") } head(toppdata.airway) ``` As the code reminds you, the use of this data must be done so in accordance with ToppGene's Terms of Use. For more information, please visit: https://toppgene.cchmc.org/navigation/termsofuse.jsp If you have an existing SummarizedExperiment or SingleCellExperiment object, scToppR also includes a function to add the toppData results to the metadata of that object. This allows users to easily access their ToppGene results within their existing data objects. ```{r save_to_se} se <- addToppData(se, toppdata.airway) print(head(metadata(se)$toppData)) ``` # Visualizing ToppGene Results The toppData dataframe (whether from live API call or cached data) includes all results from ToppGene. We can use this dataframe to quickly generate pathway analysis plots using the toppPlot() function. The function can be used to generate a single plot, for example: ```{r plot1, fig.dim=c(8,8)} toppPlot(toppdata.airway, category = "GeneOntologyMolecularFunction", clusters = "cluster0" ) ``` The toppPlot() function can also be used with the toppData dataframe directly, without needing to add it to a SummarizedExperiment or SingleCellExperiment object. ```{r plot_se, fig.dim=c(8,8)} toppPlot(se, category = "GeneOntologyMolecularFunction", clusters = "cluster0" ) ``` The toppPlot() function can also create a plot for each cluster for a specified category; simply assign the parameter `clusters` to NULL. In this case, the function will return a list of plots. ```{r plot_list, fig.dim=c(8,8)} plot_list <- toppPlot(toppdata.airway, category = "GeneOntologyMolecularFunction", clusters = NULL ) plot_list[1] ``` All of these plots can also be automatically saved by the toppPlot() function. The files and their save locations can be set using the parameters: -save = TRUE -save_dir="/path/to/save_directory" -file_name_prefix="GO_Molecular_Function" The cluster/celltype name will be automatically added to the filename prior to saving. ```{r plot_save} plot_list <- toppPlot(toppdata.airway, category = "GeneOntologyMolecularFunction", clusters = NULL, save = TRUE, save_dir = tempdir(), file_prefix = "GO_molecular_function" ) ``` scToppR also uses the toppBalloon() function to create a balloon plot, allowing researchers to quickly compare the top terms from the ToppGene results. ```{r plot_balloon, fig.dim=c(8,5)} toppBalloon(toppdata.airway, categories = "GeneOntologyBiologicalProcess" ) ``` Some advantages of using scToppR in a pipeline include access to the other categories in ToppGene. Users can quickly view results from all ToppGene categories using these plotting function, or by examining the toppData results. For example, a user could explore any common results among celltypes in terms such as Pathway, ToppCell, and TFBS. For example, a quick look at the toppBalloon plot for Pathway shows a distinction with the Dendritic Cells compared to others: ```{r plot_balloon2, fig.dim=c(8,5)} toppBalloon(toppdata.airway, categories = "Pathway" ) ``` The Pubmed category also provides researchers with other papers exploring similar data: ```{r plot_balloon3, fig.dim=c(8,5)} toppBalloon(toppdata.airway, categories = "Pubmed" ) ``` # Saving ToppGene Results To save toppData results, scToppR also includes a toppSave() function. This function can save the toppData results as a single file, or it can split the data into different clusters/celltypes and save each individually. To do so, set `save = TRUE` in the function call. The function saves the files as Excel spreadsheets by default, but this can be changed to .csv or .tsv files using the `format` parameter. ```{r save} toppSave(toppdata.airway, filename = "airway_toppData", save_dir = tempdir(), split = TRUE, format = "xlsx" ) ``` ```{r sessionInfo} sessionInfo() ```