From be02fa9d9c1bf10c86f1b376660c3a087abde7db Mon Sep 17 00:00:00 2001 From: Till Hartmann Date: Tue, 30 Apr 2024 13:36:35 +0200 Subject: [PATCH] fix: move config access in gcnv/contig_ploidy wrapper to params --- .../workflows/sv_calling_targeted/__init__.py | 16 ++++++++++++++++ .../workflows/sv_calling_wgs/__init__.py | 17 +++++++++++++++++ .../wrappers/gcnv/contig_ploidy/wrapper.py | 4 +--- .../test_workflows_sv_calling_targeted.py | 4 ++-- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/snappy_pipeline/workflows/sv_calling_targeted/__init__.py b/snappy_pipeline/workflows/sv_calling_targeted/__init__.py index 3cb8d4675..81cbf3a5e 100644 --- a/snappy_pipeline/workflows/sv_calling_targeted/__init__.py +++ b/snappy_pipeline/workflows/sv_calling_targeted/__init__.py @@ -103,6 +103,22 @@ def __init__(self, parent): # Take shortcut from library to library kit. self.ngs_library_to_kit = self.parent.ngs_library_to_kit + def get_params(self, action: str): + param_fn = super().get_params(action) + + def _get_params(*args, **kwargs): + params = param_fn(*args, **kwargs) + if action == "contig_ploidy": + par_intervals = ( + self.config.get("helper_gcnv_model_targeted", {}) + .get("gcnv", {}) + .get("path_par_intervals", "") + ) + params.update({"par_intervals": par_intervals}) + return params + + return _get_params + class SvCallingTargetedWorkflow(BaseStep): """Perform germline targeted sequencing CNV calling""" diff --git a/snappy_pipeline/workflows/sv_calling_wgs/__init__.py b/snappy_pipeline/workflows/sv_calling_wgs/__init__.py index 5e8569d1f..d18e2311f 100644 --- a/snappy_pipeline/workflows/sv_calling_wgs/__init__.py +++ b/snappy_pipeline/workflows/sv_calling_wgs/__init__.py @@ -127,6 +127,23 @@ def _build_ngs_library_to_kit(self): if donor.dna_ngs_library: yield donor.dna_ngs_library.name, "wgs" + def get_params(self, action: str): + param_fn = super().get_params(action) + + def _get_params(*args, **kwargs): + params = param_fn(*args, **kwargs) + if action == "contig_ploidy": + par_intervals = ( + self.config.get("helper_gcnv_model_wgs", {}) + .get("gcnv", {}) + .get("path_par_intervals", "") + ) + params.update({"par_intervals": par_intervals}) + params.update({"par_intervals": par_intervals}) + return params + + return _get_params + def escape_dots_dashes(s: str) -> str: """Escape dots and dashes with double-underscore constructs.""" diff --git a/snappy_wrappers/wrappers/gcnv/contig_ploidy/wrapper.py b/snappy_wrappers/wrappers/gcnv/contig_ploidy/wrapper.py index 6974d42ce..4c100feea 100644 --- a/snappy_wrappers/wrappers/gcnv/contig_ploidy/wrapper.py +++ b/snappy_wrappers/wrappers/gcnv/contig_ploidy/wrapper.py @@ -26,9 +26,7 @@ paths_tsv = " ".join(snakemake.input.tsv) # Add interval block list for PAR regions if configured. -par_intervals = snakemake.config["step_config"]["helper_gcnv_model_targeted"]["gcnv"].get( - "path_par_intervals" -) +par_intervals = snakemake.params.get("par_intervals", "") if par_intervals: par_args = f"-XL {par_intervals}" else: diff --git a/tests/snappy_pipeline/workflows/test_workflows_sv_calling_targeted.py b/tests/snappy_pipeline/workflows/test_workflows_sv_calling_targeted.py index 20f774f31..257818cdf 100644 --- a/tests/snappy_pipeline/workflows/test_workflows_sv_calling_targeted.py +++ b/tests/snappy_pipeline/workflows/test_workflows_sv_calling_targeted.py @@ -667,11 +667,11 @@ def test_gcnv_get_params_ploidy_model(sv_calling_targeted_workflow): wildcards = Wildcards(fromdict={"library_kit": "Agilent_SureSelect_Human_All_Exon_V6"}) wildcards_fake = Wildcards(fromdict={"library_kit": "__not_a_library_kit__"}) # Test large cohort - model defined in config - expected = {"model": "/path/to/ploidy-model"} + expected = {"model": "/path/to/ploidy-model", "par_intervals": ""} actual = sv_calling_targeted_workflow.get_params("gcnv", "contig_ploidy")(wildcards) assert actual == expected # Test large cohort - model not defined in config - expected = {"model": "__no_ploidy_model_for_library_in_config__"} + expected = {"model": "__no_ploidy_model_for_library_in_config__", "par_intervals": ""} actual = sv_calling_targeted_workflow.get_params("gcnv", "contig_ploidy")(wildcards_fake) assert actual == expected