Created
June 23, 2020 09:49
-
-
Save seanlaidlaw/ec16251b8d94d0b63e3682a3188bd65a to your computer and use it in GitHub Desktop.
Minimal working example for running Slingshot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(Seurat) | |
library(slingshot) | |
library(RColorBrewer) | |
# start with a Seurat object containing assay of normalised cell counts, with a PCA or TSNE | |
# for example: | |
# > seuratobj | |
# An object of class Seurat | |
# features across 801 samples within 1 assay | |
# Active assay: RNA (832 features) | |
# 1 dimensional reduction calculated: pca | |
# Plot 1 : Plot slingshot pseudotime | |
slingshotObject <- slingshot(as.SingleCellExperiment(seuratobj)) | |
colors <- rainbow(50, alpha = 1) | |
plot(reducedDims(slingshotObject)$PCA, col = colors[cut(slingshotObject$slingPseudotime_1,breaks=50)], pch=16, asp = 1) | |
# Plot 2 : Plot cell type with slingshot lineage calculation | |
# create matrix of PC_1, PC_2 values for each cell | |
cellLabels = as.double(seuratobj$seurat_clusters) | |
names(cellLabels) = labels(seuratobj$seurat_clusters) | |
# create matrix of PC_1, PC_2 values for each cell | |
reducedDimension = reducedDim(as.SingleCellExperiment(seuratobj)) | |
# use slingshot to calculate lineage between cells in low dimensional space | |
lineage <- getLineages(reducedDimension, cellLabels) | |
# plot the cells by PC_1 and PC_2, and the lineage slingshot calculates | |
{plot(reducedDimension, col = brewer.pal(9,"Set1")[cellLabels], asp = 1, pch = 16) | |
lines(lineage, col = 'black')} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment