From 93574de7a8b9e742104e64f3711cec65ddbce4db Mon Sep 17 00:00:00 2001 From: beatrizsavinhas Date: Tue, 3 Sep 2024 14:48:04 +0200 Subject: [PATCH] Add reads q30 check and tests. --- .../post_processing_service.py | 2 +- cg/store/crud/update.py | 11 +++++++-- tests/store/crud/update/test_update.py | 23 +++++++++++++++++-- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/cg/services/illumina/post_processing/post_processing_service.py b/cg/services/illumina/post_processing/post_processing_service.py index 44e5b89b53..9a0a49eaf1 100644 --- a/cg/services/illumina/post_processing/post_processing_service.py +++ b/cg/services/illumina/post_processing/post_processing_service.py @@ -134,7 +134,7 @@ def update_samples_for_metrics( ) -> None: unique_samples_on_run: list[str] = self.get_unique_samples_from_run(sample_metrics) for sample_id in unique_samples_on_run: - self.status_db.update_sample_reads_illumina(internal_id=sample_id) + self.status_db.update_sample_reads_illumina(internal_id=sample_id, sequencer_type=sequencing_run.sequencer_type) self.status_db.update_sample_sequenced_at( sample_id, date=sequencing_run.sequencing_completed_at ) diff --git a/cg/store/crud/update.py b/cg/store/crud/update.py index 5d07132ba2..e55ee48bad 100644 --- a/cg/store/crud/update.py +++ b/cg/store/crud/update.py @@ -6,6 +6,8 @@ from cg.constants import SequencingRunDataAvailability from cg.constants.constants import SequencingQCStatus +from cg.constants.sequencing import Sequencers +from cg.services.illumina.post_processing.utils import get_q30_threshold from cg.store.base import BaseHandler from cg.store.models import ( Case, @@ -58,12 +60,17 @@ def update_sequencing_qc_status(self, case: Case, status: SequencingQCStatus) -> case.aggregated_sequencing_qc = status self.session.commit() - def update_sample_reads_illumina(self, internal_id: str): + def update_sample_reads_illumina(self, internal_id: str, sequencer_type: Sequencers): sample: Sample = self.get_sample_by_internal_id(internal_id) total_reads_for_sample: int = 0 sample_metrics: list[IlluminaSampleSequencingMetrics] = sample.sample_run_metrics + + q30_threshold: int = get_q30_threshold(sequencer_type) + for sample_metric in sample_metrics: - total_reads_for_sample += sample_metric.total_reads_in_lane + if sample_metric.base_passing_q30_percent >= q30_threshold: + total_reads_for_sample += sample_metric.total_reads_in_lane + sample.reads = total_reads_for_sample self.session.commit() diff --git a/tests/store/crud/update/test_update.py b/tests/store/crud/update/test_update.py index 4862ef6512..072bc738f3 100644 --- a/tests/store/crud/update/test_update.py +++ b/tests/store/crud/update/test_update.py @@ -1,7 +1,8 @@ from datetime import datetime from cg.constants import SequencingRunDataAvailability -from cg.store.models import IlluminaSequencingRun, Sample +from cg.constants.sequencing import Sequencers +from cg.store.models import IlluminaSequencingRun, Sample, IlluminaSampleSequencingMetrics from cg.store.store import Store @@ -50,7 +51,7 @@ def test_update_sample_reads_illumina( # WHEN updating the sample reads for a sequencing run store_with_illumina_sequencing_data.update_sample_reads_illumina( - internal_id=selected_novaseq_x_sample_ids[0] + internal_id=selected_novaseq_x_sample_ids[0], sequencer_type=Sequencers.NOVASEQX ) # THEN the total reads for the sample is updated @@ -60,6 +61,24 @@ def test_update_sample_reads_illumina( total_reads_for_sample += sample_metric.total_reads_in_lane assert sample.reads == total_reads_for_sample +def test_update_sample_reads_illumina_fail_q30( + store_with_illumina_sequencing_data: Store, selected_novaseq_x_sample_ids: list[str] +): + # GIVEN a store with Illumina Sequencing Runs and a sample id + sample: Sample = store_with_illumina_sequencing_data.get_sample_by_internal_id( + selected_novaseq_x_sample_ids[0] + ) + assert sample.reads == 0 + # GIVEN that the q30 for the lane is below the threshold for the sequencer type + sample.sample_run_metrics[0].base_passing_q30_percent = 30 + + # WHEN updating the sample reads for a sequencing run + store_with_illumina_sequencing_data.update_sample_reads_illumina( + internal_id=selected_novaseq_x_sample_ids[0], sequencer_type=Sequencers.NOVASEQX + ) + + # THEN the total reads for the sample is updated + assert sample.reads == 0 def test_update_sample_last_sequenced_at( store_with_illumina_sequencing_data: Store,