Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add balsamic sample sex validation #3665

Merged
merged 8 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,8 @@ class InvalidVolumeError(CaseSampleError):
class InvalidBufferError(CaseSampleError):
field: str = "elution_buffer"
message: str = "The chosen buffer is not allowed when skipping reception control"


class SubjectIdGenderError(CaseSampleError):
field: str = "subject_id"
seallard marked this conversation as resolved.
Show resolved Hide resolved
message: str = "Another sample with the same subject id has a different gender"
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from cg.services.order_validation_service.errors.case_sample_errors import SubjectIdGenderError
from cg.services.order_validation_service.workflows.balsamic.models.order import BalsamicOrder
from cg.services.order_validation_service.workflows.balsamic.rules.case_sample.utils import (
has_sex_and_subject,
)
from cg.store.store import Store


def validate_subject_sex_consistency(
seallard marked this conversation as resolved.
Show resolved Hide resolved
order: BalsamicOrder,
store: Store,
) -> list[SubjectIdGenderError]:
errors: list[SubjectIdGenderError] = []

for case_index, case in order.enumerated_new_cases:
for sample_index, sample in case.enumerated_new_samples:
if not has_sex_and_subject(sample):
continue

if store.sample_exists_with_different_sex(
customer_internal_id=order.customer,
subject_id=sample.subject_id,
sex=sample.sex,
):
error = SubjectIdGenderError(
case_index=case_index,
sample_index=sample_index,
)
errors.append(error)
return errors
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from cg.services.order_validation_service.workflows.balsamic.models.sample import BalsamicSample


def has_sex_and_subject(sample: BalsamicSample) -> bool:
return sample.subject_id and sample.sex
seallard marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
validate_volume_interval,
validate_wells_contain_at_most_one_sample,
)
from cg.services.order_validation_service.workflows.balsamic.rules.case_sample.rules import (
validate_subject_sex_consistency,
)


CASE_RULES: list[callable] = [
validate_case_internal_ids_exist,
Expand All @@ -43,4 +47,5 @@
validate_subject_ids_different_from_sample_names,
validate_volume_interval,
validate_wells_contain_at_most_one_sample,
validate_subject_sex_consistency,
]
13 changes: 13 additions & 0 deletions cg/store/crud/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -1562,3 +1562,16 @@ def get_case_ids_for_samples(self, sample_ids: list[int]) -> list[str]:
for sample_id in sample_ids:
case_ids.extend(self.get_case_ids_with_sample(sample_id))
return list(set(case_ids))

def sample_exists_with_different_sex(
self,
customer_internal_id: str,
subject_id: str,
sex: str,
) -> bool:
samples: list[Sample] = self.get_samples_by_customer_and_subject_id(
customer_internal_id=customer_internal_id,
subject_id=subject_id,
)
existing_sex: set[str] = {sample.sex for sample in samples}
seallard marked this conversation as resolved.
Show resolved Hide resolved
return bool(samples) and sex not in existing_sex
Loading