Skip to content

Commit

Permalink
Validate that negative control sample for cases passes control
Browse files Browse the repository at this point in the history
  • Loading branch information
seallard committed Dec 12, 2023
1 parent 0227515 commit 48e247b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
6 changes: 4 additions & 2 deletions cg/meta/workflow/microsalt/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import List, Dict
from pydantic import BaseModel

from cg.store.models import Sample


class BlastPubmlst(BaseModel):
sequence_type: str
Expand Down Expand Up @@ -42,5 +44,5 @@ class QualityMetrics(BaseModel):


class QualityResult(BaseModel):
sample_id: str
passed: bool
sample: Sample
passes_qc: bool
10 changes: 8 additions & 2 deletions cg/meta/workflow/microsalt/quality_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from cg.constants.constants import MicrosaltAppTags, MicrosaltQC
from cg.meta.workflow.microsalt.models import QualityMetrics, QualityResult, SampleMetrics
from cg.meta.workflow.microsalt.utils import (
get_negative_control_result,
is_valid_10x_coverage,
is_valid_average_coverage,
is_valid_duplication_rate,
Expand Down Expand Up @@ -39,6 +40,7 @@ def quality_control(self, run_dir_path: Path, lims_project: str):
self.quality_control_case(sample_results)

def quality_control_sample(self, sample_id: str, metrics: SampleMetrics) -> QualityResult:
sample = self.status_db.get_sample_by_internal_id(sample_id)
valid_reads: bool = self.is_valid_total_reads(sample_id)
valid_mapping: bool = self.is_valid_mapped_rate(metrics)
valid_duplication: bool = self.is_valid_duplication_rate(metrics)
Expand All @@ -56,12 +58,12 @@ def quality_control_sample(self, sample_id: str, metrics: SampleMetrics) -> Qual
)

return QualityResult(
sample_id=sample_id,
sample=sample,
passed=sample_passes_qc,
)

def quality_control_case(self, sample_results: list[QualityResult]) -> bool:
negative_control_passes: bool = True
control_passes_qc: bool = self.is_valid_negative_control(sample_results)

def microsalt_qc(self, case_id: str, run_dir_path: Path, lims_project: str) -> bool:
"""Check if given microSALT case passes QC check."""
Expand Down Expand Up @@ -196,3 +198,7 @@ def is_valid_average_coverage(self, metrics: SampleMetrics) -> bool:
def is_valid_10x_coverage(self, metrics: SampleMetrics) -> bool:
coverage_10x: float = metrics.microsalt_samtools_stats.coverage_10x
return is_valid_10x_coverage(coverage_10x)

def is_valid_negative_control(self, results: list[QualityResult]) -> bool:
negative_control_result: QualityResult = get_negative_control_result(results)
return negative_control_result.passes_qc
9 changes: 8 additions & 1 deletion cg/meta/workflow/microsalt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from cg.constants.constants import MicrosaltQC
from cg.io.json import read_json
from cg.meta.workflow.microsalt.models import QualityMetrics
from cg.meta.workflow.microsalt.models import QualityMetrics, QualityResult
from cg.models.orders.sample_base import ControlEnum


def is_valid_total_reads(reads: int, target_reads: int) -> bool:
Expand Down Expand Up @@ -36,3 +37,9 @@ def is_valid_10x_coverage(coverage_10x: float) -> bool:
def parse_quality_metrics(file_path: Path) -> QualityMetrics:
data = read_json(file_path)
return QualityMetrics.model_validate_json(data)


def get_negative_control_result(results: list[QualityResult]) -> QualityResult:
for result in results:
if result.sample.control == ControlEnum.negative:
return result

0 comments on commit 48e247b

Please sign in to comment.