snifter provides an R wrapper for the openTSNE implementation of fast interpolated t-SNE (FI-tSNE). It is based on basilisk and reticulate. This vignette aims to provide a brief overview of typical use when applied to scRNAseq data, but it does not provide a comprehensive guide to the available options in the package.
It is highly advisable to review the documentation in snifter and the openTSNE documentation to gain a full understanding of the available options.
We will illustrate the use of snifter using data from scRNAseq and single cell utility functions provided by scuttle, scater and scran - first we load these libraries and set a random seed to ensure the t-SNE visualisation is reproducible (note: it is good practice to ensure that a t-SNE embedding is robust by running the algorithm multiple times).
library("snifter") library("scRNAseq") library("scran") library("scuttle") library("scater") library("ggplot2") theme_set(theme_bw()) set.seed(42)
Before running t-SNE, we first load data generated by Zeisel et al. from scRNAseq. We filter this data to remove genes expressed only in a small number of cells, estimate normalisation factors using scran and generate 20 principal components. We will use these principal components to generate the t-SNE embedding later.
data <- ZeiselBrainData() data <- data[rowMeans(counts(data) != 0) > 0.05, ] data <- computeSumFactors(data, cluster = quickCluster(data)) data <- logNormCounts(data) data <- runPCA(data, ncomponents = 20) ## Convert this to a factor to use as colouring variable later data$level1class <- factor(data$level1class)
The main functionality of the package lies in the
function. This function returns a matrix of t-SNE co-ordinates. In this case,
we pass in the 20 principal components computed based on the
log-normalised counts. We colour points based on the discrete
cell types identified by the authors.
mat <- reducedDim(data) fit <- fitsne(mat, random_state = 42L) ggplot() + aes(fit[, 1], fit[, 2], colour = data$level1class) + geom_point(pch = 19) + scale_colour_discrete(name = "Cell type") + labs(x = "t-SNE 1", y = "t-SNE 2")