Skip to content

Commit

Permalink
Merge branch 'branch_label_allow'
Browse files Browse the repository at this point in the history
* branch_label_allow:
  Add "clean" rule to validation tests
  Check branch labels upon v2 dataset JSON validation
  allow config/validate of branch_label display default (v2)
  • Loading branch information
jameshadfield committed Feb 26, 2020
2 parents 9800528 + f4ea7a0 commit a73ad8f
Show file tree
Hide file tree
Showing 7 changed files with 622 additions and 2 deletions.
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 @@ -719,7 +719,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))

return not warnings


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

0 comments on commit a73ad8f

Please sign in to comment.