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
47 changes: 41 additions & 6 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 @@ -3,24 +3,28 @@
import unittest
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 local_testing_utilities.generate_patients import (CROSSMATCH_TXM_EVENT_NAME,
LARGE_DATA_FOLDER,
SMALL_DATA_FOLDER_WITH_CROSSMATCH,
store_generated_patients_from_folder)
from tests.test_utilities.prepare_app_for_tests import DbTests
from tests.utils.hla_system.type_a_example_recipient import TYPE_A_EXAMPLE_REC
from txmatching.database.services.txm_event_service import get_txm_event_complete, get_txm_event_db_id_by_name
from txmatching.patients.hla_code import HLACode
from txmatching.patients.hla_model import HLAAntibodyRaw
from txmatching.patients.hla_model import HLAAntibodyRaw, HLAType
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,
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__)


class TestCrossmatch(unittest.TestCase):
class TestCrossmatch(DbTests):
kristinagalik marked this conversation as resolved.
Show resolved Hide resolved
# It's difficult to have a patient with type A.
# And in order to create the unittests for all special cases, sometimes we will state
# directly that a patient is type A (even if biologically he is not)
Expand Down Expand Up @@ -595,3 +599,34 @@ 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):
store_generated_patients_from_folder(SMALL_DATA_FOLDER_WITH_CROSSMATCH, CROSSMATCH_TXM_EVENT_NAME)

txm_event = get_txm_event_complete(get_txm_event_db_id_by_name(CROSSMATCH_TXM_EVENT_NAME))

recipient_db_id = [recipient.db_id for recipient in txm_event.active_and_valid_recipients_dict.values()
if recipient.medical_id == 'CAN_5R'][0]
donor_db_id = [donor.db_id for donor in txm_event.active_and_valid_donors_dict.values()
if donor.medical_id == 'CAN_5'][0]

recipient_antibodies = txm_event.active_and_valid_recipients_dict[recipient_db_id].hla_antibodies
donor_antigens = txm_event.active_and_valid_donors_dict[donor_db_id].parameters.hla_typing

recipient_antibodies.hla_antibodies_per_groups[5].hla_antibody_list.append(
create_antibody_parsed('DQA1*02:03', 2100, 2000, 'DQB1*18:01')
)
recipient_antibodies.hla_antibodies_per_groups[5].hla_antibody_list.append(
create_antibody_parsed('DQA1*02:03', 2100, 2000, None, HLAAntibodyType.THEORETICAL)
)
recipient_antibodies.hla_antibodies_per_groups[5].hla_antibody_list.append(
create_antibody_parsed('DQB1*18:01', 2100, 2000, None, HLAAntibodyType.THEORETICAL)
)

donor_antigens.hla_per_groups[5].hla_types.append(HLAType('DQA1*02:03', HLACode('DQA1*02:03', None, None)))

self.assertTrue(do_crossmatch_in_type_a(
donor_antigens,
recipient_antibodies,
True
) is not None)
kristinagalik marked this conversation as resolved.
Show resolved Hide resolved