Skip to content

Commit

Permalink
Updated the vignettes.
Browse files Browse the repository at this point in the history
  • Loading branch information
PratibhaPanwar committed Jul 25, 2024
1 parent 3ee47d9 commit 67bd1f4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 84 deletions.
35 changes: 26 additions & 9 deletions vignettes/MERFISH_mouseHypothalamus.Rmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
# MERFISH mouse preoptic hypothalamus data analysis
---
title: "Multisample analysis"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Getting started: clustSIGNAL}
%\VignetteEngine{knitr::knitr}
%\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
message = FALSE,
warning = FALSE,
comment = "#>"
)
```

Multisample data analysis
# MERFISH mouse preoptic hypothalamus data analysis

```{r}
# load required packages
Expand All @@ -24,7 +41,7 @@ names(colData(spe2))

To run clustSIGNAL, we need the column names of sample and cell IDs in the colData dataframe of the spatial experiment object. Here, the cell IDs are in the column 'Cell_ID' and sample IDs are in 'samples' column.

## run clustSIGNAL
# Run clustSIGNAL

```{r}
set.seed(101)
Expand All @@ -39,7 +56,7 @@ spe2 = res_hyp$spe_final
spe2
```

## calculate clustering metrics
# Calculate clustering metrics

```{r}
samplesList <- levels(spe2[[samples]])
Expand All @@ -64,15 +81,15 @@ spe2$rcSil <- silWidthRC[, 3]
# metrics like adjusted rand index (ARI) and normalised mutual information (NMI)
as.data.frame(colData(spe2)) %>%
group_by(samples) %>%
summarise(ARI = ARI(Cell_class, reCluster),
NMI = NMI(Cell_class, reCluster),
summarise(ARI = aricode::ARI(Cell_class, reCluster),
NMI = aricode::NMI(Cell_class, reCluster),
ASW = mean(rcSil),
min_Entropy = min(entropy),
max_Entropy = max(entropy),
mean_Entropy = mean(entropy))
```

## Visualisation of clustSIGNAL outputs
# Visualise clustSIGNAL outputs

```{r}
colors = c("#635547", "#8EC792", "#9e6762", "#FACB12", "#3F84AA", "#0F4A9C",
Expand Down Expand Up @@ -102,7 +119,7 @@ hst_ent <- as.data.frame(colData(spe2)) %>%
spt_ent <- as.data.frame(colData(spe2)) %>%
ggplot(aes(x = spatialCoords(spe2)[, 1],
y = -spatialCoords(spe2)[, 2])) +
geom_point(size = 1,
geom_point(size = 0.5,
aes(colour = entropy)) +
scale_colour_gradient2("Entropy", low = "grey", high = "blue") +
scale_size_continuous(range = c(0, max(spe2$entropy))) +
Expand All @@ -124,7 +141,7 @@ df_ent = as.data.frame(colData(spe2))
spt_clust <- df_ent %>%
ggplot(aes(x = spatialCoords(spe2)[, 1],
y = -spatialCoords(spe2)[, 2])) +
geom_point(size = 1, aes(colour = reCluster)) +
geom_point(size = 0.5, aes(colour = reCluster)) +
scale_color_manual(values = colors) +
facet_wrap(vars(samples), scales = "free", nrow = 1) +
labs(x = "x-coordinate", y = "y-coordinate") +
Expand Down
59 changes: 0 additions & 59 deletions vignettes/clustSIGNAL_gettingStarted.Rmd

This file was deleted.

26 changes: 10 additions & 16 deletions vignettes/seqFISH_mouseEmbryo.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Getting started: clustSIGNAL"
title: "Single sample analysis"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
Expand All @@ -17,9 +17,7 @@ knitr::opts_chunk$set(
)
```

# Introduction

clustSIGNAL (clustering of Spatially Informed Gene expression with Neighborhood Adapted Learning) is an R package for a spatial clustering method that takes into account the heterogeneity of cell neighborhoods.
# SeqFISH mouse embryo data analysis

```{r}
# load required packages
Expand All @@ -32,10 +30,6 @@ library(ggplot2)
library(patchwork)
```

# SeqFISH mouse embryo data analysis

Single sample data analysis

```{r}
data(mouseEmbryo2)
spe
Expand All @@ -47,7 +41,7 @@ names(colData(spe))

To run clustSIGNAL, we need the column names of sample and cell labels in the colData dataframe of the spatial experiment object. Here, the cell labels are in the column 'uniqueID' and sample labels are in 'embryo' column.

## Running clustSIGNAL
# Run clustSIGNAL

```{r}
set.seed(100)
Expand All @@ -72,7 +66,7 @@ spe = res_emb$spe_final
spe
```

## Calculating clustering metrics
# Calculate clustering metrics

```{r}
# calculating silhouette width
Expand All @@ -85,15 +79,15 @@ spe$rcSil <- silCluster[, 3]
# for datasets with annotated cell type information, we can also calculate
# metrics like adjusted rand index (ARI) and normalised mutual information (NMI)
as.data.frame(colData(spe)) %>%
summarise(ARI = ARI(celltype_mapped_refined, reCluster),
NMI = NMI(celltype_mapped_refined, reCluster),
summarise(ARI = aricode::ARI(celltype_mapped_refined, reCluster),
NMI = aricode::NMI(celltype_mapped_refined, reCluster),
ASW = mean(rcSil),
min_Entropy = min(entropy),
max_Entropy = max(entropy),
mean_Entropy = mean(entropy))
```

## Visualising clustSIGNAL outputs
# Visualise clustSIGNAL outputs

```{r}
colors = c("#635547", "#8EC792", "#9e6762", "#FACB12", "#3F84AA", "#0F4A9C",
Expand Down Expand Up @@ -122,7 +116,7 @@ hst_ent <- as.data.frame(colData(spe)) %>%
spt_ent <- as.data.frame(colData(spe)) %>%
ggplot(aes(x = spatialCoords(spe)[, 1],
y = -spatialCoords(spe)[, 2])) +
geom_point(size = 1,
geom_point(size = 0.5,
aes(colour = entropy)) +
scale_colour_gradient2("Entropy", low = "grey", high = "blue") +
scale_size_continuous(range = c(0, max(spe$entropy))) +
Expand All @@ -143,7 +137,7 @@ df_ent = as.data.frame(colData(spe))
spt_clust <- df_ent %>%
ggplot(aes(x = spatialCoords(spe)[, 1],
y = -spatialCoords(spe)[, 2])) +
geom_point(size = 1, aes(colour = reCluster)) +
geom_point(size = 0.5, aes(colour = reCluster)) +
scale_color_manual(values = colors) +
ggtitle("Spatial distribution of clusters") +
labs(x = "x-coordinate", y = "y-coordinate") +
Expand Down Expand Up @@ -175,5 +169,5 @@ box_clust <- df_ent %>%
text = element_text(size = 15),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
spt_clust + box_clust + plot_layout(guides = "collect", widths = c(1, 2))
spt_clust + box_clust + patchwork::plot_layout(guides = "collect", widths = c(1, 2))
```

0 comments on commit 67bd1f4

Please sign in to comment.