-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.nf
222 lines (199 loc) · 7.57 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
#!/usr/bin/env nextflow
nextflow.enable.dsl=2
import java.nio.file.Paths
log.info """\
======================================
C A L L - S S V N F P I P E L I N E
======================================
Boutros Lab
Current Configuration:
- pipeline:
name: ${workflow.manifest.name}
version: ${workflow.manifest.version}
- input:
samples: ${params.samples_to_process}
reference_fasta: "${params.reference_fasta}"
reference_fasta_index: "${params.reference_fasta}.fai"
exclusion_file: "${params.exclusion_file}"
filter_condition: "${params.filter_condition}"
- output:
output_dir: "${params.output_dir}"
log_output_dir: "${params.log_output_dir}"
- options:
save_intermediate_files: ${params.save_intermediate_files}
SV caller(s): ${params.algorithm}
- tools:
DELLY: ${params.delly_version}
BCFtools: ${params.bcftools_version}
Manta: ${params.manta_version}
GRIDSS2: ${params.gridss_version}
PipeVal: ${params.pipeval_version}
------------------------------------
Starting workflow...
------------------------------------
"""
.stripIndent()
include { run_validate_PipeVal } from "./external/pipeline-Nextflow-module/modules/PipeVal/validate/main.nf" addParams(
options: [ docker_image_version: params.pipeval_version ]
)
include { query_SampleName_BCFtools; filter_BCF_BCFtools } from './module/bcftools' addParams(
workflow_output_dir: "${params.output_dir_base}/DELLY-${params.delly_version}"
)
include { call_sSV_Delly; filter_sSV_Delly } from './module/delly' addParams(
workflow_output_dir: "${params.output_dir_base}/DELLY-${params.delly_version}"
)
include { call_sSV_Manta } from './module/manta' addParams(
workflow_output_dir: "${params.output_dir_base}/Manta-${params.manta_version}"
)
include { preprocess_BAM_GRIDSS; run_assembly_GRIDSS } from './module/gridss' addParams(
workflow_output_dir: "${params.output_dir_base}/GRIDSS-${params.gridss_version}"
)
include { generate_sha512 as generate_sha512_BCFtools } from './module/sha512' addParams(
workflow_output_dir: "${params.output_dir_base}/DELLY-${params.delly_version}"
)
include { generate_sha512 as generate_sha512_Manta } from './module/sha512' addParams(
workflow_output_dir: "${params.output_dir_base}/Manta-${params.manta_version}"
)
// Returns the index file for the given bam
def indexFile(bam) {
if (bam.endsWith('.bam')) {
return "${bam}.bai"
} else {
throw new Exception("Index file for ${bam} file type not supported. Use .bam!")
}
}
Channel.from(params.samples_to_process)
.map{ sample -> ['index': indexFile(sample.path)] + sample }
.set{ input_ch_samples_with_index }
Channel.from(params.samples_to_process)
.map{ sample -> [sample.id, sample.path, indexFile(sample.path)] }
.set{ gridss_ch }
input_ch_samples_with_index
.map{ sample -> [sample.path, sample.index] }
.flatten()
.set{ input_validation }
if (params.verbose){
input_validation.view()
}
tumor_id_bam_bai = input_ch_samples_with_index
.filter{ it.sample_type == 'tumor' }
.map{ it -> [it.id, it.path, it.index] }
normal_bam_bai = input_ch_samples_with_index
.filter{ it.sample_type == 'normal' }
.map{ it -> [it.path, it.index] }
input_paired_bams_ch = tumor_id_bam_bai.combine(normal_bam_bai)
if (params.verbose){
input_paired_bams_ch.view()
}
reference_fasta_index = "${params.reference_fasta}.fai"
// Collect GRIDSS reference files
gridss_reference_files = Channel.fromPath( "${params.gridss_reference_fasta}.*", checkIfExists: true ).collect()
workflow {
/**
* Validate the input bams
*/
run_validate_PipeVal(input_validation)
// Collect and store input validation output
run_validate_PipeVal.out.validation_result.collectFile(
name: 'input_validation.txt',
storeDir: "${params.output_dir_base}/validation/run_validate_PipeVal"
)
/**
* Call "delly call -x hg19.excl -o t1.bcf -g hg19.fa tumor1.bam normal1.bam" per paired (tumor sample, normal sample)
* The sv are stored in call_sSV_Delly.out.nt_call_bcf
* also create call_sSV_Delly.out.samples per paired (tumor sample, normal sample)
*/
if ('delly' in params.algorithm) {
call_sSV_Delly(
input_paired_bams_ch,
params.reference_fasta,
reference_fasta_index,
params.exclusion_file
)
/**
* calling "delly filter -f somatic -s samples.tsv -o t1.pre.bcf t1.bcf" requires a samples.tsv, which should look like:
* sample_name sample_type
* S2_v1.1.5 tumor
* HG002.N normal
*
* Use bcftools query -l to get the sample names out of call_sSV_Delly.out.nt_call_bcf
* Further generate BCFtools_${params.bcftools_version}_${params.dataset_id}_${tumor_id}_query-tumor-normal-name.tsv which will be used by delly filter
* Note, the order of samples in call_sSV_Delly.out.nt_call_bcf is determined by the order of samples in delly call.
* For example,
* delly call \
* -g /tmp/ref/genome/genome.fa \
* -x /tmp/ref/delly/human.hg38.excl.tsv \
* -o /tmp/output/output.bcf \
* /tmp/bams/HG002.N-0.bam \
* /tmp/bams/S2.T-0.bam"
* bcftools query -l /tmp/output/output.bcf will yield
* HG002.N
* S2_v1.1.5
* If you put /tmp/bams/S2.T-0.bam in front of /tmp/bams/HG002.N-0.bam, bcftools query -l /tmp/output/output.bcf will yield
* S2_v1.1.5
* HG002.N
*/
query_SampleName_BCFtools(
call_sSV_Delly.out.nt_call_bcf,
call_sSV_Delly.out.samples,
call_sSV_Delly.out.tumor_id
)
/**
* Call "delly filter -f somatic -o t1.pre.bcf -s samples.tsv t1.bcf"
* by using the call_sSV_Delly.out.samples and call_sSV_Delly.out.nt_call_bcf
*/
filter_sSV_Delly(
query_SampleName_BCFtools.out.samples,
call_sSV_Delly.out.nt_call_bcf,
call_sSV_Delly.out.nt_call_bcf_csi,
call_sSV_Delly.out.tumor_id
)
/**
* Filter the output bcf from filter_sSV_Delly.
* The default filter_condition is "FILTER=='PASS'", which filters out NonPass calls.
*/
filter_BCF_BCFtools(
filter_sSV_Delly.out.somatic_bcf,
params.filter_condition,
call_sSV_Delly.out.tumor_id
)
/**
* Generate one sha512 checksum for DELLY's output files.
*/
generate_sha512_BCFtools(
filter_BCF_BCFtools.out.nonPassCallsFiltered_and_csi.flatten()
)
}
if ('manta' in params.algorithm) {
call_sSV_Manta(
input_paired_bams_ch,
params.reference_fasta,
reference_fasta_index
)
/**
* Generate one sha512 checksum for the output files.
*/
generate_sha512_Manta(
call_sSV_Manta.out.manta_vcfs.flatten()
)
}
if ('gridss2' in params.algorithm) {
preprocess_BAM_GRIDSS(
gridss_ch,
params.gridss_reference_fasta,
gridss_reference_files
)
gridss_preprocess_dir = preprocess_BAM_GRIDSS.out.gridss_preprocess
.flatten()
.map { parentdir -> parentdir.getParent() }
.unique()
.collect()
run_assembly_GRIDSS(
input_paired_bams_ch,
gridss_preprocess_dir,
params.gridss_reference_fasta,
gridss_reference_files,
params.gridss_blacklist
)
}
}