forked from nextstrain/WNV-old
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Snakefile
249 lines (234 loc) · 7.43 KB
/
Snakefile
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
rule all:
input:
auspice_tree = "auspice/WNV_NA_tree.json",
auspice_meta = "auspice/WNV_NA_meta.json",
rule files:
params:
input_fasta = "data/full_dataset.fasta",
input_metadata = "data/headers.csv",
reference = "config/reference.gb",
auspice_config = "config/auspice_config.json",
lat_longs = "config/lat_longs.tsv"
files = rules.files.params
rule parse:
message:
"Parsing {input.sequences}, {input.metadata} and forming FASTA + metadata TSV"
input:
sequences = files.input_fasta,
metadata = files.input_metadata
output:
sequences = "results/sequences.fasta",
metadata = "results/metadata_sans_authors.tsv"
shell:
"""
python ./scripts/parse_fasta_csv.py {input.sequences} {input.metadata} {output.sequences} {output.metadata}
"""
rule add_authors:
message:
"Adding authors to {input.metadata} -> {output.metadata} by collecting info from ENTREZ"
input:
metadata = rules.parse.output.metadata
output:
metadata = "results/metadata.tsv"
shell:
"""
python ./scripts/add_authors.py {input.metadata} {output.metadata}
"""
rule create_colors:
message:
"Creating custom color scale in {output.colors}"
input:
metadata = rules.parse.output.metadata,
output:
colors = "results/colors.tsv"
shell:
"""
python ./scripts/make_colors.py {input.metadata} {output.colors}
"""
rule create_lat_longs:
message:
"Creating lat/longs in {output.lat_longs}"
input:
metadata = rules.parse.output.metadata,
output:
lat_longs = "results/lat_longs.tsv"
shell:
"""
python ./scripts/create_lat_longs.py {input.metadata} {output.lat_longs}
"""
rule align:
message:
"""
Aligning sequences to {input.reference}
- filling gaps with N
"""
input:
sequences = rules.parse.output.sequences,
reference = files.reference
output:
alignment = "results/aligned.fasta"
shell:
"""
augur align \
--sequences {input.sequences} \
--reference-sequence {input.reference} \
--output {output.alignment} \
--fill-gaps
"""
rule tree:
message: "Building tree"
input:
alignment = rules.align.output.alignment
output:
tree = "results/tree_raw.nwk"
shell:
"""
augur tree \
--alignment {input.alignment} \
--output {output.tree} \
--method raxml \
--nthreads auto
"""
rule refine:
message:
"""
Refining tree
- estimate timetree
- use {params.coalescent} coalescent timescale
- estimate {params.date_inference} node dates
- filter tips more than {params.clock_filter_iqd} IQDs from clock expectation
"""
input:
tree = rules.tree.output.tree,
alignment = rules.align.output,
metadata = rules.parse.output.metadata
output:
tree = "results/tree.nwk",
node_data = "results/branch_lengths.json"
params:
coalescent = "opt",
date_inference = "marginal",
clock_filter_iqd = 4
shell:
"""
augur refine \
--tree {input.tree} \
--alignment {input.alignment} \
--metadata {input.metadata} \
--output-tree {output.tree} \
--output-node-data {output.node_data} \
--timetree \
--coalescent {params.coalescent} \
--date-confidence \
--root AF481864
"""
rule ancestral:
message: "Reconstructing ancestral sequences and mutations"
input:
tree = rules.refine.output.tree,
alignment = rules.align.output
output:
node_data = "results/nt_muts.json"
params:
inference = "joint"
shell:
"""
augur ancestral \
--tree {input.tree} \
--alignment {input.alignment} \
--output {output.node_data} \
--inference {params.inference}
"""
rule translate:
message: "Translating amino acid sequences"
input:
tree = rules.refine.output.tree,
node_data = rules.ancestral.output.node_data,
reference = files.reference
output:
node_data = "results/aa_muts.json"
shell:
"""
augur translate \
--tree {input.tree} \
--ancestral-sequences {input.node_data} \
--reference-sequence {input.reference} \
--output {output.node_data} \
"""
rule traits:
message: "Inferring ancestral traits for {params.columns!s}"
input:
tree = rules.refine.output.tree,
metadata = rules.parse.output.metadata
output:
node_data = "results/traits.json",
params:
columns = "state lineage"
shell:
"""
augur traits \
--tree {input.tree} \
--metadata {input.metadata} \
--output {output.node_data} \
--columns {params.columns} \
--confidence
"""
rule export:
message: "Exporting data files for for auspice using V1 JSON schema"
input:
tree = rules.refine.output.tree,
metadata = rules.add_authors.output.metadata,
branch_lengths = rules.refine.output.node_data,
traits = rules.traits.output.node_data,
nt_muts = rules.ancestral.output.node_data,
aa_muts = rules.translate.output.node_data,
colors = rules.create_colors.output.colors,
lat_longs = rules.create_lat_longs.output.lat_longs,
auspice_config = files.auspice_config
output:
auspice_tree = rules.all.input.auspice_tree,
auspice_meta = rules.all.input.auspice_meta
shell:
"""
augur export v1\
--tree {input.tree} \
--metadata {input.metadata} \
--node-data {input.branch_lengths} {input.traits} {input.nt_muts} {input.aa_muts} \
--colors {input.colors} \
--auspice-config {input.auspice_config} \
--lat-longs {input.lat_longs} \
--output-tree {output.auspice_tree} \
--output-meta {output.auspice_meta}
"""
rule export_v2:
message: "Exporting data files for for auspice using V2 JSON schema"
input:
tree = rules.refine.output.tree,
metadata = rules.add_authors.output.metadata,
branch_lengths = rules.refine.output.node_data,
traits = rules.traits.output.node_data,
nt_muts = rules.ancestral.output.node_data,
aa_muts = rules.translate.output.node_data,
colors = rules.create_colors.output.colors,
lat_longs = rules.create_lat_longs.output.lat_longs,
auspice_config = "config/auspice_config_v2.json"
output:
auspice = "auspice/WNV-nextstrain_NA.json"
shell:
"""
augur export v2 \
--tree {input.tree} \
--metadata {input.metadata} \
--node-data {input.branch_lengths} {input.traits} {input.nt_muts} {input.aa_muts} \
--colors {input.colors} \
--auspice-config {input.auspice_config} \
--lat-longs {input.lat_longs} \
--output {output.auspice}
"""
rule clean:
message: "Removing directories: {params}"
params:
"results ",
"auspice"
shell:
"rm -rfv {params}"