-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathmain.nf
More file actions
340 lines (303 loc) · 12.8 KB
/
Copy pathmain.nf
File metadata and controls
340 lines (303 loc) · 12.8 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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#!/usr/bin/env nextflow
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nf-core/rnavar
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Github : https://github.com/nf-core/rnavar
Website: https://nf-co.re/rnavar
Slack : https://nfcore.slack.com/channels/rnavar
----------------------------------------------------------------------------------------
*/
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
IMPORT FUNCTIONS / MODULES / SUBWORKFLOWS / WORKFLOWS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
include { RNAVAR } from './workflows/rnavar'
include { PREPARE_GENOME } from './subworkflows/local/prepare_genome'
include { CACHE_DOWNLOAD_ENSEMBLVEP_SNPEFF } from './subworkflows/nf-core/cache_download_ensemblvep_snpeff'
include { UTILS_ANNOTATION_CACHE } from './subworkflows/nf-core/utils_annotation_cache'
include { PIPELINE_INITIALISATION } from './subworkflows/local/utils_nfcore_rnavar_pipeline'
include { PIPELINE_COMPLETION } from './subworkflows/local/utils_nfcore_rnavar_pipeline'
// MULTIQC
include { MULTIQC } from './modules/nf-core/multiqc'
include { methodsDescriptionText } from './subworkflows/local/utils_nfcore_rnavar_pipeline'
include { paramsSummaryMap } from 'plugin/nf-schema'
include { softwareVersionsToYAML } from 'plugin/nf-core-utils'
// tools selections
include { defineToolsList } from './subworkflows/local/utils_nfcore_rnavar_pipeline'
// references
include { getGenomeAttribute } from 'plugin/nf-core-utils'
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
GENOME PARAMETER VALUES
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
params.dbsnp = getGenomeAttribute('dbsnp')
params.dbsnp_tbi = getGenomeAttribute('dbsnp_tbi')
params.dict = getGenomeAttribute('dict')
params.exon_bed = getGenomeAttribute('exon_bed')
params.fasta = getGenomeAttribute('fasta')
params.fasta_fai = getGenomeAttribute('fasta_fai')
params.gff = getGenomeAttribute('gff')
params.gtf = getGenomeAttribute('gtf')
params.known_indels = getGenomeAttribute('known_indels')
params.known_indels_tbi = getGenomeAttribute('known_indels_tbi')
params.snpeff_db = getGenomeAttribute('snpeff_db')
params.star_index = getGenomeAttribute('star')
params.vep_cache_version = getGenomeAttribute('vep_cache_version')
params.vep_genome = getGenomeAttribute('vep_genome')
params.vep_species = getGenomeAttribute('vep_species')
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
RUN MAIN WORKFLOW
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
workflow {
main:
def tools = defineToolsList(
params.bam_csi_index,
params.extract_umi,
params.generate_gvcf,
params.skip_tools,
params.tools,
params.skip_baserecalibration,
params.skip_exon_bed_check,
params.skip_intervallisttools,
params.skip_multiqc,
params.skip_variantfiltration,
)
// SUBWORKFLOW: Run initialisation tasks
PIPELINE_INITIALISATION(
params.version,
params.validate_params,
params.monochrome_logs,
args,
params.outdir,
params.input,
params.help,
params.help_full,
params.show_hidden,
params.bam_csi_index,
params.dbsnp,
params.gff,
params.gtf,
params.known_indels,
tools,
params.umitools_bc_pattern,
)
// Download cache
if (params.download_cache) {
// Assuming that even if the cache is provided, if the user specify download_cache, rnavar will download the cache
ensemblvep_info = channel.of([[id: "${params.vep_cache_version}_${params.vep_genome}"], params.vep_genome, params.vep_species, params.vep_cache_version])
snpeff_info = channel.of([[id: "${params.snpeff_db}"], params.snpeff_db])
CACHE_DOWNLOAD_ENSEMBLVEP_SNPEFF(ensemblvep_info, snpeff_info, params.vep_cache_preflight_check)
snpeff_cache = CACHE_DOWNLOAD_ENSEMBLVEP_SNPEFF.out.snpeff_cache
vep_cache = CACHE_DOWNLOAD_ENSEMBLVEP_SNPEFF.out.ensemblvep_cache
}
else {
// Looks for cache information either locally or on the cloud
UTILS_ANNOTATION_CACHE(
params.vep_cache,
params.vep_cache_version,
params.vep_custom_args,
params.vep_genome,
params.vep_species,
(params.vep_cache && params.tools && (params.tools.split(',').contains("vep") || params.tools.split(',').contains('merge'))),
params.snpeff_cache,
params.snpeff_db,
(params.snpeff_cache && params.tools && (params.tools.split(',').contains("snpeff") || params.tools.split(',').contains('merge'))),
"Please refer to https://nf-co.re/rnavar/docs/usage/#how-to-customise-snpeff-and-vep-annotation for more information.",
)
snpeff_cache = UTILS_ANNOTATION_CACHE.out.snpeff_cache
vep_cache = UTILS_ANNOTATION_CACHE.out.ensemblvep_cache
}
vep_extra_files = []
if (params.dbnsfp && params.dbnsfp_tbi) {
vep_extra_files.add(file(params.dbnsfp, checkIfExists: true))
vep_extra_files.add(file(params.dbnsfp_tbi, checkIfExists: true))
}
else if (params.dbnsfp && !params.dbnsfp_tbi) {
System.err.println("DBNSFP: ${params.dbnsfp} has been provided with `--dbnsfp, but no dbnsfp_tbi has")
System.err.println("cf: https://nf-co.re/rnavar/parameters/#dbnsfp")
error("Execution halted due to dbnsfp inconsistency.")
}
if (params.spliceai_snv && params.spliceai_snv_tbi && params.spliceai_indel && params.spliceai_indel_tbi) {
vep_extra_files.add(file(params.spliceai_indel, checkIfExists: true))
vep_extra_files.add(file(params.spliceai_indel_tbi, checkIfExists: true))
vep_extra_files.add(file(params.spliceai_snv, checkIfExists: true))
vep_extra_files.add(file(params.spliceai_snv_tbi, checkIfExists: true))
}
// WORKFLOW: Run main workflow
NFCORE_RNAVAR(
PIPELINE_INITIALISATION.out.samplesheet,
PIPELINE_INITIALISATION.out.align,
snpeff_cache,
vep_cache,
vep_extra_files,
tools,
)
def collated_versions = softwareVersionsToYAML(
softwareVersions: channel.topic("versions"),
nextflowVersion: workflow.nextflow.version,
).collectFile(
storeDir: "${params.outdir}/pipeline_info",
name: 'nf_core_' + 'rnavar_software_' + 'mqc_' + 'versions.yml',
sort: true,
newLine: true,
)
def collated_reports = channel.topic("multiqc_files")
.map { _meta, _process, _tool, reports -> reports }
// MODULE: MultiQC
// Present summary of reads, alignment, duplicates, BSQR stats for all samples as well as workflow summary/parameters as single report
def multiqc_report = channel.empty()
// MULTIQC
def multiqc_files = channel.empty()
multiqc_files = multiqc_files.mix(collated_versions)
multiqc_files = multiqc_files.mix(collated_reports)
def summary_params = paramsSummaryMap(workflow, parameters_schema: "nextflow_schema.json")
def workflow_summary = channel.value(paramsSummaryMultiqc(summary_params))
def multiqc_custom_methods_description = params.multiqc_methods_description ? file(params.multiqc_methods_description, checkIfExists: true) : file("${projectDir}/assets/methods_description_template.yml", checkIfExists: true)
def methods_description = channel.value(methodsDescriptionText(multiqc_custom_methods_description))
multiqc_files = multiqc_files.mix(workflow_summary.collectFile(name: 'workflow_summary_mqc.yaml'))
multiqc_files = multiqc_files.mix(methods_description.collectFile(name: 'methods_description_mqc.yaml', sort: true))
MULTIQC(
multiqc_files.flatten().collect().map { files ->
[
[id: 'rnavar'],
files,
params.multiqc_config
? file(params.multiqc_config, checkIfExists: true)
: file("${projectDir}/assets/multiqc_config.yml", checkIfExists: true),
params.multiqc_logo ? file(params.multiqc_logo, checkIfExists: true) : [],
[],
[],
]
}.filter { ('multiqc' in tools) }
)
multiqc_report = MULTIQC.out.report.map { _meta, report -> [report] }.toList()
// SUBWORKFLOW: Run completion tasks
PIPELINE_COMPLETION(
params.email,
params.email_on_fail,
params.plaintext_email,
params.outdir,
params.monochrome_logs,
multiqc_report,
)
publish:
multiqc = MULTIQC.out.data.mix(MULTIQC.out.plots, MULTIQC.out.report)
reports = channel.topic("multiqc_files").filter { _meta, _process, tool, _file ->
return !(tool == 'gatk4' || (tool == 'snpeff' && !('snpeff' in tools)))
}
}
output {
multiqc {
path "reports/multiqc"
}
reports {
path { meta, _process, tool, file ->
file >> "reports/${tool}/${meta.id}/"
}
}
}
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
NAMED WORKFLOWS FOR PIPELINE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
//
// WORKFLOW: Run main analysis pipeline depending on type of input
//
workflow NFCORE_RNAVAR {
take:
samplesheet
align
snpeff_cache
vep_cache
vep_extra_files
tools
main:
PREPARE_GENOME(
params.bcftools_annotations,
params.bcftools_annotations_tbi,
params.dbsnp,
params.dbsnp_tbi,
params.dict,
params.exon_bed,
params.fasta,
params.fasta_fai,
params.gff,
params.gtf,
params.known_indels,
params.known_indels_tbi,
params.star_index,
params.feature_type,
align,
params.genome ?: "genome",
tools,
)
// WORKFLOW: Run pipeline
RNAVAR(
samplesheet,
PREPARE_GENOME.out.bcfann,
PREPARE_GENOME.out.bcfann_tbi,
params.bcftools_columns ? channel.fromPath(params.bcftools_columns).collect() : false,
params.bcftools_header_lines ? channel.fromPath(params.bcftools_header_lines).collect() : channel.empty(),
PREPARE_GENOME.out.dbsnp,
PREPARE_GENOME.out.dbsnp_tbi,
PREPARE_GENOME.out.dict,
PREPARE_GENOME.out.exon_bed,
PREPARE_GENOME.out.fasta,
PREPARE_GENOME.out.fasta_fai,
PREPARE_GENOME.out.gtf,
PREPARE_GENOME.out.known_sites,
PREPARE_GENOME.out.known_sites_tbi,
PREPARE_GENOME.out.star_index,
snpeff_cache,
params.snpeff_db,
params.vep_genome,
params.vep_species,
params.vep_cache_version,
params.vep_include_fasta,
vep_cache,
vep_extra_files,
params.aligner,
params.star_ignore_sjdbgtf,
tools,
)
}
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FUNCTIONS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
// Get workflow summary for MultiQC
def paramsSummaryMultiqc(summary_params) {
def summary_section = ''
summary_params
.keySet()
.each { group ->
def group_params = summary_params.get(group)
// This gets the parameters of that particular group
if (group_params) {
summary_section += " <p style=\"font-size:110%\"><b>${group}</b></p>\n"
summary_section += " <dl class=\"dl-horizontal\">\n"
group_params
.keySet()
.sort()
.each { param ->
summary_section += " <dt>${param}</dt><dd><samp>${group_params.get(param) ?: '<span style=\"color:#999999;\">N/A</a>'}</samp></dd>\n"
}
summary_section += " </dl>\n"
}
}
def yaml_file_text = "id: '${workflow.manifest.name.replace('/', '-')}-summary'\n" as String
yaml_file_text += "description: ' - this information is collected when the pipeline is started.'\n"
yaml_file_text += "section_name: '${workflow.manifest.name} Workflow Summary'\n"
yaml_file_text += "section_href: 'https://github.com/${workflow.manifest.name}'\n"
yaml_file_text += "plot_type: 'html'\n"
yaml_file_text += "data: |\n"
yaml_file_text += "${summary_section}"
return yaml_file_text
}