From 875294291bdc3d70391c31dcb3308501e4bcb2b5 Mon Sep 17 00:00:00 2001 From: Victor Lin Date: Wed, 12 Aug 2026 11:39:48 -0700 Subject: [PATCH] Don't validate schema in helper functions This change is primarily intended for pathogen workflows that use the helper functions prior to running augur subsample, commonly during Snakemake's initialization step. Schema is still validated at run time. We are shifting to a pattern where pathogen workflows define and validate their own schema at workflow start, so the validation in these helper functions is unnecessary duplicate work. --- CHANGES.md | 2 ++ augur/subsample.py | 24 ++++++++++-------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6f40e6acc..aee4c6a10 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,9 +4,11 @@ ### Development +* subsample: Refactored helper functions to only validate config during run time. [#2039] @victorlin * Added a subsample config schema for workflows that use unaligned sequences. [#2038] @victorlin [#2038]: https://github.com/nextstrain/augur/pull/2038 +[#2039]: https://github.com/nextstrain/augur/pull/2039 ## 34.1.2 (5 August 2026) diff --git a/augur/subsample.py b/augur/subsample.py index f1d32eb4a..ef4a7dcd8 100644 --- a/augur/subsample.py +++ b/augur/subsample.py @@ -191,10 +191,14 @@ def run(args: argparse.Namespace) -> None: worth it if a proper input reuse approach such as database/parquet file support is adopted: """ - - # Load schema, parse and validate config. schema_validator = load_json_schema("schema-subsample-config.json") - config = _parse_config(args.config, args.config_section, schema_validator) + config = _parse_config(args.config, args.config_section) + + try: + validate_json(config, schema_validator, args.config) + except ValidateError as e: + raise AugurError(e) + sample_types = _get_sample_types(config) if _includes_proximal_sample(config) and not args.sequences: @@ -324,9 +328,8 @@ def get_referenced_files( set Resolved filepaths """ - # Load schema, parse and validate config. schema_validator = load_json_schema("schema-subsample-config.json") - config = _parse_config(config_file, config_section, schema_validator) + config = _parse_config(config_file, config_section) # Resolve filepaths. search_path_objs = _get_search_paths(config_file, search_paths) @@ -357,11 +360,10 @@ def requires_aligned_sequences( bool Does augur subsample require aligned sequences? """ - schema_validator = load_json_schema("schema-subsample-config.json") - config = _parse_config(config_file, config_section, schema_validator) + config = _parse_config(config_file, config_section) return _includes_proximal_sample(config) -def _parse_config(filename: str, config_section: Optional[List[str]], schema) -> Dict[str, Any]: +def _parse_config(filename: str, config_section: Optional[List[str]] = None) -> Dict[str, Any]: # Create a custom YAML loader to treat timestamps as strings. class CustomLoader(yaml.SafeLoader): pass @@ -387,12 +389,6 @@ def string_constructor(loader, node): config = traversed_section - # Validate against schema. - try: - validate_json(config, schema, filename) - except ValidateError as e: - raise AugurError(e) - return config def _get_search_paths(