本文整理汇总了Python中cogent.LoadTree.getDistances方法的典型用法代码示例。如果您正苦于以下问题:Python LoadTree.getDistances方法的具体用法?Python LoadTree.getDistances怎么用?Python LoadTree.getDistances使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cogent.LoadTree
的用法示例。
在下文中一共展示了LoadTree.getDistances方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _test_tree
# 需要导入模块: from cogent import LoadTree [as 别名]
# 或者: from cogent.LoadTree import getDistances [as 别名]
def _test_tree(self, method, treestring):
t = LoadTree(treestring=treestring)
t_distances = t.getDistances()
reconstructed = method(t_distances)
distances = reconstructed.getDistances()
for key in t_distances:
self.assertAlmostEqual(t_distances[key], distances[key])
示例2: processTree
# 需要导入模块: from cogent import LoadTree [as 别名]
# 或者: from cogent.LoadTree import getDistances [as 别名]
def processTree(fstr):
# Attempt to load input as tree
host_tree = LoadTree(treestring=fstr)
host_dist = cogent_dist_to_qiime_dist(host_tree.getDistances())
return host_tree, host_dist
示例3: TreeReconstructionTests
# 需要导入模块: from cogent import LoadTree [as 别名]
# 或者: from cogent.LoadTree import getDistances [as 别名]
class TreeReconstructionTests(unittest.TestCase):
def setUp(self):
self.tree = LoadTree(treestring='((a:3,b:4):2,(c:6,d:7):30,e:5)')
self.dists = self.tree.getDistances()
def assertTreeDistancesEqual(self, t1, t2):
d1 = t1.getDistances()
d2 = t2.getDistances()
self.assertEqual(len(d1), len(d2))
for key in d2:
self.assertAlmostEqual(d1[key], d2[key])
def test_nj(self):
"""testing nj"""
reconstructed = nj(self.dists)
self.assertTreeDistancesEqual(self.tree, reconstructed)
def test_gnj(self):
"""testing gnj"""
results = gnj(self.dists, keep=1)
(length, reconstructed) = results[0]
self.assertTreeDistancesEqual(self.tree, reconstructed)
results = gnj(self.dists, keep=10)
(length, reconstructed) = results[0]
self.assertTreeDistancesEqual(self.tree, reconstructed)
# Results should be a TreeCollection
len(results)
results.getConsensusTree()
# From GNJ paper. Pearson, Robins, Zhang 1999.
tied_dists = {
('a', 'b'):3, ('a', 'c'):3, ('a', 'd'):4, ('a', 'e'):3,
('b', 'c'):3, ('b', 'd'):3, ('b', 'e'):4,
('c', 'd'):3, ('c', 'e'):3,
('d', 'e'):3}
results = gnj(tied_dists, keep=3)
scores = [score for (score, tree) in results]
self.assertEqual(scores[:2], [7.75, 7.75])
self.assertNotEqual(scores[2], 7.75)
def test_wls(self):
"""testing wls"""
reconstructed = wls(self.dists)
self.assertTreeDistancesEqual(self.tree, reconstructed)
def test_truncated_wls(self):
"""testing wls with order option"""
order = ['e', 'b', 'c', 'd']
reconstructed = wls(self.dists, order=order)
self.assertEqual(set(reconstructed.getTipNames()), set(order))
def test_limited_wls(self):
"""testing (well, exercising at least), wls with constrained start"""
init = LoadTree(treestring='((a,c),b,d)')
reconstructed = wls(self.dists, start=init)
self.assertEqual(len(reconstructed.getTipNames()), 5)
init2 = LoadTree(treestring='((a,d),b,c)')
reconstructed = wls(self.dists, start=[init, init2])
self.assertEqual(len(reconstructed.getTipNames()), 5)
init3 = LoadTree(treestring='((a,d),b,e)')
self.assertRaises(Exception, wls, self.dists, start=[init, init3])
# if start tree has all seq names, should raise an error
self.assertRaises(Exception, wls, self.dists,
start=[LoadTree(treestring='((a,c),b,(d,e))')])