def post(self): """ returns leader match status of single HLA-B-mismatched transplants sorted via a three-letter nomenclature: (1) non-shared patient's mismatch, (2) non-shared donor's mismatch, (3) shared allotype. """ try: patient = request.json['hla-b_genotype_patient'] donors = request.json['hla-b_genotype_donors'] match = HlaBGenotypeMatch(HlaBGenotype(patient['genotype'], id=patient['id']), [HlaBGenotype(donor['genotype'], id=donor['id']) for donor in donors]) results = LeaderMapper().get_match_status_info(match) return jsonify(results) except Exception as e: return e.__dict__, 500
def __init__(self, genotype_patient: HlaBGenotype, genotypes_donors: list) -> None: """ Represents the match status between two HLA-B genotypes as a two-element list of HlaBAllotypeMatches. Also, aligns the genotypes with the match grades. The first genotype represents the patient/recipient while the second genotype represents the potential donor. :param genotype_patient: HlaBGenotype object :param genotypes_donors: List of HlaBGenotype objects """ if not isinstance(genotypes_donors, list): genotypes_donors = [genotypes_donors] if not (isinstance(genotype_patient, HlaBGenotype) and False not in [isinstance(geno_donor, HlaBGenotype) for geno_donor in genotypes_donors]): genotype_patient = HlaBGenotype(str(genotype_patient)) genotypes_donors = [HlaBGenotype(str(geno_donor)) for geno_donor in genotypes_donors] self.matches = self._get_matches(genotype_patient, genotypes_donors)
def get_leader_genotype_info(self, inp_genotype: HlaBGenotype): """ Returns leader genotype information from a HLA-B genotype :param: HLA-B genotype :type: HlaBGenotype or str """ if not isinstance(inp_genotype, HlaBGenotype): inp_genotype = HlaBGenotype(inp_genotype) allotype_one = self.get_leader_allotype_info(inp_genotype.first()) allotype_two = self.get_leader_allotype_info(inp_genotype.second()) return { "leader_genotype": str(allotype_one["common_leader"]) + str(allotype_two["common_leader"]), "hla-b_genotype": dict(inp_genotype), "hla-b_allotype_one": allotype_one, "hla-b_allotype_two": allotype_two, }
def step_impl(context): context.genotype_one = HlaBGenotype(context.genotype_name_one) context.genotype_two = HlaBGenotype(context.genotype_name_two) context.sort_one = context.genotype_one.flip_sorted and "sorted" or "unsorted" context.sort_two = context.genotype_two.flip_sorted and "sorted" or "unsorted"
def step_impl(context, sorted_genotype): context.sorted_genotype = HlaBGenotype(sorted_genotype)
def step_impl(context, genotype): try: context.genotype = HlaBGenotype(genotype) except InvalidHlaBGenotypeError: context.genotype = "invalid"
def step_impl(context, genotype_name): context.genotype = HlaBGenotype(genotype_name)
def step_impl(context): donors = [] for row in context.table: donors.append(HlaBGenotype(row["HLA-B Genotype"])) context.genotypes_donors = donors
def step_impl(context, genotype_patient): context.genotype_patient = HlaBGenotype(genotype_patient)
def step_impl(context): context.genotype_one = HlaBGenotype(context.genotype_name_one) context.genotype_two = HlaBGenotype(context.genotype_name_two) context.sort_one = context.genotype_one.flip_sorted and 'sorted' or 'unsorted' context.sort_two = context.genotype_two.flip_sorted and 'sorted' or 'unsorted'