forked from genomic-medicine-sweden/jasen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.nf
183 lines (157 loc) · 7.28 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
#!/usr/bin/env nextflow
// Example of an bacterial analysis pipeline
nextflow.enable.dsl=2
include { samtools_sort as samtools_sort_one; samtools_sort as samtools_sort_two; samtools_index as samtools_index_one; samtools_index as samtools_index_two } from './nextflow-modules/modules/samtools/main.nf'
include { sambamba_markdup } from './nextflow-modules/modules/sambamba/main.nf'
include { freebayes } from './nextflow-modules/modules/freebayes/main.nf' addParams( args: ['-C', '2', '-F', '0.2', '--pooled-continuous'] )
include { spades } from './nextflow-modules/modules/spades/main.nf' addParams( args: ['--only-assembler'] )
include { save_analysis_metadata; mask_polymorph_assembly; export_to_cdm; export_to_cgviz } from './nextflow-modules/modules/cmd/main.nf'
include { quast } from './nextflow-modules/modules/quast/main.nf' addParams( args: [] )
include { mlst } from './nextflow-modules/modules/mlst/main.nf' addParams( args: [] )
include { ariba_run } from './nextflow-modules/modules/ariba/main.nf' addParams( args: ['--force'] )
include { ariba_summary } from './nextflow-modules/modules/ariba/main.nf' addParams( args: ['--col_filter', 'n', '--row_filter', 'n'] )
include { kraken } from './nextflow-modules/modules/kraken/main.nf' addParams( args: ['--gzip-compressed'] )
include { bracken } from './nextflow-modules/modules/bracken/main.nf' addParams( args: ['-r', '150'] )
include { bwa_mem as bwa_mem_ref; bwa_mem as bwa_mem_dedup; bwa_index } from './nextflow-modules/modules/bwa/main.nf' addParams( args: ['-M'] )
include { chewbbaca_allelecall; chewbbaca_split_results; chewbbaca_split_missing_loci } from './nextflow-modules/modules/chewbbaca/main.nf' addParams( args: ['--fr'] )
include { resfinder } from './nextflow-modules/modules/resfinder/main.nf' addParams( args: [] )
include { virulencefinder } from './nextflow-modules/modules/virulencefinder/main.nf' addParams( args: [] )
process ariba_summary_to_json {
tag "${sampleName}"
label "process_low"
publishDir params.outdir,
mode: params.publishDirMode,
overwrite: params.publishDirOverwrite
input:
tuple val(sampleName), path(report), path(summary)
path reference
output:
tuple val(sampleName), path("${output}"), emit: output
script:
output = "${summary.simpleName}_export.json"
"""
ariba2json.pl ${reference} ${summary} ${report} > ${output}
"""
}
process post_align_qc {
tag "${sampleName}"
label "process_low"
publishDir params.outdir,
mode: params.publishDirMode,
overwrite: params.publishDirOverwrite
input:
tuple val(sampleName), path(bam)
path bai
path reference
output:
tuple val(sampleName), path(output)
script:
output = "${sampleName}_bwa.qc"
"""
postaln_qc.pl ${bam} ${reference} ${sampleName} ${task.cpus} > ${output}
"""
}
workflow bacterial_default {
reads = Channel .fromPath(params.csv)
.splitCsv(header:true)
.map{ row -> tuple(row.id, tuple(file(row.read1), file(row.read2))) }
// load references
genomeReference = file(params.genomeReference, checkIfExists: true)
genomeReferenceDir = file(genomeReference.getParent(), checkIfExists: true)
aribaReference = file(params.aribaReference, checkIfExists: true)
aribaReferenceDir = file(aribaReference.getParent(), checkIfExists: true)
// databases
mlstDb = file(params.mlstBlastDb, checkIfExists: true)
cgmlstDb = file(params.cgmlstDb, checkIfExists: true)
cgmlstSchema = file(params.cgmlstSchema, checkIfExists: true)
trainingFile = file(params.trainingFile, checkIfExists: true)
resfinderDb = file(params.resfinderDb, checkIfExists: true)
pointfinderDb = file(params.pointfinderDb, checkIfExists: true)
virulencefinderDb = file(params.virulencefinderDb, checkIfExists: true)
main:
runInfo = save_analysis_metadata()
// assembly and qc processing
referenceMapping = bwa_mem_ref(reads, genomeReferenceDir)
sortedReferenceMapping = samtools_sort_one(referenceMapping, [])
sortedReferenceMappingIdx = samtools_index_one(sortedReferenceMapping.bam)
//sambamba_markdup(sortedReferenceMapping.bam, sortedReferenceMappingIdx)
sortedReferenceMapping.bam
.join(sortedReferenceMappingIdx)
.multiMap { id, bam, bai ->
bam: tuple(id, bam)
bai: bai
}
.set{ post_align_qc_ch }
postQc = post_align_qc(post_align_qc_ch.bam, post_align_qc_ch.bai, cgmlstSchema)
assembly = spades(reads)
// mask polymorph regions
assemblyBwaIdx = bwa_index(assembly)
reads
.join(assemblyBwaIdx)
.multiMap { id, reads, bai ->
reads: tuple(id, reads)
bai: bai
}
.set { bwa_mem_dedup_ch }
assemblyMapping = bwa_mem_dedup(bwa_mem_dedup_ch.reads, bwa_mem_dedup_ch.bai)
sortedAssemblyMapping = samtools_sort_two(assemblyMapping, [])
sortedAssemblyMappingIdx = samtools_index_two(sortedAssemblyMapping.bam)
// construct freebayes input channels
assembly
.join(sortedAssemblyMapping.bam)
.join(sortedAssemblyMappingIdx)
.multiMap { id, fasta, bam, bai ->
assembly: tuple(id, fasta)
mapping: tuple(bam, bai)
}
.set { freebayes_ch }
maskedRegionsVcf = freebayes(freebayes_ch.assembly, freebayes_ch.mapping)
//maskedRegionsVcf = freebayes(assembly.join(sortedAssemblyMappingIdx).join(sortedAssemblyMapping.bam))
maskedAssembly = mask_polymorph_assembly(assembly.join(maskedRegionsVcf))
assemblyQc = quast(assembly, genomeReference)
mlstResult = mlst(assembly, params.specie, mlstDb)
// split assemblies and id into two seperate channels to enable re-pairing
// of results and id at a later stage. This to allow batch cgmlst analysis
// maskedAssembly
// .multiMap { id, fasta ->
// idx: id
// fasta: fasta
// }
// .set{ chewbbaca_fasta_ch }
// chewbbaca_fasta_ch.idx.collect().view()
// chewbbaca_fasta_ch.fasta.collect().view()
chewbbacaResult = chewbbaca_allelecall(maskedAssembly, cgmlstDb, trainingFile)
//chewbbaca_split_results(chewbbacaResult.results)
//chewbbaca_split_missing_loci(chewbbacaResult.missing)
// end point
export_to_cdm(chewbbacaResult.join(assemblyQc).join(postQc))
// ariba path
aribaReport = ariba_run(reads, aribaReferenceDir)
aribaSummary = ariba_summary(aribaReport)
aribaJson = ariba_summary_to_json(aribaReport.join(aribaSummary), aribaReference)
// perform resistance prediction
resfinderOutput = resfinder(reads, params.specie, resfinderDb, pointfinderDb)
virulencefinderOutput = virulencefinder(reads, params.useVirulenceDbs, virulencefinderDb)
// combine results for export
combinedOutput = assemblyQc
.join(mlstResult.json)
.join(chewbbacaResult)
.join(aribaJson)
.join(resfinderOutput.json)
.join(virulencefinderOutput.json)
// Using kraken for species identificaiton
if( params.useKraken ) {
krakenDb = file(params.krakenDb, checkIfExists: true)
krakenReport = kraken(reads, krakenDb).report
brackenOutput = bracken(krakenReport, krakenDb).output
combinedOutput = combinedOutput.join(brackenOutput)
}
export_to_cgviz(
runInfo,
resfinderOutput.meta.join(virulencefinderOutput.meta),
combinedOutput
)
emit:
cgviz_import = export_to_cgviz.output
cdm_import = export_to_cdm.output
}