-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPCA_analysis_complete_paralog.R
443 lines (342 loc) · 14.4 KB
/
PCA_analysis_complete_paralog.R
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
######################################
## Full-lenght paralog PCA analysis ##
## author : Pascale Lemieux ##
## Date : 2023-01-10 ##
######################################
library(tidyverse)
library(magrittr)
library(gtools)
library(mixtools)
firstup <- function(x) {
substring(x, 2) <- tolower(substring(x, 2))
x
}
##############################################
## Import raw data generated by pyphe-quant ##
##############################################
## Recheck with rawdata from pyphe
# For prey array plates, final diploid selection plates and final MTX plates #
# Read array plan in 1536 format
plate1536 <-
read.csv('~/ancSH3_paper/SupplementaryMaterial/Data/plate1536_complete_paralog.csv')
# Set working directory with raw data from pyphe (for diploid S2 and MTX2)
setwd("~/ancSH3_paper/SupplementaryMaterial/Data/complete_paralog_RD/S2_diploid/")
file = dir(pattern = ".csv")
# Assign names to each data frame object
j = 1
for (i in file) {
assign(x = paste0('plate', j), read.csv(i))
j = j + 1
}
# merge each data frame with array plan
n = 48 #number of data frame
for (i in 1:n) {
p <- get(paste0('plate', i))
assign('p',
merge(
p,
plate1536,
by.x = c('row', 'column'),
by.y = c('row', 'col'),
all = T
))
p$plate <- i
assign(paste0('plate', i), p)
}
# assemble all data frame
all_plate <-
do.call(rbind.data.frame, mget(ls(pattern = "^plate.{1,2}$")))
# write file with data of each selection step
# MTX2_data.csv , diploid2_data.csv or DHFR3_data.csv
filename = '~/ancSH3_paper/SupplementaryMaterial/Data/complete_paralog_data/diploid2_data.csv'
write.csv(all_plate,
file = filename,
row.names = T,
quote = T)
######################################
## Data verification and filtering ##
######################################
# Removal of non-growing position in the prey array and
# diploid selection for the MTX data #
# Set working directory where all the output files will be generated
setwd('~/ancSH3_paper/SupplementaryMaterial/Data/complete_paralog_data/')
# Read assembled data
MTX2_data <-
read.csv(file = './MTX2_data.csv')
diploid2_data <-
read.csv(file = './diploid2_data.csv')
DHFR3_data <-
read.csv(file = './DHFR3_data.csv')
# Verification that all absent positions in plate DHFR3 96/384
# are also absent 1536 DHFR3 plate
ngrowth <- DHFR3_data[is.na(DHFR3_data$area),c('row', 'column', 'orf')]
# Histogram of colony area distribution of prey array
ggplot(data = DHFR3_data)+
geom_histogram(mapping = aes(x = area),
binwidth = 20)+
theme_minimal()
table(ngrowth$orf)
# YDR480W YLR078C YPL049C
# 5 5 4
# Verification of no growth positions in diploid2 selection plates
# Histogram of colony area distribution of diploid selection
ggplot(data = diploid2_data)+
geom_histogram(mapping = aes(x = area),
binwidth = 20)+
xlim(0, 8000)+
geom_vline(xintercept = 500)+
theme_minimal()
# Determination of positions to withdraw for each plate. Each orf has to be
# present in two replicates on each plates to be conserved in the analysis
# Important to verify that the absence of growth is consistent with the prey
# tested and not technical errors. Remove all non-growing positions and remove
# all prey wich has less than 2 replicates per plate
diploid2.data.na <- diploid2_data
diploid2.data.na[, 'area'] <- na.replace(diploid2.data.na[ , 'area'], 0)
diploid2.data.na$growth <- diploid2.data.na$area > 500
# Frequence of total non-growing diploid for each orf per plate
pos <- table(diploid2.data.na[!diploid2.data.na$growth, c('orf', 'plate')])
pos <- as.data.frame(pos)
# Frequence of total expected diploid for each orf per plate
orf<- diploid2.data.na[!diploid2.data.na$growth, 'orf']
orf.to.with <-
table(diploid2.data.na[diploid2.data.na$orf %in% orf , c('orf', 'plate')])
orf.to.with <- as.data.frame(orf.to.with)
# Determine which orf has less than 2 replicate by plate
orf.to.with$ngrowth <- pos$Freq
orf.to.with$with <- orf.to.with$Freq - orf.to.with$ngrowth < 2
pos.to.with <-
diploid2.data.na[diploid2.data.na$area < 500, c('row', 'column', 'plate')]
pos.to.with$with <- TRUE
# Withdrawal of the nongrowing orf in each diploid2 plate
diploid2_data.tresh <-
merge(x = diploid2_data,
y = orf.to.with,
by = c('orf', 'plate'),
all = TRUE)
diploid2_data.tresh <-
merge(x = diploid2_data.tresh,
y = pos.to.with,
by = c('row', 'column', 'plate'),
all = TRUE)
diploid2.data.clean <-
subset(diploid2_data.tresh,
subset = (diploid2_data.tresh$with.x | diploid2_data.tresh$with.y) %in% c(FALSE, NA),
select = colnames(diploid2_data))
nrow(diploid2_data.tresh) - nrow(diploid2.data.clean)
#2426
# Comparison
ggplot(data = diploid2.data.clean)+
geom_histogram(mapping = aes(x = area),
binwidth = 20, alpha = 0.7, fill = 'red')+
geom_histogram(data = diploid2_data, mapping = aes(x = area),
binwidth = 20, alpha = 0.7)+
xlim(0,8000)+
theme_minimal()
# Withdrawal of nongrowing orf on diploid2 plates in each MTX2 plate
MTX2.data.tresh <- merge(x = MTX2_data,
y = orf.to.with,
by = c('orf', 'plate'),
all = TRUE)
MTX2.data.tresh <- merge(x = MTX2.data.tresh,
y = pos.to.with,
by = c('row', 'column', 'plate'),
all = TRUE)
MTX2.data.clean <-
subset(MTX2.data.tresh,
subset = (MTX2.data.tresh$with.x | MTX2.data.tresh$with.y) %in% c(FALSE, NA),
select = colnames(diploid2_data))
MTX2.data.clean$area <-
na.replace(MTX2.data.clean$area, 0)
# Histrogram of the distribution of MTX colony area
ggplot(data = MTX2.data.clean)+
geom_histogram(mapping = aes(x = area),
binwidth = 20)+
theme_minimal()
### Export clean MTX2 data
write.csv(x = MTX2.data.clean,
file = '~/ancSH3_paper/SupplementaryMaterial/Data/complete_paralog_data/MTX2_data_clean.csv',
quote = TRUE,
fileEncoding = 'UTF-8')
#############################
## MTX data transformation ##
#############################
library(viridis)
MTX2.data <-
read.csv(file = '~/ancSH3_paper/SupplementaryMaterial/Data/complete_paralog_data/MTX2_data_clean.csv',
fileEncoding = 'UTF-8', )
# Columns removal and transformation
MTX2.data$X <- NULL
MTX2.data$X.1 <- NULL
MTX2.data$X.2 <- NULL
MTX2.data$plate <- as.factor(MTX2.data$plate)
# Removal of unwanted plates (growth problem or other strains)
MTX2.data <- subset(MTX2.data,
subset = !(MTX2.data$plate %in% c(2, 10, 26, 34)))
# Adjust area = 0 to area = 1 for logarithm transformation
MTX2.data %<>% mutate(adjust = area + 1)
# Transform colony adjusted area in log2 scale
MTX2.data$log2.area <- log2(MTX2.data$adjust)
#Distribution of log2(colony area) per plate (Supplementary Figure 2A)
sf2a <-
ggplot(data = MTX2.data) +
geom_density(mapping = aes(x = log2.area, color = plate))+
theme_minimal()+
theme(legend.position = 'none')+
theme_minimal()+
geom_vline(xintercept = 3, color = 'grey20', linewidth = 1)+
geom_vline(xintercept = 13.13, color = 'grey20', linewidth = 1)+
geom_vline(xintercept = 8.60733, color = 'orangered', linewidth = 1)+
theme(legend.position = 'none')+
xlim(0, 14)+
theme_bw()+
xlab(expression(paste(log[2], '(colony area)')))+
ylab('Density')+
scale_color_viridis(option = 'G', discrete = T)+
theme(legend.position = 'none',
legend.text = element_text(size = 14),
legend.title = element_text(size = 16),
axis.title = element_text(size =14),
axis.text = element_text(size =12),
strip.text.x = element_text(size = 16),
panel.grid.major = element_blank(), panel.grid.minor = element_blank())
saveRDS(sf2a, file = '~/ancSH3_paper/SupplementaryMaterial/FigurePanels/SuppFig2A.rds')
# Remove the empty positions
MTX2.data <- subset(MTX2.data,
MTX2.data$log2.area >= 3)
# Remove aberrant data
MTX2.data <- subset(MTX2.data,
MTX2.data$area < 9000)
# Import bait description
bait <- read.csv2('~/ancSH3_paper/SupplementaryMaterial/Data/complete_paralog_data/bait_description.csv')
colnames(bait) <- c('plate', 'sh3_sequence', 'Bait.Standard_name', 'tech_rep')
MTX2.data <-
merge(bait,
MTX2.data,
by ='plate')
MTX2.data$strain <- str_c(MTX2.data$sh3_sequence, MTX2.data$Bait.Standard_name, sep = '.')
saveRDS(MTX2.data, file = '~/ancSH3_paper/SupplementaryMaterial/Data/complete_paralog_data/MTX2_trans.rds')
###############################
## Normalization : PCA score ##
###############################
library(ggpubr)
# Important to compare the plates with each other
MTX2.list <- readRDS('~/ancSH3_paper/SupplementaryMaterial/Data/complete_paralog_data/MTX2_trans.rds')
# Withdrawal of the border
#MTX2.list %<>% filter(orf != 'border')
# Verification if there is bias between the baits
exbiais <-
MTX2.list[, c(2,3,7,13,15)]
# Withdrawal of the border for biais check
exbiais %<>% filter(orf != 'border')
exbiais <-
exbiais[exbiais$sh3_sequence %in% c('MYO3_WT', 'MYO5_WT'), ]
exbiais$Bait.Standard_name <-
firstup(gsub(exbiais$Bait.Standard_name, pattern = 'p', replacement= ''))
exbiais$sh3_sequence <- firstup(gsub(exbiais$sh3_sequence, pattern = '_WT', replacement = ''))
compare_means(area~Bait.Standard_name, exbiais)
# bias confirmed
sf2b <-
ggplot(exbiais)+
geom_violin(aes(y = log2.area, x = Bait.Standard_name,
fill = Bait.Standard_name),
fill = 'grey60',alpha = 0.4, color = 'grey20')+
stat_compare_means(aes(x = Bait.Standard_name, y = log2.area),
method = 'wilcox.test', size = 4.5, label.x = 1)+
ylim(0,15)+
ylab(expression(paste(log[2], '(colony area)')))+
xlab('WT bait')+
theme_bw()+
theme(
#legend.position = 'none',
legend.title = element_blank(),
legend.text = element_text(size = 14),
#legend.title = element_text(size = 16),
axis.title = element_text(size =14),
axis.text = element_text(size =12),
strip.text.x = element_text(size = 16),
panel.grid.major = element_blank(), panel.grid.minor = element_blank())
saveRDS(sf2b, file = '~/ancSH3_paper/SupplementaryMaterial/FigurePanels/SuppFig2B.rds')
# Calculation of min/max for each plate
MTX2.list %<>%
group_by(plate) %>%
mutate(max = max(log2.area, na.rm = TRUE))%>%
ungroup()
MTX2.list %<>%
group_by(plate) %>%
mutate(min = min(log2.area, na.rm = TRUE))%>%
ungroup()
x <- MTX2.list[MTX2.list$max == MTX2.list$log2.area, ]
# Calculation of standardized data using the min/max calculated
MTX2.list %<>%
mutate(norm = ((log2.area - min)/(max-min)))
# Withdrawal of the border
MTX2.list %<>% filter(orf != 'border')
# Verification of the correlation between technical replicates
dfrep1 = MTX2.list %>% filter(tech_rep == 1)
dfrep2 = MTX2.list %>% filter(tech_rep == 2)
dfrep1 %<>% mutate(baitXprey_1 = interaction(strain, orf)) %>% select(baitXprey_1, norm, log2.area)
dfrep2 %<>% mutate(baitXprey_2 = interaction(strain, orf)) %>% select(baitXprey_2, norm, log2.area)
crep <- merge(dfrep1,
dfrep2,
by.x="baitXprey_1",
by.y="baitXprey_2")
# Supplementary Figure 2C
sf2c <-
ggplot(data = crep, aes(x = norm.x, y = norm.y)) +
geom_point(aes(x = norm.x, y = norm.y), alpha = 0.2)+
xlab('PCA score replicate 1')+
ylab('PCA score replicate 2')+
lims(y = c(0,1), x = c(0,1))+
stat_cor(size = 4.5, cor.coef.name = c('r'), label.y = 1)+
theme_bw()+
theme(legend.position = 'none', legend.title = element_blank(),
legend.text = element_text(size = 14),
axis.title = element_text(size =14),
axis.text = element_text(size =12),
strip.text.x = element_text(size = 16),
panel.grid.major = element_blank(), panel.grid.minor = element_blank())
saveRDS(sf2c, file = '~/ancSH3_paper/SupplementaryMaterial/FigurePanels/SuppFig2C.rds')
# Export normalized data
saveRDS(MTX2.list, file = '~/ancSH3_paper/SupplementaryMaterial/Data/complete_paralog_data/MTX2_norm.rds')
###########################
## PPI score computation ##
###########################
MTX2.list <- readRDS(file = '~/ancSH3_paper/SupplementaryMaterial/Data/complete_paralog_data/MTX2_norm.rds')
MTX2.list.rep <- vector(mode = 'list', length = 1)
# Compute the median of biological replicates (unique prey-bait combination) (PPI_score)
MTX2.list.rep <-
MTX2.list%>%
group_by(sh3_sequence, Bait.Standard_name, orf) %>%
dplyr::summarise(n(), medsize = median(adjust ,na.rm = TRUE ),
medrep = median(norm, na.rm = TRUE ))
# Transform columns
MTX2.list.rep %<>% mutate(strain= str_c(sh3_sequence, Bait.Standard_name, sep = '.'))
MTX2.list.rep %<>% mutate(log2medsize = log2(medsize))
# Create object with PCA and PPI scores
MTX2.list.rep <-
merge(MTX2.list ,
MTX2.list.rep[, c('orf', 'strain', 'medsize','log2medsize','medrep','n()')],
by = c('orf', 'strain'))
# Establishing the threshold for median colony area size
# Bellow the threshold is noise
x = 390 #colony size threshold
ggplot(data = MTX2.list.rep ) +
geom_density(aes(x = medsize, colour = strain)) +
theme_minimal()+
geom_vline(xintercept = x)+
theme(legend.position = 'none')
# Threshold the data & remove preys with less than 20 data points
for(j in unique(MTX2.list.rep$orf)){
test <-
subset(MTX2.list.rep,
subset = orf == j)
if(all(test$medsize < x)){
MTX2.list.rep %<>% subset(subset = orf != j)
} else if(nrow(test) < 20){
MTX2.list.rep %<>% subset(subset = orf != j)
}
}
# Export the data (used for PCA_SH3_dependency_test.R)
saveRDS(MTX2.list.rep ,
file = '~/ancSH3_paper/SupplementaryMaterial/Data/complete_paralog_data/MTX2data_complete_paralog.rds')