-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprep.R
174 lines (147 loc) · 9.98 KB
/
prep.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
## Prepare environment
if (!require("shiny")){
install.packages("shiny")
}
if (!require("devtools")){
install.packages("devtools")
}
if (!require("ggplot2")){
install.packages("ggplot2")
}
if (!require("ggrepel")){
install.packages("ggrepel")
}
if (!require("data.table")){
install.packages("data.table")
}
if (!require("DT")){
install.packages("DT")
}
if (!require("plyr")){
install.packages("DT")
}
if (!requireNamespace("BiocManager", quietly = TRUE)){
install.packages("BiocManager")
}
if (!require("GenomeInfoDbData")){
BiocManager::install("GenomeInfoDbData")
}
# Get CCprofiler package differential branch
if (!require("CCprofiler")){
devtools::install_github("CCprofiler/CCprofiler", ref = "differential")
}
# load packages
library(shiny)
library(CCprofiler)
library(ggplot2)
library(plotly)
library(data.table)
library(DT)
library(ggrepel)
### Prepare/read data
# generic
pepTraces <- readRDS("data/pepTracesList_filtered.rds")
protTraces <- readRDS("data/protein_traces_list.rds")
designMatrix <- readRDS("data/design_matrix.rds")
calibration <- readRDS("data/calibration.rds")
# protein-centric
proteinFeatures <- readRDS("data/proteinFeaturesFiltered.rda")
diffProteins_stimulated_undifferentiated <- readRDS("data/protein_DiffExprProtein_stimulated_undifferentiated.rda")
diffProteins_stimulated_differentiated <- readRDS("data/protein_DiffExprProtein_stimulated_differentiated.rda")
diffProteins_differentiated_undifferentiated <- readRDS("data/protein_DiffExprProtein_differentiated_undifferentiated.rda")
diffAssemblyState_stimulated_undifferentiated <- fread("data/diffAssemblyState_stimulated_undifferentiated.txt")
diffAssemblyState_stimulated_differentiated <- fread("data/diffAssemblyState_stimulated_differentiated.txt")
diffAssemblyState_differentiated_undifferentiated <- fread("data/diffAssemblyState_differentiated_undifferentiated.txt")
# complex-centric
complexFeatures <- readRDS("data/complexFeaturesCollapsed.rda")
diffComplexes_stimulated_undifferentiated <- readRDS("data/complex_DiffExprComplex_stimulated_undifferentiated.rda")
diffComplexes_stimulated_differentiated <- readRDS("data/complex_DiffExprComplex_stimulated_differentiated.rda")
diffComplexes_differentiated_undifferentiated <- readRDS("data/complex_DiffExprComplex_differentiated_undifferentiated.rda")
# Explore & process into useable overview tables
proteins = unique(rbind(protTraces$undifferentiated_1$trace_annotation[, .(protein_id, Entry_name, Gene_names, Entry_name, Length, Mass, protein_mw)],
protTraces$undifferentiated_2$trace_annotation[, .(protein_id, Entry_name, Gene_names, Entry_name, Length, Mass, protein_mw)],
protTraces$undifferentiated_3$trace_annotation[, .(protein_id, Entry_name, Gene_names, Entry_name, Length, Mass, protein_mw)],
protTraces$differentiated_1$trace_annotation[, .(protein_id, Entry_name, Gene_names, Entry_name, Length, Mass, protein_mw)],
protTraces$differentiated_2$trace_annotation[, .(protein_id, Entry_name, Gene_names, Entry_name, Length, Mass, protein_mw)],
protTraces$differentiated_3$trace_annotation[, .(protein_id, Entry_name, Gene_names, Entry_name, Length, Mass, protein_mw)],
protTraces$stimulated_1$trace_annotation[, .(protein_id, Entry_name, Gene_names, Entry_name, Length, Mass, protein_mw)],
protTraces$stimulated_2$trace_annotation[, .(protein_id, Entry_name, Gene_names, Entry_name, Length, Mass, protein_mw)],
protTraces$stimulated_3$trace_annotation[, .(protein_id, Entry_name, Gene_names, Entry_name, Length, Mass, protein_mw)]))
# remove redundant Entry_name column
proteins[, 2]=NULL
proteins[, in_diffProteins:=protein_id%in%c(diffProteins_differentiated_undifferentiated$feature_id,
diffProteins_stimulated_differentiated$feature_id,
diffProteins_stimulated_undifferentiated$feature_id), .(protein_id)]
proteins[, in_diffAssembly:=protein_id%in%c(diffAssemblyState_differentiated_undifferentiated$protein_id,
diffAssemblyState_stimulated_differentiated$protein_id,
diffAssemblyState_stimulated_undifferentiated$protein_id), .(protein_id)]
# Add proteins info to diffProteins tables
if (!("Gene_names" %in% names(diffProteins_differentiated_undifferentiated))) {
diffProteins_differentiated_undifferentiated = merge(diffProteins_differentiated_undifferentiated, proteins[, .(protein_id, Entry_name, Gene_names)],
by.x = "feature_id", by.y = "protein_id", all.x = T, all.y = F)
saveRDS(diffProteins_differentiated_undifferentiated,
file = "data/protein_DiffExprProtein_differentiated_undifferentiated.rda")
}
if (!("Gene_names" %in% names(diffProteins_stimulated_differentiated))) {
diffProteins_stimulated_differentiated = merge(diffProteins_stimulated_differentiated, proteins[, .(protein_id, Entry_name, Gene_names)],
by.x = "feature_id", by.y = "protein_id", all.x = T, all.y = F)
saveRDS(diffProteins_stimulated_differentiated,
file = "data/protein_DiffExprProtein_stimulated_differentiated.rda")
}
if (!("Gene_names" %in% names(diffProteins_stimulated_undifferentiated))) {
diffProteins_stimulated_undifferentiated = merge(diffProteins_stimulated_undifferentiated, proteins[, .(protein_id, Entry_name, Gene_names)],
by.x = "feature_id", by.y = "protein_id", all.x = T, all.y = F)
saveRDS(diffProteins_stimulated_undifferentiated,
file = "data/protein_DiffExprProtein_stimulated_undifferentiated.rda")
}
# Add proteins info to diffAssembly tables
if (!("Gene_names" %in% names(diffAssemblyState_differentiated_undifferentiated))) {
diffAssemblyState_differentiated_undifferentiated = merge(diffAssemblyState_differentiated_undifferentiated, proteins[, .(protein_id, Entry_name, Gene_names)],
by = "protein_id", all.x = T, all.y = F)
saveRDS(diffAssemblyState_differentiated_undifferentiated,
file = "data/diffAssemblyState_differentiated_undifferentiated.rda")
}
if (!("Gene_names" %in% names(diffAssemblyState_stimulated_differentiated))) {
diffAssemblyState_stimulated_differentiated = merge(diffAssemblyState_stimulated_differentiated, proteins[, .(protein_id, Entry_name, Gene_names)],
by = "protein_id", all.x = T, all.y = F)
saveRDS(diffAssemblyState_stimulated_differentiated,
file = "data/diffAssemblyState_stimulated_differentiated.rda")
}
if (!("Gene_names" %in% names(diffAssemblyState_stimulated_undifferentiated))) {
diffAssemblyState_stimulated_undifferentiated = merge(diffAssemblyState_stimulated_undifferentiated, proteins[, .(protein_id, Entry_name, Gene_names)],
by = "protein_id", all.x = T, all.y = F)
saveRDS(diffAssemblyState_stimulated_undifferentiated,
file = "data/diffAssemblyState_stimulated_undifferentiated.rda")
}
# annotate diffComplexes with complex names and protein subunits so they appear in the table output later
complexFeaturesAbbrev <- subset(complexFeatures, select = c(complex_id, complex_name, subunits, apex))
diffComplexes_stimulated_undifferentiated <- join(x = diffComplexes_stimulated_undifferentiated, y = complexFeaturesAbbrev, by = c("complex_id", "apex"),
type="left")
diffComplexes_stimulated_undifferentiated <- diffComplexes_stimulated_undifferentiated [, c(1,17,18,2:16)]
saveRDS(diffAssemblyState_stimulated_undifferentiated, file = "data/complex_DiffExprComplex_stimulated_undifferentiated_annot.rda")
diffComplexes_stimulated_differentiated <- join(x = diffComplexes_stimulated_differentiated, y = complexFeaturesAbbrev, by = c("complex_id", "apex"),
type="left")
diffComplexes_stimulated_differentiated <- diffComplexes_stimulated_differentiated [, c(1,17,18,2:16)]
saveRDS(diffComplexes_stimulated_differentiated, file = "data/complex_DiffExprComplex_stimulated_differentiated_annot.rda")
diffComplexes_differentiated_undifferentiated <- join(x = diffComplexes_differentiated_undifferentiated, y = complexFeaturesAbbrev, by = c("complex_id", "apex"),
type="left")
diffComplexes_differentiated_undifferentiated <- diffComplexes_differentiated_undifferentiated [, c(1,17,18,2:16)]
saveRDS(diffComplexes_differentiated_undifferentiated, file = "data/complex_DiffExprComplex_differentiated_undifferentiated_annot.rda")
# Annotate parent complexes
proteins[, parent_complex_ids:=paste(unique(complexFeatures[grep(protein_id, complexFeatures$subunits)]$complex_id), collapse = ","), .(protein_id)]
proteins[, parent_complex_names:=paste(unique(complexFeatures[grep(protein_id, complexFeatures$subunits)]$complex_name), collapse = ","), .(protein_id)]
proteins[, parent_complex_feature_identifiers:=paste(unique(complexFeatures[grep(protein_id, complexFeatures$subunits)]$unique_feature_identifier), collapse = ","), .(protein_id)]
saveRDS(proteins, "data/proteins.rda")
saveRDS(names(proteins)[c(1:3,9,10,11)], "data/protidcols.rda")
# Make complex selection table (Differential Tab)
complexes_diff_ids = unique(c(diffComplexes_differentiated_undifferentiated$complex_id,
diffComplexes_stimulated_differentiated$complex_id,
diffComplexes_stimulated_undifferentiated$complex_id))
saveRDS(complexes_diff_ids, file = "data/complexes_diff_ids.rda")
# Make complex feature selection table
names(complexFeatures)
cfidcols = names(complexFeatures)[c(7,1,2,3)]
saveRDS(cfidcols, file = "data/cfidcols.rda")
# Set bioconductor repository for Shiny deploy to go thru..
library(BiocManager)
options(repos = BiocManager::repositories())