snifter 1.12.0
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 by generating some toy data. First, we’ll load the needed libraries, and set a random seed to ensure the simulated data are reproducible (note: it is good practice to ensure that a t-SNE embedding is robust by running the algorithm multiple times).
library("snifter")
library("ggplot2")
theme_set(theme_bw())
set.seed(42)
n_obs <- 500
n_feats <- 200
means_1 <- rnorm(n_feats)
means_2 <- rnorm(n_feats)
counts_a <- replicate(n_obs, rnorm(n_feats, means_1))
counts_b <- replicate(n_obs, rnorm(n_feats, means_2))
counts <- t(cbind(counts_a, counts_b))
label <- rep(c("A", "B"), each = n_obs)
The main functionality of the package lies in the fitsne
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.
fit <- fitsne(counts, random_state = 42L)
ggplot() +
aes(fit[, 1], fit[, 2], colour = label) +
geom_point(pch = 19) +
scale_colour_discrete(name = "Cluster") +
labs(x = "t-SNE 1", y = "t-SNE 2")