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

Allow config/validate of branch_label in display_defaults #445

Merged
merged 3 commits into from
Feb 26, 2020
Merged
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
4 changes: 4 additions & 0 deletions augur/data/schema-auspice-config-v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@
"layout": {
"type": "string",
"enum": ["rect", "radial", "unrooted", "clock"]
},
"branch_label": {
"type": "string",
"enum": ["clade", "aa", "none"]
}
}
},
Expand Down
6 changes: 5 additions & 1 deletion augur/data/schema-export-v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,14 @@
"description": "Default tree layout",
"type": "string",
"enum": ["rect", "radial", "unrooted", "clock"]
},
},
"map_triplicate": {
"description": "Should the map be extended / wrapped around. Useful if transmissions are worldwide.",
"type": "boolean"
},
"branch_label": {
"description": "What branch label should be displayed by default.",
"type": "string"
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion augur/export_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,8 @@ def set_display_defaults(data_json, config):
["color_by", "colorBy"],
["distance_measure", "distanceMeasure"],
["map_triplicate", "mapTriplicate"],
["layout", "layout"]
["layout", "layout"],
["branch_label", "branch_label"]
]

display_defaults = {}
Expand Down
14 changes: 14 additions & 0 deletions augur/validate_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ def recurse(node):
genes -= {"nuc"}
return genes

def collectBranchLabels(root):
labels = set()
def recurse(node):
labels.update(node.get("branch_attrs", {}).get("labels", {}).keys())
if "children" in node:
[recurse(child) for child in node["children"]]
recurse(root)
return labels

def verifyMainJSONIsInternallyConsistent(data, ValidateError):
"""
Expand Down Expand Up @@ -144,6 +152,12 @@ def warn(msg):
if gene not in data["meta"]["genome_annotations"]:
warn("The tree defined mutations on gene {} which doesn't appear in the metadata annotations object.".format(gene))

default_branch_label = data.get("meta").get("display_defaults", {}).get("branch_label")
if default_branch_label and default_branch_label.lower() != "none":
labels = collectBranchLabels(data['tree'])
if not default_branch_label in labels:
warn("Default label to display \"{}\" isn't found anywhere on the tree!".format(default_branch_label))

if not warnings:
print("Validation succeeded")
else:
Expand Down
1 change: 1 addition & 0 deletions tests/builds/validation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!/auspice/*
9 changes: 9 additions & 0 deletions tests/builds/validation/Snakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rule all:
shell:
"""
augur validate export-v2 auspice/v2_zika.json
"""

rule clean:
run:
pass
Loading