本文整理汇总了Python中biom.table.Table.iter_data方法的典型用法代码示例。如果您正苦于以下问题:Python Table.iter_data方法的具体用法?Python Table.iter_data怎么用?Python Table.iter_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类biom.table.Table
的用法示例。
在下文中一共展示了Table.iter_data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TopLevelTests
# 需要导入模块: from biom.table import Table [as 别名]
# 或者: from biom.table.Table import iter_data [as 别名]
#.........这里部分代码省略.........
[{"taxonomy": ["Bacteria"]}, {"taxonomy": ["Archaea"]}, {"taxonomy": ["Streptococcus"]}],
[None, None, None, None, None, None],
)
self.otu_table_f = Table(
self.otu_table_values,
["OTU1", "OTU2", "OTU3"],
["Sample1", "Sample2", "Sample3", "Sample4", "Sample5", "Sample6"],
[
{"taxonomy": ["1A", "1B", "1C", "Bacteria"]},
{"taxonomy": ["2A", "2B", "2C", "Archaea"]},
{"taxonomy": ["3A", "3B", "3C", "Streptococcus"]},
],
[None, None, None, None, None, None],
)
self.full_lineages = [
["1A", "1B", "1C", "Bacteria"],
["2A", "2B", "2C", "Archaea"],
["3A", "3B", "3C", "Streptococcus"],
]
self.metadata = [
[
["Sample1", "NA", "A"],
["Sample2", "NA", "B"],
["Sample3", "NA", "A"],
["Sample4", "NA", "B"],
["Sample5", "NA", "A"],
["Sample6", "NA", "B"],
],
["SampleID", "CAT1", "CAT2"],
[],
]
self.tree_text = ["('OTU3',('OTU1','OTU2'))"]
fh, self.tmp_heatmap_fpath = mkstemp(prefix="test_heatmap_", suffix=".pdf")
close(fh)
def test_extract_metadata_column(self):
"""Extracts correct column from mapping file"""
obs = extract_metadata_column(self.otu_table.sample_ids, self.metadata, category="CAT2")
exp = ["A", "B", "A", "B", "A", "B"]
self.assertEqual(obs, exp)
def test_get_order_from_categories(self):
"""Sample indices should be clustered within each category"""
category_labels = ["A", "B", "A", "B", "A", "B"]
obs = get_order_from_categories(self.otu_table, category_labels)
group_string = "".join([category_labels[i] for i in obs])
self.assertTrue("AAABBB" == group_string or group_string == "BBBAAA")
def test_get_order_from_tree(self):
obs = get_order_from_tree(self.otu_table.observation_ids, self.tree_text)
exp = [2, 0, 1]
assert_almost_equal(obs, exp)
def test_make_otu_labels(self):
lineages = []
for val, id, meta in self.otu_table.iter(axis="observation"):
lineages.append([v for v in meta["taxonomy"]])
obs = make_otu_labels(self.otu_table.observation_ids, lineages, n_levels=1)
exp = ["Bacteria (OTU1)", "Archaea (OTU2)", "Streptococcus (OTU3)"]
self.assertEqual(obs, exp)
full_lineages = []
for val, id, meta in self.otu_table_f.iter(axis="observation"):
full_lineages.append([v for v in meta["taxonomy"]])
obs = make_otu_labels(self.otu_table_f.observation_ids, full_lineages, n_levels=3)
exp = ["1B;1C;Bacteria (OTU1)", "2B;2C;Archaea (OTU2)", "3B;3C;Streptococcus (OTU3)"]
self.assertEqual(obs, exp)
def test_names_to_indices(self):
new_order = ["Sample4", "Sample2", "Sample3", "Sample6", "Sample5", "Sample1"]
obs = names_to_indices(self.otu_table.sample_ids, new_order)
exp = [3, 1, 2, 5, 4, 0]
assert_almost_equal(obs, exp)
def test_get_log_transform(self):
obs = get_log_transform(self.otu_table)
data = [val for val in self.otu_table.iter_data(axis="observation")]
xform = asarray(data, dtype=float64)
for (i, val) in enumerate(obs.iter_data(axis="observation")):
non_zeros = argwhere(xform[i] != 0)
xform[i, non_zeros] = log10(xform[i, non_zeros])
assert_almost_equal(val, xform[i])
def test_get_clusters(self):
data = asarray([val for val in self.otu_table.iter_data(axis="observation")])
obs = get_clusters(data, axis="row")
self.assertTrue([0, 1, 2] == obs or obs == [1, 2, 0])
obs = get_clusters(data, axis="column")
exp = [2, 3, 1, 4, 0, 5]
self.assertEqual(obs, exp)
def test_plot_heatmap(self):
plot_heatmap(
self.otu_table, self.otu_table.observation_ids, self.otu_table.sample_ids, filename=self.tmp_heatmap_fpath
)
self.assertEqual(exists(self.tmp_heatmap_fpath), True)
remove_files(set([self.tmp_heatmap_fpath]))
示例2: TopLevelTests
# 需要导入模块: from biom.table import Table [as 别名]
# 或者: from biom.table.Table import iter_data [as 别名]
class TopLevelTests(TestCase):
"""Tests of top-level functions"""
def setUp(self):
"""define some top-level data"""
self.otu_table_values = array([[0, 0, 9, 5, 3, 1],
[1, 5, 4, 0, 3, 2],
[2, 3, 1, 1, 2, 5]])
{(0, 2): 9.0, (0, 3): 5.0, (0, 4): 3.0, (0, 5): 1.0,
(1, 0): 1.0, (1, 1): 5.0, (1, 2): 4.0, (1, 4): 3.0, (1, 5): 2.0,
(2, 0): 2.0, (2, 1): 3.0, (2, 2): 1.0, (2, 3): 1.0, (2, 4): 2.0, (2, 5): 5.0}
self.otu_table = Table(self.otu_table_values,
['OTU1', 'OTU2', 'OTU3'],
['Sample1', 'Sample2', 'Sample3',
'Sample4', 'Sample5', 'Sample6'],
[{"taxonomy": ['Bacteria']},
{"taxonomy": ['Archaea']},
{"taxonomy": ['Streptococcus']}],
[None, None, None, None, None, None])
self.otu_table_f = Table(self.otu_table_values,
['OTU1', 'OTU2', 'OTU3'],
['Sample1', 'Sample2', 'Sample3',
'Sample4', 'Sample5', 'Sample6'],
[{"taxonomy": ['1A', '1B', '1C', 'Bacteria']},
{"taxonomy":
['2A', '2B', '2C', 'Archaea']},
{"taxonomy": ['3A', '3B', '3C', 'Streptococcus']}],
[None, None, None, None, None, None])
self.full_lineages = [['1A', '1B', '1C', 'Bacteria'],
['2A', '2B', '2C', 'Archaea'],
['3A', '3B', '3C', 'Streptococcus']]
self.metadata = [[['Sample1', 'NA', 'A'],
['Sample2', 'NA', 'B'],
['Sample3', 'NA', 'A'],
['Sample4', 'NA', 'B'],
['Sample5', 'NA', 'A'],
['Sample6', 'NA', 'B']],
['SampleID', 'CAT1', 'CAT2'], []]
self.tree_text = ["('OTU3',('OTU1','OTU2'))"]
fh, self.tmp_heatmap_fpath = mkstemp(prefix='test_heatmap_',
suffix='.pdf')
close(fh)
def test_extract_metadata_column(self):
"""Extracts correct column from mapping file"""
obs = extract_metadata_column(self.otu_table.ids(),
self.metadata, category='CAT2')
exp = ['A', 'B', 'A', 'B', 'A', 'B']
self.assertEqual(obs, exp)
def test_get_order_from_categories(self):
"""Sample indices should be clustered within each category"""
category_labels = ['A', 'B', 'A', 'B', 'A', 'B']
obs = get_order_from_categories(self.otu_table, category_labels)
group_string = "".join([category_labels[i] for i in obs])
self.assertTrue("AAABBB" == group_string or group_string == "BBBAAA")
def test_get_order_from_tree(self):
obs = get_order_from_tree(
self.otu_table.ids(axis='observation'),
self.tree_text)
exp = [2, 0, 1]
assert_almost_equal(obs, exp)
def test_make_otu_labels(self):
lineages = []
for val, id, meta in self.otu_table.iter(axis='observation'):
lineages.append([v for v in meta['taxonomy']])
obs = make_otu_labels(self.otu_table.ids(axis='observation'),
lineages, n_levels=1)
exp = ['Bacteria (OTU1)', 'Archaea (OTU2)', 'Streptococcus (OTU3)']
self.assertEqual(obs, exp)
full_lineages = []
for val, id, meta in self.otu_table_f.iter(axis='observation'):
full_lineages.append([v for v in meta['taxonomy']])
obs = make_otu_labels(self.otu_table_f.ids(axis='observation'),
full_lineages, n_levels=3)
exp = ['1B;1C;Bacteria (OTU1)',
'2B;2C;Archaea (OTU2)',
'3B;3C;Streptococcus (OTU3)']
self.assertEqual(obs, exp)
def test_names_to_indices(self):
new_order = ['Sample4', 'Sample2', 'Sample3',
'Sample6', 'Sample5', 'Sample1']
obs = names_to_indices(self.otu_table.ids(), new_order)
exp = [3, 1, 2, 5, 4, 0]
assert_almost_equal(obs, exp)
def test_get_log_transform(self):
obs = get_log_transform(self.otu_table)
data = [val for val in self.otu_table.iter_data(axis='observation')]
xform = asarray(data, dtype=float64)
for (i, val) in enumerate(obs.iter_data(axis='observation')):
#.........这里部分代码省略.........