-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrgt.wdl
More file actions
496 lines (442 loc) · 13.8 KB
/
Copy pathtrgt.wdl
File metadata and controls
496 lines (442 loc) · 13.8 KB
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
490
491
492
493
494
495
496
version 1.0
workflow trgt {
meta {
title: "TRGT workflow"
summary: "Tandem Repeat Genotyping Tool (TRGT) workflow"
description: "Workflow to genotype tandem repeats using TRGT. The workflow extracts reads overlapping repeat regions, performs genotyping, and generates both allele and waterfall plots including methylation visualization."
}
parameter_meta {
sample_name: {
help: "Name of the sample being processed",
label: "Sample name"
}
sex: {
help: "Biological sex of the sample",
label: "Sample sex",
choices: ["M", "F"]
}
mapped_bam: {
help: "Input BAM file containing aligned reads",
label: "Mapped BAM"
}
mapped_bam_bai: {
help: "Index file for the input BAM",
label: "Mapped BAM index"
}
ref_fasta: {
help: "Reference genome in FASTA format",
label: "Reference FASTA"
}
ref_index: {
help: "Index file for the reference FASTA",
label: "Reference FASTA index"
}
trgt_bed: {
help: "BED file containing tandem repeat regions to analyze",
label: "TRGT tandem repeat catalog BED"
}
reads_overlapping_repeats: {
help: "BAM file containing reads that overlap with repeat regions",
label: "Repeat region reads BAM"
}
reads_overlapping_repeats_bai: {
help: "Index for the BAM containing reads overlapping repeat regions",
label: "Repeat region reads BAM index"
}
spanning_bam: {
help: "Output BAM containing reads spanning repeat regions",
label: "TRGT spanning reads BAM"
}
spanning_bam_bai: {
help: "Index for the spanning reads BAM",
label: "TRGT spanning reads BAM index"
}
vcf: {
help: "Output VCF containing repeat genotypes",
label: "TRGT repeats VCF"
}
images_motifs_allele: {
help: "Archive containing SVG plots showing repeat motifs in allele view",
label: "Motif allele plots"
}
images_meth_allele: {
help: "Archive containing SVG plots showing methylation in allele view",
label: "Methylation allele plots"
}
images_motifs_waterfall: {
help: "Archive containing SVG plots showing repeat motifs in waterfall view",
label: "Motif waterfall plots"
}
images_meth_waterfall: {
help: "Archive containing SVG plots showing methylation in waterfall view",
label: "Methylation waterfall plots"
}
}
input {
String sample_name
String sex
File mapped_bam
File mapped_bam_bai
File ref_fasta
File ref_index
File trgt_bed
String docker_smrttools
}
call get_reads_overlapping_repeats {
input:
sample_name = sample_name,
mapped_bam = mapped_bam,
mapped_bam_bai = mapped_bam_bai,
trgt_bed = trgt_bed,
docker_smrttools = docker_smrttools
}
call trgt_genotype {
input:
sample_name = sample_name,
sex = sex,
mapped_bam = mapped_bam,
mapped_bam_bai = mapped_bam_bai,
ref_fasta = ref_fasta,
ref_index = ref_index,
trgt_bed = trgt_bed,
docker_smrttools = docker_smrttools
}
call trgt_plot as trgt_plot_motifs_allele {
input:
sample_name = sample_name,
vcf = trgt_genotype.vcf,
spanning_bam = trgt_genotype.spanning_bam,
spanning_bam_bai = trgt_genotype.spanning_bam_bai,
ref_fasta = ref_fasta,
ref_index = ref_index,
trgt_bed = trgt_bed,
methylation = false,
waterfall = false,
docker_smrttools = docker_smrttools
}
call trgt_plot as trgt_plot_meth_allele {
input:
sample_name = sample_name,
vcf = trgt_genotype.vcf,
spanning_bam = trgt_genotype.spanning_bam,
spanning_bam_bai = trgt_genotype.spanning_bam_bai,
ref_fasta = ref_fasta,
ref_index = ref_index,
trgt_bed = trgt_bed,
methylation = true,
waterfall = false,
docker_smrttools = docker_smrttools
}
call trgt_plot as trgt_plot_motifs_waterfall {
input:
sample_name = sample_name,
vcf = trgt_genotype.vcf,
spanning_bam = trgt_genotype.spanning_bam,
spanning_bam_bai = trgt_genotype.spanning_bam_bai,
ref_fasta = ref_fasta,
ref_index = ref_index,
trgt_bed = trgt_bed,
methylation = false,
waterfall = true,
docker_smrttools = docker_smrttools
}
call trgt_plot as trgt_plot_meth_waterfall {
input:
sample_name = sample_name,
vcf = trgt_genotype.vcf,
spanning_bam = trgt_genotype.spanning_bam,
spanning_bam_bai = trgt_genotype.spanning_bam_bai,
ref_fasta = ref_fasta,
ref_index = ref_index,
trgt_bed = trgt_bed,
methylation = true,
waterfall = true,
docker_smrttools = docker_smrttools
}
output {
File vcf = trgt_genotype.vcf
File spanning_bam = trgt_genotype.spanning_bam
File spanning_bam_bai = trgt_genotype.spanning_bam_bai
File images_motifs_allele = trgt_plot_motifs_allele.images
File images_meth_allele = trgt_plot_meth_allele.images
File images_motifs_waterfall = trgt_plot_motifs_waterfall.images
File images_meth_waterfall = trgt_plot_meth_waterfall.images
File reads_overlapping_repeats = get_reads_overlapping_repeats.reads_overlapping_repeats
File reads_overlapping_repeats_bai = get_reads_overlapping_repeats.reads_overlapping_repeats_bai
}
}
task get_reads_overlapping_repeats {
meta {
title: "Extract reads overlapping repeat regions"
summary: "Extracts reads from BAM file that overlap with specified repeat regions"
description: "Uses samtools to extract reads that overlap with expanded repeat regions, creating a subset BAM for downstream analysis"
}
parameter_meta {
sample_name: {
help: "Name of the sample being processed",
label: "Sample name"
}
mapped_bam: {
help: "Input BAM file containing aligned reads",
label: "Mapped BAM"
}
mapped_bam_bai: {
help: "Index file for the input BAM",
label: "Mapped BAM index"
}
trgt_bed: {
help: "BED file containing tandem repeat regions to analyze",
label: "TRGT tandem repeat catalog BED"
}
expand_size: {
help: "Padding size in bases to expand repeat regions by (default 3000)",
label: "Region expansion padding size"
}
reads_overlapping_repeats: {
help: "BAM file containing reads that overlap with repeat regions",
label: "Repeat region reads BAM"
}
reads_overlapping_repeats_bai: {
help: "Index for the BAM containing reads overlapping repeat regions",
label: "Repeat region reads BAM index"
}
}
input {
String sample_name
File mapped_bam
File mapped_bam_bai
File trgt_bed
Int expand_size = 3000
Int threads = 1
Int mem_gb = 4
String docker_smrttools
}
String output_name = "~{sample_name}.repeats.bam"
String index_name = "~{output_name}.bai"
String output_name_with_index = "~{output_name}##idx##~{index_name}"
String expanded_bed_name = "~{sample_name}.expanded.bed"
Int disk_size = ceil(size(mapped_bam, 'GB') * 2 + 10)
command <<<
set -e
awk -v sz=~{expand_size} \
'{if ($2 < sz) { print $1"\t0\t"$3 + sz} else {print $1"\t"$2 - sz"\t"$3 + sz} }' \
~{trgt_bed} \
> ~{expanded_bed_name}
samtools view \
--write-index \
--use-index \
--target-file ~{expanded_bed_name} \
--output ~{output_name_with_index} \
~{mapped_bam}
>>>
output {
File reads_overlapping_repeats = "~{output_name}"
File reads_overlapping_repeats_bai = "~{index_name}"
}
runtime {
docker: docker_smrttools
cpu: threads
memory: "~{mem_gb} GB"
disk: disk_size + " GB"
disks: "local-disk " + disk_size + " SSD"
}
}
task trgt_genotype {
meta {
title: "TRGT genotyper"
summary: "Genotype tandem repeats using TRGT"
description: "Performs genotyping of tandem repeat regions using TRGT."
}
parameter_meta {
sample_name: {
help: "Name of the sample being processed",
label: "Sample name"
}
sex: {
help: "Biological sex of the sample",
label: "Sample sex",
choices: ["M", "F"]
}
mapped_bam: {
help: "Input BAM file containing aligned reads",
label: "Mapped BAM"
}
mapped_bam_bai: {
help: "Index file for the input BAM",
label: "Mapped BAM index"
}
ref_fasta: {
help: "Reference genome in FASTA format",
label: "Reference FASTA"
}
ref_index: {
help: "Index file for the reference FASTA",
label: "Reference FASTA index"
}
trgt_bed: {
help: "BED file containing tandem repeat regions to analyze",
label: "TRGT tandem repeat catalog BED"
}
threads: {
help: "Number of CPU threads to use (default: 8)",
label: "CPU threads"
}
mem_gb: {
help: "Memory allocation in gigabytes (default: 16)",
label: "Memory (GB)"
}
vcf: {
help: "Output VCF containing repeat genotypes",
label: "TRGT repeats VCF"
}
spanning_bam: {
help: "Output BAM containing reads spanning repeat regions",
label: "TRGT spanning reads BAM"
}
spanning_bam_bai: {
help: "Index for the spanning reads BAM",
label: "TRGT spanning reads BAM index"
}
}
input {
String sample_name
String? sex
File mapped_bam
File mapped_bam_bai
File ref_fasta
File ref_index
File trgt_bed
Int threads = 8
Int mem_gb = 16
String docker_smrttools
}
String out_prefix = "~{sample_name}.trgt"
String karyotype = if select_first([sex, "F"]) == "M" then "XY" else "XX"
Int disk_size = ceil((size(mapped_bam, 'GB') + size(ref_fasta, 'GB')) * 2 + 20)
command <<<
set -e
trgt --verbose genotype \
--threads ~{threads} \
--preset targeted \
--genome ~{ref_fasta} \
--karyotype ~{karyotype} \
--reads ~{mapped_bam} \
--repeats ~{trgt_bed} \
--output-prefix ~{out_prefix}
gunzip -c "~{out_prefix}.vcf.gz" > ~{out_prefix}.vcf
samtools sort -o ~{out_prefix}.sorted.spanning.bam ~{out_prefix}.spanning.bam
samtools index ~{out_prefix}.sorted.spanning.bam
>>>
output {
File vcf = "~{out_prefix}.vcf"
File spanning_bam = "~{out_prefix}.sorted.spanning.bam"
File spanning_bam_bai = "~{out_prefix}.sorted.spanning.bam.bai"
}
runtime {
docker: docker_smrttools
cpu: threads
memory: "~{mem_gb} GB"
disk: disk_size + " GB"
disks: "local-disk " + disk_size + " SSD"
}
}
task trgt_plot {
meta {
title: "TRGT plotter"
summary: "Generates visualization plots for TRGT results"
description: "Creates SVG plots for each repeat region showing either motif composition or methylation status in either allele or waterfall view styles. Outputs are bundled into a ZIP archive."
}
parameter_meta {
sample_name: {
help: "Name of the sample being processed",
label: "Sample name"
}
vcf: {
help: "Input VCF containing repeat genotypes from TRGT",
label: "TRGT VCF"
}
spanning_bam: {
help: "BAM file containing reads spanning repeat regions",
label: "Spanning reads BAM"
}
spanning_bam_bai: {
help: "Index for the spanning reads BAM",
label: "Spanning reads BAM index"
}
ref_fasta: {
help: "Reference genome in FASTA format",
label: "Reference FASTA"
}
ref_index: {
help: "Index file for the reference FASTA",
label: "Reference FASTA index"
}
trgt_bed: {
help: "BED file containing tandem repeat regions to analyze",
label: "TRGT tandem repeat catalog BED"
}
methylation: {
help: "Whether to show methylation status instead of motifs (default: false)",
label: "Show methylation"
}
waterfall: {
help: "Whether to use waterfall plot style instead of allele view (default: false)",
label: "Use waterfall plot"
}
threads: {
help: "Number of CPU threads to use (default: 1)",
label: "CPU threads"
}
mem_gb: {
help: "Memory allocation in gigabytes (default: 4)",
label: "Memory (GB)"
}
images: {
help: "Archive containing SVG plot files",
label: "Plot archive"
}
}
input {
String sample_name
File vcf
File spanning_bam
File spanning_bam_bai
File ref_fasta
File ref_index
File trgt_bed
Boolean methylation = false
Boolean waterfall = false
Int threads = 1
Int mem_gb = 4
String docker_smrttools
}
String show = if (methylation) then "meth" else "motifs"
String plot_type = if (waterfall) then "waterfall" else "allele"
String output_prefix = "~{sample_name}.~{show}_~{plot_type}"
Int disk_size = ceil((size(spanning_bam, 'GB') + size(ref_fasta, 'GB')) * 2 + 20)
# Note: bcftools is provided by the SMRT Link toolchain in the container
command <<<
bcftools query -f '%INFO/TRID\n' ~{vcf} | while read -r i; do
trgt plot \
--repeat-id "$i" \
--genome ~{ref_fasta} \
--repeats ~{trgt_bed} \
--spanning-reads ~{spanning_bam} \
--vcf ~{vcf} \
--show ~{show} \
--plot-type ~{plot_type} \
--image "~{output_prefix}.$(printf '%s' "$i").trgt_plot.svg"
done;
python3 -m zipfile -c ~{output_prefix}.trgt_plots.zip ./*.trgt_plot.svg
>>>
output {
File images = "~{output_prefix}.trgt_plots.zip"
}
runtime {
docker: docker_smrttools
cpu: threads
memory: "~{mem_gb} GB"
disk: disk_size + " GB"
disks: "local-disk " + disk_size + " SSD"
}
}