--- title: "Slingshot" author: "Nina-Lydia Kazakou" date: "08/07/2021" output: html_document --- # Load libraries ```{r} library(slingshot) library(scales) library(Seurat) library(ggplot2) library(RColorBrewer) library(Seurat) ``` # Set the colour pallete ```{r} mypal <- pal_npg("nrc", alpha = 0.7)(10) mypal2 <-pal_tron("legacy", alpha = 0.7)(7) mypal3 <- pal_lancet("lanonc", alpha = 0.7)(9) mypal4 <- pal_simpsons(palette = c("springfield"), alpha = 0.7)(16) mypal5 <- pal_rickandmorty(palette = c("schwifty"), alpha = 0.7)(6) mypal6 <- pal_futurama(palette = c("planetexpress"), alpha = 0.7)(5) mypal7 <- pal_startrek(palette = c("uniform"), alpha = 0.7)(5) mycoloursP<- c(mypal, mypal2, mypal3, mypal4, mypal5, mypal6, mypal7) show_col(mycoloursP, labels =F) ``` # Load object ```{r} alt.co.oligos <- readRDS(here("data", "Oligos_only", file = "alt.co.oligos.rds")) head(alt.co.oligos.rds@meta.data) Idents(alt.co.oligos.rds) <- "ClusterID" DimPlot(alt.co.oligos.rds, cols = mycoloursP, pt.size = 1, label = TRUE) & NoAxes() ``` # Slingshot does not support ggplot2. Workaround: ```{r} cell_pal <- function(cell_vars, pal_fun,...) { if (is.numeric(cell_vars)) { pal <- pal_fun(100, ...) return(pal[cut(cell_vars, breaks = 100)]) } else { categories <- sort(unique(cell_vars)) pal <- setNames(pal_fun(length(categories), ...), categories) return(pal[cell_vars]) } } ``` # Run Slingshot on the whole oligo_subset ```{r} # For the whole dataset, I will set as starting point the primitive OPCs (cluster 0) sds_alt.co.oligos <- slingshot(Embeddings(alt.co.oligos, "umap"), clusterLabels = alt.co.oligos$ClusterID, start.clus = 0, stretch = 0) cell_colors_clust <- cell_pal(alt.co.oligos$ClusterID, hue_pal()) plot(reducedDim(sds_alt.co.oligos), col = cell_colors_clust, pch = 16, cex = 0.5) lines(sds_alt.co.oligos, lwd = 2, type = 'lineages', col = 'black') ``` # Create a slingshot trajectory for each timepoint seperately ```{r} # Week 16 Idents(alt.co.oligos) <- "Sample" week_16 <- subset(alt.co.oligos, ident = "wk16") sds_week_16 <- slingshot(Embeddings(week_16, "umap"), clusterLabels = week_16$ClusterID, start.clus = 0, stretch = 0) cell_colors_clust <- cell_pal(week_16$ClusterID, hue_pal()) plot(reducedDim(sds_week_16), col = cell_colors_clust, pch = 16, cex = 0.5) lines(sds_week_16, lwd = 2, type = 'lineages', col = 'black') ``` ```{r} # Week 21 Idents(alt.co.oligos) <- "Sample" week_21 <- subset(alt.co.oligos, ident = "wk21") sds_week_21 <- slingshot(Embeddings(week_21, "umap"), clusterLabels = week_21$ClusterID, start.clus = 0, stretch = 0) cell_colors_clust <- cell_pal(week_21$ClusterID, hue_pal()) plot(reducedDim(sds_week_21), col = cell_colors_clust, pch = 16, cex = 0.5) lines(sds_week_21, lwd = 2, type = 'lineages', col = 'black') ``` ```{r} # Week 25 Idents(alt.co.oligos) <- "Sample" week_25 <- subset(alt.co.oligos, ident = "wk25") sds_week_25 <- slingshot(Embeddings(week_25, "umap"), clusterLabels = week_25$ClusterID, start.clus = 0, stretch = 0) cell_colors_clust <- cell_pal(week_25$ClusterID, hue_pal()) plot(reducedDim(sds_week_25), col = cell_colors_clust, pch = 16, cex = 0.5) lines(sds_week_25, lwd = 2, type = 'lineages', col = 'black') ```