-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.nf
More file actions
247 lines (199 loc) · 8.39 KB
/
Copy pathmain.nf
File metadata and controls
247 lines (199 loc) · 8.39 KB
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/usr/bin/env nextflow
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
IMPORT FUNCTIONS / MODULES / SUBWORKFLOWS / WORKFLOWS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
nextflow.enable.dsl=2
include { ALIGN_MINIMAP2 } from './modules/align_minimap2'
include { SAMTOOLS_FLAGSTAT } from './modules/samtools_flagstat'
include { SAMTOOLS_STATS } from './modules/samtools_stats'
include { MOSDEPTH } from './modules/mosdepth'
include { CRAMINO } from './modules/cramino'
include { SNIFFLES_SINGLE } from './modules/sniffles_single'
include { SNIFFLES_MERGE } from './modules/sniffles_merge'
include { SNIFFLES_SPLIT_SINGLE } from './modules/sniffles_split_single'
include { SNIFFLES_SPLIT_COHORT } from './modules/sniffles_split_cohort'
include {
VCF_SV_SUMMARY as VCF_SV_SUMMARY_SINGLE_FULL
VCF_SV_SUMMARY as VCF_SV_SUMMARY_SINGLE_BND
VCF_SV_SUMMARY as VCF_SV_SUMMARY_SINGLE_NONBND
VCF_SV_SUMMARY as VCF_SV_SUMMARY_COHORT_FULL
VCF_SV_SUMMARY as VCF_SV_SUMMARY_COHORT_BND
VCF_SV_SUMMARY as VCF_SV_SUMMARY_COHORT_NONBND
} from './modules/vcf_sv_summary'
include {
VCF_BCFTOOLS_STATS as VCF_BCFTOOLS_STATS_DV_SINGLE
} from './modules/vcf_bcftools_stats'
include { SNIFFLES2_PLOT_SINGLE } from './modules/sniffles2_plot_single'
include { SNIFFLES2_PLOT_MULTI } from './modules/sniffles2_plot_multi'
include { CLAIRSTO_SINGLE } from './modules/clairsto_single'
include { SMALLVAR_MERGE_SINGLE } from './modules/smallvar_merge_single'
include { SMALLVAR_SPLIT_SINGLE } from './modules/smallvar_split_single'
include { SMALLVAR_SUMMARY } from './modules/smallvar_summary'
include { SMALLVAR_COHORT_TABLE } from './modules/smallvar_cohort_table'
include { MULTIQC } from './modules/multiqc'
def validateParams() {
if( !params.samplesheet ) error "Missing --samplesheet"
if( !params.reference_mmi ) error "Missing --reference_mmi"
if( !params.reference_fasta ) error "Missing --reference_fasta"
if( !file(params.samplesheet).exists() ) error "Samplesheet not found: ${params.samplesheet}"
if( !file(params.reference_mmi).exists() ) error "Reference MMI not found: ${params.reference_mmi}"
if( !file(params.reference_fasta).exists() ) error "Reference FASTA not found: ${params.reference_fasta}"
if( params.tandem_repeats && !file(params.tandem_repeats).exists() ) error "Tandem repeats BED not found: ${params.tandem_repeats}"
}
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RUN MAIN WORKFLOW
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
workflow {
main:
validateParams()
samples_ch = channel
.fromPath(params.samplesheet)
.splitCsv(header: true)
.map { row ->
if( !row.sample_id ) error "Samplesheet row missing sample_id: ${row}"
if( !row.fastq_dir ) error "Samplesheet row missing fastq_dir: ${row}"
tuple(row.sample_id as String, file(row.fastq_dir))
}
ref_mmi_ch = channel.value(file(params.reference_mmi))
ref_fasta = file(params.reference_fasta)
ref_fai = file(params.reference_fai)
tr_bed_val = params.tandem_repeats ? file(params.tandem_repeats) : null
/*
* Alignment + BAM QC
*/
bam_ch = ALIGN_MINIMAP2(samples_ch, ref_mmi_ch)
flagstat_ch = SAMTOOLS_FLAGSTAT(bam_ch)
stats_ch = SAMTOOLS_STATS(bam_ch)
mosdepth_ch = MOSDEPTH(bam_ch)
cramino_ch = CRAMINO(bam_ch)
/*
* Sniffles single
*/
sniffles_input_ch = bam_ch.map { x ->
tuple(x[0], x[1], x[2], tr_bed_val, ref_fasta)
}
sniffles_single_ch = SNIFFLES_SINGLE(sniffles_input_ch)
/*
* Sniffles cohort
*/
snf_files_ch = sniffles_single_ch
.map { x -> x[3] }
.collect()
cohort_ch = SNIFFLES_MERGE(snf_files_ch, tr_bed_val, ref_fasta)
/*
* Split Sniffles outputs
*/
sniffles_split_single_ch = SNIFFLES_SPLIT_SINGLE(sniffles_single_ch)
sniffles_split_cohort_ch = SNIFFLES_SPLIT_COHORT(cohort_ch)
/*
* Full SV summaries
*/
full_sv_summary_input_single_ch = sniffles_single_ch.map { x ->
tuple("${x[0]}.full_sv", x[1], x[2])
}
full_sv_summary_single_ch = VCF_SV_SUMMARY_SINGLE_FULL(full_sv_summary_input_single_ch)
// full_sv_stats_input_single_ch = sniffles_single_ch.map { x ->
// tuple("${x[0]}.full_sv", x[1], x[2])
// }
// full_sv_stats_single_ch = VCF_BCFTOOLS_STATS_SINGLE_FULL(full_sv_stats_input_single_ch)
full_sv_summary_input_cohort_ch = cohort_ch.map { x ->
tuple("cohort.full_sv", x[0], x[1])
}
full_sv_summary_cohort_ch = VCF_SV_SUMMARY_COHORT_FULL(full_sv_summary_input_cohort_ch)
// full_sv_stats_input_cohort_ch = cohort_ch.map { x ->
// tuple("cohort.full_sv", x[0], x[1])
// }
// full_sv_stats_cohort_ch = VCF_BCFTOOLS_STATS_COHORT_FULL(full_sv_stats_input_cohort_ch)
/*
* BND summaries
*/
bnd_summary_input_single_ch = sniffles_split_single_ch.map { x ->
tuple("${x[0]}.bnd", x[1], x[2])
}
bnd_summary_single_ch = VCF_SV_SUMMARY_SINGLE_BND(bnd_summary_input_single_ch)
// bnd_stats_input_single_ch = sniffles_split_single_ch.map { x ->
// tuple("${x[0]}.bnd", x[1], x[2])
// }
// bnd_stats_single_ch = VCF_BCFTOOLS_STATS_SINGLE_BND(bnd_stats_input_single_ch)
bnd_summary_input_cohort_ch = sniffles_split_cohort_ch.map { x ->
tuple("cohort.bnd", x[0], x[1])
}
bnd_summary_cohort_ch = VCF_SV_SUMMARY_COHORT_BND(bnd_summary_input_cohort_ch)
// bnd_stats_input_cohort_ch = sniffles_split_cohort_ch.map { x ->
// tuple("cohort.bnd", x[0], x[1])
// }
// bnd_stats_cohort_ch = VCF_BCFTOOLS_STATS_COHORT_BND(bnd_stats_input_cohort_ch)
/*
* non-BND summaries
*/
nonbnd_summary_input_single_ch = sniffles_split_single_ch.map { x ->
tuple("${x[0]}.nonbnd", x[3], x[4])
}
nonbnd_summary_single_ch = VCF_SV_SUMMARY_SINGLE_NONBND(nonbnd_summary_input_single_ch)
// nonbnd_stats_input_single_ch = sniffles_split_single_ch.map { x ->
// tuple("${x[0]}.nonbnd", x[3], x[4])
// }
// nonbnd_stats_single_ch = VCF_BCFTOOLS_STATS_SINGLE_NONBND(nonbnd_stats_input_single_ch)
nonbnd_summary_input_cohort_ch = sniffles_split_cohort_ch.map { x ->
tuple("cohort.nonbnd", x[2], x[3])
}
nonbnd_summary_cohort_ch = VCF_SV_SUMMARY_COHORT_NONBND(nonbnd_summary_input_cohort_ch)
// nonbnd_stats_input_cohort_ch = sniffles_split_cohort_ch.map { x ->
// tuple("cohort.nonbnd", x[2], x[3])
// }
// nonbnd_stats_cohort_ch = VCF_BCFTOOLS_STATS_COHORT_NONBND(nonbnd_stats_input_cohort_ch)
/*
* Sniffles plots
*/
sniffles2_plot_single_ch = SNIFFLES2_PLOT_SINGLE(sniffles_single_ch)
sniffles2_plot_multi_ch = SNIFFLES2_PLOT_MULTI(cohort_ch)
/*
* ClairS-TO per sample
*/
clairsto_input_ch = bam_ch.map { x ->
tuple(x[0], x[1], x[2], ref_fasta, ref_fai)
}
clairsto_ch = CLAIRSTO_SINGLE(clairsto_input_ch)
smallvar_merged_ch = SMALLVAR_MERGE_SINGLE(clairsto_ch)
smallvar_split_ch = SMALLVAR_SPLIT_SINGLE(smallvar_merged_ch)
smallvar_summary_ch = SMALLVAR_SUMMARY(smallvar_split_ch)
smallvar_cohort_input_ch = smallvar_merged_ch
.map { x -> x[1] }
.collect()
smallvar_cohort_table_ch = SMALLVAR_COHORT_TABLE(smallvar_cohort_input_ch)
/*
* MultiQC
*/
if( params.run_multiqc ) {
multiqc_input_ch = flagstat_ch
.mix(stats_ch)
.mix(mosdepth_ch)
.mix(cramino_ch)
.mix(full_sv_summary_single_ch)
.mix(full_sv_summary_cohort_ch)
.mix(bnd_summary_single_ch)
.mix(bnd_summary_cohort_ch)
.mix(nonbnd_summary_single_ch)
.mix(nonbnd_summary_cohort_ch)
.mix(smallvar_summary_ch)
.mix(smallvar_cohort_table_ch)
.collect()
MULTIQC(multiqc_input_ch)
}
bam_ch
sniffles_single_ch
cohort_ch
clairsto_ch
smallvar_merged_ch
sniffles2_plot_single_ch
sniffles2_plot_multi_ch
}
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
THE END
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/