py_hla_match.matching

class py_hla_match.matching.MatchResult(patient, donor, pairing_score, allele_match_levels, ard_match_levels=None, ard_match_level_certainty=None, molecular_match_levels=None, molecular_match_level_certainty=None)[source]

Bases: object

Result object for comparing two HLA genotype pairs at a single locus.

This class is designed for research use to describe HLA match or mismatch categories between two individuals.

Variables:
  • patient – HLA allele pair in the ‘patient’ role.

  • donor – HLA allele pair in the ‘donor’ role.

  • pairing_score – Internal ordinal score summarising the two AlleleMatchLevel values.

  • allele_match_levels – Tuple of AlleleMatchLevel values for the two allele-level comparisons (patient allele 1 vs donor allele X, patient allele 2 vs donor allele Y).

  • ard_match_levels – Tuple of ARDMatchLevel values refining ARD-equivalent allele pairs (NOT_APPLICABLE if not ARD-matched).

  • ard_match_certainties – Tuple of ARDMatchLevelCertainty values indicating how certain the ARD refinement is given typing resolution.

  • molecular_match_levels – Tuple of MolecularMatchLevel values refining ARD-equivalent allele pairs at 1–4-field level (NOT_APPLICABLE if not ARD-matched).

  • molecular_match_certainties – Tuple of MolecularMatchLevelCertainty values indicating how certain the molecular refinement is given typing resolution.

  • dpb1_tce_status – Optional DPB1 permissive/non-permissive classification from the EBI TCE API (only populated for DPB1 loci).

  • is_homozygous_patientTrue if the patient is homozygous at this locus at ARD-reduced level, False if heterozygous, or None if ARD-reduced alleles are not available.

Parameters:
get_dpb1_tce_status(api_version='3.0', timeout=10)[source]

Calculate DPB1 permissive/non-permissive classification via EBI API.

Intended for research workflows.

WARNING: may slow things down significantly.

Sets self.dpb1_tce_result to one of: - DPB1Result

Parameters:
  • api_version (str) – The version of the EBI API to query (default “3.0”)

  • timeout (int) – Time in seconds to wait for the API response

Returns:

The DPB1Result object, or None if the locus is not DPB1

Return type:

DPB1Result | None

get_match_level_for_resolution(resolution)[source]

Get locus-level match category for a given resolution.

Parameters:

resolution (str) – Resolution level ("basic" or "high").

Returns:

Match level for the given resolution as a string.

Raises:

ValueError – If an unknown resolution level is requested.

Return type:

str

property loci_match_basic_resolution
property loci_match_high_resolution
py_hla_match.matching.allele_match(hla1, hla2)[source]

Compares two HLA alleles and returns a MatchLevel

Parameters:
  • hla1 (HLA) – First HLA allele object

  • hla2 (HLA) – Second HLA allele object

Returns:

MatchLevel enum value indicating position of matches and mismatch (cf. HLA nomenclature)

Raises:
Return type:

AlleleMatchLevel

py_hla_match.matching.allele_pair_match(patient, donor)[source]

Compute research match/mismatch levels for two HLA allele pairs, one in the ‘patient’ role and one in the ‘donor’ role.

Intended for research workflows.

Parameters:
  • patient (HLAPair) – Patient HLAPair containing two HLA alleles.

  • donor (HLAPair) – Donor HLAPair containing two HLA alleles.

Returns:

MatchResult object storing allele-level match categories and all ARD and molecular refinements for the optimal pairing.

Return type:

MatchResult

Notes

  • The function assumes that both patient and donor have exactly two

    HLA alleles

  • Uses _get_correct_allele_pairing to evaluate all possible

    allele pairings and selects the one with the highest score

py_hla_match.matching.multi_locus_match(patient, donor)[source]

Compute HLA match/mismatch categories between two Individuals for all loci that are typed in the first Individual.

Intended for research workflows.

Parameters:
Returns:

List of MatchResult objects for each locus

Return type:

List[MatchResult]

Classes

MatchResult(patient, donor, pairing_score, ...)

Result object for comparing two HLA genotype pairs at a single locus.

Functions

allele_match(hla1, hla2)

Compares two HLA alleles and returns a MatchLevel

allele_pair_match(patient, donor)

Compute research match/mismatch levels for two HLA allele pairs, one in the 'patient' role and one in the 'donor' role.

multi_locus_match(patient, donor)

Compute HLA match/mismatch categories between two Individuals for all loci that are typed in the first Individual.