Skip to content

Commit

Permalink
Patch sequencing metrics model (#425)(patch)
Browse files Browse the repository at this point in the history
### Fixed
- q30 metrics naming
- Threshold comparison for q30 values
  • Loading branch information
seallard authored Aug 25, 2023
1 parent 8650d0b commit 93d2370
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions cg_lims/EPPs/qc/sequencing_quality_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ def _update_sample_with_quality_results(
sample_id=metrics.sample_internal_id,
lane=metrics.flow_cell_lane_number,
reads=metrics.sample_total_reads_in_lane,
q30_score=metrics.sample_base_fraction_passing_q30 * 100,
q30_score=metrics.sample_base_percentage_passing_q30,
passed_quality_control=passed_quality_control,
)

def _quality_control(self, metrics: SampleLaneSequencingMetrics) -> bool:
return self._passes_quality_thresholds(
reads=metrics.sample_total_reads_in_lane,
q30_score=metrics.sample_base_fraction_passing_q30,
q30_score=metrics.sample_base_percentage_passing_q30,
)

def _passes_quality_thresholds(self, q30_score: float, reads: int) -> bool:
"""Check if the provided metrics pass the minimum quality thresholds."""
passes_q30_threshold = q30_score * 100 >= self.q30_threshold
passes_q30_threshold = q30_score >= self.q30_threshold
passes_read_threshold = reads >= self.READS_MIN_THRESHOLD
return passes_q30_threshold and passes_read_threshold

Expand Down
2 changes: 1 addition & 1 deletion cg_lims/models/sample_lane_sequencing_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ class SampleLaneSequencingMetrics(BaseModel):
flow_cell_lane_number: int
sample_internal_id: str
sample_total_reads_in_lane: int
sample_base_fraction_passing_q30: float
sample_base_percentage_passing_q30: float
20 changes: 10 additions & 10 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def sequencing_metrics_json() -> List[Dict]:
"flow_cell_lane_number": 1,
"sample_internal_id": "test",
"sample_total_reads_in_lane": 100,
"sample_base_fraction_passing_q30": 0.95,
"sample_base_percentage_passing_q30": 95,
"sample_base_mean_quality_score": 30.0,
}
]
Expand Down Expand Up @@ -263,7 +263,7 @@ def generate_metrics_json(
sample_ids: List[str],
lanes: int,
total_reads_in_lane: int,
base_fraction_passing_q30: float,
base_percentage_passing_q30: float,
) -> List[Dict]:
metrics = []
for sample_id in sample_ids:
Expand All @@ -273,7 +273,7 @@ def generate_metrics_json(
"flow_cell_lane_number": lane,
"sample_internal_id": sample_id,
"sample_total_reads_in_lane": total_reads_in_lane,
"sample_base_fraction_passing_q30": base_fraction_passing_q30,
"sample_base_percentage_passing_q30": base_percentage_passing_q30,
"created_at": dt.datetime.now().isoformat(),
}
metrics.append(metric)
Expand All @@ -289,7 +289,7 @@ def novaseq_metrics_passing_thresholds_json(
sample_ids=novaseq_sample_ids,
lanes=novaseq_lanes,
total_reads_in_lane=10000,
base_fraction_passing_q30=0.95,
base_percentage_passing_q30=95,
)


Expand All @@ -302,7 +302,7 @@ def novaseq_metrics_failing_q30_threshold_json(
sample_ids=novaseq_sample_ids,
lanes=novaseq_lanes,
total_reads_in_lane=10000,
base_fraction_passing_q30=0,
base_percentage_passing_q30=0,
)


Expand All @@ -315,7 +315,7 @@ def novaseq_metrics_failing_reads_json(
sample_ids=novaseq_sample_ids,
lanes=novaseq_lanes,
total_reads_in_lane=0,
base_fraction_passing_q30=0.95,
base_percentage_passing_q30=95,
)


Expand All @@ -328,10 +328,10 @@ def novaseq_metrics_two_failing(
sample_ids=novaseq_sample_ids,
lanes=novaseq_lanes,
total_reads_in_lane=10000,
base_fraction_passing_q30=0.95,
base_percentage_passing_q30=95,
)

metrics[0]["sample_base_fraction_passing_q30"] = 0
metrics[0]["sample_base_percentage_passing_q30"] = 0
metrics[1]["sample_total_reads_in_lane"] = 0

return metrics
Expand Down Expand Up @@ -365,7 +365,7 @@ def novaseq_metrics_missing_for_sample_in_lane(
sample_ids=novaseq_sample_ids,
lanes=novaseq_lanes,
total_reads_in_lane=10000,
base_fraction_passing_q30=0.95,
base_percentage_passing_q30=95,
)
for metric in metrics:
if (
Expand All @@ -390,7 +390,7 @@ def novaseq_missing_sample(
sample_ids=novaseq_sample_ids,
lanes=novaseq_lanes,
total_reads_in_lane=10000,
base_fraction_passing_q30=0.95,
base_percentage_passing_q30=95,
)
return metrics

Expand Down

0 comments on commit 93d2370

Please sign in to comment.