-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
574 lines (449 loc) · 39.4 KB
/
app.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
## app.R ##
#Rlib="/data/manke/sikora/shiny_apps/Rlibs3.5.0_bioc3.7"
Rlib="/rstudio/galaxy/.rstudio/R/x86_64-pc-linux-gnu-library/3.6"
.libPaths(Rlib)
library(shiny)
library(shinydashboard)
library(rhandsontable)
library(shinyBS)
library(shinyalert)
ui <- function(request) {dashboardPage(
dashboardHeader(title = "Dataset selection"),
## Sidebar content
dashboardSidebar(
useShinyalert(),
selectInput(inputId="selectworkflow",label="Select NGS workflow",choices=c("PLEASE SELECT WORKFLOW","ATAC-seq","ChIP-seq","DNA-mapping","HiC","mRNA-seq","noncoding-RNA-seq","WGBS","scRNAseq")),
textInput(inputId="analysistitle", label="Analysis title", value = "", width = NULL, placeholder = NULL),
selectInput(inputId="genome", label="Select organism", choices=c("PLEASE SELECT A GENOME","Zebrafish [zv10]","Fission yeast","Fruitfly [dm6]","Fruitfly [dm3]","Human [hg37]","Human [hg38]","Mouse [mm9]","Mouse [mm10]"), selected = NULL),
selectInput(inputId="selectformat",label="Select input file format",choices=c("fastq.gz","bam"),selected="bam"),
textInput(inputId="group", label="Group", value = "", width = NULL, placeholder = NULL),
textInput(inputId="owner", label="Project Owner", value = "", width = NULL, placeholder = NULL),
textInput(inputId="projectid", label="Project ID", value = "", width = NULL, placeholder = NULL),
textInput(inputId="pathtodata", label="Data folder", value = "", width = NULL, placeholder = NULL),
actionButton(inputId="adddataset", label="Add dataset"),
imageOutput("logo"),
tags$footer("Copyright 2018-2020 MPI-IE Freiburg Bioinfo Core Unit"),
bsTooltip(id="group", title="Enter group/department PI name as specified in the sequencing request.", placement = "right", trigger = "hover"),
bsTooltip(id="owner", title="Enter the name of data owner as specified in the sequencing request.", placement = "right", trigger = "hover"),
bsTooltip(id="projectid", title="Enter the sequencing project ID/number you have received from the sequencing facility.", placement = "right", trigger = "hover"),
bsTooltip(id="pathtodata", title="Paste the path to the folder containg the reads you would like to analyze.", placement = "right", trigger = "hover"),
bsTooltip(id="adddataset", title="Add a set of reads identified using the information above.", placement = "right", trigger = "hover"),
bsTooltip(id="analysistitle", title="Provide an optional analysis title.", placement = "right", trigger = "hover")
),
dashboardBody(
h2("User input"),
uiOutput("resultPanels")
)
)}
server <- function(input, output, session) {
##########load packages
library("yaml")
library("stringi")
library("sendmailR")
library("reshape2")
#########define functions
sInfoTOyaml<-function(df){
df2<-df[!df$ChIPgroup %in% "Input",!colnames(df) %in% c("Group","Read1","SampleID","ChIPgroup","Merge")]
df2$MatchedInput<-as.character(df2$MatchedInput)
df2$MatchedInput<-paste0("control: ",ifelse(df2$MatchedInput=="NA","False",df2$MatchedInput))
df2$MarkWidth<-as.character(df2$MarkWidth)
df2$MarkWidth[!df2$MarkWidth %in% c("Broad","Narrow")]<-"Narrow"
df2$MarkWidth[grep("Broad",df2$MarkWidth)]<-noquote("broad: True")
df2$MarkWidth[grep("Narrow",df2$MarkWidth)]<-noquote("broad: False")
df3<-as.data.frame(t(df2),stringsAsFactors=FALSE)
l3<-list(df3)
names(l3)<-"chip_dict"
l3y<-as.yaml(l3,omap=TRUE)
l3ymod<-gsub("'","",gsub("- ","",gsub("!omap","",l3y)))
l4<-yaml.load(l3ymod)
return(l4)
}
create_cellName_files<-function(sinfo){
sl<-split(sinfo,factor(sinfo$IntermediateID))
BCmat<-matrix(1:384,ncol=24,nrow=16,byrow=TRUE)
LmatH<-matrix(1:384,ncol=24,nrow=16,byrow=TRUE)
LmatHr<-matrix(1:384,ncol=24,nrow=16,byrow=TRUE)
for(i in seq(from=2,to=16,by=2)){
LmatHr[i,]<-rev(LmatHr[i,])
}
LmatV<-matrix(1:384,ncol=24,nrow=16,byrow=FALSE)
b<-melt(t(BCmat))$value
for(i in seq_along(sl)){
tabi<-sl[[i]]
if(as.character(tabi$SortOrder)=="A1-A24,B1-B24..."){
z<-melt(t(LmatH))$value
} else if(as.character(tabi$SortOrder)=="A1-P1,A2-P2..."){
z<-melt(t(LmatV))$value
} else if(as.character(tabi$SortOrder)=="A1-A24,B24-B1..."){
z<-melt(t(LmatHr))$value
}
zb<-data.frame(z,b)
cell_idx<-zb$b[order(zb$z)]
tabi<-data.frame(tabi,cell_idx)
tabi$cell_name<-paste0(tabi$IntermediateID,"_",tabi$cell_idx)
sl[[i]]<-tabi
}
return(sl)
}
write_cellNames<-function(cnlist,outdir){
for(i in seq_along(cnlist)){
tabi<-cnlist[[i]]
##subset and rename columns
tabi<-tabi[,c("SampleID","Plate","cell_idx","cell_name")]
colnames(tabi)<-c("sample","plate","cell_idx","cell_name")
write.table(tabi,file=file.path(outdir,paste0(names(cnlist)[i],".csv")),sep="\t",quote=FALSE,row.names=FALSE)
}
}
########init reactive values
values <- reactiveValues()
values$datdir<-c()
values$sInfoDest<-""
values$chDictDest<-""
values$cellNameDest<-""
values$genome<-""
####### constant observer on the project input
observe({
if ((input$group!="")&(input$owner!="")&(input$projectid!="")&(input$pathtodata!="")){
showModal(modalDialog(
title = "REDUNDANT INFORMATION PROVIDED",
"Please make sure to either fill in the Group-Owner-Project fields AND leave the folder path empty, or the reverse!",
easyClose = TRUE
))}
})
#######observe add dataset
observeEvent(input$adddataset, {
dsel<-c("fastq.gz"="Project","bam"="Analysis")
psel<-c("fastq.gz"="*fastq.gz$","bam"="*.bam$")
inFormat<-isolate(input$selectformat)
shinyalert("SEARCH IN PROGRESS", "Depending on the number of your files, this may take some time.", type = "success")
if((input$group!="")&(input$owner!="")&(input$projectid!="")&(input$pathtodata=="")){
inGroup<-isolate(input$group)
inOwner<-isolate(input$owner)
inProjectID<-isolate(input$projectid)
values$datdir<-c(values$datdir,system(sprintf("find /data/%s/sequencing_data* -name %s_%s_%s_%s -type d -maxdepth 2 | sort",tolower(gsub("-.+","",inGroup)),dsel[inFormat],inProjectID,inOwner,inGroup,tolower(gsub("-.+","",inGroup))),intern=TRUE))
}
else if ((input$group=="")&(input$owner=="")&(input$projectid=="")&(input$pathtodata!="")){
values$datdir<-c(values$datdir,isolate(input$pathtodata))
}
#handle single and paired end data ###allow for multiple sequencing runs
values$datPath<-dir(values$datdir,pattern=psel[inFormat],full.names=TRUE,recursive=TRUE)
if(!isTruthy(values$datdir)){
showModal(modalDialog(
title = "DATA NOT FOUND",
"Please verify the spelling of Group and Owner names (first capital letter of the last name) or the path you provided!",
easyClose = TRUE
))}
req(values$datdir)
if(inFormat %in% "bam"){
values$ispaired<-FALSE
values$Read1<-grep(".+.bam$",values$datPath,value=TRUE,perl=TRUE)
values$datshort<-gsub(".bam","",gsub(".filtered.bam","",gsub(".PCRrm.bam","",basename(values$datPath))))
}
else{
#get rid of optical duplicates
values$datPath<-grep("*optical*",values$datPath,value=TRUE,invert=TRUE)
if(sum(grepl(".+_R*2.fastq.gz",values$datPath,perl=TRUE))>0){values$ispaired<-TRUE
output$ispaired<-renderText("Paired reads detected.")
values$Read1<-grep(".+_R*1.fastq.gz",values$datPath,value=TRUE,perl=TRUE)
values$Read2<-grep(".+_R*2.fastq.gz",values$datPath,value=TRUE,perl=TRUE)
output$Read1<-renderText(values$Read1)
output$Read2<-renderText(values$Read2)
values$datshort<-gsub("_R*1.fastq.gz","",basename(grep(".+_R*1.fastq.gz",values$Read1,value=TRUE,perl=TRUE)),perl=TRUE)}
else{values$ispaired<-FALSE
output$ispaired<-renderText("Single reads detected.")
values$Read1<-grep("*.fastq.gz",values$datPath,value=TRUE)
output$Read1<-renderText(values$Read1)
values$datshort<-gsub("_R*1*.fastq.gz","",basename(values$Read1))}
}
if(length(unique(values$datshort))<length(values$datshort)){
values$datwarnings<-"Warning! Your dataset contains multiple instances of identically named samples! If these are resequenced samples, consider merging them before continuing with the analysis or exclude them by leaving NAs in the Group column. Otherwise they will be overwritten."
}else{values$datwarnings<-"All sample names are unique. Proceed with the analysis."}
output$datawarnings<-renderText(values$datwarnings)
},ignoreInit=TRUE)#end of observe input$adddataset
####observe workflow choice and create reactive table
observe({
values$inWorkflow<-input$selectworkflow
if(values$inWorkflow=="ChIP-seq"){
values$DF<-data.frame(SampleID=values$datshort,Group=(factor(rep("NA",(length(values$datshort))),levels=c("Control","Treatment","NA"))),Merge=factor(rep("NA",(length(values$datshort))),levels=c("NA",unique(values$datshort)),ordered=TRUE),Read1=values$Read1,ChIPgroup=factor(rep("NA",(length(values$datshort))),levels=c("NA","ChIP","Input"),ordered=TRUE),MatchedInput=factor(rep("NA",(length(values$datshort))),levels=c("NA",unique(values$datshort)),ordered=TRUE),MarkWidth=factor(rep("NA",(length(values$datshort))),levels=c("NA","Broad","Narrow"),ordered=TRUE),stringsAsFactors = F)
output$tabdesc<-renderText({"<font size=4><ul><li>SampleID: automaticaly parsed from read names: do not modify.</li><li>Group: assign samples to Control and Treatment groups. Leave NA for samples you would like to exclude from the analysis.</li><li>Merge: select a Sample ID under which you would like to merge fastq files. Leave NA if not needed.</li><li>Read1: for your information, the identity of the read file. Only 1 of the 2 paired end files will be listed.</li><li>ChIPgroup: define the samples as Input or ChIP.</li><li>MatchedInput: to each ChIP sample, assign the matched Input sample.</li><li>MarkWidth: specify if Narrow or Broad peak calling mode should be used.</li></ul></font>"})
}
else if(values$inWorkflow=="HiC"){
values$DF<-data.frame(SampleID=values$datshort,Group=(rep("NA",(length(values$datshort)))),Merge=factor(rep("NA",(length(values$datshort))),levels=c("NA",unique(values$datshort)),ordered=TRUE),Read1=values$Read1,stringsAsFactors = F)
output$tabdesc<-renderText({"<font size=4><ul><li>SampleID: automaticaly parsed from read names: do not modify.</li><li>Group: type in sample group names. Leave NA for samples you would like to exclude from the analysis.</li><li>Merge: select a Sample ID under which you would like to merge fastq files. Leave NA if not needed.</li><li>Read1: for your information, the identity of the read file. Only 1 of the 2 paired end files will be listed.</li></ul></font>"})
}
else if(values$inWorkflow %in% c("WGBS","ATAC-seq")){
values$DF<-data.frame(SampleID=values$datshort,Group=(factor(rep("NA",(length(values$datshort))),levels=c("Control","Treatment","WT","Mut","NA"))),PlottingID=values$datshort,Merge=factor(rep("NA",(length(values$datshort))),levels=c("NA",unique(values$datshort)),ordered=TRUE),Read1=values$Read1,stringsAsFactors = F)
output$tabdesc<-renderText({"<font size=4><ul><li>SampleID: automaticaly parsed from read names: do not modify.</li><li>Group: assign samples to Control and Treatment or WT and Mut groups. Leave NA for samples you would like to exclude from the analysis.</li><li>PlottingID: type in names to use for plots if deviating from sample names.</li><li>Merge: select a Sample ID under which you would like to merge fastq files. Leave NA if not needed.</li><li>Read1: for your information, the identity of the read file. Only 1 of the 2 paired end files will be listed.</li></ul></font>"})
}
else if(values$inWorkflow=="scRNAseq"){
values$DF<-data.frame(SampleID=values$datshort,Group=(rep("NA",(length(values$datshort)))),Plate=(factor(rep("NA",(length(values$datshort))),levels=c(paste0("P",1:20),"NA"))),NewSampleID=(rep("NA",(length(values$datshort)))),SortOrder=factor(rep("NA",(length(values$datshort))),levels=c("A1-A24,B1-B24...","A1-P1,A2-P2...","A1-A24,B24-B1...","NA")),Read1=values$Read1,stringsAsFactors = F)
output$tabdesc<-renderText({"<font size=4><ul><li>You don't need to fill the Group column, this is for internal code compatibility and will be ignored in the analysis. Fill in Plate, NewSampleID, and SortOrder information only if you'd like request analysis with mode Gruen and have your samples renamed. Currently the renaming is implemented only for 384 well format. For other analysis modes, or when no sample renaming is needed, leave in NA values and save sample sheet with the samples you want to use.</li><li>SampleID: automaticaly parsed from read names: do not modify.</li><li>Plate: assign plate number.</li><li>NewSampleID: this will substitute SampleID in the analysis.</li><li>SortOrder: which order were your cells FACS sorted onto the plate? If your sort order is not on the list, ask bioinfo-core to add it.</li><li>Read1: for your information, the identity of the read file. Only 1 of the 2 paired end files will be listed.</li></ul></font>"})
} else {
values$DF<-data.frame(SampleID=values$datshort,Group=(factor(rep("NA",(length(values$datshort))),levels=c("Control","Treatment","NA"))),ComparisonGroup=(factor(rep("NA",(length(values$datshort))),levels=c("All",paste0("Group",1:20),"NA"))),Merge=factor(rep("NA",(length(values$datshort))),levels=c("NA",unique(values$datshort)),ordered=TRUE),Read1=values$Read1,stringsAsFactors = F)
output$tabdesc<-renderText({"<font size=4><ul><li>SampleID: automaticaly parsed from read names: do not modify.</li><li>Group: assign samples to Control and Treatment groups. Leave NA for samples you would like to exclude from the analysis.</li><li>Merge: select a Sample ID under which you would like to merge fastq files. Leave NA if not needed.</li><li>Read1: for your information, the identity of the read file. Only 1 of the 2 paired end files will be listed.</li></ul></font>"})
}
#values$DF<-DF
DF2<-isolate(values$DF)
values$DF2<-DF2
})#end of observe input$selectworkflow
observe({
if(!is.null(input$hot)){
DF2 <- hot_to_r(input$hot)
values$DF2<-DF2}
})
output$hot <- renderRHandsontable({
DF2<-values$DF2
rhandsontable(DF2,height=400)})
##########observe save samplesheet
observeEvent(input$savetable, {
values$analysisName<-gsub("[^[:alnum:]]", "_", isolate(input$analysistitle))
values$ranstring<-stri_rand_strings(n=1,length=8)
sampleInfo<-isolate(values$DF2)
if(values$inWorkflow=="scRNAseq"){
if(sum(sampleInfo$Plate %in% "NA")==nrow(sampleInfo)){sampleInfo$IntermediateID<-sampleInfo$NewSampleID}else{
sampleInfo$IntermediateID<-paste0(sampleInfo$NewSampleID,"_",sampleInfo$Plate)}
}
output$hot<-renderRHandsontable({rhandsontable(sampleInfo)})
###check for replicates, else issue a warning
if(sum(is.na(sampleInfo$Group),sampleInfo$Group %in% "NA")<length(sampleInfo$Group)){
sampleInfo$Group<-as.character(sampleInfo$Group)
sampleInfo<-sampleInfo[!is.na(sampleInfo$Group)&!sampleInfo$Group %in% "NA",]
#rownames(sampleInfo)<-make.names(sampleInfo$SampleID, unique=TRUE)
srep<-table(sampleInfo$SampleID)[unique(sampleInfo$SampleID)]
if(any(srep>1)){
rv<-unlist(sapply(srep,function(X)seq(1,X)))
rn<-paste0(sampleInfo$SampleID,"_",rv)
rownames(sampleInfo)<-rn} else {rownames(sampleInfo)<-sampleInfo$SampleID}
sampleInfo<-sampleInfo[order(sampleInfo$Group),]
gl<-min(ave(1:nrow(sampleInfo),sampleInfo$Group,FUN=length))
if(gl==1){
values$datwarnings<-c(values$datwarnings,"SOME SAMPLE GROUPS DON'T HAVE REPLICATES!!!")
}
else if (gl==2){
values$datwarnings<-c(values$datwarnings,"Some of your sample groups have only 2 replicates. This might be suboptimal for some analyses and lead to higher FDR.")
}
else if (gl==3){
values$datwarnings<-c(values$datwarnings,"All sample groups have at least 3 replicates.")
}
}else {srep<-table(sampleInfo$SampleID)[unique(sampleInfo$SampleID)]
if(any(srep>1)){
rv<-unlist(sapply(srep,function(X)seq(1,X)))
rn<-paste0(sampleInfo$SampleID,"_",rv)
rownames(sampleInfo)<-rn} else {rownames(sampleInfo)<-sampleInfo$SampleID}}
###check if ChIPseq is selected, if yes, create a yaml
if(values$inWorkflow=="ChIP-seq"){
chip_dict<-sInfoTOyaml(sampleInfo)
values$chDictDest<-sprintf("/data/manke/group/shiny/snakepipes_input/%s_%s_samples.yaml",values$ranstring,values$analysisName)
write_yaml(noquote(chip_dict),file=isolate(values$chDictDest))
}
###check if scRNAseq is selected, if yes, create cellName files
if(values$inWorkflow=="scRNAseq" & sum(sampleInfo$Plate %in% "NA")!=nrow(sampleInfo)){
cellName_list<-create_cellName_files(sampleInfo)
values$cellNameDest<-sprintf("/data/manke/group/shiny/snakepipes_input/%s_%s/plate_csv",values$ranstring,values$analysisName)
system(paste0('mkdir -p ',values$cellNameDest))
write_cellNames(cellName_list,isolate(values$cellNameDest))
}
#update read1 and read2 stored in reactive values
if (values$ispaired){
vRead1<-sampleInfo$Read1
vRead2<-sub("1.fastq.gz","2.fastq.gz",sampleInfo$Read1)
values$Reads<-c(vRead1,vRead2)
} else {
vRead1<-sampleInfo$Read1
values$Reads<-vRead1
}
values$sInfoDest<-sprintf("/data/manke/group/shiny/snakepipes_input/%s_%s_sampleSheet.tsv",values$ranstring,values$analysisName)
colnames(sampleInfo)[1:2]<-c("name","condition")
if(values$inWorkflow %in% c("mRNA-seq","noncoding-RNA-seq")){
colnames(sampleInfo)[3]<-c("group")
}
write.table(sampleInfo,file=values$sInfoDest,sep="\t",quote=FALSE)
output$sIsaved<-renderText("Sample sheet saved.")
output$from<-renderUI({textInput(inputId="sender",label="Your email address",placeholder="lastname@ie-freiburg.mpg.de")})
output$freetext<-renderUI({textInput(inputId="comments",label="Your message to the bioinfo facility",placeholder="Sample X might be an outlier.",width="600px")})
output$datarequests<- renderUI({
if(values$inWorkflow %in% c("ATAC-seq","ChIP-seq","DNA-mapping","WGBS")){
tagList(
checkboxInput(inputId="fbam", label="I want to start the analysis from the bam files.", value = FALSE, width = NULL),
checkboxInput(inputId="merge", label="I want to request sample merging.", value = FALSE, width = NULL),
checkboxInput(inputId="beff", label="I expect batch effect in my data.", value = FALSE, width = NULL),
checkboxInput(inputId="nodiff", label="I don't need differential analysis.", value = FALSE, width = NULL),
checkboxInput(inputId="SE", label="I have single end, NOT paired end data.", value = FALSE, width = NULL))
}else if (values$inWorkflow %in% "HiC"){
tagList(checkboxInput(inputId="merge", label="I want to request sample merging.", value = FALSE, width = NULL),
checkboxInput(inputId="nodiff", label="I don't need differential analysis.", value = FALSE, width = NULL),
checkboxInput(inputId="enz", label="I used DpnII instead of HindIII for restriction digest.", value = FALSE, width = NULL),
checkboxInput(inputId="notads", label="I don't need TAD calling.", value = FALSE, width = NULL))
}else if(values$inWorkflow %in% "mRNA-seq"){
tagList(
checkboxInput(inputId="fbam", label="I want to start the analysis from the bam files.", value = FALSE, width = NULL),
checkboxInput(inputId="merge", label="I want to request sample merging.", value = FALSE, width = NULL),
checkboxInput(inputId="beff", label="I expect batch effect in my data.", value = FALSE, width = NULL),
checkboxInput(inputId="nodiff", label="I don't need differential analysis.", value = FALSE, width = NULL),
checkboxInput(inputId="SE", label="I have single end, NOT paired end data.", value = FALSE, width = NULL),
checkboxInput(inputId="lT", label="I used NEBNext Low Input RNA Library Prep and my library type is unstranded.", value = FALSE, width = NULL))
}else if(values$inWorkflow %in% "noncoding-RNA-seq"){
tagList(
checkboxInput(inputId="fbam", label="I want to start the analysis from the bam files.", value = FALSE, width = NULL),
checkboxInput(inputId="merge", label="I want to request sample merging.", value = FALSE, width = NULL),
checkboxInput(inputId="beff", label="I expect batch effect in my data.", value = FALSE, width = NULL),
checkboxInput(inputId="nodiff", label="I don't need differential analysis.", value = FALSE, width = NULL),
checkboxInput(inputId="SE", label="I have single end, NOT paired end data.", value = FALSE, width = NULL))
}else if(values$inWorkflow %in% "scRNAseq"){
tagList(
selectInput(inputId="sc_mode", label="Analysis mode",choices=c("Gruen","STARsolo","Alevin"),selected="Gruen"),
conditionalPanel(condition="input.sc_mode=='STARsolo'",selectInput(inputId="sc_ltype", label="Kit",choices=c("CellSeq192","CellSeq384","10Xv2","10Xv3"),selected="CellSeq384")),
conditionalPanel(condition="input.sc_mode=='Alevin'",selectInput(inputId="sc_ltype", label="PrepProtocol",choices=c("celseq2","chromium","chromiumV3"),selected="celseq2"))
)}
})
values$mstr<-reactive({ifelse(input$merge,"--mergeSamples","")})
values$estr<-reactive({ifelse(input$enz,"--enzyme DpnII","--enzyme HindIII")})
values$ltype<-reactive({ifelse(input$lT,"--libraryType 0","")})
values$se<-reactive({ifelse(input$SE,"--singleEnd","")})
values$sc_mode<-input$sc_mode
values$sc_ltype<-input$sc_ltype
})#end of observe input$savetable
###########observe submit request
observeEvent(input$savesubmit, {
##########prepare the command
if(values$inWorkflow %in% c("ChIP-seq","ATAC-seq")){path_to_exec<-values$inWorkflow}else{
path_to_exec<-paste0("module load snakePipes; ",values$inWorkflow)}###add version selection
topdir<-sprintf("/data/processing/bioinfo-core/requests/%s_%s_%s",values$analysisName,values$ranstring,values$inWorkflow)
dsel<-c("fastq.gz"="fastq","bam"="bam")
indir<-sprintf("%s/%s",topdir,dsel[input$selectformat])
link_cmd<- paste0("ln -t ",indir,' -s ',paste(values$Reads,collapse=" "))
outdir<-sprintf("%s/analysis",topdir)
cp_sInfo_cmd<-sprintf("cp -v %s %s",values$sInfoDest,topdir)
values$sInfo_in<-paste0(topdir,"/",basename(values$sInfoDest))
genome_sel<-c("PLEASE SELECT A GENOME"="NONE","Zebrafish [zv10]"="GRCz10","Fission yeast"="SchizoSPombe_ASM294v2","Fruitfly [dm6]"="dm6","Fruitfly [dm3]"="dm3","Human [hg37]"="hs37d5","Human [hg38]"="hg38","Mouse [mm9]"="mm9","Mouse [mm10]"="mm10")
values$genome<-genome_sel[input$genome]
path_to_DNA_mapping<-paste0("module load snakePipes; DNA-mapping")
fbam<-c("fastq.gz"="","bam"="--fromBAM")
if(values$inWorkflow=="ATAC-seq"){
if(input$fbam){
values$command<-sprintf("mkdir -p %s ; %s ; %s ; %s -d %s --fromBAM %s --sampleSheet %s %s ",indir,link_cmd,cp_sInfo_cmd,path_to_exec,outdir,indir,values$sInfo_in,values$genome)
} else{
values$command<-sprintf("mkdir -p %s ; %s ; %s ;%s -i %s -o %s %s ; %s -d %s --sampleSheet %s %s ",indir,link_cmd,cp_sInfo_cmd,path_to_DNA_mapping,indir,outdir,values$genome,path_to_exec,outdir,values$sInfo_in,values$genome) }
output$command<-renderText({ values$command })
}##end of ATACseq
else if(values$inWorkflow=="ChIP-seq"){
cp_chDict_cmd<-sprintf("cp -v %s %s",values$chDictDest,topdir)
values$chDictr_in<-paste0(topdir,"/",basename(values$chDictDest))
if(input$fbam){
values$command<-sprintf("mkdir -p %s ; %s ; %s ; %s ; %s -d %s --fromBAM %s --sampleSheet %s %s %s %s",indir,link_cmd,cp_sInfo_cmd,cp_chDict_cmd,path_to_exec,outdir,indir,values$sInfo_in,values$se(),values$genome,values$chDictr_in)
} else {
values$command<-sprintf("mkdir -p %s ; %s ; %s ; %s ; %s -i %s -o %s %s ; %s -d %s --sampleSheet %s %s %s %s",indir,link_cmd,cp_sInfo_cmd,cp_chDict_cmd,path_to_DNA_mapping,indir,outdir,values$genome,path_to_exec,outdir,values$sInfo_in,values$se(),values$genome,values$chDictr_in) }
output$command<-renderText({ values$command })
}##end of ChIP-seq
else if(values$inWorkflow=="HiC"){
mstr<-isolate(values$mstr())
estr<-isolate(values$estr())
values$command<-sprintf("mkdir -p %s ; %s ; %s ; %s -i %s -o %s %s %s %s",indir,link_cmd,cp_sInfo_cmd,path_to_exec,indir,outdir,estr,mstr,values$genome)
output$command<-renderText({ values$command })
}##end of HiC
else if(values$inWorkflow=="DNA-mapping"){
values$command<-sprintf("mkdir -p %s ; %s ; %s ; %s -i %s -o %s %s ",indir,link_cmd,cp_sInfo_cmd,path_to_DNA_mapping,indir,outdir,values$genome)
output$command<-renderText({ values$command })
} #end of DNA-mapping
else if(values$inWorkflow=="mRNA-seq"){
ltype<-isolate(values$ltype())
values$command<-sprintf("mkdir -p %s ; %s ; %s ; %s --mode alignment -i %s -o %s --sampleSheet %s %s %s %s %s ",indir,link_cmd,cp_sInfo_cmd,path_to_exec,indir,outdir,values$sInfo_in,fbam[input$selectformat],ltype,values$se(),values$genome)
output$command<-renderText({ values$command })
} #end of RNA-seq
else if(values$inWorkflow=="noncoding-RNA-seq"){
values$command<-sprintf("mkdir -p %s ; %s ; %s ; %s --mode alignment -i %s -o %s --sampleSheet %s %s %s %s ",indir,link_cmd,cp_sInfo_cmd,path_to_exec,indir,outdir,values$sInfo_in,fbam[input$selectformat],values$se(),values$genome)
output$command<-renderText({ values$command })
} #end of RNA-seq
else if(values$inWorkflow=="WGBS"){
values$command<-sprintf("mkdir -p %s ; %s ; %s ; %s -i %s -o %s --sampleSheet %s %s %s %s ",indir,link_cmd,cp_sInfo_cmd,path_to_exec,indir,outdir,values$sInfo_in,fbam[input$selectformat],values$se(),values$genome)
output$command<-renderText({ values$command })
} #end of WGBS
else if(values$inWorkflow=="scRNAseq"){
md<-isolate(input$sc_mode)
sc_ltype<-isolate(input$sc_ltype)
cp_csv_cmd<-ifelse(dir.exists(isolate(values$cellNameDest)),sprintf("cp -rv %s %s",isolate(values$cellNameDest),topdir),"")
cn<-ifelse(dir.exists(values$cellNameDest),sprintf("--cellNames %s",file.path(topdir,"plate_csv")),"")
if(md=="Gruen"){
lt<-"--trim --cellBarcodeFile /data/processing/bioinfo-core/celseq_barcodes.384.txt --cellBarcodePattern NNNNNNNXXXXXXX"
} else if (md=="STARsolo"){
lt<-sprintf("--myKit %s",sc_ltype)
} else if (md=="Alevin"){
lt<-sprintf("--prepRrotocol %s",sc_ltype)
}
values$command<-sprintf("mkdir -p %s ; %s ; %s ; %s ; %s -i %s -o %s %s --mode %s %s %s ",indir,link_cmd,cp_sInfo_cmd,cp_csv_cmd,path_to_exec,indir,outdir,cn,md,lt,values$genome)
output$command<-renderText({ values$command })
} #end of scRNAseq
####write command to script
bshscript<-sprintf("/data/manke/group/shiny/snakepipes_input/%s_%s_script.sh",values$ranstring,values$analysisName)
fileConn<-file(bshscript)
shebang<-"#!/bin/bash"
exports<-""
writeLines(c(shebang,exports,unlist(strsplit(isolate(values$command),split=";"))), fileConn)
close(fileConn)
###############compose email message
fbam_request<-ifelse(isolate(input$fbam),"I want to start the analysis from the bam files.","I want to start the analysis from fastq files.")
merge_request<-ifelse(isolate(input$merge),"I want to request sample merging. Please consider the information I entered in the Merge column of the sample sheet. \n Please update the sample sheet after merging files.","No sample merging is needed.")
b_eff_request<-ifelse(isolate(input$beff),"I expect batch effect in my data.","No batch effect is expected.")
nodiff_request<-ifelse(isolate(input$nodiff),"I don't need differential analysis.","I want to request differential analysis.")
SE_request<-ifelse(isolate(input$SE),"I have single end data.","I have paired end data.")
lT_request<-ifelse(isolate(input$lT),"My library type is unstranded.","My library type is stranded.")
enz_request<-ifelse(isolate(input$enz),"I used DpnII.","I used HindIII.")
notads_request<-ifelse(isolate(input$notads),"I don't need TAD calling.","I need TAD calling.")
cc<-isolate(input$sender)
#from<-sprintf("<sendmailR@%s>", Sys.info()[4])
from<-"sendmailR@ie-freiburg.mpg.de"
to<-"bioinfo-core@ie-freiburg.mpg.de"
#to<-"sikora@ie-freiburg.mpg.de"
subject<-paste0("Analysis request ",isolate(input$analysistitle), "_" ,isolate(values$ranstring))
if(values$inWorkflow %in% c("ATAC-seq","ChIP-seq","DNA-mapping","WGBS")){msg <- gsub(";","\n \n",paste0(cc," has requested the following analysis: \n \n Workflow: ", isolate(values$inWorkflow)," \n \n Genome: ", values$genome," \n \n ", fbam_request, " \n \n " ,merge_request," \n \n ", b_eff_request ," \n \n ", nodiff_request, " \n \n ", SE_request, " \n \n User comments: \n \n", isolate(input$comments),"\n \n Please review the input files and the attached sample sheet before proceeding. \n \n End of message. \n \n ",paste(rep("#",times=80),collapse="")," \n \n ", values$command ,"\n \n"))
}else if(values$inWorkflow %in% "HiC"){msg <- gsub(";","\n \n",paste0(cc," has requested the following analysis: \n \n Workflow: ", isolate(values$inWorkflow)," \n \n Genome: ", values$genome," \n \n ", merge_request," \n \n ", nodiff_request, " \n \n ",enz_request, " \n \n ",notads_request ," \n \n User comments: \n \n", isolate(input$comments),"\n \n Please review the input files and the attached sample sheet before proceeding. \n \n End of message. \n \n ",paste(rep("#",times=80),collapse="")," \n \n ", values$command ,"\n \n"))}else if (values$inWorkflow %in% c("mRNA-seq","noncoding-RNA-seq")){
msg <- gsub(";","\n \n",paste0(cc," has requested the following analysis: \n \n Workflow: ", isolate(values$inWorkflow)," \n \n Genome: ", values$genome," \n \n ", fbam_request, " \n \n " ,merge_request," \n \n ", b_eff_request ," \n \n ", nodiff_request, " \n \n ", SE_request," \n \n ", lT_request, " \n \n User comments: \n \n", isolate(input$comments),"\n \n Please review the input files and the attached sample sheet before proceeding. \n \n End of message. \n \n ",paste(rep("#",times=80),collapse="")," \n \n ", values$command ,"\n \n"))
}else if (values$inWorkflow %in% "scRNAseq"){
msg <- gsub(";","\n \n",paste0(cc," has requested the following analysis: \n \n Workflow: ", isolate(values$inWorkflow)," \n \n Genome: ", values$genome," \n \n Mode: ", md, " \n \n PrepProtocol: ", sc_ltype, " \n \n User comments: \n \n", isolate(input$comments),"\n \n Please review the input files before proceeding. \n \n End of message. \n \n ",paste(rep("#",times=80),collapse="")," \n \n ", values$command ,"\n \n"))
}
if(values$inWorkflow=="ChIP-seq"){
sendmail(from=sprintf("%s",from), to=to, subject=subject, control=list(smtpServer="owa.ie-freiburg.mpg.de"), msg=list(msg,mime_part(isolate(values$sInfoDest)),mime_part(isolate(values$chDictDest)),mime_part(bshscript)),cc=sprintf("%s",cc))
}
else{
sendmail(from=sprintf("%s",from), to=to, subject=subject, control=list(smtpServer="owa.ie-freiburg.mpg.de"), msg=list(msg,mime_part(isolate(values$sInfoDest)),mime_part(bshscript)),cc=sprintf("%s",cc))}
output$eSent<-renderText("Your request has been sent to the MPI-IE Bioinfo facility. A copy was sent to your email address.")
},ignoreInit=TRUE,once=TRUE)#end of observe input$savesubmit
###################################################################################
output$logo<-renderImage({list(src="/data/manke/sikora/shiny_apps/userIN_to_yaml/MPIIE_logo_sRGB.jpg",width=100,height=100)},deleteFile =FALSE)
output$walkthrough<-renderText({"<font size=4><ol><li>Specify workflow parameters: which kind of analysis should be performed on your data? Which reference genome should be used? Provide an optional title to your analysis.</li><li>Select input data. You can do so by providing either a combination of names and project number or by pasting the path to the folder containg your input reads. Click on Add dataset to retrieve the data. The result appears in the Input Data tab. Repeat the procedure until you have retrieved all the data you would like to jointly analyze.</li><li>Fill in the workflow-specific sample sheet. Detailed explanations will be displayed accordingly. Provide new sample names in the Merge column if you wish your reads to be merged.</li><li>Save your sample sheet. This will reset the table to default.</li><li>Fill in your email address, any comments you would like to pass to the bioinformatic facility and check any boxes might be relevant to your data.</li><li>Submit the analysis. Verify the copy of your request in your email box.</li><li>You're done! You will be contacted by the bioinfo facility as soon as your data goes through the requested pipeline.</li></ol></font>"})
output$workflow<-renderImage({list(src="/data/manke/sikora/shiny_apps/userIN_to_yaml/dev/userIN_to_yaml.workflow.png",width=800,height=600)},deleteFile=FALSE)
output$sampleInfoWarning<-renderText({"Please save sample sheet first."})
output$resultPanels<-renderUI({myTabs<-list(
tabPanel(title="Input Data",
fluidPage(tags$head(tags$style(HTML(".shiny-output-error-validation {color: green; position: relative; bottom: -300px;}"))),
box(textOutput("ispaired"),width=12,height=50,title="Read pairing detection"),
rHandsontableOutput("hot"),
box(textOutput("datawarnings"),width=4,height=300,title="Data Warnings"),
actionButton(inputId="savetable",label="Save sample sheet"),
box(textOutput("sIsaved"),width=4,height=100,title="Table status"),
box(htmlOutput("tabdesc"),width=12,title="Column description")
)
),
tabPanel(title="User information",conditionalPanel(condition= "input.savetable == 1",
fluidPage(
fluidRow(
uiOutput("from"),
uiOutput("freetext"),
uiOutput("datarequests")
),
actionButton(inputId="savesubmit",label="Save workflow configuration and submit request"),
box(textOutput("eSent"),width=4,height=100,title="Request status")
)
),
conditionalPanel(condition= "input.savetable == 0",box(textOutput("sampleInfoWarning")))),
tabPanel(title="Walkthrough",
fluidPage(
box(htmlOutput("walkthrough"),width=12),
imageOutput("workflow",inline=TRUE)
)
)
)
do.call(tabsetPanel, myTabs)
})
}
shinyApp(ui, server)