Skip to content

Commit

Permalink
Add sampling year coloring
Browse files Browse the repository at this point in the history
For builds where we've chosen not to infer a timetree it's still very
useful to communicate the sampling date. Here we export the year which
forms a nice continuous coloring. (An ordinal coloring would be better
but the date range in this dataset means Auspice repeats colors which
isn't ideal. Temporal coloring will be better once it accepts YYYY-MM-DD
strings, but as of Auspice 2.55 it interprets integers as January 1st.)
  • Loading branch information
jameshadfield committed Aug 22, 2024
1 parent 67b7941 commit 0162bf4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions phylogenetic/defaults/auspice_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
"title": "Country",
"type": "categorical"
},
{
"key": "year",
"title": "Sampling year",
"type": "continuous"
},
{
"key": "host",
"title": "Host",
Expand Down
15 changes: 15 additions & 0 deletions phylogenetic/rules/annotate_phylogeny.smk
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,18 @@ rule translate:
--output {output.node_data} \
2>&1 | tee {log}
"""

rule add_year_metadata:
input:
metadata = "data/metadata.tsv",
params:
strain_id = config["strain_id_field"],
output:
node_data = "results/year.json"
run:
from augur.io import read_metadata
import json
m = read_metadata(input.metadata, id_columns=[params.strain_id])
nodes = {name: {'year': date.split('-')[0]} for name,date in zip(m.index, m['date']) if date and not date.startswith('X')}
with open(output.node_data, 'w') as fh:
json.dump({"nodes": nodes}, fh)
3 changes: 2 additions & 1 deletion phylogenetic/rules/export.smk
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ rule export:
branch_lengths = "results/branch_lengths.json",
nt_muts = "results/nt_muts.json",
aa_muts = "results/aa_muts.json",
year = "results/year.json",
colors = config["files"]["colors"],
auspice_config = config["files"]["auspice_config"],
description = config["files"]["description"]
Expand All @@ -30,7 +31,7 @@ rule export:
--tree {input.tree} \
--metadata {input.metadata} \
--metadata-id-columns {params.strain_id} \
--node-data {input.branch_lengths} {input.nt_muts} {input.aa_muts} \
--node-data {input.branch_lengths} {input.nt_muts} {input.aa_muts} {input.year} \
--colors {input.colors} \
--auspice-config {input.auspice_config} \
--include-root-sequence-inline \
Expand Down

0 comments on commit 0162bf4

Please sign in to comment.