本文整理汇总了Python中cogent.parse.tree.DndParser.leafLcaDepths方法的典型用法代码示例。如果您正苦于以下问题:Python DndParser.leafLcaDepths方法的具体用法?Python DndParser.leafLcaDepths怎么用?Python DndParser.leafLcaDepths使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cogent.parse.tree.DndParser
的用法示例。
在下文中一共展示了DndParser.leafLcaDepths方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: analysisTests
# 需要导入模块: from cogent.parse.tree import DndParser [as 别名]
# 或者: from cogent.parse.tree.DndParser import leafLcaDepths [as 别名]
class analysisTests(TestCase):
"""Tests of top-level functions."""
def setUp(self):
"""Make a couple of standard trees"""
self.t1 = DndParser('((a,(b,c)),(d,e))', RangeNode)
#selt.t1 indices: ((0,(1,2)5)6,(3,4)7)8
def test_threeway_counts(self):
"""threeway_counts should produce correct count matrix"""
self.t1.makeIdIndex()
ind = self.t1.IdIndex
ind[0].Sequence = array([0,0,0])
ind[1].Sequence = array([0,1,0])
ind[2].Sequence = array([1,0,1])
ind[3].Sequence = array([1,1,0])
ind[4].Sequence = array([1,1,1])
depths = self.t1.leafLcaDepths()
result = tree_threeway_counts(self.t1, depths, ABPairs)
#check we got the right number of comparisons
self.assertEqual(len(result), 20)
#check we got the right keys
for k in [(1,2,0),(2,1,0),(0,1,3),(1,0,3),(0,1,4),(1,0,4),(0,2,3),\
(2,0,3),(0,2,4),(2,0,4),(1,2,3),(2,1,3),(1,2,4),(2,1,4),(3,4,1),\
(4,3,1),(3,4,2),(4,3,2)]:
assert k in result
#spot-check a few results
self.assertEqual(result[(1,2,0)]._data, array([[2,1],[0,0]]))
self.assertEqual(result[(2,1,0)]._data, array([[1,2],[0,0]]))
self.assertEqual(result[(2,1,3)]._data, array([[0,1],[1,1]]))
def test_twoway_counts(self):
"""twoway_counts should produce correct count matrix"""
self.t1.makeIdIndex()
ind = self.t1.IdIndex
ind[0].Sequence = array([0,0,0])
ind[1].Sequence = array([0,1,0])
ind[2].Sequence = array([1,0,1])
ind[3].Sequence = array([1,1,0])
ind[4].Sequence = array([1,1,1])
depths = self.t1.leafLcaDepths()
#check that it works with averaging
result = tree_twoway_counts(self.t1, ABPairs)
#check we got the right number of comparisons: average by default
self.assertEqual(len(result), 10)
#check we got the right keys
for k in [(0,1),(0,2),(0,3),(0,4),(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)]:
assert k in result
#spot-check a few results
self.assertEqual(result[(0,1)]._data, array([[2,.5],[.5,0]]))
self.assertEqual(result[(2,3)]._data, array([[0,1],[1,1]]))
#check that it works when we don't average
result = tree_twoway_counts(self.t1, ABPairs, average=False)
self.assertEqual(len(result), 20)
#check we got the right keys
for k in [(0,1),(0,2),(0,3),(0,4),(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)]:
assert k in result
#reverse should be in result too
assert (k[1],k[0]) in result
#spot-check values
self.assertEqual(result[(0,1)]._data, array([[2,1],[0,0]]))
self.assertEqual(result[(1,0)]._data, array([[2,0],[1,0]]))
def test_counts_to_probs(self):
"""counts_to_probs should skip cases with zero rows"""
counts = {
(0,1): Counts(array([[0,1],[1,0]]), ABPairs),
(1,2): Counts(array([[0,0],[1,0]]), ABPairs), #bad row
(0,3): Counts(array([[0,0],[0,0]]), ABPairs), #bad row
(0,4): Counts(array([[0.0,0.0],[0.0,0.0]]), ABPairs), #bad row
(0,5): Counts(array([[0.1,0.3],[0.0,0.0]]), ABPairs), #bad row
(3,4): Counts(array([[0.1,0.3],[0.4,0.1]]), ABPairs),
(2,1): Counts(array([[0,5],[1,0]]), ABPairs),
}
result = counts_to_probs(counts)
self.assertEqual(len(result), 3)
self.assertFloatEqual(result[(0,1)]._data, array([[0,1],[1,0]]))
self.assertFloatEqual(result[(3,4)]._data, \
array([[0.25,0.75],[0.8,0.2]]))
self.assertFloatEqual(result[(2,1)]._data, array([[0,1],[1,0]]))
def test_probs_to_rates(self):
"""probs_to_rates converts probs to rates, omitting problem cases"""
probs = dict([(i, Probs.random(DnaPairs)) for i in range(100)])
rates = probs_to_rates(probs)
#check we got at most the same number of items as in probs
assert len(rates) <= len(probs)
#check that we didn't get anything bad
vals = rates.values()
for v in vals:
assert not v.isSignificantlyComplex()
#check that we didn't miss anything good
for key, val in probs.items():
if key not in rates:
try:
r = val.toRates()
print r.isValid()
assert r.isSignificantlyComplex() or (not r.isValid())
except (ZeroDivisionError, OverflowError, ValueError):
pass
#.........这里部分代码省略.........