예제 #1
0
 def test_nj_dm1(self):
     self.assertEqual(nj(self.dm1, result_constructor=str),
                      self.expected1_str)
     # what is the correct way to compare TreeNode objects for equality?
     actual_TreeNode = nj(self.dm1)
     self.assertEqual(actual_TreeNode.compare_tip_distances(
         self.expected1_TreeNode), 0.0)
예제 #2
0
 def test_nj_dm1(self):
     self.assertEqual(nj(self.dm1, result_constructor=str),
                      self.expected1_str)
     # what is the correct way to compare TreeNode objects for equality?
     actual_TreeNode = nj(self.dm1)
     self.assertEqual(actual_TreeNode.compare_tip_distances(
         self.expected1_TreeNode), 0.0)
예제 #3
0
 def test_nj_zero_branch_length(self):
     # no nodes have negative branch length when we disallow negative
     # branch length. self is excluded as branch length is None
     tree = nj(self.dm4)
     for n in tree.postorder(include_self=False):
         self.assertTrue(n.length >= 0)
     # only tips associated with the large distance in the input
     # have positive branch lengths when we allow negative branch
     # length
     tree = nj(self.dm4, False)
     self.assertTrue(tree.find('a').length > 0)
     self.assertTrue(tree.find('b').length < 0)
     self.assertTrue(tree.find('c').length < 0)
     self.assertTrue(tree.find('d').length < 0)
     self.assertTrue(tree.find('e').length > 0)
예제 #4
0
 def test_nj_zero_branch_length(self):
     # no nodes have negative branch length when we disallow negative
     # branch length. self is excluded as branch length is None
     tree = nj(self.dm4)
     for n in tree.postorder(include_self=False):
         self.assertTrue(n.length >= 0)
     # only tips associated with the large distance in the input
     # have positive branch lengths when we allow negative branch
     # length
     tree = nj(self.dm4, False)
     self.assertTrue(tree.find('a').length > 0)
     self.assertTrue(tree.find('b').length < 0)
     self.assertTrue(tree.find('c').length < 0)
     self.assertTrue(tree.find('d').length < 0)
     self.assertTrue(tree.find('e').length > 0)
예제 #5
0
 def test_nj_trivial(self):
     data = [[0, 3, 2],
             [3, 0, 3],
             [2, 3, 0]]
     dm = DistanceMatrix(data, list('abc'))
     expected_str = "(b:2.000000, a:1.000000, c:1.000000);"
     self.assertEqual(nj(dm, result_constructor=str), expected_str)
예제 #6
0
 def test_nj_trivial(self):
     data = [[0, 3, 2],
             [3, 0, 3],
             [2, 3, 0]]
     dm = DistanceMatrix(data, list('abc'))
     expected_str = "(b:2.000000, a:1.000000, c:1.000000);"
     self.assertEqual(nj(dm, result_constructor=str), expected_str)
예제 #7
0
def get_nj_tree_newick(pairwise_differences, samples):
    pairwise_differences = copy.deepcopy(pairwise_differences)
    np.fill_diagonal(pairwise_differences, 0)

    distance_matrix = skbio.DistanceMatrix(pairwise_differences, ids=samples)
    # This computes a neighbour-joining tree and outputs a newick string
    nj_newick = skbio.nj(distance_matrix, result_constructor=str)
    return nj_newick
예제 #8
0
def create_tree_of_trees(trees: dict, out, metric='score', outgroup=''):
    output_dir, output_filename = parse_path(out)
    names = sorted(trees.keys())
    n = len(names)
    m = np.zeros((n, n))
    for i, ref in enumerate(names[:-1]):
        targets = [trees[names[j]] for j in range(i + 1, n)]
        dists = get_dist_trees(trees[ref], targets, metric)
        m[i + 1:n, i] = dists
    m += m.T
    dist_m = DistanceMatrix(m, names)
    tree = ete3.Tree(nj(dist_m, result_constructor=str))
    if outgroup is not None:
        outgroup_tree(tree)
    if out:
        tree.write(outfile=out)
    return tree
예제 #9
0
 def test_nj_dm3(self):
     actual_TreeNode = nj(self.dm3)
     self.assertAlmostEqual(actual_TreeNode.compare_tip_distances(
         self.expected3_TreeNode), 0.0)
예제 #10
0
 def test_nj_dm3(self):
     actual_TreeNode = nj(self.dm3)
     self.assertAlmostEqual(
         actual_TreeNode.compare_tip_distances(self.expected3_TreeNode),
         0.0)