-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGenotypeGVCFs.wdl
260 lines (238 loc) · 6.24 KB
/
GenotypeGVCFs.wdl
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
#
# GenotypeGVCFs_WF
# Cromwell workflow for genotyping gvcfs with GATK
#
# Copyright (C) 2021 Anestis Gkanogiannis <anestis@gkanogiannis.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
workflow GenotypeGVCFs_WF {
String genome_ref
String listChromosomeFile
String listChromosomeLengthFile
Array[String] listChromosome = read_lines(listChromosomeFile)
String? listScaffoldFile
String? listScaffoldLengthFile
Boolean withScaffolds
String basename
String workDir
String gDB_base
Array[String] gDB_chr
String? gDB_Sca
String tmp
String log
String threads
String gatk
String tabix
call getIntervals as intervals_chr {
input:
contigs=listChromosomeFile,
lengths=listChromosomeLengthFile,
basename=basename,
log=log
}
scatter (interval in intervals_chr.out) {
call GenotypeGVCFs as GTChromosome {
input:
ref = genome_ref,
outDir = workDir,
gDB_base = gDB_base,
gDb_suffix=interval[0],
basename=basename,
log = log,
tmp = tmp,
interval_contig = interval[0],
interval_start = interval[1],
interval_end = interval[2],
threads = 2,
gatk = gatk,
tabix = tabix
}
}
if(withScaffolds){
call getIntervals as intervals_sca {
input:
contigs=listScaffoldFile,
lengths=listScaffoldLengthFile,
basename=basename,
log=log
}
scatter (interval in intervals_sca.out) {
call GenotypeGVCFs as GTScaffold {
input:
ref = genome_ref,
outDir = workDir,
gDB_base=gDB_base,
gDb_suffix = "Scaffolds",
basename=basename,
log = log,
tmp = tmp,
interval_contig = interval[0],
interval_start = interval[1],
interval_end = interval[2],
threads = 1,
gatk = gatk,
tabix = tabix
}
}
}
call GatherVCFs as GatherVCFs_chr{
input:
ref = genome_ref,
outDir = workDir,
basename=basename,
log = log,
tmp = tmp,
vcfs = GTChromosome.vcf,
vcfsIndex = GTChromosome.vcfIndex,
suffix = "chromosomes",
threads = 2,
gatk = gatk,
tabix = tabix
}
if(withScaffolds){
call GatherVCFs as GatherVCFs_sca{
input:
ref = genome_ref,
outDir = workDir,
basename=basename,
log = log,
tmp = tmp,
vcfs = GTScaffold.vcf,
vcfsIndex = GTScaffold.vcfIndex,
suffix = "scaffolds",
threads = 2,
gatk = gatk,
tabix = tabix
}
}
}
#################################################################
task getIntervals {
File contigs
File lengths
String basename
String log
command <<<
paste ${contigs} ${lengths} | while IFS=$'\t' read -r contig length ; do
start=1 ;
end=1000000;
while (( end<length )); do
echo -e "$contig\t$start\t$end" ;
(( start=start+1000000 )) ;
(( end=end+1000000 )) ;
done;
echo -e "$contig\t$start\t$length" ;
done ;
exit 0 ;
>>>
runtime {
cpu: 2
memory: "512 MB"
my_job_name: "VD_GetIntervals_${basename}"
my_log: "${log}/VD_GetIntervals_${basename}"
}
output {
Array[Array[String]] out = read_tsv(stdout())
}
}
task GenotypeGVCFs {
String ref
String outDir
String gDB_base
String gDb_suffix
String basename
String log
String tmp
String interval_contig
String interval_start
String interval_end
String gatk
String tabix
Int threads
Int mem=10000
Int mems=8000
command <<<
mkdir -p ${outDir} ${tmp} ;
VCF="${outDir}/${basename}_${interval_contig}_${interval_start}-${interval_end}.raw.vcf.gz" ;
VCFINDEX="${outDir}/${basename}_${interval_contig}_${interval_start}-${interval_end}.raw.vcf.gz.tbi" ;
if [[ ! -f $VCF || ! -f $VCFINDEX ]]; then
${gatk} --java-options "-Xms${mems}M -Xmx${mem}M" GenotypeGVCFs \
-R ${ref} \
-L ${interval_contig}:${interval_start}-${interval_end} \
-V gendb://${gDB_base}/${gDb_suffix} \
-O ${outDir}/${basename}_${interval_contig}_${interval_start}-${interval_end}.raw.vcf.gz \
--seconds-between-progress-updates 60 \
--max-alternate-alleles 4 \
--only-output-calls-starting-in-intervals \
--tmp-dir=${tmp} ;
else
echo -e "${outDir}/${basename}_${interval_contig}_${interval_start}-${interval_end}.raw.vcf.gz exists" ;
fi ;
exit 0 ;
>>>
runtime {
cpu: threads
memory: 2.0*mem/threads + " MB"
my_job_name: "VD_GenotypeGVCFs_${basename}_${interval_contig}_${interval_start}-${interval_end}"
my_log: "${log}/VD_GenotypeGVCFs_${basename}_${interval_contig}_${interval_start}-${interval_end}"
maxRetries: 1
}
output {
File vcf = "${outDir}/${basename}_${interval_contig}_${interval_start}-${interval_end}.raw.vcf.gz"
File vcfIndex = "${outDir}/${basename}_${interval_contig}_${interval_start}-${interval_end}.raw.vcf.gz.tbi"
}
}
task GatherVCFs {
String ref
String outDir
String basename
String log
String tmp
Array[File] vcfs
Array[File] vcfsIndex
String suffix
String gatk
String tabix
Int threads
Int mem=64000
Int mems=60000
command <<<
mkdir -p ${outDir} ${tmp} ;
VCF="${outDir}/${basename}.${suffix}.raw.vcf.gz" ;
VCFINDEX="${outDir}/${basename}.${suffix}.raw.vcf.gz.tbi" ;
if [[ ! -f $VCF || ! -f $VCFINDEX ]]; then
${gatk} --java-options "-Xms${mems}M -Xmx${mem}M" GatherVcfs \
-R ${ref} \
--TMP_DIR ${tmp} \
--VALIDATION_STRINGENCY LENIENT \
--INPUT ${sep=' --INPUT ' vcfs} \
--OUTPUT ${outDir}/${basename}.${suffix}.raw.vcf.gz ;
fi ;
${tabix} -p vcf ${outDir}/${basename}.${suffix}.raw.vcf.gz ;
exit 0 ;
>>>
runtime {
cpu: threads
memory: 2.0*mem/threads + " MB"
my_job_name: "VD_GatherVCFs_${basename}_${suffix}"
my_log: "${log}/VD_GatherVCFs_${basename}_${suffix}"
maxRetries: 1
}
output {
File vcf = "${outDir}/${basename}.${suffix}.raw.vcf.gz"
File vcfIndex = "${outDir}/${basename}.${suffix}.raw.vcf.gz.tbi"
}
}