|
a |
|
b/scripts/CD3+_space.Rmd |
|
|
1 |
--- |
|
|
2 |
title: "CD3+ cells" |
|
|
3 |
author: "Ming Tang" |
|
|
4 |
date: '2023-07-26' |
|
|
5 |
output: html_document |
|
|
6 |
--- |
|
|
7 |
|
|
|
8 |
```{r} |
|
|
9 |
library(devtools) |
|
|
10 |
library(Seurat) |
|
|
11 |
library(tidyverse) |
|
|
12 |
library(presto) |
|
|
13 |
library(here) |
|
|
14 |
library(tictoc) |
|
|
15 |
library(ComplexHeatmap) |
|
|
16 |
# presto is much faster than Seurat::FindAllMarkers |
|
|
17 |
# install_github('immunogenomics/presto') |
|
|
18 |
``` |
|
|
19 |
|
|
|
20 |
|
|
|
21 |
Read in the Seurat object |
|
|
22 |
|
|
|
23 |
```{r} |
|
|
24 |
cd3_plus_annotated<- readRDS(here("data/cd3_plus_annotated_seurat_subcluster.rds")) |
|
|
25 |
``` |
|
|
26 |
|
|
|
27 |
### whole CD3+ subset |
|
|
28 |
|
|
|
29 |
|
|
|
30 |
```{r} |
|
|
31 |
|
|
|
32 |
annotation_colors<-c("#3366cc", "#7d5378", "#c83e27", "#e7580c", "#f68104", "#cc9803", "#649710", "#1d8723", "#58455b", "#950395", "#5740ab", "#1882bf", "#427fae", "#a4598a", "#c55660", "#92842c", "#6ba103", "#8e6a17", "#855499", "#814256", "#465a84", "#4e5a96", "#7b4c97", "#7b4c97", "#29aa92", "#b4332b", "#a0aa1b", "#907d56") |
|
|
33 |
|
|
|
34 |
# Figure 1a |
|
|
35 |
DimPlot(cd3_plus_annotated, group.by = "clusters_anno_sub", cols = annotation_colors) |
|
|
36 |
|
|
|
37 |
|
|
|
38 |
# supp Figure 2 |
|
|
39 |
set.seed(123) |
|
|
40 |
library(ComplexHeatmap) |
|
|
41 |
|
|
|
42 |
clusters<- cd3_plus_annotated@meta.data$clusters_anno_sub%>%unique() |
|
|
43 |
|
|
|
44 |
markers<- presto::wilcoxauc(cd3_plus_annotated, 'clusters_anno_sub', assay = 'data', |
|
|
45 |
groups_use = clusters) |
|
|
46 |
|
|
|
47 |
markers %>% |
|
|
48 |
arrange(desc(auc)) %>% |
|
|
49 |
filter(pct_in> 20, pct_out < 30) %>% |
|
|
50 |
head() |
|
|
51 |
|
|
|
52 |
top_markers_unique<- filter(markers, padj <=0.05, abs(logFC) >=0.8) %>% |
|
|
53 |
pull(feature) %>% |
|
|
54 |
unique() |
|
|
55 |
|
|
|
56 |
## for plotting heatmap, subsample the seurat object, 100000 or 5000 cells |
|
|
57 |
cd3_plus_annotated_sub<- cd3_plus_annotated[, sample.int(ncol(cd3_plus_annotated), size = 10000)] |
|
|
58 |
|
|
|
59 |
all_cells<- cd3_plus_annotated_sub@meta.data$clusters_anno_sub %in% clusters |
|
|
60 |
|
|
|
61 |
all_mat<- cd3_plus_annotated_sub[["RNA"]]@data[top_markers_unique, all_cells ] %>% as.matrix() |
|
|
62 |
|
|
|
63 |
## scale the rows |
|
|
64 |
all_mat<- t(scale(t(all_mat))) |
|
|
65 |
|
|
|
66 |
cluster_anno<- cd3_plus_annotated_sub@meta.data$clusters_anno_sub[all_cells] |
|
|
67 |
|
|
|
68 |
column_ha2<- HeatmapAnnotation( |
|
|
69 |
cluster_anno = cluster_anno, |
|
|
70 |
col = list(cluster_anno = setNames(annotation_colors, sort(clusters))), |
|
|
71 |
na_col = "grey", |
|
|
72 |
show_annotation_name = TRUE |
|
|
73 |
) |
|
|
74 |
|
|
|
75 |
|
|
|
76 |
quantile(all_mat, c(0.1, 0.5, 0.95, 0.99)) |
|
|
77 |
|
|
|
78 |
PurpleAndYellow() |
|
|
79 |
#col_fun = colorRamp2(c(-1, 0, 2), c("blue", "white", "red")) |
|
|
80 |
#col_fun = circlize::colorRamp2(c(-1, 0, 2), c("#FF00FF", "black", "#FFFF00")) |
|
|
81 |
|
|
|
82 |
col_fun<- circlize::colorRamp2(c(-1, 0, 2), c("#440154FF", "#238A8DFF", "#FDE725FF")) |
|
|
83 |
|
|
|
84 |
## for big matrix, raster helps. https://jokergoo.github.io/2020/06/30/rasterization-in-complexheatmap/ |
|
|
85 |
## cluster the slice (without specifiying the factor level) and the columns. |
|
|
86 |
|
|
|
87 |
# can not directly rotate column titles (cluster annotation) for 45, has to use decorate() function, see |
|
|
88 |
# https://github.com/jokergoo/ComplexHeatmap/issues/189 |
|
|
89 |
|
|
|
90 |
pdf(here("results/figures/2022-04-14_cd3_plus_all_clusters_marker_gene_heatmap_remake_new_color.pdf"), width = 16, height = 18) |
|
|
91 |
Heatmap(all_mat, name = "Expression", |
|
|
92 |
column_split = factor(cluster_anno), |
|
|
93 |
cluster_columns = TRUE, |
|
|
94 |
show_column_dend = FALSE, |
|
|
95 |
cluster_column_slices = TRUE, |
|
|
96 |
row_dend_reorder = TRUE, |
|
|
97 |
column_title_gp = gpar(fontsize = 6), |
|
|
98 |
column_title_rot = 90, |
|
|
99 |
column_gap = unit(0.5, "mm"), |
|
|
100 |
cluster_rows = TRUE, |
|
|
101 |
column_dend_reorder = TRUE, |
|
|
102 |
show_row_dend = FALSE, |
|
|
103 |
col = col_fun, |
|
|
104 |
row_km = 20, |
|
|
105 |
row_gap = unit(0.5, "mm"), |
|
|
106 |
row_title = NULL, |
|
|
107 |
row_names_gp = gpar(fontsize = 6), |
|
|
108 |
top_annotation = column_ha2, |
|
|
109 |
show_column_names = FALSE, |
|
|
110 |
use_raster = TRUE, |
|
|
111 |
raster_by_magick = TRUE, |
|
|
112 |
raster_quality = 10) |
|
|
113 |
dev.off() |
|
|
114 |
|
|
|
115 |
StackedVlnPlot(cd3_plus_annotated, features = top_markers_unique, idents = c(0:25, 27,28)) |
|
|
116 |
ggsave(here("results/figures/cd3_plus_clusters_marker_gene_stacked_violin.pdf"), width = 6, height = 10) |
|
|
117 |
``` |
|
|
118 |
|
|
|
119 |
### clustered dotplot |
|
|
120 |
|
|
|
121 |
|
|
|
122 |
```{r} |
|
|
123 |
source(here("src/cluster_dotplot.R")) |
|
|
124 |
|
|
|
125 |
cd3_genes<- c("IFNG", "IL12A", "LAG3", "CD274", "IL4", "PDCD1", "CCR5", "IL32", "IL10", "HAVCR2", "IRF4", "GZMB", "TBX21", "PRF1", "TGFB1", "KLRG1", "TRGC1", "TRGC2", "TRDC", "B3GAT1", "KLRB1", "RORC", "BCL6", "TNF", "GATA3", "CD44", "CCR4", "IL2RA", "FOXP3", "CD28", "CTLA4", "CD27", "SELL", "CCR7", "CD4", "CD8A", "CD8B", "TRBV30", "TRAV8-2", "TRAV13-1", "TRBV21-1", "TRBV24-1", "TRDV2", "TRGV9", "TRBV11-3", "TRAV16", "TRAV12-1", "TRAV1-2", "ISG15", "IFIT2", "IFIT3", "IFI44L","PMAIP1", "OASL", "ZC3HAV1", "DUSP2", "MAP3K8", "SRGN", "CCL3", "NCR3", "CD247", "FCGR3A", "KLRF1", "FCER1G", "TYROBP", "HCST", "CST7", "NKG7", "CCL5", "GZMA", "CTSW", "GZMM", "HOPX", "CCL4", "KLRD1", "GNLY", "FGFBP2", "GZMH", "NFKBIA", "JUNB", "TNFAIP3", "FOS", "DUSP1", "DDIT4", "FTH1", "ZFP36L2", "LINC02446", "PELI1", "SOX4", "GZMK", "HLA-DMA", "HLA-DQB1", "HLA-DPA1", "HLA-DPB1", "HLA-DRA", "HLA-DRB1", "HLA-DQA1", "CD74", "TXN", "COTL1", "CRIP1", "CD52", "S100A4", "B2M", "PCNA","PCLAF", "TYMS", "STMN1", "DUT", "DEK", "TUBA1B", "TUBB", "HMGN1", "H2AFY", "ANP32B", "NASP", "VIM", "TRDV1", "TRDV3") |
|
|
126 |
|
|
|
127 |
cd3_genes[!cd3_genes %in% rownames(cd3_plus_annotated)] |
|
|
128 |
|
|
|
129 |
|
|
|
130 |
clusters<- cd3_plus_annotated$clusters_anno%>%unique() |
|
|
131 |
cd3_cells<- cd3_plus_annotated$clusters_anno %in% clusters |
|
|
132 |
|
|
|
133 |
|
|
|
134 |
cd3_plus_annotation<- |
|
|
135 |
select(cd3_plus_annotated@meta.data, seurat_clusters, annotation) %>% |
|
|
136 |
distinct() %>% |
|
|
137 |
mutate(annotation = str_replace_all(annotation, "-", "_")) %>% |
|
|
138 |
mutate(annotation = str_replace_all(annotation, "\\+", "")) |
|
|
139 |
|
|
|
140 |
library(Polychrome) |
|
|
141 |
annotation_colors<- kelly.colors(length(unique(cd3_plus_annotation$annotation))) %>% |
|
|
142 |
unname() |
|
|
143 |
pdf(here("results/figures/cd3_plus_all_dotplot.pdf"), width = 10, height = 24) |
|
|
144 |
cluster_dot_plot(cd3_plus_annotated[, cd3_cells], features = unique(cd3_genes), annotation = cd3_plus_annotation, annotation_colors = annotation_colors, color_scale_limits = c(-1.5, 2.5)) |
|
|
145 |
dev.off() |
|
|
146 |
|
|
|
147 |
|
|
|
148 |
pdf(here("results/figures/cd3_plus_healthy_only_all_dotplot.pdf"), width = 10, height = 24) |
|
|
149 |
|
|
|
150 |
cd3_cells<- cd3_plus_annotated_health$clusters_anno %in% clusters |
|
|
151 |
|
|
|
152 |
cluster_dot_plot(cd3_plus_annotated_health[, cd3_cells], features = unique(cd3_genes), annotation = cd3_plus_annotation, annotation_colors = annotation_colors, color_scale_limits = c(-1.5, 2.5)) |
|
|
153 |
dev.off() |
|
|
154 |
|
|
|
155 |
|
|
|
156 |
pdf(here("results/figures/cd3_plus_no_health_all_dotplot.pdf"), width = 10, height = 24) |
|
|
157 |
|
|
|
158 |
cd3_cells<- cd3_plus_annotated_no_health$clusters_anno %in% clusters |
|
|
159 |
cluster_dot_plot(cd3_plus_annotated_no_health[, cd3_cells], features = unique(cd3_genes), annotation = cd3_plus_annotation, annotation_colors = annotation_colors, color_scale_limits = c(-1.5, 2.5)) |
|
|
160 |
dev.off() |
|
|
161 |
|
|
|
162 |
|
|
|
163 |
``` |
|
|
164 |
|