Skip to content

Commit

Permalink
Add some CS fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
abragtim authored and kubantjan committed May 24, 2023
1 parent c9582e4 commit fd3b76a
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions txmatching/web/api/crossmatch_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from dataclasses import dataclass
from typing import List, Tuple

from flask_restx import Resource
Expand All @@ -23,6 +24,12 @@
from txmatching.web.web_utils.route_utils import request_body, response_ok


@dataclass
class AssumedHLATypingParsingResult:
assumed_hla_typing: List[List[HLAType]]
parsing_issues: List[ParsingIssueBase]


@crossmatch_api.route('/do-crossmatch', methods=['POST'])
class DoCrossmatch(Resource):
@crossmatch_api.doc(security='bearer',
Expand All @@ -44,8 +51,11 @@ def post(self):
recipient_antibodies=hla_antibodies,
use_high_resolution=True)

assumed_hla_typing, typing_parsing_issues = _solve_potential_hla_typing(
assumed_hla_typing_parsing_result = _get_assumed_hla_typing_and_return_parsing_issues(
crossmatch_dto.potential_donor_hla_typing, hla_antibodies)
assumed_hla_typing = assumed_hla_typing_parsing_result.assumed_hla_typing
typing_parsing_issues = assumed_hla_typing_parsing_result.parsing_issues

antibody_matches_for_hla_type = [
AntibodyMatchForHLAType.from_crossmatched_antibodies(
assumed_hla_type=assumed_hla_type,
Expand All @@ -71,16 +81,15 @@ def _get_hla_antibodies_and_parsing_issues(antibodies: List[HLAAntibodiesUploadD
hla_antibodies_per_groups=antibodies_dto.hla_antibodies_per_groups), parsing_issues


def _solve_potential_hla_typing(potential_hla_typing_raw: List[List[str]],
antibodies_to_solve_hla_typing: HLAAntibodies) \
-> Tuple[List[List[HLAType]], List[ParsingIssueBase]]:
def _get_assumed_hla_typing_and_return_parsing_issues(potential_hla_typing_raw: List[List[str]],
antibodies_to_solve_hla_typing: HLAAntibodies) \
-> AssumedHLATypingParsingResult:
"""
:param potential_hla_typing_raw: has a very similar meaning to assumed
(has all the same limitations, viz AntibodyMatchForHLAType),
but is a more extended version. Usually, all high res codes for
assumed HLA type are presented in the corresponding antibodies,
or they occur just once. So we have to analyze all potential
hla types against certain list of antibodies to satisfy this condition.
:param potential_hla_typing_raw: all potential hla_typing codes that were derived from
a lab test (likely PCR) of patient are stored.
This is then processed to assumed hla_typing that contains only
the typing that has a match with antibodies and therefore is
meaning for crossmatch computation.
:param antibodies_to_solve_hla_typing: certain antibodies which help to transform potential
HLA Typing into assumed.
:return: solved assumed HLA typing and parsing issues for the remaining assumed HLA typing.
Expand Down Expand Up @@ -113,7 +122,7 @@ def _solve_potential_hla_typing(potential_hla_typing_raw: List[List[str]],
assumed_hla_typing for hla in assumed_hla_type]
))

return assumed_hla_typing, assumed_hla_typing_parsing_issues
return AssumedHLATypingParsingResult(assumed_hla_typing, assumed_hla_typing_parsing_issues)


def _convert_potential_hla_type_to_low_res(potential_hla_type: List[HLAType]) -> List[HLAType]:
Expand Down

0 comments on commit fd3b76a

Please sign in to comment.