当前位置: 首页>>代码示例>>Python>>正文


Python Table.norm方法代码示例

本文整理汇总了Python中biom.table.Table.norm方法的典型用法代码示例。如果您正苦于以下问题:Python Table.norm方法的具体用法?Python Table.norm怎么用?Python Table.norm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在biom.table.Table的用法示例。


在下文中一共展示了Table.norm方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TopLevelTests

# 需要导入模块: from biom.table import Table [as 别名]
# 或者: from biom.table.Table import norm [as 别名]
class TopLevelTests(TestCase):

    """Tests of top-level functions"""

    def setUp(self):
        self.otu_table_vals = array([[1, 0, 2, 4],
                                     [1, 2, 0, 1],
                                     [0, 1, 1, 0],
                                     [1, 2, 1, 0]])

        self.otu_table = Table(self.otu_table_vals,
                                       ['0', '1', '2', '3'],
                                       ['s1', 's2', 's3', 's4'],
                                       [{"taxonomy": ["Root", "Bacteria", "Actinobacteria", "Actinobacteria", "Coriobacteridae", "Coriobacteriales", "Coriobacterineae", "Coriobacteriaceae"]},
                                        {"taxonomy": ["Root",
                                                      "Bacteria",
                                                      "Firmicutes",
                                                      "\"Clostridia\""]},
                                        {"taxonomy": ["Root",
                                                      "Bacteria",
                                                      "Firmicutes",
                                                      "\"Clostridia\""]},
                                        {"taxonomy": ["Root", "Bacteria"]}],
                                        None,)

        self.mapping = """#SampleID\tBarcodeSequence\tTreatment\tDescription
#Test mapping file
s1\tAAAA\tControl\tControl mouse, I.D. 354
s2\tGGGG\tControl\tControl mouse, I.D. 355
s3\tCCCC\tExp\tDisease mouse, I.D. 356
s4\tTTTT\tExp\tDisease mouse, I.D. 357""".split('\n')

    def test_sum_counts_by_consensus(self):
        """should sum otu counts by consensus"""
        #otu_table = parse_otu_table(self.otu_table)
        #otu_table = parse_biom_table(self.otu_table)
        obs_result, obs_mapping = sum_counts_by_consensus(self.otu_table, 3)
        exp_result = {(
            'Root', 'Bacteria', 'Actinobacteria'): array([1, 0, 2, 4]),
            ('Root', 'Bacteria', 'Firmicutes'): array([1, 3, 1, 1]),
            ('Root', 'Bacteria', 'Other'): array([1, 2, 1, 0])}
        exp_mapping = {'s1': 0, 's2': 1, 's3': 2, 's4': 3}
        self.assertItemsEqual(obs_result, exp_result)
        self.assertEqual(obs_mapping, exp_mapping)

        obs_result, obs_mapping = sum_counts_by_consensus(self.otu_table, 2)
        exp_result = {('Root', 'Bacteria'): array([3, 5, 4, 5])}
        exp_mapping = {'s1': 0, 's2': 1, 's3': 2, 's4': 3}
        self.assertItemsEqual(obs_result, exp_result)
        self.assertEqual(obs_mapping, exp_mapping)

        obs_result, obs_mapping = sum_counts_by_consensus(self.otu_table, 4)
        exp_result = {('Root', 'Bacteria', 'Actinobacteria', 'Actinobacteria'):
                      array([1, 0, 2, 4]),
                      ('Root', 'Bacteria', 'Firmicutes', '"Clostridia"'):
                      array([1, 3, 1, 1]),
                      ('Root', 'Bacteria', 'Other', 'Other'): array([1, 2, 1, 0])}
        exp_mapping = {'s1': 0, 's2': 1, 's3': 2, 's4': 3}
        self.assertItemsEqual(obs_result, exp_result)
        self.assertEqual(obs_mapping, exp_mapping)

    def test_make_new_summary_file(self):
        """make_new_summary_file works
        """
        lower_percentage, upper_percentage = None, None
        #otu_table = parse_otu_table(self.otu_table, int)
        #otu_table = parse_biom_table(self.otu_table)
        summary, header = make_summary(
            self.otu_table, 3, upper_percentage, lower_percentage)
        self.assertEqual(header, ['Taxon', 's1', 's2', 's3', 's4'])
        self.assertEqual(
            summary, [[('Root', 'Bacteria', 'Actinobacteria'), 1, 0, 2, 4],
                      [('Root', 'Bacteria', 'Firmicutes'),
                       1, 3, 1, 1],
                      [('Root', 'Bacteria', 'Other'), 1, 2, 1, 0]])

        # test that works with relative abundances
        #otu_table = parse_otu_table(self.otu_table, float)
        #otu_table = parse_biom_table(self.otu_table, float)
        #otu_table = convert_otu_table_relative(otu_table)
        otu_table = self.otu_table.norm(axis='sample', inplace=False)
        summary, header = make_summary(
            otu_table, 3, upper_percentage, lower_percentage)
        self.assertEqual(header, ['Taxon', 's1', 's2', 's3', 's4'])
        self.assertEqual(summary[0][0], ('Root', 'Bacteria', 'Actinobacteria'))
        assert_almost_equal(summary[0][1:], [1.0 / 3, 0.0, 0.5, 0.8])
        self.assertEqual(summary[1][0], ('Root', 'Bacteria', 'Firmicutes'))
        assert_almost_equal(summary[1][1:], [1.0 / 3, 0.6, 0.25, 0.2])
        self.assertEqual(summary[2][0], ('Root', 'Bacteria', 'Other'))
        assert_almost_equal(summary[2][1:], [1.0 / 3, 0.4, 0.25, 0.0])

        ##
        # testing lower triming
        lower_percentage, upper_percentage = 0.3, None
        summary, header = make_summary(
            otu_table, 3, upper_percentage, lower_percentage)
        self.assertEqual(summary[0][0], ('Root', 'Bacteria', 'Other'))
        assert_almost_equal(summary[0][1:], [1.0 / 3, 0.4, 0.25, 0.0])

        ##
#.........这里部分代码省略.........
开发者ID:AhmedAbdelfattah,项目名称:qiime,代码行数:103,代码来源:test_summarize_taxa.py


注:本文中的biom.table.Table.norm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。