From bf1c02dff82f6956895d6f687b492d0fda4b8083 Mon Sep 17 00:00:00 2001 From: james hadfield Date: Wed, 19 Feb 2025 09:08:53 +1300 Subject: [PATCH] [export, num_date] use inferred / raw_date attrs These provide two important pieces of information for Auspice: 1. A way to unambiguously know if a tip date was inferred or not. 2. When a tip date was inferred we can now display the raw (ambiguous) date string. Note that the new output would validate on the old schema as additional properties are allowed (by default). --- augur/data/schema-export-v2.json | 8 ++++++++ augur/export_v2.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/augur/data/schema-export-v2.json b/augur/data/schema-export-v2.json index 7b0cb925c..e24789378 100644 --- a/augur/data/schema-export-v2.json +++ b/augur/data/schema-export-v2.json @@ -167,6 +167,14 @@ {"type": "number"}, {"type": "number"} ] + }, + "inferred": { + "type": "boolean", + "description": "[terminal nodes only] was the 'value' inferred or known?" + }, + "raw_value": { + "type": "string", + "description": "[terminal nodes only, and only if inferred=true] the known (ambiguous) date string" } } }, diff --git a/augur/export_v2.py b/augur/export_v2.py index 6484eca7d..4ad9313d3 100644 --- a/augur/export_v2.py +++ b/augur/export_v2.py @@ -859,6 +859,13 @@ def _transfer_num_date(node, raw_data): if is_valid(raw_data.get("num_date", None)): # it's ok not to have temporal information node["node_attrs"]["num_date"] = {"value": format_number(raw_data["num_date"])} node["node_attrs"]["num_date"].update(attr_confidence(node["name"], raw_data, "num_date")) + # For tips, transfer information about whether the date was inferred or known + # and if it was inferred then store the underlying (ambiguous) date string + if len(node.get('children', []))==0 and 'date_inferred' in raw_data: + node["node_attrs"]["num_date"]["inferred"] = raw_data['date_inferred'] + if raw_data['date_inferred'] and raw_data.get('raw_date', False): + node["node_attrs"]["num_date"]["raw_value"] = raw_data['raw_date'] + def _transfer_url_accession(node, raw_data): for prop in ["url", "accession"]: @@ -918,6 +925,7 @@ def node_data_prop_is_normal_trait(name): 'clock_length', 'mutation_length', 'date', + 'date_inferred', 'muts', 'aa_muts', 'sequence',