Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix order of exported colorings from augur export v2 when color by metadata is used #1177

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions scripts/diff_jsons.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
parser.add_argument("--significant-digits", type=int, default=5, help="number of significant digits to use when comparing numeric values")
parser.add_argument("--exclude-paths", nargs="+", help="list of paths to exclude from consideration when performing a diff", default=["root['generated_by']['version']"])
parser.add_argument("--exclude-regex-paths", nargs="+", help="list of path regular expressions to exclude from consideration when performing a diff")
parser.add_argument("--pretty", action="store_true", help="use DeepDiff's pretty method when printing differences")

args = parser.parse_args()

Expand All @@ -24,12 +25,15 @@
with open(args.second_json, "r") as fh:
second_json = json.load(fh)

print(
deepdiff.DeepDiff(
first_json,
second_json,
significant_digits=args.significant_digits,
exclude_paths=args.exclude_paths,
exclude_regex_paths=args.exclude_regex_paths,
)
difference = deepdiff.DeepDiff(
first_json,
second_json,
significant_digits=args.significant_digits,
exclude_paths=args.exclude_paths,
exclude_regex_paths=args.exclude_regex_paths,
)

if args.pretty:
difference = difference.pretty()

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

Run export with metadata and color by a metadata column ("custom_trait") in addition to colorings defined in the node data.

$ ${AUGUR} export v2 \
> --tree export_v2/tree.nwk \
> --metadata export_v2/dataset1_metadata_with_strain.tsv \
> --node-data export_v2/div_node-data.json export_v2/location_node-data.json \
> --auspice-config export_v2/auspice_config1.json \
> --maintainers "Nextstrain Team" \
> --color-by-metadata custom_trait \
> --output "$TMP/dataset_with_color_from_metadata.json" > /dev/null
WARNING: [config file] Trait 'custom_trait' is missing type information. We've guessed 'categorical'.
\s{0} (re)

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

$ popd > /dev/null
14 changes: 7 additions & 7 deletions tests/functional/export_v2/dataset1_metadata_with_strain.tsv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
strain div mutation_length
tipA 1 1
tipB 3 1
tipC 3 1
tipD 8 3
tipE 9 4
tipF 6 1
strain div mutation_length custom_trait
tipA 1 1 A
tipB 3 1 A
tipC 3 1 B
tipD 8 3 B
tipE 9 4 C
tipF 6 1 D
248 changes: 248 additions & 0 deletions tests/functional/export_v2/dataset_with_color_from_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
{
"meta": {
"colorings": [
{
"key": "location",
"legend": [
{
"display": "\u03b1",
"value": "alpha"
},
{
"value": "beta"
}
],
"scale": [
[
"beta",
"#bd0026"
],
[
"gamma",
"#6a51a3"
]
],
"title": "Location",
"type": "categorical"
},
{
"key": "mutation_length",
"legend": [
{
"bounds": [
-1,
2
],
"display": "0-2",
"value": 1
},
{
"bounds": [
2,
5
],
"display": "3-5",
"value": 3
},
{
"bounds": [
5,
10
],
"display": ">5",
"value": 5
}
],
"scale": [
[
1,
"#081d58"
],
[
3,
"#1d91c0"
],
[
5,
"#c7e9b4"
]
],
"title": "Mutations per branch",
"type": "continuous"
},
{
"key": "location",
"legend": [
{
"display": "\u03b1",
"value": "alpha"
},
{
"value": "beta"
}
],
"scale": [
[
"beta",
"#bd0026"
],
[
"gamma",
"#6a51a3"
]
],
"title": "Location",
"type": "categorical"
},
{
"key": "custom_trait",
"title": "custom_trait",
"type": "categorical"
}
],
"filters": [
"location",
"custom_trait"
],
"panels": [
"tree"
],
"updated": "2021-06-09"
},
"tree": {
"branch_attrs": {},
"children": [
{
"branch_attrs": {},
"name": "tipA",
"node_attrs": {
"div": 1,
"location": {
"value": "delta"
},
"mutation_length": {
"value": 1
},
"custom_trait": {
"value": "A"
}
}
},
{
"branch_attrs": {},
"children": [
{
"branch_attrs": {},
"name": "tipB",
"node_attrs": {
"div": 3,
"location": {
"value": "gamma"
},
"mutation_length": {
"value": 1
},
"custom_trait": {
"value": "A"
}
}
},
{
"branch_attrs": {},
"name": "tipC",
"node_attrs": {
"div": 3,
"location": {
"value": "gamma"
},
"mutation_length": {
"value": 1
},
"custom_trait": {
"value": "B"
}
}
}
],
"name": "internalBC",
"node_attrs": {
"div": 2,
"mutation_length": {
"value": 2
}
}
},
{
"branch_attrs": {},
"children": [
{
"branch_attrs": {},
"name": "tipD",
"node_attrs": {
"div": 8,
"location": {
"value": "alpha"
},
"mutation_length": {
"value": 3
},
"custom_trait": {
"value": "B"
}
}
},
{
"branch_attrs": {},
"name": "tipE",
"node_attrs": {
"div": 9,
"location": {
"value": "alpha"
},
"mutation_length": {
"value": 4
},
"custom_trait": {
"value": "C"
}
}
},
{
"branch_attrs": {},
"name": "tipF",
"node_attrs": {
"div": 6,
"location": {
"value": "beta"
},
"mutation_length": {
"value": 1
},
"custom_trait": {
"value": "D"
}
}
}
],
"name": "internalDEF",
"node_attrs": {
"div": 5,
"location": {
"value": "alpha"
},
"mutation_length": {
"value": 5
}
}
}
],
"name": "ROOT",
"node_attrs": {
"div": 0,
"mutation_length": {
"value": 0
}
}
},
"version": "v2"
}