|
a |
|
b/RNA-seq/AnalysisPipeline/5.2.Immune.Macrophage.R |
|
|
1 |
#' @description: analysis Macrophage |
|
|
2 |
|
|
|
3 |
library(Seurat) |
|
|
4 |
library(harmony) |
|
|
5 |
library(clustree) |
|
|
6 |
library(ggpubr) |
|
|
7 |
library(dplyr) |
|
|
8 |
library(tidyverse) |
|
|
9 |
library(patchwork) |
|
|
10 |
library(ComplexHeatmap) |
|
|
11 |
library(circlize) |
|
|
12 |
library(vegan) |
|
|
13 |
library(openxlsx) |
|
|
14 |
set.seed(101) |
|
|
15 |
library(future) |
|
|
16 |
plan("multiprocess", workers = 5) |
|
|
17 |
options(future.globals.maxSize = 50000 * 1024^2) # set 50G RAM |
|
|
18 |
setwd(dir = "/data/active_data/lzl/RenalTumor-20200713/DataAnalysis-20210803/scRNA") |
|
|
19 |
source(file = "/home/longzhilin/Analysis_Code/Plot_colorPaletters.R") |
|
|
20 |
source(file = "/home/longzhilin/Analysis_Code/SingleCell/scRNA.Integrate.multipleSample.R") |
|
|
21 |
source(file = "/home/longzhilin/Analysis_Code/SingleCell/variableFeatureSelection.R") |
|
|
22 |
source(file = "/home/longzhilin/Analysis_Code/code/ratio.plot.R") |
|
|
23 |
|
|
|
24 |
data.merge <- readRDS("data.merge.pro.rds") |
|
|
25 |
DefaultAssay(data.merge) <- "RNA" |
|
|
26 |
cell.Type <- c("Macrophage") |
|
|
27 |
sub.scRNA <- subset(data.merge, subset = cellType_low == cell.Type) |
|
|
28 |
sub.scRNA <- DietSeurat(sub.scRNA, assays = "RNA") |
|
|
29 |
index <- match(paste0("SCT_snn_res.", seq(0.2, 1.2, by=0.1)), colnames(sub.scRNA@meta.data)) |
|
|
30 |
sub.scRNA@meta.data <- sub.scRNA@meta.data[,-index] |
|
|
31 |
|
|
|
32 |
####----------------------------------------------------- 1. clustring cell |
|
|
33 |
# split the dataset into a list of two seurat objects (stim and CTRL) |
|
|
34 |
sub.list <- SplitObject(sub.scRNA, split.by = "orig.ident") |
|
|
35 |
sub.list <- lapply(X = sub.list, FUN = function(x) { |
|
|
36 |
x <- SCTransform(x, vars.to.regress = c("nCount_RNA", "percent.mt"), verbose = FALSE) |
|
|
37 |
}) |
|
|
38 |
sub.scRNA <- merge(sub.list[[1]], y = sub.list[2:length(sub.list)], project = "Renal_Macrophage") |
|
|
39 |
DefaultAssay(sub.scRNA) <- "SCT" |
|
|
40 |
seurat.features.SCT <- SelectIntegrationFeatures(object.list = sub.list, nfeatures = 3000) |
|
|
41 |
VariableFeatures(sub.scRNA) <- seurat.features.SCT |
|
|
42 |
pdf("5.Immune/Macrophage/SCT.Harmony.Integration.pdf") |
|
|
43 |
sub.scRNA.harmony <- Harmony.integration.reduceDimension(seurat.object = sub.scRNA, assay = "SCT", set.resolutions = seq(0.2, 1.2, by = 0.1), PC = 30, npcs = 50) |
|
|
44 |
dev.off() |
|
|
45 |
sub.scRNA.harmony$seurat_clusters <- sub.scRNA.harmony$SCT_snn_res.0.3 |
|
|
46 |
Idents(sub.scRNA.harmony) <- sub.scRNA.harmony$seurat_clusters |
|
|
47 |
DefaultAssay(sub.scRNA.harmony) <- "RNA" |
|
|
48 |
sub.scRNA.harmony <- NormalizeData(sub.scRNA.harmony, verbose = FALSE) |
|
|
49 |
sub.scRNA.harmony <- ScaleData(sub.scRNA.harmony, verbose = FALSE, vars.to.regress = c("nCount_RNA", "percent.mt"), features = rownames(sub.scRNA.harmony)) |
|
|
50 |
saveRDS(sub.scRNA.harmony, file = "5.Immune/Macrophage/sub.scRNA.harmony.rds") |
|
|
51 |
|
|
|
52 |
####----------------------------------------------------- 2. defined the cell population |
|
|
53 |
DefaultAssay(sub.scRNA.harmony) <- "RNA" |
|
|
54 |
#### 1.marker |
|
|
55 |
pdf("5.Immune/Macrophage/markerExpression.pdf") |
|
|
56 |
VlnPlot(sub.scRNA.harmony, features = c("CD3D", "PLVAP", "CD68", "CD163"), ncol = 2) |
|
|
57 |
FeaturePlot(sub.scRNA.harmony, features = c("CD3D", "PLVAP", "CD68", "CD163"), cols = c("lightgrey", "red"), ncol = 2) |
|
|
58 |
VlnPlot(sub.scRNA.harmony, features = c("APOE", "C1QA", "C1QB", "C1QC"), ncol = 2) |
|
|
59 |
FeaturePlot(sub.scRNA.harmony, features = c("APOE", "C1QA", "C1QB", "C1QC"), cols = c("lightgrey", "red"), ncol = 2) |
|
|
60 |
VlnPlot(sub.scRNA.harmony, features = c("SPP1", "CSTB", "FABP5", "FN1"), ncol = 2) |
|
|
61 |
FeaturePlot(sub.scRNA.harmony, features = c("SPP1", "CSTB", "FABP5", "FN1"), cols = c("lightgrey", "red"), ncol = 2) |
|
|
62 |
VlnPlot(sub.scRNA.harmony, features = c("S100A8", "S100A12", "FCGR3A", "FCN1"), ncol = 2) |
|
|
63 |
FeaturePlot(sub.scRNA.harmony, features = c("S100A8", "S100A12", "FCGR3A", "FCN1"), cols = c("lightgrey", "red"), ncol = 2) |
|
|
64 |
dev.off() |
|
|
65 |
|
|
|
66 |
features <- c("CD3D", "CD3E", "PLVAP", "ESM1", "ITGAM", "CD68", "CD163", "CSF1R") |
|
|
67 |
pdf("5.Immune/Macrophage/cluster.markerExpression.dot.pdf", height = 2, width = 5) |
|
|
68 |
DotPlot(sub.scRNA.harmony, features = features, cols = c("#1e90ff", "#F15F30"), group.by = "seurat_clusters", dot.scale = 3.5) + RotatedAxis() + theme(axis.text.x = element_text(size = 7)) + theme(axis.text.y = element_text(size = 8)) |
|
|
69 |
DotPlot(sub.scRNA.harmony, features = features, cols = c("#1e90ff", "#F15F30"), group.by = "seurat_clusters", dot.scale = 3.5) + RotatedAxis() + NoLegend() + theme(axis.text.x = element_text(size = 7)) + theme(axis.text.y = element_text(size = 8)) |
|
|
70 |
dev.off() |
|
|
71 |
pdf("5.Immune/Macrophage/cluster.markerExpression.dot.test.pdf", height = 4, width = 5) |
|
|
72 |
DotPlot(sub.scRNA.harmony, features = features, cols = c("#1e90ff", "#F15F30"), group.by = "seurat_clusters", dot.scale = 3.5) + RotatedAxis() + theme(axis.text.x = element_text(size = 7)) + theme(axis.text.y = element_text(size = 8)) |
|
|
73 |
DotPlot(sub.scRNA.harmony, features = features, cols = c("#1e90ff", "#F15F30"), group.by = "seurat_clusters", dot.scale = 3.5) + RotatedAxis() + NoLegend() + theme(axis.text.x = element_text(size = 7)) + theme(axis.text.y = element_text(size = 8)) |
|
|
74 |
dev.off() |
|
|
75 |
|
|
|
76 |
pdf("5.Immune/Macrophage/cluster.ratio.pdf", height = 3, width = 5) |
|
|
77 |
ratio.plot(seurat.object = sub.scRNA.harmony, id.vars1 = "orig.ident", id.vars2 = "seurat_clusters", angle = 60) |
|
|
78 |
ratio.plot(seurat.object = sub.scRNA.harmony, id.vars1 = "orig.ident", id.vars2 = "seurat_clusters", angle = 60) |
|
|
79 |
dev.off() |
|
|
80 |
|
|
|
81 |
#### 2. differential expression |
|
|
82 |
DefaultAssay(sub.scRNA.harmony) <- "RNA" |
|
|
83 |
cluster.DE <- FindAllMarkers(sub.scRNA.harmony, only.pos = T, |
|
|
84 |
group.by = "seurat_clusters", logfc.threshold = 0.25, min.pct = 0.1, |
|
|
85 |
test.use = "MAST", latent.vars = "orig.ident") |
|
|
86 |
idents <- as.character(unique(cluster.DE$cluster)) |
|
|
87 |
saveFormat <- lapply(idents, function(x){ |
|
|
88 |
index <- which(cluster.DE$cluster == x) |
|
|
89 |
DEGs <- cluster.DE[index,] |
|
|
90 |
DEGs.up <- DEGs %>% filter(avg_log2FC>0) %>% arrange(desc(avg_log2FC)) |
|
|
91 |
DEGs.down <- DEGs %>% filter(avg_log2FC<0) %>% arrange(avg_log2FC) |
|
|
92 |
DEGs <- rbind(DEGs.up, DEGs.down) |
|
|
93 |
return(DEGs) |
|
|
94 |
}) |
|
|
95 |
write.xlsx(saveFormat, file = "5.Immune/Macrophage/cluster.DE.xlsx", sheetName = idents, rowNames = F) |
|
|
96 |
saveRDS(cluster.DE, file = "5.Immune/Macrophage/cluster.DE.rds") |
|
|
97 |
|
|
|
98 |
####----------------------------------------------------- 3. Remove miscellaneous |
|
|
99 |
sub.scRNA.harmony <- subset(sub.scRNA.harmony, subset = seurat_clusters %in% c(0,1,2)) |
|
|
100 |
DefaultAssay(sub.scRNA.harmony) <- "SCT" |
|
|
101 |
pdf("5.Immune/Macrophage/SCT.Harmony.Integration.pro.pdf") |
|
|
102 |
sub.scRNA.harmony <- Harmony.integration.reduceDimension(seurat.object = sub.scRNA.harmony, assay = "SCT", set.resolutions = seq(0.2, 1.2, by = 0.1), PC = 30, npcs = 50) |
|
|
103 |
dev.off() |
|
|
104 |
sub.scRNA.harmony$seurat_clusters <- sub.scRNA.harmony$SCT_snn_res.0.2 |
|
|
105 |
Idents(sub.scRNA.harmony) <- sub.scRNA.harmony$seurat_clusters |
|
|
106 |
sub.scRNA.harmony$cellType2 <- paste0("C", as.numeric(sub.scRNA.harmony$seurat_clusters)) |
|
|
107 |
Idents(sub.scRNA.harmony) <- factor(sub.scRNA.harmony$cellType2, levels = c("C1", "C2", "C3")) |
|
|
108 |
|
|
|
109 |
cellType3 <- sub.scRNA.harmony$cellType2 |
|
|
110 |
cellType3 <- gsub("^C1$", "TAM-C1QB", cellType3) |
|
|
111 |
cellType3 <- gsub("^C2$", "TAM-RGCC", cellType3) |
|
|
112 |
cellType3 <- gsub("^C3$", "TAM-LGALS3", cellType3) |
|
|
113 |
sub.scRNA.harmony$cellType3 <- factor(cellType3, levels = c("TAM-C1QB", "TAM-RGCC", "TAM-LGALS3")) |
|
|
114 |
Idents(sub.scRNA.harmony) <- sub.scRNA.harmony$cellType3 |
|
|
115 |
saveRDS(sub.scRNA.harmony, file = "5.Immune/Macrophage/sub.scRNA.harmony.pro.rds") |
|
|
116 |
|
|
|
117 |
sub.scRNA.harmony$cellType <- sub.scRNA.harmony$cellType3 |
|
|
118 |
Idents(sub.scRNA.harmony) <- sub.scRNA.harmony$cellType |
|
|
119 |
cellType.colors <- c("#F8766D", "#00BA38", "#619CFF") |
|
|
120 |
|
|
|
121 |
pdf("5.Immune/Macrophage/cluster.pro.pdf") |
|
|
122 |
DimPlot(object = sub.scRNA.harmony, reduction = 'tsne', pt.size = 1.5, label = TRUE, group.by = "seurat_clusters")+NoLegend() |
|
|
123 |
DimPlot(object = sub.scRNA.harmony, reduction = 'umap', pt.size = 1.5, label = TRUE, group.by = "seurat_clusters")+NoLegend() |
|
|
124 |
dev.off() |
|
|
125 |
pdf("5.Immune/Macrophage/cellType.pdf") |
|
|
126 |
DimPlot(object = sub.scRNA.harmony, reduction = 'tsne', pt.size = 1.5, label = TRUE, group.by = "cellType")+NoLegend() |
|
|
127 |
DimPlot(object = sub.scRNA.harmony, reduction = 'umap', pt.size = 1.5, label = TRUE, group.by = "cellType")+NoLegend() |
|
|
128 |
dev.off() |
|
|
129 |
|
|
|
130 |
features <- c("IER2", "JUN", "F13A1", "APOE", "C1QB", "C1QC", "C1QA", |
|
|
131 |
"EREG", "NLRP3", "AREG", "SLC2A3", "RGCC", "CLEC5A", |
|
|
132 |
"LILRB4", "MARCO", "ANXA2", "LGALS3", "GPNMB", "TREM2") |
|
|
133 |
pdf("5.Immune/Macrophage/cluster.markerExpression.dot.pro.pdf", height = 1.5, width = 6) |
|
|
134 |
DotPlot(sub.scRNA.harmony, features = features, cols = c("#1e90ff", "#F15F30"), group.by = "cellType", dot.scale = 3.5) + theme(axis.text.x = element_text(size = 7, angle = 90)) + theme(axis.text.y = element_text(size = 8)) |
|
|
135 |
DotPlot(sub.scRNA.harmony, features = features, cols = c("#1e90ff", "#F15F30"), group.by = "cellType", dot.scale = 3.5) + NoLegend() + theme(axis.text.x = element_text(size = 7, angle = 90)) + theme(axis.text.y = element_text(size = 8)) |
|
|
136 |
dev.off() |
|
|
137 |
pdf("5.Immune/Macrophage/cluster.markerExpression.dot.pro.test.pdf", height = 4, width = 6) |
|
|
138 |
DotPlot(sub.scRNA.harmony, features = features, cols = c("#1e90ff", "#F15F30"), group.by = "cellType", dot.scale = 3.5) + theme(axis.text.x = element_text(size = 7, angle = 90)) + theme(axis.text.y = element_text(size = 8)) |
|
|
139 |
DotPlot(sub.scRNA.harmony, features = features, cols = c("#1e90ff", "#F15F30"), group.by = "cellType", dot.scale = 3.5) + NoLegend() + theme(axis.text.x = element_text(size = 7, angle = 90)) + theme(axis.text.y = element_text(size = 8)) |
|
|
140 |
dev.off() |
|
|
141 |
|
|
|
142 |
pdf("5.Immune/Macrophage/markerExpression.pro.pdf") |
|
|
143 |
VlnPlot(sub.scRNA.harmony, features = c("IL1A", "IL1B", "IFITM1", "IFITM2"), ncol = 2) |
|
|
144 |
FeaturePlot(sub.scRNA.harmony, features = c("IL1A", "IL1B", "IFITM1", "IFITM2"), cols = c("lightgrey", "red"), ncol = 2) |
|
|
145 |
VlnPlot(sub.scRNA.harmony, features = c("FLT1", "SPARC", "RGS5", "MRC1"), ncol = 2) |
|
|
146 |
FeaturePlot(sub.scRNA.harmony, features = c("FLT1", "SPARC", "RGS5", "MRC1"), cols = c("lightgrey", "red"), ncol = 2) |
|
|
147 |
dev.off() |
|
|
148 |
|
|
|
149 |
####----------------------------------------------------- 2.differential expression |
|
|
150 |
DefaultAssay(sub.scRNA.harmony) <- "RNA" |
|
|
151 |
cluster.DE <- FindAllMarkers(sub.scRNA.harmony, |
|
|
152 |
group.by = "cellType", logfc.threshold = 0, min.pct = 0.1, |
|
|
153 |
test.use = "MAST", latent.vars = "orig.ident") |
|
|
154 |
idents <- levels(sub.scRNA.harmony) |
|
|
155 |
saveFormat <- lapply(idents, function(x){ |
|
|
156 |
index <- which(cluster.DE$cluster == x) |
|
|
157 |
DEGs <- cluster.DE[index,] |
|
|
158 |
DEGs.up <- DEGs %>% filter(avg_log2FC>0) %>% arrange(desc(avg_log2FC)) |
|
|
159 |
DEGs.down <- DEGs %>% filter(avg_log2FC<0) %>% arrange(avg_log2FC) |
|
|
160 |
DEGs <- rbind(DEGs.up, DEGs.down) |
|
|
161 |
return(DEGs) |
|
|
162 |
}) |
|
|
163 |
names(saveFormat) <- idents |
|
|
164 |
write.xlsx(saveFormat, file = "5.Immune/Macrophage/cellType.DE.pro.xlsx", sheetName = idents, rowNames = F) |
|
|
165 |
saveRDS(cluster.DE, file = "5.Immune/Macrophage/cellType.DE.pro.rds") |
|
|
166 |
|
|
|
167 |
####-- pathway enrichment |
|
|
168 |
DEGs <- lapply(saveFormat, function(x){ |
|
|
169 |
x <- x %>% filter(p_val_adj<0.05 & avg_log2FC>0.5) %>% arrange(desc(avg_log2FC)) |
|
|
170 |
return(x) |
|
|
171 |
}) |
|
|
172 |
names(DEGs) <- idents |
|
|
173 |
write.xlsx(DEGs, file = "5.Immune/Macrophage/cellType.DEGs.xlsx", sheetName = idents, rowNames = F) |
|
|
174 |
saveRDS(DEGs, file = "5.Immune/Macrophage/cellType.DEGs.rds") |
|
|
175 |
|
|
|
176 |
DEGs <- lapply(DEGs, function(x){ |
|
|
177 |
return(x$gene) |
|
|
178 |
}) |
|
|
179 |
source("/home/longzhilin/Analysis_Code/PathwayEnrichment/clusterProfiler.enricher.R") |
|
|
180 |
pdf("5.Immune/Macrophage/program.pathway.enrichment.pdf") |
|
|
181 |
res <- lapply(names(DEGs), function(x){ |
|
|
182 |
y <- DEGs[[x]] |
|
|
183 |
res <- cluterProfiler.enricher(gene = y, geneType = "SYMBOL", db.type = "MsigDB", saveDir = paste0(getwd(),"/5.Immune/Macrophage/cluterProfiler_MsigDB"), |
|
|
184 |
title = x, qvalueCutoff = 0.05, pvalueCutoff = 0.05) |
|
|
185 |
# gene ratio |
|
|
186 |
res <- res$em.res.genesymbol@result %>% filter(p.adjust<0.05) #fdr adjust |
|
|
187 |
pathway.geneNum <- unlist(strsplit(res$BgRatio, "/"))[seq(1, nrow(res),by=2)] |
|
|
188 |
gene.ratio <- as.numeric(res$Count)/as.numeric(pathway.geneNum) |
|
|
189 |
res$gene.ratio <- gene.ratio |
|
|
190 |
return(res) |
|
|
191 |
}) |
|
|
192 |
dev.off() |
|
|
193 |
names(res) <- names(DEGs) |
|
|
194 |
library(openxlsx) |
|
|
195 |
write.xlsx(res, file = "5.Immune/Macrophage/cluterProfiler_MsigDB/clusterProfiler.enricher.result.xlsx", sheetName = idents, rowNames = F) |
|
|
196 |
#### show the cluster profiler result |
|
|
197 |
wrapText <- function(x, len) { |
|
|
198 |
sapply(x, function(y) paste(strwrap(y, len), collapse = "\n"), USE.NAMES = FALSE) |
|
|
199 |
} |
|
|
200 |
library(ggthemes) |
|
|
201 |
enrich.pathways <- c(res[[1]]$ID[c(1, 3, 17, 26, 27, 30, 32, 46, 68, 73, 75, 99, 119, 196, 216, 397, 430)], |
|
|
202 |
res[[2]]$ID[c(1:5, 7, 8, 10, 18, 19, 61, 72, 122, 127)], |
|
|
203 |
res[[3]]$ID[c(1, 2, 3, 5, 6, 8, 9, 38, 74, 173)]) |
|
|
204 |
enrich.pathways <- unique(enrich.pathways) |
|
|
205 |
|
|
|
206 |
enrich <- lapply(res, function(x){ |
|
|
207 |
idx <- which(x$ID %in% enrich.pathways) |
|
|
208 |
return(x[idx, c("ID", "p.adjust", "Count")]) |
|
|
209 |
}) |
|
|
210 |
names(enrich) <- names(DEGs) |
|
|
211 |
enrich <- lapply(names(enrich), function(x){ |
|
|
212 |
enrich[[x]]$Type <- rep(x, nrow(enrich[[x]])) |
|
|
213 |
return(enrich[[x]]) |
|
|
214 |
}) |
|
|
215 |
enrich.res <- Reduce(function(x,y) rbind(x,y), enrich) |
|
|
216 |
rownames(enrich.res) <- NULL |
|
|
217 |
|
|
|
218 |
enrich.res$p.adjust <- -log10(enrich.res$p.adjust) |
|
|
219 |
enrich.res$wrap <- wrapText(enrich.res$ID, 45) |
|
|
220 |
pdf("5.Immune/Macrophage/cluterProfiler_MsigDB/cluterProfiler_MsigDB.enrichment.pdf") |
|
|
221 |
p1 <- ggplot(enrich.res, |
|
|
222 |
aes(x = Type, |
|
|
223 |
y = wrap, |
|
|
224 |
size = Count, |
|
|
225 |
color = p.adjust, |
|
|
226 |
fill = p.adjust)) |
|
|
227 |
p2 <- p1 + guides(color=FALSE) + geom_point(shape = 21, alpha = 0.7) + theme_few() + scale_color_gradient(low = "#FF9375", high = "red") + scale_fill_gradient(low = "#FF9375", high = "red", breaks = c(1.3, 2, 3, 4, 5, 6), labels = c(0.05, 0.01, 0.001, 0.0001, 0.00001, 0.000001)) |
|
|
228 |
p2 <- p2 + theme(axis.text.x = element_text(angle = 45,vjust = 1,hjust = 1, size = 8), axis.text.y = element_text(size = 8)) + xlab("") + ylab("") |
|
|
229 |
print(p2) |
|
|
230 |
|
|
|
231 |
#heatmap |
|
|
232 |
pathway.p <- enrich.res[, c("ID", "Type", "p.adjust")] |
|
|
233 |
pathway.data <- pivot_wider(pathway.p, names_from = "Type", values_from = "p.adjust") |
|
|
234 |
pathway.data <- as.data.frame(pathway.data) |
|
|
235 |
rownames(pathway.data) <- pathway.data$ID |
|
|
236 |
pathway.data <- as.data.frame(pathway.data[,-1]) |
|
|
237 |
cols <- colorRamp2(c(0, 10, 20), c("white", "#ffff66", "red")) |
|
|
238 |
Heatmap(pathway.data, name = "-log10(FDR)", show_column_dend = F, show_row_dend = F, col = cols, |
|
|
239 |
na_col = "#f2f3f4", border = "grey", border_gp = gpar(col = "grey"), rect_gp = gpar(col = "grey"), |
|
|
240 |
width = unit(3, "cm"), height = unit(12, "cm"), cluster_rows = F, cluster_columns = F, |
|
|
241 |
row_names_gp = gpar(fontsize = 8), column_names_gp = gpar(fontsize = 8)) |
|
|
242 |
dev.off() |
|
|
243 |
|
|
|
244 |
##### TCGA survival |
|
|
245 |
source(file = "/home/longzhilin/Analysis_Code/code/analysis.diff.survival.TCGA.R") |
|
|
246 |
DESeq2.normalized_counts <- readRDS("/data/active_data/lzl/RenalTumor-20200713/Data/TCGA/KIRC/Result/DESeq2.normalized_counts.rds") |
|
|
247 |
DESeq2.normalized_counts <- log2(DESeq2.normalized_counts+1) |
|
|
248 |
DESeq2.result <- readRDS("/data/active_data/lzl/RenalTumor-20200713/Data/TCGA/KIRC/Result/DESeq2.result.rds") |
|
|
249 |
clin.data <- readRDS("/data/active_data/lzl/RenalTumor-20200713/Data/TCGA/KIRC/Result/clin.data.rds") |
|
|
250 |
pdf("5.Immune/Macrophage/DEGs.survival.pdf") |
|
|
251 |
TCGA.TAM.C1QB <- analysis.diff.survival.TCGA(interest.gene = DEGs[["TAM-C1QB"]], diff.gene.pro = DESeq2.result, exp.data.process = DESeq2.normalized_counts, clin.data = clin.data, EnhancedVolcano.plot = F, main = "TAM-C1QB", Box.plot = F, meta.signature = T, single.signature = F) |
|
|
252 |
TCGA.TAM.RGCC <- analysis.diff.survival.TCGA(interest.gene = DEGs[["TAM-RGCC"]], diff.gene.pro = DESeq2.result, exp.data.process = DESeq2.normalized_counts, clin.data = clin.data, EnhancedVolcano.plot = F, main = "TAM-RGCC", Box.plot = F, meta.signature = T, single.signature = F) |
|
|
253 |
TCGA.TAM.LGALS3 <- analysis.diff.survival.TCGA(interest.gene = DEGs[["TAM-LGALS3"]], diff.gene.pro = DESeq2.result, exp.data.process = DESeq2.normalized_counts, clin.data = clin.data, EnhancedVolcano.plot = F, main = "TAM-LGALS3", Box.plot = F, meta.signature = T, single.signature = F) |
|
|
254 |
dev.off() |
|
|
255 |
|
|
|
256 |
##### ICB survival |
|
|
257 |
library(ggpubr) |
|
|
258 |
source(file = "/home/longzhilin/Analysis_Code/SurvivalAnalysis/Cox.function.R") |
|
|
259 |
source(file = "/home/longzhilin/Analysis_Code/code/RCC.ICB.analysis.R") |
|
|
260 |
normalized_expression <- readRDS("/data/active_data/lzl/RenalTumor-20200713/Data/ICB.therapy/normalized_expression.rds") |
|
|
261 |
patient.info.RNA <- readRDS("/data/active_data/lzl/RenalTumor-20200713/Data/ICB.therapy/patient.info.RNA.rds") |
|
|
262 |
patient.info.RNA$Sex <- gsub("^F|FEMALE|Female$", 0, patient.info.RNA$Sex) |
|
|
263 |
patient.info.RNA$Sex <- gsub("^M|Male|MALE$", 1, patient.info.RNA$Sex) |
|
|
264 |
patient.info.RNA$Tumor_Sample_Primary_or_Metastasis <- gsub("PRIMARY", 0, patient.info.RNA$Tumor_Sample_Primary_or_Metastasis) |
|
|
265 |
patient.info.RNA$Tumor_Sample_Primary_or_Metastasis <- gsub("METASTASIS", 1, patient.info.RNA$Tumor_Sample_Primary_or_Metastasis) |
|
|
266 |
|
|
|
267 |
pdf("5.Immune/Macrophage/DEGs.ICB.survival.pdf") |
|
|
268 |
ICB.res <- RCC.icb.analysis(signature.list = DEGs, expresionMatrix = normalized_expression, clincal.info = patient.info.RNA) |
|
|
269 |
dev.off() |
|
|
270 |
|
|
|
271 |
|
|
|
272 |
####----------------------------------------------------- 3.Define cell state based on signature |
|
|
273 |
## M1 和 M2 |
|
|
274 |
source(file = "/home/longzhilin/Analysis_Code/SingleCell/vision_seurat.R") |
|
|
275 |
source(file = "/home/longzhilin/Analysis_Code/SingleCell/vision.plot.R") |
|
|
276 |
signature.genes <- read.table("/data/ExtraDisk/sdd/longzhilin/Data/signatureGeneSet/Immune/M1&M2&angiogenic&phagocytic.Cheng.2021.Cell.txt", header = T, stringsAsFactors = F, sep = "\t") |
|
|
277 |
vision_state <- vision_seurat(seurat.object = sub.scRNA.harmony, customize.signature = signature.genes, mc.cores = 36, min_signature_genes = 4) |
|
|
278 |
saveRDS(vision_state, file = "5.Immune/Macrophage/vision_signatureScore.rds") |
|
|
279 |
|
|
|
280 |
pdf("5.Immune/Macrophage/vision_signatureScore.pdf") |
|
|
281 |
res <- vision.plot(vision.obj = vision_state, groupName = "cellType") |
|
|
282 |
res <- vision.plot(vision.obj = vision_state, groupName = "cellType", signature.names = c("M1-state", "M2-state"), title = "M1 & M2") |
|
|
283 |
# heatmap |
|
|
284 |
vision.score <- as.data.frame(vision_state@SigScores) |
|
|
285 |
vision.score.mean <- apply(vision.score, 2, function(x){ |
|
|
286 |
score <- tapply(x, sub.scRNA.harmony$cellType, mean) |
|
|
287 |
return(score) |
|
|
288 |
}) |
|
|
289 |
p <- Heatmap(t(vision.score.mean), width = unit(6, "cm"), height = unit(6, "cm"), name = "Signature score", |
|
|
290 |
show_row_dend = F, show_column_dend = F, row_names_gp = gpar(fontsize = 8), column_names_gp = gpar(fontsize = 8)) |
|
|
291 |
print(p) |
|
|
292 |
vision.score.mean.scale <- scale(vision.score.mean) |
|
|
293 |
p <- Heatmap(t(vision.score.mean.scale), width = unit(6, "cm"), height = unit(6, "cm"), name = "Signature score", |
|
|
294 |
show_row_dend = F, show_column_dend = F, row_names_gp = gpar(fontsize = 8), column_names_gp = gpar(fontsize = 8)) |
|
|
295 |
print(p) |
|
|
296 |
|
|
|
297 |
# violin |
|
|
298 |
vision.score$group <- sub.scRNA.harmony$cellType |
|
|
299 |
plot.list <- lapply(colnames(vision.score), function(x){ |
|
|
300 |
my_comparisons <- as.list(as.data.frame(combn(levels(sub.scRNA.harmony$cellType),2))) |
|
|
301 |
a <- vision.score[, c(x, "group")] |
|
|
302 |
names(a) <- c("Signature score", "group") |
|
|
303 |
p <- ggboxplot(a, x = "group", y = "Signature score", title = x, color = "black", fill = "group", add = "jitter", add.params = list(color = "black", size = 0.1)) + |
|
|
304 |
xlab("") + rotate_x_text(angle = 45, vjust = 1) + scale_fill_manual(values = cellType.colors) + |
|
|
305 |
stat_compare_means(comparisons = my_comparisons, label = "p.signif") + NoLegend() |
|
|
306 |
return(p) |
|
|
307 |
}) |
|
|
308 |
p <- ggarrange(plotlist = plot.list[1:4],ncol = 2, nrow = 2) |
|
|
309 |
print(p) |
|
|
310 |
dev.off() |
|
|
311 |
|
|
|
312 |
#### M1 and M2 expression matrix |
|
|
313 |
library(reshape2) |
|
|
314 |
signature.genes <- signature.genes[which(signature.genes$Type %in% c("M1-state", "M2-state")),] |
|
|
315 |
idx <- match(signature.genes$Gene, rownames(sub.scRNA.harmony)) |
|
|
316 |
signature.genes <- signature.genes[which(!is.na(idx)),] |
|
|
317 |
signature.names <- unique(signature.genes$Type) |
|
|
318 |
signature.list <- lapply(signature.names, function(x){ |
|
|
319 |
genes <- signature.genes$Gene[which(signature.genes$Type == x)] |
|
|
320 |
return(genes) |
|
|
321 |
}) |
|
|
322 |
names(signature.list) <- signature.names |
|
|
323 |
#signature gene matrix |
|
|
324 |
exp.matrix <- AverageExpression(sub.scRNA.harmony, signature.genes$Gene, assay = "RNA", slot = "scale.data") |
|
|
325 |
exp.matrix <- exp.matrix$RNA |
|
|
326 |
col.split <- signature.genes$Type |
|
|
327 |
exp.matrix.scale <- scale(t(exp.matrix)) |
|
|
328 |
pdf("5.Immune/Macrophage/M1&M2.signature.score.pdf") |
|
|
329 |
Heatmap(t(exp.matrix), name = "Expression", cluster_columns = T, column_split = col.split, cluster_rows = T, show_row_dend = F, show_column_dend = F, row_names_gp = gpar(fontsize = 8), column_names_gp = gpar(fontsize = 7), width = unit(10, "cm"), height = unit(3, "cm")) |
|
|
330 |
Heatmap(exp.matrix.scale, name = "Expression", cluster_columns = T, column_split = col.split, cluster_rows = T, show_row_dend = F, show_column_dend = F, row_names_gp = gpar(fontsize = 8), column_names_gp = gpar(fontsize = 7), width = unit(10, "cm"), height = unit(3, "cm")) |
|
|
331 |
dev.off() |
|
|
332 |
|
|
|
333 |
####----Observe other signatrue patterns----#### |
|
|
334 |
Immune.checkpoint.evasion.genes <- c("ICOSLG", "CD80", "CD86", "VSIR", "VSIG4", "LGALS9", "CD274", "PDCD1LG2", "SIGLEC10") |
|
|
335 |
pdf("5.Immune/Macrophage/Immune.checkpoint.evasion.genes.pdf", height = 1.5, width = 5) |
|
|
336 |
DotPlot(sub.scRNA.harmony, features = Immune.checkpoint.evasion.genes, cols = c("#1e90ff", "#F15F30"), group.by = "cellType", dot.scale = 3.5) + theme(axis.text.x = element_text(size = 7, angle = 90)) + theme(axis.text.y = element_text(size = 8)) |
|
|
337 |
DotPlot(sub.scRNA.harmony, features = Immune.checkpoint.evasion.genes, cols = c("#1e90ff", "#F15F30"), group.by = "cellType", dot.scale = 3.5) + NoLegend() + theme(axis.text.x = element_text(size = 7, angle = 90)) + theme(axis.text.y = element_text(size = 8)) |
|
|
338 |
dev.off() |
|
|
339 |
pdf("5.Immune/Macrophage/Immune.checkpoint.evasion.genes.test.pdf", height = 4, width = 5) |
|
|
340 |
DotPlot(sub.scRNA.harmony, features = Immune.checkpoint.evasion.genes, cols = c("#1e90ff", "#F15F30"), group.by = "cellType", dot.scale = 3.5) + theme(axis.text.x = element_text(size = 7, angle = 90)) + theme(axis.text.y = element_text(size = 8)) |
|
|
341 |
DotPlot(sub.scRNA.harmony, features = Immune.checkpoint.evasion.genes, cols = c("#1e90ff", "#F15F30"), group.by = "cellType", dot.scale = 3.5) + NoLegend() + theme(axis.text.x = element_text(size = 7, angle = 90)) + theme(axis.text.y = element_text(size = 8)) |
|
|
342 |
dev.off() |
|
|
343 |
|
|
|
344 |
###--- MHC molecular |
|
|
345 |
signature.genes <- read.table("/data/ExtraDisk/sdd/longzhilin/Data/signatureGeneSet/Immune/antigenPresenting.LeiZhang.2021.Cell&Guillermo.2014.frontiersImmunology.txt", header = T, stringsAsFactors = F, sep = "\t") |
|
|
346 |
idx <- match(signature.genes$Gene, rownames(sub.scRNA.harmony)) |
|
|
347 |
signature.genes <- signature.genes[which(!is.na(idx)),] |
|
|
348 |
signature.genes <- signature.genes[-c(4, 9, 15, 21, 23, 25, 26, 32:35),] |
|
|
349 |
exp.matrix <- AverageExpression(sub.scRNA.harmony, signature.genes$Gene, assay = "RNA", slot = "data") |
|
|
350 |
exp.matrix <- exp.matrix$RNA |
|
|
351 |
exp.matrix.scale <- scale(t(exp.matrix)) |
|
|
352 |
col.split <- factor(signature.genes$Type, levels = c("MCH-I", "MCH-II", "Pro-inflammatory cytokine", "Anti-inflammatory cytokine", "Chemokine", "Other")) |
|
|
353 |
pdf("5.Immune/Macrophage/MHC.expression_cytokines.pdf") |
|
|
354 |
Heatmap(exp.matrix, name = "Expression", cluster_rows = T, row_split = col.split, cluster_columns = T, show_row_dend = F, show_column_dend = F, row_names_gp = gpar(fontsize = 8), column_names_gp = gpar(fontsize = 8), height = unit(12, "cm"), width = unit(1.5, "cm")) |
|
|
355 |
Heatmap(t(exp.matrix.scale), name = "Expression", cluster_rows = T, row_split = col.split, cluster_columns = T, show_row_dend = F, show_column_dend = F, row_names_gp = gpar(fontsize = 8), column_names_gp = gpar(fontsize = 8), height = unit(12, "cm"), width = unit(1.5, "cm")) |
|
|
356 |
DotPlot(sub.scRNA.harmony, features = signature.genes$Gene, cols = c("#1e90ff", "#F15F30"), group.by = "cellType", dot.scale = 3.5) + RotatedAxis() + theme(axis.text.y = element_text(size = 8)) + labs(x= "", y = "") + theme(axis.text.x = element_text(size = 8)) |
|
|
357 |
dev.off() |