Skip to main content
. 2021 May 24;37(22):4100–4107. doi: 10.1093/bioinformatics/btab404

Table 3.

Case study for the detection of gamma delta T cells among lymphoid cells

Step Seurat tidyseurat
Create and visualize signature in UMAP dimension
Score signature signature_score_1 =
  •  seurat_obj[c(“CD3D”, “TRDC”, “TRGC1”, “TRGC2”),] %>%

  •  Seurat::GetAssayData(assay=“SCT”, slot=“data”) %>%

  •  colSums() %>%

  •  scales::rescale(to=c(0,1))

  • signature_score_2 =

  •  seurat_obj[c(“CD8A”, “CD8B”),] %>%

  •  Seurat::GetAssayData(assay=“SCT”, slot=“data”) %>%

  •  colSums() %>%

  •  scales::rescale(to=c(0,1))

  • seurat_obj$signature_score =

  •  signature_score_1 - signature_score_2

seurat_obj_sig = seurat_obj %>%
  •  join_features(

  •  features =

  •   c(“CD3D”, “TRDC”, “TRGC1”, “TRGC2”,   “CD8A”, “CD8B”),

  •   shape = “wide”,

  •   assay = “SCT”

  •  ) %>%

  •  mutate(signature_score =

  •   scales::rescale(CD3D + TRDC + TRGC1 +    TRGC2, to=c(0,1)) -

  •   scales::rescale(CD8A + CD8B, to=c(0,1))

  •  )

Subsample splits = colnames(seurat_obj) %>%
  •  split(seurat_obj$sample)

  • min_size = splits %>%

  •  sapply(length) %>% min()

  • cell_subset = splits %>%

  •  lapply(function(x) sample(x, min_size)) %>%

  •  unlist()

  • seurat_obj = seurat_obj[, cell_subset]

seurat_obj_sig %>%
  •  add_count(sample, name = “tot_cells”) %>%

  •  mutate(min_cells = min(tot_cells)) %>%

  •  group_by(sample) %>%

  •  sample_n(min_cells) %>%

Plot Seurat::FeaturePlot(
  •  seurat_obj,

  •  features = c(“signature_score”, “CD3D”, “TRDC”, “TRGC1”,  “TRGC2”, “CD8A”, “CD8B”),

  •  split.by = “type”,

  •  min.cutoff = 0.1

  • )

  • pivot_longer(cols=c(“CD3D”, “TRDC”, “TRGC1”, “TRGC2”, “CD8A”, “CD8B”, “signature_score”)) %>%

  •  group_by(name) %>%

  •  mutate(value = scale(value)) %>%

  •  ggplot(aes(UMAP_1, UMAP_2, color=value)) +

  •  geom_point() +

  •  facet_grid(type∼name)

Gate cells and visualize cell proportions biological conditions
Gate cells p = Seurat::FeaturePlot(seurat_obj, features = “signature_score”)
  • seurat_obj$within_gate = colnames(seurat_obj) %in% CellSelector(plot = p)

  • seurat_obj[[]] %>% # Pass object to plot

seurat_obj_sig %>%
  •  mutate(gamma_delta = tidygate::gate_chr(

  •   UMAP_1, UMAP_2, .color = signature_score

  • )) %>%

Proportion (common)  add_count(sample, name = “tot_cells”) %>%
  •  count(sample, type, tot_cells, within_gate) %>%

  •  mutate(frac = n/tot_cells) %>%

  •  filter(within_gate == T) %>%

Plot (common)
  •  ggplot(aes(type, frac)) +

  •  geom_boxplot() +

  •  geom_point()

Note: Both Seurat and tidyseurat style coding is shown.