Skip to content

Commit 1e3272a

Browse files
authored
Merge pull request #1218 from nextstrain/james/export-fixes
Fixes to augur export
2 parents 497a5ea + 9e9d4a4 commit 1e3272a

File tree

6 files changed

+20
-83
lines changed

6 files changed

+20
-83
lines changed

CHANGES.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44

55
### Bug fixes
66

7+
* export: No longer export duplicate entries in the colorings array, a bug which has been present in Augur since at least v12 [#719][]. [#1218][] (@jameshadfield)
8+
9+
* export: In version 22.0.0, some configurations of export may have resulted in the clade coloring appearing last in the Auspice dropdown rather than first. This is now fixed. [#1218] (@jameshadfield)
10+
711
* export: In version 22.0.0, validation of `augur.utils.read_node_data` was changed to error when a node data JSON did not contain any actual data. This causes export to error when an empty node data JSON is passed, as for example in ncov's pathogen-ci. This is now fixed by warning instead. The bug was originally introduced in PR [#728][]. [#1214][] (@corneliusroemer)
812

13+
[#719]: https://github.com/nextstrain/augur/issues/719
914
[#1214]: https://github.com/nextstrain/augur/pull/1214
15+
[#1218]: https://github.com/nextstrain/augur/pull/1218
1016

1117
## 22.0.0 (9 May 2023)
1218

augur/export_v2.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,14 @@ def _add_title_and_type(coloring):
355355
return False # a warning message will have been printed before `InvalidOption` is raised
356356
return coloring
357357

358-
def _create_coloring(key):
358+
def _add_coloring(colorings, key):
359359
# handle deprecations
360360
if key == "authors":
361361
deprecated("[colorings] The 'authors' key is now called 'author'")
362362
key = "author"
363-
return {"key": key}
363+
# check if the key has already been added by another part of the color-creating logic
364+
if key not in {x['key'] for x in colorings}:
365+
colorings.append({"key": key})
364366

365367
def _is_valid(coloring):
366368
key = coloring["key"]
@@ -389,18 +391,18 @@ def _get_colorings():
389391
if command_line_colorings:
390392
# start with auto_colorings (already validated to be included)
391393
for x in auto_colorings:
392-
colorings.append(_create_coloring(x))
394+
_add_coloring(colorings, x)
393395
# then add in command line colorings
394396
for x in command_line_colorings:
395-
colorings.append(_create_coloring(x))
397+
_add_coloring(colorings, x)
396398
else:
397399
# if we have a config file, start with these (extra info, such as title&type, is added in later)
398400
if config:
399401
for x in config.keys():
400-
colorings.append(_create_coloring(x))
402+
_add_coloring(colorings, x)
401403
# then add in any auto-colorings already validated to include
402404
for x in auto_colorings:
403-
colorings.append(_create_coloring(x))
405+
_add_coloring(colorings, x)
404406

405407
explicitly_defined_colorings = [x["key"] for x in colorings]
406408
# add in genotype as a special case if (a) not already set and (b) the data supports it
@@ -794,8 +796,9 @@ def node_data_prop_is_normal_trait(name):
794796
"authors", # authors are set as a node property, not a trait property
795797
"author", # see above
796798
"vaccine", # vaccine info is stored as a "special" node prop
799+
'clade_membership', # explicitly set as a coloring if present
797800
'branch_length',
798-
'num_date',
801+
'num_date', # explicitly set as a coloring if present
799802
'raw_date',
800803
'numdate',
801804
'clock_length',

tests/functional/export_v2/dataset-with-branch-labels.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
},
2626
"colorings": [
2727
{
28-
"key": "gt",
29-
"title": "Genotype",
28+
"key": "clade_membership",
29+
"title": "Clade",
3030
"type": "categorical"
3131
},
3232
{
33-
"key": "clade_membership",
34-
"title": "Clade",
33+
"key": "gt",
34+
"title": "Genotype",
3535
"type": "categorical"
3636
}
3737
],

tests/functional/export_v2/dataset1.json

-24
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,6 @@
6969
],
7070
"title": "Mutations per branch",
7171
"type": "continuous"
72-
},
73-
{
74-
"key": "location",
75-
"legend": [
76-
{
77-
"display": "\u03b1",
78-
"value": "alpha"
79-
},
80-
{
81-
"value": "beta"
82-
}
83-
],
84-
"scale": [
85-
[
86-
"beta",
87-
"#bd0026"
88-
],
89-
[
90-
"gamma",
91-
"#6a51a3"
92-
]
93-
],
94-
"title": "Location",
95-
"type": "categorical"
9672
}
9773
],
9874
"filters": [

tests/functional/export_v2/dataset2.json

-24
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,6 @@
6969
],
7070
"title": "Mutations per branch",
7171
"type": "continuous"
72-
},
73-
{
74-
"key": "location",
75-
"legend": [
76-
{
77-
"display": "\u03b1",
78-
"value": "alpha"
79-
},
80-
{
81-
"value": "beta"
82-
}
83-
],
84-
"scale": [
85-
[
86-
"beta",
87-
"#bd0026"
88-
],
89-
[
90-
"gamma",
91-
"#6a51a3"
92-
]
93-
],
94-
"title": "Location",
95-
"type": "categorical"
9672
}
9773
],
9874
"filters": [

tests/functional/export_v2/dataset3.json

-24
Original file line numberDiff line numberDiff line change
@@ -82,30 +82,6 @@
8282
"#4042C7"
8383
]
8484
]
85-
},
86-
{
87-
"key": "location",
88-
"title": "Location",
89-
"type": "categorical",
90-
"scale": [
91-
[
92-
"beta",
93-
"#bd0026"
94-
],
95-
[
96-
"gamma",
97-
"#6a51a3"
98-
]
99-
],
100-
"legend": [
101-
{
102-
"value": "alpha",
103-
"display": "\u03b1"
104-
},
105-
{
106-
"value": "beta"
107-
}
108-
]
10985
}
11086
],
11187
"filters": [

0 commit comments

Comments
 (0)