本文整理汇总了Python中skbio.TabularMSA.reindex方法的典型用法代码示例。如果您正苦于以下问题:Python TabularMSA.reindex方法的具体用法?Python TabularMSA.reindex怎么用?Python TabularMSA.reindex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skbio.TabularMSA
的用法示例。
在下文中一共展示了TabularMSA.reindex方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_reindex_key_and_keys_both_provided
# 需要导入模块: from skbio import TabularMSA [as 别名]
# 或者: from skbio.TabularMSA import reindex [as 别名]
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)
示例2: test_reindex_makes_copy_of_keys
# 需要导入模块: from skbio import TabularMSA [as 别名]
# 或者: from skbio.TabularMSA import reindex [as 别名]
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]))
示例3: test_reindex_keys_length_mismatch
# 需要导入模块: from skbio import TabularMSA [as 别名]
# 或者: from skbio.TabularMSA import reindex [as 别名]
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)
示例4: test_reindex_non_hashable_keys
# 需要导入模块: from skbio import TabularMSA [as 别名]
# 或者: from skbio.TabularMSA import reindex [as 别名]
def test_reindex_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.reindex(key=lambda x: [42])
# original state is maintained
npt.assert_array_equal(msa.keys, keys)
with self.assertRaises(TypeError):
msa.reindex(keys=[[42], [42]])
npt.assert_array_equal(msa.keys, keys)
示例5: test_reindex_non_unique_keys
# 需要导入模块: from skbio import TabularMSA [as 别名]
# 或者: from skbio.TabularMSA import reindex [as 别名]
def test_reindex_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.reindex(key=lambda x: 42)
# original state is maintained
npt.assert_array_equal(msa.keys, keys)
with six.assertRaisesRegex(self, UniqueError, 'Duplicate keys:.*42'):
msa.reindex(keys=[42, 42])
npt.assert_array_equal(msa.keys, keys)
示例6: test_has_keys
# 需要导入模块: from skbio import TabularMSA [as 别名]
# 或者: from skbio.TabularMSA import reindex [as 别名]
def test_has_keys(self):
self.assertFalse(TabularMSA([]).has_keys())
self.assertTrue(TabularMSA([], key=str).has_keys())
self.assertFalse(TabularMSA([DNA('')]).has_keys())
self.assertTrue(TabularMSA([DNA('')], key=str).has_keys())
self.assertFalse(TabularMSA([DNA('ACG'), DNA('GCA')]).has_keys())
self.assertTrue(
TabularMSA([DNA('ACG', metadata={'id': 1}),
DNA('GCA', metadata={'id': 2})], key='id').has_keys())
msa = TabularMSA([])
self.assertFalse(msa.has_keys())
msa.reindex(key=str)
self.assertTrue(msa.has_keys())
msa.reindex()
self.assertFalse(msa.has_keys())
示例7: test_reindex_non_empty
# 需要导入模块: from skbio import TabularMSA [as 别名]
# 或者: from skbio.TabularMSA import reindex [as 别名]
def test_reindex_non_empty(self):
msa = TabularMSA([DNA('ACG', metadata={'id': 1}),
DNA('AAA', metadata={'id': 2})], key=str)
npt.assert_array_equal(msa.keys, np.array(['ACG', 'AAA']))
msa.reindex(key='id')
self.assertEqual(
msa,
TabularMSA([DNA('ACG', metadata={'id': 1}),
DNA('AAA', metadata={'id': 2})], key='id'))
npt.assert_array_equal(msa.keys, np.array([1, 2]))
msa.reindex(keys=iter('ab'))
self.assertEqual(
msa,
TabularMSA([DNA('ACG', metadata={'id': 1}),
DNA('AAA', metadata={'id': 2})], keys=iter('ab')))
npt.assert_array_equal(msa.keys, np.array(['a', 'b']))
msa.reindex()
self.assertFalse(msa.has_keys())
示例8: test_reindex_empty
# 需要导入模块: from skbio import TabularMSA [as 别名]
# 或者: from skbio.TabularMSA import reindex [as 别名]
def test_reindex_empty(self):
# sequence empty
msa = TabularMSA([])
msa.reindex()
self.assertEqual(msa, TabularMSA([]))
self.assertFalse(msa.has_keys())
msa.reindex(key=str)
self.assertEqual(msa, TabularMSA([], key=str))
npt.assert_array_equal(msa.keys, np.array([]))
msa.reindex(keys=iter([]))
self.assertEqual(msa, TabularMSA([], keys=iter([])))
npt.assert_array_equal(msa.keys, np.array([]))
# position empty
msa = TabularMSA([DNA('')])
msa.reindex()
self.assertEqual(msa, TabularMSA([DNA('')]))
self.assertFalse(msa.has_keys())
msa.reindex(key=str)
self.assertEqual(msa, TabularMSA([DNA('')], key=str))
npt.assert_array_equal(msa.keys, np.array(['']))
msa.reindex(keys=iter(['a']))
self.assertEqual(msa, TabularMSA([DNA('')], keys=iter(['a'])))
npt.assert_array_equal(msa.keys, np.array(['a']))