Skip to content

Instantly share code, notes, and snippets.

@kevinrue
Last active May 24, 2019 09:59
Show Gist options
  • Save kevinrue/7d060d60eee1c7795b052eb48731c966 to your computer and use it in GitHub Desktop.
Save kevinrue/7d060d60eee1c7795b052eb48731c966 to your computer and use it in GitHub Desktop.
Example apps to demonstrate the use of a reduced dimension on the x-axis of colDataPlot and featAssayPlot
library(scRNAseq)
data(allen)
class(allen)
# Example data ----
library(scater)
sce <- as(allen, "SingleCellExperiment")
counts(sce) <- assay(sce, "tophat_counts")
sce <- normalize(sce)
sce <- runPCA(sce, ncomponents=4)
sce <- runTSNE(sce)
rowData(sce)$ave_count <- rowMeans(counts(sce))
rowData(sce)$n_cells <- rowSums(counts(sce)>0)
sce
# App of colDataPlot, featAssay and redDimPlot side by side ----
initialPanels <- DataFrame(
Name = c(
"Column data plot 1",
"Reduced dimension plot 1",
"Feature assay plot 1",
"Reduced dimension plot 2"
),
Width = rep(6L, 4)
)
colDataArgs <- colDataPlotDefaults(sce, 1)
colDataArgs$DataBoxOpen <- TRUE
colDataArgs$YAxis <- "driver_1_s"
colDataArgs$XAxis <- "Reduced dimension"
colDataArgs$ColorBy <- "Column data"
colDataArgs$ColorByColData <- "driver_1_s"
# Find a gene highly correlated with PCA dimension 1
# pca1 <- reducedDim(sce)[, 1]
# logcountsMatrix <- assay(sce, "logcounts")
# cor1 <- apply(logcountsMatrix, 1, cor, y = pca1)
# max(cor1, na.rm = TRUE)
# which.max(cor1)
featAssayArgs <- featAssayPlotDefaults(sce, 1)
featAssayArgs$DataBoxOpen <- TRUE
featAssayArgs$YAxisFeatName <- "Lmo3"
featAssayArgs$Assay <- 6L
featAssayArgs$XAxis <- "Reduced dimension"
featAssayArgs$ColorBy <- "Feature name"
featAssayArgs$ColorByFeatName <- "Lmo3"
featAssayArgs$ColorByFeatNameAssay <- 6L
redDimArgs <- redDimPlotDefaults(sce, 2)
redDimArgs$DataBoxOpen <- TRUE
redDimArgs$ColorBy <- c("Column data", "Feature name")
redDimArgs$ColorByColData <- "driver_1_s"
redDimArgs$ColorByFeatName <- "Lmo3"
redDimArgs$ColorByFeatNameAssay <- 6L
app <- iSEE(
sce, initialPanels = initialPanels,
colDataArgs = colDataArgs, featAssayArgs = featAssayArgs, redDimArgs = redDimArgs)
if (interactive()) {
shiny::runApp(app, port=1234)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment