-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1_PbPPCd276_analysis
More file actions
215 lines (184 loc) · 7.29 KB
/
1_PbPPCd276_analysis
File metadata and controls
215 lines (184 loc) · 7.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
################################################################################################################################################
# Load libraries
# Required packages for single-cell analysis, visualization, and plotting
################################################################################################################################################
library(SingleCellExperiment)
library(Seurat)
library(tidyverse)
library(RCurl)
library(dplyr)
library(paletteer)
library(patchwork)
library(readxl)
library(ggpubr)
library(ggrepel)
################################################################################################################################################
# Load merged Seurat object
################################################################################################################################################
load("merged_cells.RData")
# Use integrated assay for downstream dimensionality reduction
DefaultAssay(merged_cells) <- "integrated"
# Scaling and feature selection
merged_cells <- ScaleData(merged_cells)
merged_cells <- FindVariableFeatures(object = merged_cells, nfeatures = 3000)
merged_cells <- RunPCA(object = merged_cells)
# Elbow plot to check number of PCs
pdf('ElbowPlot_merged_cells.pdf', height = 4, width = 6)
ElbowPlot(merged_cells)
dev.off()
# Construct neighborhood graph, run UMAP and clustering
merged_cells <- FindNeighbors(object = merged_cells, dims = 1:50)
merged_cells <- RunUMAP(object = merged_cells, dims = 1:50)
merged_cells <- FindClusters(object = merged_cells, resolution = 0.1)
################################################################################################################################################
# Define colors for broad cell types
################################################################################################################################################
celltype_colors <- c(
"Epithelial" = "#5ECCF3FF",
"MDSC" = "#239f6e",
"TAM_DC" = "#D17DF9",
"T_NK" = "#84BD00",
"B_cell" = "#F7A35C",
"Fibroblast" = "#E6C1A4",
"Endothelial" = "#FFB6DBFF",
"Perivascular" = "#7E605E",
"Peripheral_nerve"= "#3F007D"
)
# Assign identities and plot
Idents(merged_cells) <- merged_cells$celltype
all_col <- celltype_colors
identities_order <- as.character(unique(Idents(merged_cells)))
color_vector <- all_col[identities_order]
pdf('DimPlot_merged_cells_celltype_colors_labelcolor.pdf', height = 4, width = 6)
DimPlot(
merged_cells, label = TRUE, repel = TRUE,
cols = all_col, label.color = color_vector, label.size = 3
) + NoAxes()
dev.off()
################################################################################################################################################
# Define colors for fine-grained cell states
################################################################################################################################################
Idents(merged_cells) <- merged_cells$cellstate
cellstate_color <- c(
# Epithelial
"Epi_Basal" = "#5ECCF3FF",
"Epi_Intermediate" = "#b1d8ff",
"Epi_Luminal" = "#4E67C8FF",
"Epi_Proliferative" = "#A7EA52FF",
"NEPC" = "#239f6e",
# MDSC
"MDSC_Spp1" = "#7FD2FF",
"MDSC_Csf3r" = "#CD69C9",
"MDSC_Gngt2" = "#894FC6",
"MDSC_Isg" = "#B2B2FF",
# TAM/DC
"TAM_C1q" = "#bbb1ff",
"TAM_Mrc1" = "#FBCBF4FF",
"TAM_Vcan" = "#AE048EFF",
"TAM_IFN" = "#D17DF9",
"TAM_Proliferative" = "#3283FEFF",
"DC" = "#ed968c",
# T/NK
"Cd8_effector" = "#239f6e",
"Cd8_IFN" = "#63ff55",
"Cd4_Treg" = "#b1d8ff",
"Cd4_Th17" = "#3B95C4",
"Cd4_Th2" = "#4E67C8FF",
"T_Proliferative" = "#F14124FF",
"NK_Gzmc" = "#ffd000",
"NK_Gzma" = "#FF8021FF",
# B cells
"B_cell" = "#FFCA08",
"Plasma_B" = "#FE801A",
# Endothelial
"Arterial" = "#F14124FF",
"Venous" = "#90CFFF",
"Capillary_ECM" = "#FFB6DBFF",
"Capillary_IFN" = "#FF6DB6FF",
"Capillary_Stress" = "#CD69C9",
"Lymphatic" = "#ABCFA8",
"Proliferative_Endothelial" = "#22763F",
# Pericyte/VSMC
"Pericyte_Stress" = "#F79CD4",
"Pericyte_Cytokine" = "#CC99FF",
"Pericyte_ECM" = "#b1d8ff",
"Pericyte_IFN" = "#9900CC",
"VSMC" = "#756BB1",
# Nerve
"Peripheral_nerve" = "#3F007D",
# CAF subtypes
"CAF_ECM" = "#F5CDB4",
"CAF_C3" = "#B2B2FF",
"CAF_Igfbp2" = "#B07AA1",
"CAF_Apoe" = "#b97e45",
"CAF_Proliferative" = "#31c7ba"
)
all_col <- cellstate_color
identities_order <- as.character(unique(Idents(merged_cells)))
color_vector <- all_col[identities_order]
pdf('DimPlot_merged_cells_cellstate_labelcolor.pdf', height = 4, width = 5)
DimPlot(
merged_cells, label = TRUE, repel = TRUE, cols = all_col,
label.color = color_vector, raster = FALSE, label.size = 2.5
) + NoAxes() + NoLegend()
dev.off()
################################################################################################################################################
# Differential expression analysis
################################################################################################################################################
DefaultAssay(merged_cells) <- "RNA"
# Identify markers for each cluster
celltype_markers <- FindAllMarkers(
merged_cells, only.pos = TRUE, min.pct = 0.2, logfc.threshold = 0.2
)
# Select top 10 marker genes per cluster with logFC > 0.5
celltype_markers %>%
group_by(cluster) %>%
dplyr::filter(avg_log2FC > 0.5) %>%
slice_head(n = 10) %>%
ungroup() -> top10
# DotPlot visualization
pdf('DotPlot_merged_cells.pdf', height = 6, width = 20)
DotPlot(
merged_cells, features = unique(top10$gene),
cols = "RdYlBu", dot.scale = 8
) + theme(
axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5),
axis.text = element_text(size = 15),
text = element_text(size = 15),
axis.title.x = element_blank(),
axis.title.y = element_blank()
)
dev.off()
################################################################################################################################################
# Heatmap of average expression for top markers
################################################################################################################################################
source('avg_exp_heatmap.R')
source('top10_deduplicated_select.R')
Idents(merged_cells) <- merged_cells$celltype
top10_deduplicated <- top10_deduplicated_select(celltype_markers)
table(top10_deduplicated$cluster)
pdf_lable <- 'celltype'
avg_exp_heatmap(
plot_obj = merged_cells,
top10 = top10_deduplicated,
markergene_plot = top10_deduplicated$gene,
cell_type_colors = celltype_colors,
pdfname = paste0(pdf_lable, '_top10_heatmap.pdf'),
heatmap_col = colorRamp2(c(-1.5, 0, 1.5), c("#5484AF", "white", "#CE352E")),
height = 4,
width = 16
)
################################################################################################################################################
# Barplot of cell composition across samples
################################################################################################################################################
source('barplot_function.R')
plot_metadata <- [email protected]
plot_metadata$cellstate <- plot_metadata$celltype
barplot_function(
metadata = plot_metadata,
cell_type_colors = celltype_colors,
lable = '1_celltype_all',
method = "wilcox.test",
cellstate,
boxplot_width = 5
)