Skip to content

Commit

Permalink
adds spatially variable feature seelection
Browse files Browse the repository at this point in the history
  • Loading branch information
Geert van Geest committed Jun 14, 2024
1 parent 4871b20 commit 39963e1
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 20 deletions.
7 changes: 5 additions & 2 deletions 2_quality_control.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,13 @@ SpatialPlot(seu, cells.highlight = cells_nfeature_keep,
Now, we remove the spots, and visualize the spots that are left over:

```{r}
#| message: FALSE
#| warning: FALSE
seu <- seu[, seu$percent_mt_keep & seu$nFeature_Spatial_keep]
SpatialPlot(seu, alpha = 0.5, group.by = "percent_mt_keep") +
plot_layout(guides='collect') & theme(legend.position = "none")
SpatialPlot(seu, group.by = "percent_mt_keep", pt.size.factor = 2.5) +
plot_layout(guides='collect') & theme(legend.position = "none") &
scale_fill_manual(values = c("black"))
```

### Gene-level QC
Expand Down
6 changes: 3 additions & 3 deletions 3_normalization_scaling.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ Showing us that an assay called `SCT` has appeared.

:::

Now that we have done the transformation it is also possible to plot gene experssion information in a spatial context, e.g. `Ttr`:
Now that we have done the transformation it is also possible to plot gene experssion information in a spatial context, e.g. `Calb2`:

```{r}
SpatialPlot(seu_list$Anterior,
features = "Ttr") +
features = "Calb2") +
SpatialPlot(seu_list$Posterior,
features = "Ttr") +
features = "Calb2") +
plot_layout(guides = "collect") &
theme(legend.position = "right")
```
Expand Down
95 changes: 80 additions & 15 deletions 5_marker_gene_identification.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,33 @@ SpatialPlot(seu,
::: {.callout-important}
## Exercise

Do the same for cluster 0. What is the top marker? Can you guess what kind of tissue this is?
What kind of tissue is cluster 7 you think? Does the mouse brain atlas show similar patterns for this gene?

Compare the expression to the images at [Allen Brain Atlas](http://atlas.brain-map.org/atlas?atlas=2&plate=100883804#atlas=2&plate=100884129&resolution=19.04&x=7671.818403764205&y=4000&zoom=-4&structure=549) to figure out the tissue type.

To compare the expression, go to [mouse.brain-map.org](https://mouse.brain-map.org/), type the gene name in the search box. Select the gene entry in the sagittal plane, click 'View selections' at the left bottom of the page. Select a similar slice (i.e. in the middle of the brain).



:::

::: {.callout-tip collapse="true"}
## Answer

Based on the comparison of the brain atlas it seems to be layer 2/3 of the isocortex.

It has similar expression based on in-situ hybridization from the brain atlas. Also expression in the striatium and medulla correspond.

![](assets/images/Lamp5_sagittal_ISH.png)

:::

::: {.callout-important}
## Exercise

Create the same visualization for cluster 0. What is the top marker? Can you guess what kind of cells this tissue is mostly comprised of?

The marker is expressed in many spots, and therefore it is not part of specific cell groups. Therefore, check out the gene at e.g. wikipedia.

:::

Expand All @@ -105,26 +131,65 @@ SpatialPlot(seu,
features = top_markers$gene[top_markers$cluster == 0][1],
pt.size.factor = 2)
```

The top gene is [Plp1](https://en.wikipedia.org/wiki/Proteolipid_protein_1) which protein is an important component of the myelin sheets of neurons. Therefore cluster 0 seems to represent the white matter of the brain.

:::


## Bonus exercise: spatially variable features

In stead of looking for features that are variable among all spots, you can also identify that mainly vary in space, i.e. while taking spot distance into account:

```{r}
#| warning: FALSE
#| message: FALSE
#| output: FALSE
# take the output of part 3 (non-integrated and non-clustered)
seu_list <- readRDS("output/seu_part3.rds")
# we only do Anterior for now
DefaultAssay(seu_list$Anterior) <- "SCT"
seu_list$Anterior <-
FindSpatiallyVariableFeatures(
seu_list$Anterior,
selection.method = "moransi",
features = VariableFeatures(seu_list$Anterior)
)
spatialFeatures <-
SVFInfo(seu_list$Anterior, method = "moransi", status = TRUE)
spatialFeatures <-
spatialFeatures |> arrange(rank)
```

::: {.callout-important}
## Exercise

Run the code and plot the top spatial variable genes.

<!-- ```{r} -->
<!-- DefaultAssay(seu_list$Anterior) <- "SCT" -->
The spatial features are ordered already ordered, so you can get them with e.g.

<!-- seu_list$Anterior <- -->
<!-- FindSpatiallyVariableFeatures( -->
<!-- seu_list$Anterior, -->
<!-- features = rownames(seu), -->
<!-- selection.method = "moransi" -->
<!-- ) -->
```{r}
#| eval: FALSE
rownames(spatialFeatures)[1:4]
```

<!-- spatialFeatures <- -->
<!-- SVFInfo(seu_list$Anterior, method = "moransi", status = TRUE) -->
<!-- spatialFeatures <- -->
<!-- spatialFeatures |> arrange(rank) -->
Any interesting marker genes in there?

<!-- SpatialPlot(seu_list$Anterior, features = rownames(spatialFeatures)[1:6], ncol = 3, alpha = c(0.1, 1)) -->
<!-- ``` -->
:::

::: {.callout-tip collapse="true"}
## Answer

```{r}
SpatialPlot(seu_list$Anterior,
features = rownames(spatialFeatures)[1:4],
ncol = 2)
```
:::
Binary file added assets/images/Lamp5_sagittal_ISH.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 39963e1

Please sign in to comment.