-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.nf
124 lines (100 loc) · 2.89 KB
/
main.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
nextflow.enable.dsl=2
params.help = false
if (params.help) {
log.info """
-----------------------------------------------------------------------
covdist
===========
Documentation and issues can be found at:
https://github.com/brwnj/covdist
Required arguments:
-------------------
--crams Aligned sequences in .bam and/or .cram format.
Indexes (.bai/.crai) must be present.
--reference Reference FASTA. Index (.fai) must exist in same
directory.
--gaps Regions of known gaps in .bed format.
Options:
--------
--outdir Base results directory for output.
Default: '/.results'
--exclude Chromosomes to exclude as comma separated string.
Default: 'decoy,random,chrUn,alt,chrEBV,chrM'
--cpus Number of cpus dedicated to `mosdepth` calls.
Default: 4
-----------------------------------------------------------------------
""".stripIndent()
exit 0
}
params.crams = false
params.reference = false
params.gaps = false
params.outdir = './results'
params.cpus = 4
if(!params.crams) {
exit 1, "--crams argument like '/path/to/*.cram' is required"
}
if(!params.reference) {
exit 1, "--reference argument is required"
}
if(!params.gaps) {
exit 1, "--gaps argument is required"
}
crams = channel.fromPath(params.crams)
crais = crams.map { it -> it + ("${it}".endsWith('.cram') ? '.crai' : '.bai') }
exclude = params.exclude.tokenize(",")
chroms = channel
.fromPath("${params.reference}.fai")
.splitCsv(sep: "\t", strip: true)
.map { row -> "${row[0]}" }
.filter( ~/(?!${exclude.collect {".*$it.*"}.join("|")})([a-zA-Z0-9_]+)/ )
process makebed {
input:
val chrs
path(reference)
output:
path("include.bed"), emit: bed
script:
template "makebed.py"
}
process bedtools {
input:
path(genome)
path(gaps)
output:
path("include_gaps.bed"), emit: bed
script:
"""
bedtools subtract -a ${genome} -b ${gaps} > include_gaps.bed
"""
}
process mosdepth {
publishDir "${params.outdir}/mosdepth", mode: "copy"
cpus params.cpus
input:
path(cram)
path(crai)
path(reference)
path(bed)
output:
path("*global.dist.txt"), emit: txt
script:
"""
mosdepth -f ${reference} -b ${bed} -n -x -t ${task.cpus} ${cram.getSimpleName()} ${cram}
"""
}
process covdist {
publishDir params.outdir, mode: "copy"
input:
path(txts)
output:
path("covdist.html"), emit: html
script:
template "covdist.py"
}
workflow {
makebed(chroms.collect(), "${params.reference}.fai")
bedtools(makebed.output.bed, params.gaps)
mosdepth(crams, crais, params.reference, bedtools.output.bed)
covdist(mosdepth.output.txt.collect())
}