-
Notifications
You must be signed in to change notification settings - Fork 0
/
bam2bw.nf
95 lines (67 loc) · 1.87 KB
/
bam2bw.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
#!/usr/bin/env nextflow
params.bamDir = false
params.outDir = false
params.help = false
def helpMessage() {
log.info"""
Usage:
The typical command for running the pipeline is as follows:
plotECDF --bam ./path/to/lib1,./path/to/lib2,./path/to/lib3,...
or
bam2bw --prefix myECDF --bam ./path/to/lib1,./path/to/lib2,./path/to/lib3,... --outDir path/to/results.pdf
Mandatory arguments:
--bamDir [path] Name of the a direcoty with bam files and their index to compute coverages (can be local or valid S3 location.
Facultative arguments
--outDir [path] Path to a diectory to save the bigwig coveage files (can be local or valid S3 location.
""".stripIndent()
}
if (params.help){
helpMessage()
exit 0
}
if (!params.bamDir) {
exit 1, "--bamDir is a required arguments. Use --help to get the full usage."
}
if(!params.outDir){
outDir = file(params.bamDir).getParent() + "/bigwigs"
} else {
outDir = params.outDir
}
Channel
.fromPath("${params.bamDir}/*.bam")
.set{bam_ch}
process index {
label 'index'
tag '_${id}'
cpus 48
memory '100 GB'
container 'mblanche/bwa-samtools'
publishDir "${params.bamDir}",
mode: "copy"
input:
path(bam) from bam_ch
output:
tuple id, path(bam), path("*.bam.bai") into bamNidx_ch
script:
id = bam.name.toString().take(bam.name.toString().lastIndexOf('.'))
"""
samtools index -@${task.cpus} ${bam}
"""
}
process bam2bw {
label 'batch'
tag "_${id}"
cpus 20
memory '150 GB'
container 'mblanche/r-cov'
publishDir "${outDir}",
mode: 'copy'
input:
tuple val(id), path(bam), path(idx) from bamNidx_ch
output:
path "*.bw" into bigwig_ch
script:
"""
bam2bw ${bam} ${id}.bw ${task.cpus}
"""
}