-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path004-mutation_effects.Rmd
More file actions
222 lines (144 loc) · 5.96 KB
/
Copy path004-mutation_effects.Rmd
File metadata and controls
222 lines (144 loc) · 5.96 KB
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
---
title: "004 - compute dLFC"
author: "Guillaume Diss"
date: '2023-02-03'
output:
html_document:
code_folding: show
pdf_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, cache = TRUE)
```
# Introduction
Here, we will compute dLFC directly using limma because we can't compute them posthoc.
# Load packages
```{r a}
suppressPackageStartupMessages({
library(parallel)
library(mutscan)
library(rgl)
library(stringdist)
library(ggplot2)
library(data.table)
library(Biostrings)
library(readxl)
library(stringr)
})
```
# Data description
# Load data
```{r c}
# batch composition
batches = read.delim("000-data/TableS10_batches.txt")
# load counts already aggregated per AA
load("003-summarizedExperiment_AA.Rdata")
# table of barcode variant association
load("001-barcode_variants_association_table.Rdata")
# filter out barcodes that can't be used (not correct length, promiscuous or close neighbour)
uniq_pairs = uniq_pairs[uniq_pairs$length_bc == 22 & uniq_pairs$dist_closest_neighbour > 1 & uniq_pairs$Abc == 1,]
# the id for WT has not been set correctly in the barcode-variant association script. Fix it
uniq_pairs$id_bait[uniq_pairs$Nmut_bait == 0] = "0xx"
uniq_pairs$id_prey[uniq_pairs$Nmut_prey == 0] = "0xx"
uniq_pairs$std_id_bait[uniq_pairs$Nmut_bait == 0] = "x0x"
uniq_pairs$std_id_prey[uniq_pairs$Nmut_prey == 0] = "x0x"
uniq_pairs$finalBaitNt = as.character(reverseComplement(DNAStringSet(uniq_pairs$bait)))
# add one or two bp from the restriction site if the nt seq length is not a mutliple of 3
n = nchar(uniq_pairs$finalBaitNt) %% 3
tmp = do.call("rbind",strsplit(uniq_pairs$va[n==2],uniq_pairs$bait[n==2]))[,1]
r = as.character(reverseComplement(DNAStringSet(str_sub(tmp,-1,-1))))
uniq_pairs$finalBaitNt[n==2] = paste0(uniq_pairs$finalBaitNt[n==2],r)
tmp = do.call("rbind",strsplit(uniq_pairs$va[n==1],uniq_pairs$bait[n==1]))[,1]
r = as.character(reverseComplement(DNAStringSet(str_sub(tmp,-2,-1))))
uniq_pairs$finalBaitNt[n==1] = paste0(uniq_pairs$finalBaitNt[n==1],r)
uniq_pairs$finalBaitAA = as.character(translate(DNAStringSet(uniq_pairs$finalBaitNt),no.init.codon=T))
# I checked, all those flagged as ending with stop indeed end with a stop here as well
uniq_pairs[,bait_aa:=NULL]
uniq_pairs = uniq_pairs[
uniq_pairs$cst3 != "dubious" &
!is.na(uniq_pairs$id_bait) &
uniq_pairs$bait_ends_stop &
!uniq_pairs$baitFlag
,]
ub = uniq_pairs[!duplicated(uniq_pairs$finalBaitAA),]
seq2wtbait = ub$wt_bait
names(seq2wtbait) = ub$finalBaitAA
# wt AA sequence
wt_seq = read.delim("000-data/TableS6_wt_bZIPs_aa_seq.txt")
tmp = wt_seq$Gene
wt_seq = wt_seq$bZIP_aa
names(wt_seq) = tmp
# wt nt sequence for preys
wt_nt_seq = read.csv("000-data/TableS9_wt_preys_gblocks_and_barcodes.txt")
wt_nt_seq$seq = substr(wt_nt_seq$seq,983,1500)
str_sub(wt_nt_seq$seq,-6,-1) = ""
wt_bar = wt_nt_seq$barcode
names(wt_bar) = wt_nt_seq$bZIP
tmp = wt_nt_seq$bZIP
wt_nt_seq = wt_nt_seq$seq
names(wt_nt_seq) = tmp
```
# Compute mutation effects as dLFC
```{r d}
dlfc = lapply(1:length(se_coll_aa), function(i){
cat("\r",i)
x = se_coll_aa[[i]]
counts = SummarizedExperiment::assay(x, "counts")
ids = do.call("rbind",strsplit(rownames(counts),"_"))
ids = cbind(ids, seq2wtbait[ids[,2]])
#keep only bait bZIP present in batch
k = ids[,3] %in% batches$gene[batches$batch == i]
counts = counts[k,]
ids = ids[k,]
wt_pairs = ids[ids[,2] %in% paste0(wt_seq,"*"),]
# need to remove pairs where wt have reads with 0 in any replicate. These would anyway be filtered out
wt_counts = counts[ids[,2] %in% paste0(wt_seq,"*"),]
w = which(rowSums(as.matrix(wt_counts) == 0) == 0)
wt_pairs = wt_pairs[w,]
colData = SummarizedExperiment::colData(x)
do.call("rbind",mclapply(1:nrow(wt_pairs),function(j){
counts_sub = counts[ids[,1] == wt_pairs[j,1] & ids[,3] == wt_pairs[j,3],]
wt_row = rownames(counts)[ids[,1] == wt_pairs[j,1] & ids[,3] == wt_pairs[j,3] & ids[,2] %in% paste0(wt_seq,"*")]
s = SummarizedExperiment::SummarizedExperiment(
assays = list(counts = counts_sub),
colData = colData,
metadata = S4Vectors::metadata(x)
)
xx = calculateRelativeFC(
se = s,
design = model.matrix(~ replicate + condition,
data = colData),
WTrows = wt_row,
coef = "conditionoutput", pseudocount = 1, method = "limma"
)
cbind(as.matrix(counts_sub), xx)
},mc.cores=48))
})
```
We need to format the data
```{r e}
# we first order because in case of synonymous mutation that were not expected, some features might not have been determined. So it is better that the expected one comes before its unexpected synonymous variant, so that we get the features
uniq_pairs = uniq_pairs[order(uniq_pairs$expected_bait, decreasing = T),]
uniq_pairs$full_id_bait = paste(uniq_pairs$wt_bait, uniq_pairs$std_id_bait, sep="_")
variant_features_baits = uniq_pairs[!duplicated(uniq_pairs$finalBaitAA),c(55,29,46,45,47:49,44,43,54,6)]
# merge read counts and LFcs
dlfc2 = mclapply(1:4,function(i){
x = dlfc[[i]]
ids = do.call("rbind",strsplit(rownames(x),"_"))
tmp = match(ids[,2], variant_features_baits$finalBaitAA)
x = data.frame(full_id_bait = variant_features_baits$full_id_bait[tmp], x)
names(x)[2:7] = c("i1","o1","i2","o2","i3","o3")
x = cbind(x,variant_features_baits[tmp,2:ncol(variant_features_baits)])
x$full_id_prey = paste0(ids[,1],"_x0x")
x$finalPreyAA = wt_seq[ids[,1]]
x = x[,c(1,29,2:27,30,28)]
},mc.cores=4)
# we keep only JUN from batch 2
dlfc2[[1]] = dlfc2[[1]][dlfc2[[1]]$wt_bait != "JUN",]
dlfc2[[3]] = dlfc2[[3]][dlfc2[[3]]$wt_bait != "JUN",]
dlfc2[[4]] = dlfc2[[4]][dlfc2[[4]]$wt_bait != "JUN",]
dlfc = do.call("rbind",dlfc2)
dlfc$adj.P.Val = p.adjust(dlfc$P.Value, method="fdr")
save(dlfc,file="004-mutation_effects.Rdata")
```
We don't need to normalize batches as we did for absolute LFCs because the normalization to WT already accounts for batch effects in principle