knitr::opts_chunk$set(echo = TRUE) options(bitmapType="cairo")
This is a quick walkthrough demonstrating how to generate SWNE plots alongside the Pagoda2 pipeline using a 3k PBMC dataset as an example.
To save time we will be using the pre-computed Pagoda2 object pbmc3k_pagoda2.Robj
, which can be downloaded here.
First let's load the required libraries
library(pagoda2) library(swne) library(Matrix)
Next let's load the Pagoda2 object
p2 <- readRDS("/media/Home_Raid1/yan/swne/Data/pbmc3k_pagoda2.Robj")
Most scRNA-seq pipelines only use a subset of highly overdispersed genes for analysis. We'll pull out those variable genes here, as well as the cluster labels.
## Pull out variable genes n.od.genes <- 1.5e3 var.info <- p2$misc$varinfo; var.info <- var.info[order(var.info$lp, decreasing = F),]; od.genes <- rownames(var.info[1:n.od.genes,]) length(od.genes) ## Pull out clusters clusters <- p2$clusters$PCA$multilevel table(clusters)
The easiest way to generate an SWNE embedding is to use the wrapper function RunSWNE
## Run SWNE genes.embed <- c("MS4A1", "GNLY", "CD3E", "CD14", "FCER1A", "FCGR3A", "LYZ", "PPBP", "CD8A") swne.embedding <- RunSWNE(p2, k = 16, var.genes = od.genes, genes.embed = genes.embed, sample.groups = clusters) ## Plot SWNE PlotSWNE(swne.embedding, alpha.plot = 0.4, sample.groups = clusters, do.label = T, label.size = 3.5, pt.size = 1.5, show.legend = F, seed = 42)
We can also make a t-SNE plot for comparison.
tsne.scores <- p2$embeddings$PCA$tSNE PlotDims(tsne.scores, sample.groups = clusters, pt.size = 0.75, label.size = 3.5, alpha = 0.3, show.legend = F, seed = 42, show.axes = F)
Extract cluster colors for compatibility with other plotting methods (i.e. Monocle)
color.mapping <- ExtractSWNEColors(swne.embedding, sample.groups = clusters, seed = 42) color.mapping
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.