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 %>%
|
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_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)
|
|