@@ -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)
1620library(ggplot2)
1721library(plotly)
1822library(dplyr)
1923library(colorspace)
2024library(dittoSeq)
2125library(tidySingleCellExperiment)
2226library(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}
3035sce_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}
5457sce_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