-
Notifications
You must be signed in to change notification settings - Fork 11
/
export.smk
180 lines (169 loc) · 6.48 KB
/
export.smk
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
"""
This part of the workflow collects the phylogenetic tree and annotations to
export a Nextstrain dataset.
REQUIRED INPUTS:
metadata = data/metadata_all.tsv
tree = results/tree.nwk
branch_lengths = results/branch_lengths.json
node_data = results/*.json
OUTPUTS:
auspice_json = auspice/${build_name}.json
There are optional sidecar JSON files that can be exported as part of the dataset.
See Nextstrain's data format docs for more details on sidecar files:
https://docs.nextstrain.org/page/reference/data-formats.html
This part of the workflow usually includes the following steps:
- augur export v2
- augur frequencies
See Augur's usage docs for these commands for more details.
"""
import json
rule colors:
input:
color_schemes = "config/color_schemes.tsv",
color_orderings = "config/color_orderings.tsv",
metadata = "data/metadata_{serotype}.tsv",
output:
colors = "results/colors_{serotype}.tsv"
shell:
"""
python3 scripts/assign-colors.py \
--color-schemes {input.color_schemes} \
--ordering {input.color_orderings} \
--metadata {input.metadata} \
--output {output.colors}
"""
rule prepare_auspice_config:
"""Prepare the auspice config file for each serotypes"""
output:
auspice_config="results/config/{gene}/auspice_config_{serotype}.json",
params:
replace_clade_key=lambda wildcard: r"clade_membership" if wildcard.gene in ['genome'] else r"genotype_nextclade",
replace_clade_title=lambda wildcard: r"Serotype" if wildcard.serotype in ['all'] else r"Dengue Genotype (Nextclade)",
run:
data = {
"title": "Real-time tracking of dengue virus evolution",
"maintainers": [
{"name": "the Nextstrain team", "url": "https://nextstrain.org/team"}
],
"data_provenance": [
{
"name": "GenBank",
"url": "https://www.ncbi.nlm.nih.gov/genbank/"
}
],
"build_url": "https://github.com/nextstrain/dengue",
"colorings": [
{
"key": "gt",
"title": "Genotype",
"type": "categorical"
},
{
"key": "num_date",
"title": "Date",
"type": "continuous"
},
{
"key": "country",
"title": "Country",
"type": "categorical"
},
{
"key": "region",
"title": "Region",
"type": "categorical"
},
{
"key": "genotype_nextclade",
"title": "Dengue Genotype (Nextclade)",
"type": "categorical"
},
{
"key": "serotype_genbank",
"title": "Serotype (Genbank metadata)",
"type": "categorical"
}
],
"geo_resolutions": [
"country",
"region"
],
"display_defaults": {
"map_triplicate": True,
"color_by": params.replace_clade_key
},
"filters": [
"country",
"region",
"author"
],
"metadata_columns": [
"genbank_accession"
]
}
# During genome/dengue_all workflows, clade membership represents Serotype
# While genome/dengue_denvX workflows, clade_membership represents the more detailed Genotype
if params.replace_clade_key == 'clade_membership':
if wildcards.gene in ['genome'] and wildcards.serotype in ['all']:
clade_membership_title="Serotype (Nextstrain)"
else:
clade_membership_title="Dengue Genotype (Nextstrain)"
data["colorings"].append({
"key": "clade_membership",
"title": clade_membership_title,
"type": "categorical"
})
else:
# During E/dengue_all workflows, default color by Serotype
if wildcards.serotype in ['all']:
data["display_defaults"]["color_by"]="serotype_genbank"
with open(output.auspice_config, 'w') as fh:
json.dump(data, fh, indent=2)
rule export:
"""Exporting data files for auspice"""
input:
tree = "results/{gene}/tree_{serotype}.nwk",
metadata = "data/metadata_{serotype}.tsv",
branch_lengths = "results/{gene}/branch-lengths_{serotype}.json",
traits = "results/{gene}/traits_{serotype}.json",
clades = lambda wildcard: "results/{gene}/clades_{serotype}.json" if wildcard.gene in ['genome'] else [],
nt_muts = "results/{gene}/nt-muts_{serotype}.json",
aa_muts = "results/{gene}/aa-muts_{serotype}.json",
description = config["export"]["description"],
auspice_config = "results/config/{gene}/auspice_config_{serotype}.json",
colors = "results/colors_{serotype}.tsv",
output:
auspice_json = "results/{gene}/raw_dengue_{serotype}.json"
params:
strain_id = config.get("strain_id_field", "strain"),
shell:
"""
augur export v2 \
--tree {input.tree} \
--metadata {input.metadata} \
--metadata-id-columns {params.strain_id} \
--node-data {input.branch_lengths} {input.traits} {input.clades} {input.nt_muts} {input.aa_muts} \
--colors {input.colors} \
--description {input.description} \
--auspice-config {input.auspice_config} \
--include-root-sequence-inline \
--output {output.auspice_json}
"""
rule final_strain_name:
input:
auspice_json="results/{gene}/raw_dengue_{serotype}.json",
metadata="data/metadata_{serotype}.tsv",
output:
auspice_json="auspice/dengue_{serotype}_{gene}.json"
params:
strain_id=config.get("strain_id_field", "strain"),
display_strain_field=config.get("display_strain_field", "strain"),
shell:
"""
python3 scripts/set_final_strain_name.py \
--metadata {input.metadata} \
--metadata-id-columns {params.strain_id} \
--input-auspice-json {input.auspice_json} \
--display-strain-name {params.display_strain_field} \
--output {output.auspice_json}
"""