Skip to content

Commit

Permalink
Merge pull request #12 from nextstrain/james/year
Browse files Browse the repository at this point in the history
Add sampling year coloring
  • Loading branch information
jameshadfield authored Aug 22, 2024
2 parents 67b7941 + 0534d0d commit 1df5993
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
8 changes: 7 additions & 1 deletion 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 Expand Up @@ -60,6 +65,7 @@
"author",
"strain",
"division",
"location"
"location",
"date"
]
}
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 1df5993

Please sign in to comment.