diff --git a/defaults/parameters.yaml b/defaults/parameters.yaml index 282393346..057465f81 100644 --- a/defaults/parameters.yaml +++ b/defaults/parameters.yaml @@ -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: diff --git a/docs/src/reference/workflow-config-file.rst b/docs/src/reference/workflow-config-file.rst index 23f9ed789..1dee0d683 100644 --- a/docs/src/reference/workflow-config-file.rst +++ b/docs/src/reference/workflow-config-file.rst @@ -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 ------ diff --git a/nextstrain_profiles/nextstrain-gisaid/builds.yaml b/nextstrain_profiles/nextstrain-gisaid/builds.yaml index f13692a33..f4b9cec65 100644 --- a/nextstrain_profiles/nextstrain-gisaid/builds.yaml +++ b/nextstrain_profiles/nextstrain-gisaid/builds.yaml @@ -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: diff --git a/scripts/assign-colors.py b/scripts/assign-colors.py index fe822c7b8..ef5e95c06 100644 --- a/scripts/assign-colors.py +++ b/scripts/assign-colors.py @@ -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() @@ -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 diff --git a/workflow/snakemake_rules/common.smk b/workflow/snakemake_rules/common.smk index 0c2713950..ba550598a 100644 --- a/workflow/snakemake_rules/common.smk +++ b/workflow/snakemake_rules/common.smk @@ -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"] diff --git a/workflow/snakemake_rules/main_workflow.smk b/workflow/snakemake_rules/main_workflow.smk index 4e140108b..54b543b90 100644 --- a/workflow/snakemake_rules/main_workflow.smk +++ b/workflow/snakemake_rules/main_workflow.smk @@ -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: