-
Notifications
You must be signed in to change notification settings - Fork 0
/
epiPipe_dev.nf
1010 lines (816 loc) · 21.2 KB
/
epiPipe_dev.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
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env nextflow
params.outDir = false
params.biosample = false
params.genewizMap = false
params.fastqDir = false
params.libraryID = false
params.genome = 'hg38'
params.resolutions = false
params.ABresolutions = false
params.HiChIP = false
params.help = false
params.mapQ = 40
params.capture = false
params.hichip = false
params.copyFastq = false
params.config = 'default'
params.chicago-res = "5,10,20"
params.baits = 'hs_pc_1'
def helpMessage() {
log.info"""
Usage:
The typical command for running the pipeline is as follows:
epiPipe --biosample bisample1,biosample2,biosample3 --outDir ~/ebs/ref_push/prodEpi/myExpName
or
epiPipe --fastqDir ~/ebs/ref_push/prodEpi/myExpName/fastqs/ --outDir ~/ebs/ref_push/prodEpi/myExpName
Mandatory arguments:
--outDir [pathOfDir] Path of where to publish the data, can be local or an S3 accessible bucket
Input (minimum one of these, can be mixed):
--biosample [str] Comma seperated list of BaseSpace biosamples.
--fastqDir [str] Path to a directoy of fastq files.
--genewizMap [str] CSV file descrbibing the LIMS id to S3 path on GeneWiz bucket. Field: LIMS_ID,LIBRAY_ID,S3_path_R1,S3_path_R2
Restriting to a set of library:
--libraryID [str] Comma seperated list of library prefixes. Need to be used in conjunction with --fastqDir.
Copying file from genewiz bucke to outDir
--copyFastq [bool] Move a copy of the fastq files to the outDir. Default false.
Basespce token and host:
--config [config] if using a basespce config file different from ~/.basename/default.cfg pass ~/.basespace/<config>.cfg
Arrowhead parameters:
--resolutions [integers] Comma-seperated list of resolutions in kb for loops finding. Default: [5,10]
--ABresolutions [integers] Comma-seperated list of resolutions in kb. Default: [32,64,128]
Alignment:
--genome [str] Name of the genome to use. Possible choice: hg38, hg19, mm10, dm3. Default: hg38.
--mapQ [int] Quqlity score to filter reads. Integer between 0 and 60. Default: 40.
Sub-Steps:
--capture Runs only steps required for HiC capture. Will not permoform AB, TAD and loop calls.
--hichip Runs only steps required for HiChIP. Will not permoform AB, TAD and loop calls.
Chicago parameters:
--baits Capture panel used. Possible choise: pc-hs-1, pc-mm-1. Default: pc-hs-1.
--chicago-res [integers] Comma-seperated list of resolutions for computing genomic bins. Default: [5,10,20]
""".stripIndent()
}
if (params.help){
helpMessage()
exit 0
}
if ( !(params.biosample || params.fastqDir || params.genewizMap) ){
exit 1, "You need to use either --biosample aBaseSpace-biosample or --fastqDir path/to/bam/files or --genewizMap mappingFiles.csv. Use --help to get the full usage."
}
if ( !(params.outDir) ){
exit 1, "--outDir is a required arguments. Use --help to get the full usage."
}
if (params.resolutions){
resolutions = params.resolutions.split(/,/,-1)
} else {
resolutions = [5,10]
}
if (params.ABresolutions){
ABresolutions = params.ABresolutions.toString().split(/,/,-1)
} else {
ABresolutions = [32,64,128]
}
if (!params.genome =~ /hg19|hg38|mm10|dm3/){
exit 1, "Only hg38, mm10 and dm3 genomes are currently offered"
} else {
Channel
.fromFilePairs("${HOME}/ebs/genome/nextflow/${params.genome}/*.{amb,sa,pac,ann,bwt,fa}", size: -1, checkIfExists: true)
.ifEmpty { exit 1, "BWA index not found: ${params.genome}" }
.set { bwa_index }
Channel
.fromPath("${HOME}/ebs/genome/nextflow/${params.genome}/${params.genome}.fa", checkIfExists: true)
.ifEmpty { exit 1, "Genome not found: ${params.genome}" }
.set { abcomp_genome_ch }
}
if (params.biosample){
Channel
.from(params.biosample)
.splitCsv()
.flatten()
.set { biosample_ch }
} else {
Channel
.empty()
.into { biosample_ch;fastqs_ch }
}
if (params.fastqDir){
if (params.libraryID){
Channel
.from(params.libraryID)
.splitCsv()
.flatten()
.map {id -> file("${params.fastqDir}/${id}_*R1*.fastq.gz")}
.flatten()
.map {R1 ->
def m = R1.name.toString() =~ /(.+)_R1/
def id = m[0][1]
def R2 = file("${params.fastqDir}/${id}*_R2*.fastq.gz")
if (R2.size() > 1) {
return( "R2 has more than one entry")
} else {
return(tuple(id, R1, R2[0]) )
}
}
.set{fastqDir_ch}
} else {
Channel
.fromFilePairs("${params.fastqDir}/*_{R1,R2}*.fastq.gz",
chekIfExists: true,
flat: true)
.set{fastqDir_ch}
}
} else {
if (params.libraryID){
exit 1, "--libraryID needs to be used in conjuction with --fastqDir. Use --help to get details"
} else {
Channel
.empty()
.set{fastqDir_ch}
}
}
if (params.genewizMap) {
def i = 0
Channel
.fromPath(params.genewizMap)
.splitCsv()
.map{row ->
i=i+1
tuple(row[0]+"-rep"+i,file(row[2]),file(row[3]))
}
.into{keyMapping_ch;genewiz_ch;genewiz_ch2}
process copy_mapping {
cpus 1
memory "2 GB"
container 'mblanche/basespace-cli'
publishDir "${params.outDir}",
mode: 'copy'
input:
val mapping from keyMapping_ch
.map { l = [it[0],it[1].toString(),it[2].toString()]
l.join(",")
}
.flatten()
.collect()
output:
path ("*.csv") into outMapping
script:
"""
echo "id,R1_fastq,R2_fastq" > keyMapping.csv
for l in ${mapping}; do
echo \${l::-1} >> keyMapping.csv
done
"""
}
process copy_manifest {
cpus 1
memory "2 GB"
container 'mblanche/basespace-cli'
publishDir "${params.outDir}",
mode: 'copy'
input:
path manifest from Channel.fromPath(params.genewizMap)
output:
path manifest into outManifest
script:
"""
cat ${manifest}
"""
}
if (params.copyFastq) {
process cp_fq {
cpus 16
memory "4 GB"
container 'mblanche/basespace-cli'
publishDir "${params.outDir}/fastqs",
mode: 'copy'
input:
tuple id, path(R1s), path(R2s) from genewiz_ch2
output:
tuple id, path(R1s), path(R2s) into outFqCp
script:
"""
echo "copy ${R1s} and ${R2s}"
"""
}
}
}else{
Channel
.empty()
.set{genewiz_ch}
}
if (params.biosample){
/////
// Get BS tokent from config file
////
/// TODO: Add some logic if things are not working
bsConfig = file("${HOME}/.basespace/${params.config}.cfg", checkIfExists:true)
for ( line : bsConfig.readLines() ) {
if (m = line =~ /apiServer.+=(.+)/) {
host = m[0][1].replaceAll(' ','')
} else if ( m = line =~ /accessToken.+=(.+)/){
token = m [0][1].replaceAll(' ','')
}
}
process get_bs_files {
cpus 1
memory '1G'
container 'mblanche/basespace-cli'
input:
val bs from biosample_ch
output:
stdout into bs_id_ch
script:
"""
findNewestBS.sh ${bs} ${token} ${host}
"""
}
process download_bs {
echo true
label "movers"
cpus 4
memory '4G'
container 'mblanche/basespace-cli'
queue 'moversQ'
publishDir "${params.outDir}/fastqs",
mode: 'copy'
input:
tuple id, val(bs) from bs_id_ch
.splitCsv(header: false)
output:
tuple bs, path("*.fastq.gz") into fastqs_ch
script:
"""
bs file download --api-server ${host} --access-token ${token} -i ${id} -o .
"""
}
}
process bwa_mem {
tag "_${id}"
cpus 62
memory '96 GB'
container 'mblanche/bwa-samtools'
input:
tuple id, path(R1s), path(R2s) from fastqs_ch
.map{bs,file ->
pref = file.name.toString().take(file.name.toString().indexOf('_R'))
return(tuple(pref,file))
}
.groupTuple()
.flatten()
.collate(3)
.mix(fastqDir_ch)
.mix(genewiz_ch)
tuple index, path(index_files) from bwa_index.first() //This is an hack to make sure all files are in staged area
output:
tuple id, path("*.bam"), path("*.tsv") into pairtools_parse_ch
script:
"""
bwa mem -5SP -t ${task.cpus} \
${index} \
<(zcat ${R1s}) \
<(zcat ${R2s}) \
|samtools view -@ ${task.cpus} -Shb -o ${id}.bam - \
&& samtools view -H ${id}.bam | \
awk -v OFS='\t' '/^@SQ/ && !(\$2 ~ /:(chr|"")M/) {split(\$2,chr,":");split(\$3,ln,":");print chr[2],ln[2]}' | \
sort -V -k1,1 \
> chr_size.tsv
"""
}
process pairtools_parse {
tag "_${id}"
cpus 14
memory '50 GB'
container 'mblanche/pairtools'
input:
tuple id, path(sam), path(chr_sizes) from pairtools_parse_ch
output:
tuple id, path("*.pairsam.gz") into pairsam_part_ch
script:
"""
pairtools parse \
--min-mapq ${params.mapQ} \
--walks-policy 5unique \
--max-inter-align-gap 30 \
--nproc-in ${task.cpus} --nproc-out ${task.cpus} \
--chroms-path ${chr_sizes} \
--output ${id}.pairsam.gz \
${sam}
"""
}
process pairtools_merge_lane {
tag "_${id}"
cpus 14
memory '50 GB'
container 'mblanche/pairtools'
input:
tuple id, path(sam) from pairsam_part_ch
.map {id, file ->
def key = id.tokenize('_').get(0)
return tuple(key, file)
}
.groupTuple()
output:
tuple id, path("*.pairsam.gz") into pairsam_ch
script:
if (sam.sort().size() >1) {
"""
pairtools merge -o ${id}.pairsam.gz --nproc ${task.cpus} ${sam}
"""
} else {
"""
ln -sf ${sam} ${id}_ML.pairsam.gz
"""
}
}
process pairtools_sort {
tag "_${id}"
cpus 14
memory '100 GB'
container 'mblanche/pairtools'
input:
tuple id, path(sam) from pairsam_ch
output:
tuple id, path("*_sorted.pairsam.gz") into sorted_ps_ch
script:
"""
mkdir -p tmp
pairtools sort --tmpdir ./tmp \
--nproc ${task.cpus} \
--output ${id}_sorted.pairsam.gz \
$sam
"""
}
process pairtools_dedup {
tag "_${id}"
cpus 14
memory '40 GB'
container 'mblanche/pairtools'
publishDir "${params.outDir}/pairtools_stat",
mode: 'copy',
saveAs: {filename -> filename.endsWith('.stats') ? filename : null}
input:
tuple id, path(sam) from sorted_ps_ch
output:
tuple id, path("*_dedup.pairsam.gz") into dedup_ps_ch
tuple id, path("*_unmapped.pairsam.gz") into unmapped_ps_ch
tuple id, path("*_pairtools.stats") into ps_stats_ch
script:
"""
pairtools dedup --nproc-in ${task.cpus} --nproc-out ${task.cpus} \
--mark-dups \
--output-stats ${id}_pairtools.stats \
--output ${id}_dedup.pairsam.gz \
--output-unmapped ${id}_unmapped.pairsam.gz \
${sam}
"""
}
process pairtools_stats_merge {
tag "_${id}"
cpus 1
memory '4 GB'
container 'mblanche/pt-stats'
publishDir "${params.outDir}",
mode: 'copy'
input:
path(stats) from ps_stats_ch
.map{it[1]}
.collect()
output:
path('pairtoolsStats.csv') into merged_stats_ch
script:
"""
pairtoolsStat.sh ${stats} > pairtoolsStats.csv
"""
}
process pairtools_split_dedup {
tag "_${id}"
cpus 14
memory '40 GB'
container 'mblanche/pairtools'
input:
tuple id, path(sam) from dedup_ps_ch
output:
tuple id, path("*.bam") into bam_parts_ch
tuple id, path("*.valid.pairs.gz") into pairs_parts_ch, pairs_parts_ch_test
script:
"""
pairtools split --nproc-in ${task.cpus} --nproc-out ${task.cpus} \
--output-sam ${id}_PT.bam \
--output-pairs ${id}_PT.valid.pairs.gz \
${sam}
"""
}
process merge_bam {
tag "_${id}"
cpus 48
memory '100 GB'
container 'mblanche/bwa-samtools'
input:
tuple id, path(bam_part) from bam_parts_ch
.map {id, file ->
if ( id.contains("-rep") ){
def key = id.replaceFirst(/(.*)-rep.*/,'$1')
return tuple(key, file)
} else {
return( tuple(id,file) )
}
}
.groupTuple()
output:
tuple id, path("*.bam") into merged_bam_sort_ch
script:
bam_files = bam_part.sort()
if (bam_files.size() >1) {
"""
samtools merge -@ ${task.cpus} ${id}_MB.bam ${bam_part}
"""
} else {
"""
ln -s ${bam_part} ${id}_MB.bam
"""
}
}
process bam_sort {
tag "bam_sort_${id}"
cpus 48
memory '150 GB'
container 'mblanche/bwa-samtools'
publishDir "${params.outDir}/bam",
mode: 'copy',
pattern: "${id}.bam"
input:
tuple id, path(bam) from merged_bam_sort_ch
output:
tuple id, path("${id}.bam"),path("${id}.bam.bai") into bam_bigwig_ch, bam_chicago_ch
script:
"""
samtools sort -m 2G \
-@ ${task.cpus} \
-o ${id}.bam \
${bam}
samtools index -@${task.cpus} ${id}.bam
"""
}
process pairtools_split_unmapped {
tag "_${id}"
cpus 14
memory '40 GB'
container 'mblanche/pairtools'
publishDir "${params.outDir}/unmapped",
mode: 'copy'
input:
tuple id, path(sam) from unmapped_ps_ch
output:
path "*_unmapped.bam" into unmapped_bam_ch
path "*_unmapped.valid.pairs.gz" into unmapped_pairs_ch
script:
"""
pairtools split --nproc-in ${task.cpus} --nproc-out ${task.cpus} \
--output-sam ${id}_unmapped.bam \
--output-pairs ${id}_unmapped.valid.pairs.gz \
${sam}
"""
}
process merge_pairs {
tag "_${id}"
cpus 14
memory '40 GB'
container 'mblanche/pairtools'
publishDir "${params.outDir}/validPairs",
mode: 'copy'
input:
tuple val(id), path(pairs) from pairs_parts_ch
.map {id, file ->
if ( id.contains("-rep") ){
def key = id.replaceFirst(/(.*)-rep.*/,'$1')
return tuple(key, file)
} else {
return( tuple(id,file) )
}
}
.groupTuple()
output:
tuple id, path("*.valid.pairs.gz"), path("*.px2") into pairs_chrSize_ch
script:
pair_files = pairs.sort()
if (pair_files.size() >1) {
"""
pairtools merge -o ${id}.valid.pairs.gz --nproc ${task.cpus} ${pairs}
pairix ${id}.valid.pairs.gz
"""
} else {
"""
ln -s ${pairs} ${id}.valid.pairs.gz
pairix ${id}.valid.pairs.gz
"""
}
}
process chr_size {
tag "_${id}"
cpus 4
memory '24 GB'
container 'mblanche/pairtools'
input:
tuple id, path(pairs), path(idx) from pairs_chrSize_ch
output:
tuple id, path(pairs), path(idx), path("*.tsv") into pairs_ch_cooler, pairs_ch_juicer
script:
"""
pairix -H -f ${pairs} \
| awk -v OFS='\t' '/^#chromsize/ {print \$2,\$3}' \
| sort -V -k1,1 \
> chr_size.tsv
"""
}
process cooler_cload {
tag "_${id}"
cpus 48
memory '100 GB'
container 'mblanche/cooler'
input:
tuple id, path(pairs), path(idx), path(chr_sizes) from pairs_ch_cooler
output:
tuple id, path("*.cool") into balance_cooler_ch
script:
"""
cooler cload pairix \
-p ${task.cpus} \
${chr_sizes}:1000 \
${pairs} \
${id}.cool
"""
}
process balance_cooler {
tag "_${id}"
cpus 48
memory '100 GB'
container 'mblanche/cooler'
publishDir "${params.outDir}/coolerFiles",
mode: 'copy'
input:
tuple id, path(cooler) from balance_cooler_ch
output:
tuple id, path(cooler) into zoomify_cooler_ch
script:
"""
cooler balance --force -p ${task.cpus} ${cooler}
"""
}
process cooler_zoomify {
tag "_${id}"
cpus 48
memory '100 GB'
container 'mblanche/cooler'
publishDir "${params.outDir}/coolerFiles",
mode: 'copy'
input:
tuple id, path(cooler) from zoomify_cooler_ch
output:
tuple id, path("*.mcool") into mustache_mcool_ch, abcomp_mcool_ch
script:
"""
cooler zoomify --balance -p ${task.cpus} ${cooler}
"""
}
process bam2bw {
tag "_${id}"
cpus 20
memory '175 GB'
container 'mblanche/r-cov'
publishDir "${params.outDir}/bigwigs",
mode: 'copy'
input:
tuple id, path(bam),path(idx) from bam_bigwig_ch
output:
tuple id, path ("*.bw") into bigwig_out_ch
script:
"""
bam2bw ${bam} ${id}.bw ${task.cpus}
"""
}
process juicer {
tag "_${id}"
cpus 24
memory '150 GB'
container 'mblanche/juicer'
publishDir "${params.outDir}/hicFiles",
mode: 'copy'
input:
tuple id, path(pairs), path(idx), path(chr_sizes) from pairs_ch_juicer
output:
tuple id, path("*.hic") into arrowhead_ch, hiccups_ch
script:
"""
java -Xmx96000m -Djava.awt.headless=true \
-jar /juicer_tools.jar pre \
--threads ${task.cpus} \
-j ${task.cpus} \
-k VC,VC_SQRT,KR,SCALE \
${pairs} \
${id}.hic \
${chr_sizes}
"""
}
if (!(params.capture|params.hichip)){
process arrowhead {
tag "_${id}"
cpus 12
memory '40 GB'
container "mblanche/juicer"
publishDir "${params.outDir}/arrowHead",
mode: 'copy'
input:
tuple id, path(hic), val(res) from arrowhead_ch
.combine(Channel.from(resolutions))
output:
tuple id, path("${id}_${res}kb") into arrowhead_out_ch
script:
bpRes = res.toInteger() * 1000
"""
mkdir -p ${id}_${res}kb && touch ${id}_${res}kb/${bpRes}_blocks.bedpe
java -Xmx24000m \
-jar /juicer_tools.jar \
arrowhead \
--threads ${task.cpus} \
--ignore-sparsity \
-r ${bpRes} \
-k KR \
${hic} \
${id}_${res}kb
"""
}
process hiccups {
tag "_${id}"
label 'gpu'
accelerator 1
cpus 6
memory '30 GB'
container "mblanche/hiccups-gpu"
publishDir "${params.outDir}/hiccups/",
mode: 'copy'
input:
tuple id, path(hic), val(res) from hiccups_ch
.combine(Channel.from(resolutions.collect{it*1000}.join(',')))
output:
tuple id, path("${id}_loops") into hiccups_out_ch
script:
"""
java -Xmx24000m \
-jar /juicer_tools.jar \
hiccups \
--threads ${task.cpus} \
--ignore-sparsity \
-m 500 \
-r ${res} \
-k KR \
${hic} \
${id}_loops
"""
}
process mustache {
tag "_${id}"
cpus 24
memory '48 GB'
container "mblanche/mustache"
publishDir "${params.outDir}/mustache",
mode: 'copy'
input:
tuple id, path(mcool), val(res) from mustache_mcool_ch
.combine(Channel.from(1000,4000,16000))
output:
tuple id, path("*.tsv") into mustache_2_merge_ch
script:
"""
touch ${id}_${res}kb_loops.tsv
mustache -p ${task.cpus} \
-f ${mcool} \
-r ${res} \
-o ${id}_${res}kb_loops.tsv
"""
}
process ABcomp {
tag "_${id}"
cpus 1
memory '12 GB'
container "mblanche/fan-c"
publishDir "${params.outDir}/AB_comp",
mode: 'copy'
input:
tuple id, path(cool), val(resKB) from abcomp_mcool_ch
.combine(Channel.from(ABresolutions))
path(genome) from abcomp_genome_ch.first()
output:
tuple id, path("*.bed"), path("*.ab") into fanc_out_ch
script:
res = resKB.toInteger() * 1000
"""
fanc compartments \
-f \
-v ${id}_eigenV_${resKB}kb.bed \
-d ${id}_AB_${resKB}kb.bed \
-g ${genome} \
${cool}@${res} \
${id}_${resKB}kb.ab
"""
}
}
if (params.capture){
switch(params.baits) {
case "pc-hs-1":
baits = ""
break
case "pc-mm-1":
baits = ""
break
default:
exit 1, "Wrong capure design. Has to be pc-hs-1 or pc-mm-1."
break
}
Channel
.from(params.chicago-res)
.splitCsv(header: false)
.flatten()
.map{it.toInteger() * 1000}
.set{res_ch}
process make_mapFiles {
echo true
tag "_${id}"
cpus 1
memory '8 GB'
container 'mblanche/chicago'
publishDir "${outDir}",
saveAs: {filename -> filename.endsWith('.rmap') ? filename : null},
mode: 'copy'
input:
tuple path(baits), val(genome), val(res) from Channel.fromPath(baits)
.combine(Channel.from(params.genome).first())
.combine(res_ch)
output:
tuple val(res), path("*.rmap"), path("*.baitmap") into mapFiles_ch
script:
"""
prep4Chicago ${baits} ${res} ${genome}
"""
}
process cleanUpBam {
label 'index'
tag "_${id}"
cpus 48
memory '100 GB'
container 'mblanche/bwa-samtools'
input:
path(bam) from bam_chicago_ch
output:
tuple id, path("*-cleanedUp.bam") into cleanBam_ch
script:
id = bam.name.toString().take(bam.name.toString().lastIndexOf('.'))
"""
samtools index -@${task.cpus} ${bam} \
&& samtools view -@ ${task.cpus} -Shu -F 2048 ${bam} \
| samtools sort -n -@ ${task.cpus} -o ${id}-cleanedUp.bam -
"""
}
process make_design {
tag "_${id}"
cpus 1
memory '8 GB'
container 'mblanche/chicago'
input:
tuple val(res), path(rmap), path(baitmap) from mapFiles_ch
output:
tuple val(res), path(rmap), path(baitmap), path("${res}kDesingFiles*") into design_ch
script:
"""
python3 /makeDesignFiles_py3.py \
--minFragLen 75 \
--maxFragLen 30000 \
--maxLBrownEst 1000000 \
--binsize 20000 \
--rmapfile ${rmap} \
--baitmapfile ${baitmap} \
--outfilePrefix ${res}kDesingFiles
"""
}
process run_Chicago {
tag "_${id}"
cpus 1
memory '182 GB'
container 'mblanche/chicago'
publishDir "${outDir}/${id}_${res}",
mode: 'copy'
input:
tuple id, path(bam), val(res), path(rmap), path (baitmap), path(designFiles) from cleanBam_ch
.combine(design_ch)
output:
tuple id, path("${id}_${res}_chinput"), path("${id}_${res}bp") into chicago_ch
script:
"""
bam2chicago.sh ${bam} ${baitmap} ${rmap} ${id}_${res}_chinput