library(SingleCellExperiment)
library(ggplot2)
library(plotly)
library(dplyr)
library(colorspace)
library(dittoSeq)
library(tidyseurat)

seurat_obj <- RMedicine2023tidytranscriptomics::seurat_obj

Question 1

What proportion of all cells are gamma-delta T cells? Use signature_score > 0.7 to identify gamma-delta T cells.

seurat_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(gamma_delta = signature_score > 0.7) |>
  
  count(gamma_delta) |> 
  summarise(proportion = n/sum(n))
## tidyseurat says: A data frame is returned for independent data analysis.
## Warning: Returning more (or less) than 1 row per `summarise()` group was deprecated in
## dplyr 1.1.0.
##  Please use `reframe()` instead.
##  When switching from `summarise()` to `reframe()`, remember that `reframe()`
##   always returns an ungrouped data frame and adjust accordingly.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## # A tibble: 2 × 1
##   proportion
##        <dbl>
## 1    0.997  
## 2    0.00256

Question 2

There is a cluster of cells characterised by a low RNA output (nCount_RNA < 100). Identify the cell composition (cell_type) of that cluster.

seurat_obj |>
    filter(nCount_RNA < 100) %>% 
    count(curated_cell_type)
## tidyseurat says: A data frame is returned for independent data analysis.
## # A tibble: 3 × 2
##   curated_cell_type                 n
##   <chr>                         <int>
## 1 CD4+_Tcm_S100A4_IL32_IL7R_VIM     1
## 2 CD8+_Tcm                         12
## 3 MAIT                              1