knitr::opts_chunk$set(warning = FALSE)
Dimensionality reduction algorithms (PCA/ICA) can be run through the singleCellTK toolkit using both interactive shiny application and R console. For the interactive analysis, the toolkit offers a streamlined workflow to both compute metrics for dimensionality reduction and then visualize the results using any of the available interactive plots. For the console analysis, the toolkit offers a single wrapper function runDimReduce()
to compute metrics for any of the integrated algorithms and multiple methods to visualize the computed results.
Methods available with the toolkit include PCA
from scater
[@McCarthy2017] package and PCA
& ICA
from Seurat
[@Butler2018][@Stuart2019][@Satija2017][@Hao2021] package. Visualization options available for users include 2D Component Plot, Elbow Plot, JackStraw Plot and Heatmap. A complete list of supported visualization options against each method are specified at the bottom of the tabs below.
To view detailed instructions on how to use these methods, please select 'Interactive Analysis', from the tabs below, for performing dimension reduction in shiny application or 'Console Analysis' for using these methods in R console:
````{=html}
## Workflow Guide ````{=html} <div class="tab"> <button class="tablinks" onclick="openTab(event, 'interactive')" id="ia-button">Interactive Analysis</button> <button class="tablinks" onclick="openTab(event, 'console')" id="console-button">Console Analysis</button> </div> <div id="interactive" class="tabcontent">
In general, the UI offers options for selection of data items and choice of parameters on the left side, and a visualization panel on the right side of the interface. A detailed workflow guide to run and visualize dimension reduction (DR) is described below:
\
\
50
.\
\
````{=html}
Visualizations Supported
| Method | 2-Dimensional Component Plot | Elbow Plot | JackStraw Plot | Heatmap Plot | |---|---|---|---|---| |PCA| yes | yes | yes | yes | |ICA| yes | no | no |yes| ````{=html} </details> </div> <div id="console" class="tabcontent">
Here we show how to perform dimension reduction with the generic function runDimReduce()
,
together with the method to visualize and explore the results.
1. Compute dimensionality reduction
sce <- runDimReduce(inSCE = sce, method = "scaterPCA", useAssay = "logcounts", scale = TRUE, useFeatureSubset = "HVG_modelGeneVar2000", nComponents = 50, reducedDimName = "PCA")
The generic function runDimReduce()
allows "scaterPCA"
from scater, "seuratPCA"
and "seuratICA"
from Seurat as options of dimension reduction for method
argument. For detailed parameter description, please click on the function name to be redirected to its reference page.
2. Visualization
There are multiple functions that can create scatter plot using dimensions stored in reducedDims
slot of the SCE object.
# Make scatter plot without annotation plotDimRed(sce, useReduction = "PCA") # Short-cut for reduced dims named as "PCA" plotPCA(sce) # Customizing scatter plot with more information from cell metadata (colData) plotSCEDimReduceColData(sce, colorBy = "cluster", reducedDimName = "PCA") # Color scatter plot with feature expression plotSCEDimReduceFeatures(sce, feature = "CD8A", reducedDimName = "PCA")
Besides, SCTK also wraps elbow plot, Jackstraw plot and DimHeatmap methods from Seurat. For usage of these visualization methods, please refer to Seurat Curated Workflow
````{=html}
Example
```r library(singleCellTK) sce <- importExampleData("pbmc3k") sce <- runNormalization(sce, normalizationMethod = "LogNormalize", useAssay = "counts", outAssayName = "logcounts") sce <- runFeatureSelection(sce, useAssay = "counts", method = "modelGeneVar") sce <- setTopHVG(sce, method = "modelGeneVar", hvgNumber = 2000, featureSubsetName = "HVG") # Run sce <- runDimReduce(sce, method = "seuratPCA", useAssay = "logcounts", scale = TRUE, useFeatureSubset = "HVG", reducedDimName = "PCA", nComponents = 50) # Plot plotDimRed(sce, "PCA") ``` ````{=html} </details> <details> <summary><b>Individual Functions</b></summary>
While the runDimReduce()
wrapper function can be used for all dimensionality reduction algorithms including PCA and ICA, and additionally for 2D embeddings like tSNE and UMAP, separate functions are also available for all of the included methods. The following functions can be used for specific methods:
Running PCA with Seurat method:
# Recommended to find variable features before running runSeuratPCA # sce <- runSeuratFindHVG(inSCE = sce, useAssay = "seuratScaledData") sce <- runSeuratPCA(inSCE = sce, useAssay = "seuratNormData", scale = TRUE, reducedDimName = "seuratPCA")
Running ICA with Seurat method:
# Recommended to find variable features before running runSeuratICA # sce <- runSeuratFindHVG(inSCE = sce, useAssay = "seuratScaledData") sce <- runSeuratICA(inSCE = sce, useAssay = "seuratNormData", scale = TRUE, reducedDimName = "seuratICA")
Running PCA with scater method:
# Recommended to find variable features before running scaterPCA # sce <- runSeuratFindHVG(inSCE = sce, useAssay = "seuratScaledData") # sce <- setTopHVG(inSCE = sce, hvgNumber = 2000) sce <- scaterPCA(inSCE = sce, useAssay = "logcounts", useFeatureSubset = "HVG_vst2000", scale = TRUE, reducedDimName = "scaterPCA")
````{=html}
Visualizations Supported
| Method | 2-Dimensional Component Plot | Elbow Plot | JackStraw Plot | Heatmap Plot | |---|---|---|---|---| |PCA| yes | yes | yes | yes | |ICA| yes | no | no |yes| ````{=html} </details> </div> <script> document.getElementById("ia-button").click(); </script> </body>
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.