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

Add sampling year coloring #12

Merged
merged 2 commits into from
Aug 22, 2024
Merged
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: 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} \
Copy link
Contributor

Choose a reason for hiding this comment

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

not asking for a change, just curious

Instead of making another node-data JSON, why not just add a year column to the metadata.tsv that can be used directly as a coloring?

Copy link
Member Author

Choose a reason for hiding this comment

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

I found the approach here cleaner to implement, although if other rules used the data I'd have probably gone for modifying the TSV. It should also be trivial to copy & paste into other workflows which would benefit from this. Of course, once Auspice has a proper temporal scale this'll all be removed anyways.

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps analogous to avian-flu where we currently add in a column (H5 LABEL) to the TSV but want to switch away from this to a node-data JSON

--colors {input.colors} \
--auspice-config {input.auspice_config} \
--include-root-sequence-inline \
Expand Down