Skip to content

Commit

Permalink
Revert "Revert earlier changes (#3689)" (#3769)(patch)
Browse files Browse the repository at this point in the history
### Changed
- Reverts the commit in PR #3689
  • Loading branch information
Karl-Svard authored Sep 26, 2024
1 parent bba0521 commit abcb885
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cg/services/illumina/post_processing/housekeeper_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
get_undetermined_fastqs,
rename_fastq_file_if_needed,
)
from cg.store.models import Sample
from cg.store.store import Store
from cg.utils.files import get_files_matching_pattern

Expand All @@ -32,6 +33,10 @@ def _should_fastq_path_be_stored_in_housekeeper(
Check if a sample fastq file should be tracked in Housekeeper.
Only fastq files that pass the q30 threshold should be tracked.
"""
sample: Sample = store.get_sample_by_internal_id(internal_id=sample_id)

if sample.is_negative_control:
return True

lane = get_lane_from_sample_fastq(sample_fastq_path)
q30_threshold: int = get_q30_threshold(sequencer_type)
Expand Down
5 changes: 4 additions & 1 deletion cg/store/crud/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ def update_sample_reads_illumina(self, internal_id: str, sequencer_type: Sequenc
q30_threshold: int = get_q30_threshold(sequencer_type)

for sample_metric in sample_metrics:
if sample_metric.base_passing_q30_percent >= q30_threshold:
if (
sample_metric.base_passing_q30_percent >= q30_threshold
or sample.is_negative_control
):
total_reads_for_sample += sample_metric.total_reads_in_lane

sample.reads = total_reads_for_sample
Expand Down
25 changes: 25 additions & 0 deletions tests/store/crud/update/test_update.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime

from cg.constants import SequencingRunDataAvailability
from cg.constants.constants import ControlOptions
from cg.constants.sequencing import Sequencers
from cg.store.models import IlluminaSequencingRun, Sample, IlluminaSampleSequencingMetrics, Analysis
from cg.store.store import Store
Expand Down Expand Up @@ -82,6 +83,30 @@ def test_update_sample_reads_illumina_fail_q30(
assert sample.reads == 0


def test_update_sample_reads_illumina_negative_control(
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 sample is a negative control sample
sample.control = ControlOptions.NEGATIVE

# 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
total_reads_for_sample: int = 0
sample_metrics: list[IlluminaSampleSequencingMetrics] = sample.sample_run_metrics
for sample_metric in sample_metrics:
total_reads_for_sample += sample_metric.total_reads_in_lane
assert sample.reads == total_reads_for_sample


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 abcb885

Please sign in to comment.