Skip to content

Commit

Permalink
fixup! Use ISO duration format for clade recency
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlin committed Oct 1, 2024
1 parent 024ae94 commit 1ae7447
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion defaults/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ ancestral:
inference: "joint"

colors:
# Months back to color clades, if "all" then all clades are colored
# Amount of time back to color clades, if "all" then all clades are colored
# Can be specified per build in builds.yaml
default:
clade_recency: "all"
Expand Down
7 changes: 4 additions & 3 deletions docs/src/reference/workflow-config-file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -965,9 +965,10 @@ Each named traits configuration (``default`` or build-named) supports the follow
clade_recency
~~~~~~~~~~~~~

- type: integer
- description: if integer value is provided, restrict to clades found in tree within X months of present
- default: ``all``
- type: string
- format: `ISO 8601 <https://en.wikipedia.org/wiki/ISO_8601#Durations>`__ duration with optional ``P`` prefix (e.g. ``2M``, ``18M``, ``1Y6M``)
- description: restrict to clades found in tree within this duration from present
- default: ``all`` (no restriction)

traits
------
Expand Down
11 changes: 10 additions & 1 deletion workflow/snakemake_rules/common.smk
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Small, shared functions used to generate inputs and parameters.
"""
import datetime
import isodate
from itertools import product
from shlex import (
quote as shquote, # shquote() is used in this file and also other workflow files
Expand Down Expand Up @@ -181,9 +182,17 @@ def _get_clade_recency_for_wildcards(wildcards):

def _get_clade_recency_argument(wildcards):
clade_recency_setting = _get_clade_recency_for_wildcards(wildcards)

def is_duration(s):
try:
isodate.parse_duration(s)
return True
except:
return False

if clade_recency_setting == "all":
return ""
elif isinstance(clade_recency_setting, int):
elif is_duration(clade_recency_setting):
return "--clade-recency " + shquote(str(clade_recency_setting))
else:
return ""
Expand Down

0 comments on commit 1ae7447

Please sign in to comment.