-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.nf
198 lines (153 loc) · 4.32 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
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
#!/usr/bin/env nextflow
//Build link to reference
referenceLink = params.ref.base_url + params.ref.chr + ".fsa.zip"
//Take accessions defined in nextflow.config.
//Use --take N to process first N accessions or --take all to process all
accessionsChannel = Channel.from(params.accessions).take( params.take == 'all' ? -1 : params.take )
//fetch adapters file - either local or remote
adaptersChannel = Channel.fromPath(params.adapters)
process download_chromosome {
tag { params.ref.chr }
//Prevent re-downloading of large files
storeDir { "${params.outdir}/downloaded" } //use with care, caching will not work as normal so changes to input may not take effect
scratch false //must be false otherwise storeDir ignored
input:
referenceLink
output:
file('*') into references
script:
"""
wget ${referenceLink}
"""
}
process bgzip_chromosome {
cpus '2' //consider defining in conf/requirements.config based on process name or label
tag { ref }
input:
file ref from references
output:
file('*') into chromosomesChannel
script:
"""
unzip -p ${ref} \
| bgzip --threads ${task.cpus} \
> ${ref}.gz
"""
}
process bgzip_chromosome_subregion {
input:
file chr from chromosomesChannel
output:
file('subregion') into subregionsChannel
script:
"""
samtools faidx ${chr} ${params.ref.chr}:${params.ref.start}-${params.ref.end} \
| bgzip --threads ${task.cpus} \
> subregion
"""
}
process extract_reads {
tag { accession }
storeDir { "${workDir}/downloaded_reads" } //use with care, caching will not work as normal so changes to input may not take effect
input:
val accession from accessionsChannel
//e.g. ACBarrie
output:
set val(accession), file("${accession}_R?.fastq.gz") into (extractedReadsChannelA, extractedReadsChannelB)
//e.g. ACBarrie, [ACBarrie_R1.fastq.gz, ACBarrie_R2.fastq.gz]
script:
"""
samtools view -hu "${params.bam.base_url}/${params.bam.chr}/${accession}.realigned.bam" \
${params.bam.chr}:${params.bam.start}-${params.bam.end} \
| samtools collate -uO - \
| samtools fastq -F 0x900 -1 ${accession}_R1.fastq.gz -2 ${accession}_R2.fastq.gz \
-s /dev/null -0 /dev/null - \
&& zcat ${accession}_R1.fastq.gz | head | awk 'END{exit(NR<4)}' \
&& zcat ${accession}_R2.fastq.gz | head | awk 'END{exit(NR<4)}'
"""
}
process fastqc_raw {
tag { accession }
input:
set val(accession), file('*') from extractedReadsChannelA
output:
file('*') into fastqcRawResultsChannel
script:
"""
fastqc --quiet --threads ${task.cpus} *
"""
}
process multiqc_raw {
input:
file('*') from fastqcRawResultsChannel.collect()
output:
file('*') into multiqcRawResultsChannel
script:
"""
multiqc .
"""
}
process trimmomatic_pe {
echo true
tag {accession}
input:
set file(adapters), val(accession), file('*') from adaptersChannel.combine(extractedReadsChannelB)
output:
set val(accession), file('*.paired.fastq.gz') into (trimmedReadsChannelA, trimmedReadsChannelB)
script:
"""
trimmomatic PE \
*.fastq.gz \
${accession}_R1.paired.fastq.gz \
${accession}_R1.unpaired.fastq.gz \
${accession}_R2.paired.fastq.gz \
${accession}_R2.unpaired.fastq.gz \
ILLUMINACLIP:${adapters}:2:30:10:3:true \
LEADING:2 \
TRAILING:2 \
SLIDINGWINDOW:4:15 \
MINLEN:36
"""
}
process fastqc_trimmed {
tag { accession }
input:
set val(accession), file('*') from trimmedReadsChannelB
output:
file('*') into fastqcTrimmedResultsChannel
script:
"""
fastqc --quiet --threads ${task.cpus} *
"""
}
process multiqc_trimmed {
input:
file('*') from fastqcTrimmedResultsChannel.collect()
output:
file('*') into multiqcTrimmedResultsChannel
script:
"""
multiqc .
"""
}
process bwa_index {
input:
file(ref) from subregionsChannel
output:
set val(ref.name), file("*") into indexChannel //also valid: set val("${ref}"), file("*") into indexChannel
script:
"""
bwa index -a bwtsw ${ref}
"""
}
process bwa_mem {
tag { accession }
input:
set val(ref), file('*'), val(accession), file(reads) from indexChannel.combine(trimmedReadsChannelA)
output:
file('*.bam') into alignedReadsChannel
script:
"""
bwa mem -t ${task.cpus} -R '@RG\\tID:${accession}\\tSM:${accession}' ${ref} ${reads} | samtools view -b > ${accession}.bam
"""
}