-
Notifications
You must be signed in to change notification settings - Fork 4
/
align_dna.nf
executable file
·188 lines (152 loc) · 5.41 KB
/
align_dna.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
#!/usr/bin/env nextflow
import CopyHelper
import ChannelUtil
import FastQC
import PathUtil
import ParamsHelper
// ---------------------------------------------------------------------------
// Read preprocessing and alignment for DNA (WES or WGS) reads.
// ---------------------------------------------------------------------------
if (params.verbose)
echo true
ParamsHelper.checkNonEmptyParam(params.runID, "runID");
ParamsHelper.checkNonEmptyParam(params.runPlatform, "runPlatform");
ParamsHelper.checkNonEmptyParam(params.dataDir, "dataDir");
copyHelper = new CopyHelper(params.dataDir, params.printCopyMsgs)
// Open channel for left and right files and merge it into triples, the
// first entry is the LCS of the file names that can be used as a read
// pair identifier.
readPairs = ChannelUtil.createFilePairChannel(
params.runID,
Channel.fromPath([params.dataDir, 'fastq', 'original', '*_{R,}1.fastq.gz'].join(File.separator)),
Channel.fromPath([params.dataDir, 'fastq', 'original', '*_{R,}2.fastq.gz'].join(File.separator)),
)
// Genome and index files.
indexFileBWA = file(params.indexBWA)
// Duplicate the read pairs into one queue for runFastQCOriginal
// and runTrimming.
(readPairsFastQCOriginal, readPairsRunTrimming) = readPairs.separate(2) { x -> [x, x] }
// --------------------------------------------------------------------------
// Step 1a) Run FastQC
//
// - yields report
// --------------------------------------------------------------------------
process runFastQCOriginal {
cpus params.fastqc.cpus
module 'fastqc/0.11.2'
input:
set runID, file(readL), file(readR) from readPairsFastQCOriginal
output:
set file('*.zip'), file('*.html') into fastqcOutputOriginal
script:
"""
set -x
fastqc -t params.fastqc.cpus -o . ${readL} ${readR}
"""
}
copyHelper.copyFiles(fastqcOutputOriginal, 'reports/fastqc-original');
System.exit(0);
// --------------------------------------------------------------------------
// Step 1b) Run adapter trimming
//
// - yields trimmed read, used as downstream input
// --------------------------------------------------------------------------
process runTrimming {
cpus params.skewer.cpus
module 'skewer/0.1.124'
input:
set runID, file(readL), file(readR) from readPairsRunTrimming
output:
set runID, file { "out/${readL}" }, file { "out/${readR}" } into readPairsTrimmed
set file("*.log") into trimmingLogs
script:
"""
set -x
# call Skewer
skewer \\
-x ${params.skewer.adaptersR1} \\
-y ${params.skewer.adaptersR2} \\
-m pe \\
-z \\
-t ${params.skewer.cpus} \\
${readL} \\
${readR}
# compute name of left/right Skewer result file
NAMEBASE=${readL}
LEFT=\${NAMEBASE%.gz}-trimmed-pair1.fastq.gz
RIGHT=\${NAMEBASE%.gz}-trimmed-pair2.fastq.gz
# move Skewer output to expected file names
mkdir -p out
mv \${LEFT} out/${readL}
mv \${RIGHT} out/${readR}
"""
}
// Duplicate the read pairs into multiple queues for processing / copying out.
(readPairsFastQCTrimmed,
readPairsRunMapping,
readPairsTrimmedCopyOut) = readPairsTrimmed.separate(3) { x -> [ x, x, x ] }
// Copy out results from trimming step (map removes the pair).
copyHelper.copyFiles(trimmingLogs, 'reports/trimming');
copyHelper.copyFiles(readPairsTrimmedCopyOut.map { [it[1], it[2]] }, 'fastq/trimmed');
// --------------------------------------------------------------------------
// Step 2a) Run FastQC on trimmed
//
// - yields report
// --------------------------------------------------------------------------
process runFastQCTrimmed {
cpus params.fastqc.cpus
module 'fastqc/0.11.2'
input:
set runID, file(readL), file(readR) from readPairsFastQCTrimmed
output:
set file('*.zip'), file('*.html') into fastqcOutputTrimmed
script:
"""
set -x
fastqc -t ${params.fastqc.cpus} -o . ${readL} ${readR}
"""
}
copyHelper.copyFiles(fastqcOutputTrimmed, 'reports/fastqc-trimmed');
// --------------------------------------------------------------------------
// Step 2b) Align reads using BWA-MEM
//
// - align reads
// - sort
// - mark duplicates
// - yields alignment for downstream processing
// --------------------------------------------------------------------------
// Group trimmed read FASTQ files by runID (the runID is part of the output
// of a previous process).
jointBams = readPairsRunMapping.map{f -> [f[0], f[1], f[2]] }.groupTuple()
// The alignments are written to the temporary files alignment.bam. These
// BAM files are already sorted.
process runReadMapping {
cpus params.bwa.cpus
module 'bwa/0.7.12'
module 'samtools/1.2'
module 'samblaster/0.1.21'
input:
indexFileBWA
set runID, readL, readR from jointBams
output:
file { "${runID}.bam*" } into bamFilesOut
set runID, file { "${runID}.bam" }, file { "${runID}.bam.bai" } into bamFiles
script:
"""
set -x
bwa mem \\
-R '@RG\tID:${runID}\tSM:${runID}\tPL:${params.runPlatform}' \\
-t ${params.bwa.cpus} \\
${indexFileBWA} \\
<(zcat ${readL.join(" ")}) \\
<(zcat ${readR.join(" ")}) \\
| samblaster \\
| samtools view -u -Sb - \\
| samtools sort - ${runID}
samtools index ${runID}.bam
"""
}
(bamFilesForCoverage,
bamFilesForQualimap,
bamFilesForVariantCalling) = bamFiles.separate(3) { x -> [ x, x, x ] }
copyHelper.copyFiles(bamFilesOut, 'bam')