-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.nf
192 lines (166 loc) · 8.52 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
#!/usr/bin/env nextflow
nextflow.enable.dsl=2
log.info """\
=======================================
C A L L - G 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:
sample: ${params.sample_to_process}
reference_fasta: ${params.reference_fasta}
reference_fasta_index: "${params.reference_fasta}.fai"
exclusion_file: ${params.exclusion_file}
mappability_map: ${params.mappability_map}
- output:
output_dir: ${params.output_dir}
log_output_dir: ${params.log_output_dir}
- options:
save_intermediate_files: ${params.save_intermediate_files}
run_qc: ${params.run_qc}
map_qual: ${params.map_qual}
run_delly: ${params.run_delly}
run_manta: ${params.run_manta}
- tools:
delly: ${params.delly_version}
manta: ${params.manta_version}
bcftools: ${params.bcftools_version}
vcftools: ${params.vcftools_version}
rtgtools: ${params.rtgtools_version}
validation tool: ${params.pipeval_version}
------------------------------------
Starting workflow...
------------------------------------
"""
.stripIndent()
include { generate_standard_filename } from './external/pipeline-Nextflow-module/modules/common/generate_standardized_filename/main.nf'
include { run_validate_PipeVal } from './external/pipeline-Nextflow-module/modules/PipeVal/validate/main.nf' addParams(
options: [ docker_image_version: params.pipeval_version ]
)
include { call_gSV_Delly; call_gCNV_Delly; regenotype_gSV_Delly; regenotype_gCNV_Delly } from './module/delly' addParams(
output_filename: generate_standard_filename(
"DELLY-${params.delly_version}",
params.dataset_id,
"${params.sample}",
[:]
),
workflow_output_dir: "${params.output_dir_base}/DELLY-${params.delly_version}",
workflow_log_dir: "${params.log_output_dir}/process-log/DELLY-${params.delly_version}"
)
include { call_gSV_Manta } from './module/manta' addParams(
output_filename: generate_standard_filename(
"Manta-${params.manta_version}",
params.dataset_id,
"${params.sample}",
[:]
),
workflow_output_dir: "${params.output_dir_base}/Manta-${params.manta_version}",
workflow_log_dir: "${params.log_output_dir}/process-log/Manta-${params.manta_version}"
)
include { convert_BCF2VCF_BCFtools as convert_gSV_BCF2VCF_BCFtools; convert_BCF2VCF_BCFtools as convert_gCNV_BCF2VCF_BCFtools } from './module/bcftools' addParams(
workflow_output_dir: "${params.output_dir_base}/DELLY-${params.delly_version}",
workflow_log_dir: "${params.log_output_dir}/process-log/DELLY-${params.delly_version}"
)
include { run_vcfstats_RTGTools as run_gSV_vcfstats_RTGTools; run_vcfstats_RTGTools as run_gCNV_vcfstats_RTGTools } from './module/rtgtools' addParams(
workflow_output_dir: "${params.output_dir_base}/DELLY-${params.delly_version}",
workflow_log_dir: "${params.log_output_dir}/process-log/DELLY-${params.delly_version}"
)
include { run_vcf_validator_VCFtools as run_gSV_vcf_validator_VCFtools; run_vcf_validator_VCFtools as run_gCNV_vcf_validator_VCFtools } from './module/vcftools' addParams(
workflow_output_dir: "${params.output_dir_base}/DELLY-${params.delly_version}",
workflow_log_dir: "${params.log_output_dir}/process-log/DELLY-${params.delly_version}"
)
include { run_sha512sum as run_sha512sum_gSV_Delly; run_sha512sum as run_sha512sum_gCNV_Delly; run_sha512sum as run_sha512sum_regeno_gSV_Delly; run_sha512sum as run_sha512sum_regeno_gCNV_Delly } from './module/sha512' addParams(
workflow_output_dir: "${params.output_dir_base}/DELLY-${params.delly_version}",
workflow_log_dir: "${params.log_output_dir}/process-log/DELLY-${params.delly_version}"
)
include { run_sha512sum as run_sha512sum_Manta } from './module/sha512' addParams(
workflow_output_dir: "${params.output_dir_base}/Manta-${params.manta_version}",
workflow_log_dir: "${params.log_output_dir}/process-log/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.sample_to_process)
.map{ sample -> ['index': indexFile(sample.path)] + sample }
.set{ input_ch_samples_with_index }
input_ch_samples_with_index
.map{ sample -> [sample.path, sample.index] }
.flatten()
.set{ input_validation }
input_ch_samples_with_index
.map{ it -> [it.id, it.path, it.index] }
.set { input_bam_ch }
if (!params.reference_fasta) {
// error out - must provide a reference FASTA file
error "***Error: You must specify a reference FASTA file***"
}
if (!params.exclusion_file) {
// error out - must provide exclusion file
error "***Error: You must provide an exclusion file***"
}
if (!params.run_delly && !params.run_manta) {
// error out - must specify a valid SV caller
error "***Error: You must specify either Delly or Manta***"
}
reference_fasta_index = "${params.reference_fasta}.fai"
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"
)
if (params.run_discovery) {
if (params.run_manta) {
call_gSV_Manta(input_bam_ch, params.reference_fasta, reference_fasta_index)
run_sha512sum_Manta(call_gSV_Manta.out.vcf_small_indel_sv_file.mix(
call_gSV_Manta.out.vcf_diploid_sv_file,
call_gSV_Manta.out.vcf_candidate_sv_file,
call_gSV_Manta.out.vcf_small_indel_sv_tbi,
call_gSV_Manta.out.vcf_diploid_sv_tbi,
call_gSV_Manta.out.vcf_candidate_sv_tbi
))
}
if (params.run_delly) {
call_gSV_Delly(input_bam_ch, params.reference_fasta, reference_fasta_index, params.exclusion_file)
convert_gSV_BCF2VCF_BCFtools(call_gSV_Delly.out.bcf_sv_file, call_gSV_Delly.out.bam_sample_name, params.GSV)
run_sha512sum_gSV_Delly(call_gSV_Delly.out.bcf_sv_file.mix(call_gSV_Delly.out.bcf_sv_file_csi))
if (params.variant_type.contains(params.GCNV)) {
call_gCNV_Delly(input_bam_ch, call_gSV_Delly.out.bcf_sv_file.toList(), params.reference_fasta, reference_fasta_index, params.mappability_map)
convert_gCNV_BCF2VCF_BCFtools(call_gCNV_Delly.out.bcf_cnv_file, call_gCNV_Delly.out.bam_sample_name, params.GCNV)
run_sha512sum_gCNV_Delly(call_gCNV_Delly.out.bcf_cnv_file.mix(call_gCNV_Delly.out.bcf_cnv_file_csi))
}
if (params.run_qc) {
run_gSV_vcfstats_RTGTools(convert_gSV_BCF2VCF_BCFtools.out.vcf_file, call_gSV_Delly.out.bam_sample_name, params.GSV)
run_gSV_vcf_validator_VCFtools(convert_gSV_BCF2VCF_BCFtools.out.vcf_file, call_gSV_Delly.out.bam_sample_name, params.GSV)
if (params.variant_type.contains(params.GCNV)) {
run_gCNV_vcfstats_RTGTools(convert_gCNV_BCF2VCF_BCFtools.out.vcf_file, call_gCNV_Delly.out.bam_sample_name, params.GCNV)
run_gCNV_vcf_validator_VCFtools(convert_gCNV_BCF2VCF_BCFtools.out.vcf_file, call_gCNV_Delly.out.bam_sample_name, params.GCNV)
}
}
}
}
// When 'run_regenotyping' is set to true, the variant_type specified in the input_csv will be used to determine which
// regenotyping process to run. For example, if the variant_type contains 'gSV', regenotype_gSV_Delly will run, etc.
if (params.run_regenotyping) {
if (params.variant_type.contains(params.GSV)) {
regenotype_gSV_Delly(input_bam_ch, params.reference_fasta, reference_fasta_index, params.exclusion_file, params.merged_sites_gSV)
run_sha512sum_regeno_gSV_Delly(regenotype_gSV_Delly.out.regenotyped_sv_bcf.mix(regenotype_gSV_Delly.out.regenotyped_sv_bcf_csi))
}
if (params.variant_type.contains(params.GCNV)) {
regenotype_gCNV_Delly(input_bam_ch, params.reference_fasta, reference_fasta_index, params.mappability_map, params.merged_sites_gCNV)
run_sha512sum_regeno_gCNV_Delly(regenotype_gCNV_Delly.out.regenotyped_cnv_bcf.mix(regenotype_gCNV_Delly.out.regenotyped_cnv_bcf_csi))
}
}
}