Exemple #1
0
    def test_ibd_parent_vs_all_children(self):
        '''Test calculating distant IBD segments against all surrogate parents;
        compare with IBD segments based on nucelar family info.'''
#        segment_set = ibd_segments_with_surrogate_parents(self.problem, 0,
#                                                          PhaseParam(margin=0., surrogate_parent_fill_threshold=0.9,
#                                                                     max_path_length=2, debug=True),
#                                                          prob_ibd_calculator=im.ibd_hmm.prob_ibd_hmm,
#                                                          is_i_phased=True)
        # Turn off kinship-based POO determination IBD segment computation since we don't have
        # a complete pedigree here 
        segment_set = ibd_segments_with_relatives(self.problem, 0,
                                                  genotyped_children(self.problem, self.problem.first_family),
                                                  PhaseParam(id_coef_file=im.itu.ID_COEF_FILE, max_path_length=2),
                                                  im.ibd_hmm.prob_ibd_hmm, use_kinship=False)
        im.itu.assert_segments_almost_equal(segment_set,
                                            [((0   , 1420), (16484792, 33032458, 16.548, 1), ((2, 0), (0, 0))),
                                             ((241 , 446), (19643555, 23761236, 4.118, 1), ((0, 0), (2, 1))),
                                             ((2215, 2270), (40876234, 42241372, 1.365, 1), ((0, 0), (2, 1))),
                                             ((3138, 3206), (49803008, 50837224, 1.034, 1), ((0, 0), (2, 1))),
                                             ((1278, 1337), (31217345, 32331594, 1.114, 1), ((0, 1), (2, 0))),
                                             ((1411, 3218), (32978753, 51156934, 18.178, 1), ((0, 1), (2, 0))),
                                             ((1278, 1337), (31217345, 32331594, 1.114, 1), ((3, 0), (0, 0))),
                                             ((241 , 451), (19643555, 23817486, 4.174, 1), ((0, 0), (3, 1))),
                                             ((2276, 2363), (42344297, 43527681, 1.183, 1), ((0, 0), (3, 1))),
                                             ((3138, 3206), (49803008, 50837224, 1.034, 1), ((0, 0), (3, 1))),
                                             ((0   , 3218), (16484792, 51156934, 34.672, 1), ((0, 1), (3, 0))),
                                             ((1278, 1337), (31217345, 32331594, 1.114, 1), ((0, 0), (4, 0))),
                                             ((2552, 3218), (45011952, 51156934, 6.145, 1), ((0, 0), (4, 0))),
                                             ((385 , 451), (22583252, 23817486, 1.234, 1), ((0, 0), (4, 1))),
                                             ((2215, 2270), (40876234, 42241372, 1.365, 1), ((0, 0), (4, 1))),
                                             ((0   , 2571), (16484792, 45231758, 28.747, 1), ((0, 1), (4, 0))),
                                             ((0   , 3218), (16484792, 51156934, 34.672, 1), ((0, 0), (5, 0))),
                                             ((385 , 451), (22583252, 23817486, 1.234, 1), ((5, 1), (0, 0))),
                                             ((2276, 2363), (42344297, 43527681, 1.183, 1), ((5, 1), (0, 0))),
                                             ((3138, 3206), (49803008, 50837224, 1.034, 1), ((5, 1), (0, 0))),
                                             ((1278, 1337), (31217345, 32331594, 1.114, 1), ((0, 1), (5, 0))),
                                             ((0   , 805), (16484792, 27119061, 10.634, 1), ((0, 0), (6, 0))),
                                             ((1278, 1337), (31217345, 32331594, 1.114, 1), ((0, 0), (6, 0))),
                                             ((241 , 347), (19643555, 22015144, 2.372, 1), ((6, 1), (0, 0))),
                                             ((385 , 451), (22583252, 23817486, 1.234, 1), ((6, 1), (0, 0))),
                                             ((2276, 2363), (42344297, 43527681, 1.183, 1), ((6, 1), (0, 0))),
                                             ((3138, 3206), (49803008, 50837224, 1.034, 1), ((6, 1), (0, 0))),
                                             ((762 , 3218), (26836780, 51156934, 24.320, 1), ((0, 1), (6, 0)))],
                                             full_data=True, decimal=3, err_msg='Wrong IBD segments')
Exemple #2
0
def ibd_segments_in_family_sibs(request, family):
    '''Even if both parents are not genotyped, output IBD segments within siblings, since
    they share (long) segments on their corresponding paternal haplotypes and maternal haplotypes.
    Only long segments are considered.'''
    problem, params = request.problem, request.params
    genotyped_children = gt.genotyped_children(problem, family)

    # TODO: swap the haps of phased children (that are parents in another family) if inconsistent with their sibs       
    # self.d = (self.h_child != np.transpose(np.tile(self.h_child[:,template], (self.num_children,1)))).astype('int8')
        
    # There exist at least two genotyped children to compare. Pick one as a template
    # and compare every other child against it, or all children as templates
    h = problem.haplotype
    template_mode = params.template_mode
    if template_mode == PhaseParam.TEMPLATE_MODE.ONE:
        # 1 templates = most-filled child 
        fill = problem.fill_fraction(sample=genotyped_children)
        template_index = np.argmax(fill[:, 1])
        template_child = int(fill[template_index, 0])
        templates = [(template_index, template_child)]
        pairs_to_check = lambda i, j: i != j
    if template_mode == PhaseParam.TEMPLATE_MODE.TWO:
        # 2 templates = two most-filled children 
        fill = problem.fill_fraction(sample=genotyped_children)
        template_index = np.argsort(-fill[:, 1])[0:2]
        template_child = fill[template_index, 0].astype(np.int8)
        templates = [(x, template_child[i]) for (i, x) in enumerate(template_index)]
        pairs_to_check = lambda i, j: i != j
    elif template_mode == PhaseParam.TEMPLATE_MODE.ALL:
        # EVery child serves as a template
        templates = enumerate(genotyped_children)
        pairs_to_check = lambda i, j: i < j
    else:
        raise ValueError('Unsupported template mode ''%s''' % (template_mode,))
        
    for parent_type in ALLELES:
        for i, template_child in templates:
            for j, child in enumerate(genotyped_children):
                if pairs_to_check(i, j):
                    yield ibd.ibs_segments(h, template_child, child, parent_type, parent_type,
                                           error_filter='fast_max',
                                           min_segment_length=params.min_segment_length_sibs,
                                           include_alt_phase=False, debug=params.debug)