本文整理汇总了Python中skbio.TabularMSA类的典型用法代码示例。如果您正苦于以下问题:Python TabularMSA类的具体用法?Python TabularMSA怎么用?Python TabularMSA使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TabularMSA类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sort_on_invalid_key
def test_sort_on_invalid_key(self):
msa = TabularMSA([DNA('AAA'), DNA('ACG')], keys=[42, 43])
with self.assertRaises(KeyError):
msa.sort(key='id')
self.assertEqual(
msa,
TabularMSA([DNA('AAA'), DNA('ACG')], keys=[42, 43]))
示例2: test_keys_setter_non_empty
def test_keys_setter_non_empty(self):
msa = TabularMSA([DNA('AC'), DNA('AG'), DNA('AT')])
self.assertFalse(msa.has_keys())
msa.keys = range(3)
npt.assert_array_equal(msa.keys, np.array([0, 1, 2]))
msa.keys = range(3, 6)
npt.assert_array_equal(msa.keys, np.array([3, 4, 5]))
示例3: test_sort_on_unorderable_msa_keys
def test_sort_on_unorderable_msa_keys(self):
unorderable = Unorderable()
msa = TabularMSA([DNA('AAA'), DNA('ACG')], keys=[42, unorderable])
with self.assertRaises(TypeError):
msa.sort()
self.assertEqual(
msa,
TabularMSA([DNA('AAA'), DNA('ACG')], keys=[42, unorderable]))
示例4: test_metadata_setter_invalid_type
def test_metadata_setter_invalid_type(self):
msa = TabularMSA([Protein('PAW')], metadata={123: 456})
for md in (None, 0, 'a', ('f', 'o', 'o'), np.array([]),
pd.DataFrame()):
with six.assertRaisesRegex(self, TypeError,
'metadata must be a dict'):
msa.metadata = md
self.assertEqual(msa.metadata, {123: 456})
示例5: test_keys_setter_non_hashable_keys
def test_keys_setter_non_hashable_keys(self):
msa = TabularMSA([DNA('ACGT'), DNA('TGCA')], key=str)
keys = np.array(['ACGT', 'TGCA'])
npt.assert_array_equal(msa.keys, keys)
with self.assertRaises(TypeError):
msa.keys = [[42], [42]]
# original state is maintained
npt.assert_array_equal(msa.keys, keys)
示例6: test_keys_setter_non_unique_keys
def test_keys_setter_non_unique_keys(self):
msa = TabularMSA([DNA('ACGT'), DNA('TGCA')], key=str)
keys = np.array(['ACGT', 'TGCA'])
npt.assert_array_equal(msa.keys, keys)
with six.assertRaisesRegex(self, UniqueError, 'Duplicate keys:.*42'):
msa.keys = [42, 42]
# original state is maintained
npt.assert_array_equal(msa.keys, keys)
示例7: test_from_dict_to_dict_roundtrip
def test_from_dict_to_dict_roundtrip(self):
d = {}
self.assertEqual(TabularMSA.from_dict(d).to_dict(), d)
# can roundtrip even with mixed key types
d1 = {'a': DNA('CAT'), 42: DNA('TAG')}
d2 = TabularMSA.from_dict(d1).to_dict()
self.assertEqual(d2, d1)
self.assertIs(d1['a'], d2['a'])
self.assertIs(d1[42], d2[42])
示例8: test_reindex_makes_copy_of_keys
def test_reindex_makes_copy_of_keys(self):
msa = TabularMSA([DNA('AC'), DNA('AG'), DNA('AT')])
keys = np.asarray([1, 2, 3])
msa.reindex(keys=keys)
npt.assert_array_equal(msa.keys, np.array([1, 2, 3]))
self.assertFalse(msa.keys.flags.writeable)
self.assertTrue(keys.flags.writeable)
keys[1] = 42
npt.assert_array_equal(msa.keys, np.array([1, 2, 3]))
示例9: test_reindex_key_and_keys_both_provided
def test_reindex_key_and_keys_both_provided(self):
msa = TabularMSA([DNA('ACGT'), DNA('TGCA')], key=str)
keys = np.array(['ACGT', 'TGCA'])
npt.assert_array_equal(msa.keys, keys)
with six.assertRaisesRegex(self, ValueError, 'both.*key.*keys'):
msa.reindex(key=str, keys=['a', 'b'])
# original state is maintained
npt.assert_array_equal(msa.keys, keys)
示例10: test_has_metadata
def test_has_metadata(self):
msa = TabularMSA([])
self.assertFalse(msa.has_metadata())
# Handles metadata efficiently.
self.assertIsNone(msa._metadata)
self.assertFalse(TabularMSA([], metadata={}).has_metadata())
self.assertTrue(TabularMSA([], metadata={'': ''}).has_metadata())
self.assertTrue(TabularMSA([], metadata={'foo': 42}).has_metadata())
示例11: test_reindex_keys_length_mismatch
def test_reindex_keys_length_mismatch(self):
msa = TabularMSA([DNA('ACGT'), DNA('TGCA')], key=str)
keys = np.array(['ACGT', 'TGCA'])
npt.assert_array_equal(msa.keys, keys)
with six.assertRaisesRegex(self, ValueError,
'Number.*keys.*number.*sequences: 0 != 2'):
msa.reindex(keys=iter([]))
# original state is maintained
npt.assert_array_equal(msa.keys, keys)
示例12: test_sort_on_unorderable_key
def test_sort_on_unorderable_key(self):
unorderable = Unorderable()
msa = TabularMSA([
DNA('AAA', metadata={'id': 42}),
DNA('ACG', metadata={'id': unorderable})], keys=[42, 43])
with self.assertRaises(TypeError):
msa.sort(key='id')
self.assertEqual(
msa,
TabularMSA([
DNA('AAA', metadata={'id': 42}),
DNA('ACG', metadata={'id': unorderable})], keys=[42, 43]))
示例13: test_sort_on_key_with_all_repeats
def test_sort_on_key_with_all_repeats(self):
msa = TabularMSA([
DNA('TTT', metadata={'id': 'a'}),
DNA('TTT', metadata={'id': 'b'}),
DNA('TTT', metadata={'id': 'c'})], keys=range(3))
msa.sort(key=str)
self.assertEqual(
msa,
TabularMSA([
DNA('TTT', metadata={'id': 'a'}),
DNA('TTT', metadata={'id': 'b'}),
DNA('TTT', metadata={'id': 'c'})], keys=range(3)))
示例14: filter_positions
def filter_positions(alignment_fh, maximum_gap_frequency,
maximum_position_entropy):
"""Filter gaps and high entropy positions from an alignment."""
with alignment_fh:
try:
aln = TabularMSA.read(alignment_fh, constructor=DNA)
except ValueError:
alignment_fh.seek(0)
aln = TabularMSA.read(alignment_fh, constructor=RNA)
aln = _filter_gap_positions(aln, maximum_gap_frequency)
aln = _filter_high_entropy_positions(aln, maximum_position_entropy)
return aln
示例15: test_metadata_getter
def test_metadata_getter(self):
msa = TabularMSA([])
self.assertIsNone(msa._metadata)
self.assertEqual(msa.metadata, {})
self.assertIsNotNone(msa._metadata)
self.assertIsInstance(msa.metadata, dict)
msa = TabularMSA([], metadata={42: 'foo', ('hello', 'world'): 43})
self.assertEqual(msa.metadata, {42: 'foo', ('hello', 'world'): 43})
self.assertIsInstance(msa.metadata, dict)
msa.metadata[42] = 'bar'
self.assertEqual(msa.metadata, {42: 'bar', ('hello', 'world'): 43})