本文整理匯總了Python中cogent.core.usage.BaseUsage.normalize方法的典型用法代碼示例。如果您正苦於以下問題:Python BaseUsage.normalize方法的具體用法?Python BaseUsage.normalize怎麽用?Python BaseUsage.normalize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cogent.core.usage.BaseUsage
的用法示例。
在下文中一共展示了BaseUsage.normalize方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_distance
# 需要導入模塊: from cogent.core.usage import BaseUsage [as 別名]
# 或者: from cogent.core.usage.BaseUsage import normalize [as 別名]
def test_distance(self):
"""BaseUsage distance() should return dist between two BUs"""
#absolute numbers, will normalize to calculate distance
self.assertFloatEqual(BaseUsage('GC').distance(BaseUsage('AU')),1)
self.assertFloatEqual(BaseUsage('AU').distance(BaseUsage('GC')),1)
self.assertFloatEqual(BaseUsage('GCAU').distance(BaseUsage('AUAU')),.5)
#should work even against dict with 'T's
self.assertFloatEqual(BaseUsage('GCAU').distance(\
BaseUsage({'A':2,'T':2,'C':0,'G':0,})),.5)
#rounding error
self.assertEqual(BaseUsage('ACG').distance(BaseUsage('CCGGAA')),0)
#normalized - as in unit simplex
ag = BaseUsage('AG')
ag.normalize()
uc = BaseUsage('UC')
uc.normalize()
self.assertFloatEqual(ag.distance(uc),1)
self.assertFloatEqual(BaseUsage({'A':0.4,'G':0.1,'C':0.4,'U':0.1})\
.distance(BaseUsage({'A':0.1,'G':0.4,'U':0.4,'C':0.1})),0.6)
self.assertFloatEqual(BaseUsage({'A':0.25,'G':0.25,'C':0.25,'U':0.25})\
.distance(BaseUsage({'A':0.25,'G':0.25,'U':0.25,'C':0.25})),0.0)
self.assertFloatEqual(BaseUsage({'A':0.245,'G':0.255,'C':0.245,\
'U':0.255}).distance(BaseUsage({'A':0.255,'G':0.245,'U':0.245,\
'C':0.255})),0.02)
self.assertFloatEqual(BaseUsage({'A':0.245,'G':0.255,'C':0.245,\
'U':0.255}).distance(BaseUsage({'A':0.25,'G':0.25,'U':0.25,\
'C':0.25})),0.01)
self.assertFloatEqual(BaseUsage({'A':0.248,'G':0.252,'C':0.248,\
'U':0.252}).distance(BaseUsage({'A':0.25,'G':0.25,'U':0.25,\
'C':0.25})),0.004)
示例2: test_normalize
# 需要導入模塊: from cogent.core.usage import BaseUsage [as 別名]
# 或者: from cogent.core.usage.BaseUsage import normalize [as 別名]
def test_normalize(self):
"""BaseUsage normalize should work when empty"""
b = BaseUsage()
b.normalize()
self.assertEqual(b, {'U':0,'C':0,'A':0,'G':0})
b = BaseUsage('AACG')
b.normalize()
self.assertEqual(b, {'U':0, 'C':0.25, 'A':0.5, 'G':0.25})
示例3: test_setitem
# 需要導入模塊: from cogent.core.usage import BaseUsage [as 別名]
# 或者: from cogent.core.usage.BaseUsage import normalize [as 別名]
def test_setitem(self):
"""BaseUsage should map keys on setitem"""
b = BaseUsage()
b['t'] = 3
b['G'] = 3
b.normalize()
i = b.items()
i.sort()
self.assertEqual(i, [('A',0.0),('C',0.0),('G',0.5),('U',0.5)])
示例4: test_getitem
# 需要導入模塊: from cogent.core.usage import BaseUsage [as 別名]
# 或者: from cogent.core.usage.BaseUsage import normalize [as 別名]
def test_getitem(self):
"""BaseUsage should map key on getitem"""
b = BaseUsage({'a':3, 'T':2, 'X':1})
self.assertEqual(b['X'], 1)
self.assertEqual(b['A'], 3)
self.assertEqual(b['U'], 2)
self.assertEqual(b['a'], 3)
self.assertEqual(b['t'], 2)
b.normalize()
assert 'X' not in b
self.assertFloatEqual(b['A'], 0.6)
self.assertFloatEqual(b['u'], 0.4)
示例5: test_init_data
# 需要導入模塊: from cogent.core.usage import BaseUsage [as 別名]
# 或者: from cogent.core.usage.BaseUsage import normalize [as 別名]
def test_init_data(self):
"""BaseUsage should init with arbitrary data"""
b = BaseUsage('UUUUUGGGCA')
self.assertEqual(b, {'U':5, 'G':3, 'C':1, 'A':1})
b.normalize()
self.assertEqual(b, {'U':0.5, 'G':0.3, 'C':0.1, 'A':0.1})