Skip to content

Commit

Permalink
update exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
stemangiola committed May 20, 2024
1 parent 0601d68 commit 24b8f68
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 43 deletions.
62 changes: 20 additions & 42 deletions vignettes/Session_1_sequencing_assays.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -481,15 +481,15 @@ 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`.

- 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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -732,15 +732,15 @@ 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,

- 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

Expand Down Expand Up @@ -945,56 +945,34 @@ 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.

Leptomeningeal cells refer to the cells that make up the leptomeninges, which consist of two of the three layers olet's meninges surrounding the brain and spinal cord: the arachnoid mater and the pia mater. These layers play a critical role in protecting the central nervous system and assisting in various physiological processes.

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**

Expand Down
46 changes: 45 additions & 1 deletion vignettes/Solutions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
```

0 comments on commit 24b8f68

Please sign in to comment.