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

Export ambiguous date strings for tips #1760

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions augur/data/schema-export-v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
},
Expand Down
8 changes: 8 additions & 0 deletions augur/export_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Comment on lines +865 to +866
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the check for raw_data['date_inferred'] in L866 after it's already been used in L865?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be false (not inferred, i.e. known) and if so then date==raw_date so we don't export the raw date string.

node["node_attrs"]["num_date"]["raw_value"] = raw_data['raw_date']


def _transfer_url_accession(node, raw_data):
for prop in ["url", "accession"]:
Expand Down Expand Up @@ -918,6 +925,7 @@ def node_data_prop_is_normal_trait(name):
'clock_length',
'mutation_length',
'date',
'date_inferred',
'muts',
'aa_muts',
'sequence',
Expand Down
6 changes: 5 additions & 1 deletion augur/refine.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,11 @@ def run(args):
)
return 1

attributes.extend(['numdate', 'clock_length', 'mutation_length', 'raw_date', 'date'])
for node in T.find_clades():
inferred = node.raw_date_constraint is None or isinstance(node.raw_date_constraint, list)
setattr(node, 'date_inferred', inferred)

attributes.extend(['numdate', 'clock_length', 'mutation_length', 'raw_date', 'date', 'date_inferred'])
if args.date_confidence:
attributes.append('num_date_confidence')
else:
Expand Down
Loading