Skip to content

Commit

Permalink
Do not produce duplicate coloring entries
Browse files Browse the repository at this point in the history
The logic for creating colorings involves many steps, and when adding a
coloring we had neglected to check if it had already been added.
For instance, colorings explicitly defined in the auspice-config
which were provided via node-data files (rather than the metadata tsv)
would be added twice. In our current nCoV build there are 7 such
duplicates! There were also a few duplicates that were present in our
tests. Whoops! These weren't a problem for auspice (the first was used),
but added unnecessary complexity and bytes to the JSON.

Closes #719
  • Loading branch information
jameshadfield committed May 16, 2023
1 parent 497a5ea commit 5daf6e8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 78 deletions.
16 changes: 10 additions & 6 deletions augur/export_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,16 @@ def _add_title_and_type(coloring):
return False # a warning message will have been printed before `InvalidOption` is raised
return coloring

def _create_coloring(key):
def _add_coloring(colorings, key):
# handle deprecations
if key == "authors":
deprecated("[colorings] The 'authors' key is now called 'author'")
key = "author"
return {"key": key}
# check if the key has already been added by another part of the color-creating logic
if key in {x['key'] for x in colorings}:
return False
colorings.append({"key": key})
return True

def _is_valid(coloring):
key = coloring["key"]
Expand Down Expand Up @@ -389,18 +393,18 @@ def _get_colorings():
if command_line_colorings:
# start with auto_colorings (already validated to be included)
for x in auto_colorings:
colorings.append(_create_coloring(x))
_add_coloring(colorings, x)
# then add in command line colorings
for x in command_line_colorings:
colorings.append(_create_coloring(x))
_add_coloring(colorings, x)
else:
# if we have a config file, start with these (extra info, such as title&type, is added in later)
if config:
for x in config.keys():
colorings.append(_create_coloring(x))
_add_coloring(colorings, x)
# then add in any auto-colorings already validated to include
for x in auto_colorings:
colorings.append(_create_coloring(x))
_add_coloring(colorings, x)

explicitly_defined_colorings = [x["key"] for x in colorings]
# add in genotype as a special case if (a) not already set and (b) the data supports it
Expand Down
24 changes: 0 additions & 24 deletions tests/functional/export_v2/dataset1.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,6 @@
],
"title": "Mutations per branch",
"type": "continuous"
},
{
"key": "location",
"legend": [
{
"display": "\u03b1",
"value": "alpha"
},
{
"value": "beta"
}
],
"scale": [
[
"beta",
"#bd0026"
],
[
"gamma",
"#6a51a3"
]
],
"title": "Location",
"type": "categorical"
}
],
"filters": [
Expand Down
24 changes: 0 additions & 24 deletions tests/functional/export_v2/dataset2.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,6 @@
],
"title": "Mutations per branch",
"type": "continuous"
},
{
"key": "location",
"legend": [
{
"display": "\u03b1",
"value": "alpha"
},
{
"value": "beta"
}
],
"scale": [
[
"beta",
"#bd0026"
],
[
"gamma",
"#6a51a3"
]
],
"title": "Location",
"type": "categorical"
}
],
"filters": [
Expand Down
24 changes: 0 additions & 24 deletions tests/functional/export_v2/dataset3.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,30 +82,6 @@
"#4042C7"
]
]
},
{
"key": "location",
"title": "Location",
"type": "categorical",
"scale": [
[
"beta",
"#bd0026"
],
[
"gamma",
"#6a51a3"
]
],
"legend": [
{
"value": "alpha",
"display": "\u03b1"
},
{
"value": "beta"
}
]
}
],
"filters": [
Expand Down

0 comments on commit 5daf6e8

Please sign in to comment.