Пример #1
0
    def test_ibs_segments(self):
        '''Test locating IBD segments between parent and child haplotypes.'''
        (parent, child, hap1, hap2) = (1, 2, 0, 1)
        het_snps = gt.where_heterozygous(self.haplotype.data, parent)

        segment_set = ibd.ibs_segments(self.haplotype, parent, child, hap1,
                                       hap2, het_snps, True)
        assert_segments_almost_equal(
            segment_set,
            [((3, 172), (17080378, 18541497, 1.461, 0), ((1, 1), (2, 1))),
             ((193, 3218), (18996226, 51156934, 32.161, 1), ((1, 0), (2, 1)))],
            full_data=True,
            decimal=3,
            err_msg='Wrong IBD segments')

        segment_set = ibd.ibs_segments(self.haplotype,
                                       parent,
                                       child,
                                       hap1,
                                       hap2,
                                       het_snps,
                                       True,
                                       length_bound='base_pair',
                                       min_segment_length=10.0)
        assert_segments_almost_equal(segment_set,
                                     [((193, 3218),
                                       (18996226, 51156934, 32.161, 1),
                                       ((1, 0), (2, 1)))],
                                     full_data=True,
                                     decimal=3,
                                     err_msg='Wrong IBD segments')
Пример #2
0
    def test_ibs_segments(self):
        '''Test locating IBD segments between parent and child haplotypes.'''
        (parent, child, hap1, hap2) = (1, 2, 0, 1)
        het_snps = gt.where_heterozygous(self.haplotype.data, parent)
        
        segment_set = ibd.ibs_segments(self.haplotype, parent, child, hap1, hap2, het_snps, True)
        assert_segments_almost_equal(segment_set,
                                     [((3   , 172), (17080378, 18541497, 1.461, 0), ((1, 1), (2, 1))),
                                      ((193 , 3218), (18996226, 51156934, 32.161, 1), ((1, 0), (2, 1)))],
                                     full_data=True, decimal=3, err_msg='Wrong IBD segments') 

        segment_set = ibd.ibs_segments(self.haplotype, parent, child, hap1, hap2, het_snps, True,
                                       length_bound='base_pair', min_segment_length=10.0)
        assert_segments_almost_equal(segment_set,
                                     [((193 , 3218), (18996226, 51156934, 32.161, 1), ((1, 0), (2, 1)))],
                                     full_data=True, decimal=3, err_msg='Wrong IBD segments') 
Пример #3
0
def ibd_segments_parent_child(haplotype, parent, child, parent_type, het_snps,
                              min_segment_length=INDETERMINATE, debug=False):
    '''Return 1) IBD segments between a parent and child. 2) List of het_snp indices at which there
    are likely genotype errors.'''
    # Parent phase is dummy. Could be either one.
    # if debug:
#    if parent == 1036 or child == 1036:
#        print 'parent-child IBD', parent, child, parent_type
    return ibd.ibs_segments(haplotype, parent, child, PATERNAL, parent_type, het_snps, debug=debug)
Пример #4
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)