Changes between Initial Version and Version 1 of SOP/scRNA-seq/diffusionMaps


Ignore:
Timestamp:
10/05/20 14:20:20 (4 years ago)
Author:
ibarrasa
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SOP/scRNA-seq/diffusionMaps

    v1 v1  
     1
     2=== Making diffusion maps with destiny ===
     3
     4Seurat v3 doesn't have a function to make diffusion maps anymore. The alternatives are to 1) run the analysis in python using scanpy or 2) make a single cell object, i.e. from the Seurat object, and run the "DiffusionMap" function from the destiny package. Example commands for the second option are shown below.
     5 
     6  * **Making a single cell object from a Seurat object**
     7{{{
     8library(Seurat)
     9library(SingleCellExperiment)
     10sce <- as.SingleCellExperiment(seuratObject)
     11#this has the cell classification
     12table(sce$ident)
     13}}}
     14
     15  * **Running diffusion map**
     16<code>
     17#this step may take a long time (days) or not finish. It is recommend to send it to the cluster as a script that reads the Seurat or the single cell object, runs DiffusionMap, and saves the object.
     18library(destiny)
     19dm <- DiffusionMap(sce, verbose = TRUE)
     20}}}
     21
     22  * **Plotting the diffusion map**
     23{{{
     24library(ggplot2)
     25cellLabels <- sce$ident
     26tmp <- data.frame(DC1 = eigenvectors(dm)[, 1],
     27                  DC2 = eigenvectors(dm)[, 2],
     28                  DC3 = eigenvectors(dm)[, 3],
     29                  DC4 = eigenvectors(dm)[, 4],
     30                  Samples = cellLabels)
     31pdf("./DC1_DC2.pdf", w=11, h=8.5)
     32ggplot(tmp, aes(x = DC1, y = DC2, colour = Samples)) +
     33  geom_point()  +
     34  xlab("Diffusion component 1") +
     35  ylab("Diffusion component 2") +
     36  theme_classic()
     37dev.off()
     38}}}
     39  * **Plotting cell progression along the diffusion map components**
     40{{{
     41sce$pseud_dm1 <- rank(eigenvectors(dm)[,1])      # rank cells by their dpt dm1
     42sce$pseud_dm2 <- rank(eigenvectors(dm)[,2])      # rank cells by their dpt dm2
     43sce$pseud_dm1R <- rank(-eigenvectors(dm)[,1])    # rank cells by their dpt dm1 reverse order
     44sce$pseud_dm2R <- rank(-eigenvectors(dm)[,2])    # rank cells by their dpt dm2 reverse order
     45
     46SortedDM1 <- data.frame(DM1Sort = as.data.frame(colData(sce))$pseud_dm1,
     47                        Samples = as.data.frame(colData(sce))$ident)
     48SortedDM2 <- data.frame(DM2Sort = as.data.frame(colData(sce))$pseud_dm2,
     49                        Samples = as.data.frame(colData(sce))$ident)
     50SortedDM1R <- data.frame(DM1SortR = as.data.frame(colData(sce))$pseud_dm1R,
     51                         Samples = as.data.frame(colData(sce))$ident)
     52SortedDM2R <- data.frame(DM2SortR = as.data.frame(colData(sce))$pseud_dm2R,
     53                         Samples = as.data.frame(colData(sce))$ident)
     54
     55ggplot(SortedDM1, aes(x=SortedDM1[,1], y=Samples,color=Samples)) +
     56  geom_jitter() + xlab("Diffusion component 1 (DC1)") + ylab("Samples") +
     57  ggtitle("Cells ordered by DC1")
     58ggplot(SortedDM2, aes(x=SortedDM2[,1], y=Samples,color=Samples)) +
     59  geom_jitter() + xlab("Diffusion component 2 (DC2)") + ylab("Samples") +
     60  ggtitle("Cells ordered by DC2")
     61 
     62ggplot(SortedDM1R, aes(x=SortedDM1R[,1], y=Samples,color=Samples)) +
     63  geom_jitter() + xlab("Minus Diffusion component 1 (DC1)") + ylab("Samples") +
     64  ggtitle("Cells ordered by reversed DC1")
     65ggplot(SortedDM2R, aes(x=SortedDM2R[,1], y=Samples,color=Samples)) +
     66  geom_jitter() + xlab("Minus Diffusion component 2 (DC2)") + ylab("Samples") +
     67  ggtitle("Cells ordered by reversed DC2")
     68}}}
     69
     70  * **Make and interactive 2D and 3D diffusion map figure**
     71{{{
     72library(plotly)
     73
     74#interactive 2D
     75p2 = plot_ly(x=tmp$DC1, y=tmp$DC2, type="scatter", mode="markers", color=tmp$Samples, marker.size = 0.5)
     76htmlwidgets::saveWidget(as_widget(p2), "Interactive2D_DiffM.html", title = "Diffusion map")
     77
     78#interactive 3D
     79p = plot_ly(x=tmp$DC1, y=tmp$DC2, z=tmp$DC3, type="scatter3d", mode="markers", color=tmp$Samples, marker = list(size = 2 ))
     80htmlwidgets::saveWidget(as_widget(p), "Interactive3D.html", title = "Diffusion map")
     81
     82}}}
     83
     84{{{
     85
     86}}}