本文整理汇总了Python中skbio.SequenceCollection.kmer_frequencies方法的典型用法代码示例。如果您正苦于以下问题:Python SequenceCollection.kmer_frequencies方法的具体用法?Python SequenceCollection.kmer_frequencies怎么用?Python SequenceCollection.kmer_frequencies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skbio.SequenceCollection
的用法示例。
在下文中一共展示了SequenceCollection.kmer_frequencies方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_kmer_frequencies
# 需要导入模块: from skbio import SequenceCollection [as 别名]
# 或者: from skbio.SequenceCollection import kmer_frequencies [as 别名]
def test_kmer_frequencies(self):
expected1 = Counter({'GAT': 1, 'TAC': 1})
expected2 = Counter({'TTG': 1})
self.assertEqual(
self.s1.kmer_frequencies(k=3, overlap=False, relative=False),
[expected1, expected2])
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.kmer_frequencies(k=1, relative=True),
[expected1, expected2])
expected1 = defaultdict(float)
expected1['GAT'] = 1 / 2.
expected1['TAC'] = 1 / 2.
expected2 = defaultdict(float)
expected2['TTG'] = 1 / 1.
self.assertEqual(
self.s1.kmer_frequencies(k=3, overlap=False, relative=True),
[expected1, expected2])
self.assertEqual(self.empty.kmer_frequencies(k=1, relative=True), [])
# Test to ensure floating point precision bug isn't present. See the
# tests for Sequence.kmer_frequencies for more details.
sc = SequenceCollection([RNA('C' * 10, metadata={'id': 's1'}),
RNA('G' * 10, metadata={'id': 's2'})])
self.assertEqual(sc.kmer_frequencies(1, relative=True),
[defaultdict(float, {'C': 1.0}),
defaultdict(float, {'G': 1.0})])
示例2: SequenceCollectionTests
# 需要导入模块: from skbio import SequenceCollection [as 别名]
# 或者: from skbio.SequenceCollection import kmer_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_kmer_frequencies(self):
expected1 = Counter({'GAT': 1, 'TAC': 1})
expected2 = Counter({'TTG': 1})
self.assertEqual(
self.s1.kmer_frequencies(k=3, overlap=False, relative=False),
[expected1, expected2])
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.kmer_frequencies(k=1, relative=True),
[expected1, expected2])
expected1 = defaultdict(float)
expected1['GAT'] = 1 / 2.
expected1['TAC'] = 1 / 2.
expected2 = defaultdict(float)
expected2['TTG'] = 1 / 1.
self.assertEqual(
self.s1.kmer_frequencies(k=3, overlap=False, relative=True),
[expected1, expected2])
self.assertEqual(self.empty.kmer_frequencies(k=1, relative=True), [])
# Test to ensure floating point precision bug isn't present. See the
# tests for Sequence.kmer_frequencies for more details.
sc = SequenceCollection([RNA('C' * 10, metadata={'id': 's1'}),
RNA('G' * 10, metadata={'id': 's2'})])