本文整理汇总了Python中skbio.TabularMSA类的典型用法代码示例。如果您正苦于以下问题:Python TabularMSA类的具体用法?Python TabularMSA怎么用?Python TabularMSA使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TabularMSA类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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]))
开发者ID:hainm,项目名称:scikit-bio,代码行数:7,代码来源:test_tabular_msa.py
示例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]))
开发者ID:hainm,项目名称:scikit-bio,代码行数:7,代码来源:test_tabular_msa.py
示例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]))
开发者ID:hainm,项目名称:scikit-bio,代码行数:8,代码来源:test_tabular_msa.py
示例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})
开发者ID:hainm,项目名称:scikit-bio,代码行数:9,代码来源:test_tabular_msa.py
示例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)
开发者ID:hainm,项目名称:scikit-bio,代码行数:10,代码来源:test_tabular_msa.py
示例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)
开发者ID:hainm,项目名称:scikit-bio,代码行数:10,代码来源:test_tabular_msa.py
示例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])
开发者ID:hainm,项目名称:scikit-bio,代码行数:10,代码来源:test_tabular_msa.py
示例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]))
开发者ID:hainm,项目名称:scikit-bio,代码行数:10,代码来源:test_tabular_msa.py
示例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)
开发者ID:hainm,项目名称:scikit-bio,代码行数:10,代码来源:test_tabular_msa.py
示例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())
开发者ID:hainm,项目名称:scikit-bio,代码行数:10,代码来源:test_tabular_msa.py
示例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)
开发者ID:hainm,项目名称:scikit-bio,代码行数:11,代码来源:test_tabular_msa.py
示例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]))
开发者ID:hainm,项目名称:scikit-bio,代码行数:12,代码来源:test_tabular_msa.py
示例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)))
开发者ID:hainm,项目名称:scikit-bio,代码行数:12,代码来源:test_tabular_msa.py
示例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
开发者ID:JTFouquier,项目名称:ghost-tree,代码行数:13,代码来源:filter.py
示例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})
开发者ID:hainm,项目名称:scikit-bio,代码行数:13,代码来源:test_tabular_msa.py
示例16: test_metadata_setter_makes_shallow_copy
def test_metadata_setter_makes_shallow_copy(self):
msa = TabularMSA([RNA('-.-'), RNA('.-.')])
md = {'foo': 'bar', 42: []}
msa.metadata = md
self.assertEqual(msa.metadata, md)
self.assertIsNot(msa.metadata, md)
md['foo'] = 'baz'
self.assertEqual(msa.metadata, {'foo': 'bar', 42: []})
md[42].append(True)
self.assertEqual(msa.metadata, {'foo': 'bar', 42: [True]})
开发者ID:hainm,项目名称:scikit-bio,代码行数:13,代码来源:test_tabular_msa.py
示例17: test_keys_update_subset_of_keys
def test_keys_update_subset_of_keys(self):
# keys can be copied, modified, then re-set
msa = TabularMSA([DNA('AC'), DNA('AG'), DNA('AT')], key=str)
npt.assert_array_equal(msa.keys, np.array(['AC', 'AG', 'AT']))
new_keys = msa.keys.copy()
new_keys[1] = 42
msa.keys = new_keys
npt.assert_array_equal(msa.keys,
np.array(['AC', 42, 'AT'], dtype=object))
self.assertFalse(msa.keys.flags.writeable)
self.assertTrue(new_keys.flags.writeable)
new_keys[1] = 'GG'
npt.assert_array_equal(msa.keys,
np.array(['AC', 42, 'AT'], dtype=object))
开发者ID:hainm,项目名称:scikit-bio,代码行数:16,代码来源:test_tabular_msa.py
示例18: test_reformat_treepuzzle
def test_reformat_treepuzzle(self):
""" Test functionality of reformat_treepuzzle()
"""
species_tree = TreeNode.read(self.species_tree_fp, format='newick')
gene_tree_3 = TreeNode.read(self.gene_tree_3_fp, format='newick')
output_tree_fp = join(self.working_dir, "joined_trees.nwk")
output_msa_phy_fp = join(self.working_dir, "gene_tree_3.phy")
reformat_treepuzzle(gene_tree_3,
species_tree,
self.msa_fa_3_fp,
output_tree_fp,
output_msa_phy_fp)
reformat_tree_exp = [
"(((((((SE001:2.1494877,SE010:1.08661):3.7761166,SE008:"
"0.86305436):0.21024487,(SE006:0.56704221,SE009:0.5014676):"
"0.90294223):0.20542323,SE005:3.0992506):0.37145632,SE004:"
"1.8129133):0.72933621,SE003:1.737411):0.24447835,(SE002:"
"1.6606127,SE007:0.70000178):1.6331374);\n",
"(((((((SE001:2.1494876,SE010:2.1494876):"
"3.7761166,SE008:5.9256042):0.2102448,(SE006:"
"5.2329068,SE009:5.2329068):0.9029422):0.2054233,"
"SE005:6.3412723):0.3714563,SE004:6.7127286):"
"0.7293362,SE003:7.4420648):0.2444784,SE002:"
"7.6865432);\n"]
with open(output_tree_fp, 'r') as output_tree_f:
reformat_tree_act = output_tree_f.readlines()
self.assertListEqual(reformat_tree_exp, reformat_tree_act)
msa_fa = TabularMSA.read(output_msa_phy_fp, constructor=Protein)
labels_exp = [u'SE001', u'SE002', u'SE003', u'SE004', u'SE005',
u'SE006', u'SE008', u'SE009', u'SE010']
labels_act = list(msa_fa.index)
self.assertListEqual(labels_exp, labels_act)
开发者ID:carlyboyd,项目名称:WGS-HGT,代码行数:32,代码来源:test_reformat_input.py
示例19: test_sort_on_key_with_some_repeats
def test_sort_on_key_with_some_repeats(self):
msa = TabularMSA([
DNA('TCCG', metadata={'id': 10}),
DNA('TAGG', metadata={'id': 10}),
DNA('GGGG', metadata={'id': 8}),
DNA('ACGT', metadata={'id': 0}),
DNA('TAGG', metadata={'id': 10})], keys=range(5))
msa.sort(key='id')
self.assertEqual(
msa,
TabularMSA([
DNA('ACGT', metadata={'id': 0}),
DNA('GGGG', metadata={'id': 8}),
DNA('TCCG', metadata={'id': 10}),
DNA('TAGG', metadata={'id': 10}),
DNA('TAGG', metadata={'id': 10})], keys=[3, 2, 0, 1, 4]))
开发者ID:hainm,项目名称:scikit-bio,代码行数:16,代码来源:test_tabular_msa.py
示例20: aln_distmat
def aln_distmat(alignment, reps=3):
'''Calculate pairwise distances from a MSA of genomes'''
aln = TabularMSA.read(alignment, constructor=DNA)
aln.reassign_index(minter="id")
dist = DistanceMatrix.from_iterable([seq.values for seq in aln],
metric=hamming, keys=aln.index)
return dist
开发者ID:kdmurray91,项目名称:kwip-experiments,代码行数:7,代码来源:alndist.py
注:本文中的skbio.TabularMSA类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论