Skip to content

Commit

Permalink
Merge pull request #1185 from mild-blue/1183_rozsirit_informaci_o_pri…
Browse files Browse the repository at this point in the history
…dani_theoretical_antibody

Rozsirit informaci o pridani theoretical antibody
  • Loading branch information
kubantjan authored Apr 12, 2023
2 parents d7282d4 + dff04a4 commit 7bd8398
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
43 changes: 33 additions & 10 deletions txmatching/patients/hla_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _check_groups_for_multiple_cutoffs(hla_antibodies: List[HLAAntibody]) -> Lis


def _add_single_hla_antibodies(antibody_list_single_code: List[HLAAntibody]) -> Tuple[
List[ParsingIssueBase], List[HLAAntibody]]:
List[ParsingIssueBase], List[HLAAntibody]]:
def _group_key(hla_antibody: HLAAntibody) -> str:
return hla_antibody.raw_code

Expand Down Expand Up @@ -201,7 +201,7 @@ def _add_double_hla_antibodies(antibody_list_double_code: List[HLAAntibody],
# if both are mixed add double antibody
else:
theoretical_parsing_issues, theoretical_antibodies = _resolve_theoretical_antibody(
double_antibody, parsed_hla_codes, mfi_dictionary)
double_antibody, parsed_hla_codes, mfi_dictionary, antibody_list_double_code)
hla_antibodies_joined.extend(theoretical_antibodies)
parsing_issues.extend(theoretical_parsing_issues)

Expand All @@ -210,20 +210,16 @@ def _add_double_hla_antibodies(antibody_list_double_code: List[HLAAntibody],

def _resolve_theoretical_antibody(double_antibody: HLAAntibody,
parsed_hla_codes: Set[str],
mfi_dictionary: Dict[str, List[int]]) -> \
mfi_dictionary: Dict[str, List[int]],
antibody_list_double_code: List[HLAAntibody]) -> \
Tuple[List[ParsingIssueBase], List[HLAAntibody]]:
parsing_issues = []
hla_antibodies = []

# add double antibody and parsing issue
hla_antibodies.append(double_antibody)
parsing_issues.append(
ParsingIssueBase(
hla_code_or_group=double_antibody.raw_code + ', ' + double_antibody.second_raw_code,
parsing_issue_detail=ParsingIssueDetail.CREATED_THEORETICAL_ANTIBODY,
message=ParsingIssueDetail.CREATED_THEORETICAL_ANTIBODY.value
)
)

parsing_issues.append(create_parsing_issue_creating_double_antibody(double_antibody, antibody_list_double_code))

# join theoretical alpha and beta unparsed chains with averaged MFI
_join_both_chains_if_unparsed(double_antibody, hla_antibodies, parsed_hla_codes,
Expand All @@ -232,6 +228,33 @@ def _resolve_theoretical_antibody(double_antibody: HLAAntibody,
return parsing_issues, hla_antibodies


def create_parsing_issue_creating_double_antibody(double_antibody: HLAAntibody,
antibody_list_double_code: List[HLAAntibody]) -> ParsingIssueBase:
# extract other occurences of alpha chain
alpha_chain_occurences = ', '.join([create_raw_code_for_double_antibody(
antibody) + " mfi: " + str(antibody.mfi) for antibody in antibody_list_double_code if
antibody.code == double_antibody.code and not antibody == double_antibody])

# extract other occurences of beta chain
beta_chain_occurences = ', '.join([create_raw_code_for_double_antibody(
antibody) + " mfi: " + str(antibody.mfi) for antibody in antibody_list_double_code if
antibody.second_code == double_antibody.second_code and not antibody == double_antibody])

detailed_message = " Other antibodies with alpha: " + alpha_chain_occurences + \
". Other antibodies with beta: " + beta_chain_occurences + "."
return ParsingIssueBase(
hla_code_or_group=double_antibody.raw_code + ', ' + double_antibody.second_raw_code,
parsing_issue_detail=ParsingIssueDetail.CREATED_THEORETICAL_ANTIBODY,
message=ParsingIssueDetail.CREATED_THEORETICAL_ANTIBODY.value + detailed_message
)


def create_raw_code_for_double_antibody(hla_antibody: HLAAntibody) -> str:
# Example of HLA antibody raw format: DP[02:01,03:02]
return hla_antibody.code.high_res[:2] + '[' + hla_antibody.code.high_res.split('*')[1] + ',' + \
hla_antibody.second_code.high_res.split('*')[1] + ']'


def _parse_double_antibody_mfi_under_cutoff(double_antibody: HLAAntibody,
parsed_hla_codes: Set[str],
mfi_dictionary: Dict[str, List[int]]) -> List[HLAAntibody]:
Expand Down
2 changes: 1 addition & 1 deletion txmatching/patients/hla_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __eq__(self, other):
self.raw_code == other.raw_code and
self.mfi == other.mfi and
self.cutoff == other.cutoff and
self.second_raw_code == other.second_raw_code,
self.second_raw_code == other.second_raw_code and
self.type == other.type)

def __hash__(self):
Expand Down
8 changes: 1 addition & 7 deletions txmatching/utils/hla_system/hla_preparation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ def create_antibodies(hla_antibodies_list: List[HLAAntibodyRaw]) -> HLAAntibodie
)


def _create_raw_code_for_double_antibody(hla_antibody: HLAAntibody) -> str:
# Example of HLA antibody raw format: DP[02:01,03:02]
return hla_antibody.raw_code[:2] + '[' + hla_antibody.raw_code.split('*')[1] + ',' + \
hla_antibody.second_raw_code.split('*')[1] + ']'


def create_antibody(raw_code: str, mfi: int, cutoff: int) -> HLAAntibodyRaw:
return HLAAntibodyRaw(
raw_code=raw_code,
Expand All @@ -55,7 +49,7 @@ def create_antibody(raw_code: str, mfi: int, cutoff: int) -> HLAAntibodyRaw:


def create_antibody_parsed(raw_code: str, mfi: int, cutoff: int, second_raw_code: str = None,
antibody_type: HLAAntibodyType = HLAAntibodyType.NORMAL) -> HLAAntibody:
antibody_type: HLAAntibodyType = HLAAntibodyType.NORMAL) -> HLAAntibody:
code = parse_hla_raw_code_and_return_parsing_issue_list(raw_code)[1]
second_code = parse_hla_raw_code_and_return_parsing_issue_list(
second_raw_code)[1] if second_raw_code is not None else None
Expand Down

0 comments on commit 7bd8398

Please sign in to comment.