Skip to content

Commit afd54da

Browse files
committed
edits
1 parent a3abf11 commit afd54da

File tree

3 files changed

+107
-137
lines changed

3 files changed

+107
-137
lines changed

vignettes/solutions.Rmd

+14-18
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,42 @@ library(plotly)
1414
library(dplyr)
1515
library(colorspace)
1616
library(dittoSeq)
17+
library(tidySingleCellExperiment)
18+
19+
sce_obj <- bioc2022tidytranscriptomics::sce_obj
1720
```
1821

1922
## Question 1
2023

21-
What is the proportion of gamma-delta T cells, among all cells? Use signature_score > 0.8 to identify gamma-delta T cells.
22-
23-
```{r, eval=FALSE}
24+
What proportion of all cells are gamma-delta T cells? Use signature_score > 0.7 to identify gamma-delta T cells.
2425

25-
seurat_obj |>
26-
26+
```{r}
27+
sce_obj |>
2728
2829
join_features(
2930
features = c("CD3D", "TRDC", "TRGC1", "TRGC2", "CD8A", "CD8B"),
30-
shape = "wide",
31-
assay = "SCT"
32-
31+
shape = "wide"
3332
) |>
3433
3534
mutate(signature_score =
36-
scales::rescale(CD3D + TRDC + TRGC1+ TRGC2, to=c(0,1)) -
35+
scales::rescale(CD3D + TRDC + TRGC1 + TRGC2, to=c(0,1)) -
3736
scales::rescale(CD8A + CD8B, to=c(0,1))
3837
) |>
3938
40-
mutate(is_gamma-delta = signature_score > 0.8) |>
39+
mutate(gamma_delta = signature_score > 0.7) |>
4140
42-
count(is_gamma-delta) %>%
41+
count(gamma_delta) |>
4342
summarise(proportion = n/sum(n))
44-
4543
```
4644

4745
## Question 2
4846

49-
There is a cluster of cells characterised by a low RNA output (nCount_RNA < 100). Identify the cell composition (curated_cell_type) of that cluster.
50-
47+
There is a cluster of cells characterised by a low RNA output (nCount_RNA < 100). Identify the cell composition (cell_type) of that cluster.
5148

52-
```{r, eval=FALSE}
5349

54-
seurat_obj |>
50+
```{r}
51+
sce_obj |>
5552
filter(nCount_RNA < 100) %>%
56-
count(curated_cell_type)
57-
53+
count(cell_type)
5854
```
5955

vignettes/supplementary.Rmd

+24-65
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,27 @@ knitr::opts_chunk$set(echo = TRUE)
1313

1414

1515
```{r message = FALSE}
16+
library(batchelor)
17+
library(igraph)
18+
library(scran)
19+
library(magrittr)
1620
library(ggplot2)
1721
library(plotly)
1822
library(dplyr)
1923
library(colorspace)
2024
library(dittoSeq)
2125
library(tidySingleCellExperiment)
2226
library(tidygate)
23-
```
2427
28+
sce_obj <- bioc2022tidytranscriptomics::sce_obj
29+
```
2530

26-
The gamma delta T cells (the blue cluster on the left with high signature score) could be interactively selected from the plot using the tidygate package.
2731

28-
```{r eval=FALSE}
32+
Instead of filtering using a specified threshold, the gamma delta T cells could be interactively selected from the plot using the tidygate package.
2933

34+
```{r eval = FALSE}
3035
sce_obj |>
3136
32-
3337
join_features(
3438
features = c("CD3D", "TRDC", "TRGC1", "TRGC2", "CD8A", "CD8B" ), shape = "wide"
3539
) |>
@@ -47,10 +51,9 @@ sce_obj |>
4751
4852
```
4953

50-
After the selection we can reload from file the gate drawn for reproducibility.
51-
52-
```{r eval=FALSE}
54+
After the selection we could reload from a file the gate that was drawn, for reproducibility.
5355

56+
```{r}
5457
sce_obj |>
5558
5659
join_features(
@@ -72,12 +75,12 @@ sce_obj |>
7275
7376
```
7477

75-
And the dataset could be filtered for just these cells using tidyverse `filter`.
76-
77-
```{r eval=FALSE}
78-
79-
sce_obj |>
78+
The dataset can be filtered for just these cells using tidyverse `filter`.
8079

80+
```{r}
81+
sce_obj_gamma_delta <-
82+
83+
sce_obj |>
8184
8285
join_features(
8386
features = c("CD3D", "TRDC", "TRGC1", "TRGC2", "CD8A", "CD8B" ), shape = "wide"
@@ -94,68 +97,24 @@ sce_obj |>
9497
filter(gate == 1)
9598
```
9699

97-
It was then possible to perform analyses on these gamma delta T cells by simply chaining further commands, such as below.
100+
For comparison, we show the alternative using base R and SingleCellExperiment.
98101

99-
```{r eval = FALSE}
100-
101-
sce_obj |>
102-
103-
104-
join_features(
105-
features = c("CD3D", "TRDC", "TRGC1", "TRGC2", "CD8A", "CD8B"), shape = "wide"
106-
107-
) |>
108-
109-
mutate(signature_score =
110-
scales::rescale(CD3D + TRDC + TRGC1+ TRGC2, to=c(0,1)) -
111-
scales::rescale(CD8A + CD8B, to=c(0,1))
112-
) |>
113-
114-
mutate( gate = gate_int(UMAP_1, UMAP_2, gate_list = bioc2022tidytranscriptomics::gate_sce_obj) ) |>
115-
116-
filter(gate == 1) |>
117-
118-
# Reanalyse
119-
NormalizeData(assay="RNA") |>
120-
FindVariableFeatures( nfeatures = 100, assay="RNA") |>
121-
SplitObject(split.by = "file") |>
122-
RunFastMNN(assay="RNA") |>
123-
RunUMAP(reduction = "mnn", dims = 1:20) |>
124-
FindNeighbors( dims = 1:20, reduction = "mnn") |>
125-
FindClusters( resolution = 0.3)
126-
```
127-
128-
For comparison, we show the alternative using base R and SingleCellExperiment
129-
130-
```{r eval = FALSE}
131-
132-
counts_positive =
133-
GetAssayData(sce_obj, assay="SCT")[c("CD3D", "TRDC", "TRGC1", "TRGC2"),] |>
102+
```{r}
103+
counts_positive <-
104+
assay(sce_obj)[c("CD3D", "TRDC", "TRGC1", "TRGC2"),] |>
134105
colSums() |>
135106
scales::rescale(to=c(0,1))
136107
137-
counts_negative =
138-
GetAssayData(sce_obj, assay="SCT")[c("CD8A", "CD8B"),] |>
108+
counts_negative <-
109+
assay(sce_obj)[c("CD8A", "CD8B"),] |>
139110
colSums() |>
140111
scales::rescale(to=c(0,1))
141112
142-
sce_obj$signature_score = counts_positive - counts_negative
143-
144-
p = FeaturePlot(sce_obj, features = "signature_score")
113+
sce_obj$signature_score <- counts_positive - counts_negative
145114
146115
# This is not reproducible (in contrast to tidygate)
147-
sce_obj$within_gate = colnames(sce_obj) %in% CellSelector(plot = p)
116+
sce_obj$within_gate <- colnames(sce_obj) %in% CellSelector(plot = p)
148117
149-
sce_obj |>
150-
subset(within_gate == TRUE) |>
151-
152-
# Reanalyse
153-
NormalizeData(assay="RNA") |>
154-
FindVariableFeatures( nfeatures = 100, assay="RNA") |>
155-
SplitObject(split.by = "file") |>
156-
RunFastMNN(assay="RNA") |>
157-
RunUMAP(reduction = "mnn", dims = 1:20) |>
158-
FindNeighbors( dims = 1:20, reduction = "mnn") |>
159-
FindClusters( resolution = 0.3)
118+
sce_obj_gamma_delta <- sce_obj[, sce_obj$within_gate == TRUE]
160119
```
161120

0 commit comments

Comments
 (0)