-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_TCapp.R
586 lines (428 loc) · 25.1 KB
/
test_TCapp.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
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
# Load Packages ---
# library(shiny)
# library(tidyverse)
# library(openxlsx)
# library(DT)
if(!require(markdown)){
install.packages("markdown")
library(markdown)
}
if(!require(shiny)){
install.packages("shiny")
library(shiny)
}
if(!require(tidyverse)){
install.packages("tidyverse")
library(tidyverse)
}
if(!require(openxlsx)){
install.packages("openxlsx")
library(openxlsx)
}
if(!require(DT)){
install.packages("DT")
library(DT)
}
if(!require(vroom)){
install.packages("vroom")
library(vroom)
}
# Functions
extract <- function(text) {
text <- gsub(" ", "", text)
split <- strsplit(text, ",")[[1]]
as.numeric(split)
}
APMS_MQ = function(df){
df %>%
dplyr::select(., any_of(c("Majority protein IDs", "Protein names", "Fasta headers", "Gene names", "Gene name", "Potential contaminant", "Peptides",
"Razor + unique peptides", "Unique peptides", "Sequence coverage [%]")),
contains("Difference"), contains("p-value"), contains("Significant"), starts_with("LFQ intensity"), starts_with("MS/MS count")) %>%
dplyr::mutate(across(.cols = starts_with("LFQ intensity"), ~round(.x, 4)),
across(.cols = contains("Difference"), ~round(.x, 4))) %>%
dplyr::mutate("Summed LFQ Intensity" = round(rowSums(2^across(.cols = starts_with("LFQ intensity")), na.rm=TRUE)), 0) %>%
dplyr::select(., any_of(c("Majority protein IDs", "Protein names", "Gene names", "Gene name", "Fasta headers", "Razor + unique peptides", "Potential contaminant")),
contains("Difference"), contains("p-value"), contains("Significant"), starts_with("LFQ intensity"), "Peptides",
"Unique peptides", "Sequence coverage [%]", starts_with("Sequence coverage"), "Summed LFQ Intensity", starts_with("MS/MS count"),
-contains("significant", ignore.case=FALSE)) %>%
dplyr::arrange(.,desc(`Summed LFQ Intensity`))
}
import_pers = function(file_loc){
firstRead = read.delim(file_loc, sep = "\t", na.strings = c("NaN", "NA"), check.names = FALSE)
finalRead = read.delim(file_loc, sep = "\t", skip = sum(grepl("#!", firstRead[,1])),
col.names = names(firstRead), na.strings = c("NaN", "NA"), check.names = FALSE)
# skips the first several rows which contain a #!
# also renames columns from the first read, and converts blank, NaN and NA values to N/A
}
options(shiny.maxRequestSize=200*1024^2) # increase server.R limit to 200MB file size
ui <- navbarPage("Table Converter",
tabPanel("File Upload",
sidebarLayout(
sidebarPanel(
h3("Select data type"),
radioButtons("SearchEngine", "Select Seach Engine Used:",
choices = c("Spectronaut", "Byos", "MQ-Perseus")),
conditionalPanel(
h3("Byos"),
condition = "input.SearchEngine == 'Byos'", # Do i need Byos to be in single quotes? yes
fileInput("byosFile", "Select the preprocessed results:",
multiple = FALSE,
placeholder = ".xlsx",
accept = c(".xlsx")),
h4("Choose one option to supply expected mass values:"),
radioButtons("expectedInput", "Choose method for expected masses:",
choices = (c("Manual", "xlsx"))),
fileInput("byosExpectedFile", "upload a xlsx file containing expected masses"),
textInput("expectedMasses", label = "Optional: Add expected masses, only separated by a comma",
value = "")
#selectInput("tab2", "Transformed Tab", choices = NULL),
),
conditionalPanel(
h3("Spectronaut"),
condition = "input.SearchEngine == 'Spectronaut'",
fileInput("SpectroStatsFile", "Select a Candidate Stats file:",
multiple = FALSE,
accept = c(".xls", ".tsv")),
fileInput("SpectroQuantFile", "Select a Report quant file:",
multiple = FALSE,
accept = c(".xls", ".tsv")),
radioButtons("SpectroDataType", "Data Type:", choices = c("Protein", "PTM"), selected = "Protein"),
conditionalPanel(
condition = "input.SpectroDataType == 'PTM'",
checkboxGroupInput("SpNPTMsKeep", "Which PTMs do you want to keep:",
choices = NULL),
),
radioButtons("AddConditions", "Import SpN condition setup FIle: yes/no", choices = c("Yes", "No"), selected = "No"),
conditionalPanel(
condition = "input.AddConditions == 'Yes'",
fileInput("SpectroConditions", "Select a Condition file:",
multiple = FALSE,
accept = c(".tsv"))
),
checkboxGroupInput("SpNcomparisons", "Choose which comparisons to keep:",
choices = NULL),
radioButtons("transformSpectro", "How do you want the sample quantity values",
choices = c("non-transformed", "Log2", "Both"), selected = "Log2"),
radioButtons("statsFilter", "stats value to filter on:", c("p-value" = "pvalue","q-value" = "qvalue"), selected = "qvalue"),
#numericInput("statsValue", "stats value to filter by:", value = "0.05")
),
conditionalPanel(
h3("MQ-Perseus"),
condition = "input.SearchEngine == 'MQ-Perseus'", # can this have 2 options
fileInput("perseusUnimputedFile", "Select the UNIMPUTED Perseus txt file:",
multiple = FALSE,
accept = c(".txt")),
fileInput("perseusImputedFile", "Select the IMPUTED Perseus txt file:",
multiple = FALSE,
accept = c(".txt")),
h6("You can filter the comparison tabs 2 ways, either strickly by pvalue < 0.05 or pvalue<0.05 & FC>1"),
radioButtons("PerseusFilterOption", "Choose method to filter data by:",
choices = (c("pval", "pval & log2FC")))
),
selectInput("tab2", "Select tab to view", choices = NULL),
textInput("outputFileName", label = "Export file name:", value = ""),
actionButton("convert", label = "Convert", class = "btn btn-success"),
downloadButton("download", label = "Download", icon = icon("download"), class = "btn btn-primary")
),
mainPanel(
DT::dataTableOutput("df2"))
)),
tabPanel("Manual",
includeMarkdown("manual.md")))
server = function(input, output, session){
byosDf = reactive({
req(input$byosFile)
sheet_names = getSheetNames(input$byosFile$datapath) # extract all excel sheet names
file1 = lapply(sheet_names, function(x){
as.data.frame(read.xlsx(input$byosFile$datapath, sheet = x, sep.names = " ")) # read in each tab
})
names(file1) = sheet_names
return(file1)
})
ByosSheetNames = reactive({
req(input$byosFile)
sheet_names = getSheetNames(input$byosFile$datapath) # will get "path" must be string error if I don't have the $datapath part
return(sheet_names)
})
byosExpectedFile = reactive({
req(input$byosExpectedFile)
file = read.xlsx(input$byosExpectedFile$datapath, sheet=1)[,2]
return(file)
})
byosExpectedInput = reactive({
expected = extract(input$expectedMasses)
})
spectroStats = reactive({
req(input$SpectroStatsFile)
#file = read.delim(input$SpectroStatsFile$datapath, sep = "\t", check.names = FALSE)
#file = fread(input$SpectroStatsFile$datapath, sep = "\t", na.strings = c("NA", "NaN"), nThread = 2)
file = vroom(input$SpectroStatsFile$datapath, delim = "\t", na = c("NA", "NaN"), show_col_types = FALSE, progress = FALSE, num_threads = 2)
return(file)
})
spectroQuant = reactive({
req(input$SpectroQuantFile)
#file = read.delim(input$SpectroQuantFile$datapath, sep = "\t", check.names = FALSE)
file = vroom(input$SpectroQuantFile$datapath, delim = "\t", na = c("NA", "NaN", "Filtered"), show_col_types = FALSE, progress = FALSE, num_threads = 2)
return(file)
})
spectroCond = reactive({
req(input$SpectroConditions)
#file = read.delim(input$SpectroQuantFile$datapath, sep = "\t", check.names = FALSE)
file = vroom(input$SpectroConditions$datapath, delim = "\t", na = c("NA", "NaN"), show_col_types = FALSE, progress = FALSE, num_threads = 1)
return(file)
})
spectroSheetNames = reactive({
df = spectroStats()
rm_pool = df %>%
#filter(!grepl("pool", tolower(`Comparison (group1/group2)`))) %>%
dplyr::filter(., `Comparison (group1/group2)` %in% input$SpNcomparisons)
sheetnames = unique(rm_pool$`Comparison (group1/group2)`) %>%
gsub(" ", "", .) %>%
gsub("/", " V ", .)
names = c("Proteins", sheetnames)
})
perseusUnImputed = reactive({
req(input$perseusUnimputedFile)
file = import_pers(file_loc = input$perseusUnimputedFile$datapath)
return(file)
})
perseusImputed = reactive({
req(input$perseusImputedFile)
file = import_pers(file_loc = input$perseusImputedFile$datapath)
return(file)
})
perseusSheetNames = reactive({
df = perseusImputed()
tabNames = str_replace_all(str_remove_all(names(dplyr::select(df, contains("p-value"))), "Student's T-test p-value "),
pattern = "_", replacement = " v ")
tabnames = c("Proteins", "Imputed", tabNames)
})
observeEvent(spectroStats(), {
updateCheckboxGroupInput(session, "SpNcomparisons", choices = sort(unique(spectroStats()$`Comparison (group1/group2)`)))
})
observeEvent(spectroQuant(), {
updateCheckboxGroupInput(session, "SpNPTMsKeep", choices = unique(spectroQuant()$`PTM.ModificationTitle`))
})
finalSheetnames = reactive({
switch(input$SearchEngine,
"MQ-Perseus" = perseusSheetNames(),
"Byos" = ByosSheetNames(),
"Spectronaut" = spectroSheetNames())
})
observeEvent(finalSheetnames(), {
updateSelectInput(session, "tab2", choices = finalSheetnames())
})
conv_Byos = eventReactive(list(input$convert, input$SearchEngine == "Byos"),{
if(input$expectedInput == "Manual"){
expected = byosExpectedInput()
}
else{
expected = byosExpectedFile()
}
sheet_names = ByosSheetNames()
byosdf = byosDf()
nist = byosdf[[1]] %>%
dplyr::select(., Name, Mass, `Expected mass`, Intensity) %>%
mutate(Mass = as.numeric(Mass),
Intensity = as.numeric(Intensity)) %>%
arrange(desc(Intensity)) %>%
mutate(`Expected mass` = as.numeric(`Expected mass`)) %>%
mutate("Delta mass from expected" = round(Mass - `Expected mass`, 4)) %>%
mutate("Delta mass from most intense" = round(dplyr::first(Mass) - Mass, 4)) %>%
mutate("Local Rel. Int. (%)" = round(Intensity / dplyr::first(Intensity) * 100, 2), "%") %>%
dplyr::rename(., "Measured mass" = Mass) %>%
mutate(Intensity = formatC(Intensity, format = "e", digits = 2)) %>%
dplyr::select(., Name, `Measured mass`, `Expected mass`,
`Delta mass from expected`,
`Delta mass from most intense`, Intensity, `Local Rel. Int. (%)`)
samps = map2(expected, byosdf[2:length(byosdf)], function(x,y){
red2 = y %>%
dplyr::select(., Name, Mass, `Expected mass`, Intensity) %>%
mutate(Mass = as.numeric(Mass),
Intensity = as.numeric(Intensity)) %>%
arrange(desc(Intensity)) %>%
mutate(`Expected mass` = as.numeric(`Expected mass`)) %>%
mutate("Delta mass from expected (ilab)" = round((Mass - x), 4)) %>%
mutate("Delta mass from expected (byos)" = round((Mass - `Expected mass`), 4)) %>%
mutate("Expected mass (ilab)" = rep(x, nrow(.))) %>%
mutate("Delta mass from most intense" = round((dplyr::first(Mass) - Mass), 4)) %>%
mutate("Local Rel. Int. (%)" = round(Intensity / dplyr::first(Intensity) * 100, 2), "%") %>%
dplyr::rename(., "Measured mass" = Mass) %>%
mutate(Intensity = formatC(Intensity, format = "e", digits = 2)) %>%
dplyr::select(., Name, `Measured mass`, `Expected mass (ilab)`, `Delta mass from expected (ilab)`,
`Expected mass (byos)` = `Expected mass`, `Delta mass from expected (byos)`,
`Delta mass from most intense`, Intensity, `Local Rel. Int. (%)`)
})
lst = c(list(nist), samps)
names(lst) = ByosSheetNames()
return(lst)
})
conv_Spec = eventReactive(list(input$convert, input$SearchEngine == "Spectronaut"),{
stats_df = spectroStats()
quant_df = spectroQuant()
stats2 = stats_df %>% # remember this data is in the long format until the end when i pivot_wider
dplyr::filter(., if_any(matches("Valid"), ~Valid == TRUE)) %>% # if the valid column exists, filter it for only true values
dplyr::select(., comparison = starts_with("Comparison"), Group,
log2FC = `AVG Log2 Ratio`, pvalue = Pvalue, qvalue = Qvalue) %>%
dplyr::filter(., comparison %in% input$SpNcomparisons) %>%
#dplyr::filter(!grepl("pool", tolower(comparison))) %>% # remove comparisons that contain the word "pool", should not need now with SpNcomparisons
tidyr::pivot_wider(., names_from = comparison, values_from = c(log2FC, pvalue, qvalue))
if(input$SpectroDataType == "Protein"){
report_column_names_keep = c("ProteinGroups", "ProteinNames", "Genes", "ProteinDescriptions","FastaFiles", "FastaHeaders",
"CellularComponent", "BiologicalProcess", "MolecularFunction", "UniquePeptides")
quant2 = quant_df %>%
dplyr::select(., any_of(c("PG.ProteinGroups", "PG.ProteinNames", "PG.Genes", "PG.ProteinDescriptions", "PG.FastaFiles", "PG.NrOfStrippedSequencesIdentified (Experiment-wide)",
"PG.FastaHeaders", "PG.CellularComponent", "PG.BiologicalProcess", "PG.MolecularFunction")), ends_with("PG.Quantity")) %>%
dplyr::rename(., "UniquePeptides" = `PG.NrOfStrippedSequencesIdentified (Experiment-wide)`) %>%
dplyr::rename_with(., .cols = !ends_with("PG.Quantity"), ~gsub("^.*\\.", "", .x)) %>%
dplyr::select(., any_of(report_column_names_keep), ends_with("PG.Quantity")) %>%
dplyr::mutate("SummedQuantity" = round(rowSums(across(ends_with("PG.Quantity")), na.rm=TRUE)),0) %>%
dplyr::mutate(across(.cols = ends_with("PG.Quantity"), ~round(.x, 4))) %>%
dplyr::left_join(., stats2, by = c("ProteinGroups" = "Group")) %>%
dplyr::select(., any_of(c(report_column_names_keep, "SummedQuantity")), # unique peptides column comes from the candidates dataframe
starts_with("log2FC"), starts_with("pvalue"), starts_with("qvalue"), ends_with("PG.Quantity")) %>%
dplyr::rename_all(~str_replace_all(., "\\s+", "")) %>%
dplyr::arrange(., desc(SummedQuantity)) %>%
Filter(function(x) !all(is.na(x)), .) # removes any columns that only contain NA's, mostly used for GO term columns that are empty.
}
if(input$SpectroDataType == "PTM"){
report_column_names_keep = c("ProteinId", "ProteinNames", "Genes", "ProteinDescriptions","FastaFiles", "FastaHeaders",
"CellularComponent", "BiologicalProcess", "MolecularFunction", "UniquePeptides",
"CollapseKey", "Multiplicity", "ModificationTitle", "SiteAA", "SiteLocation", "FlankingRegion")
quant2 = quant_df %>%
dplyr::select(., any_of(c("PTM.ProteinId", "PG.Genes", "PG.ProteinDescriptions", "PG.FastaFiles", "PG.FastaHeaders",
"PTM.CollapseKey", "PTM.Multiplicity", "PTM.ModificationTitle", "PTM.SiteAA", "PTM.SiteLocation", "PTM.FlankingRegion",
"PG.CellularComponent", "PG.BiologicalProcess", "PG.MolecularFunction")), ends_with("PTM.Quantity")) %>%
#dplyr::rename(., "UniquePeptides" = `PG.NrOfStrippedSequencesIdentified (Experiment-wide)`) %>%
dplyr::rename_with(., .cols = !ends_with("PTM.Quantity"), ~gsub("^.*\\.", "", .x)) %>% # removes everything before . in column names, except quant values
dplyr::select(., any_of(report_column_names_keep), ends_with("PTM.Quantity")) %>%
dplyr::mutate("SummedQuantity" = round(rowSums(across(ends_with("PTM.Quantity")), na.rm=TRUE)),0) %>%
dplyr::mutate(across(.cols = ends_with("PTM.Quantity"), ~round(.x, 4))) %>%
dplyr::left_join(., stats2, by = c("CollapseKey" = "Group")) %>%
dplyr::select(., any_of(c(report_column_names_keep, "SummedQuantity")), # unique peptides column comes from the candidates dataframe
starts_with("log2FC"), starts_with("pvalue"), starts_with("qvalue"), ends_with("PTM.Quantity")) %>%
dplyr::rename_all(~str_replace_all(., "\\s+", "")) %>%
dplyr::filter(., ModificationTitle %in% input$SpNPTMsKeep) %>%
dplyr::arrange(., desc(SummedQuantity)) %>%
Filter(function(x) !all(is.na(x)), .) # removes any columns that only contain NA's, mostly used for GO term columns that are empty.
}
if(input$transformSpectro == "Log2"){
quant2 = quant2 %>%
dplyr::mutate(across(.cols = matches("[PG|PTM].Quantity"), ~log2(.x), .names = "log2_{.col}"), .keep = "unused") %>%
dplyr::mutate(across(.cols = matches("[PG|PTM].Quantity"), ~round(.x, 4))) %>%
dplyr::arrange(., desc(SummedQuantity))
}
if(input$transformSpectro == "Both"){
cols_to_keep = names(quant2)[!grepl("[PG|PTM].Quantity", names(quant2))]
quant2 = quant2 %>%
dplyr::mutate(across(.cols = matches("[PG|PTM].Quantity"), ~log2(.x), .names = "log2_{.col}")) %>%
dplyr::mutate(across(.cols = matches("[PG|PTM].Quantity"), ~round(.x, 4))) %>%
dplyr::select(., any_of(cols_to_keep), starts_with("log2_"), starts_with("[")) %>%
dplyr::arrange(., desc(SummedQuantity))
}
# change the order of the p-values or q-values based on which was filtered on
if(input$statsFilter == "pvalue"){
quant2 = quant2 %>%
dplyr::select(., any_of(c(report_column_names_keep, "SummedQuantity")),
starts_with("log2FC"), starts_with("pvalue"), starts_with("qvalue"), matches("[PG|PTM].Quantity"))
}
if(input$statsFilter == "qvalue"){
quant2 = quant2 %>%
dplyr::select(., any_of(c(report_column_names_keep, "SummedQuantity")),
starts_with("log2FC"), starts_with("qvalue"), starts_with("pvalue"), matches("[PG|PTM].Quantity"))
}
# if condition file was added, rename the quant column to match
# for some reason this code works when run on its own but not when run within Shiny??
if(input$AddConditions == "Yes"){
cond_df = spectroCond()
if(input$SpectroDataType == "Protein"){
var_names = cond_df %>%
dplyr::select(., any_of(c("Run Label", "Condition", "Replicate"))) %>%
dplyr::mutate(num = seq(1:nrow(.))) %>%
dplyr::mutate(current_names = paste0("log2_", "[", num, "]", `Run Label`, ".PG.Quantity")) %>%
dplyr::mutate(samp_names = paste0("Log2_", Condition, "_", Replicate, "_Quantity")) %>%
dplyr::select(., all_of(c("samp_names", "current_names"))) %>%
tibble::deframe()
}
if(input$SpectroDataType == "PTM"){
var_names = cond_df %>%
dplyr::select(., any_of(c("Run Label", "Condition", "Replicate"))) %>%
dplyr::mutate(num = seq(1:nrow(.))) %>%
dplyr::mutate(current_names = paste0("log2_", "[", num, "]", `Run Label`, ".PTM.Quantity")) %>%
dplyr::mutate(samp_names = paste0("Log2_", Condition, "_", Replicate, "_Quantity")) %>%
dplyr::select(., all_of(c("samp_names", "current_names"))) %>%
tibble::deframe()
}
quant2 = quant2 %>%
dplyr::rename(!!!var_names)
}
# removes any comparisons that weren't choosen
stats_rmPool = stats_df %>%
dplyr::filter(!grepl("pool", tolower(`Comparison (group1/group2)`))) %>%
dplyr::filter(., `Comparison (group1/group2)` %in% input$SpNcomparisons)
# creates the comparison tabs by filtering on either p-value or q-value
# removed the log2FC filter forthe separate tabs
ind_comps = lapply(gsub("\\s+", "", unique(stats_rmPool$`Comparison (group1/group2)`)), function(x){
int = quant2 %>%
#dplyr::filter(., !!as.symbol(paste0("log2FC_",x)) > 0.6 | !!as.symbol(paste0("log2FC_", x)) < -0.6) %>%
dplyr::filter(., !!as.symbol(paste0(input$statsFilter, "_", x)) < 0.05) %>%
dplyr::filter(., UniquePeptides > 1) %>% # added this filter so that we keep these in the proteins tab but not in the comp. tabs
dplyr::arrange(., desc(!!as.symbol(paste0("log2FC_", x))))
})
lst = c(list(quant2), ind_comps)
names(lst) = spectroSheetNames()
return(lst)
})
conv_Perseus_MQ = eventReactive(list(input$convert, input$SearchEngine == "MQ-Perseus|PD-Perseus"),{
if(input$SearchEngine == "MQ-Perseus"){
cleaned_unimputed = APMS_MQ(df = perseusUnImputed())
cleaned_imputed = APMS_MQ(df = perseusImputed())
# just separate the comparisons that are on the cleaned_imputed df
log_names = names(dplyr::select(cleaned_imputed, contains("Difference")))
pvalue_names = names(dplyr::select(cleaned_imputed, contains("p-value")))
if(input$PerseusFilterOption == "pval"){
filt = map2(log_names, pvalue_names, function(x,y){
int = cleaned_imputed %>%
dplyr::filter(., !!as.symbol(y) < 0.05) %>%
dplyr::arrange(., desc((!!as.symbol(x))))
})
lst = c(list(cleaned_unimputed, cleaned_imputed), filt)
names(lst) = perseusSheetNames()
return(lst)
}
if(input$PerseusFilterOption == "pval & log2FC"){
filt = map2(log_names, pvalue_names, function(x,y){
int = cleaned_imputed %>%
dplyr::filter(., !!as.symbol(x) > 1 | !!as.symbol(y) < -1) %>%
dplyr::filter(., !!as.symbol(y) < 0.05) %>% # this method to evaluate "column name" as a variable. first turn into symbol, then !! inject it into expression
dplyr::arrange(., desc(!!as.symbol(x)))
})
lst = c(list(cleaned_unimputed, cleaned_imputed), filt)
names(lst) = perseusSheetNames()
return(lst)
}
}
})
finalOut = reactive({
switch(input$SearchEngine,
"MQ-Perseus" = conv_Perseus_MQ(),
"PD-Perseus" = PD,
"Byos" = conv_Byos(),
"Spectronaut" = conv_Spec())
})
DT = reactive({
newDT = finalOut()[[input$tab2]]
})
output$df2 = DT::renderDataTable(DT())
output$download = downloadHandler(
filename = function() {
paste0(format(Sys.time(),'%Y%m%d'), "_", input$outputFileName, "_Results.xlsx" )
},
content = function(file){
hs = createStyle(textDecoration = "Bold", wrapText = TRUE)
write.xlsx(finalOut(), file,
sheetName = finalSheetnames(), overwrite = TRUE, headerStyle = hs, keepNA = TRUE)
}
)
}
shinyApp(ui, server)