| 1 | |
| 2 | == Making diffusion maps with Slingshot == |
| 3 | |
| 4 | You can either assigned cells to clusters based on [https://bioconductor.org/packages/release/bioc/vignettes/slingshot/inst/doc/vignette.html | Slingshot protocol ] or make a single cell object, i.e. from the Seurat object. Example commands for convert to single cell object from Seurat. |
| 5 | |
| 6 | * **Making a single cell object from a Seurat object** |
| 7 | {{{ |
| 8 | library(Seurat) |
| 9 | library(SingleCellExperiment) |
| 10 | sce <- as.SingleCellExperiment(seuratObject) |
| 11 | #this has the cell classification |
| 12 | table(sce$ident) |
| 13 | }}} |
| 14 | |
| 15 | == Calculate pseudotime and lineages with Slingshot == |
| 16 | |
| 17 | You can use either PCA/UMAP/TSNE for reduction. Since Slingshot is designed for cases in which cells fall along a continuous trajectory, it's better to use PCA if clearly discrete clusters in UMAP, as mentioned in [https://github.com/kstreet13/slingshot/issues/43 | Slingshot github page] |
| 18 | |
| 19 | {{{ |
| 20 | sce <- slingshot(sce, clusterLabels = ident, reducedDim = "PCA", |
| 21 | allow.breaks = FALSE) |
| 22 | # get the lineages: |
| 23 | lnes <- getLineages(reducedDim(sce,"PCA"), sce$ident) |
| 24 | lnes@lineages |
| 25 | |
| 26 | }}} |
| 27 | |
| 28 | If you know the which cluster is the origin ( last cluster), you can assign starting cluster/last cluster: |
| 29 | |
| 30 | {{{ |
| 31 | sce <- slingshot(sce, clusterLabels = ident, reducedDim = "PCA", |
| 32 | allow.breaks = FALSE, start.clus="2") |
| 33 | # get the lineages: |
| 34 | lnes <- getLineages(reducedDim(sce2,"PCA"), |
| 35 | sce2$ident, start.clus = "2") |
| 36 | lnes@lineages |
| 37 | }}} |
| 38 | |
| 39 | == Visualize the pseudotime or lineages == |
| 40 | |
| 41 | draw plot with first pseudotime as x-axis, and y-axis is the cell type. If you have multiple lineages, cells that were identified as being specific to Lineage 2 will have NA values for slingPseudotime_1 ( [https://github.com/kstreet13/slingshot/issues/42 | slingshot github page] ) |
| 42 | |
| 43 | {{{ |
| 44 | |
| 45 | library(Polychrome) |
| 46 | library(ggbeeswarm) |
| 47 | library(ggthemes) |
| 48 | |
| 49 | my_color <- createPalette(length(levels(sce$ident)), c("#010101", "#ff0000"), M=1000) |
| 50 | names(my_color) <- unique(as.character(sce$ident)) |
| 51 | |
| 52 | slingshot_df <- data.frame(colData(sce)) |
| 53 | |
| 54 | # re-order y-axis for better figure: |
| 55 | slingshot_df$ident = factor(slingshot_df$ident, levels=c(4,2,1,0,3,5,6)) |
| 56 | |
| 57 | ggplot(slingshot_df, aes(x = slingPseudotime_1, y = ident, |
| 58 | colour = ident)) + |
| 59 | geom_quasirandom(groupOnX = FALSE) + theme_classic() + |
| 60 | xlab("First Slingshot pseudotime") + ylab("cell type") + |
| 61 | ggtitle("Cells ordered by Slingshot pseudotime")+scale_colour_manual(values = my_color) |
| 62 | |
| 63 | |
| 64 | }}} |
| 65 | |
| 66 | # plot Lineages along the cells in PCAs |
| 67 | |
| 68 | {{{ |
| 69 | |
| 70 | plot(reducedDims(sce)$PCA, col = my_color[as.character(sce$ident)], |
| 71 | pch=16, |
| 72 | asp = 1) |
| 73 | legend("bottomleft",legend = names(my_color[levels(sce$ident)]), |
| 74 | fill = my_color[levels(sce$ident)]) |
| 75 | lines(SlingshotDataSet(lnes), lwd=2, type = 'lineages', col = c("black")) |
| 76 | |
| 77 | }}} |
| 78 | |