|
a |
|
b/Fig6H_FigS6H_CGA_heatmap_GSE98588.R |
|
|
1 |
GIT_HOME="/research/users/ppolonen/git_home/ImmunogenomicLandscape-BloodCancers/" |
|
|
2 |
source(file.path(GIT_HOME, "common_scripts/visualisation/plotting_functions.R")) |
|
|
3 |
source(file.path(GIT_HOME, "common_scripts/featurematrix/functions_generate_fm.R")) |
|
|
4 |
source(file.path(GIT_HOME, "common_scripts/statistics/functions_statistics.R")) |
|
|
5 |
source(file.path(GIT_HOME, "common_scripts/pathway_analysis/functions.GSEA.R")) |
|
|
6 |
|
|
|
7 |
library(data.table) |
|
|
8 |
library(parallel) |
|
|
9 |
library(GSVA) |
|
|
10 |
|
|
|
11 |
setwd("/research/groups/sysgen/PROJECTS/HEMAP_IMMUNOLOGY/petri_work/HEMAP_IMMUNOLOGY/Published_data_figures") |
|
|
12 |
|
|
|
13 |
fm=get(load("GSE98588_fm.Rdata")) |
|
|
14 |
annot=get(load("GSE98588_annot.Rdata")) |
|
|
15 |
profile=get(load("GSE98588_DLBCL_mixtureM_profile.Rdata")) |
|
|
16 |
|
|
|
17 |
# exclude testis dlbcl |
|
|
18 |
profile=profile[,!colnames(fm)%in%"DLBCL_LS2208"] |
|
|
19 |
annot=annot[!colnames(fm)%in%"DLBCL_LS2208",] |
|
|
20 |
fm=fm[,!colnames(fm)%in%"DLBCL_LS2208"] |
|
|
21 |
|
|
|
22 |
# CGAs |
|
|
23 |
t.df = read.delim("t.antigen_df.txt", stringsAsFactors=F, header=T) |
|
|
24 |
|
|
|
25 |
|
|
|
26 |
# Choose GCB or ABC, or "" |
|
|
27 |
name="ABC" |
|
|
28 |
GSE="GSE98588_DLBCL" |
|
|
29 |
|
|
|
30 |
if(name=="GCB"){ |
|
|
31 |
GSE="GSE98588_DLBCL_GCB" |
|
|
32 |
annot=annot[fm["B:SAMP:COO_byGEP_GCB",]==1,] |
|
|
33 |
profile=profile[,fm["B:SAMP:COO_byGEP_GCB",]==1] |
|
|
34 |
fm=fm[,fm["B:SAMP:COO_byGEP_GCB",]==1] |
|
|
35 |
} |
|
|
36 |
|
|
|
37 |
if(name=="ABC"){ |
|
|
38 |
GSE="GSE98588_DLBCL_ABC" |
|
|
39 |
annot=annot[fm["B:SAMP:COO_byGEP_ABC",]==1,] |
|
|
40 |
profile=profile[,fm["B:SAMP:COO_byGEP_ABC",]==1] |
|
|
41 |
fm=fm[,fm["B:SAMP:COO_byGEP_ABC",]==1] |
|
|
42 |
} |
|
|
43 |
|
|
|
44 |
gexp=fm[grepl("N:GEXP:", rownames(fm)),] |
|
|
45 |
rownames(gexp)=gsub("N:GEXP:", "", rownames(gexp)) |
|
|
46 |
|
|
|
47 |
res=fread("/research/groups/sysgen/PROJECTS/HEMAP_IMMUNOLOGY/petri_work/HEMAP_IMMUNOLOGY/GSE98588_DLBCL_antigen_correlations.tsv", data.table = F) |
|
|
48 |
|
|
|
49 |
scores=c("N:SAMP:CytolyticScore", "N:SAMP:HLAIScore", "N:SAMP:HLAIIScore") |
|
|
50 |
|
|
|
51 |
feats=c("N:SAMP:numberOfCNAs","N:SAMP:numberOfMutations", "N:SAMP:numberOfChromosomalRearrangements") |
|
|
52 |
|
|
|
53 |
mut=c("B:GNAB:KLHL6", "B:GNAB:CD58","B:GNAB:SGK1", "B:GNAB:CD83", "B:GNAB:MYD88","B:GNAB:HIST1H1E", "B:GNAB:HIST1H2BK","B:CNVR:6Q:LOSS","B:GNAB:BTG1","B:GNAB:HLA-A", "B:GNAB:ETV6", "B:GNAB:UBE2A", "B:CNVR:1P13_1:LOSS", "B:GNAB:SPEN", "B:GNAB:NFKBIA", "B:GNAB:GNA13") |
|
|
54 |
|
|
|
55 |
other.genes="N:GEXP:CD58" |
|
|
56 |
|
|
|
57 |
#************************************** GSEA ************************************** |
|
|
58 |
|
|
|
59 |
GENESETS="Combined_pathway_signatures_2017_filtered_robust.gmt" |
|
|
60 |
WD=file.path(getwd(), "GSEA") |
|
|
61 |
OUTDIR=file.path(getwd(), "GSEA") |
|
|
62 |
|
|
|
63 |
if(name=="GCB"){ |
|
|
64 |
# run GSEA: |
|
|
65 |
# command=run.GSEA(data=gexp, cls.vector = as.numeric(fm["N:SAMP:nCGA",]), datatype = "N", GENESETS = GENESETS, dataname = GSE, clsname = "nCGA", WD=WD, OUTDIR=OUTDIR) |
|
|
66 |
# try(system(command)) |
|
|
67 |
|
|
|
68 |
a=read.delim(file.path(WD, "GSE98588_DLBCL_GCB_nCGA_continuous_phenotype.Gsea.1552654676702/gsea_report_for_feat_pos_1552654676702.xls"), stringsAsFactors = F) |
|
|
69 |
b=read.delim(file.path(WD, "GSE98588_DLBCL_GCB_nCGA_continuous_phenotype.Gsea.1552654676702/gsea_report_for_feat_neg_1552654676702.xls"), stringsAsFactors = F) |
|
|
70 |
} |
|
|
71 |
|
|
|
72 |
if(name=="ABC"){ |
|
|
73 |
# run GSEA: |
|
|
74 |
# command=run.GSEA(data=gexp, cls.vector = as.numeric(fm["N:SAMP:nCGA",]), datatype = "N", GENESETS = GENESETS, dataname = GSE, clsname = "nCGA", WD=WD, OUTDIR=OUTDIR) |
|
|
75 |
# try(system(command)) |
|
|
76 |
|
|
|
77 |
a=read.delim(file.path(WD, "GSE98588_DLBCL_ABC_nCGA_continuous_phenotype.Gsea.1552654669505/gsea_report_for_feat_pos_1552654669505.xls"), stringsAsFactors = F) |
|
|
78 |
b=read.delim(file.path(WD, "GSE98588_DLBCL_ABC_nCGA_continuous_phenotype.Gsea.1552654669505/gsea_report_for_feat_neg_1552654669505.xls"), stringsAsFactors = F) |
|
|
79 |
} |
|
|
80 |
#***************************************************************************************************** |
|
|
81 |
|
|
|
82 |
c=rbind(a, b) |
|
|
83 |
|
|
|
84 |
# get GSVA visualization for the pathways |
|
|
85 |
library(GSVA) |
|
|
86 |
library(parallel) |
|
|
87 |
|
|
|
88 |
# Geneset list |
|
|
89 |
Onc.pathways=read.delim(GENESETS, stringsAsFactors = FALSE, header=F, col.names = paste("V",1:max(count.fields(GENESETS, sep = '\t'), na.rm = T)), fill = TRUE) |
|
|
90 |
|
|
|
91 |
# Make list |
|
|
92 |
listA=mclapply(1:length(Onc.pathways[,1]), function(i){A=as.character(Onc.pathways[i,3:length(Onc.pathways),]) |
|
|
93 |
B=A[!A==""&!A=="NA"]}, mc.cores=6) |
|
|
94 |
|
|
|
95 |
names(listA) <- Onc.pathways[,1] |
|
|
96 |
|
|
|
97 |
# visualize using GSVA |
|
|
98 |
viz_scores=gsva(expr = data.matrix(gexp), gset.idx.list = listA, parallel.sz=8, method="gsva", tau=0.25) |
|
|
99 |
|
|
|
100 |
# make a complex heatmap |
|
|
101 |
significant=c(c[c$FWER.p.val<0.001,1]) |
|
|
102 |
|
|
|
103 |
if(length(significant)>11)significant=significant[1:11] |
|
|
104 |
|
|
|
105 |
dat_plot=viz_scores[match(significant, toupper(rownames(viz_scores))),] |
|
|
106 |
|
|
|
107 |
profile[profile==-1] = 0 |
|
|
108 |
profile[data.matrix(gexp)<5]=0 |
|
|
109 |
f=sort(rowSums(profile[rownames(profile)%in%unique(t.df[,1]),]), decreasing = T) |
|
|
110 |
f2=signif(f/dim(profile)[2],2) |
|
|
111 |
names(f2)=f2 |
|
|
112 |
f2=f2[!f==0] |
|
|
113 |
f=f[!f==0] |
|
|
114 |
|
|
|
115 |
ag=c(paste0("N:GEXP:", names(f))) |
|
|
116 |
|
|
|
117 |
ag=ag[ag%in%rownames(fm)] |
|
|
118 |
|
|
|
119 |
add=data.frame(scale(t(pl2))) |
|
|
120 |
add[add>2]=2 |
|
|
121 |
add[add<(-2)]=-2 |
|
|
122 |
|
|
|
123 |
pl1=data.matrix(fm[scores,order(fm["N:SAMP:nCGA",], decreasing = F)]) |
|
|
124 |
pl1=t(scale(t(pl1))) |
|
|
125 |
pl1[pl1>2]=2 |
|
|
126 |
pl1[pl1<(-2)]=-2 |
|
|
127 |
|
|
|
128 |
pl2=data.matrix(fm[feats,order(fm["N:SAMP:nCGA",], decreasing = F)]) |
|
|
129 |
pl2[pl2>250]=250 |
|
|
130 |
# pl2=t(scale(t(pl2))) |
|
|
131 |
# pl2[pl2>2]=2 |
|
|
132 |
# pl2[pl2<(-2)]=-2 |
|
|
133 |
|
|
|
134 |
pl3=data.matrix(fm[ag,order(fm["N:SAMP:nCGA",], decreasing = F)]) |
|
|
135 |
pl3=t(scale(t(pl3))) |
|
|
136 |
pl3[pl3>2]=2 |
|
|
137 |
pl3[pl3<(-2)]=-2 |
|
|
138 |
|
|
|
139 |
pl4=data.matrix(fm[mut,order(fm["N:SAMP:nCGA",], decreasing = F)]) |
|
|
140 |
|
|
|
141 |
pl5=data.matrix(fm[other.genes,order(fm["N:SAMP:nCGA",], decreasing = F)]) |
|
|
142 |
pl5=t(scale(t(pl5))) |
|
|
143 |
pl5[pl5>2]=2 |
|
|
144 |
pl5[pl5<(-2)]=-2 |
|
|
145 |
|
|
|
146 |
pl6=data.matrix(dat_plot[,order(fm["N:SAMP:nCGA",], decreasing = F)]) |
|
|
147 |
|
|
|
148 |
ann=data.frame("n.CGA"=t(fm["N:SAMP:nCGA",order(fm["N:SAMP:nCGA",], decreasing = F)]), stringsAsFactors = F) |
|
|
149 |
|
|
|
150 |
library(ComplexHeatmap) |
|
|
151 |
library(circlize) |
|
|
152 |
library(multipanelfigure) |
|
|
153 |
|
|
|
154 |
rownames(pl3)=gsub(".*.:", "", rownames(pl3)) |
|
|
155 |
rownames(pl4)=gsub(".*.:", "", rownames(pl4)) |
|
|
156 |
rownames(pl6)=gsub("-.*.|_HOMO_SAPIENS", "", rownames(pl6)) |
|
|
157 |
|
|
|
158 |
p1=Heatmap(pl1, top_annotation = HeatmapAnnotation("n.CGA"=anno_barplot(ann, height = unit(10, "mm")), df = annot$COO_byGEP), cluster_columns = F, cluster_rows = F, row_names_side = "left", column_names_gp = gpar(fontsize = 8), row_names_gp = gpar(fontsize = 6), name="cluster", col = colorRamp2(c(2, 0, -2), c("red", "white", "blue")), show_column_names = F, width = unit(40, "mm"), height = unit(2*dim(pl1)[1]+10, "mm")) |
|
|
159 |
|
|
|
160 |
p2=Heatmap(pl2, top_annotation = HeatmapAnnotation("nr.cnv"=anno_barplot(data.frame(pl2[1,]), height = unit(10, "mm")), "nr.mut"=anno_barplot(data.frame(pl2[2,]), height = unit(10, "mm"), ylim=c(0,250)),"nr.strrearr"=anno_barplot(data.frame(pl2[3,]), height = unit(10, "mm"))), cluster_columns = F, cluster_rows = F, row_names_side = "left", column_names_gp = gpar(fontsize = 8), row_names_gp = gpar(fontsize = 6), name="Samp-features", col=colorRamp2(c(-2, 0, 2), c("grey85", "white", "indianred")), show_column_names = F, width = unit(40, "mm"), height = unit(2*dim(pl2)[1]+10, "mm")) |
|
|
161 |
|
|
|
162 |
p3=Heatmap(pl3, cluster_columns = F, cluster_rows = F, row_names_side = "left", column_names_gp = gpar(fontsize = 8), row_names_gp = gpar(fontsize = 6), name="Scaled log2\nexpression", col=colorRamp2(c(-2,0,2), c("blue", "white", "red")), show_column_names = F, width = unit(40, "mm"), height = unit(2*dim(pl3)[1], "mm")) + Heatmap(f2, width = unit(5, "mm"), row_names_gp = gpar(fontsize = 6)) |
|
|
163 |
|
|
|
164 |
p4=Heatmap(pl4, cluster_columns = F, cluster_rows = F, row_names_side = "left", column_names_gp = gpar(fontsize = 8), row_names_gp = gpar(fontsize = 6), name="Mutations", col=colorRamp2(c(0,1), c("grey85", "darkgreen")), show_column_names = F, width = unit(40, "mm"), height = unit(2*dim(pl4)[1], "mm")) |
|
|
165 |
|
|
|
166 |
p5=Heatmap(pl5, cluster_columns = F, cluster_rows = F, row_names_side = "left", column_names_gp = gpar(fontsize = 8), row_names_gp = gpar(fontsize = 6), name="Scaled log2\nexpression", col=colorRamp2(c(-2,0,2), c("blue", "white", "red")), show_column_names = F, width = unit(40, "mm"), height = unit(2*dim(pl5)[1], "mm")) |
|
|
167 |
|
|
|
168 |
p6=Heatmap(pl6, cluster_columns = F, cluster_rows = F, row_names_side = "left", column_names_gp = gpar(fontsize = 8), row_names_gp = gpar(fontsize = 6), name="Scaled log2\nexpression", col=colorRamp2(c(-0.6, 0, 0.6), c("grey50", "white", "red")), show_column_names = F, width = unit(40, "mm"), height = unit(2*dim(pl6)[1], "mm")) |
|
|
169 |
|
|
|
170 |
panels=list(p1, p2, p3, p4, p5, p6) |
|
|
171 |
panels=panels[!is.null(panels)] |
|
|
172 |
nrows=sum(c(dim(pl1)[1], dim(pl2)[1], dim(pl3)[1], dim(pl4)[1], dim(pl5)[1], dim(pl6)[1])) |
|
|
173 |
|
|
|
174 |
figure <- multi_panel_figure(width = 200, height = 220+nrows*3, rows = length(panels), columns = 1, panel_label_type = "lower-alpha") |
|
|
175 |
|
|
|
176 |
for(i in seq(panels))figure <- fill_panel(figure,panels[[i]], row = i, column = 1) |
|
|
177 |
|
|
|
178 |
save_multi_panel_figure(figure, filename=paste0("Fig6H_FigS6H_", "_", GSE, "_CGA_heatmap.pdf")) |
|
|
179 |
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
gexp=fm[grepl("N:GEXP:", rownames(fm)),] |
|
|
183 |
rownames(gexp)=gsub("N:GEXP:", "", rownames(gexp)) |
|
|
184 |
|
|
|
185 |
# All pathways |
|
|
186 |
GENESETS="/research/work/ppolonen/genesets/Combined_pathway_signatures_2017_filtered_robust.gmt" |
|
|
187 |
WD="/research/groups/sysgen/PROJECTS/HEMAP_IMMUNOLOGY/petri_work/HEMAP_IMMUNOLOGY/" |
|
|
188 |
OUTDIR="/research/groups/sysgen/PROJECTS/HEMAP_IMMUNOLOGY/petri_work/HEMAP_IMMUNOLOGY/" |
|
|
189 |
|
|
|
190 |
# get GSVA visualization for the pathways |
|
|
191 |
# Geneset list |
|
|
192 |
Onc.pathways=read.delim(GENESETS, stringsAsFactors = FALSE, header=F, col.names = paste("V",1:max(count.fields(GENESETS, sep = '\t'), na.rm = T)), fill = TRUE) |
|
|
193 |
|
|
|
194 |
# Make list |
|
|
195 |
listA=mclapply(1:length(Onc.pathways[,1]), function(i){A=as.character(Onc.pathways[i,3:length(Onc.pathways),]) |
|
|
196 |
B=A[!A==""&!A=="NA"]}, mc.cores=6) |
|
|
197 |
|
|
|
198 |
names(listA) <- Onc.pathways[,1] |
|
|
199 |
|
|
|
200 |
viz_scores=gsva(expr = data.matrix(gexp), gset.idx.list = listA, parallel.sz=8, method="gsva", tau=0.25) |
|
|
201 |
|
|
|
202 |
expressed_testis_num=colSums(profile[rownames(profile)%in%unique(t.df$gene),]) |
|
|
203 |
feat_class=expressed_testis_num |
|
|
204 |
feat_class[expressed_testis_num==0]="0 CGA" |
|
|
205 |
feat_class[expressed_testis_num>=1&expressed_testis_num<=2]="1-2 CGA" |
|
|
206 |
feat_class[expressed_testis_num>=3]=">3 CGA" |
|
|
207 |
|
|
|
208 |
logicalVectors=lapply(unique(feat_class), function(cl)feat_class%in%cl) |
|
|
209 |
names(logicalVectors)=paste("ABC", unique(feat_class)) |
|
|
210 |
|
|
|
211 |
annof=data.frame("HLAI"=annot$HLAIScore, "HLAII"=annot$HLAIIScore, "CytolyticScore"=annot$CytolyticScore, "TNFA_SIGNALING_VIA_NFKB"=viz_scores[rownames(viz_scores)%in%"TNFA_SIGNALING_VIA_NFKB-MsigDB_HALLMARKS",]) |
|
|
212 |
|
|
|
213 |
genelist=c("HLAI", "HLAII", "CytolyticScore", "TNFA_SIGNALING_VIA_NFKB") |
|
|
214 |
p.all=lapply(genelist, plot.boxplot, logicalVectors = logicalVectors[c(1,3,2)], data = t(annof),order.bl = F,spread = T) |
|
|
215 |
|
|
|
216 |
TestGeneWilcox("HLAI", data = t(annof), logicalVectors = logicalVectors[c(1,3,2)], logicalVector_normals = logicalVectors[c(1,3,2)], ALTERNATIVE = "less") |
|
|
217 |
TestGeneWilcox("HLAII", data = t(annof), logicalVectors = logicalVectors[c(1,3,2)], logicalVector_normals = logicalVectors[c(1,3,2)], ALTERNATIVE = "less") |
|
|
218 |
TestGeneWilcox("CytolyticScore", data = t(annof), logicalVectors = logicalVectors[c(1,3,2)], logicalVector_normals = logicalVectors[c(1,3,2)], ALTERNATIVE = "less") |
|
|
219 |
TestGeneWilcox("TNFA_SIGNALING_VIA_NFKB", data = t(annof), logicalVectors = logicalVectors[c(1,3,2)], logicalVector_normals = logicalVectors[c(1,3,2)], ALTERNATIVE = "less") |
|
|
220 |
|
|
|
221 |
ggsave(plot = p.all[[1]], filename = paste0(GSE, "_HLA.pdf"), width = unit(3.25, "cm"), height = unit(3, "cm")) |
|
|
222 |
ggsave(plot = p.all[[2]], filename = paste0(GSE, "_HLAII.pdf"), width = unit(3.25, "cm"), height = unit(3, "cm")) |
|
|
223 |
ggsave(plot = p.all[[3]], filename = paste0("FigS6I_", GSE, "_CytScore.pdf"), width = unit(3.25, "cm"), height = unit(3, "cm")) |
|
|
224 |
ggsave(plot = p.all[[4]], filename = paste0(GSE, "_TNFA.pdf"), width = unit(3.25, "cm"), height = unit(3, "cm")) |