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

test na to ze se bude removovat positive match #1209

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 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
46 changes: 41 additions & 5 deletions tests/utils/hla_system/test_crossmatch.py
kristinagalik marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
from typing import Callable, List

from local_testing_utilities.generate_patients import LARGE_DATA_FOLDER
from txmatching.utils.hla_system.hla_preparation_utils import create_hla_typing, create_hla_type, \
create_antibodies, create_antibody, create_antibody_parsed
from tests.utils.hla_system.type_a_example_recipient import TYPE_A_EXAMPLE_REC
from txmatching.patients.hla_code import HLACode
from txmatching.patients.hla_model import HLAAntibodyRaw
from txmatching.patients.hla_model import HLAAntibody, HLAAntibodyRaw
from txmatching.utils.constants import \
SUFFICIENT_NUMBER_OF_ANTIBODIES_IN_HIGH_RES
from txmatching.utils.enums import (AntibodyMatchTypes, HLAAntibodyType,
HLACrossmatchLevel)
from txmatching.utils.hla_system.hla_crossmatch import (
AntibodyMatch, do_crossmatch_in_type_a, do_crossmatch_in_type_b,
AntibodyMatch, add_theoretical_crossmatch_type, do_crossmatch_in_type_a, do_crossmatch_in_type_b,
is_positive_hla_crossmatch, is_recipient_type_a)

from txmatching.utils.hla_system.hla_preparation_utils import create_hla_typing, create_hla_type, \
create_antibodies, create_antibody, create_antibody_parsed
logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -595,3 +594,40 @@ def test_crossmatch_for_antibodies_with_two_codes(self):
)

self.assertEqual(crossmatch_result[4].antibody_matches[0].match_type, AntibodyMatchTypes.HIGH_RES_WITH_SPLIT)

def test_positive_crossmatch_theoretical_antibody(self):
# add_theoretical_crossmatch_type changes match_type of theoretical antibodies
# to theoretical, thus these two antibodies will be equal
positive_matches = {AntibodyMatch(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jako tohle by se ale nikdy nemelo stat, ze budou protilatky, co maji stejny hla kod ale ruzny typ preci ne?

Obecne chceme mit v testech realna data a ne nejaky situace, ktery v realite nesmi nastat

Copy link
Contributor Author

@kristinagalik kristinagalik May 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toto je priklad co sa stal, tak je asi problem niekde inde... :/ @kubantjan

mam zalozit novu issue ci to riesit vramci tejto

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha! tak to urcite zkusme vyresit v ramci teto, ale priorita je nizsi nez ty jine veci :)

hla_antibody=HLAAntibody(raw_code='DQA1*02:03',
code=HLACode('DQA1*02:03', 'DQA2', 'DQA2'),
mfi=2100,
cutoff=2000,
second_raw_code=None,
second_code=None,
type=HLAAntibodyType.THEORETICAL),
match_type=AntibodyMatchTypes.HIGH_RES),
AntibodyMatch(
hla_antibody=HLAAntibody(raw_code='DQA1*02:03',
code=HLACode('DQA1*02:03', 'DQA2', 'DQA2'),
mfi=2100,
cutoff=2000,
second_raw_code=None,
second_code=None,
type=HLAAntibodyType.THEORETICAL),
match_type=AntibodyMatchTypes.HIGH_RES_WITH_SPLIT)
}

kristinagalik marked this conversation as resolved.
Show resolved Hide resolved
expected_positive_matches = {AntibodyMatch(
hla_antibody=HLAAntibody(raw_code='DQA1*02:03',
code=HLACode('DQA1*02:03', 'DQA2', 'DQA2'),
mfi=2100,
cutoff=2000,
second_raw_code=None,
second_code=None,
type=HLAAntibodyType.THEORETICAL),
match_type=AntibodyMatchTypes.THEORETICAL)
}

add_theoretical_crossmatch_type(positive_matches)
self.assertEqual(positive_matches, expected_positive_matches)
6 changes: 3 additions & 3 deletions txmatching/utils/hla_system/hla_crossmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def do_crossmatch_in_type_a(donor_hla_typing: HLATyping,
_do_crossmatch_for_hlas_recipient_was_not_tested_for(
hla_per_group, [antibody], antibodies, positive_matches, use_high_resolution)

_add_theoretical_crossmatch_type(positive_matches)
add_theoretical_crossmatch_type(positive_matches)
_add_none_crossmatch_type(_get_antibodies_over_cutoff(antibodies), positive_matches)
antibody_matches_for_groups.append(AntibodyMatchForHLAGroup(hla_per_group.hla_group, list(positive_matches)))
return antibody_matches_for_groups
Expand Down Expand Up @@ -388,7 +388,7 @@ def do_crossmatch_in_type_b(donor_hla_typing: HLATyping,
if _add_broad_crossmatch_type(hla_type, tested_antibodies_that_match, positive_matches):
continue

_add_theoretical_crossmatch_type(positive_matches)
add_theoretical_crossmatch_type(positive_matches)
_add_none_crossmatch_type(antibodies, positive_matches)

antibody_matches_for_groups.append(AntibodyMatchForHLAGroup(hla_per_group.hla_group, list(positive_matches)))
Expand Down Expand Up @@ -497,7 +497,7 @@ def _add_undecidable_crossmatch_type(antibodies: List[HLAAntibody],
positive_matches.add(AntibodyMatch(antibody, AntibodyMatchTypes.UNDECIDABLE))


def _add_theoretical_crossmatch_type(positive_matches: Set[AntibodyMatch]):
def add_theoretical_crossmatch_type(positive_matches: Set[AntibodyMatch]):
matches_to_remove = set()
for match in positive_matches:
if match.hla_antibody.type == HLAAntibodyType.THEORETICAL and match.match_type != AntibodyMatchTypes.UNDECIDABLE:
Expand Down