Skip to content

Commit

Permalink
Add reads q30 check and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
beatrizsavinhas committed Sep 3, 2024
1 parent 55ee4fc commit 93574de
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
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
23 changes: 21 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 @@ -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,
Expand Down

0 comments on commit 93574de

Please sign in to comment.