本文整理汇总了Python中skbio.SequenceCollection.ids方法的典型用法代码示例。如果您正苦于以下问题:Python SequenceCollection.ids方法的具体用法?Python SequenceCollection.ids怎么用?Python SequenceCollection.ids使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skbio.SequenceCollection
的用法示例。
在下文中一共展示了SequenceCollection.ids方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SequenceCollectionTests
# 需要导入模块: from skbio import SequenceCollection [as 别名]
# 或者: from skbio.SequenceCollection import ids [as 别名]
#.........这里部分代码省略.........
def test_distribution_stats(self):
actual1 = self.s1.distribution_stats()
self.assertEqual(actual1[0], 2)
self.assertAlmostEqual(actual1[1], 5.0, 3)
self.assertAlmostEqual(actual1[2], 2.0, 3)
actual2 = self.s2.distribution_stats()
self.assertEqual(actual2[0], 3)
self.assertAlmostEqual(actual2[1], 7.333, 3)
self.assertAlmostEqual(actual2[2], 3.682, 3)
actual3 = self.s3.distribution_stats()
self.assertEqual(actual3[0], 5)
self.assertAlmostEqual(actual3[1], 6.400, 3)
self.assertAlmostEqual(actual3[2], 3.323, 3)
actual4 = self.empty.distribution_stats()
self.assertEqual(actual4[0], 0)
self.assertEqual(actual4[1], 0.0)
self.assertEqual(actual4[2], 0.0)
def test_degap(self):
expected = SequenceCollection([
RNASequence('GAUUACA', id="r1"),
RNASequence('UUG', id="r2"),
RNASequence('UUGCC', id="r3")])
actual = self.s2.degap()
self.assertEqual(actual, expected)
def test_get_seq(self):
self.assertEqual(self.s1.get_seq('d1'), self.d1)
self.assertEqual(self.s1.get_seq('d2'), self.d2)
def test_ids(self):
self.assertEqual(self.s1.ids(), ['d1', 'd2'])
self.assertEqual(self.s2.ids(), ['r1', 'r2', 'r3'])
self.assertEqual(self.s3.ids(),
['d1', 'd2', 'r1', 'r2', 'r3'])
self.assertEqual(self.empty.ids(), [])
def _assert_sequence_collections_equal(self, observed, expected):
"""Compare SequenceCollections strictly."""
# TODO remove this custom equality testing code when SequenceCollection
# has an equals method (part of #656). We need this method to include
# IDs in the comparison (not part of SequenceCollection.__eq__).
self.assertEqual(observed, expected)
for obs_seq, exp_seq in zip(observed, expected):
self.assertTrue(obs_seq.equals(exp_seq))
def test_update_ids_default_behavior(self):
# 3 seqs
exp_sc = SequenceCollection([
RNA('GAUUACA', id="1"),
RNA('UUG', id="2"),
RNA('U-----UGCC--', id="3")
])
exp_id_map = {'1': 'r1', '2': 'r2', '3': 'r3'}
obs_sc, obs_id_map = self.s2.update_ids()
self._assert_sequence_collections_equal(obs_sc, exp_sc)
self.assertEqual(obs_id_map, exp_id_map)
# empty
obs_sc, obs_id_map = self.empty.update_ids()
self._assert_sequence_collections_equal(obs_sc, self.empty)
self.assertEqual(obs_id_map, {})
示例2: SequenceCollectionTests
# 需要导入模块: from skbio import SequenceCollection [as 别名]
# 或者: from skbio.SequenceCollection import ids [as 别名]
#.........这里部分代码省略.........
def test_distribution_stats(self):
actual1 = self.s1.distribution_stats()
self.assertEqual(actual1[0], 2)
self.assertAlmostEqual(actual1[1], 5.0, 3)
self.assertAlmostEqual(actual1[2], 2.0, 3)
actual2 = self.s2.distribution_stats()
self.assertEqual(actual2[0], 3)
self.assertAlmostEqual(actual2[1], 7.333, 3)
self.assertAlmostEqual(actual2[2], 3.682, 3)
actual3 = self.s3.distribution_stats()
self.assertEqual(actual3[0], 5)
self.assertAlmostEqual(actual3[1], 6.400, 3)
self.assertAlmostEqual(actual3[2], 3.323, 3)
actual4 = self.empty.distribution_stats()
self.assertEqual(actual4[0], 0)
self.assertEqual(actual4[1], 0.0)
self.assertEqual(actual4[2], 0.0)
def test_degap(self):
expected = SequenceCollection([
RNA('GAUUACA', metadata={'id': "r1"}),
RNA('UUG', metadata={'id': "r2"}),
RNA('UUGCC', metadata={'id': "r3"})])
actual = self.s2.degap()
self.assertEqual(actual, expected)
def test_get_seq(self):
self.assertEqual(self.s1.get_seq('d1'), self.d1)
self.assertEqual(self.s1.get_seq('d2'), self.d2)
def test_ids(self):
self.assertEqual(self.s1.ids(), ['d1', 'd2'])
self.assertEqual(self.s2.ids(), ['r1', 'r2', 'r3'])
self.assertEqual(self.s3.ids(),
['d1', 'd2', 'r1', 'r2', 'r3'])
self.assertEqual(self.empty.ids(), [])
def test_update_ids_default_behavior(self):
# 3 seqs
exp_sc = SequenceCollection([
RNA('GAUUACA', metadata={'id': "1"}),
RNA('UUG', metadata={'id': "2"}),
RNA('U-----UGCC--', metadata={'id': "3"})
])
exp_id_map = {'1': 'r1', '2': 'r2', '3': 'r3'}
obs_sc, obs_id_map = self.s2.update_ids()
self.assertEqual(obs_sc, exp_sc)
self.assertEqual(obs_id_map, exp_id_map)
# empty
obs_sc, obs_id_map = self.empty.update_ids()
self.assertEqual(obs_sc, self.empty)
self.assertEqual(obs_id_map, {})
def test_update_ids_prefix(self):
# 3 seqs
exp_sc = SequenceCollection([
RNA('GAUUACA', metadata={'id': "abc1"}),
RNA('UUG', metadata={'id': "abc2"}),
RNA('U-----UGCC--', metadata={'id': "abc3"})
])
exp_id_map = {'abc1': 'r1', 'abc2': 'r2', 'abc3': 'r3'}
obs_sc, obs_id_map = self.s2.update_ids(prefix='abc')
示例3: SequenceCollectionTests
# 需要导入模块: from skbio import SequenceCollection [as 别名]
# 或者: from skbio.SequenceCollection import ids [as 别名]
class SequenceCollectionTests(TestCase):
"""Tests of the SequenceCollection class """
def setUp(self):
"""Initialize values to be used in tests
"""
self.d1 = DNASequence('GATTACA', id="d1")
self.d2 = DNASequence('TTG', id="d2")
self.d1_lower = DNASequence('gattaca', id="d1")
self.d2_lower = DNASequence('ttg', id="d2")
self.r1 = RNASequence('GAUUACA', id="r1")
self.r2 = RNASequence('UUG', id="r2")
self.r3 = RNASequence('U-----UGCC--', id="r3")
self.i1 = DNASequence('GATXACA', id="i1")
self.seqs1 = [self.d1, self.d2]
self.seqs1_lower = [self.d1_lower, self.d2_lower]
self.seqs2 = [self.r1, self.r2, self.r3]
self.seqs3 = self.seqs1 + self.seqs2
self.seqs1_t = [('d1', 'GATTACA'), ('d2', 'TTG')]
self.seqs2_t = [('r1', 'GAUUACA'), ('r2', 'UUG'),
('r3', 'U-----UGCC--')]
self.seqs3_t = self.seqs1_t + self.seqs2_t
self.s1 = SequenceCollection(self.seqs1)
self.s1_lower = SequenceCollection(self.seqs1_lower)
self.s2 = SequenceCollection(self.seqs2)
self.s3 = SequenceCollection(self.seqs3)
self.empty = SequenceCollection([])
self.invalid_s1 = SequenceCollection([self.i1])
def test_init(self):
"""Initialization functions as expected with varied input types
"""
SequenceCollection(self.seqs1)
SequenceCollection(self.seqs2)
SequenceCollection(self.seqs3)
SequenceCollection([])
def test_init_fail(self):
"""initialization with sequences with overlapping ids fails
"""
s1 = [self.d1, self.d1]
self.assertRaises(SequenceCollectionError, SequenceCollection, s1)
def test_init_validate(self):
"""initialization with validation functions as expected
"""
SequenceCollection(self.seqs1, validate=True)
SequenceCollection(self.seqs1, validate=True)
# can't validate self.seqs2 as a DNASequence
self.assertRaises(SequenceCollectionError, SequenceCollection,
self.invalid_s1, validate=True)
def test_from_fasta_records(self):
"""Initialization from list of tuples functions as expected
"""
SequenceCollection.from_fasta_records(self.seqs1_t, DNASequence)
SequenceCollection.from_fasta_records(self.seqs2_t, RNASequence)
SequenceCollection.from_fasta_records(self.seqs3_t, NucleotideSequence)
def test_contains(self):
"""in operator functions as expected
"""
self.assertTrue('d1' in self.s1)
self.assertTrue('r2' in self.s2)
self.assertFalse('r2' in self.s1)
def test_eq(self):
"""equality operator functions as expected
"""
self.assertTrue(self.s1 == self.s1)
self.assertFalse(self.s1 == self.s2)
# different objects can be equal
self.assertTrue(self.s1 == SequenceCollection([self.d1, self.d2]))
self.assertTrue(SequenceCollection([self.d1, self.d2]) == self.s1)
# SequenceCollections with different number of sequences are not equal
self.assertFalse(self.s1 == SequenceCollection([self.d1]))
class FakeSequenceCollection(SequenceCollection):
pass
# SequenceCollections of different types are not equal
self.assertFalse(self.s1 == FakeSequenceCollection([self.d1, self.d2]))
self.assertFalse(self.s1 == Alignment([self.d1, self.d2]))
# SequenceCollections with different sequences are not equal
self.assertFalse(self.s1 == SequenceCollection([self.d1, self.r1]))
def test_getitem(self):
"""getitem functions as expected
"""
self.assertEqual(self.s1[0], self.d1)
self.assertEqual(self.s1[1], self.d2)
self.assertEqual(self.s2[0], self.r1)
#.........这里部分代码省略.........