-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDEP.Rmd
executable file
·166 lines (120 loc) · 6.08 KB
/
DEP.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
---
title: "Vaccine clinical samples proteomics"
output: html_notebook
---
### Proteomics using MS-DAP
The samples were all prepared and analysed within the same batch and then analysed with DIA-NN.
```{r}
# if (!requireNamespace("BiocManager", quietly=TRUE))
# install.packages("BiocManager")
# BiocManager::install("DEP")
library(DEP)
library(dplyr)
library(openxlsx)
library(readxl)
```
```{r}
data <- read.delim("../report.pg_matrix.tsv", header = T)
data_measurements <- log2(data[,c(6:236)])
short_names <- sapply(colnames(data_measurements), function(x) strsplit(x, split = "Data.50.0075.")[[1]][2])
short_names <- sapply(short_names, function(x) strsplit(x, split = ".rawIdx.wiff.dia")[[1]][1])
short_names <- sapply(short_names, function(x) strsplit(x, split = "_50.0075_")[[1]][2])
colnames(data_measurements) <- short_names
meta <- read_excel("../20210909_50-0075_InnateVaccineResponse.xlsx") %>%
na.omit() %>%
mutate(condition = paste(vacc_group, visit, sep = "_")) %>%
rename(label = sample_id) %>%
group_by(condition) %>%
mutate(replicate = row_number())
meta$label <- sapply(meta$label, function(x) strsplit(x, split = "_50-0075_")[[1]][2])
data_measurements <- data_measurements[meta$label]
# exp design
# IVR_meta <- openxlsx::read.xlsx("../sample_metadata.xlsx")
SE_meta <- meta
SE_data <- make_unique(cbind(data[,1:5], data_measurements), "Genes", "Protein.Ids", delim = ";")
SE_data_columns <- 6:131
data_se <- make_se(SE_data, SE_data_columns, SE_meta)
```
```{r}
# Plot a barplot of the protein identification overlap between samples
plot_frequency(data_se)
# Filter for proteins that are identified in all replicates of at least one condition
data_filt <- filter_missval(data_se, thr = 0)
# Less stringent filtering:
# Filter for proteins that are identified in 2 out of 3 replicates of at least one condition
data_filt2 <- filter_missval(data_se, thr = 1)
# Plot a barplot of the number of identified proteins per samples
plot_numbers(data_filt)
# Plot a barplot of the protein identification overlap between samples
plot_coverage(data_filt)
```
```{r}
# Normalize the data
data_norm <- normalize_vsn(data_filt)
# Visualize normalization by boxplots for all samples before and after normalization
plot_normalization(data_filt, data_norm)
# Plot a heatmap of proteins with missing values
plot_missval(data_filt)
# Plot intensity distributions and cumulative fraction of proteins with and without missing values
plot_detect(data_filt)
## Error in match.arg(fun): 'arg' should be one of "bpca", "knn", "QRILC", "MLE", "MinDet", "MinProb", "man", "min", "zero", "mixed", "nbavg"
# Impute missing data using random draws from a Gaussian distribution centered around a minimal value (for MNAR)
data_imp <- impute(data_norm, fun = "MinProb", q = 0.01)
# Impute missing data using random draws from a manually defined left-shifted Gaussian distribution (for MNAR)
data_imp_man <- impute(data_norm, fun = "man", shift = 1.8, scale = 0.3)
# Impute missing data using the k-nearest neighbour approach (for MAR)
data_imp_knn <- impute(data_norm, fun = "knn", rowmax = 0.9)
#The effect of the imputation on the distributions can be visualized.
# Plot intensity distributions before and after imputation
plot_imputation(data_norm, data_imp)
plot_imputation(data_norm, data_imp_man) #best for our data
plot_imputation(data_norm, data_imp_knn)
```
```{r}
# Differential enrichment analysis based on linear models and empherical Bayes statistics
# Test all possible comparisons of samples
#data_diff_all_contrasts <- test_diff(data_imp, type = "all")
## Tested contrasts: Ubi4_vs_Ubi6, Ubi4_vs_Ctrl, Ubi4_vs_Ubi1, Ubi6_vs_Ctrl, Ubi6_vs_Ubi1, Ctrl_vs_Ubi1
# Test manually defined comparisons
data_diff_manual <- test_diff(data_imp_man, type = "manual",
test = c("AZD_BNT_visit_0_vs_AZD_BNT_visit_4", "AZD_BNT_visit_0_vs_AZD_BNT_visit_8",
"BNT_BNT_visit_0_vs_BNT_BNT_visit_4", "BNT_BNT_visit_0_vs_BNT_BNT_visit_8",
"AZD_BNT_visit_0_vs_AZD_BNT_visit_1", "BNT_BNT_visit_0_vs_BNT_BNT_visit_1",
"AZD_BNT_visit_5_vs_AZD_BNT_visit_6", "BNT_BNT_visit_5_vs_BNT_BNT_visit_6"))
## Tested contrasts: Ubi4_vs_Ctrl, Ubi6_vs_Ctrl
#Finally, significant proteins are defined by user-defined cutoffs using add_rejections.
# Denote significant proteins based on user defined cutoffs
dep <- add_rejections(data_diff_manual, alpha = 0.05, lfc = log2(1))
```
```{r}
# Plot the first and second principal components
plot_pca(dep, x = 1, y = 2, n = 20, point_size = 4, indicate = c("visit"))
# Plot the Pearson correlation matrix
plot_cor(dep, significant = TRUE, lower = 0, upper = 1, pal = "Reds", indicate = c("vacc_group","visit"), font_size = 7)
# Plot a heatmap of all significant proteins with the data centered per protein
plot_heatmap(dep, type = "centered", kmeans = TRUE,
k = 6, col_limit = 4, show_row_names = FALSE,
indicate = c("vacc_group", "visit"))
# Plot a heatmap of all significant proteins (rows) and the tested contrasts (columns)
plot_heatmap(dep, type = "contrast", kmeans = TRUE,
k = 6, col_limit = 10, show_row_names = FALSE)
# Plot a volcano plot for the contrast "Ubi6 vs Ctrl""
plot_volcano(dep, contrast = "AZD_BNT_visit_0_vs_AZD_BNT_visit_1", label_size = 2, add_names = TRUE)
plot_volcano(dep, contrast = "BNT_BNT_visit_0_vs_BNT_BNT_visit_1", label_size = 2, add_names = TRUE)
plot_volcano(dep, contrast = "AZD_BNT_visit_5_vs_AZD_BNT_visit_6", label_size = 2, add_names = TRUE)
plot_volcano(dep, contrast = "BNT_BNT_visit_5_vs_BNT_BNT_visit_6", label_size = 2, add_names = TRUE)
```
```{r}
# Generate a results table
data_results <- get_results(dep)
# Number of significant proteins
data_results %>% filter(significant) %>% nrow()
# Generate a wide data.frame
df_wide <- get_df_wide(dep)
# Generate a long data.frame
df_long <- get_df_long(dep)
# Save analyzed data
save(data_se, data_norm, data_imp_man, data_diff_manual, dep, file = "IVRproteomics_DEP.RData")
# These data can be loaded in future R sessions using this command
#load("data.RData")
```