本文整理汇总了Python中skbio.Alignment.position_frequencies方法的典型用法代码示例。如果您正苦于以下问题:Python Alignment.position_frequencies方法的具体用法?Python Alignment.position_frequencies怎么用?Python Alignment.position_frequencies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skbio.Alignment
的用法示例。
在下文中一共展示了Alignment.position_frequencies方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_position_frequencies_floating_point_precision
# 需要导入模块: from skbio import Alignment [as 别名]
# 或者: from skbio.Alignment import position_frequencies [as 别名]
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})])
示例2: AlignmentTests
# 需要导入模块: from skbio import Alignment [as 别名]
# 或者: from skbio.Alignment import position_frequencies [as 别名]
#.........这里部分代码省略.........
for i in range(33)]))
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})])
示例3: AlignmentTests
# 需要导入模块: from skbio import Alignment [as 别名]
# 或者: from skbio.Alignment import position_frequencies [as 别名]
#.........这里部分代码省略.........
expected = Alignment([r1, r2])
self.assertEqual(self.a2.omit_gap_positions(0.0), expected)
self.assertEqual(self.empty.omit_gap_positions(0.0), self.empty)
self.assertEqual(self.empty.omit_gap_positions(0.49), self.empty)
self.assertEqual(self.empty.omit_gap_positions(1.0), self.empty)
def test_omit_gap_sequences(self):
"""omitting gap sequences functions as expected
"""
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)
def test_position_counters(self):
"""position_counters functions as expected
"""
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)
self.assertEqual(self.empty.position_counters(), [])
def test_position_frequencies(self):
"""computing position frequencies functions as expected
"""
expected = [defaultdict(int, {'U': 0.5, 'A': 0.5}),
defaultdict(int, {'U': 0.5, 'C': 0.5}),
defaultdict(int, {'A': 0.5, 'G': 0.5}),
defaultdict(int, {'U': 1.0}),
defaultdict(int, {'-': 0.5, 'U': 0.5})]
self.assertEqual(self.a2.position_frequencies(), expected)
self.assertEqual(self.empty.position_frequencies(), [])
def test_position_entropies(self):
"""computing positional uncertainties functions as expected
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_k_word_frequencies(self):
"""k_word_frequencies functions as expected
"""
expected = [defaultdict(int, {'U': 3 / 5, 'A': 1 / 5, '-': 1 / 5}),