Repository navigation
Expand file tree
/
Copy pathserver.R
More file actions
255 lines (191 loc) · 8.13 KB
/
Copy pathserver.R
File metadata and controls
255 lines (191 loc) · 8.13 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
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
library(AnnotationDbi)
library(PlexedPiper)
library(progress)
library(zeallot)
library(plyr)
library(odbc)
library(tidyverse)
library(data.table)
library(AnnotationHub)
source("shiny_utils.R")
server <- function(input, output, session) {
progress <- reactiveValues(text = "MASIC not downloaded",
col = "red",
icon = "times-circle",
text2 = "MS-GF+ not downloaded",
col2 = "red",
text3 = "Data not quantified",
col3 = "red")
## 1st event
observeEvent(input$submit, {
jr <- PlexedPiper:::get_job_records_by_dataset_package(input$DataPkgNumber)
max_steps <- length(unique(jr$Dataset))
progress_bar <- shiny::Progress$new(session, min=0, max=max_steps*2)
on.exit(progress_bar$close())
# use the main progress outside of llply
progress_bar$set( value = 0, "Getting MASIC Data...")
if (input$DataPkgNumber == "") {
showNotification("Please select Data Package ID", type = "warning")
}
req(input$DataPkgNumber)
validate(need(input$DataPkgNumber, "Please select a Data Package"))
progress[['text']] <<- "MASIC data being fetched."
# withCallingHandlers({
# shinyjs::html("text", "")
# withProgress(message = 'Fetching MASIC data', value = 0, {
masic_data <<- read_masic_data_from_DMS_shiny(input$DataPkgNumber,
interference_score = T, progress_shiny(progress_bar))
if (!is.null(masic_data$InterferenceScore)) {
progress_bar$set( value = 0.5, "Filtering MASIC data")
masic_data <<- filter_masic_data(masic_data, interference_score_threshold = input$interference_score,
s2n_threshold = input$s2n)
}
# masic_progress[[1]] <<- "MASIC filtered"
progress[['text']] <<- "MASIC Processed" # do i really need <<- here?
progress[['col']] <<- "green"
})
output$ibox <- renderInfoBox({
infoBox("MASIC", value = progress[['text']], color = progress[["col"]])
})
output$masic_out <- renderDataTable({
masic_data
})
observeEvent(input$submit2, {
if (input$DataPkgNumber == "") {
showNotification("Please select Data Package ID", type = "warning")
}
req(input$DataPkgNumber)
validate(
need(input$DataPkgNumber, "Please select a Data Package")
)
progress[['text2']] <<- "MS-GF+ data being fetched."
jr <- PlexedPiper:::get_job_records_by_dataset_package(input$DataPkgNumber)
max_steps <- length(unique(jr$Dataset))
org_name <- gsub("_", " ", jr$Organism)
## TODO if org_name isn't in list of supported species, throw error
progress_bar <- shiny::Progress$new(session, min=0, max=max_steps)
# use the main progress outside of llply
progress_bar$set( value = 0, "Getting MS-GF+ Data...")
msnid <<- read_msms_data_from_DMS_shiny(input$DataPkgNumber, progress = progress_shiny(progress_bar))
msnid <<- correct_peak_selection(msnid)
progress_bar$close()
progress_bar <- shiny::Progress$new(session, min=0, max=1)
on.exit(progress_bar$close())
if (input$proteome == "Phospho" && input$add_ascore) {
progress_bar$set(value = 0.10, "Adding A-score")
ascore <- get_AScore_results(input$DataPkgNumber)
msnid <<- best_PTM_location_by_ascore(msnid, ascore)
}
progress_bar$set(value = 0.25, "Filtering unique peptide ID FDR")
if (input$proteome == "Phospho") {
psms(msnid) <<- psms(msnid)[grepl("\\*", psms(msnid)$Peptide),]
}
msnid <<- filter_msgf_data_peptide_level(msnid, input$pep_fdr)
if (input$remap_genes == T) {
progress_bar$set(value = 0.4, "Remapping to genes")
msnid <<- remap_accessions_refseq_to_gene(msnid,
organism_name=org_name)
path_to_FASTA <- path_to_FASTA_used_by_DMS.http(input$DataPkgNumber)
fst <- remap_accessions_refseq_to_gene_fasta_shiny(
path_to_FASTA,
organism_name = org_name)
## TODO add option for uniprot_to_gene
}
else {
path_to_FASTA <- path_to_FASTA_used_by_DMS.http(input$DataPkgNumber)
fst <- Biostrings::readAAStringSet(path_to_FASTA)
}
if (input$proteome == "Global") {
progress_bar$set(value = 0.5, "Filtering accession-level FDR")
msnid <<- compute_num_peptides_per_1000aa_shiny(msnid, fst)
msnid <<- filter_msgf_data_protein_level(msnid, input$prot_fdr)
}
if (input$proteome == "Phospho") {
progress_bar$set(value = 0.6, "Mapping modification sites")
path_to_FASTA <- path_to_FASTA_used_by_DMS.http(input$DataPkgNumber)
fst <- Biostrings::readAAStringSet(path_to_FASTA)
names(fst) <- sub("(^\\S*)\\s.*", "\\1", names(fst))
msnid <<- map_mod_sites(msnid, fst,
accession_col = "accession",
peptide_mod_col = "Peptide",
mod_char = "*",
site_delimiter = "lower")
}
progress_bar$set(value = 0.75, "Performing parsimonious inference")
if (input$protein_inference == T) {
msnid <<- infer_parsimonious_accessions(msnid, unique_only=input$unique_only)
}
psms(msnid)$isContam <- grepl("Contam", psms(msnid)$accession)
msnid <- apply_filter(msnid, "!isContam")
msnid <<- apply_filter(msnid, "!isDecoy")
progress_bar$set(value = 1, "MS/MS data processing complete")
progress[['text2']] <<- "MS-GF+ data processed."
progress[['col2']] <<- "green"
})
output$ibox2 <- renderInfoBox({
infoBox("MS-GF+", value = progress[['text2']], color = progress[['col2']], icon = icon("list"))
})
output$msms_out <- renderDataTable({
msnid
})
observeEvent(input$submit3, {
if (!exists("masic_data") | !exists("msnid")) {
showNotification("Please download both MASIC and MS-GF+ data before this step.",
type = "error")
}
validate(
need(exists('masic_data'), "Please download MASIC")
)
validate(
need(exists('msnid'), "Please download MS-GF+")
)
progress[['text3']] <<- "Data not quantified"
withProgress(message = 'Creating crosstab', value = 0, {
samples <- data.frame()
fractions <- data.frame()
references <- data.frame()
c(samples, fractions, references) %<-% get_study_design_by_dataset_package.http(input$DataPkgNumber)
if (input$proteome == "Global") {
if (input$gl_aggregate_to == "Accession")
aggregation_level <<- c("accession")
if(input$gl_aggregate_to == "Peptide")
aggregation_level <<- c("accession", "peptide")
}
if (input$proteome == "Phospho") {
if (input$ph_aggregate_to == "Peptide")
aggregation_level <<- c("accession", "peptide")
if(input$ph_aggregate_to == "SiteID")
aggregation_level <<- c("SiteID")
}
incProgress(amount = 0.25, message = "Rolling up...")
crosstab <<- PlexedPiper::create_crosstab(msnid, masic_data, aggregation_level,
fractions, samples, references)
incProgress(amount = 1, message = "Crosstab created")
})
progress[['text3']] <<- "Data quantified and ready for download"
progress[['col3']] <<- "green"
})
output$ibox3 <- renderInfoBox({
infoBox("Quant", value = progress[['text3']], color = progress[['col3']], icon = icon("file-alt"))
})
output$crosstab_out <- renderDataTable({
if (input$submit3 == 0)
return()
validate(
need(exists('crosstab'), "Crosstab doesn't exist")
)
isolate(
as.data.frame(crosstab)
)
})
## handle downloading data
output$downloadData <- downloadHandler(
filename = function() {
paste0("crosstab", ".txt")
},
content = function(file) {
write.table(signif(crosstab, 3), file, sep = "\t", col.names = NA, quote = F,
na = "")
}
)
}