Instead of filtering using a specified threshold, the gamma delta T cells could be interactively selected from the plot using the tidygate package.

sce_obj |>

  join_features(
    features = c("CD3D", "TRDC", "TRGC1", "TRGC2", "CD8A", "CD8B" ), shape = "wide"
  ) |>

  mutate(signature_score =
           scales::rescale(CD3D + TRDC + TRGC1+ TRGC2, to=c(0,1)) -
           scales::rescale(CD8A + CD8B, to=c(0,1))
  ) |>

  mutate(gate = gate_int(
    UMAP_1, UMAP_2,
    .size = 0.1,
    .color =signature_score
  ))

After the selection we could reload from a file the gate that was drawn, for reproducibility.

sce_obj |>

  join_features(
    features = c("CD3D", "TRDC", "TRGC1", "TRGC2", "CD8A", "CD8B" ), shape = "wide"

  ) |>

  mutate(signature_score =
           scales::rescale(CD3D + TRDC + TRGC1+ TRGC2, to=c(0,1)) -
           scales::rescale(CD8A + CD8B, to=c(0,1))
  ) |>

  mutate(gate = gate_int(
    UMAP_1, UMAP_2,
    .size = 0.1,
    .color =signature_score,
    gate_list = bioc2022tidytranscriptomics::gate_sce_obj
  ))
## # A SingleCellExperiment-tibble abstraction: 3,580 × 26
## # Features=482 | Cells=3580 | Assays=counts, logcounts
##    .cell      Barcode batch BCB    S.Score G2M.S…¹ Phase cell_…² nCoun…³ nFeat…⁴
##    <chr>      <fct>   <fct> <fct>    <dbl>   <dbl> <fct> <fct>     <int>   <int>
##  1 1_AAATGGA… AAATGG… 1     BCB1… -2.07e-2 -0.0602 G1    TCR_V_…     215      36
##  2 1_AACAAGA… AACAAG… 1     BCB1…  2.09e-2 -0.0357 S     CD8+_t…     145      41
##  3 1_AACGTCA… AACGTC… 1     BCB1… -2.54e-2 -0.133  G1    CD8+_h…     356      44
##  4 1_AACTTCT… AACTTC… 1     BCB1…  2.85e-2 -0.163  S     CD8+_t…     385      58
##  5 1_AAGTCGT… AAGTCG… 1     BCB1… -2.30e-2 -0.0581 G1    MAIT        352      42
##  6 1_AATGAAG… AATGAA… 1     BCB1…  1.09e-2 -0.0621 S     CD4+_r…     335      40
##  7 1_ACAAAGA… ACAAAG… 1     BCB1… -2.06e-2 -0.0409 G1    CD4+_T…     242      39
##  8 1_ACACGCG… ACACGC… 1     BCB1… -3.95e-4 -0.176  G1    CD8+_h…     438      45
##  9 1_ACATGCA… ACATGC… 1     BCB1… -4.09e-2 -0.0829 G1    CD4+_r…     180      39
## 10 1_ACGATCA… ACGATC… 1     BCB1…  8.82e-2 -0.0397 S     CD4+_r…      82      34
## # … with 3,570 more rows, 16 more variables: nCount_SCT <int>,
## #   nFeature_SCT <int>, ident <fct>, file <chr>, treatment <chr>,
## #   sample <glue>, CD3D <dbl>, TRDC <dbl>, TRGC1 <dbl>, TRGC2 <dbl>,
## #   CD8A <dbl>, CD8B <dbl>, signature_score <dbl>, gate <int>, UMAP_1 <dbl>,
## #   UMAP_2 <dbl>, and abbreviated variable names ¹​G2M.Score, ²​cell_type,
## #   ³​nCount_RNA, ⁴​nFeature_RNA
## # ℹ Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names

The dataset can be filtered for just these cells using tidyverse filter.

sce_obj_gamma_delta <-
    
  sce_obj |>

  join_features(
    features = c("CD3D", "TRDC", "TRGC1", "TRGC2", "CD8A", "CD8B" ), shape = "wide"

  ) |>

  mutate(signature_score =
           scales::rescale(CD3D + TRDC + TRGC1+ TRGC2, to=c(0,1)) -
           scales::rescale(CD8A + CD8B, to=c(0,1))
  ) |>

  mutate(gate = gate_int(UMAP_1, UMAP_2, gate_list = bioc2022tidytranscriptomics::gate_sce_obj)) |>

  filter(gate == 1)