|
a |
|
b/Fig5A_ligands_heatmap.R |
|
|
1 |
|
|
|
2 |
# Plot Figure 5A immunomodulatory molecule heatmap |
|
|
3 |
|
|
|
4 |
library(ComplexHeatmap) |
|
|
5 |
library(circlize) |
|
|
6 |
library(dendextend) |
|
|
7 |
library(readxl) |
|
|
8 |
library(RColorBrewer) |
|
|
9 |
library(matrixStats) |
|
|
10 |
|
|
|
11 |
# load Hemap gene expression data |
|
|
12 |
data = get(load("data9544_with_gene_symbols.RData")) |
|
|
13 |
|
|
|
14 |
# load Hemap annotations |
|
|
15 |
annot = get(load("Hemap_immunology_Annotations.Rdata")) |
|
|
16 |
|
|
|
17 |
annot = annot[!(annot$Category.specifying.lineage.tumor.origin=="MM"&annot$CELLS_SORTED==0),] # remove non-malignant myeloma samples |
|
|
18 |
|
|
|
19 |
data = data[annot[,1],] |
|
|
20 |
|
|
|
21 |
# modify annotations |
|
|
22 |
annot$Category.specifying.subtype.Heatmap <- annot$plotNormals |
|
|
23 |
|
|
|
24 |
annot$Category.specifying.subtype.Heatmap[annot$Sample.type%in%c("Cancer", "Prolif")] <- annot$Category.specifying.subtype[annot$Sample.type%in%c("Cancer", "Prolif")] |
|
|
25 |
|
|
|
26 |
annot$Category.specifying.subtype.Heatmap[annot$Category.specifying.lineage.tumor.origin=="MDS"] <- "MDS" |
|
|
27 |
annot$Category.specifying.subtype.Heatmap[annot$Category.specifying.lineage.tumor.origin=="AML"] <- "AML" |
|
|
28 |
annot$Category.specifying.subtype.Heatmap[annot$Category.specifying.subtype=="AILT"] <- "AITL" |
|
|
29 |
annot$Category.specifying.subtype.Heatmap[annot$Category.specifying.subtype=="LC"] <- "LCH" |
|
|
30 |
|
|
|
31 |
|
|
|
32 |
# ----------------------- |
|
|
33 |
|
|
|
34 |
|
|
|
35 |
# list of immunomodulatory genes |
|
|
36 |
ligands = read_excel("ligands.xlsx") |
|
|
37 |
genelist = ligands$Gene |
|
|
38 |
|
|
|
39 |
# Select cancer samples and summarize by cancer type medians |
|
|
40 |
ligands_cancer <- data[annot$Sample.type%in%c("Cancer", "Prolif")&annot$Category.specifying.subtype.Heatmap!="na", colnames(data) %in% genelist] |
|
|
41 |
ligands_cancer_median <- aggregate(ligands_cancer, by = list(annot$Category.specifying.subtype.Heatmap[annot$Sample.type%in%c("Cancer", "Prolif")&annot$Category.specifying.subtype.Heatmap!="na"]), FUN = "median") |
|
|
42 |
rownames(ligands_cancer_median) <- ligands_cancer_median$Group.1 |
|
|
43 |
ligands_cancer_median$Group.1 <- NULL |
|
|
44 |
|
|
|
45 |
# ----------------------- |
|
|
46 |
|
|
|
47 |
# select genes from expression matrix |
|
|
48 |
mat_unscaled = t(ligands_cancer_median) |
|
|
49 |
mat_unscaled = mat_unscaled[genelist,] |
|
|
50 |
|
|
|
51 |
# scaale |
|
|
52 |
mat = t(apply(mat_unscaled, 1, scale)) |
|
|
53 |
colnames(mat) <- colnames(mat_unscaled) |
|
|
54 |
|
|
|
55 |
# remove genes with max log2 expression <5 (not expressed) |
|
|
56 |
mat = mat[!rowMaxs(mat_unscaled)<5,] |
|
|
57 |
|
|
|
58 |
# make another data matrix for receptor names for later use |
|
|
59 |
mat_receptor <- mat |
|
|
60 |
|
|
|
61 |
# add more common names of ligands in parentheses |
|
|
62 |
ligands <- ligands[match(rownames(mat), ligands$Gene),] |
|
|
63 |
|
|
|
64 |
rownames(mat) <- paste(ligands$Gene, paste0("(", ligands$`Common name`, ")")) |
|
|
65 |
rownames(mat) <- gsub("\\ \\(NA\\)", "", rownames(mat)) |
|
|
66 |
rownames(mat) <- gsub("PD-1H", "", rownames(mat)) |
|
|
67 |
|
|
|
68 |
# make lineage annotation to heatmap |
|
|
69 |
lineage <- colnames(mat) |
|
|
70 |
lineage[grepl("AML|CML|MDS|JMML|Monocyte|Neutrophil|Myeloid|Dendritic|Macrophage|^LC|Langerhans|Erythroid", lineage)] <- "Myeloid" |
|
|
71 |
lineage[grepl("CLL|HCL|FL|MM|MALT|MCL|MZL|CHL|NLPHL|BL|B-ALL|DLBCL|B cell|Germinal|Plasma", lineage)] <- "B cell" |
|
|
72 |
lineage[grepl("AITL|ALCL|ATL|HSTCL|ENKTL|CTCL|PTCLNOS|T-ALL|T/NKcell", lineage)] <- "T/NK cell" |
|
|
73 |
|
|
|
74 |
lineage <- as.data.frame(lineage) |
|
|
75 |
|
|
|
76 |
mainclass <- colnames(mat) |
|
|
77 |
mainclass[grepl("AML|CML|JMML|T-ALL|CLL|pre-B-ALL|HCL", mainclass)] <- "Leukemia" |
|
|
78 |
mainclass[grepl("DLBCL|FL|MALT|MCL|MZL|CHL|NLPHL|BL|AI|ALCL|ATL|HSTCL|ENKTL|CTCL|PTCLNOS", mainclass)] <- "Lymphoma" |
|
|
79 |
mainclass[grepl("MM|LC|MDS", mainclass)] <- "Other" |
|
|
80 |
mainclass <- as.data.frame(mainclass) |
|
|
81 |
|
|
|
82 |
heatmap_annot <- cbind(lineage, mainclass) |
|
|
83 |
|
|
|
84 |
# heatmap annotations |
|
|
85 |
ha1 = HeatmapAnnotation(df = heatmap_annot, |
|
|
86 |
col = list(lineage = structure(brewer.pal(length(unique(heatmap_annot$lineage)), "Set2")[c(1,3,2)], |
|
|
87 |
names = as.character(unique(heatmap_annot$lineage))[c(2,1,3)]), |
|
|
88 |
mainclass = structure(brewer.pal(10, "Set3")[c(10,7,9)], |
|
|
89 |
names = as.character(unique(heatmap_annot$mainclass))[c(2,1,3)]) |
|
|
90 |
), |
|
|
91 |
annotation_legend_param = list(lineage = list(title = "Lineage", title_gp = gpar(fontsize = 10, fontface = "plain"), |
|
|
92 |
labels_gp = gpar(fontsize = 10)), |
|
|
93 |
mainclass = list(title = "Cancer type", title_gp = gpar(fontsize = 10, fontface = "plain"), |
|
|
94 |
labels_gp = gpar(fontsize = 10)) |
|
|
95 |
)) |
|
|
96 |
|
|
|
97 |
|
|
|
98 |
# ligand cell type information annotation |
|
|
99 |
ha2 = rowAnnotation(df = as.data.frame(ligands[5]), |
|
|
100 |
col = list(`Immune checkpoint function` = structure(brewer.pal(length(unique(ligands$`Immune checkpoint function`)), "Paired")[c(3,2,1,4)], |
|
|
101 |
names = as.character(unique(ligands$`Immune checkpoint function`))[c(3,2,1,4)])), |
|
|
102 |
annotation_legend_param = list(`Immune checkpoint function` = list(title = "Immune checkpoint function", title_gp = gpar(fontsize = 10, fontface = "plain"), |
|
|
103 |
labels_gp = gpar(fontsize = 10)), width = unit(0.25, "cm"))) |
|
|
104 |
|
|
|
105 |
|
|
|
106 |
# receptor names |
|
|
107 |
zero_col_mat = matrix(nrow = nrow(mat), ncol = 0) |
|
|
108 |
rownames(zero_col_mat) <- ligands$`Receptor common name` |
|
|
109 |
rownames(zero_col_mat) <- gsub("\\, TNFSF14", "", rownames(zero_col_mat)) |
|
|
110 |
|
|
|
111 |
# dendrogram colors |
|
|
112 |
dend = hclust(as.dist(1-cor(mat, method="spearman")), method = "ward.D") |
|
|
113 |
dend = color_branches(dend, k = 3, col = c("#66C2A5", "#B3DE69", "#FC8D62")) |
|
|
114 |
|
|
|
115 |
|
|
|
116 |
# print heatmap |
|
|
117 |
pdf(file = "Figure5A_Hemap_ligands_heatmap.pdf", height = 8.5, width = 10) |
|
|
118 |
draw(Heatmap(mat, |
|
|
119 |
split = ligands$Split, |
|
|
120 |
gap = unit(2, "mm"), |
|
|
121 |
name = "Expression (log2)\nZ-score", |
|
|
122 |
col = colorRamp2(c(seq(-2, 2, length.out = 9), 4), rev(brewer.pal(9, "RdBu"))[c(1:9,9)]), |
|
|
123 |
rect_gp = gpar(col = "white", lty = 1, lwd = 1), |
|
|
124 |
row_names_side = "right", |
|
|
125 |
row_names_gp = gpar(fontsize = 9), |
|
|
126 |
column_names_gp = gpar(fontsize = 10), |
|
|
127 |
cluster_rows = FALSE, |
|
|
128 |
clustering_distance_rows = "spearman", |
|
|
129 |
clustering_method_rows = "ward.D", |
|
|
130 |
cluster_columns = dend, |
|
|
131 |
clustering_distance_columns = "spearman", |
|
|
132 |
clustering_method_columns = "ward.D", |
|
|
133 |
top_annotation = ha1, |
|
|
134 |
heatmap_legend_param = list(title_gp = gpar(fontsize = 10, fontface = "plain")) |
|
|
135 |
) + |
|
|
136 |
Heatmap(zero_col_mat, |
|
|
137 |
right_annotation = ha2, |
|
|
138 |
row_names_gp = gpar(fontsize = 9)), |
|
|
139 |
auto_adjust = F |
|
|
140 |
) |
|
|
141 |
dev.off() |
|
|
142 |
|
|
|
143 |
|
|
|
144 |
|