forked from proychou/Tpallidum_WGS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.nf
executable file
·233 lines (214 loc) · 7.72 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
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
#!/usr/bin/env nextflow
// Using Nextflow DSL-2 to account for logic flow of this workflow
nextflow.preview.dsl=2
def helpMessage() {
log.info"""
T. pallidum whole genome sequencing
Usage:
An example command for running the pipeline is as follows:
nextflow run michellejlin/Tpallidum_WGS \\
--INPUT Input folder where all fastqs are located.
./ can be used for current directory.
Fastqs should all be gzipped. This can be done with the command gzip *.fastq. [REQUIRED]
--OUTDIR Output directory. [REQUIRED]
""".stripIndent()
}
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
/* */
/* SET UP CONFIGURATION VARIABLES */
/* */
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// Show help message
params.help = false
if (params.help){
helpMessage()
exit 0
}
params.INPUT = false
params.OUTDIR= false
params.SINGLE_END = false
// if INPUT not set
if (params.INPUT == false) {
println( "Must provide an input directory with --INPUT")
exit(1)
}
// Make sure INPUT ends with trailing slash
if (!params.INPUT.endsWith("/")){
params.INPUT = "${params.INPUT}/"
}
// if OUTDIR not set
if (params.OUTDIR == false) {
println( "Must provide an output directory with --OUTDIR")
exit(1)
}
// Make sure OUTDIR ends with trailing slash
if (!params.OUTDIR.endsWith("/")){
params.OUTDIR = "${params.OUTDIR}/"
}
//
// Reference files
//
ADAPTERS = file("s3://clomp-reference-data/tool_specific_data/Tpallidum_WGS/All_adapters.fa")
//REF_FASTAS = file("${baseDir}/refs/TPA_refseqs.fasta")
REF_FASTAS = file("s3://clomp-reference-data/tool_specific_data/Tpallidum_WGS/refs/TPA_rRNA_refs.fasta")
//REF_FASTAS_MASKED = file("s3://clomp-reference-data/tool_specific_data/Tpallidum_WGS/refs/Tp_refs_rRNA_masked.fasta")
REF_FASTAS_MASKED = file("${baseDir}/refs/Tp_refs_rRNA_masked.fasta")
REF_FASTAS_TRIM = file("s3://clomp-reference-data/tool_specific_data/Tpallidum_WGS/refs/TPA_refseqs_trim.fasta")
NC_021508 = file("s3://clomp-reference-data/tool_specific_data/Tpallidum_WGS/refs/NC_021508.fasta")
// bowtie2 indexes
NC_021508_1 = file("s3://clomp-reference-data/tool_specific_data/Tpallidum_WGS/refs/NC_021508.1.bt2")
NC_021508_2 = file("s3://clomp-reference-data/tool_specific_data/Tpallidum_WGS/refs/NC_021508.2.bt2")
NC_021508_3 = file("s3://clomp-reference-data/tool_specific_data/Tpallidum_WGS/refs/NC_021508.3.bt2")
NC_021508_4 = file("s3://clomp-reference-data/tool_specific_data/Tpallidum_WGS/refs/NC_021508.4.bt2")
NC_021508_5 = file("s3://clomp-reference-data/tool_specific_data/Tpallidum_WGS/refs/NC_021508.rev.1.bt2")
NC_021508_6 = file("s3://clomp-reference-data/tool_specific_data/Tpallidum_WGS/refs/NC_021508.rev.2.bt2")
// bwa indexes
NC_021508_BWA1 = file("s3://clomp-reference-data/tool_specific_data/Tpallidum_WGS/refs/NC_021508.fasta.amb")
NC_021508_BWA2 = file("s3://clomp-reference-data/tool_specific_data/Tpallidum_WGS/refs/NC_021508.fasta.ann")
NC_021508_BWA3 = file("s3://clomp-reference-data/tool_specific_data/Tpallidum_WGS/refs/NC_021508.fasta.bwt")
NC_021508_BWA4 = file("s3://clomp-reference-data/tool_specific_data/Tpallidum_WGS/refs/NC_021508.fasta.pac")
NC_021508_BWA5 = file("s3://clomp-reference-data/tool_specific_data/Tpallidum_WGS/refs/NC_021508.fasta.sa")
REF_GB = file("s3://clomp-reference-data/tool_specific_data/Tpallidum_WGS/refs/NC_021508.gb")
// Scripts
TP_MAKE_SEQ = file("${baseDir}/tp_make_seq.R")
TP_GENERATE_CONSENSUS = file("${baseDir}/tp_generate_consensus.R")
//REPEAT_FILTER_FASTA = file("s3://clomp-reference-data/tool_specific_data/Tpallidum_WGS/refs/repeat_filter_UPDATE.fasta")
REPEAT_FILTER_FASTA = file("s3://clomp-reference-data/tool_specific_data/Tpallidum_WGS/refs/repeat_filter_with_TprK.fasta")
// Read in fastq pairs into input_read_ch
if(params.SINGLE_END == false){
input_read_ch = Channel
.fromFilePairs("${params.INPUT}*_R{1,2}*.gz")
.ifEmpty { error "Cannot find any FASTQ pairs in ${params.INPUT} ending with .gz" }
.map { it -> [it[0], it[1][0], it[1][1]]}
}
//
// Import processes
//
include trimReads from './modules'
include filterTp from './modules'
include mapUnmatchedReads from './modules'
include moreFiltering from './modules'
include mapReads from './modules'
include samToBam from './modules'
include removeDuplicates from './modules'
include callVariants from './modules'
include deNovoAssembly from './modules'
include mergeAssemblyMapping from './modules'
include remapReads from './modules'
include pilonPolishing from './modules'
include remapPilon from './modules'
include generateConsensus from './modules'
include generatePilonConsensus from './modules'
include annotateConsensus from './modules'
include annotatePilonConsensus from './modules'
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
/* */
/* RUN THE WORKFLOW */
/* */
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
workflow {
input_read_ch = Channel
.fromFilePairs("${params.INPUT}*_R{1,2}*.gz")
.ifEmpty { error "Cannot find any FASTQ pairs in ${params.INPUT} ending with .gz" }
.map { it -> [it[0], it[1][0], it[1][1]]}
trimReads (
input_read_ch,
ADAPTERS
)
filterTp (
trimReads.out,
REF_FASTAS
)
mapUnmatchedReads (
filterTp.out[1],
REF_FASTAS_MASKED
)
moreFiltering (
mapUnmatchedReads.out[1],
REPEAT_FILTER_FASTA
)
mapReads (
filterTp.out[0].groupTuple()
.join(
mapUnmatchedReads.out[0].groupTuple()
),
NC_021508,
NC_021508_1,
NC_021508_2,
NC_021508_3,
NC_021508_4,
NC_021508_5,
NC_021508_6
)
samToBam (
mapReads.out
)
removeDuplicates (
samToBam.out
)
callVariants (
removeDuplicates.out[2],
NC_021508
)
deNovoAssembly (
moreFiltering.out[0]
)
mergeAssemblyMapping (
deNovoAssembly.out[0].groupTuple()
.join(
removeDuplicates.out[1].groupTuple()
),
file(NC_021508),
file(NC_021508_BWA1),
file(NC_021508_BWA2),
file(NC_021508_BWA3),
file(NC_021508_BWA4),
file(NC_021508_BWA5),
file(TP_MAKE_SEQ)
)
remapReads (
mergeAssemblyMapping.out[0].groupTuple()
.join(
removeDuplicates.out[5].groupTuple()
)
)
pilonPolishing (
remapReads.out[1]
)
remapPilon (
pilonPolishing.out[0].groupTuple()
.join(
removeDuplicates.out[6].groupTuple()
)
)
generateConsensus (
remapReads.out[0].groupTuple(
).join(
mergeAssemblyMapping.out[1].groupTuple()
).join(
removeDuplicates.out[1].groupTuple()
),
TP_GENERATE_CONSENSUS
)
generatePilonConsensus (
remapPilon.out[0].groupTuple(
).join(
pilonPolishing.out[1].groupTuple()
).join(
removeDuplicates.out[3].groupTuple()
),
TP_GENERATE_CONSENSUS
)
annotateConsensus (
generateConsensus.out,
REF_GB
)
annotatePilonConsensus (
generatePilonConsensus.out,
REF_GB
)
}