Esempio n. 1
0
    def test_fitch_descendants_missing_data(self):
        """fitch_descendants should work with missing data"""
        #tree and envs for testing missing values
        t_str = '(((a:1,b:2):4,(c:3,d:1):2):1,(e:2,f:1):3);'
        env_str = """a   A
b   B
c   D
d   C
e   C
f   D"""
        t = DndParser(t_str, UniFracTreeNode)
        node_index, nodes = index_tree(t)
        env_counts = count_envs(env_str.split('\n'))
    
        count_array, unique_envs, env_to_index, node_to_index = \
            index_envs(env_counts, node_index)    

        branch_lengths = get_branch_lengths(node_index)
        #test just the AB pair
        ab_counts = count_array[:, 0:2]
        bindings = bind_to_array(nodes, ab_counts)
        changes = fitch_descendants(bindings, counter=FitchCounter)
        self.assertEqual(changes, 1)
        orig_result = ab_counts.copy()
        #check that the original Fitch counter gives the expected 
        #incorrect parsimony result
        changes = fitch_descendants(bindings, counter=FitchCounterDense)
        self.assertEqual(changes, 5)
        new_result = ab_counts.copy()
        #check that the two versions fill the array with the same values
        self.assertEqual(orig_result, new_result)
Esempio n. 2
0
    def test_fitch_descendants_missing_data(self):
        """fitch_descendants should work with missing data"""
        #tree and envs for testing missing values
        t_str = '(((a:1,b:2):4,(c:3,d:1):2):1,(e:2,f:1):3);'
        env_str = """a   A
b   B
c   D
d   C
e   C
f   D"""
        t = DndParser(t_str, UniFracTreeNode)
        node_index, nodes = index_tree(t)
        env_counts = count_envs(env_str.split('\n'))

        count_array, unique_envs, env_to_index, node_to_index = \
            index_envs(env_counts, node_index)

        branch_lengths = get_branch_lengths(node_index)
        #test just the AB pair
        ab_counts = count_array[:, 0:2]
        bindings = bind_to_array(nodes, ab_counts)
        changes = fitch_descendants(bindings, counter=FitchCounter)
        self.assertEqual(changes, 1)
        orig_result = ab_counts.copy()
        #check that the original Fitch counter gives the expected
        #incorrect parsimony result
        changes = fitch_descendants(bindings, counter=FitchCounterDense)
        self.assertEqual(changes, 5)
        new_result = ab_counts.copy()
        #check that the two versions fill the array with the same values
        self.assertEqual(orig_result, new_result)
Esempio n. 3
0
 def test_fitch_descendants(self):
     """fitch_descendants should assign states by fitch parsimony, ret. #"""
     id_, child = index_tree(self.t3)
     a = zeros((11, 3)) + 99  # fill with junk
     bindings = bind_to_array(child, a)
     # load in leaf envs
     a[0] = a[1] = a[2] = a[7] = [0, 1, 0]
     a[3] = [1, 0, 0]
     a[6] = [0, 0, 1]
     changes = fitch_descendants(bindings)
     self.assertEqual(changes, 2)
     self.assertEqual(
         a,
         array(
             [
                 [0, 1, 0],
                 [0, 1, 0],
                 [0, 1, 0],
                 [1, 0, 0],
                 [0, 1, 0],
                 [1, 0, 0],
                 [0, 0, 1],
                 [0, 1, 0],
                 [1, 1, 0],
                 [0, 1, 1],
                 [0, 1, 0],
             ]
         ),
     )
Esempio n. 4
0
 def test_fitch_descendants(self):
     """fitch_descendants should assign states by fitch parsimony, ret. #"""
     id_, child = index_tree(self.t3)
     a = zeros((11, 3)) + 99  #fill with junk
     bindings = bind_to_array(child, a)
     #load in leaf envs
     a[0] = a[1] = a[2] = a[7] = [0, 1, 0]
     a[3] = [1, 0, 0]
     a[6] = [0, 0, 1]
     changes = fitch_descendants(bindings)
     self.assertEqual(changes, 2)
     self.assertEqual(a, \
         array([[0,1,0],[0,1,0],[0,1,0],[1,0,0],[0,1,0],[1,0,0],\
         [0,0,1],[0,1,0],[1,1,0],[0,1,1],[0,1,0]])
     )