forked from large-scale-gxe-methods/genotype-conversion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genotype_conversion.wdl
489 lines (411 loc) · 10.8 KB
/
genotype_conversion.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
task bgen_to_vcf {
File bgen_file
File sample_file
Float? maf
String outfile = basename(bgen_file, ".bgen")
Int? memory = 10
Int? disk = 20
command <<<
$PLINK2 \
--bgen ${bgen_file} ref-first \
--sample ${sample_file} \
--allow-extra-chr \
${"--maf " + maf} \
--make-pgen \
--out ${outfile}
mv ${outfile}.pvar ${outfile}.pvar2
echo '##INFO=<ID=R2,Number=1,Type=Float,Description="Imputation R2">' > ${outfile}.pvar
head -1 ${outfile}.pvar2 | awk '{print $0"\tINFO"}' >> ${outfile}.pvar
tail -n +2 ${outfile}.pvar2 | awk '{print $0"\tR2=1"}' >> ${outfile}.pvar
$PLINK2 \
--pfile ${outfile} \
--allow-extra-chr \
${"--maf " + maf} \
--export vcf bgz id-paste=iid vcf-dosage=DS-force \
--out ${outfile}
>>>
runtime {
docker: "quay.io/large-scale-gxe-methods/genotype-conversion:latest"
memory: "${memory} GB"
disks: "local-disk ${disk} HDD"
gpu: false
}
output {
File out_vcf = "${outfile}.vcf.gz"
}
}
task bgen_to_vcf_2 {
File bgen_file
File? sample_file
String? variant_range_filter = ""
String outfile = basename(bgen_file, ".bgen")
Int? memory = 10
Int? disk = 20
command {
$QCTOOL \
-g ${bgen_file} \
${"-s " + sample_file} \
-incl-range ${variant_range_filter} \
-og ${outfile}.vcf.gz
}
runtime {
docker: "quay.io/large-scale-gxe-methods/genotype-conversion:latest"
memory: "${memory} GB"
disks: "local-disk ${disk} HDD"
gpu: false
}
output {
File out_vcf = "${outfile}.vcf.gz"
}
}
task vcf_to_bgen {
File vcf_file
String? dosage_type
Float? maf
String? variant_range_filter = ""
Int? memory = 10
Int? disk = 20
String outfile_nogz = basename(vcf_file, ".gz")
String outfile = sub(outfile_nogz, "\\.vcf", "")
command {
$PLINK2 \
--vcf ${vcf_file} ${"dosage=" + dosage_type} \
${"--maf " + maf} \
--export bgen-1.2 id-paste=iid \
--out ${outfile}
}
#$QCTOOL \
# -g ${vcf_file} \
# -incl-range ${variant_range_filter} \
# -og ${outfile}.bgen \
# -os ${outfile}.sample
runtime {
docker: "quay.io/large-scale-gxe-methods/genotype-conversion:latest"
memory: "${memory} GB"
disks: "local-disk ${disk} HDD"
gpu: false
}
output {
File out_bgen = "${outfile}.bgen"
File out_sample = "${outfile}.sample"
}
}
task vcf_to_minimac {
File vcf_file
#File? info_file
String outfile = basename(vcf_file, ".vcf.gz")
Int? memory = 10
Int? disk = 20
command <<<
$DosageConvertor \
--vcfDose ${vcf_file} \
--type mach \
--format 1 \
--prefix ${outfile}
gunzip < "${outfile}.mach.dose.gz" | tr '\t' ' ' > "${outfile}.mach.dose"
>>>
runtime {
docker: "quay.io/large-scale-gxe-methods/genotype-conversion:latest"
memory: "${memory} GB"
disks: "local-disk ${disk} HDD"
gpu: false
}
output {
File out_minimac_gz = "${outfile}.mach.dose.gz"
File out_minimac = "${outfile}.mach.dose"
File out_info = "${outfile}.mach.info"
}
}
task vcf_to_plink2 {
File vcf_file
String? dosage_type
Float? maf
String outfile = basename(vcf_file, ".vcf.gz")
Int? memory = 10
Int? disk = 20
command {
$PLINK2 \
--vcf ${vcf_file} ${"dosage=" + dosage_type} \
${"--maf " + maf} \
--make-pgen \
--out ${outfile}
}
runtime {
docker: "quay.io/large-scale-gxe-methods/genotype-conversion:latest"
memory: "${memory} GB"
disks: "local-disk ${disk} HDD"
gpu: false
}
output {
File out_pgen = "${outfile}.pgen"
File out_psam = "${outfile}.psam"
File out_pvar = "${outfile}.pvar"
}
}
task vcf_to_gen {
File vcf_file
String? dosage_type
Float? maf
String outfile = basename(vcf_file, ".vcf.gz")
Int? memory = 10
Int? disk = 20
command {
$PLINK2 \
--vcf ${vcf_file} \
--allow-extra-chr \
${"--maf " + maf} \
--export oxford bgz \
--out ${outfile}
}
#--vcf ${vcf_file} ${"dosage=" + dosage_type} \
runtime {
docker: "quay.io/large-scale-gxe-methods/genotype-conversion:latest"
memory: "${memory} GB"
disks: "local-disk ${disk} HDD"
gpu: false
}
output {
File out_gen = "${outfile}.gen.gz"
File out_sample = "${outfile}.sample"
}
}
task minimac_to_mmap {
File dose_file
File info_file
String outfile = basename(dose_file, ".dose.gz")
Int? memory = 10
Int? disk = 20
command {
$MMAP \
--mach_dose2mmap \
--mach_info_filename ${info_file} \
--mach_dose_filename ${dose_file} \
--binary_output_filename ${outfile}_bin_SxM
$MMAP \
--transpose_binary_genotype_file \
--binary_input_filename ${outfile}_bin_SxM \
--binary_output_filename ${outfile}_bin
}
runtime {
docker: "quay.io/large-scale-gxe-methods/genotype-conversion:latest"
memory: "${memory} GB"
disks: "local-disk ${disk} HDD"
gpu: false
}
output {
File out_mmap = "${outfile}_bin"
}
}
task bgen_to_plink2 {
File bgen_file
File? sample_file
Float? maf
String outfile = basename(bgen_file, ".bgen")
Int? memory = 10
Int? disk = 20
command {
$PLINK2 \
--bgen ${bgen_file} \
--sample ${sample_file} \
${"--maf " + maf} \
--make-pgen \
--out ${outfile}
}
runtime {
docker: "quay.io/large-scale-gxe-methods/genotype-conversion:latest"
memory: "${memory} GB"
disks: "local-disk ${disk} HDD"
gpu: false
}
output {
File out_pgen = "${outfile}.pgen"
File out_psam = "${outfile}.psam"
File out_pvar = "${outfile}.pvar"
}
}
task bgen_to_gen {
File bgen_file
File? sample_file
Float? maf
String outfile = basename(bgen_file, ".bgen")
Int? memory = 10
Int? disk = 20
command {
$PLINK2 \
--bgen ${bgen_file} \
--sample ${sample_file} \
${"--maf " + maf} \
--export oxford \
--out ${outfile}
}
runtime {
docker: "quay.io/large-scale-gxe-methods/genotype-conversion:latest"
memory: "${memory} GB"
disks: "local-disk ${disk} HDD"
gpu: false
}
output {
File out_gen = "${outfile}.gen"
File out_sample = "${outfile}.sample"
}
}
workflow convert {
String conversion
Array[File] input_files
Array[File]? sample_files
Array[File]? info_files
String? dosage_type
Float? maf
String? variant_range_filter
String? memory
String? disk
if(conversion == "bgen2vcf") {
Array[File] sample_files_nonoptional = select_first([sample_files, []])
Array[Pair[File,File]] bgen_filesets = zip(input_files, sample_files_nonoptional)
scatter (fileset in bgen_filesets) {
call bgen_to_vcf {
input:
bgen_file = fileset.left,
sample_file = fileset.right,
maf = maf,
memory = memory,
disk = disk
}
}
output {
Array[File]? converted_vcf_files = bgen_to_vcf.out_vcf
}
}
if(conversion == "vcf2bgen") {
scatter (input_file in input_files) {
call vcf_to_bgen {
input:
vcf_file = input_file,
dosage_type = dosage_type,
maf = maf,
variant_range_filter = variant_range_filter,
memory = memory,
disk = disk
}
}
output {
Array[File]? converted_bgen_files = vcf_to_bgen.out_bgen
Array[File]? converted_bgen_sample_files = vcf_to_bgen.out_sample
}
}
if(conversion == "vcf2minimac") {
scatter (input_file in input_files) {
call vcf_to_minimac {
input:
vcf_file = input_file,
memory = memory,
disk = disk
#info_file = info_file
}
}
output {
Array[File]? converted_dose_files = vcf_to_minimac.out_minimac
Array[File]? converted_info_files = vcf_to_minimac.out_info
}
}
if(conversion == "vcf2plink2") {
scatter (input_file in input_files) {
call vcf_to_plink2 {
input:
vcf_file = input_file,
dosage_type = dosage_type,
maf = maf,
memory = memory,
disk = disk
}
}
output {
Array[File]? converted_plink2_pgen = vcf_to_plink2.out_pgen
Array[File]? converted_plink2_psam = vcf_to_plink2.out_psam
Array[File]? converted_plink2_pvar = vcf_to_plink2.out_pvar
}
}
if(conversion == "vcf2gen") {
scatter (input_file in input_files) {
call vcf_to_gen {
input:
vcf_file = input_file,
dosage_type = dosage_type,
maf = maf,
memory = memory,
disk = disk
}
}
output {
Array[File]? converted_gen_files = vcf_to_gen.out_gen
Array[File]? converted_gen_sample_files = vcf_to_gen.out_sample
}
}
if(conversion == "minimac2mmap") {
Array[File] info_files_nonoptional = select_first([info_files, []])
Array[Pair[File,File]] minimac_filesets = zip(input_files, info_files_nonoptional)
scatter (fileset in minimac_filesets) {
call minimac_to_mmap {
input:
dose_file = fileset.left,
info_file = fileset.right,
memory = memory,
disk = disk
}
}
output {
Array[File]? converted_mmap_files = minimac_to_mmap.out_mmap
}
}
#if(conversion == "bgen2plink2") {
# Array[File] sample_files_for_plink2_nonoptional = select_first([sample_files, []])
# Array[Pair[File,File]] bgen_filesets_for_plink2 = zip(input_files, sample_files_for_plink2_nonoptional)
# scatter (fileset in bgen_filesets_for_plink2) {
# call bgen_to_plink2 {
# input:
# bgen_file = fileset.left,
# sample_file = fileset.right,
# memory = memory,
# disk = disk
# }
# }
# output {
# Array[File]? converted_plink2_pgen = bgen_to_plink2.out_pgen
# Array[File]? converted_plink2_psam = bgen_to_plink2.out_psam
# Array[File]? converted_plink2_pvar = bgen_to_plink2.out_pvar
# }
#}
#if(conversion == "bgen2gen") {
# Array[File] sample_files_for_gen_nonoptional = select_first([sample_files, []])
# Array[Pair[File,File]] bgen_filesets_for_gen = zip(input_files, sample_files_for_gen_nonoptional)
# scatter (fileset in bgen_filesets_for_gen) {
# call bgen_to_gen {
# input:
# bgen_file = fileset.left,
# sample_file = fileset.right,
# memory = memory,
# disk = disk
# }
# }
# output {
# Array[File]? converted_gen_files = bgen_to_gen.out_gen
# Array[File]? converted_gen_sample_files = bgen_to_gen.out_sample
# }
#}
parameter_meta {
conversion: "String representing the requested conversion. Current options include: bgen2vcf, vcf2bgen, vcf2minimac, vcf2plink2, vcf2gen, and minimac2mmap."
input_files: "Array of genotype dosage files (currently, in VCF or .bgen format)."
sample_files: "Array of .bgen sample files (optionally used in the .bgen to VCF conversion)."
info_files: "Array of variant info files (used in the Minimac to MMAP conversion)."
dosage_type: "Type of allele dosage to read in from imputed VCF file (optional; options = GP/GP-force/HDS/DS)."
maf: "Optional float setting a minimum minor allele frequency filter."
variant_range_filter: "Optional string for variant filtering. Format: chr:start-stop (e.g. 2:100000-500000)."
memory: "Requested memory (in GB)."
disk: "Requested disk space (in GB)."
}
meta {
author: "Kenny Westerman"
email: "[email protected]"
decription: "Convert imputed genotype data file formats for use in downstream GxE testing, with Minimac4 VCF as the 'hub' for conversion ot other formats. Currently implements VCF to .bgen, .gen (Oxford), pgen/psam/pvar (PLINK2), or Minimac dose; .bgen to VCF; and Minimac dose to MMAP."
}
}