-
Notifications
You must be signed in to change notification settings - Fork 24
/
genophase.wdl
316 lines (273 loc) · 8.66 KB
/
genophase.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
version 1.0
struct RuntimeEnvironment {
String docker
String singularity
}
workflow genophase {
meta {
version: "1.15.1"
caper_docker: "encodedcc/hic-pipeline:1.15.1"
caper_singularity: "docker://encodedcc/hic-pipeline:1.15.1"
croo_out_def: "https://raw.githubusercontent.com/ENCODE-DCC/hic-pipeline/dev/croo_out_def.json"
}
input {
File reference_fasta
Array[File] bams
String donor_id
# .tar.gz archive containing Ommi, Mills, Hapmap, and 1000G VCFs + indexes
# https://gatk.broadinstitute.org/hc/en-us/articles/360035890811-Resource-bundle
# https://console.cloud.google.com/storage/browser/genomics-public-data/resources/broad/hg38/v0/
File? gatk_bundle_tar
Int? gatk_num_cpus
Int? gatk_disk_size_gb
Int? gatk_ram_gb
Int? run_3d_dna_num_cpus
Int? run_3d_dna_disk_size_gb
Int? run_3d_dna_ram_gb
Int? concatenate_bams_disk_size_gb
Boolean no_phasing = false
String docker = "encodedcc/hic-pipeline:1.15.1"
String singularity = "docker://encodedcc/hic-pipeline:1.15.1"
}
RuntimeEnvironment runtime_environment = {
"docker": docker,
"singularity": singularity
}
call create_fasta_index as create_reference_fasta_index { input:
fasta = reference_fasta,
runtime_environment = runtime_environment,
}
call create_gatk_references { input:
reference_fasta = reference_fasta,
reference_fasta_index = create_reference_fasta_index.fasta_index,
output_stem = basename(reference_fasta, ".fasta.gz"),
runtime_environment = runtime_environment,
}
call gatk { input:
bams = bams,
reference_fasta = reference_fasta,
donor_id = donor_id,
reference_fasta_index = create_reference_fasta_index.fasta_index,
sequence_dictionary = create_gatk_references.sequence_dictionary,
interval_list = create_gatk_references.interval_list,
bundle_tar = gatk_bundle_tar,
num_cpus = gatk_num_cpus,
ram_gb = gatk_ram_gb,
disk_size_gb = gatk_disk_size_gb,
runtime_environment = runtime_environment,
}
if (!no_phasing) {
call run_3d_dna { input:
vcf = gatk.snp_vcf,
bams = bams,
num_cpus = run_3d_dna_num_cpus,
ram_gb = run_3d_dna_ram_gb,
disk_size_gb = run_3d_dna_disk_size_gb,
runtime_environment = runtime_environment,
}
call convert_psf_to_bedpe { input:
psf = run_3d_dna.psf,
runtime_environment = runtime_environment,
}
}
}
task concatenate_bams {
input {
Array[File] bams
Int disk_size_gb = 6000
Int num_cpus = 16
Int ram_gb = 100
RuntimeEnvironment runtime_environment
}
command <<<
for bam in ~{sep=" " bams}
do
header_filename=$(basename $bam | sed 's/\.bam/_header\.bam/g')
samtools view -H $bam > $header_filename
done
samtools merge \
--no-PG megaheader.bam \
*_header.bam
samtools cat \
-@ ~{num_cpus} \
-h megaheader.bam ~{sep=" " bams} \
-o concatenated.bam
>>>
output {
File bam = "concatenated.bam"
}
runtime {
cpu : "~{num_cpus}"
memory: "~{ram_gb} GB"
disks: "local-disk ~{disk_size_gb} HDD"
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task create_fasta_index {
input {
File fasta
RuntimeEnvironment runtime_environment
}
command <<<
set -euo pipefail
gzip -dc ~{fasta} > ~{basename(fasta, ".gz")}
samtools faidx ~{basename(fasta, ".gz")}
>>>
output {
File fasta_index = "~{basename(fasta, '.gz')}.fai"
}
runtime {
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task create_gatk_references {
input {
File reference_fasta
File reference_fasta_index
String output_stem
RuntimeEnvironment runtime_environment
}
command <<<
set -euo pipefail
gzip -dc ~{reference_fasta} > ~{basename(reference_fasta, ".gz")}
mv ~{reference_fasta_index} .
gatk \
CreateSequenceDictionary \
--REFERENCE ~{basename(reference_fasta, ".gz")} \
--OUTPUT ~{output_stem}.dict \
--URI ~{basename(reference_fasta, ".gz")}
gatk \
ScatterIntervalsByNs \
--REFERENCE ~{basename(reference_fasta, ".gz")} \
--OUTPUT_TYPE ACGT \
--MAX_TO_MERGE 500 \
--OUTPUT ~{output_stem}.interval_list
>>>
output {
File sequence_dictionary = "~{output_stem}.dict"
File interval_list = "~{output_stem}.interval_list"
}
runtime {
cpu : "1"
memory: "16 GB"
disks: "local-disk 100 HDD"
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task gatk {
input {
Array[File] bams
File reference_fasta
File reference_fasta_index
File sequence_dictionary
File interval_list
String donor_id
File? bundle_tar
Int num_cpus = 16
Int ram_gb = 128
Int disk_size_gb = 1000
RuntimeEnvironment runtime_environment
}
String final_snp_vcf_name = "snp.out.vcf"
String final_indel_vcf_name = "indel.out.vcf"
command <<<
mkdir bundle
if [[ ~{if defined(bundle_tar) then "1" else "0"} -eq 1 ]]
then
tar -xvzf ~{bundle_tar} -C bundle
fi
mkdir reference
mv ~{reference_fasta_index} ~{sequence_dictionary} ~{interval_list} reference
gzip -dc ~{reference_fasta} > reference/~{basename(reference_fasta, ".gz")}
run-gatk-after-juicer2.sh \
-r reference/~{basename(reference_fasta, ".gz")} \
~{if defined(bundle_tar) then "--gatk-bundle bundle" else ""} \
--sample ~{donor_id} \
--threads ~{num_cpus} \
~{sep=" " bams}
gzip -n ~{final_snp_vcf_name}
gzip -n ~{final_indel_vcf_name}
>>>
output {
File snp_vcf = "~{final_snp_vcf_name}.gz"
File indel_vcf = "~{final_indel_vcf_name}.gz"
}
runtime {
cpu : "~{num_cpus}"
memory: "~{ram_gb} GB"
disks: "local-disk ~{disk_size_gb} HDD"
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task run_3d_dna {
input {
File vcf
Array[File] bams
Int num_cpus = 8
Int disk_size_gb = 2000
Int ram_gb = 100
RuntimeEnvironment runtime_environment
}
command <<<
set -euo pipefail
export VCF_FILENAME=~{basename(vcf, ".gz")}
gzip -dc ~{vcf} > ${VCF_FILENAME}
bash \
/opt/3d-dna/phase/run-hic-phaser-encode.sh \
--threads ~{num_cpus} \
--to-stage update_vcf \
${VCF_FILENAME} \
~{sep=" " bams}
gzip -n *.txt *.vcf *.assembly
ls
>>>
output {
File snp_vcf = "snp.out.vcf.gz"
File hic_vcf = "snp.out_HiC.vcf.gz"
# .hic files
File hic_in= "snp.out.in.hic"
File hic = "snp.out.out.hic"
# Scaffold boundary files (Juicebox 2D annotation format)
File scaffold_track = "snp.out.out_asm.scaffold_track.txt.gz"
File superscaffold_track = "snp.out.out_asm.superscaf_track.txt.gz"
File scaffold_track_in = "snp.out.in_asm.scaffold_track.txt.gz"
File superscaffold_track_in = "snp.out.in_asm.superscaf_track.txt.gz"
File assembly_in = "snp.out.in.assembly.gz"
File assembly = "snp.out.out.assembly.gz"
File psf = "out.psf"
}
runtime {
cpu : "~{num_cpus}"
disks: "local-disk ~{disk_size_gb} HDD"
memory: "~{ram_gb} GB"
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task convert_psf_to_bedpe {
input {
File psf
Int num_cpus = 1
Int disk_size_gb = 1000
Int ram_gb = 16
RuntimeEnvironment runtime_environment
}
command <<<
set -euo pipefail
awk -f /opt/psf-to-bedpe/psf-to-bedpe.awk ~{psf} > "psf.bedpe"
>>>
output {
File bedpe = "psf.bedpe"
}
runtime {
cpu : "~{num_cpus}"
disks: "local-disk ~{disk_size_gb} HDD"
memory: "~{ram_gb} GB"
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}