Beispiel #1
0
    def test_is_member(self):
        """Check simple set membership logic."""
        self.assertTrue(
            is_member(self.g, [self.pedigree.node_of[126251]]), "Should have been in genotyped list but is not"
        )
        self.assertFalse(is_member(self.g, [-1]), "Should have not been in genotyped list but is")

        self.assertTrue(has_at_least_n_members(set([1, 2, 3]), [1, 2], 1))
        self.assertTrue(has_at_least_n_members(set([1, 2, 3]), [1, 2], 2))
        self.assertTrue(has_at_least_n_members(set([1, 2, 3]), [1, 2], 3))
Beispiel #2
0
    def test_is_member(self):
        '''Check simple set membership logic.'''
        self.assertTrue(is_member(self.g, [self.pedigree.node_of[126251]]),
                        'Should have been in genotyped list but is not')
        self.assertFalse(is_member(self.g, [-1]),
                         'Should have not been in genotyped list but is')

        self.assertTrue(has_at_least_n_members(set([1, 2, 3]), [1, 2], 1))
        self.assertTrue(has_at_least_n_members(set([1, 2, 3]), [1, 2], 2))
        self.assertTrue(has_at_least_n_members(set([1, 2, 3]), [1, 2], 3))
Beispiel #3
0
 def __compute_duos(self, parent_type, genotyped=True, kids=None):
     '''Return a list of (x, parent[x]) where x=child ID and parent[x]=parent ID such that
     both the parent and child are genotyped.'''
     ids = self.__sample_index(genotyped)
     for i in (kids if kids is not None else ids):
         parents = self.parents(i)
         if parents.has_key(parent_type) and (util.is_member(ids, [parents[parent_type]]) if genotyped else True):
             yield (i, self.parents(i)[parent_type])
Beispiel #4
0
 def __compute_trios(self, genotyped=True, kids=None):
     '''Emit all (if kids=None) or selected genotyped trios for a pedigree p and genotype set g. Trios are unsorted.
     This assumes that parents are sorted in a consistent order (say, (father, mother)) in
     the lists returned from Pedigree.parents(). If kids is not None, returns only the trios of the kids in the list ids.'''
     ids = self.__sample_index(genotyped)
     for i in (kids if kids is not None else ids):
         parents = self.parents(i)
         if len(parents) == 2 and (util.is_member(ids, parents.itervalues()) if genotyped else True):
             yield tuple(parents.itervalues()) + (i,)
Beispiel #5
0
def __handle_outer_duos(self, request):
    '''Similar to __FamilyParentChildPhaser, only works with parent-child duos and does not compare
    multiple children in a family. Handles only children outside nuclear families.'''
    problem, params = request.problem, request.params
    h = problem.haplotype
    family_members = problem.families_union(min_children=0)
    for parent_type in constants.ALLELES:
        for child, parent in pt.selected_duos(problem, params, parent_type):
            if not util.is_member(family_members, [child]):
                ibd.phase_by_ibd(request, ip.ibd_segments_in_duo(h, parent, child, parent_type,
                                                                 parent_het_fill_threshold=params.het_fill_threshold,
                                                                 debug=params.debug), 'max')
    return False
Beispiel #6
0
    def __in_extended_family(p, g, x, min_children=None):
        """Check whether a member x of a genotyped-person list g in is in a nuclear family or not according
        to the pedigree graph p.
        This is defined as:
        CASE 1: x's parents are in G and all their children are in G;
        OR 
        CASE 2: x has children, they are all in G and all their parents are in G.
        
        If min_children is specified (not None), the following alternative definition is used instead:
        CASE 1: x's parents are in G and at least min_children of their children are in G;
        OR 
        CASE 2: x has children, of which at least min_children are in G; all of x's children's parents are in G.
        
        Note: this code does not treat polygamous families correctly and assumes that such families are
        'extended', i.e., have more than 2 parents.
        """

        # Optimization: don't bother checking further if x is not in G
        if not p.has_node(x):
            raise Exception("Node " + str(x) + " not in pedigree")
        if not is_member(g, [x]):
            return False

        # Case 1
        parents = p.predecessors(x)
        if is_member(g, parents) and has_at_least_n_members(g, pt.all_successors(p, parents), min_children):
            return True

        # Case 2
        children = p.successors(x)
        if (
            children
            and has_at_least_n_members(g, children, min_children)
            and is_member(g, pt.all_predecessors(p, children))
        ):
            return True

        return False
Beispiel #7
0
    def __in_extended_family(p, g, x, min_children=None):
        '''Check whether a member x of a genotyped-person list g in is in a nuclear family or not according
        to the pedigree graph p.
        This is defined as:
        CASE 1: x's parents are in G and all their children are in G;
        OR 
        CASE 2: x has children, they are all in G and all their parents are in G.
        
        If min_children is specified (not None), the following alternative definition is used instead:
        CASE 1: x's parents are in G and at least min_children of their children are in G;
        OR 
        CASE 2: x has children, of which at least min_children are in G; all of x's children's parents are in G.
        
        Note: this code does not treat polygamous families correctly and assumes that such families are
        'extended', i.e., have more than 2 parents.
        '''

        # Optimization: don't bother checking further if x is not in G
        if not p.has_node(x):
            raise Exception('Node ' + str(x) + ' not in pedigree')
        if not is_member(g, [x]):
            return False

        # Case 1
        parents = p.predecessors(x)
        if (is_member(g, parents) and has_at_least_n_members(
                g, pt.all_successors(p, parents), min_children)):
            return True

        # Case 2
        children = p.successors(x)
        if (children and has_at_least_n_members(g, children, min_children)
                and is_member(g, pt.all_predecessors(p, children))):
            return True

        return False
Beispiel #8
0
def __handle_outer_duos(self, request):
    '''Similar to __FamilyParentChildPhaser, only works with parent-child duos and does not compare
    multiple children in a family. Handles only children outside nuclear families.'''
    problem, params = request.problem, request.params
    h = problem.haplotype
    family_members = problem.families_union(min_children=0)
    for parent_type in constants.ALLELES:
        for child, parent in pt.selected_duos(problem, params, parent_type):
            if not util.is_member(family_members, [child]):
                ibd.phase_by_ibd(
                    request,
                    ip.ibd_segments_in_duo(
                        h,
                        parent,
                        child,
                        parent_type,
                        parent_het_fill_threshold=params.het_fill_threshold,
                        debug=params.debug), 'max')
    return False