-
Notifications
You must be signed in to change notification settings - Fork 16
/
count.nf
743 lines (631 loc) · 26.3 KB
/
count.nf
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
#!/usr/bin/env nextflow
/*
========================================================================================
MPRAflow
========================================================================================
MPRA Analysis Pipeline.
Started 2019-07-29.
Count Utility
#### Homepage / Documentation
https://github.com/shendurelab/MPRAflow
#### Authors
Vikram Agarwal <[email protected]>
Gracie Gordon <[email protected]>
Martin Kircher <[email protected]>
Max Schubach <[email protected]>
----------------------------------------------------------------------------------------
*/
def helpMessage() {
log.info"""
=========================================
shendurelab/MPRAflow v${params.version}
=========================================
Usage:
The typical command for running the pipeline is as follows:
nextflow run main.nf
Mandatory arguments:
--dir Fasta directory (must be surrounded with quotes)
--e, --experiment-file Experiment csv file
Recommended (Needed for the full count workflow. Can be neglected when only counts for saturation mutagenesis are needed):
--design Fasta of ordered insert sequences.
--association Pickle dictionary from library association process.
Options:
--labels tsv with the oligo pool fasta and a group label (ex: positive_control), a single label will be applied if a file is not specified
--outdir The output directory where the results will be saved (default outs)
--bc-length Barcode length (default 15)
--umi-length UMI length (default 10)
--no-umi Use this flag if no UMI is present in the experiment (default with UMI)
--merge_intersect Only retain barcodes in RNA and DNA fraction (TRUE/FALSE, default: FALSE)
--mpranalyze Only generate MPRAnalyze outputs
--thresh minimum number of observed barcodes to retain insert (default 10)
Extras:
--h, --help Print this help message
--email Set this parameter to your e-mail address to get a summary e-mail with details of the run sent to you when the workflow exits
--name Name for the pipeline run. If not specified, Nextflow will automatically generate a random mnemonic.
""".stripIndent()
}
/*
* SET UP CONFIGURATION VARIABLES
*/
// Show help message
if (params.containsKey('h') || params.containsKey('help')){
helpMessage()
exit 0
}
// Configurable variables
params.name = false
params.email = false
params.plaintext_email = false
output_docs = file("$baseDir/docs/output.md")
//defaults
results_path = params.outdir
params.merge_intersect=false
params.mpranalyze=false
params.thresh=10
// Validate Inputs
// experiment file saved in params.experiment_file
if (params.containsKey('e')){
params.experiment_file=file(params.e)
} else if (params.containsKey("experiment-file")) {
params.experiment_file=file(params["experiment-file"])
} else {
exit 1, "Experiment file not specified with --e or --experiment-file"
}
if( !params.experiment_file.exists()) exit 1, "Experiment file ${params.experiment_file} does not exist"
// design file saved in params.design_file
if ( params.containsKey("design")){
params.design_file=file(params.design)
if( !params.design_file.exists() ) exit 1, "Design file ${params.design} does not exist"
if( !params.containsKey("association") ) exit 1, "Association file has to be specified with --association when using option --design"
} else if (params.mpranalyze) {
exit 1, "Design file has to be specified with --association when using flag --mpranalyze"
} else {
log.info("Running MPRAflow count without design file.")
}
// Association file in params.association_file
if (params.containsKey("association")){
params.association_file=file(params.association)
if( !params.association_file.exists() ) exit 1, "Association pickle ${params.association_file} does not exist"
} else if (params.mpranalyze) {
exit 1, "Association file has to be specified with --association when using flag --mpranalyze"
} else {
log.info("Running MPRAflow count without association file.")
}
// label file saved in label_file
if (params.containsKey("labels")){
label_file=file(params.labels)
if (!label_file.exists()) {
println "Label file ${label_file} does not exist. Use NA as label!"
label_file=file("NA")
}
} else {
label_file=file("NA")
}
// check if UMIs or not are present
if (params.containsKey("no-umi")){
params.no_umi = true
} else {
params.no_umi = false
}
// BC length
if (params.containsKey("bc-length")){
params.bc_length = params["bc-length"]
} else {
params.bc_length = 15
}
// UMI length
if (params.containsKey("umi-length")){
params.umi_length = params["umi-length"]
} else {
params.umi_length = 10
}
// Create FASTQ channels
if (params.no_umi) {
reads_noUMI = Channel.fromPath(params.experiment_file).splitCsv(header: true).flatMap{
row -> [
tuple(row.Condition,row.Replicate,"DNA",
[row.Condition,row.Replicate,"DNA"].join("_"),
file([params.dir,"/",row.DNA_BC_F].join()),
file([params.dir,"/",row.DNA_BC_R].join())
),
tuple(row.Condition,row.Replicate,"RNA",
[row.Condition,row.Replicate,"RNA"].join("_"),
file([params.dir,"/",row.RNA_BC_F].join()),
file([params.dir,"/",row.RNA_BC_R].join())
)
]
}
} else {
reads = Channel.fromPath(params.experiment_file).splitCsv(header: true).flatMap{
row -> [
tuple(row.Condition, row.Replicate, "DNA",
[row.Condition,row.Replicate,"DNA"].join("_"),
file([params.dir,"/",row.DNA_BC_F].join()),
file([params.dir,"/",row.DNA_UMI].join()),
file([params.dir,"/",row.DNA_BC_R].join()),
),
tuple(row.Condition, row.Replicate, "RNA",
[row.Condition,row.Replicate,"RNA"].join("_"),
file([params.dir,"/",row.RNA_BC_F].join()),
file([params.dir,"/",row.RNA_UMI].join()),
file([params.dir,"/",row.RNA_BC_R].join()),
),
]
}
}
// Has the run name been specified by the user?
// this has the bonus effect of catching both -name and --name
custom_runName = params.name
if( !(workflow.runName ==~ /[a-z]+_[a-z]+/) ){
custom_runName = workflow.runName
}
// Header log info
log.info """=======================================================
,--./,-.
___ __ __ __ ___ /,-._.--~\'
|\\ | |__ __ / ` / \\ |__) |__ } {
| \\| | \\__, \\__/ | \\ |___ \\`-._,-`-,
`._,._,\'
MPRAflow v${params.version}"
======================================================="""
def summary = [:]
summary['Pipeline Name'] = 'shendurelab/MPRAflow'
summary['Pipeline Version'] = params.version
summary['Run Name'] = custom_runName ?: workflow.runName
//summary['Thread fqdump'] = params.threadfqdump ? 'YES' : 'NO'
summary['Output dir'] = params.outdir
summary['Working dir'] = workflow.workDir
//summary['Container Engine'] = workflow.containerEngine
//if(workflow.containerEngine) summary['Container'] = workflow.container
summary['Current home'] = "$HOME"
summary['Current user'] = "$USER"
summary['Current path'] = "$PWD"
summary['Working dir'] = workflow.workDir
summary['Output dir'] = params.outdir
summary['Script dir'] = workflow.projectDir
summary['Config Profile'] = workflow.profile
summary['Experiment File'] = params.experiment_file
summary['reads'] = (params.no_umi ? reads_noUMI : reads)
summary['UMIs'] = (params.no_umi ? "Reads without UMI" : "Reads with UMI")
summary['BC length'] = params.bc_length
summary['BC threshold'] = params.thresh
summary['mprAnalyze'] = params.mpranalyze
if(params.email) summary['E-mail Address'] = params.email
log.info summary.collect { k,v -> "${k.padRight(15)}: $v" }.join("\n")
log.info "========================================="
// Check that Nextflow version is up to date enough
// try / throw / catch works for NF versions < 0.25 when this was implemented
try {
if( ! nextflow.version.matches(">= $params.nf_required_version") ){
throw GroovyException('Nextflow version too old')
}
} catch (all) {
log.error "====================================================\n" +
" Nextflow version $params.nf_required_version required! You are running v$workflow.nextflow.version.\n" +
" Pipeline execution will continue, but things may break.\n" +
" Please run `nextflow self-update` to update Nextflow.\n" +
"============================================================"
}
println 'start analysis'
/*
* STEP 1: Create BAM files
* contributions: Martin Kircher, Max Schubach, & Gracie Gordon
*/
//if UMI
if (!params.no_umi) {
process 'create_BAM' {
tag "make idx"
label 'longtime'
conda 'conf/mpraflow_py27.yml'
input:
tuple val(cond), val(rep), val(type), val(datasetID), file(fw_fastq), file(umi_fastq), file(rev_fastq) from reads
val(bc_length) from params.bc_length
output:
tuple val(cond), val(rep), val(type),val(datasetID),file("${datasetID}.bam") into clean_bam
shell:
"""
#!/bin/bash
echo $datasetID
echo $fw_fastq
echo $umi_fastq
echo $rev_fastq
umi_length=`zcat $umi_fastq | head -2 | tail -1 | wc -c`
umi_length=\$(expr \$((\$umi_length-1)))
fwd_length=`zcat $fw_fastq | head -2 | tail -1 | wc -c`
fwd_length=\$(expr \$((\$fwd_length-1)))
rev_start=\$(expr \$((\$fwd_length+1)))
rev_length=`zcat $rev_fastq | head -2 | tail -1 | wc -c`
rev_length=\$(expr \$((\$rev_length-1)))
minoverlap=`echo \${fwd_length} \${fwd_length} $bc_length | awk '{print (\$1+\$2-\$3-1 < 11) ? \$1+\$2-\$3-1 : 11}'`
echo \$rev_start
echo \$umi_length
echo \$minoverlap
paste <( zcat $fw_fastq ) <( zcat $rev_fastq ) <( zcat $umi_fastq ) | awk '{if (NR % 4 == 2 || NR % 4 == 0) {print \$1\$2\$3} else {print \$1}}' | python ${"$baseDir"}/src/FastQ2doubleIndexBAM.py -p -s \$rev_start -l 0 -m \$umi_length --RG ${datasetID} | python ${"$baseDir"}/src/MergeTrimReadsBAM.py --FirstReadChimeraFilter '' --adapterFirstRead '' --adapterSecondRead '' -p --mergeoverlap --minoverlap \$minoverlap > ${datasetID}.bam
"""
}
}
//if no UMI
/*
* contributions: Martin Kircher, Max Schubach, & Gracie Gordon
*/
if (params.no_umi) {
process 'create_BAM_noUMI' {
tag "make idx"
label 'longtime'
conda 'conf/mpraflow_py27.yml'
input:
tuple val(cond), val(rep),val(type),val(datasetID),file(fw_fastq), file(rev_fastq) from reads_noUMI
val(bc_length) from params.bc_length
output:
tuple val(cond), val(rep),val(type),val(datasetID),file("${datasetID}.bam") into clean_bam
when:
params.no_umi
shell:
"""
#!/bin/bash
echo $datasetID
echo $fw_fastq
echo $rev_fastq
fwd_length=`zcat $fw_fastq | head -2 | tail -1 | wc -c`
fwd_length=\$(expr \$((\$fwd_length-1)))
rev_start=\$(expr \$((\$fwd_length+1)))
rev_length=`zcat $rev_fastq | head -2 | tail -1 | wc -c`
rev_length=\$(expr \$((\$rev_length-1)))
minoverlap=`echo \${fwd_length} \${fwd_length} $bc_length | awk '{print (\$1+\$2-\$3-1 < 11) ? \$1+\$2-\$3-1 : 11}'`
echo \$rev_start
echo \$minoverlap
paste <( zcat $fw_fastq ) <(zcat $rev_fastq ) | \
awk '{
if (NR % 4 == 2 || NR % 4 == 0) {
print \$1\$2
} else {
print \$1
}}' | python ${"$baseDir"}/src/FastQ2doubleIndexBAM.py -p -s \$rev_start -l 0 -m 0 --RG ${datasetID} | python ${"$baseDir"}/src/MergeTrimReadsBAM.py --FirstReadChimeraFilter '' --adapterFirstRead '' --adapterSecondRead '' -p --mergeoverlap --minoverlap \$minoverlap> ${datasetID}.bam
"""
}
}
/*
* STEP 2: create raw counts
* contributions: Martin Kircher, Max Schubach, & Gracie Gordon
*/
process 'raw_counts'{
label 'shorttime'
conda 'conf/mpraflow_py36.yml'
publishDir "$params.outdir/$cond/$rep"
input:
tuple val(cond), val(rep),val(type),val(datasetID),file(bam) from clean_bam
val(umi_length) from params.umi_length
output:
tuple val(cond), val(rep),val(type),val(datasetID),file("${datasetID}_raw_counts.tsv.gz") into raw_ct
script:
if(params.no_umi)
"""
#!/bin/bash
samtools view -F 1 -r $datasetID $bam | \
awk '{print \$10}' | \
sort | \
gzip -c > ${datasetID}_raw_counts.tsv.gz
"""
else
"""
#!/bin/bash
samtools view -F 1 -r $datasetID $bam | \
awk -v 'OFS=\\t' '{ for (i=12; i<=NF; i++) {
if (\$i ~ /^XJ:Z:/) print \$10,substr(\$i,6,$umi_length)
}}' | \
sort | uniq -c | \
awk -v 'OFS=\\t' '{ print \$2,\$3,\$1 }' | \
gzip -c > ${datasetID}_raw_counts.tsv.gz
"""
}
/*
* STEP 3: Filter counts for correct barcode length
* contributions: Martin Kircher, Max Schubach, & Gracie Gordon
*/
process 'filter_counts'{
label 'shorttime'
publishDir "$params.outdir/$cond/$rep"
conda 'conf/mpraflow_py27.yml'
input:
tuple val(cond), val(rep),val(type),val(datasetID),file(rc) from raw_ct
val(bcLength) from params.bc_length
output:
tuple val(cond), val(rep),val(type),val(datasetID),file("${datasetID}_filtered_counts.tsv.gz") into filter_ct
shell:
"""
bc=$bcLength
echo \$bc
zcat $rc | grep -v "N" | \
awk -v var="\$bc" -v 'OFS=\t' '{ if (length(\$1) == var) { print } }' | \
gzip -c > ${datasetID}_filtered_counts.tsv.gz
"""
}
/*
* STEP 4: Record overrepresended UMIs and final count table
* contributions: Martin Kircher, Max Schubach, & Gracie Gordon
*/
process 'final_counts'{
label 'shorttime'
publishDir "$params.outdir/$cond/$rep"
input:
tuple val(cond), val(rep),val(type),val(datasetID),file(fc) from filter_ct
output:
tuple val(cond), val(rep),val(type),val(datasetID),file("${datasetID}_counts.tsv") into final_count, final_count_satMut
script:
if(params.no_umi)
"""
#!/bin/bash
zcat $fc | awk '{print \$1}' | \
uniq -c > ${datasetID}_counts.tsv
"""
else
"""
#!/bin/bash
for i in $fc; do
echo \$(basename \$i);
zcat \$i | cut -f 2 | sort | uniq -c | sort -nr | head;
echo;
done > ${params.outdir}/${cond}/${rep}/${datasetID}_freqUMIs.txt
zcat $fc | awk '{print \$1}' | uniq -c > ${datasetID}_counts.tsv
"""
}
/*
* STEP 5: MPRAnalyze input generation (if option selected)
* contributions: Gracie Gordon
*/
process 'dna_rna_merge_counts'{
publishDir "$params.outdir/$cond/$rep", mode:'copy'
label 'shorttime'
conda 'conf/mpraflow_py36.yml'
input:
tuple val(cond),val(rep),val(typeA),val(typeB),val(datasetIDA),val(datasetIDB),file(countA),file(countB) from final_count_satMut.groupTuple(by: [0,1]).map{i -> i.flatten()}
output:
tuple val(cond), val(rep), file("${cond}_${rep}_counts.tsv.gz") into merged_dna_rna
script:
def dna = typeA == 'DNA' ? countA : countB
def rna = typeA == 'DNA' ? countB : countA
"""
join -1 1 -2 1 -t"\$(echo -e '\\t')" \
<( cat $dna | awk 'BEGIN{ OFS="\\t" }{ print \$2,\$1 }' | sort ) \
<( cat $rna | awk 'BEGIN{ OFS="\\t" }{ print \$2, \$1 }' | sort) | \
gzip -c > ${cond}_${rep}_counts.tsv.gz
"""
}
//MPRAnalyze option
//contributions: Gracie Gordon
if(params.mpranalyze){
/*
* STEP 5: Merge each DNA and RNA file
*/
process 'dna_rna_mpranalyze_merge'{
publishDir "$params.outdir/$cond/$rep", mode:'copy'
label 'longtime'
conda 'conf/mpraflow_py36.yml'
input:
tuple val(cond),val(rep),val(typeA),val(typeB),val(datasetIDA),val(datasetIDB),file(countA),file(countB) from final_count.groupTuple(by: [0,1]).map{i -> i.flatten()}
output:
tuple val(cond), val(rep), file("${cond}_${rep}_counts.csv") into merged_ch
shell:
"""
python ${"$baseDir"}/src/merge_counts.py ${typeA} ${countA} ${countB} ${cond}_${rep}_counts.csv
"""
}
/*
* STEP 6: Merge all DNA/RNA counts into one big file
* contributions: Gracie Gordon
*/
process 'final_merge'{
label 'longtime'
publishDir "$params.outdir/$cond", mode:'copy'
conda 'conf/mpraflow_py36.yml'
result = merged_ch.groupTuple(by: 0).multiMap{i ->
cond: i[0]
replicate: i[1]
files: i[2]
}
input:
file(pairlistFiles) from result.files
val(replicate) from result.replicate
val(cond) from result.cond
output:
tuple val(cond),file("${cond}_count.csv") into merged_out
script:
inputs = [["--counts"]*replicate.size(),replicate,pairlistFiles.collect{"$it"}].transpose().flatten().join(' ')
shell:
"""
export LC_ALL=en_US.utf-8
export LANG=en_US.utf-8
python ${"$baseDir"}/src/merge_all.py --condition $cond --output "${cond}_count.csv" $inputs
"""
}
/*
* STEP 7: Add label to outfile
* contributions: Gracie Gordon
*/
process 'final_label'{
label 'shorttime'
publishDir "$params.outdir/$cond", mode:'copy'
conda 'conf/mpraflow_py36.yml'
input:
tuple val(cond), file(table) from merged_out
file(des) from params.design_file
file(association) from params.association_file
output:
tuple val(cond), file("${cond}_final_labeled_counts.txt") into labeled_out
shell:
"""
python ${"$baseDir"}/src/label_final_count_mat.py $table $association "${cond}_final_labeled_counts.txt" $des
"""
}
/*
* STEP 8: Generate inputs
* contributions: Tal Ashuach
*/
process 'generate_mpranalyze_inputs'{
label 'shorttime'
publishDir "$params.outdir/$cond", mode:'copy'
conda 'conf/mpraflow_py36.yml'
input:
tuple val(cond),file(labeled_file) from labeled_out
output:
file("rna_counts.tsv") into mpranalyze_rna_counts
file("dna_counts.tsv") into mpranalyze_dna_counts
file("rna_annot.tsv") into mpranalyze_rna_annotation
file("dna_annot.tsv") into mpranalyze_fna_annotation
shell:
"""
python ${"$baseDir"}/src/mpranalyze_compiler.py $labeled_file
"""
}
}
/*
* STEP 5: Merge each DNA and RNA file label with sequence and insert and normalize
* contributions: Gracie Gordon
*/
//merge and normalize
if(!params.mpranalyze && params.containsKey("association")){
process 'dna_rna_merge'{
label 'longtime'
publishDir "$params.outdir/$cond/$rep", mode:'copy'
conda 'conf/mpraflow_py36.yml'
input:
tuple val(cond), val(rep),val(typeA),val(typeB),val(datasetIDA),val(datasetIDB),file(countA),file(countB) from final_count.groupTuple(by: [0,1]).map{i -> i.flatten()}
file(des) from params.design_file
file(association) from params.association_file
val(bc_length) from params.bc_length
output:
tuple val(cond), val(rep), file("${cond}_${rep}_counts.tsv") into merged_ch, merged_ch2
shell:
"""
python ${"$baseDir"}/src/merge_label.py --control-type ${typeA} --control ${countA} --experiment ${countB} \
--coord $association --design $des \
--merge-intersect ${params.merge_intersect} --bc-length ${bc_length} \
--output ${cond}_${rep}_counts.tsv
"""
}
/*
* STEP 6: Calculate correlations between Replicates
* contributions: Vikram Agarwal & Gracie Gordon
*/
process 'calc_correlations'{
label 'shorttime'
publishDir "$params.outdir/$cond", mode:'copy'
conda 'conf/mpraflow_r.yml'
result = merged_ch.groupTuple(by: 0).multiMap{i ->
cond: i[0]
replicate: i[1].join(" ")
files: i[2]
}
input:
file(pairlistFiles) from result.files
val(replicate) from result.replicate
val(cond) from result.cond
file(lab) from label_file
output:
file "*.png"
file "*_correlation.txt"
script:
pairlist = pairlistFiles.collect{"$it"}.join(' ')
def label = lab.exists() ? lab : lab.name
"""
Rscript ${"$baseDir"}/src/plot_perInsertCounts_correlation.R $cond $label $params.thresh $pairlist $replicate
"""
}
/*
* contributions: Vikram Agarwal & Gracie Gordon
*/
process 'make_master_tables' {
label 'shorttime'
publishDir "$params.outdir/$cond", mode:'copy'
conda 'conf/mpraflow_r.yml'
result = merged_ch2.groupTuple(by: 0).multiMap{i ->
cond: i[0]
replicate: i[1].join(" ")
files: i[2]
}
input:
file(pairlistFiles) from result.files
val(replicate) from result.replicate
val(cond) from result.cond
output:
file "average_allreps.tsv"
file "allreps.tsv"
script:
pairlist = pairlistFiles.collect{"$it"}.join(' ')
shell:
"""
Rscript ${"$baseDir"}/src/make_master_tables.R $cond $params.thresh allreps.tsv average_allreps.tsv $pairlist $replicate
"""
}
}
/*
* Completion e-mail notification
*/
/*
workflow.onComplete {
// Set up the e-mail variables
def subject = "[NCBI-Hackathons/ATACFlow] Successful: $workflow.runName"
if(!workflow.success){
subject = "[NCBI-Hackathons/ATACFlow] FAILED: $workflow.runName"
}
def email_fields = [:]
email_fields['version'] = params.version
email_fields['runName'] = custom_runName ?: workflow.runName
email_fields['success'] = workflow.success
email_fields['dateComplete'] = workflow.complete
email_fields['duration'] = workflow.duration
email_fields['exitStatus'] = workflow.exitStatus
email_fields['errorMessage'] = (workflow.errorMessage ?: 'None')
email_fields['errorReport'] = (workflow.errorReport ?: 'None')
email_fields['commandLine'] = workflow.commandLine
email_fields['projectDir'] = workflow.projectDir
email_fields['summary'] = summary
email_fields['summary']['Date Started'] = workflow.start
email_fields['summary']['Date Completed'] = workflow.complete
email_fields['summary']['Pipeline script file path'] = workflow.scriptFile
email_fields['summary']['Pipeline script hash ID'] = workflow.scriptId
if(workflow.repository) email_fields['summary']['Pipeline repository Git URL'] = workflow.repository
if(workflow.commitId) email_fields['summary']['Pipeline repository Git Commit'] = workflow.commitId
if(workflow.revision) email_fields['summary']['Pipeline Git branch/tag'] = workflow.revision
email_fields['summary']['Nextflow Version'] = workflow.nextflow.version
email_fields['summary']['Nextflow Build'] = workflow.nextflow.build
email_fields['summary']['Nextflow Compile Timestamp'] = workflow.nextflow.timestamp
// Render the TXT template
def engine = new groovy.text.GStringTemplateEngine()
def tf = new File("$baseDir/assets/email_template.txt")
def txt_template = engine.createTemplate(tf).make(email_fields)
def email_txt = txt_template.toString()
// Render the HTML template
def hf = new File("$baseDir/assets/email_template.html")
def html_template = engine.createTemplate(hf).make(email_fields)
def email_html = html_template.toString()
// Render the sendmail template
def smail_fields = [ email: params.email, subject: subject, email_txt: email_txt, email_html: email_html, baseDir: "$baseDir", attach1: "$baseDir/results/Documentation/pipeline_report.html", attach2: "$baseDir/results/pipeline_info/NCBI-Hackathons/ATACFlow_report.html", attach3: "$baseDir/results/pipeline_info/NCBI-Hackathons/ATACFlow_timeline.html" ]
def sf = new File("$baseDir/assets/sendmail_template.txt")
def sendmail_template = engine.createTemplate(sf).make(smail_fields)
def sendmail_html = sendmail_template.toString()
// Send the HTML e-mail
if (params.email) {
try {
if( params.plaintext_email ){ throw GroovyException('Send plaintext e-mail, not HTML') }
// Try to send HTML e-mail using sendmail
[ 'sendmail', '-t' ].execute() << sendmail_html
log.info "[NCBI-Hackathons/ATACFlow] Sent summary e-mail to $params.email (sendmail)"
} catch (all) {
// Catch failures and try with plaintext
[ 'mail', '-s', subject, params.email ].execute() << email_txt
log.info "[NCBI-Hackathons/ATACFlow] Sent summary e-mail to $params.email (mail)"
}
}
// Write summary e-mail HTML to a file
def output_d = new File( "${params.outdir}/Documentation/" )
if( !output_d.exists() ) {
output_d.mkdirs()
}
def output_hf = new File( output_d, "pipeline_report.html" )
output_hf.withWriter { w -> w << email_html }
def output_tf = new File( output_d, "pipeline_report.txt" )
output_tf.withWriter { w -> w << email_txt }
log.info "[NCBI-Hackathons/ATACFlow] Pipeline Complete"
}
*/