-
Notifications
You must be signed in to change notification settings - Fork 0
/
pgs_variant_overlap.wdl
175 lines (154 loc) · 4.87 KB
/
pgs_variant_overlap.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
version 1.0
workflow pgs_variant_overlap {
input {
File target_variant_file
String? include
String? exclude
Int? variants_per_batch=5000000
}
call create_score_id_files {
input:
include=include,
exclude=exclude,
variants_per_batch=variants_per_batch
}
scatter (file in create_score_id_files.score_ids_files) {
call combine_score_files {
input:
score_ids_file=file
}
}
scatter (file in combine_score_files.combined_scoring_file) {
call calculate_overlap {
input:
target_variant_file=target_variant_file,
combined_scoring_file=file
}
}
call combine_overlap_files {
input:
files=calculate_overlap.overlap_file
}
call render_overlap_report {
input:
overlap_file=combine_overlap_files.combined_overlap_file
}
output {
File overlap_file = combine_overlap_files.combined_overlap_file
Array[File] match_report = calculate_overlap.match_report
File overlap_report = render_overlap_report.report
}
meta {
author: "Adrienne Stilp"
email: "[email protected]"
}
}
task create_score_id_files {
input {
String? include
String? exclude
Int? variants_per_batch=500000
}
command <<<
python3 /usr/local/primed-pgs-queries/pgs_variant_overlap/create_score_files.py \
--output-dir output \
--variants-per-batch ~{variants_per_batch} \
~{"--include " + include } \
~{"--exclude " + exclude }
>>>
output {
Array[File] score_ids_files = glob("output/score_ids_*.txt")
}
runtime {
# Pull from DockerHub
docker: "uwgac/primed-pgs-queries:0.4.1"
}
}
task combine_score_files {
input {
File score_ids_file
}
command <<<
set -e -o pipefail
mkdir tmp
# Download the scoring files
while IFS= read -r line || [[ -n "$line" ]]; do
sleep 10
pgscatalog-download --pgs $line --build GRCh38 -o tmp/
done < ~{score_ids_file}
# pgscatalog-download --pgs $(cat ~{score_ids_file}) --build GRCh38 -o tmp/
# Combine the scoring files
pgscatalog-combine -s tmp/PGS*.txt.gz -t GRCh38 -o combined.txt.gz
>>>
output {
File combined_scoring_file = "combined.txt.gz"
}
runtime {
# Pull from DockerHub
docker: "uwgac/primed-pgs-queries:0.4.1"
memory: "16 G"
}
}
task calculate_overlap {
input {
File target_variant_file
File combined_scoring_file
}
Float combined_scoring_file_size = size(combined_scoring_file, "GB")
Float target_variant_file_size = size(target_variant_file, "GB")
Int mem_gb = ceil(2 * combined_scoring_file_size + 2 * target_variant_file_size) + 10
command <<<
set -e -o pipefail
echo "combined scoring file size: " ~{combined_scoring_file_size}
echo "target variant file size: " ~{target_variant_file_size}
echo "requested memory: " ~{mem_gb}
mkdir output
# Calculate the overlap.
pgscatalog-match --dataset primed --scorefiles ~{combined_scoring_file} --target ~{target_variant_file} --outdir output --only_match
# Call a script to process overlap.
cp /usr/local/primed-pgs-queries/pgs_variant_overlap/calculate_overlap.Rmd .
R -e "rmarkdown::render('calculate_overlap.Rmd', params=list(matches_file='output/0.ipc.zst', combined_scoring_file='~{combined_scoring_file}'))"
>>>
output {
File overlap_file = "overlap_fraction.tsv"
File match_report="calculate_overlap.html"
}
runtime {
# Pull from DockerHub
docker: "uwgac/primed-pgs-queries:0.4.1"
memory: mem_gb + " GB"
}
}
task combine_overlap_files {
input {
Array[File] files
}
command <<<
# Combine files with the header row from only the first.
# Stack overflow: xhttps://stackoverflow.com/questions/40027867/how-to-concatenate-multiple-files-with-same-header-some-of-the-files-only-have-h
awk 'FNR>1 || NR==1' ~{sep=" " files} > overlap_fraction_combined.txt
>>>
output {
File combined_overlap_file = "overlap_fraction_combined.txt"
}
runtime {
# Pull from DockerHub
docker: "uwgac/primed-pgs-queries:0.4.1"
}
}
task render_overlap_report {
input {
File overlap_file
}
command <<<
cp /usr/local/primed-pgs-queries/pgs_variant_overlap/overlap_report.Rmd .
R -e "rmarkdown::render('overlap_report.Rmd', params=list(overlap_file='~{overlap_file}'))"
>>>
output {
File report = "overlap_report.html"
}
runtime {
# Pull from DockerHub
docker: "uwgac/primed-pgs-queries:0.4.1"
}
}