Skip to content

Commit

Permalink
Add q30 check when calculating sample reads (#3680)
Browse files Browse the repository at this point in the history
### Added

- Check for q30 when calculating Sample.reads
- Tests for when the q30 of a lane is below the threshold for the sequencer type
  • Loading branch information
beatrizsavinhas authored Sep 3, 2024
1 parent f19de7d commit a826107
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ 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
)
Expand Down
11 changes: 9 additions & 2 deletions cg/store/crud/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()

Expand Down
25 changes: 23 additions & 2 deletions tests/store/crud/update/test_update.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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
Expand All @@ -61,6 +62,26 @@ def test_update_sample_reads_illumina(
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,
selected_novaseq_x_sample_ids: list[str],
Expand Down

0 comments on commit a826107

Please sign in to comment.