-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlfq.Rmd
289 lines (216 loc) · 6.96 KB
/
lfq.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
---
title: "Label Free Quantification (LFQ)"
author: "Christian Panse / Jonas Grossmann"
date: "2016/01/24"
output:
- slidy_presentation
- rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{LabelFreeQuantification}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
# load reqired R libraries
```{r}
library(ISCB2017)
library(knitr)
library(lattice)
```
# focus on proteins (peptides)
```{r}
unique(XIC$protein)
unique(XIC$peptide
)
```
# Howto extract XIC data?
https://biblio.ugent.be/publication/8502633
```{r fig.retina=3, fig.height=4}
dim(XIC)
table(XIC$filename)
table(XIC$protein)
table(XIC$peptide)
xic.filter <- XIC$filename == '20161115_13_G1_b.raw' & XIC$peptide == 'IFTVPTETLQAVTK'
lattice::xyplot(count ~ rt | as.character(charge) * filename,
data = XIC,
subset = xic.filter, #(XIC$peptide == 'IFTVPTETLQAVTK'),
type = 'h')
lattice::xyplot(count ~ rt | as.character(charge) * filename,
data = XIC,
subset = xic.filter, #(XIC$peptide == 'IFTVPTETLQAVTK'),
xlim=c(62,65),
type = 'h')
```
# plot filtered LC-MS map
```{r fig.retina=3, fig.height=20}
peptide.rt$pim <- sapply(as.character(peptide.rt$peptide), parentIonMass)
lattice::xyplot(pim ~ rt,
group = filename,
data=peptide.rt,
auto.key =TRUE)
```
# XIC
reqirement: query RT for every peptide and every LC-MS run
```{r fig.retina=3, fig.width=16, fig.height=12}
lattice::xyplot(peptide ~ rt | filename,
group=grepl('GE', filename),
data = peptide.rt)
```
# Find for each LC-MS run the RT of the corresponding peptide
```{r}
pmax <- aggregate(score ~ filename + peptide,
FUN=max,
data=peptide.rt)
peptide.rt.max <- merge(peptide.rt, pmax, by=c('peptide', 'filename', 'score'))
```
```{r eval=FALSE}
View(peptide.rt.max)
```
# merge and filter XIC and RT
```{r}
dim(XIC)
dim(peptide.rt.max)
XIC.rt <- merge(XIC, peptide.rt.max, by=c('peptide', 'filename'))
dim(XIC.rt)
eps <- 0.5
filter <- XIC.rt$rt.y - eps < XIC.rt$rt.x & XIC.rt$rt.x < XIC.rt$rt.y + eps
XIC.rt.filtered <- XIC.rt[filter, ]
dim(XIC.rt.filtered)
#library(lattice())
#xyplot(log(count,2) ~ rt|protein ,group=charge, data=XIC.f[grepl("20161115_12_GE1_b.raw", XIC.f$filename),], type='h')
```
# Determine the max peak of each peptide
```{r fig.retina=3}
XIC.max <- aggregate(count ~ protein + peptide + charge + filename,
data=XIC.rt.filtered, FUN=max)
bwplot(count ~ filename | protein * grepl('GE', filename),
data=XIC.max,
scales = list(x = list(rot = 45)))
bwplot(log(count) ~ filename | protein * grepl('GE', filename),
data=XIC.max,
scales = list(x = list(rot = 45)))
bwplot( (log(count)-mean(log(count)))/sd(log(count)) ~ filename | protein * grepl('GE', filename),
data=XIC.max,
scales = list(x = list(rot = 45)))
```
# long to wide
```{r}
head(XIC.max)
M <- reshape2::dcast(XIC.max, formula = protein + peptide + charge ~ filename)
head(M)
rownames(M) <-paste(M[,1], M[,2], M[,3])
M[,1:3] <- NULL
M[is.na(M)] <- 0
```
```{r eval=FALSE}
View(M)
```
```{r}
S.sum <- aggregate(count ~ protein + grepl('GE', filename) + filename, data=XIC.max, FUN=sum)
S.max <- aggregate(count ~ protein + grepl('GE', filename) + filename, data=XIC.max, FUN=max)
S.mean <- aggregate(count ~ protein + grepl('GE', filename) + filename, data=XIC.max, FUN=mean)
bwplot(log(S.sum$count) ~ S.sum$protein| grepl('GE', S.sum$filename),layout=c(2,1))
bwplot(log(S.mean$count) ~ S.mean$protein| grepl('GE', S.mean$filename),layout=c(2,1))
bwplot(log(S.max$count) ~ S.max$protein| grepl('GE', S.max$filename),layout=c(2,1))
```
```{r fig.retina=3}
image(t(as.matrix(asinh(M))))
```
```{r fig.retina=3, fig.height=8}
library(gplots)
gplots::heatmap.2(asinh(as.matrix((M))), margins = c(20,15), trace = "none")
```
# RT normalization
http://bioconductor.org/packages/release/data/experiment/vignettes/msqc1/inst/doc/chromatography.html
# Two Group
lets switch to mq data ...
```{r fig.retina=3}
gg <- c(rep('G', 6), rep('GE', 6))
dim(prxmq)
table(gg)
op <- par(mfrow=c(1,3))
# example 0
idx <- 2
x <- log(unlist(prxmq[idx, ]),2)
boxplot(x ~ gg, main=row.names(prxmq)[idx])
t.test(x ~ gg, alternative = "two.sided")
# example 1
idx <- which(row.names(prxmq) == "sp|P00331|ADH2_YEAST")
x <- log(unlist(prxmq[idx, ]),2)
boxplot(x ~ gg, main=row.names(prxmq)[idx])
t.test(x ~ gg, alternative = "two.sided")
#example 2
idx <- which(row.names(prxmq) == "sp|P33302|PDR5_YEAST")
x <- log(unlist(prxmq[idx, ]),2)
boxplot(x ~ gg, main=row.names(prxmq)[idx])
t.test(x ~ gg, alternative = "two.sided")
```
```{r}
expression_analysis <- function(S, groups){
S.t.test <- lapply(1:nrow(S), function(idx){
x <- unlist(S[idx, ])
x[x==0] <- NA
if (min(aggregate(x, by=list(groups), function(x){sum(!is.na(x))})$x) > 5){
t <- t.test(log(x, 2) ~ groups, alternative = "two.sided")
r <- cbind(FC = diff(t$estimate), p.value = t$p.value, idx=idx)
row.names(r) <- row.names(S)[idx]
r
}else{NULL}
})
S.t.test <- as.data.frame(do.call('rbind', S.t.test))
S.t.test
}
SwissProtID <- sapply(strsplit (as.character(unique(XIC$protein)), split='_'), function(x){x[1]})
sp_filter <- grepl(paste(SwissProtID, collapse ='|'), rownames(prxmq))
S.t.test <- expression_analysis(prxmq[sp_filter,], gg)
S.t.test
```
# volcano plot - p.value vs FC
```{r fig.retina=3}
plot_volcano <- function(S.t.test, label=FALSE, ...){
plot(-log(p.value,10) ~ FC, data=S.t.test,
main="volcano plot",
sub="p1946 prx", ...)
abline(v=c(-0.5,0.5), col='grey')
abline(h=-log(0.025, 10), col='grey')
points(-log(p.value,10) ~ FC,
data=S.t.test[abs(S.t.test$FC)>0.5 & S.t.test$p.value<0.025,],
col='red',cex=0.5)
points(-log(p.value,10) ~ FC,
data=S.t.test[grepl('ZZ', rownames(S.t.test)),],
col='cyan')
points(-log(p.value,10) ~ FC,
data=S.t.test[grepl('REV', rownames(S.t.test)),],
cex=2, lwd=2,
col='green')
if(label){
text(S.t.test$FC, -log(S.t.test$p.value,10), rownames(S.t.test), cex=0.5, pos=3)
}
}
plot_volcano(S.t.test, xlim=c(-10,10))
```
# take all proteins
```{r}
S.t.test <- expression_analysis(prxmq, gg)
plot_volcano(S.t.test, xlim=c(-10,10), label = FALSE)
```
# What happen if you mess up your annotation?
```{r}
random_swap <- function(x){
a <- sample(length(x),2)
tmp <- x[a[1]]
x[a[1]] <- x[a[2]]
x[a[2]] <- tmp
return(x)
}
```
```{r fig.retina=5}
op<-par(mfrow=c(2,2))
plot_volcano(S.t.test)
(gg <- random_swap(gg)); S.t.test <- expression_analysis(prxmq, gg); plot_volcano(S.t.test)
(gg <- random_swap(gg)); S.t.test <- expression_analysis(prxmq, gg); plot_volcano(S.t.test)
(gg <- random_swap(gg)); S.t.test <- expression_analysis(prxmq, gg); plot_volcano(S.t.test)
```
* a viewpoint on volcano plot:
Uses and misuses of the fudge factor in
quantitative discovery proteomics, Proteomics 2016, 16, 1955–1960
http://onlinelibrary.wiley.com/doi/10.1002/pmic.201600132/epdf