From ba3ea514fa6891b884b9eb3b62f53ae533be4b1a Mon Sep 17 00:00:00 2001 From: Eric Blanc Date: Tue, 17 Dec 2024 18:18:59 +0100 Subject: [PATCH] refactor: proper naming of wrapper scripts for logs --- .../__init__.py | 18 ++++++++++------- ...orkflows_somatic_purity_ploidy_estimate.py | 20 +++++++++---------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/snappy_pipeline/workflows/somatic_purity_ploidy_estimate/__init__.py b/snappy_pipeline/workflows/somatic_purity_ploidy_estimate/__init__.py index ab40bc27..25b7ba06 100644 --- a/snappy_pipeline/workflows/somatic_purity_ploidy_estimate/__init__.py +++ b/snappy_pipeline/workflows/somatic_purity_ploidy_estimate/__init__.py @@ -170,14 +170,10 @@ def get_result_files(self) -> list[str]: tpl + "purity.txt", tpl + "segments.txt", ] - for action in ("prepare_hts", "run", "guess_sex"): + for action in ("prepare_hts", "run"): tpl = "work/{mapper}.ascat.{library_name}/log/{mapper}.ascat.{library_name}." - for ext in ("conda_info.txt", "conda_list.txt", "log", "wrapper"): + for ext in ("conda_info.txt", "conda_list.txt", "log", "R"): results.append(tpl + f"{action}.{ext}") - tpl = "work/{mapper}.ascat.{library_name}/log/{mapper}.ascat.{library_name}.chr" - for chrom_name in AscatStepPart.chromosome_names: - for ext in ("conda_info.txt", "conda_list.txt", "log", "wrapper"): - results.append(tpl + f"{chrom_name}.build_baf.{ext}") return results @dictify @@ -188,11 +184,19 @@ def get_log_file(self, action: str): tpl = "work/{mapper}.ascat.{library_name}/log/{mapper}.ascat.{library_name}.chr{chrom_name}." else: tpl = "work/{mapper}.ascat.{library_name}/log/{mapper}.ascat.{library_name}." - for ext in ("conda_info.txt", "conda_list.txt", "log", "wrapper"): + for ext in ("conda_info.txt", "conda_list.txt", "log"): k = ext.replace(".txt", "") v = tpl + action + "." + ext yield k, v yield k + "_md5", v + ".md5" + if action in ("guess_sex", "build_baf"): + ext = "sh" + else: + ext = "R" + k = "script" + v = tpl + action + "." + ext + yield k, v + yield k + "_md5", v + ".md5" def get_args(self, action: str): # Validate action diff --git a/tests/snappy_pipeline/workflows/test_workflows_somatic_purity_ploidy_estimate.py b/tests/snappy_pipeline/workflows/test_workflows_somatic_purity_ploidy_estimate.py index 40c92130..ede1f3d0 100644 --- a/tests/snappy_pipeline/workflows/test_workflows_somatic_purity_ploidy_estimate.py +++ b/tests/snappy_pipeline/workflows/test_workflows_somatic_purity_ploidy_estimate.py @@ -242,13 +242,16 @@ def test_ascat_step_part_get_log_file(somatic_purity_ploidy_estimate_workflow): for action in actions: err_msg = f"Assert error for action '{action}'." expected = get_expected_log_files_dict(base_out=base_out + action) - expected["wrapper"] = base_out + action + ".wrapper" - expected["wrapper_md5"] = expected["wrapper"] + ".md5" + if action == "guess_sex": + expected["script"] = base_out + action + ".sh" + else: + expected["script"] = base_out + action + ".R" + expected["script_md5"] = expected["script"] + ".md5" actual = somatic_purity_ploidy_estimate_workflow.get_log_file("ascat", action) assert actual == expected, err_msg expected = get_expected_log_files_dict(base_out=base_out + "chr{chrom_name}.build_baf") - expected["wrapper"] = base_out + "chr{chrom_name}.build_baf.wrapper" - expected["wrapper_md5"] = expected["wrapper"] + ".md5" + expected["script"] = base_out + "chr{chrom_name}.build_baf.sh" + expected["script_md5"] = expected["script"] + ".md5" actual = somatic_purity_ploidy_estimate_workflow.get_log_file("ascat", "build_baf") assert actual == expected @@ -324,10 +327,9 @@ def test_somatic_purity_ploidy_estimate_workflow(somatic_purity_ploidy_estimate_ assert actual == expected # Check result file construction for ascat - chromosome_names = list(map(str, range(1, 23))) + ["X"] out_exts = ("goodness_of_fit", "na", "nb", "purity", "ploidy", "segments") - actions = ("guess_sex", "prepare_hts", "run") - log_exts = ("conda_info.txt", "conda_list.txt", "log", "wrapper") + actions = ("prepare_hts", "run") + log_exts = ("conda_info.txt", "conda_list.txt", "log", "R") mapper = "bwa" expected = [] for lib in ((1, 1), (2, 1), (2,2)): @@ -339,10 +341,6 @@ def test_somatic_purity_ploidy_estimate_workflow(somatic_purity_ploidy_estimate_ for log_ext in log_exts: expected.append(f"output/{tpl}/log/{tpl}.{action}.{log_ext}") expected.append(f"output/{tpl}/log/{tpl}.{action}.{log_ext}.md5") - for chrom_name in chromosome_names: - for log_ext in log_exts: - expected.append(f"output/{tpl}/log/{tpl}.chr{chrom_name}.build_baf.{log_ext}") - expected.append(f"output/{tpl}/log/{tpl}.chr{chrom_name}.build_baf.{log_ext}.md5") expected = set(expected) actual = set(somatic_purity_ploidy_estimate_workflow.get_result_files())