-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhackaton2_day4.nf
239 lines (165 loc) · 6.48 KB
/
hackaton2_day4.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/* Population genomics pipeline
* Usage:
*
*
* Author: participants of Hackaton 2
*/
// Setting some defaults here,
// Establishing parameters
params.reads="/home/ec2-user/environment/data/ggal/*_{1,2}.*fq"
params.ref="/home/ec2-user/environment/data/ggal/transcriptome.fa"
params.outdir="/home/ec2-user/environment/result_alignment"
params.out = "${params.outdir}/out"
//params.tmpdir = "${params.outdir}/gatk_temp"
//params.gatk = "/opt/broad/GenomeAnalysisTK.jar"
//params.snpeff_data = "${params.outdir}/snpeff_data"
log.info """\
===================================================
|| POPULATION_GENOMICS - N F P I P E L I N E ||
===================================================
Reference Genome: ${params.ref}
Read_file(s) : ${params.reads}
outdir : ${params.outdir}
"""
.stripIndent()
num_samples = 0
Channel
.fromFilePairs( params.reads )
.ifEmpty { error "Cannot find any reads matching: ${params.reads}" }
.tap { read_pairs_ch }
.subscribe({ num_samples += 1 })
//read_pairs_ch.view()
process indexing_genome_dict {
echo true
input:
path transcriptome from params.ref
output:
file("*.dict") into picard_dict_ch
file("*.fai") into samtools_index_ch, gen_indx_var_filtering_ch
script:
"""
echo "java -jar /data/software/picard/build/libs/picard.jar \
CreateSequenceDictionary R= ${transcriptome} \
O=${transcriptome}.dict" > ${transcriptome}.dict
echo "samtools faidx ${transcriptome}" > ${transcriptome}.fai
"""
}
//picard_dict_ch.view()
//samtools_index_ch.view()
process index {
container 'gencorefacility/variant-calling-pipeline-gatk4'
input:
path transcriptome from params.ref
output:
//path 'index' into index_ch
file("*") into index_ch
script:
"""
bwa index ${transcriptome}
"""
}
//index_ch.view()
process align {
cpus 1
// tells the output of the chanel it is created automatically by nextflow
publishDir "${params.out}/aligned_reads", mode:'copy'
container 'gencorefacility/variant-calling-pipeline-gatk4'
input:
set pair_id, file(reads) from read_pairs_ch //the chanel creates the pair ids
file(index) from index_ch
path(ref) from params.ref
output:
set val(pair_id), file("${pair_id}_aligned_reads.sam") \
into aligned_reads_ch
script:
"""
bwa mem ${ref} ${reads} > ${pair_id}_aligned_reads.sam
"""
}
//aligned_reads_ch.view()
process sam_to_sorted_index_bam {
publishDir "${params.out}/sort_indexed_bam", mode:'copy'
container 'gencorefacility/variant-calling-pipeline-gatk4'
input:
set val(pair_id), file(aligned_reads) from aligned_reads_ch
output:
set val(pair_id), file("${pair_id}_aligned_reads_sorted.bam"), file("${pair_id}_aligned_reads_sorted.bam.bai") into bam_for_sorting_bam_ch
script:
"""
samtools view -S -b ${aligned_reads} > ${pair_id}_aligned_reads.bam
samtools sort ${pair_id}_aligned_reads.bam -o ${pair_id}_aligned_reads_sorted.bam
samtools index ${pair_id}_aligned_reads_sorted.bam
"""
}
//bam_for_sorting_bam_ch.view()
process markDuplicates {
echo true
publishDir "${params.out}/dedup_sorted", mode:'copy'
container 'cbcrg/callings-nf@sha256:b65a7d721b9dd2da07d6bdd7f868b04039860f14fa514add975c59e68614c310'
input:
set val(pair_id), path(bamfile), path(baifile) from bam_for_sorting_bam_ch
output:
set val(pair_id), path("${pair_id}_sorted_duplicates_rm.bam") into bam_for_variant_calling_ch, sorted_dedup_ch_for_metrics, bam_for_bqsr
set val(pair_id), path("${pair_id}_sorted_duplicates_metrics.txt") into dedup_qc_ch
script:
"""
echo "java -jar /data/software/picard/build/libs/picard.jar \
MarkDuplicates I=${bamfile} O=${pair_id}_sorted_duplicates_rm.bam \
M=${pair_id}_sorted_duplicates_metrics.txt \
REMOVE_SEQUENCING_DUPLICATES=true" > ${pair_id}_sorted_duplicates_rm.bam
echo "${pair_id}" > ${pair_id}_sorted_duplicates_metrics.txt
"""
}
//bam_for_variant_calling_ch.flatten().view()
//bam_for_variant_calling_ch.collect().view()
process variant_calling {
publishDir "${params.out}/Variant_Called", mode:'copy'
echo true
input:
set val(pair_id), path (bam_files) from bam_for_variant_calling_ch
//set val(pair_id), file(set_bam_files) from bam_for_variant_calling_ch
file (indexed_ref) from samtools_index_ch
output:
set val(pair_id), file ("${pair_id}_var_call_vcf_file.vcf") into vcf_variant_ch
set val(pair_id), file ("${pair_id}_var_call_bam_file.bam") into bam_variant_ch
script:
"""
echo "gatk --java-options "-Xmx4g" HaplotypeCaller \
-R ${indexed_ref}.fna -I $bam_files -O ${pair_id}_var_call_vcf_file.vcf.gz \
-bamout ${pair_id}_var_call_bam_file.bam" > ${pair_id}_var_call_vcf_file.vcf
echo "gatk --java-options "-Xmx4g" HaplotypeCaller \
-R ${indexed_ref}.fna -I $bam_files -O ${pair_id}_var_call_vcf_file.vcf.gz \
-bamout ${pair_id}_var_call_bam_file.bam" > ${pair_id}_var_call_bam_file.bam
"""
}
process variant_filter {
echo true
publishDir "${params.out}/Variant_Called", mode:'copy'
input:
set val(pair_id), file (vcf_file) from vcf_variant_ch
file (indexed_ref) from gen_indx_var_filtering_ch
output:
file ("${pair_id}_variant_filtered.vcf*") into var_filtered_ch
script:
"""
echo "gatk VariantFiltration -R ${indexed_ref}.fna \
-V vcf_file -O ${pair_id}_variant_filtered.vcf.gz --filter-name \
'my_filter1' --filter-expression 'QUAL < 0 || DP<10.0 || MQ < 30.00 || SOR > 10.000 || QD < 2.00 || QD> 5.00|| FS > 200.000 || ReadPosRankSum < -20.000 || ReadPosRankSum > 20.000' " > ${pair_id}_variant_filtered.vcf
"""
}
// Same case as Variant_calling. Require use of several files at the same time.
//var_filtered_ch.collect().view()
process merging_VCFs {
echo true
publishDir "${params.out}/Variant_Called", mode:'copy'
input:
path (var_filt_file) from var_filtered_ch.collect()
output:
file ("VCF_var_filt_merged.vcf") into var_filt_merged_ch
script:
"""
echo "java -jar /data/software/picard/build/libs/picard.jar MergeVcfs \
`for f in *.vcf; do echo I = \${f}; done;`\
O = VCF_var_filt_merged.vcf.gz" > VCF_var_filt_merged.vcf
"""
}