本文整理汇总了Python中skbio.Alignment._validate_lengths方法的典型用法代码示例。如果您正苦于以下问题:Python Alignment._validate_lengths方法的具体用法?Python Alignment._validate_lengths怎么用?Python Alignment._validate_lengths使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skbio.Alignment
的用法示例。
在下文中一共展示了Alignment._validate_lengths方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AlignmentTests
# 需要导入模块: from skbio import Alignment [as 别名]
# 或者: from skbio.Alignment import _validate_lengths [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())
示例2: AlignmentTests
# 需要导入模块: from skbio import Alignment [as 别名]
# 或者: from skbio.Alignment import _validate_lengths [as 别名]
#.........这里部分代码省略.........
"""
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}),
defaultdict(int, {'A': 1 / 5, 'C': 1 / 5, 'G': 1 / 5,
'U': 2 / 5})]
actual = self.a2.k_word_frequencies(k=1)
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):
"""sequence_length functions as expected
"""
self.assertEqual(self.a1.sequence_length(), 13)
self.assertEqual(self.a2.sequence_length(), 5)
self.assertEqual(self.empty.sequence_length(), 0)
def test_to_phylip(self):
"""to_phylip functions as expected
"""
d1 = DNASequence('..ACC-GTTGG..', id="d1")
d2 = DNASequence('TTACCGGT-GGCC', id="d2")
d3 = DNASequence('.-ACC-GTTGC--', id="d3")
a = Alignment([d1, d2, d3])
phylip_str, id_map = a.to_phylip(map_labels=False)
self.assertEqual(id_map, {'d1': 'd1',
'd3': 'd3',
'd2': 'd2'})
expected = "\n".join(["3 13",
"d1 ..ACC-GTTGG..",
"d2 TTACCGGT-GGCC",
"d3 .-ACC-GTTGC--"])
self.assertEqual(phylip_str, expected)
def test_to_phylip_map_labels(self):
"""to_phylip functions as expected with label mapping
"""
d1 = DNASequence('..ACC-GTTGG..', id="d1")
d2 = DNASequence('TTACCGGT-GGCC', id="d2")
d3 = DNASequence('.-ACC-GTTGC--', id="d3")
a = Alignment([d1, d2, d3])
phylip_str, id_map = a.to_phylip(map_labels=True, label_prefix="s")
self.assertEqual(id_map, {'s1': 'd1',
's3': 'd3',
's2': 'd2'})
expected = "\n".join(["3 13",
"s1 ..ACC-GTTGG..",
"s2 TTACCGGT-GGCC",
"s3 .-ACC-GTTGC--"])
self.assertEqual(phylip_str, expected)
def test_to_phylip_unequal_sequence_lengths(self):
d1 = DNASequence('A-CT', id="d1")
d2 = DNASequence('TTA', id="d2")
d3 = DNASequence('.-AC', id="d3")
a = Alignment([d1, d2, d3])
with self.assertRaises(SequenceCollectionError):
a.to_phylip()
def test_to_phylip_no_sequences(self):
with self.assertRaises(SequenceCollectionError):
Alignment([]).to_phylip()
def test_to_phylip_no_positions(self):
d1 = DNASequence('', id="d1")
d2 = DNASequence('', id="d2")
a = Alignment([d1, d2])
with self.assertRaises(SequenceCollectionError):
a.to_phylip()
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([
DNASequence('TTT', id="d1")])._validate_lengths())
self.assertFalse(Alignment([
DNASequence('TTT', id="d1"),
DNASequence('TT', id="d2")])._validate_lengths())