Skip to content

Commit

Permalink
Allow build-specific clade_recency
Browse files Browse the repository at this point in the history
Set up a build-specific override for colors: clade_recency parameter. Make the default to be empty string "" and have this keep all clades colored. Override for the Nextstrain GISAID profile to specify clade_recency of
- `1` month for "1m" build
- `2` months for "2m" build
- `6` months for "6m" build
- `""` (all months) for "all-time" build
  • Loading branch information
trvrb committed Sep 25, 2024
1 parent 593e9ca commit 00e90e0
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 5 deletions.
4 changes: 2 additions & 2 deletions defaults/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ refine:
ancestral:
inference: "joint"

# Gray out clades that are older than 18 months when constructing a color ramp
colors:
clade_recency: 18
# Months back to color clades, if "" then all clades are colored
clade_recency: ""

# Frequencies settings
frequencies:
Expand Down
27 changes: 27 additions & 0 deletions docs/src/reference/workflow-config-file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,33 @@ no_timetree
- description: Do not produce a time tree.
- default: ``false``

colors
------

- type: object
- description: Parameters for assigning colors in ``scripts/assign-colors.py``
- examples:

.. code:: yaml
colors:
default:
clade_recency: ""
global-6m:
# Override clade recency colors for "global-6m" build
clade_recency: 6
Each named traits configuration (``default`` or build-named) supports the following attributes:

.. contents::
:local:

clade_recency
~~~~~~~~~~~~~

- type: integer
- description: if provided, restrict to clades found in tree within X months of present
- default: ````

traits
------
Expand Down
62 changes: 62 additions & 0 deletions nextstrain_profiles/nextstrain-gisaid/builds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,68 @@ subsampling:
max_sequences: 75
exclude: "--exclude-where 'region!=Oceania'"

# if different traits should be reconstructed for some builds, specify here
# otherwise the default trait config in defaults/parameters.yaml will used
colors:
reference:
clade_recency: ""
global_1m:
clade_recency: 1
global_2m:
clade_recency: 2
global_6m:
clade_recency: 6
global_all-time:
clade_recency: ""
africa_1m:
clade_recency: 1
africa_2m:
clade_recency: 2
africa_6m:
clade_recency: 6
africa_all-time:
clade_recency: ""
asia_1m:
clade_recency: 1
asia_2m:
clade_recency: 2
asia_6m:
clade_recency: 6
asia_all-time:
clade_recency: ""
europe_1m:
clade_recency: 1
europe_2m:
clade_recency: 2
europe_6m:
clade_recency: 6
europe_all-time:
clade_recency: ""
north-america_1m:
clade_recency: 1
north-america_2m:
clade_recency: 2
north-america_6m:
clade_recency: 6
north-america_all-time:
clade_recency: ""
oceania_1m:
clade_recency: 1
oceania_2m:
clade_recency: 2
oceania_6m:
clade_recency: 6
oceania_all-time:
clade_recency: ""
south-america_1m:
clade_recency: 1
south-america_2m:
clade_recency: 2
south-america_6m:
clade_recency: 6
south-america_all-time:
clade_recency: ""

# if different traits should be reconstructed for some builds, specify here
# otherwise the default trait config in defaults/parameters.yaml will used
traits:
Expand Down
4 changes: 2 additions & 2 deletions scripts/assign-colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def date_within_last_n_months(date_str, cutoff_date):
parser.add_argument('--color-schemes', type=str, required=True, help="input color schemes file")
parser.add_argument('--metadata', type=str, help="if provided, restrict colors to only those found in metadata")
parser.add_argument('--clade-node-data', type=str, help="if provided, restrict to only those clades found in tree")
parser.add_argument('--clade-recency', type=int, help="if provided, restrict to clades found in tree within X months of present")
parser.add_argument('--clade-recency', type=int, nargs='?', const=None, help="if provided, restrict to clades found in tree within X months of present")
parser.add_argument('--output', type=str, required=True, help="output colors tsv")
args = parser.parse_args()

Expand Down Expand Up @@ -61,7 +61,7 @@ def date_within_last_n_months(date_str, cutoff_date):
import json
clades = json.load(fh)['nodes']

if args.clade_recency and args.metadata:
if args.clade_recency is not None and args.metadata:
# Calculate the cutoff date based on clade_recency (number of months ago from today)
cutoff_date = datetime.today() - timedelta(days=args.clade_recency * 30) # approximate months as 30 days

Expand Down
6 changes: 6 additions & 0 deletions workflow/snakemake_rules/common.smk
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ def _get_metadata_by_wildcards(wildcards):
"""
return _get_metadata_by_build_name(wildcards.build_name)

def _get_clade_recency_for_wildcards(wildcards):
if wildcards.build_name in config["colors"] and 'clade_recency' in config["colors"][wildcards.build_name]:
return config["colors"][wildcards.build_name]["clade_recency"]
else:
return config["colors"]["default"]["clade_recency"]

def _get_trait_columns_by_wildcards(wildcards):
if wildcards.build_name in config["traits"]:
return config["traits"][wildcards.build_name]["columns"]
Expand Down
2 changes: 1 addition & 1 deletion workflow/snakemake_rules/main_workflow.smk
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ rule colors:
metadata="results/{build_name}/metadata_adjusted.tsv.xz",
clades = rules.clades.output.clade_data
params:
clade_recency = config["colors"]["clade_recency"]
clade_recency = _get_clade_recency_for_wildcards
output:
colors = "results/{build_name}/colors.tsv"
log:
Expand Down

0 comments on commit 00e90e0

Please sign in to comment.