diff --git a/vignettes/Session_1_sequencing_assays.Rmd b/vignettes/Session_1_sequencing_assays.Rmd index 113bc13..af2a567 100644 --- a/vignettes/Session_1_sequencing_assays.Rmd +++ b/vignettes/Session_1_sequencing_assays.Rmd @@ -463,9 +463,9 @@ reducedDimNames(spatial_data) reducedDim(spatial_data, "PCA")[1:5, 1:5] ``` -::: note +:::: note As for single-cell data, we need to verify that there is not significant batch effect. If so we need to adjust for it (a.k.a. integration) before calculating principal component. Many adjustment methods to output adjusted principal components directly. -::: +:::: #### UMAP @@ -481,7 +481,7 @@ spatial_data <- scater::runUMAP(spatial_data, dimred = "PCA") scater::plotUMAP(spatial_data, colour_by = "sample_id", point_size = 0.2) ``` -::: note +:::: note **Exercise 1.1** Visualise where the two macro clusters are located spatially. We will take a very pragmatic approach and get cluster label from splitting the UMAP coordinated in two (`colData()` and `reducedDim()` will help us, see above), and then visualise it with `ggspavis`. @@ -489,7 +489,7 @@ Visualise where the two macro clusters are located spatially. We will take a ver - Modify the `SpatialExperiment` object based on the UMAP1 dimension so to divide those 2 cluster - Visualise the UMAP colouring by the new labelling - Visualise the Visium slide colouring by the new labelling -::: +:::: ### 7. Clustering @@ -631,9 +631,9 @@ spe_joint <- do.call(cbind, spatial_data_list) Here, we perform PCA using the BANKSY algorithm on the joint dataset. The group argument specifies how to treat different samples, ensuring that features are scaled separately per sample group to account for variations among them. -::: note +:::: note Note: this step takes long time -::: +:::: ```{r, eval=TRUE, message=FALSE, warning=FALSE} spe_joint <- runBanksyPCA( # Run PCA on the Banskly matrix @@ -732,7 +732,7 @@ ggspavis::plotSpots(spatial_data, annotate = "spatialLIBD") + labs(title = "spatialLIBD regions") ``` -::: note +:::: note **Exercise 1.2** We have applied cluster smoothing using `smoothLabels`. How much do you think this operation has affected the cluster labels. To find out, @@ -740,7 +740,7 @@ We have applied cluster smoothing using `smoothLabels`. How much do you think th - Plot the non smoothed cluster - identify the pixel that have been smoothed, and - visualise them using `plotSpotQC` that we have used above. -::: +:::: ### 8. Deconvolution of pixel-based spatial data @@ -945,24 +945,24 @@ plotCorrelationMatrix(res$mat) #### Excercise -Rather than looking at the correlation matrix, overall, let's observe whether the correlation structure amongst cell types is consistent across samples. Do you think it's consistent or noticably different? -```{r, fig.width=7, fig.height=8} -res_spatialLIBD = split(data.frame(res$mat), colData(spatial_data_gene_name)$sample_id ) +:::: note +**Exercise 1.3** -lapply(res_spatialLIBD, function(x) plotCorrelationMatrix(as.matrix(x[,-10]))) +Rather than looking at the correlation matrix, overall, let's observe whether the correlation structure amongst cell types is consistent across samples. Do you think it's consistent or noticeably different? +:::: -``` -Now let's observe whether the correlation structure is consistent across spatial regions, irrespectively of the sample of origin. Do you think they are consistent or noticably different? +:::: note +**Exercise 1.4** -```{r, fig.width=7, fig.height=8} +Now let's observe whether the correlation structure is consistent across spatial regions, irrespectively of the sample of origin. Do you think they are consistent or noticably different? +:::: -res_spatialLIBD = split(data.frame(res$mat), colData(spatial_data_gene_name)$spatialLIBD ) -lapply(res_spatialLIBD, function(x) plotCorrelationMatrix(as.matrix(x[,-10]))) -``` +:::: note +**Exercise 1.5** Some of the most positive correlations involve the end of cells with Oligodendrocytes and Leptomeningeal cells. @@ -970,31 +970,9 @@ Leptomeningeal cells refer to the cells that make up the leptomeninges, which co Oligodendrocytes are a type of glial cell in the central nervous system (CNS) of vertebrates, including humans and mouse. These cells are crucial for the formation and maintenance of the myelin sheath, a fatty layer that encases the axons of many neurons. -Hello, let's try to visualise the pixel where these cell types most occur. - -```{r, fig.width=7, fig.height=8} - -mat_df = as.data.frame(res$mat) - -is_endothelial_leptomeningeal = mat_df$endothelial_cell >0.1 & mat_df$leptomeningeal_cell>0.1 & mat_df$endothelial_cell + mat_df$leptomeningeal_cell > 0.4 -is_endothelial_oligodendrocytes = mat_df$endothelial_cell >0.1 & mat_df$oligodendrocyte>0.05 & mat_df$endothelial_cell + mat_df$oligodendrocyte > 0.4 - -spatial_data$is_endothelial_leptomeningeal = is_endothelial_leptomeningeal -spatial_data$is_endothelial_oligodendrocyte = is_endothelial_oligodendrocytes - -ggspavis::plotSpots(spatial_data, annotate = "is_endothelial_leptomeningeal") + - facet_wrap(~sample_id) + - scale_color_manual(values = c("TRUE"= "red", "FALSE" = "grey")) -theme(legend.position = "none") + - labs(title = "endothelial + leptomeningeal") - -ggspavis::plotSpots(spatial_data, annotate = "is_endothelial_oligodendrocyte") + - facet_wrap(~sample_id) + - scale_color_manual(values = c("TRUE"= "blue", "FALSE" = "grey")) -theme(legend.position = "none") + - labs(title = "endothelial + oligodendrocyte") +Let's try to visualise the pixel where these cell types most occur. +:::: -``` **Session Information** diff --git a/vignettes/Solutions.Rmd b/vignettes/Solutions.Rmd index d2e440d..177999c 100644 --- a/vignettes/Solutions.Rmd +++ b/vignettes/Solutions.Rmd @@ -22,7 +22,7 @@ knitr::opts_chunk$set(echo = TRUE, cache = FALSE) ```{r, fig.width=7, fig.height=8, eval=FALSE} # Label -colData(spatial_data)$macro_cluster = reducedDim(spatial_data, "UMAP")[,"UMAP1"] > 2.5 +colData(spatial_data)$macro_cluster = reducedDim(spatial_data, "UMAP")[,"UMAP1"] > -2.5 # Verify scater::plotUMAP(spatial_data, colour_by = "macro_cluster", point_size = 0.2) @@ -101,4 +101,48 @@ differential_analysis |> filter(FDR<0.05) # tidybulk::test_differential_abundance(~ dead + sample_id + (1 | spatialLIBD), method = "glmmseq_lme4") +``` + + + + +```{r, fig.width=7, fig.height=8} + +res_spatialLIBD = split(data.frame(res$mat), colData(spatial_data_gene_name)$sample_id ) + +lapply(res_spatialLIBD, function(x) plotCorrelationMatrix(as.matrix(x[,-10]))) + +``` + + +```{r, fig.width=7, fig.height=8} + +res_spatialLIBD = split(data.frame(res$mat), colData(spatial_data_gene_name)$spatialLIBD ) + +lapply(res_spatialLIBD, function(x) plotCorrelationMatrix(as.matrix(x[,-10]))) +``` + + +```{r, fig.width=7, fig.height=8} + +mat_df = as.data.frame(res$mat) + +is_endothelial_leptomeningeal = mat_df$endothelial_cell >0.1 & mat_df$leptomeningeal_cell>0.1 & mat_df$endothelial_cell + mat_df$leptomeningeal_cell > 0.4 +is_endothelial_oligodendrocytes = mat_df$endothelial_cell >0.1 & mat_df$oligodendrocyte>0.05 & mat_df$endothelial_cell + mat_df$oligodendrocyte > 0.4 + +spatial_data$is_endothelial_leptomeningeal = is_endothelial_leptomeningeal +spatial_data$is_endothelial_oligodendrocyte = is_endothelial_oligodendrocytes + +ggspavis::plotSpots(spatial_data, annotate = "is_endothelial_leptomeningeal") + + facet_wrap(~sample_id) + + scale_color_manual(values = c("TRUE"= "red", "FALSE" = "grey")) +theme(legend.position = "none") + + labs(title = "endothelial + leptomeningeal") + +ggspavis::plotSpots(spatial_data, annotate = "is_endothelial_oligodendrocyte") + + facet_wrap(~sample_id) + + scale_color_manual(values = c("TRUE"= "blue", "FALSE" = "grey")) +theme(legend.position = "none") + + labs(title = "endothelial + oligodendrocyte") + ``` \ No newline at end of file