本文整理汇总了Python中skbio.Alignment.position_counters方法的典型用法代码示例。如果您正苦于以下问题:Python Alignment.position_counters方法的具体用法?Python Alignment.position_counters怎么用?Python Alignment.position_counters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skbio.Alignment
的用法示例。
在下文中一共展示了Alignment.position_counters方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AlignmentTests
# 需要导入模块: from skbio import Alignment [as 别名]
# 或者: from skbio.Alignment import position_counters [as 别名]
#.........这里部分代码省略.........
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)
# Test to ensure floating point precision bug isn't present. See the
# tests for Alignment.position_frequencies for more details.
seqs = []
for i in range(33):
seqs.append(DNA('-.', metadata={'id': str(i)}))
aln = Alignment(seqs)
self.assertEqual(aln.omit_gap_positions(1 - np.finfo(float).eps),
Alignment([DNA('', metadata={'id': str(i)})
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
示例2: AlignmentTests
# 需要导入模块: from skbio import Alignment [as 别名]
# 或者: from skbio.Alignment import position_counters [as 别名]
#.........这里部分代码省略.........
"""
expected = self.a2
self.assertEqual(self.a2.omit_gap_positions(1.0), expected)
self.assertEqual(self.a2.omit_gap_positions(0.51), expected)
r1 = RNASequence('UUAU', id="r1")
r2 = RNASequence('ACGU', id="r2")
expected = Alignment([r1, r2])
self.assertEqual(self.a2.omit_gap_positions(0.49), expected)
r1 = RNASequence('UUAU', id="r1")
r2 = RNASequence('ACGU', id="r2")
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)