Question: Can I generate a 3D t-SNE plot from Cell Ranger output?
Answer: Although you cannot view the 3D t-SNE projections in Loupe Cell Browser, you can generate the data for 3D t-SNE projections using the cellranger reanalyze
pipeline.
The key is to run cellranger reanalyze
with an updated value for tsne_max_dims in the CSV-formatted parameters file passed via the --params
argument.
cellranger reanalyze --id=pbmc4k_3d --matrix=pbmc4k_matrix.h5 --params=params.csv
This tsne_max_dims
parameter denotes the maximum number of t-SNE output dimensions. When set to 3, this produces both 2D and 3D TSNE projections (note: runtime will increase significantly).
For example, in the params.csv file, one would have:
tsne_max_dims,3
The 3D t-SNE output file is in the following path within the cellranger reanalyze
pipestance directory:
outs/analysis/tsne/3_components/projection.csv
In R, there are a number of packages for plotting in 3D (scatterplot3d, rgl). The following is an example of how to generate a 3D t-SNE plot in R using plotly and cellrangerRkit:
library(cellrangerRkit) library(plotly) # set to reanalyze pipestance path pipestance_path <- "pbmc4k_3d/" # load 3D t-SNE data in data.frame tsne_3d <- read.csv(file.path(pipestance_path, "outs", "analysis","tsne", "3_components","projection.csv")) # load analysis results using cellrangerRkit function analysis_results <- load_cellranger_analysis_results(pipestance_path) # load graph-based cluster annotation graphclust <- as.factor(analysis_results$clustering[["graphclust"]]$Cluster) # get number of clusters n_graphclust <- length(levels(graphclust)) # setup color palette colors_graphclust <- colorRampPalette(brewer.pal(10, "Set3"))(n_graphclust) # setup plot # axis settings: don't display tick marks, values ax <- list(showticklabels = FALSE) p <- plot_ly(tsne_3d, x=~`TSNE.1`,y=~`TSNE.2`,z=~`TSNE.3`, color=graphclust, colors=colors_graphclust, marker=list(size=3)) %>% layout(scene=list(xaxis=ax, yaxis=ax, zaxis=ax)) %>% add_markers() p
Disclaimer: This article and code-snippet are provided for instructional purposes only. 10x Genomics does not support or guarantee the code.