def convert_data_to_Als(fam_dict): """ convert, for a family, the alleles_names data format: from a list to an Als (like list, just adjusted to alleles_names. see 'Als' class documentation) :param fam_dict: family dict """ for fam_member in fam_dict: # F, M, 1 ... for allele_name in fam_dict[fam_member]: # A, B ... al1 = fam_dict[fam_member][allele_name][0] # first allele al2 = fam_dict[fam_member][allele_name][1] # second allele new_format = Als() # new object of Als new_format.extend([al1, al2]) # add alleles_names data fam_dict[fam_member].update({allele_name: new_format}) # update the data in the dict to be in Als format
def validate(hap_1, hap_2, member, is_serology): # todo: check it !! """ compare two haplotype to person (2 from one parent if compare to parent, and 1 from each parent if compare to _child_) :param hap_1: first haplotype :param hap_2: second haplotype :param member: family member :param is_serology: flag, if serology, the validate is checked in another way :return: True if consistency, False otherwise """ hap_1 = gl_string_to_dict(hap_1) hap_2 = gl_string_to_dict(hap_2) if not is_serology: for allele_name, allele_values in member.items(): val_member1, val_member2, val_hap1, val_hap2 = \ allele_values[0], allele_values[1], hap_1[allele_name], hap_2[allele_name] success_option1 = is_equal(val_member1, val_hap1) and is_equal( val_member2, val_hap2) success_option2 = is_equal(val_member1, val_hap2) and is_equal( val_member2, val_hap1) if not (success_option1 or success_option2): return False return True else: # serology data. could be more than 2 options in 'member[allele_name]' pairs_consistent = [False] * len(member.keys()) for idx_allele, (allele_name, allele_values) in enumerate(member.items()): val_hap1, val_hap2 = hap_1[allele_name], hap_2[allele_name] val_member = Als() val_member.extend(member[allele_name]) # the first two conditions are for [] and ["", ""] if not val_member or not any( val_member ) or val_hap1 in val_member and val_hap2 in val_member: pairs_consistent[idx_allele] = True continue if all(pairs_consistent): return True return False