inst/doc/vignette.R

## ---- echo=FALSE, results="hide", message=FALSE-------------------------------
knitr::opts_chunk$set(error=FALSE, message=FALSE, warning=FALSE)
library(BiocStyle)

## -----------------------------------------------------------------------------
suppressPackageStartupMessages(library(escape))
suppressPackageStartupMessages(library(dittoSeq))
suppressPackageStartupMessages(library(SingleCellExperiment))
suppressPackageStartupMessages(library(Seurat))
pbmc_small <- get("pbmc_small")
pbmc_small <- suppressMessages(UpdateSeuratObject(pbmc_small))
sce <- as.SingleCellExperiment(pbmc_small)

## -----------------------------------------------------------------------------
GS <- getGeneSets(library = "H")

## -----------------------------------------------------------------------------
ES <- enrichIt(obj = pbmc_small, gene.sets = GS, groups = 1000, cores = 2)
ES.sce <- enrichIt(obj = sce, gene.sets = GS, groups = 1000, cores = 2)

## -----------------------------------------------------------------------------
pbmc_small <- AddMetaData(pbmc_small, ES)
met.data <- merge(colData(sce), ES.sce, by = "row.names", all=TRUE)
row.names(met.data) <- met.data$Row.names
met.data$Row.names <- NULL
colData(sce) <- met.data

## -----------------------------------------------------------------------------
colors <- colorRampPalette(c("#FF4B20", "#FFB433", "#C6FDEC", "#7AC5FF", "#0348A6"))

## -----------------------------------------------------------------------------
dittoHeatmap(pbmc_small, genes = NULL, metas = names(ES), 
             annot.by = "groups", 
             fontsize = 7, 
             cluster_cols = TRUE,
             heatmap.colors = rev(colors(50)))

## -----------------------------------------------------------------------------
dittoHeatmap(sce, genes = NULL, 
             metas = c("HALLMARK_APOPTOSIS", "HALLMARK_DNA_REPAIR", "HALLMARK_P53_PATHWAY"), 
             annot.by = "groups", 
             fontsize = 7,
             heatmap.colors = rev(colors(50)))

## -----------------------------------------------------------------------------
multi_dittoPlot(sce, vars = c("HALLMARK_APOPTOSIS", "HALLMARK_DNA_REPAIR", "HALLMARK_P53_PATHWAY"), 
                group.by = "groups", plots = c("jitter", "vlnplot", "boxplot"), 
                ylab = "Enrichment Scores", 
                theme = theme_classic() + theme(plot.title = element_text(size = 10)))

## -----------------------------------------------------------------------------
dittoScatterHex(sce, x.var = "HALLMARK_DNA_REPAIR", 
                    y.var = "HALLMARK_MTORC1_SIGNALING", 
                    do.contour = TRUE) + 
        scale_fill_gradientn(colors = rev(colors(11))) 

## -----------------------------------------------------------------------------
dittoScatterHex(sce, x.var = "HALLMARK_DNA_REPAIR", 
                y.var = "HALLMARK_MTORC1_SIGNALING", 
                do.contour = TRUE,
                split.by = "groups")  + 
        scale_fill_gradientn(colors = rev(colors(11))) 

## -----------------------------------------------------------------------------
ES2 <- data.frame(pbmc_small[[]], Idents(pbmc_small))
colnames(ES2)[ncol(ES2)] <- "cluster"
ridgeEnrichment(ES2, gene.set = "HALLMARK_DNA_REPAIR", group = "letter.idents", add.rug = TRUE)

## -----------------------------------------------------------------------------
ridgeEnrichment(ES2, gene.set = "HALLMARK_DNA_REPAIR", group = "cluster", 
                facet = "letter.idents", add.rug = TRUE)

## -----------------------------------------------------------------------------
splitEnrichment(ES2, split = "groups", gene.set = "HALLMARK_DNA_REPAIR")
splitEnrichment(ES2, x.axis = "cluster", split = "groups", gene.set = "HALLMARK_DNA_REPAIR")

## -----------------------------------------------------------------------------
PCA <- performPCA(enriched = ES2, groups = c("groups", "cluster"))

## -----------------------------------------------------------------------------
pcaEnrichment(PCA, PCx = "PC1", PCy = "PC2", contours = TRUE)

## -----------------------------------------------------------------------------
pcaEnrichment(PCA, PCx = "PC1", PCy = "PC2", contours = FALSE, facet = "cluster") 

## -----------------------------------------------------------------------------
masterPCAPlot(ES2, PCx = "PC1", PCy = "PC2", top.contribution = 10)

## -----------------------------------------------------------------------------
output <- getSignificance(ES2, group = "cluster", fit = "linear.model")

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

Try the escape package in your browser

Any scripts or data that you put into this service are public.

escape documentation built on Nov. 8, 2020, 8:21 p.m.