@@ -13,23 +13,27 @@ knitr::opts_chunk$set(echo = TRUE)
13
13
14
14
15
15
``` {r message = FALSE}
16
+ library(batchelor)
17
+ library(igraph)
18
+ library(scran)
19
+ library(magrittr)
16
20
library(ggplot2)
17
21
library(plotly)
18
22
library(dplyr)
19
23
library(colorspace)
20
24
library(dittoSeq)
21
25
library(tidySingleCellExperiment)
22
26
library(tidygate)
23
- ```
24
27
28
+ sce_obj <- bioc2022tidytranscriptomics::sce_obj
29
+ ```
25
30
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.
27
31
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.
29
33
34
+ ``` {r eval = FALSE}
30
35
sce_obj |>
31
36
32
-
33
37
join_features(
34
38
features = c("CD3D", "TRDC", "TRGC1", "TRGC2", "CD8A", "CD8B" ), shape = "wide"
35
39
) |>
@@ -47,10 +51,9 @@ sce_obj |>
47
51
48
52
```
49
53
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.
53
55
56
+ ``` {r}
54
57
sce_obj |>
55
58
56
59
join_features(
@@ -72,12 +75,12 @@ sce_obj |>
72
75
73
76
```
74
77
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 ` .
80
79
80
+ ``` {r}
81
+ sce_obj_gamma_delta <-
82
+
83
+ sce_obj |>
81
84
82
85
join_features(
83
86
features = c("CD3D", "TRDC", "TRGC1", "TRGC2", "CD8A", "CD8B" ), shape = "wide"
@@ -94,68 +97,24 @@ sce_obj |>
94
97
filter(gate == 1)
95
98
```
96
99
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 .
98
101
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"),] |>
134
105
colSums() |>
135
106
scales::rescale(to=c(0,1))
136
107
137
- counts_negative =
138
- GetAssayData (sce_obj, assay="SCT" )[c("CD8A", "CD8B"),] |>
108
+ counts_negative <-
109
+ assay (sce_obj)[c("CD8A", "CD8B"),] |>
139
110
colSums() |>
140
111
scales::rescale(to=c(0,1))
141
112
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
145
114
146
115
# 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)
148
117
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]
160
119
```
161
120
0 commit comments