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

Validate mother in same case as child #3493

Merged
merged 5 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions cg/services/order_validation_service/models/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ class InvalidMotherSexError(CaseSampleError):
message: str = "Mother must be female"


class MotherNotInCaseError(CaseSampleError):
field: str = "mother"
message: str = "Mother must be in the same case"


class InvalidGenePanelsError(CaseError):
def __init__(self, case_name: str, panels: list[str]):
message = "Invalid panels: " + ",".join(panels)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
FatherNotInCaseError,
InvalidFatherSexError,
InvalidMotherSexError,
MotherNotInCaseError,
OccupiedWellError,
RepeatedCaseNameError,
RepeatedSampleNameError,
Expand All @@ -13,6 +14,7 @@
_get_plate_samples,
get_father_case_errors,
get_father_sex_errors,
get_mother_case_errors,
get_mother_sex_errors,
get_repeated_case_name_errors,
get_repeated_sample_name_errors,
Expand Down Expand Up @@ -59,3 +61,11 @@ def validate_mothers_are_female(order: TomteOrder) -> list[InvalidMotherSexError
case_errors = get_mother_sex_errors(case)
errors.extend(case_errors)
return errors


def validate_mothers_in_same_case_as_children(order: TomteOrder) -> list[MotherNotInCaseError]:
errors = []
for case in order.cases:
case_errors = get_mother_case_errors(case)
errors.extend(case_errors)
return errors
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
FatherNotInCaseError,
InvalidFatherSexError,
InvalidMotherSexError,
MotherNotInCaseError,
OccupiedWellError,
RepeatedCaseNameError,
RepeatedSampleNameError,
Expand Down Expand Up @@ -120,10 +121,25 @@ def get_mother_sex_errors(case: TomteCase) -> list[InvalidMotherSexError]:
return errors


def get_mother_case_errors(case: TomteCase) -> list[MotherNotInCaseError]:
errors = []
children: list[TomteSample] = case.get_samples_with_mother()
for child in children:
mother: TomteSample | None = case.get_sample(child.mother)
if not mother:
error = create_mother_case_error(case=case, sample=child)
errors.append(error)
return errors


def create_father_case_error(case: TomteCase, sample: TomteSample) -> FatherNotInCaseError:
return FatherNotInCaseError(case_name=case.name, sample_name=sample.name)


def create_mother_case_error(case: TomteCase, sample: TomteSample) -> MotherNotInCaseError:
return MotherNotInCaseError(case_name=case.name, sample_name=sample.name)


def is_mother_sex_invalid(child: TomteSample, case: TomteCase) -> bool:
mother: TomteSample | None = case.get_sample(child.mother)
return mother and mother.sex != Sex.FEMALE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
validate_fathers_are_male,
validate_fathers_in_same_case_as_children,
validate_mothers_are_female,
validate_mothers_in_same_case_as_children,
validate_sample_names_not_repeated,
validate_wells_contain_at_most_one_sample,
)
Expand All @@ -42,6 +43,7 @@
validate_fathers_are_male,
validate_fathers_in_same_case_as_children,
validate_mothers_are_female,
validate_mothers_in_same_case_as_children,
validate_sample_names_not_repeated,
validate_wells_contain_at_most_one_sample,
]
Loading