本文整理匯總了Python中skbio.SequenceCollection.k_word_frequencies方法的典型用法代碼示例。如果您正苦於以下問題:Python SequenceCollection.k_word_frequencies方法的具體用法?Python SequenceCollection.k_word_frequencies怎麽用?Python SequenceCollection.k_word_frequencies使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類skbio.SequenceCollection
的用法示例。
在下文中一共展示了SequenceCollection.k_word_frequencies方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_k_word_frequencies
# 需要導入模塊: from skbio import SequenceCollection [as 別名]
# 或者: from skbio.SequenceCollection import k_word_frequencies [as 別名]
def test_k_word_frequencies(self):
expected1 = defaultdict(float)
expected1['A'] = 3 / 7.
expected1['C'] = 1 / 7.
expected1['G'] = 1 / 7.
expected1['T'] = 2 / 7.
expected2 = defaultdict(float)
expected2['G'] = 1 / 3.
expected2['T'] = 2 / 3.
self.assertEqual(self.s1.k_word_frequencies(k=1),
[expected1, expected2])
expected1 = defaultdict(float)
expected1['GAT'] = 1 / 2.
expected1['TAC'] = 1 / 2.
expected2 = defaultdict(float)
expected2['TTG'] = 1 / 1.
self.assertEqual(self.s1.k_word_frequencies(k=3, overlapping=False),
[expected1, expected2])
self.assertEqual(self.empty.k_word_frequencies(k=1), [])
# Test to ensure floating point precision bug isn't present. See the
# tests for BiologicalSequence.k_word_frequencies for more details.
sc = SequenceCollection([RNA('C' * 10, id='s1'),
RNA('G' * 10, id='s2')])
self.assertEqual(sc.k_word_frequencies(1),
[defaultdict(float, {'C': 1.0}),
defaultdict(float, {'G': 1.0})])
示例2: SequenceCollectionTests
# 需要導入模塊: from skbio import SequenceCollection [as 別名]
# 或者: from skbio.SequenceCollection import k_word_frequencies [as 別名]
#.........這裏部分代碼省略.........
class FakeSequenceCollection(SequenceCollection):
pass
# SequenceCollections of different types are not equal
self.assertTrue(self.s4 != FakeSequenceCollection([self.d1, self.d3]))
self.assertTrue(self.s4 != Alignment([self.d1, self.d3]))
# SequenceCollections with different sequences are not equal
self.assertTrue(self.s1 !=
SequenceCollection([self.d1, self.r1]))
def test_repr(self):
self.assertEqual(repr(self.s1),
"<SequenceCollection: n=2; "
"mean +/- std length=5.00 +/- 2.00>")
self.assertEqual(repr(self.s2),
"<SequenceCollection: n=3; "
"mean +/- std length=7.33 +/- 3.68>")
self.assertEqual(repr(self.s3),
"<SequenceCollection: n=5; "
"mean +/- std length=6.40 +/- 3.32>")
self.assertEqual(repr(self.empty),
"<SequenceCollection: n=0; "
"mean +/- std length=0.00 +/- 0.00>")
def test_reversed(self):
s1_iter = reversed(self.s1)
count = 0
for actual, expected in zip(s1_iter, self.seqs1[::-1]):
count += 1
self.assertEqual(actual, expected)
self.assertEqual(count, len(self.seqs1))
self.assertRaises(StopIteration, lambda: next(s1_iter))
def test_k_word_frequencies(self):
expected1 = defaultdict(float)
expected1['A'] = 3 / 7.
expected1['C'] = 1 / 7.
expected1['G'] = 1 / 7.
expected1['T'] = 2 / 7.
expected2 = defaultdict(float)
expected2['G'] = 1 / 3.
expected2['T'] = 2 / 3.
self.assertEqual(self.s1.k_word_frequencies(k=1),
[expected1, expected2])
expected1 = defaultdict(float)
expected1['GAT'] = 1 / 2.
expected1['TAC'] = 1 / 2.
expected2 = defaultdict(float)
expected2['TTG'] = 1 / 1.
self.assertEqual(self.s1.k_word_frequencies(k=3, overlapping=False),
[expected1, expected2])
self.assertEqual(self.empty.k_word_frequencies(k=1), [])
# Test to ensure floating point precision bug isn't present. See the
# tests for BiologicalSequence.k_word_frequencies for more details.
sc = SequenceCollection([RNA('C' * 10, id='s1'),
RNA('G' * 10, id='s2')])
self.assertEqual(sc.k_word_frequencies(1),
[defaultdict(float, {'C': 1.0}),
defaultdict(float, {'G': 1.0})])
def test_str(self):
exp1 = ">d1\nGATTACA\n>d2\nTTG\n"
self.assertEqual(str(self.s1), exp1)
示例3: SequenceCollectionTests
# 需要導入模塊: from skbio import SequenceCollection [as 別名]
# 或者: from skbio.SequenceCollection import k_word_frequencies [as 別名]
#.........這裏部分代碼省略.........
self.assertTrue(self.s1 != Alignment([self.d1, self.d2]))
# SequenceCollections with different sequences are not equal
self.assertTrue(self.s1 !=
SequenceCollection([self.d1, self.r1]))
def test_repr(self):
"""repr functions as expected
"""
self.assertEqual(repr(self.s1),
"<SequenceCollection: n=2; "
"mean +/- std length=5.00 +/- 2.00>")
self.assertEqual(repr(self.s2),
"<SequenceCollection: n=3; "
"mean +/- std length=7.33 +/- 3.68>")
self.assertEqual(repr(self.s3),
"<SequenceCollection: n=5; "
"mean +/- std length=6.40 +/- 3.32>")
self.assertEqual(repr(self.empty),
"<SequenceCollection: n=0; "
"mean +/- std length=0.00 +/- 0.00>")
def test_reversed(self):
"""reversed functions as expected
"""
s1_iter = reversed(self.s1)
count = 0
for actual, expected in zip(s1_iter, self.seqs1[::-1]):
count += 1
self.assertEqual(actual, expected)
self.assertEqual(count, len(self.seqs1))
self.assertRaises(StopIteration, lambda: next(s1_iter))
def test_k_word_frequencies(self):
"""k_word_frequencies functions as expected
"""
expected1 = defaultdict(int)
expected1['A'] = 3 / 7.
expected1['C'] = 1 / 7.
expected1['G'] = 1 / 7.
expected1['T'] = 2 / 7.
expected2 = defaultdict(int)
expected2['G'] = 1 / 3.
expected2['T'] = 2 / 3.
self.assertEqual(self.s1.k_word_frequencies(k=1),
[expected1, expected2])
expected1 = defaultdict(int)
expected1['GAT'] = 1 / 2.
expected1['TAC'] = 1 / 2.
expected2 = defaultdict(int)
expected2['TTG'] = 1 / 1.
self.assertEqual(self.s1.k_word_frequencies(k=3, overlapping=False),
[expected1, expected2])
self.assertEqual(self.empty.k_word_frequencies(k=1), [])
def test_str(self):
"""str functions as expected
"""
exp1 = ">d1\nGATTACA\n>d2\nTTG\n"
self.assertEqual(str(self.s1), exp1)
exp2 = ">r1\nGAUUACA\n>r2\nUUG\n>r3\nU-----UGCC--\n"
self.assertEqual(str(self.s2), exp2)
exp4 = ""
self.assertEqual(str(self.empty), exp4)