-
Notifications
You must be signed in to change notification settings - Fork 0
/
DrugCombi_QC.Rmd
412 lines (351 loc) · 16.7 KB
/
DrugCombi_QC.Rmd
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
---
title: "CLL drug combinations ex-vivo: Quality Control"
author: "Britta Velten"
date: "15 April 2020"
output:
BiocStyle::html_document:
toc: true
toc_depth: 3
params:
today: 200415
---
#Introduction
Takes the data objects created in `DrugCombi_DataImport.Rmd` and performs further QC on the data.
```{r, echo=F}
library(knitr )
knitr::opts_chunk$set(warning=FALSE, message=FALSE)
options(stringAsFactors = FALSE)
```
```{r, echo=F}
library(ggplot2)
library(RColorBrewer)
library(Biobase)
library(abind)
library(grid)
library(gtable)
library(reshape2)
library(gridExtra)
require(pracma)
library(reshape2)
library(dplyr)
library(pheatmap)
library(magrittr)
library(lattice)
library(tidyverse)
```
```{r}
datadir <- "data"
outdir = "out"
today <- params$today
figdir = paste0("figs", today, "/figuresQC/")
if(!dir.exists(figdir)) dir.create(figdir)
knitr::opts_chunk$set(dev = c("png", "pdf"), fig.path = figdir)
```
# Preparations
# Data Import
Load processed Data from `DrugCombi_DataImport.Rmd`.
```{r}
load(file.path(outdir, paste0("CLLCombiData_",today,".RData")))
```
Loaded dataframe from ImportedData:
* `CompleteDF` contains the raw and normalized values per well/plate/screen
* `df4ana` contains the normalized values for each single drug and drug-drug combination per sample and concentration)
* `DrugMetaList` contains info about the drugs used as base and combi compounds
* `SetUpList` contains the plate setups for the screens
## Setting colors for patients.
```{r}
colset = grDevices::colors()[!grepl("^gr(a|e)y", grDevices::colors())]
patcol = unique(df4ana$PatientID)
set.seed(2808)
patcol = setNames(colset[sample.int(length(colset),length(patcol))], nm=patcol)
```
Color legend for patient:
```{r legendPatients, eval=F, echo=F}
ggplot(data=data.frame(X=names(patcol), Y=1)) +
geom_bar(aes(x=X, y=Y, fill=X), stat="identity") +
scale_fill_manual(values=patcol) + guides(fill=FALSE) +
theme(axis.text.x=element_text(angle=90, hjust=1, vjust=0.5)) +
xlab("") + ylab("")
```
# Plate plots
Produces plot of the raw and normalized viability values for each plate based on the data frame containting the per well values (`CompleteDF`).
Raw values:
```{r plateplots_raw, fig.width=20, fig.height=100, eval=FALSE}
ggplot(CompleteDF, aes(y=factor(WellLetter, levels=letters[16:1]), x=WellNo)) +
facet_wrap(~ PlateID, ncol=4) + geom_tile(aes(fill=rawValue)) +
scale_fill_gradient(low="white", high="black")
```
Normalized values:
```{r plateplots_norm, fig.width=20, fig.height=100, eval=FALSE}
ggplot(CompleteDF, aes(y=factor(WellLetter, levels=letters[16:1]), x=WellNo)) +
facet_wrap(~ PlateID, ncol=4) + geom_tile(aes(fill=normalizedValue)) +
scale_fill_gradient(low="white", high="black")
```
# Check reproducibility between replicates and average
Until now the dataframe contains two replicates for each concentration and drug combination in screen 1 and 2. Here, we check the agreement between replicates and then continue with averages.
Replicates are present in screen 1 and 2: Here every measurement has one replicate
```{r}
for (screen in sort(as.character(unique(df4ana$ScreenNo)))){
df <- filter(df4ana, ScreenNo==screen)
checkDup <- select(df, PatientID, CDrugID, BDrugID, ScreenNo, CDrugConc, BDrugConcId)
dupIDX <- which(duplicated(checkDup)|duplicated(checkDup, fromLast=T))
print(paste(screen,": ", length(dupIDX), " out of ", nrow(df), " duplicated", sep=""))
}
```
Annotate replicates
```{r}
df4ana$replicate <- sapply(duplicated(select(df4ana, PatientID, CDrugID,
BDrugID, ScreenNo, CDrugConc, BDrugConcId)),
function(bool) ifelse(bool,2,1))
sum(df4ana$replicate==2)
df4ana %<>% mutate(patrep = paste(PatientID, replicate, sep="_"))
CompleteDF$replicate <- sapply(duplicated(select(CompleteDF, PatientID, BaseDrugID,
BaseDrugConcID, CombiDrug, ScreenDate,
BaseDrugConc, BaseDrugName, ScreenNo,
CombiDrugConc, CombiDrugID,CombiDrug_longname)),
function(bool) ifelse(bool,2,1))
sum(CompleteDF$replicate==2)
CompleteDF %<>% mutate(patrep = paste(PatientID, replicate, sep="_"))
```
```{r replicateConsensus_raw_all, eval=FALSE, echo=FALSE}
df_reps <- filter(CompleteDF, ScreenNo %in% c("SS1","SS2")) %>%
filter(BaseDrugID != "DM") %>% # remove control wells (no Drug B nor C)
filter(BaseDrugID != "DM+") %>% # remove wells with only C (muliple wells-average)
select(-starts_with("Well")) %>%
select(-patrep) %>%
select(-normalizedValue) %>%
mutate(replicate = paste0("rep",replicate)) %>%
spread(key="replicate", value="rawValue")
ggplot(df_reps, aes(x=rep1, y=rep2, col=as.character(PatientID))) + geom_point() +
scale_color_manual(values = patcol) +
geom_abline(intercept=0,slope=1, lty="dashed") +
geom_text(x =100000, y =600000, label = paste("r =", round(cor(df_reps$rep1,df_reps$rep2),2)), col="black", size =5) +
theme_bw() + guides(col=FALSE) + xlab("raw intensities (replicate 1)") + ylab("raw intensities (replicate 2)") +coord_fixed()
```
Check agreement between replicates for the drug-drug combination values (rawValueBC or effectBC), output: "replicateConsensus.pdf"
```{r replicateConsensus_raw}
# raw drug-drug combination intensities
df_reps <- filter(df4ana, ScreenNo %in% c("SS1","SS2")) %>%
select(-starts_with("effect")) %>%
select(-patrep) %>%
mutate(replicate = paste0("rep",replicate)) %>%
spread(key="replicate", value="rawValueBC")
ggplot(df_reps, aes(x=rep1, y=rep2, col=PatientID)) + geom_point() +
scale_color_manual(values = patcol) +
geom_abline(intercept=0,slope=1, lty="dashed") +
geom_text(x =100000, y =600000,
label = paste("r =", round(cor(df_reps$rep1,df_reps$rep2),2)),
col="black", size =5) +
theme_bw() + guides(col=FALSE) + xlab("raw intensities (replicate 1)") +
ylab("raw intensities (replicate 2)") + coord_fixed()
```
```{r replicateConsensus_normalized}
# normalized drug-drug combination viabilities
df_reps <- filter(df4ana, ScreenNo %in% c("SS1","SS2")) %>%
select(-c(effectB, effectC, patrep, rawValueBC)) %>%
mutate(replicate = paste0("rep",replicate)) %>%
spread(key="replicate", value="effectBC")
ggplot(df_reps, aes(x=rep1, y=rep2, col=PatientID)) + geom_point() +
scale_color_manual(values = patcol)+ theme_bw() +
geom_abline(intercept=0,slope=1, lty="dashed") +
geom_text(x =0.3, y =1.2,
label = paste("r =", round(cor(df_reps$rep1,df_reps$rep2),2)),
col="black", size =5) +
guides(col=FALSE) + xlab("normalized viabilities (replicate 1)") +
ylab("normalized viabilities (replicate 2)")+coord_fixed()
# normalized base drug viabilities
df_reps <- filter(df4ana, ScreenNo %in% c("SS1","SS2")) %>%
select(-c(effectBC, effectC, patrep, rawValueBC)) %>%
mutate(replicate = paste0("rep",replicate)) %>%
spread(key="replicate", value="effectB")
ggplot(df_reps, aes(x=rep1, y=rep2, col=PatientID)) + geom_point() +
scale_color_manual(values = patcol)+ theme_bw() +
geom_abline(intercept=0,slope=1, lty="dashed") +
geom_text(x =0.3, y =1.2,
label = paste("r =", round(cor(df_reps$rep1,df_reps$rep2),2)),
col="black", size =5) +
guides(col=FALSE) + xlab("normalized viabilities (replicate 1)") +
ylab("normalized viabilities (replicate 2)")+ coord_fixed()
# normalized combi drug viabilities
df_reps <- filter(df4ana, ScreenNo %in% c("SS1","SS2")) %>%
select(-c(effectBC, effectB, patrep, rawValueBC)) %>%
mutate(replicate = paste0("rep",replicate)) %>%
spread(key="replicate", value="effectC")
ggplot(df_reps, aes(x=rep1, y=rep2, col=PatientID)) + geom_point() +
scale_color_manual(values = patcol)+ theme_bw() +
geom_abline(intercept=0,slope=1, lty="dashed") +
geom_text(x =0.7, y =1.2,
label = paste("r =", round(cor(df_reps$rep1,df_reps$rep2),2)),
col="black", size =5) +
guides(col=FALSE) + xlab("normalized viabilities (replicate 1)") +
ylab("normalized viabilities (replicate 2)")+ coord_fixed()
```
Note: The last plot should be a straight line as same DM+ wells used for effectC and only one value per plate
As screen 1 is not included for tha analysis sue to the lack of a good control plate, we limit the replicate analysis to screen 2:
Check agreement between replicates, output: "replicateConsensus.pdf"
```{r replicateConsensus_raw_screen2}
# raw drug-drug combination intensities
df_reps <- filter(df4ana, ScreenNo %in% c("SS2")) %>%
select(-starts_with("effect")) %>%
select(-patrep) %>%
mutate(replicate = paste0("rep",replicate)) %>%
spread(key="replicate", value="rawValueBC")
ggplot(df_reps, aes(x=rep1, y=rep2, col=PatientID)) + geom_point(size=3) +
scale_color_manual(values = patcol) +
geom_abline(intercept=0,slope=1, lty="dashed") +
geom_text(x =100000, y =600000,
label = paste("r =", round(cor(df_reps$rep1,df_reps$rep2),2)), col="black", size =7) +
theme_bw(base_size = 20) + guides(col=FALSE) + xlab("raw intensities (replicate 1)") +
ylab("raw intensities (replicate 2)") +coord_fixed()
```
Calculate average value for replicates
```{r}
df4anaAvreplicates <- df4ana %>%
group_by(CDrugAbrv, CDrugName, CDrugID, CDrugConc, CDrugNameLong, BDrugName, BDrugID, BDrugConc, BDrugConcId, PatientID, ScreenDate,ScreenNo) %>%
summarise(effectBC = mean(effectBC),
effectB = mean(effectB),
effectC = mean(effectC),
rawValueBC = mean(rawValueBC)) %>%
ungroup()
```
# Medpolish: Comparison of measured single effects with decomposition of combination effect by medpolish
As QC to see systematic trend in difference of single effect and combination.
Use the measured viabilities after treatment with both drugs and derive from them the single drug effect by
$\log(v_{ij})= \log(v_{i})+\log(v_{j}) + r_{ij}$ using medpolish.
```{r medpolish}
listCombiEffectMatricesPerPatrep<-lapply(unique(df4ana$patrep), function(pr) {
filter(df4ana, patrep==pr) %>%
mutate(drBc=paste(BDrugID, BDrugConcId, sep="_")) %>%
melt(id.vars=c("CDrugAbrv", "drBc"), measure.vars = c("effectBC")) %>% acast(CDrugAbrv~drBc)
})
listSingleEffectBVectorsPerPatrep<-lapply(unique(df4ana$patrep), function(pr) {
dftmp<-filter(df4ana, patrep==pr) %>% mutate(drBc=paste(BDrugID, BDrugConcId, sep="_")) %>% melt(id.vars=c( "drBc"), measure.vars = c("effectB"))
dftmp<-dftmp[!duplicated(dftmp),] #remove duplicated rows as for each combi drug the same
effectBvec<-dftmp$value
names(effectBvec)<-dftmp$drBc
effectBvec
})
listSingleEffectCVectorsPerPatrep<-lapply(unique(df4ana$patrep), function(pr) {
dftmp<-filter(df4ana, patrep==pr) %>% mutate(drBc=paste(BDrugID, BDrugConcId, sep="_"))%>% melt(id.vars=c( "CDrugAbrv"), measure.vars = c("effectC"))
dftmp<-dftmp[!duplicated(dftmp),] #remove duplicated rows as for each base drug the same
effectCvec<-dftmp$value
names(effectCvec)<-dftmp$CDrugAbrv
effectCvec
})
medpolish.out.list <- lapply(listCombiEffectMatricesPerPatrep, function(mat) medpolish(log(mat)))
effectBmedpol <- lapply(medpolish.out.list, function(med) exp(med$col))
effectCmedpol <- lapply(medpolish.out.list, function(med) exp(med$row))
par(mfrow=c(3,3))
for( i in 1:length(unique(df4ana$patrep))) {
plot(effectBmedpol[[i]], listSingleEffectBVectorsPerPatrep[[i]][names(effectBmedpol[[i]])], xlab="medpolished", ylab="measured", main=paste("effectB"))
lines(seq(0,1,0.1),seq(0,1,0.1))
}
for( i in 1:length(unique(df4ana$patrep))) {
plot(effectCmedpol[[i]], listSingleEffectCVectorsPerPatrep[[i]][names(effectCmedpol[[i]])], xlab="medpolished", ylab="measured", main=paste("effectC"), xlim=c(0,1.2), ylim=c(0,1.2))
lines(seq(0,1,0.1),seq(0,1,0.1))
}
```
# Filtering
## Drop Screen 1
As no good DMSO plate available screen1 is dropped for all subseqeunt analysis
```{r}
CompleteDF <- filter(CompleteDF, ScreenNo!="SS1")
df4anaAvreplicates <- filter(df4anaAvreplicates, ScreenNo!="SS1" )
df4ana <- filter(df4ana, ScreenNo!="SS1")
patcol <- patcol[names(patcol)%in% df4ana$PatientID]
```
## Outliers
Detect outliers: For each drug-drug combination patients with viabilities above 1.4 are removed.
```{r outliers}
max(df4anaAvreplicates$effectBC)
max(df4anaAvreplicates$effectB)
max(df4anaAvreplicates$effectC)
filter_th <- 1.4
ggplot(df4anaAvreplicates, aes(x=effectBC)) +
geom_histogram() +
geom_vline(xintercept =filter_th, col="red", lty="dashed")
ggplot(df4anaAvreplicates, aes(x=effectB)) +
geom_histogram() +
geom_vline(xintercept =filter_th, col="red", lty="dashed")
ggplot(df4anaAvreplicates, aes(x=effectC)) +
geom_histogram() +
geom_vline(xintercept =filter_th, col="red", lty="dashed")
OutlierPoints <- filter(df4anaAvreplicates, effectB >filter_th | effectC >filter_th | effectBC>filter_th)
df4anaAvreplicatesRmOutliers <- filter(df4anaAvreplicates,
effectB <=filter_th & effectC <= filter_th & effectBC <= filter_th)
```
## Are there non-active compounds?
```{r hist_effectC}
dfC <- df4ana %>% select(CDrugAbrv, effectC, PatientID) %>% filter(!duplicated(.))
dfC %>% ggplot(aes(x=effectC)) +geom_histogram() + facet_wrap(~ CDrugAbrv) +
geom_vline(xintercept = 1, col = "red") +xlab("viability of combination compound alone")
df4ana %>% group_by(CDrugAbrv) %>%
summarize(var = var(pmin(1,effectC))) %>% arrange(var)
```
```{r hist_effects_B}
dfB <- df4ana %>% select(BDrugName, BDrugConcId, effectB, PatientID) %>%
filter(!duplicated(.))
dfB %>% ggplot(aes(x=effectB, fill = BDrugConcId)) +
geom_histogram() + facet_wrap(~ BDrugName) +
geom_vline(xintercept = 1, col = "red") +
xlab("viability of base compound alone")
df4ana %>% group_by(BDrugName, BDrugConcId) %>%
summarize(var = var(pmin(1,effectB)), mean = mean(effectB)) %>%
arrange(var) %>% group_by(BDrugName) %>%
summarize(max_var = max(var), min_mean = min(mean)) %>%
arrange(max_var)
```
## Are there compounds that show a different effect in as combination drug than as base durg
```{r comparison_drC_drB}
commonDrugs <- intersect(df4ana$CDrugName, df4ana$BDrugName)
dfcombi <- DrugMetaList$DrugInfoCombi %>%
filter(niceName %in% commonDrugs) %>%
select(name = niceName, conc)
dfbase <- DrugMetaList$DrugInfoBase %>%
filter(niceName %in% commonDrugs) %>%
select(name = niceName, starts_with("c"))
full_join(dfcombi, dfbase, by = "name") %>%
mutate()
matchConcs <- c("c4", "c5")
df4ana %>%
filter( (BDrugName %in% commonDrugs & BDrugName == CDrugAbrv) | CDrugAbrv == "Ibrutinib (100nM)" & BDrugName == "Ibrutinib" , BDrugConcId %in% matchConcs) %>%
mutate(label = paste(CDrugName, CDrugConc*1000, "nM")) %>%
ggplot(aes(x=effectB, y =effectC, col = factor(BDrugConc*1000))) +
geom_point() +facet_wrap(~label) + geom_abline(slope=1, intercept=0) +
guides(col = guide_legend(title = "conc (B, nM)")) + coord_equal() +
geom_hline(yintercept = 1, lty = "dashed", col="gray") +
geom_vline(xintercept = 1, lty = "dashed", col="gray")
```
For Duvelisib none of the two neighboring concentration is similiar -> exclude this from the screen.
YM155 and Venetoclax are similar in the lower concentration. Fludarabe and afatinib have no or a pro-survival effect.
Exclude Duvelisib from futher analysis, as it seems to be inactive as combination compound and not as base compound
```{r}
df4ana %<>% filter(CDrugName != "Duvelisib")
df4anaAvreplicates %<>% filter(CDrugName != "Duvelisib")
df4anaAvreplicatesRmOutliers %<>% filter(CDrugName != "Duvelisib")
CompleteDF %<>% filter(CombiDrug != "Duvelisib")
```
# Data Export
Export Data to be used in further down-stream analyses
- 'DrugMetaList': contains metadata about drug
- 'CompleteDF': contains data from all plates, wells and screens, raw values and values normalized by median of DM control wells
- 'SetUpList': contains info about plate structure for the screens
- 'df4ana': contains values for all drug-drug pairs (effectBS) with matched one-only effect from corresponding +DMSO well (effectB) or median of DM+ wells (effectC)
- 'df4anaAvrepl': df4ana with average values for replicates
- 'df4anaAvreplRemOutl': df4anaAvrepl, filtering out values above 1.4 (filter_th)
- 'patcol': color annotation for each patient
- filter_th: values above which values are filtered out
```{r}
save(DrugMetaList,CompleteDF,df4ana,SetUpList, df4anaAvreplicates, patcol, df4anaAvreplicatesRmOutliers,patcol, filter_th,
file=paste0(outdir,"/CLLCombiDataAfterQC_",today,".RData"))
```
Write the dataframe used for further analysis into a csv file.
```{r}
if(!dir.exists(file.path(outdir, "tables"))) dir.create(file.path(outdir, "tables"))
write.csv(CompleteDF, file= paste0(outdir,"/tables/viability_values_perplate_",today,".csv"))
write.csv(df4anaAvreplicatesRmOutliers, file= paste0(outdir,"/tables/combination_values_",today,".csv"))
```
#SessionInfo
```{r}
sessionInfo()
```