本文整理汇总了Python中skbio.Alignment.kmer_frequencies方法的典型用法代码示例。如果您正苦于以下问题:Python Alignment.kmer_frequencies方法的具体用法?Python Alignment.kmer_frequencies怎么用?Python Alignment.kmer_frequencies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skbio.Alignment
的用法示例。
在下文中一共展示了Alignment.kmer_frequencies方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AlignmentTests
# 需要导入模块: from skbio import Alignment [as 别名]
# 或者: from skbio.Alignment import kmer_frequencies [as 别名]
#.........这里部分代码省略.........
def test_omit_gap_sequences(self):
expected = self.a2
self.assertEqual(self.a2.omit_gap_sequences(1.0), expected)
self.assertEqual(self.a2.omit_gap_sequences(0.20), expected)
expected = Alignment([self.r2])
self.assertEqual(self.a2.omit_gap_sequences(0.19), expected)
self.assertEqual(self.empty.omit_gap_sequences(0.0), self.empty)
self.assertEqual(self.empty.omit_gap_sequences(0.2), self.empty)
self.assertEqual(self.empty.omit_gap_sequences(1.0), self.empty)
# Test to ensure floating point precision bug isn't present. See the
# tests for Alignment.position_frequencies for more details.
aln = Alignment([DNA('.' * 33, metadata={'id': 'abc'}),
DNA('-' * 33, metadata={'id': 'def'})])
self.assertEqual(aln.omit_gap_sequences(1 - np.finfo(float).eps),
Alignment([]))
def test_position_counters(self):
self.assertEqual(self.empty.position_counters(), [])
self.assertEqual(self.no_positions.position_counters(), [])
expected = [Counter({'U': 1, 'A': 1}),
Counter({'U': 1, 'C': 1}),
Counter({'A': 1, 'G': 1}),
Counter({'U': 2}),
Counter({'-': 1, 'U': 1})]
self.assertEqual(self.a2.position_counters(), expected)
def test_position_frequencies(self):
self.assertEqual(self.empty.position_frequencies(), [])
self.assertEqual(self.no_positions.position_frequencies(), [])
expected = [defaultdict(float, {'U': 0.5, 'A': 0.5}),
defaultdict(float, {'U': 0.5, 'C': 0.5}),
defaultdict(float, {'A': 0.5, 'G': 0.5}),
defaultdict(float, {'U': 1.0}),
defaultdict(float, {'-': 0.5, 'U': 0.5})]
self.assertEqual(self.a2.position_frequencies(), expected)
def test_position_frequencies_floating_point_precision(self):
# Test that a position with no variation yields a frequency of exactly
# 1.0. Note that it is important to use self.assertEqual here instead
# of self.assertAlmostEqual because we want to test for exactly 1.0. A
# previous implementation of Alignment.position_frequencies added
# (1 / sequence_count) for each occurrence of a character in a position
# to compute the frequencies (see
# https://github.com/biocore/scikit-bio/issues/801). In certain cases,
# this yielded a frequency slightly less than 1.0 due to roundoff
# error. The test case here uses an alignment of 10 sequences with no
# variation at a position. This test case exposes the roundoff error
# present in the previous implementation because 1/10 added 10 times
# yields a number slightly less than 1.0. This occurs because 1/10
# cannot be represented exactly as a floating point number.
seqs = []
for i in range(10):
seqs.append(DNA('A', metadata={'id': str(i)}))
aln = Alignment(seqs)
self.assertEqual(aln.position_frequencies(),
[defaultdict(float, {'A': 1.0})])
def test_position_entropies(self):
# tested by calculating values as described in this post:
# http://stackoverflow.com/a/15476958/3424666
expected = [0.69314, 0.69314, 0.69314, 0.0, np.nan]
np.testing.assert_almost_equal(self.a2.position_entropies(),
expected, 5)
expected = [1.0, 1.0, 1.0, 0.0, np.nan]
np.testing.assert_almost_equal(self.a2.position_entropies(base=2),
expected, 5)
np.testing.assert_almost_equal(self.empty.position_entropies(base=2),
[])
def test_kmer_frequencies(self):
expected = [defaultdict(float, {'U': 3 / 5, 'A': 1 / 5, '-': 1 / 5}),
defaultdict(float, {'A': 1 / 5, 'C': 1 / 5, 'G': 1 / 5,
'U': 2 / 5})]
actual = self.a2.kmer_frequencies(k=1, relative=True)
for a, e in zip(actual, expected):
self.assertEqual(sorted(a), sorted(e), 5)
np.testing.assert_almost_equal(sorted(a.values()),
sorted(e.values()), 5)
def test_sequence_length(self):
self.assertEqual(self.a1.sequence_length(), 13)
self.assertEqual(self.a2.sequence_length(), 5)
self.assertEqual(self.empty.sequence_length(), 0)
def test_validate_lengths(self):
self.assertTrue(self.a1._validate_lengths())
self.assertTrue(self.a2._validate_lengths())
self.assertTrue(self.empty._validate_lengths())
self.assertTrue(Alignment([
DNA('TTT', metadata={'id': "d1"})])._validate_lengths())