Skip to content

Commit

Permalink
export_v2: Make "none" an invalid coloring key
Browse files Browse the repository at this point in the history
Update `augur export v2` to warn about the invalid coloring "none" key
and skip it in export so that it does not include a coloring key that
will clash with the recent change in Auspice to use "none" to hide
tip labels¹.

¹ nextstrain/auspice#1618
  • Loading branch information
joverlee521 committed Dec 13, 2022
1 parent cbe48e1 commit a0756a9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
3 changes: 3 additions & 0 deletions augur/export_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ def _is_valid(coloring):
if key != "gt" and not trait_values:
warn("You asked for a color-by for trait '{}', but it has no values on the tree. It has been ignored.".format(key))
return False
if key == "none":
warn(f"You asked for a color-by for trait {key!r}, but this is an invalid coloring key. It has been ignored.")
return False
return True

def _get_colorings():
Expand Down
18 changes: 18 additions & 0 deletions tests/functional/export_v2.t
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,23 @@ Run export with metadata and external colors TSV that contains zero values.
{}
$ rm -f "$TMP/dataset6.json"

Run export with metadata that contains "none" column and asked to use as coloring.
This is expected to output a warning that "none" is an invalid coloring column and skip it in colorings.

$ ${AUGUR} export v2 \
> --tree export_v2/tree.nwk \
> --metadata export_v2/dataset1_metadata_with_none_column.tsv \
> --node-data export_v2/div_node-data.json export_v2/location_node-data.json \
> --auspice-config export_v2/auspice_config5.json \
> --maintainers "Nextstrain Team" \
> --output "$TMP/dataset7.json" > /dev/null
WARNING: You asked for a color-by for trait 'none', but this is an invalid coloring key. It has been ignored.
\s{0} (re)

$ python3 "$TESTDIR/../../scripts/diff_jsons.py" export_v2/dataset1.json "$TMP/dataset7.json" \
> --exclude-paths "root['meta']['updated']" "root['meta']['maintainers']"
{}
$ rm -f "$TMP/dataset1.json"


$ popd > /dev/null
37 changes: 37 additions & 0 deletions tests/functional/export_v2/auspice_config5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"colorings": [
{
"key": "location",
"title": "Location",
"type": "categorical",
"legend": [
{"value": "alpha", "display": "α"},
{"value": "beta"}
],
"scale": [
["beta", "#bd0026"],
["gamma", "#6a51a3"]
]
},
{
"key": "mutation_length",
"title": "Mutations per branch",
"type": "continuous",
"legend": [
{"value": 1, "display": "0-2", "bounds": [-1,2]},
{"value": 3, "display": "3-5", "bounds": [2,5]},
{"value": 5, "display": ">5", "bounds": [5, 10]}
],
"scale": [
[1, "#081d58"],
[3, "#1d91c0"],
[5, "#c7e9b4"]
]
},
{
"key": "none",
"title": "None",
"type": "boolean"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
strain div mutation_length none
tipA 1 1 A
tipB 3 1 B
tipC 3 1 C
tipD 8 3 D
tipE 9 4 E
tipF 6 1 F

0 comments on commit a0756a9

Please sign in to comment.