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 __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 #4
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