本文整理汇总了Python中cogent.core.profile.Profile.copy方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.copy方法的具体用法?Python Profile.copy怎么用?Python Profile.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cogent.core.profile.Profile
的用法示例。
在下文中一共展示了Profile.copy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_copy
# 需要导入模块: from cogent.core.profile import Profile [as 别名]
# 或者: from cogent.core.profile.Profile import copy [as 别名]
def test_copy(self):
"""copy: should act as expected while rebinding/modifying attributes
"""
p = Profile(array([[1, 1], [0.7, 0.3]]), {"A": "A", "G": "G", "R": "AG"}, "AG")
p_copy = p.copy()
assert p.Data is p_copy.Data
assert p.Alphabet is p_copy.Alphabet
assert p.CharOrder is p_copy.CharOrder
# modifying p.Data modifies p_copy.Data
p.Data[1, 1] = 100
assert p.Alphabet is p_copy.Alphabet
# normalizing p.Data rebinds it, so p_copy.Data is unchanged
p.normalizePositions()
assert not p.Data is p_copy.Data
# Adding something to the alphabet changes both p and p_copy
p.Alphabet["Y"] = "TC"
assert p.Alphabet is p_copy.Alphabet
# Rebinding the CharOrder does only change the original
p.CharOrder = "XX"
assert not p.CharOrder is p_copy.CharOrder
示例2: test_copy
# 需要导入模块: from cogent.core.profile import Profile [as 别名]
# 或者: from cogent.core.profile.Profile import copy [as 别名]
def test_copy(self):
"""copy: should act as expected while rebinding/modifying attributes
"""
p = Profile(array([[1,1],[.7,.3]]),{'A':'A','G':'G','R':'AG'},"AG")
p_copy = p.copy()
assert p.Data is p_copy.Data
assert p.Alphabet is p_copy.Alphabet
assert p.CharOrder is p_copy.CharOrder
#modifying p.Data modifies p_copy.Data
p.Data[1,1] = 100
assert p.Alphabet is p_copy.Alphabet
#normalizing p.Data rebinds it, so p_copy.Data is unchanged
p.normalizePositions()
assert not p.Data is p_copy.Data
#Adding something to the alphabet changes both p and p_copy
p.Alphabet['Y']='TC'
assert p.Alphabet is p_copy.Alphabet
#Rebinding the CharOrder does only change the original
p.CharOrder='XX'
assert not p.CharOrder is p_copy.CharOrder
示例3: ProfileTests
# 需要导入模块: from cogent.core.profile import Profile [as 别名]
# 或者: from cogent.core.profile.Profile import copy [as 别名]
class ProfileTests(TestCase):
"""Tests for Profile object"""
def setUp(self):
"""setUp method for all Profile tests"""
self.full = Profile(array([[2, 4], [3, 5], [4, 8]]), "AB")
self.empty = Profile(array([[]]), "AB")
self.empty_row = Profile(array([[1, 1], [0, 0]]), "AB")
self.empty_col = Profile(array([[0, 1], [0, 1]]), "AB")
self.consensus = Profile(
array([[0.2, 0, 0.8, 0], [0, 0.1, 0.2, 0.7], [0, 0, 0, 1], [0.2, 0.3, 0.4, 0.1], [0.5, 0.5, 0, 0]]),
Alphabet=DNA,
CharOrder="TCAG",
)
self.not_same_value = Profile(
array([[0.3, 0.5, 0.1, 0.1], [0.4, 0.6, 0, 0.7], [0.3, 0.2, 0, 0], [0, 0, 4, 0]]),
Alphabet=DNA,
CharOrder="TCAG",
)
self.zero_entry = Profile(array([[0.3, 0.2, 0, 0.5], [0, 0, 0.8, 0.2]]), Alphabet="UCAG")
self.score1 = Profile(Data=array([[-1, 0, 1, 2], [-2, 2, 0, 0], [-3, 5, 1, 0]]), Alphabet=DNA, CharOrder="ATGC")
self.score2 = Profile(array([[0.2, 0.4, 0.4, 0], [0.1, 0, 0.9, 0], [0.1, 0.2, 0.3, 0.4]]), Alphabet="TCAG")
self.oned = Profile(array([0.25, 0.25, 0.25, 0.25]), "ABCD")
self.pp = Profile(array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]), "ABCD")
def test_init(self):
"""__init__: should set all attributed correctly"""
self.assertRaises(TypeError, Profile)
self.assertRaises(TypeError, Profile, array([[2, 3]]))
# only alphabet
p = Profile(array([[0.2, 0.8], [0.7, 0.3]]), "AB")
self.assertEqual(p.Data, [[0.2, 0.8], [0.7, 0.3]])
self.assertEqual(p.Alphabet, "AB")
self.assertEqual(p.CharOrder, list("AB"))
self.assertEqual(translate("ABBA", p._translation_table), "\x00\x01\x01\x00")
# alphabet and char order
p = Profile(array([[0.1, 0.2], [0.4, 0.3]]), Alphabet=DNA, CharOrder="AG")
self.assertEqual(p.CharOrder, "AG")
assert p.Alphabet is DNA
# non-character alphabet
p = Profile(array([[0.1, 0.2], [0.4, 0.3]]), Alphabet=[7, 3], CharOrder=[3, 7])
self.assertEqual(p.CharOrder, [3, 7])
self.assertEqual(p.Alphabet, [7, 3])
self.assertEqual(p.Data, [[0.1, 0.2], [0.4, 0.3]])
def test_str(self):
"""__str__: should return string representation of data in profile
"""
self.assertEqual(str(self.empty_row), str(array([[1, 1], [0, 0]])))
def test_make_translation_table(self):
"""_make_translation_table: should return correct table from char order
"""
p = Profile(array([[0.2, 0.8], [0.7, 0.3]]), "ABCDE", "AB")
self.assertEqual(translate("ABBA", p._translation_table), "\x00\x01\x01\x00")
def test_hasValidData(self):
"""hasValidData: should work on full and empty profiles"""
full = self.full.copy()
full.normalizePositions()
self.assertEqual(full.hasValidData(), True)
self.assertEqual(self.empty_row.hasValidData(), False)
self.assertEqual(self.empty.hasValidData(), False)
def test_hasValidAttributes(self):
"""hasValidAttributes: should work for different alphabets/char orders
"""
p = Profile(array([[1, 2], [3, 4]]), Alphabet="ABCD", CharOrder="BAC")
# self.Data doesn't match len(CharOrder)
self.assertEqual(p.hasValidAttributes(), False)
p = Profile(array([[1, 2], [3, 4]]), Alphabet="ABCD", CharOrder="AX")
# not all chars in CharOrder in Alphabet
self.assertEqual(p.hasValidAttributes(), False)
p = Profile(array([[1, 2], [3, 4]]), Alphabet="ABCD", CharOrder="CB")
# should be fine
self.assertEqual(p.hasValidAttributes(), True)
def test_isValid(self):
"""isValid: should work as expected"""
# everything valid
p1 = Profile(array([[0.3, 0.7], [0.8, 0.2]]), Alphabet="AB", CharOrder="AB")
# invalid data, valid attributes
p2 = Profile(array([[1, 2], [3, 4]]), Alphabet="ABCD", CharOrder="BA")
# invalid attributes, valid data
p3 = Profile(array([[0.3, 0.7], [0.8, 0.2]]), Alphabet="ABCD", CharOrder="AF")
self.assertEqual(p1.isValid(), True)
self.assertEqual(p2.isValid(), False)
self.assertEqual(p3.isValid(), False)
def test_dataAt(self):
"""dataAt: should work on valid position and character"""
p = Profile(array([[0.2, 0.4, 0.4, 0], [0.1, 0, 0.9, 0], [0.1, 0.2, 0.3, 0.4]]), Alphabet="TCAG")
self.assertEqual(p.dataAt(0, "C"), 0.4)
self.assertEqual(p.dataAt(1, "T"), 0.1)
self.assertRaises(ProfileError, p.dataAt, 1, "U")
self.assertRaises(ProfileError, p.dataAt, -2, "T")
self.assertRaises(ProfileError, p.dataAt, 5, "T")
def test_copy(self):
#.........这里部分代码省略.........