From 76e068e042d3944fb79391845d75e59cfdbd334b Mon Sep 17 00:00:00 2001 From: peterpru Date: Fri, 11 Oct 2024 11:19:17 +0200 Subject: [PATCH 1/4] add to metric conditions and test --- cg/constants/nf_analysis.py | 2 ++ ...e_case_enough_reads_metrics_deliverables.yaml | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/cg/constants/nf_analysis.py b/cg/constants/nf_analysis.py index 09e5111b6b5..b0bd0999512 100644 --- a/cg/constants/nf_analysis.py +++ b/cg/constants/nf_analysis.py @@ -21,6 +21,8 @@ class NfTowerStatus(StrEnum): "MEDIAN_TARGET_COVERAGE": {"norm": "gt", "threshold": 25}, "PCT_TARGET_BASES_10X": {"norm": "gt", "threshold": 0.95}, "PCT_EXC_ADAPTER": {"norm": "lt", "threshold": 0.0005}, + "AT_DROPOUT": {"norm": "lt", "threshold": 5.5}, + "GC_DROPOUT": {"norm": "lt", "threshold": 8.4}, "predicted_sex_sex_check": {"norm": "eq", "threshold": None}, "gender": {"norm": "eq", "threshold": None}, } diff --git a/tests/fixtures/analysis/raredisease/raredisease_case_enough_reads_metrics_deliverables.yaml b/tests/fixtures/analysis/raredisease/raredisease_case_enough_reads_metrics_deliverables.yaml index 69359825152..0884422a30b 100644 --- a/tests/fixtures/analysis/raredisease/raredisease_case_enough_reads_metrics_deliverables.yaml +++ b/tests/fixtures/analysis/raredisease/raredisease_case_enough_reads_metrics_deliverables.yaml @@ -479,14 +479,18 @@ metrics: name: PCT_TARGET_BASES_100000X step: multiqc value: 0.0 -- condition: null +- condition: + norm: lt + threshold: 5.5 header: null id: ADM1 input: multiqc_data.json name: AT_DROPOUT step: multiqc value: 0.061814 -- condition: null +- condition: + norm: lt + threshold: 8.4 header: null id: ADM1 input: multiqc_data.json @@ -1599,14 +1603,18 @@ metrics: name: PCT_TARGET_BASES_100000X step: multiqc value: 0.0 -- condition: null +- condition: + norm: lt + threshold: 5.5 header: null id: ADM2 input: multiqc_data.json name: AT_DROPOUT step: multiqc value: 0.061814 -- condition: null +- condition: + norm: lt + threshold: 8.4 header: null id: ADM2 input: multiqc_data.json From fd104f29b68392828c6b4fdb320c2002cddfddbc Mon Sep 17 00:00:00 2001 From: peterpru Date: Thu, 16 Jan 2025 14:17:45 +0100 Subject: [PATCH 2/4] add conditional cutoff --- cg/constants/nf_analysis.py | 4 ++-- cg/meta/workflow/raredisease.py | 11 +++++++++++ ...isease_case_enough_reads_metrics_deliverables.yaml | 8 ++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/cg/constants/nf_analysis.py b/cg/constants/nf_analysis.py index 615859f8ad8..8378e415ce1 100644 --- a/cg/constants/nf_analysis.py +++ b/cg/constants/nf_analysis.py @@ -23,8 +23,8 @@ class NfTowerStatus(StrEnum): "MEDIAN_TARGET_COVERAGE": {"norm": "gt", "threshold": 25}, "PCT_TARGET_BASES_10X": {"norm": "gt", "threshold": 0.95}, "PCT_EXC_ADAPTER": {"norm": "lt", "threshold": 0.0005}, - "AT_DROPOUT": {"norm": "lt", "threshold": 5.5}, - "GC_DROPOUT": {"norm": "lt", "threshold": 8.4}, + "AT_DROPOUT": {"norm": "lt", "threshold": 10}, + "GC_DROPOUT": {"norm": "lt", "threshold": 10}, RAREDISEASE_PREDICTED_SEX_METRIC: {"norm": "eq", "threshold": None}, "gender": {"norm": "eq", "threshold": None}, } diff --git a/cg/meta/workflow/raredisease.py b/cg/meta/workflow/raredisease.py index 694c78a5747..02093f85bbe 100644 --- a/cg/meta/workflow/raredisease.py +++ b/cg/meta/workflow/raredisease.py @@ -23,6 +23,7 @@ RAREDISEASE_PARENT_PEDDY_METRIC_CONDITION, ) from cg.constants.scout import RAREDISEASE_CASE_TAGS, ScoutExportFileName +from cg.constants.sequencing import SeqLibraryPrepCategory from cg.constants.subject import PlinkPhenotypeStatus, PlinkSex from cg.constants.tb import AnalysisType from cg.meta.workflow.nf_analysis import NfAnalysisAPI @@ -172,6 +173,7 @@ def get_workflow_metrics(self, sample_id: str) -> dict: if "-" not in sample_id: metric_conditions: dict[str, dict[str, Any]] = RAREDISEASE_METRIC_CONDITIONS.copy() self.set_order_sex_for_sample(sample, metric_conditions) + self.set_dropout_cutoff_by_analysis_type(sample, metric_conditions) else: metric_conditions = RAREDISEASE_PARENT_PEDDY_METRIC_CONDITION.copy() return metric_conditions @@ -230,6 +232,15 @@ def set_order_sex_for_sample(sample: Sample, metric_conditions: dict) -> None: metric_conditions["predicted_sex_sex_check"]["threshold"] = sample.sex metric_conditions["gender"]["threshold"] = sample.sex + @staticmethod + def set_dropout_cutoff_by_analysis_type(sample: Sample, metric_conditions: dict) -> None: + if ( + sample.application_version.application.analysis_type + == SeqLibraryPrepCategory.WHOLE_GENOME_SEQUENCING + ): + metric_conditions["AT_DROPOUT"]["threshold"] = 5 + metric_conditions["GC_DROPOUT"]["threshold"] = 5 + def get_sample_coverage_file_path(self, bundle_name: str, sample_id: str) -> str | None: """Return the Raredisease d4 coverage file path.""" coverage_file_tags: list[str] = RAREDISEASE_COVERAGE_FILE_TAGS + [sample_id] diff --git a/tests/fixtures/analysis/raredisease/raredisease_case_enough_reads_metrics_deliverables.yaml b/tests/fixtures/analysis/raredisease/raredisease_case_enough_reads_metrics_deliverables.yaml index 0884422a30b..e3f8f4035e7 100644 --- a/tests/fixtures/analysis/raredisease/raredisease_case_enough_reads_metrics_deliverables.yaml +++ b/tests/fixtures/analysis/raredisease/raredisease_case_enough_reads_metrics_deliverables.yaml @@ -481,7 +481,7 @@ metrics: value: 0.0 - condition: norm: lt - threshold: 5.5 + threshold: 5.0 header: null id: ADM1 input: multiqc_data.json @@ -490,7 +490,7 @@ metrics: value: 0.061814 - condition: norm: lt - threshold: 8.4 + threshold: 5.0 header: null id: ADM1 input: multiqc_data.json @@ -1605,7 +1605,7 @@ metrics: value: 0.0 - condition: norm: lt - threshold: 5.5 + threshold: 5.0 header: null id: ADM2 input: multiqc_data.json @@ -1614,7 +1614,7 @@ metrics: value: 0.061814 - condition: norm: lt - threshold: 8.4 + threshold: 5.0 header: null id: ADM2 input: multiqc_data.json From 738d2389de4b8925ff25990573108caf13b4029c Mon Sep 17 00:00:00 2001 From: peterpru Date: Mon, 3 Feb 2025 14:57:18 +0100 Subject: [PATCH 3/4] make metric conditions by analysis type --- cg/constants/nf_analysis.py | 14 +++++++++++++- cg/meta/workflow/raredisease.py | 26 ++++++++++++++------------ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/cg/constants/nf_analysis.py b/cg/constants/nf_analysis.py index 8378e415ce1..4516943bd1e 100644 --- a/cg/constants/nf_analysis.py +++ b/cg/constants/nf_analysis.py @@ -17,7 +17,7 @@ class NfTowerStatus(StrEnum): RAREDISEASE_PREDICTED_SEX_METRIC = "predicted_sex_sex_check" -RAREDISEASE_METRIC_CONDITIONS: dict[str, dict[str, Any]] = { +RAREDISEASE_METRIC_CONDITIONS_WES: dict[str, dict[str, Any]] = { "percent_duplicates": {"norm": "lt", "threshold": 20}, "PCT_PF_UQ_READS_ALIGNED": {"norm": "gt", "threshold": 0.95}, "MEDIAN_TARGET_COVERAGE": {"norm": "gt", "threshold": 25}, @@ -29,6 +29,18 @@ class NfTowerStatus(StrEnum): "gender": {"norm": "eq", "threshold": None}, } +RAREDISEASE_METRIC_CONDITIONS_WGS: dict[str, dict[str, Any]] = { + "percent_duplicates": {"norm": "lt", "threshold": 20}, + "PCT_PF_UQ_READS_ALIGNED": {"norm": "gt", "threshold": 0.95}, + "MEDIAN_TARGET_COVERAGE": {"norm": "gt", "threshold": 25}, + "PCT_TARGET_BASES_10X": {"norm": "gt", "threshold": 0.95}, + "PCT_EXC_ADAPTER": {"norm": "lt", "threshold": 0.0005}, + "AT_DROPOUT": {"norm": "lt", "threshold": 5}, + "GC_DROPOUT": {"norm": "lt", "threshold": 5}, + RAREDISEASE_PREDICTED_SEX_METRIC: {"norm": "eq", "threshold": None}, + "gender": {"norm": "eq", "threshold": None}, +} + RAREDISEASE_PARENT_PEDDY_METRIC_CONDITION: dict[str, dict[str, Any]] = { "parent_error_ped_check": {"norm": "eq", "threshold": "False"}, } diff --git a/cg/meta/workflow/raredisease.py b/cg/meta/workflow/raredisease.py index 02093f85bbe..9d5ad0f7079 100644 --- a/cg/meta/workflow/raredisease.py +++ b/cg/meta/workflow/raredisease.py @@ -19,8 +19,9 @@ RAREDISEASE_COVERAGE_FILE_TAGS, RAREDISEASE_COVERAGE_INTERVAL_TYPE, RAREDISEASE_COVERAGE_THRESHOLD, - RAREDISEASE_METRIC_CONDITIONS, RAREDISEASE_PARENT_PEDDY_METRIC_CONDITION, + RAREDISEASE_METRIC_CONDITIONS_WGS, + RAREDISEASE_METRIC_CONDITIONS_WES, ) from cg.constants.scout import RAREDISEASE_CASE_TAGS, ScoutExportFileName from cg.constants.sequencing import SeqLibraryPrepCategory @@ -171,13 +172,23 @@ def get_workflow_metrics(self, sample_id: str) -> dict: """Return Raredisease workflow metric conditions for a sample.""" sample: Sample = self.status_db.get_sample_by_internal_id(internal_id=sample_id) if "-" not in sample_id: - metric_conditions: dict[str, dict[str, Any]] = RAREDISEASE_METRIC_CONDITIONS.copy() + metric_conditions: dict[str, dict[str, Any]] = ( + self.get_metric_conditions_by_analysis_type(sample_id=sample.internal_id) + ) self.set_order_sex_for_sample(sample, metric_conditions) - self.set_dropout_cutoff_by_analysis_type(sample, metric_conditions) else: metric_conditions = RAREDISEASE_PARENT_PEDDY_METRIC_CONDITION.copy() return metric_conditions + def get_metric_conditions_by_analysis_type(self, sample_id: str) -> dict: + sample: Sample = self.status_db.get_sample_by_internal_id(internal_id=sample_id) + if ( + sample.application_version.application.analysis_type + == SeqLibraryPrepCategory.WHOLE_GENOME_SEQUENCING + ): + return RAREDISEASE_METRIC_CONDITIONS_WGS.copy() + return RAREDISEASE_METRIC_CONDITIONS_WES.copy() + def _get_sample_pair_patterns(self, case_id: str) -> list[str]: """Return sample-pair patterns for searching in MultiQC.""" sample_ids: list[str] = list(self.status_db.get_sample_ids_by_case_id(case_id=case_id)) @@ -232,15 +243,6 @@ def set_order_sex_for_sample(sample: Sample, metric_conditions: dict) -> None: metric_conditions["predicted_sex_sex_check"]["threshold"] = sample.sex metric_conditions["gender"]["threshold"] = sample.sex - @staticmethod - def set_dropout_cutoff_by_analysis_type(sample: Sample, metric_conditions: dict) -> None: - if ( - sample.application_version.application.analysis_type - == SeqLibraryPrepCategory.WHOLE_GENOME_SEQUENCING - ): - metric_conditions["AT_DROPOUT"]["threshold"] = 5 - metric_conditions["GC_DROPOUT"]["threshold"] = 5 - def get_sample_coverage_file_path(self, bundle_name: str, sample_id: str) -> str | None: """Return the Raredisease d4 coverage file path.""" coverage_file_tags: list[str] = RAREDISEASE_COVERAGE_FILE_TAGS + [sample_id] From a6157825fb6b81844cc2deceffff87df8c32bdcb Mon Sep 17 00:00:00 2001 From: peterpru Date: Mon, 3 Feb 2025 15:01:42 +0100 Subject: [PATCH 4/4] rename to prep category --- cg/meta/workflow/raredisease.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cg/meta/workflow/raredisease.py b/cg/meta/workflow/raredisease.py index 9d5ad0f7079..40afb95ba0a 100644 --- a/cg/meta/workflow/raredisease.py +++ b/cg/meta/workflow/raredisease.py @@ -173,14 +173,14 @@ def get_workflow_metrics(self, sample_id: str) -> dict: sample: Sample = self.status_db.get_sample_by_internal_id(internal_id=sample_id) if "-" not in sample_id: metric_conditions: dict[str, dict[str, Any]] = ( - self.get_metric_conditions_by_analysis_type(sample_id=sample.internal_id) + self.get_metric_conditions_by_prep_category(sample_id=sample.internal_id) ) self.set_order_sex_for_sample(sample, metric_conditions) else: metric_conditions = RAREDISEASE_PARENT_PEDDY_METRIC_CONDITION.copy() return metric_conditions - def get_metric_conditions_by_analysis_type(self, sample_id: str) -> dict: + def get_metric_conditions_by_prep_category(self, sample_id: str) -> dict: sample: Sample = self.status_db.get_sample_by_internal_id(internal_id=sample_id) if ( sample.application_version.application.analysis_type