-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmain.nf
More file actions
290 lines (268 loc) · 11.9 KB
/
main.nf
File metadata and controls
290 lines (268 loc) · 11.9 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#! /usr/bin/env nextflow
// Functions
include { assembliesFromStage as preassembledInput } from "./modules/local/functions"
include { setAssemblyStage } from "./modules/local/functions"
// Data import
include { PREPARE_INPUT } from "./subworkflows/local/prepare_input/main"
// Database preparation
include { BUILD_FASTK_DATABASE as BUILD_FASTK_HIFI_DATABASE } from "./subworkflows/local/build_fastk_database/main"
include { BUILD_FASTK_DATABASE as BUILD_FASTK_HIC_DATABASE } from "./subworkflows/local/build_fastk_database/main"
include { BUILD_MERYL_DATABASE as BUILD_MERYL_HIFI_DATABASE } from "./subworkflows/local/build_meryl_database/main"
include { BUILD_MERYL_DATABASE as BUILD_MERYL_HIC_DATABASE } from "./subworkflows/local/build_meryl_database/main"
// Data conversion
include { CONVERT_FASTQ_CRAM } from "./subworkflows/local/02_convert_fastq_cram/main"
// Data inspection
include { INSPECT_DATA } from "./subworkflows/local/01_inspect_data/main"
// Assembly
include { ASSEMBLE } from "./subworkflows/local/03_assemble/main"
// Decontamination
include { DECONTAMINATE } from "./subworkflows/local/04_decontaminate/main"
// Purge duplicates
include { PURGE_DUPLICATES } from "./subworkflows/local/05_purge_dups/main"
// Scaffold
include { SCAFFOLD } from "./subworkflows/local/07_scaffold/main"
// Curation
include { SCAFFOLD_CURATION } from "./subworkflows/local/08_scaffold_curation/main"
// Evaluate assemblies
include { COMPARE_ASSEMBLIES } from "./subworkflows/local/compare_assemblies/main"
include { EVALUATE_ASSEMBLY } from "./subworkflows/local/evaluate_assembly/main"
// Align RNAseq
include { ALIGN_RNASEQ } from "./subworkflows/local/09_align_rnaseq/main"
// Report
include { ASSEMBLY_REPORT } from "./subworkflows/local/assembly_report/main"
/*
* Development: See docs/development to understand the workflow programming model and
* how channel contents are structured.
*/
workflow {
// Define constants
def workflow_permitted_stages = [
'inspect', // 01 - Read inspection
'preprocess', // 02 - Read preprocessing
'assemble', // 03 - Assembly
'screen', // 04 - Contamination screening
'purge', // 05 - Duplicate purging
'polish', // 06 - Error polishing
'scaffold', // 07 - Scaffolding
'curate', // 08 - Rapid curation
'alignRNA' // 09 - Align RNAseq data
]
// Check input
def workflow_steps = params.steps.tokenize(",")
if ( ! workflow_steps.every { step -> step in workflow_permitted_stages } ) {
error "Unrecognised workflow step in $params.steps ( $workflow_permitted_stages )"
}
// The primary workflow for the Earth Biogenome Project Pilot
log.info("""
Running NBIS Earth Biogenome Project Assembly workflow.
""")
// Setup sink channels
ch_multiqc_files = channel.value( file(params.multiqc_assembly_report_config, checkIfExists: true) )
ch_versions = channel.empty()
// Read in data
PREPARE_INPUT (
params.input
)
ch_evaluate_assemblies = PREPARE_INPUT.out.assemblies
// Create Cram and trim
CONVERT_FASTQ_CRAM ( PREPARE_INPUT.out.hic, params.hic_type.startsWith('arima') )
// Build necessary databases
// TODO: Migrate back to Meryl. Genome inspection missing KATGC and SMUDGEPLOT for meryldb
BUILD_FASTK_HIFI_DATABASE ( PREPARE_INPUT.out.hifi )
BUILD_FASTK_HIC_DATABASE ( CONVERT_FASTQ_CRAM.out.fastq )
BUILD_MERYL_HIFI_DATABASE ( PREPARE_INPUT.out.hifi )
BUILD_MERYL_HIC_DATABASE ( CONVERT_FASTQ_CRAM.out.fastq )
ch_versions = ch_versions.mix(
CONVERT_FASTQ_CRAM.out.versions,
BUILD_FASTK_HIFI_DATABASE.out.versions,
BUILD_FASTK_HIC_DATABASE.out.versions,
BUILD_MERYL_HIFI_DATABASE.out.versions,
BUILD_MERYL_HIC_DATABASE.out.versions,
)
// Data inspection
ch_hifi_kmer_cov = PREPARE_INPUT.out.hifi_merged.map { meta, _reads -> tuple(meta, []) }
if ( 'inspect' in workflow_steps ) {
// QC Steps
INSPECT_DATA(
PREPARE_INPUT.out.hifi,
PREPARE_INPUT.out.hic,
BUILD_FASTK_HIFI_DATABASE.out.fastk_hist_ktab,
BUILD_FASTK_HIC_DATABASE.out.fastk_hist_ktab
)
ch_hifi_kmer_cov = INSPECT_DATA.out.hifi_kmer_cov
ch_multiqc_files = ch_multiqc_files.mix( INSPECT_DATA.out.logs )
ch_versions = ch_versions.mix( INSPECT_DATA.out.versions )
}
// Preprocess data
if ( 'preprocess' in workflow_steps ) {
// Adapter filtering etc
// Subsampling
// Host contamination filter
}
// Assemble
if ( 'assemble' in workflow_steps ) {
// Run assemblers
ASSEMBLE (
PREPARE_INPUT.out.hifi_merged,
PREPARE_INPUT.out.hic,
params.oatkdb ? file(params.oatkdb, checkIfExists: true, type: 'dir') : channel.empty(),
params.nuclear_assembly_mode,
params.organelle_assembly_mode
)
ch_evaluate_assemblies = ch_evaluate_assemblies.mix( ASSEMBLE.out.raw_assemblies )
ch_raw_assemblies = ASSEMBLE.out.raw_assemblies
ch_multiqc_files = ch_multiqc_files.mix( ASSEMBLE.out.logs )
ch_versions = ch_versions.mix( ASSEMBLE.out.versions )
} else {
ch_raw_assemblies = channel.empty() // No assemblies from a previous stage
}
ch_raw_assemblies = ch_raw_assemblies.mix(
preassembledInput( PREPARE_INPUT.out.assemblies, 'raw' )
).dump(tag: 'Assemblies: Raw', pretty: true)
// Contamination screen
ch_to_screen = setAssemblyStage (
ch_raw_assemblies,
'decontaminated' // Set assembly stage now for filenaming
).dump(tag: 'Assemblies: to screen', pretty: true)
if ( 'screen' in workflow_steps ) {
DECONTAMINATE( ch_to_screen )
ch_evaluate_assemblies = ch_evaluate_assemblies.mix( DECONTAMINATE.out.assemblies )
ch_cleaned_assemblies = DECONTAMINATE.out.assemblies
ch_multiqc_files = ch_multiqc_files.mix( DECONTAMINATE.out.logs )
ch_versions = ch_versions.mix(DECONTAMINATE.out.versions)
} else {
ch_cleaned_assemblies = ch_to_screen
}
ch_cleaned_assemblies = ch_cleaned_assemblies.mix (
preassembledInput( PREPARE_INPUT.out.assemblies, 'decontaminated' )
).dump(tag: 'Assemblies: Cleaned', pretty: true)
// Purge duplicates
ch_to_purge = setAssemblyStage (
ch_cleaned_assemblies,
'purged' // Set assembly stage now for filenaming
).dump(tag: 'Assemblies: to purge', pretty: true)
if ( 'purge' in workflow_steps ) {
PURGE_DUPLICATES (
ch_to_purge,
PREPARE_INPUT.out.hifi_merged,
ch_hifi_kmer_cov
)
ch_evaluate_assemblies = ch_evaluate_assemblies.mix( PURGE_DUPLICATES.out.assemblies )
ch_purged_assemblies = PURGE_DUPLICATES.out.assemblies
ch_multiqc_files = ch_multiqc_files.mix( PURGE_DUPLICATES.out.logs )
ch_versions = ch_versions.mix( PURGE_DUPLICATES.out.versions )
} else {
ch_purged_assemblies = ch_to_purge
}
ch_purged_assemblies = ch_purged_assemblies.mix(
preassembledInput( PREPARE_INPUT.out.assemblies, 'purged' )
).dump(tag: 'Assemblies: Purged', pretty: true)
// Polish
ch_to_polish = setAssemblyStage (
ch_purged_assemblies,
'polished' // Set assembly stage now for filenaming
).dump(tag: 'Assemblies: to polish', pretty: true)
if ( 'polish' in workflow_steps ) {
// Run polishers
ch_polished_assemblies = ch_to_polish
} else {
ch_polished_assemblies = ch_to_polish
}
ch_polished_assemblies = ch_polished_assemblies.mix(
preassembledInput( PREPARE_INPUT.out.assemblies, 'polished' )
).dump(tag: 'Assemblies: Polished', pretty: true)
// Scaffold
ch_to_scaffold = setAssemblyStage (
ch_polished_assemblies,
'scaffolded' // Set assembly stage now for filenaming
).dump(tag: 'Assemblies: to scaffold', pretty: true)
if ( 'scaffold' in workflow_steps ) {
SCAFFOLD (
ch_to_scaffold,
CONVERT_FASTQ_CRAM.out.fastq
)
ch_evaluate_assemblies = ch_evaluate_assemblies.mix( SCAFFOLD.out.assemblies )
ch_scaffolded_assemblies = SCAFFOLD.out.assemblies
ch_multiqc_files = ch_multiqc_files.mix( SCAFFOLD.out.logs )
ch_versions = ch_versions.mix( SCAFFOLD.out.versions )
} else {
ch_scaffolded_assemblies = ch_to_scaffold
}
ch_scaffolded_assemblies = ch_scaffolded_assemblies.mix(
preassembledInput( PREPARE_INPUT.out.assemblies, 'scaffolded' )
).dump(tag: 'Assemblies: Scaffolded', pretty: true)
// Curate
ch_to_curate = setAssemblyStage (
ch_scaffolded_assemblies,
'curated' // Set assembly stage now for filenaming
).dump(tag: 'Assemblies: to curate', pretty: true)
if ( 'curate' in workflow_steps ) {
SCAFFOLD_CURATION (
ch_to_curate,
CONVERT_FASTQ_CRAM.out.fastq,
PREPARE_INPUT.out.hifi
)
ch_versions = ch_versions.mix( SCAFFOLD_CURATION.out.versions )
}
preassembledInput( PREPARE_INPUT.out.assemblies, 'curated' ).dump(tag: 'Assemblies: Curated')
// Align RNAseq
if( 'alignRNA' in workflow_steps ) {
ALIGN_RNASEQ (
PREPARE_INPUT.out.rnaseq,
PREPARE_INPUT.out.assemblies // TODO: Select assembly stage
.map { meta, assembly -> [ meta, assembly.pri_fasta ] }
)
}
// Evaluate assemblies
COMPARE_ASSEMBLIES ( ch_evaluate_assemblies )
EVALUATE_ASSEMBLY (
ch_evaluate_assemblies
.toList().flatMap(), // Introduce bottleneck to delay evaluation until previous steps are performed
BUILD_FASTK_HIFI_DATABASE.out.fastk_hist_ktab,
BUILD_MERYL_HIFI_DATABASE.out.uniondb
)
ch_multiqc_files = ch_multiqc_files.mix(
COMPARE_ASSEMBLIES.out.logs,
EVALUATE_ASSEMBLY.out.logs
)
ch_versions = ch_versions.mix(
COMPARE_ASSEMBLIES.out.versions,
EVALUATE_ASSEMBLY.out.versions
)
// Assembly report
ASSEMBLY_REPORT(
PREPARE_INPUT.out.sample_meta.map{ meta ->
[
meta,
file(params.quarto_assembly_report, checkIfExists: true),
files(params.quarto_assembly_report_aux_files, checkIfExists: true)
]
},
ch_multiqc_files,
ch_versions,
[
diagnostics: "debug" in workflow.profile.tokenize(","),
nuclear_assembly_mode: params.nuclear_assembly_mode,
organelle_assembly_mode: params.organelle_assembly_mode in ['contigs', 'reads']
] + workflow_permitted_stages.collectEntries{ step ->
[(step): step in params.steps.tokenize(",")]
}
)
workflow.onComplete = {
if( workflow.success ){
log.info("""
Thank you for using the NBIS Earth Biogenome Project Assembly workflow.
The workflow completed successfully.
Results are located in the folder: $params.outdir
""")
} else {
log.info("""
Thank you for using the NBIS Earth Biogenome Project Assembly workflow.
The workflow completed unsuccessfully.
Please read over the error message. If you are unable to solve it, please
post an issue at https://github.com/NBISweden/Earth-Biogenome-Project-pilot/issues
where we will do our best to help.
""")
}
}
}