Switch to unified view

a b/R/interpretation_analysis.R
1
# interpretation_analysis.R
2
require(data.table)
3
setDTthreads(8)
4
require(ggfortify)
5
require(umap)
6
exp_path = "Data/CV_Results/HyperOpt_DRP_ResponseOnly_gnndrug_exp_HyperOpt_DRP_CTRP_ResponseOnly_EncoderTrain_Split_BOTH_NoBottleNeck_NoTCGAPretrain_MergeByLMF_WeightedRMSELoss_GNNDrugs_gnndrug_exp/"
7
prot_path = "Data/CV_Results/HyperOpt_DRP_ResponseOnly_gnndrug_prot_HyperOpt_DRP_CTRP_ResponseOnly_EncoderTrain_Split_BOTH_NoBottleNeck_NoTCGAPretrain_MergeByLMF_WeightedRMSELoss_GNNDrugs_gnndrug_prot/"
8
dir.create("Plots/DRP")
9
dir.create("Plots/DRP/Lineage_Results")
10
11
targeted_drugs <- c("Idelalisib", "Olaparib", "Venetoclax", "Crizotinib", "Regorafenib", 
12
                    "Tretinoin", "Bortezomib", "Cabozantinib", "Dasatinib", "Erlotinib", 
13
                    "Sonidegib", "Vandetanib", "Axitinib", "Ibrutinib", "Gefitinib", 
14
                    "Nilotinib", "Tamoxifen", "Bosutinib", "Pazopanib", "Lapatinib", 
15
                    "Dabrafenib", "Bexarotene", "Temsirolimus", "Belinostat", 
16
                    "Sunitinib", "Vorinostat", "Trametinib", "Fulvestrant", "Sorafenib", 
17
                    "Vemurafenib", "Alpelisib")
18
19
ctrp <- fread("Data/DRP_Training_Data/CTRP_AAC_SMILES.txt")
20
21
length(targeted_drugs)
22
23
length(unique(ctrp[cpd_name %in% targeted_drugs]$ccl_name))  # 842 cell lines tested with targeted drugs
24
length(unique(ctrp[cpd_name %in% targeted_drugs & area_above_curve >= 0.7]$ccl_name))  # 302 of them with AAC >= 0.7
25
nrow(unique(ctrp[cpd_name %in% targeted_drugs & area_above_curve >= 0.7]))  # resulting in 395 potential samples
26
# Load cell line and interpretation results ===============================
27
exp_data <- fread(paste0(exp_path, "integrated_gradients_results.csv"))
28
prot_data <- fread(paste0(prot_path, "integrated_gradients_results.csv"))
29
cell_line_data <- fread("Data/DRP_Training_Data/DepMap_21Q2_Line_Info.csv")
30
# cur_data <- fread(paste0(path, "GDSC2_AAC_MORGAN_512_inference_results.csv"))
31
# cur_cv <- fread(paste0(path, "CV_results.csv"))
32
33
dim(cur_data)
34
exp_data[1:5, 1:10]
35
max(exp_data[1:5, -c(1:7)])
36
exp_data[RMSE_loss < 0.2][1:5, 1:5]
37
prot_data[RMSE_loss < 0.1][1:5, 1:5]
38
prot_data[RMSE_loss < 0.1][, 1:6]
39
cur_data$RMSE_loss[1]
40
cur_data$DeepLIFT_delta[1]
41
42
exp_data <- merge(exp_data, cell_line_data[, c("stripped_cell_line_name", "lineage")], by.x = "cell_name", by.y = "stripped_cell_line_name")
43
prot_data <- merge(prot_data, cell_line_data[, c("stripped_cell_line_name", "lineage")], by.x = "cell_name", by.y = "stripped_cell_line_name")
44
45
unique(prot_data$cpd_name)
46
# cur_data[, total_drug_attrib := sum(.SD), .SDcols = drug_cols, by = ]
47
setcolorder(prot_data, 'lineage')
48
prot_data[lineage == "lung" & RMSE_loss < 0.3][, 1:6]
49
prot_data[lineage == "lung"][, 1:6]
50
setcolorder(exp_data, 'lineage')
51
52
cur_data[1:5, 1:10]
53
exp_data$V1 <- NULL
54
prot_data$V1 <- NULL
55
# drug_cols = colnames(cur_data)[7:518]
56
prot_cols = colnames(prot_data)[8:ncol(prot_data)]
57
exp_cols = colnames(exp_data)[8:ncol(exp_data)]
58
col_types <- sapply(cur_data[, ..prot_cols], class)
59
which(col_types == "character")
60
unique(col_types)
61
62
mean(exp_data$RMSE_loss)
63
mean(prot_data$RMSE_loss)
64
# cur_data[lineage %like% 'blood'][, 1:8]
65
exp_data[cpd_name %like% 'Paclitaxel' & target >= 0.9 & RMSE_loss <= 0.1][, 1:8]
66
prot_data[cpd_name %like% 'Paclitaxel' & target >= 0.9 & RMSE_loss <= 0.1][, 1:8]
67
exp_data[cpd_name %like% 'Paclitaxel' & target >= 0.9 & RMSE_loss <= 0.1]$cell_name %in% prot_data[cpd_name %like% 'Paclitaxel' & target >= 0.9 & RMSE_loss <= 0.1]$cell_name
68
cur_data[cpd_name %like% 'Paclitaxel' & cell_name == "GA10"][, 1:8]
69
70
71
# Distinguish positive and negative attributions
72
exp_temp <- exp_data[cpd_name %like% 'Paclitaxel' & cell_name == "697"]
73
prot_temp <- prot_data[cpd_name %like% 'Paclitaxel' & cell_name == "697"]
74
75
# temp <- cur_data[RMSE_loss <= 0.1]
76
# temp[1:100, 1:8]
77
78
prot_temp <- melt(prot_temp[1, ..prot_cols])
79
prot_pos_temp <- prot_temp[value > 0]
80
top_10 <- quantile(prot_pos_temp$value, 0.9)
81
quantile(prot_pos_temp$value)
82
quantile(prot_pos_temp$value)[4]  # %75
83
84
# Top Prots
85
prot_pos_temp[value > quantile(prot_pos_temp$value)[4]]
86
prot_top_5 <- prot_pos_temp[value > quantile(prot_pos_temp$value, 0.95)]
87
setorder(prot_top_5, -value)
88
prot_top_5$variable <- gsub("prot_", "", prot_top_5$variable)
89
top_5_prots <- setNames(prot_top_5$value, prot_top_5$variable)
90
91
# Bottom Prots
92
# temp <- melt(temp[1, ..prot_cols])
93
neg_temp <- prot_temp[value < 0]
94
bottom_5 <- neg_temp[value < quantile(neg_temp$value, 0.05)]
95
bottom_5$value <- abs(bottom_5$value)
96
setorder(bottom_5, -value)
97
bottom_5$variable <- gsub("prot_", "", bottom_5$variable)
98
bottom_5_prots <- setNames(bottom_5$value, bottom_5$variable)
99
100
prot_top_5[variable %like% "Q02548"] # PAX5 for leukemia
101
prot_temp[variable %like% "Q02548"]
102
prot_temp[variable %like% "PAX5"]
103
prot_temp[variable %like% "NBN"]
104
prot_temp[variable %like% "GNB1"]
105
prot_temp[variable %like% "FLT3"]
106
prot_temp[variable %like% "ETV6"]
107
prot_temp[variable %like% "ACTB"]
108
109
prot_top_5[variable %like% "FLT3"]
110
prot_top_5[variable %like% "PAX5"]
111
prot_top_5[variable %like% "NBN"]
112
prot_top_5[variable %like% "GNB1"]
113
prot_top_5[variable %like% "ETV6"]
114
prot_top_5[variable %like% "ACTB"]
115
116
exp_temp <- melt(exp_temp[1, ..exp_cols])
117
exp_pos_temp <- exp_temp[value > 0]
118
top_10 <- quantile(exp_pos_temp$value, 0.9)
119
quantile(exp_pos_temp$value)
120
quantile(exp_pos_temp$value)[4]  # %75
121
exp_pos_temp[value > quantile(exp_pos_temp$value)[4]]
122
exp_top_5 <- exp_pos_temp[value > quantile(exp_pos_temp$value, 0.95)]
123
setorder(exp_top_5, -value)
124
exp_top_5$variable <- gsub("exp_", "", exp_top_5$variable)
125
top_5_exps <- setNames(exp_top_5$value, exp_top_5$variable)
126
127
exp_temp[variable %like% "PAX5"]
128
exp_temp[variable %like% "NBN"]
129
exp_temp[variable %like% "GNB1"]
130
exp_temp[variable %like% "FLT3"]
131
exp_temp[variable %like% "ETV6"]
132
exp_temp[variable %like% "ACTB"]
133
134
exp_top_5[variable %like% "FLT3"]
135
exp_top_5[variable %like% "PAX5"]
136
exp_top_5[variable %like% "NBN"]
137
exp_top_5[variable %like% "GNB1"]
138
exp_top_5[variable %like% "ETV6"]
139
exp_top_5[variable %like% "ACTB"]
140
141
exp_top_5[1:10,]
142
temp <- cur_data[RMSE_loss <= 0.1]
143
144
temp[1, 1:8]
145
temp[variable %like% "XPO1"]
146
147
temp <- melt(temp[1, ..prot_cols])
148
neg_temp <- temp[value < 0]
149
bottom_5 <- neg_temp[value < quantile(neg_temp$value, 0.05)]
150
bottom_5$value <- abs(bottom_5$value)
151
setorder(bottom_5, -value)
152
bottom_5$variable <- gsub("exp_", "", bottom_5$variable)
153
bottom_5_prots <- setNames(bottom_5$value, bottom_5$variable)
154
155
# ==== clusterProfiler ====
156
# BiocManager::install("clusterProfiler")
157
# BiocManager::install("pathview")
158
# BiocManager::install("enrichplot")
159
160
require(clusterProfiler)
161
require(pathview)
162
organism = "org.Hs.eg.db"
163
# BiocManager::install(organism, character.only = TRUE)
164
library(organism, character.only = TRUE)
165
keytypes(get(organism))
166
# org.Hs.eg.db
167
top_gse_prot <- gseGO(geneList=top_5_prots, 
168
             ont ="ALL", 
169
             keyType = "UNIPROT", 
170
             # nPerm = 10000,
171
             minGSSize = 3, 
172
             maxGSSize = 800, 
173
             pvalueCutoff = 0.05, 
174
             verbose = TRUE, 
175
             OrgDb = get(organism), 
176
             pAdjustMethod = "none")
177
p_top_prot <- ridgeplot(top_gse_prot) + labs(x = "enrichment distribution") + ggtitle("Top 5% Protein Attributions GSE",
178
                                                                            subtitle = "Cell-line 697 (lymphoblastic leukemia) + Paclitaxel\nTarget: 0.97, Predicted: 0.94")
179
ggsave("Plots/Interpretation/IntegratedGradients/GSE/gnndrug_prot_697_Paclitaxel_GSE_top_5.pdf", p_top_prot, 
180
       width = 10, units = "in")
181
182
183
bottom_gse_prot <- gseGO(geneList=bottom_5_prots, 
184
                  ont ="ALL", 
185
                  keyType = "UNIPROT", 
186
                  # nPerm = 10000,
187
                  minGSSize = 3, 
188
                  maxGSSize = 800, 
189
                  pvalueCutoff = 0.05, 
190
                  verbose = TRUE, 
191
                  OrgDb = get(organism), 
192
                  pAdjustMethod = "none")
193
p_bottom_prot <- ridgeplot(bottom_gse_prot) + labs(x = "enrichment distribution") + ggtitle("Bottom 5% Protein Attributions GSE",
194
                                                                                  subtitle = "Cell-line 697 (lymphoblastic leukemia) + Paclitaxel\nTarget: 0.97, Predicted: 0.94")
195
ggsave("Plots/Interpretation/IntegratedGradients/GSE/gnndrug_prot_697_Paclitaxel_GSE_bottom_5.pdf", p_bottom_prot, 
196
       width = 20, units = "in")
197
198
require(cowplot)
199
cowplot::plot_grid(p_top_prot, p_bottom_prot, ncol = 2)
200
dir.create("Plots/Interpretation")
201
dir.create("Plots/Interpretation/IntegratedGradients")
202
dir.create("Plots/Interpretation/IntegratedGradients/GSE")
203
ggsave("Plots/Interpretation/IntegratedGradients/GSE/gnndrug_prot_697_Paclitaxel_GSE.pdf", width = 20, units = "in")
204
205
206
gse_exp <- gseGO(geneList=top_5_exps, 
207
                 ont ="ALL", 
208
                 keyType = "SYMBOL", 
209
                 nPerm = 10000,
210
                 minGSSize = 3, 
211
                 maxGSSize = 800, 
212
                 pvalueCutoff = 0.05, 
213
                 verbose = TRUE, 
214
                 OrgDb = get(organism), 
215
                 pAdjustMethod = "none")
216
p_top_exp <- ridgeplot(gse_exp) + labs(x = "enrichment distribution") + ggtitle("Top 5% RNA-Seq Attributions GSE")
217
218
require(cowplot)
219
cowplot::plot_grid(p_top_prot, p_top_exp, ncol = 2)
220
dir.create("Plots/Interpretation")
221
dir.create("Plots/Interpretation/IntegratedGradients")
222
dir.create("Plots/Interpretation/IntegratedGradients/GSE")
223
ggsave("Plots/Interpretation/IntegratedGradients/GSE/gnndrug_exp_5637_leptomycin_b_GSE.pdf", width = 20, units = "in")
224
ggsave("Plots/Interpretation/IntegratedGradients/GSE/gnndrug_exp_vs_prot_697_paclitaxel_GSE.pdf", width = 20, units = "in")
225
max(cur_data$MSE_loss)
226
min(cur_data$MSE_loss)
227
mean(cur_data$MSE_loss)
228
quantile(cur_data$MSE_loss)
229
230
# Which lineages are easier to learn compared to others?
231
easy_samples <- cur_data[MSE_loss < quantile(cur_data$MSE_loss)[4]][, 1:6]
232
hard_samples <- cur_data[MSE_loss > quantile(cur_data$MSE_loss)[4]][, 1:6]
233
easy_samples$type <- "easy"
234
hard_samples$type <- "hard"
235
easy_hard <- rbindlist(list(easy_samples[, c("lineage", "type")], hard_samples[, c("lineage", "type")]))
236
ggplot(data = easy_hard) + geom_bar(mapping = aes(x = lineage, fill = type), stat = "count", position = "stack") + 
237
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
238
239
# easy_hard <- within(easy_hard, type <- factor(type, levels = names(sort(table(type), decreasing = T))))
240
ggplot(data = easy_hard) + geom_bar(mapping = aes(x = reorder(lineage,lineage,
241
                                                              function(x)-length(x)), fill = type)) + 
242
  theme(axis.text.x = element_text(angle = 45, hjust = 1), axis.text.y = element_text()) + 
243
  xlab("Cell Line Lineage") + ylab("Cell Line x Drug Count")
244
245
# cur_data[, total_drug_attrib := sum(.SD), .SDcols = drug_cols, by = ]
246
quantile(cur_data[2, ..drug_cols])
247
max(cur_data[2, ..drug_cols])
248
min(cur_data[2, ..drug_cols])
249
250
251
252
# Add max/min for each attribute for each data type
253
cur_data[, max_drug := max(.SD), .SDcols = drug_cols, by = c("cell_name", "cpd_name")]
254
cur_data[, min_drug := min(.SD), .SDcols = drug_cols, by = c("cell_name", "cpd_name")]
255
cur_data[, max_prot := max(.SD), .SDcols = prot_cols, by = c("cell_name", "cpd_name")]
256
cur_data[, min_prot := min(.SD), .SDcols = prot_cols, by = c("cell_name", "cpd_name")]
257
258
cur_data[, "max_drug"]
259
cur_data[, "min_drug"]
260
cur_data[, "min_prot"]
261
cur_data[, "max_prot"]
262
263
# Plot histogram encompassing all positions of the drug data
264
265
plot(cur_data[2, ..drug_cols])
266
267
268
269
pca_res <- prcomp(cur_data[, ..drug_cols], scale. = TRUE)
270
umap_drug <- umap(cur_data[, ..drug_cols])
271
autoplot(pca_res, data = cur_data[, c("MSE_loss", "lineage", drug_cols), with = F], colour = "MSE_loss")
272
autoplot(pca_res, data = cur_data[, c("MSE_loss", "lineage", drug_cols), with = F], colour = "lineage")
273
274
cur_data[, ..prot_cols][,1]
275
276
pca_prot <- prcomp(cur_data[, ..prot_cols], scale. = TRUE)
277
autoplot(pca_prot, data = cur_data[, c("MSE_loss", "lineage", prot_cols), with = F], colour = "lineage")
278
autoplot(pca_prot, data = cur_data[, c("MSE_loss", "lineage", prot_cols), with = F], colour = "MSE_loss")