def test_parse_classic_otu_table_floats_in_table(self):
        """parse_classic_otu_table functions using an OTU table containing floats
           but cast as int....this will automatically cast into floats"""

        data = self.otu_table1_floats
        data_f = data.split("\n")
        obs = parse_classic_otu_table(data_f)
        exp = (
            ["Fing", "Key", "NA"],
            ["0", "1", "2", "3", "4"],
            array(
                [
                    [19111.0, 44536.0, 42.0],
                    [1216.0, 3500.0, 6.0],
                    [1803.0, 1184.0, 2.0],
                    [1722.1, 4903.2, 17.0],
                    [589.6, 2074.4, 34.5],
                ]
            ),
            self.expected_lineages1,
        )
        # because float comps in arrays always errors
        self.assertEqual(obs[0], exp[0])
        self.assertEqual(obs[1], exp[1])
        self.assertEqual(obs[3], exp[3])
        self.assertTrue(all((obs[2] == exp[2]).tolist()))
Example #2
0
    def test_parse_classic_otu_table_consensus_lineage(self):
        """parse_classic_otu_table should accept 'consensusLineage'"""
        data = """#Full OTU Counts
#OTU ID	Fing	Key	NA	consensusLineage
0	19111	44536	42	Bacteria; Actinobacteria; Actinobacteridae; Propionibacterineae; Propionibacterium
1	1216	3500	6	Bacteria; Firmicutes; Alicyclobacillaceae; Bacilli; Lactobacillales; Lactobacillales; Streptococcaceae; Streptococcus
2	1803	1184	2	Bacteria; Actinobacteria; Actinobacteridae; Gordoniaceae; Corynebacteriaceae
3	1722	4903	17	Bacteria; Firmicutes; Alicyclobacillaceae; Bacilli; Staphylococcaceae
4	589	2074	34	Bacteria; Cyanobacteria; Chloroplasts; vectors"""
        data_f = StringIO(data)
        obs = parse_classic_otu_table(data_f)
        exp = (['Fing','Key','NA'],
               ['0','1','2','3','4'],
               array([[19111,44536,42],[1216,3500,6],[1803,1184,2],\
                    [1722,4903,17], [589,2074,34]]),
               [['Bacteria','Actinobacteria','Actinobacteridae','Propionibacterineae','Propionibacterium'],
                ['Bacteria','Firmicutes','Alicyclobacillaceae','Bacilli','Lactobacillales','Lactobacillales','Streptococcaceae','Streptococcus'],
                ['Bacteria','Actinobacteria','Actinobacteridae','Gordoniaceae','Corynebacteriaceae'],
                ['Bacteria','Firmicutes','Alicyclobacillaceae','Bacilli','Staphylococcaceae'],
                ['Bacteria','Cyanobacteria','Chloroplasts','vectors']])
        # because float comps in arrays always errors
        self.assertEqual(obs[0], exp[0])
        self.assertEqual(obs[1], exp[1])
        self.assertEqual(obs[3], exp[3])
        self.assertTrue(all((obs[2] == exp[2]).tolist()))
Example #3
0
    def test_parse_classic_otu_table_float_counts(self):
        """parse_classic_otu_table should return correct result from small table"""
        data = """#Full OTU Counts
#OTU ID	Fing	Key	NA	Consensus Lineage
0	19111	44536	42	Bacteria; Actinobacteria; Actinobacteridae; Propionibacterineae; Propionibacterium
1	1216	3500	6	Bacteria; Firmicutes; Alicyclobacillaceae; Bacilli; Lactobacillales; Lactobacillales; Streptococcaceae; Streptococcus
2	1803	1184	2	Bacteria; Actinobacteria; Actinobacteridae; Gordoniaceae; Corynebacteriaceae
3	1722	4903	17	Bacteria; Firmicutes; Alicyclobacillaceae; Bacilli; Staphylococcaceae
4	589	2074	34	Bacteria; Cyanobacteria; Chloroplasts; vectors"""
        data_f = (data.split('\n'))
        obs = parse_classic_otu_table(data_f, count_map_f=float)
        exp = (['Fing','Key','NA'],
               ['0','1','2','3','4'],
               array([[19111.,44536.,42.],[1216.,3500.,6.],[1803.,1184.,2.],\
                    [1722.,4903.,17.], [589,2074.,34.]]),
               [['Bacteria','Actinobacteria','Actinobacteridae','Propionibacterineae','Propionibacterium'],
                ['Bacteria','Firmicutes','Alicyclobacillaceae','Bacilli','Lactobacillales','Lactobacillales','Streptococcaceae','Streptococcus'],
                ['Bacteria','Actinobacteria','Actinobacteridae','Gordoniaceae','Corynebacteriaceae'],
                ['Bacteria','Firmicutes','Alicyclobacillaceae','Bacilli','Staphylococcaceae'],
                ['Bacteria','Cyanobacteria','Chloroplasts','vectors']])

        # because float comps in arrays always errors
        self.assertEqual(obs[0], exp[0])
        self.assertEqual(obs[1], exp[1])
        self.assertEqual(obs[3], exp[3])
        self.assertTrue(all((obs[2] == exp[2]).tolist()))
    def test_parse_classic_otu_table(self):
        """parse_classic_otu_table functions as expected with new-style OTU table
        """
        data = self.otu_table1
        data_f = data.split("\n")
        obs = parse_classic_otu_table(data_f)
        exp = (
            ["Fing", "Key", "NA"],
            ["0", "1", "2", "3", "4"],
            array([[19111, 44536, 42], [1216, 3500, 6], [1803, 1184, 2], [1722, 4903, 17], [589, 2074, 34]]),
            self.expected_lineages1,
        )

        # divide the comparisons into their four elements
        self.assertEqual(obs[0], exp[0])
        self.assertEqual(obs[1], exp[1])
        assert_almost_equal(obs[2], exp[2])
        self.assertEqual(obs[3], exp[3])

        # test that the modified parse_classic performs correctly on OTU tables
        # without leading comments
        data = self.otu_table_without_leading_comment
        data_f = data.split("\n")
        obs = parse_classic_otu_table(data_f)
        sams = ["let-7i", "miR-7", "miR-17n", "miR-18a", "miR-19a", "miR-22", "miR-25", "miR-26a"]
        otus = ["A2M", "AAAS", "AACS", "AADACL1"]
        vals = array(
            [
                [-0.2, 0.03680505, 0.205, 0.23, 0.66, 0.08, -0.373, 0.26],
                [-0.09, -0.25, 0.274, 0.15, 0.12, 0.29, 0.029, -0.1148452],
                [0.33, 0.19, 0.27, 0.28, 0.19, 0.25, 0.089, 0.14],
                [0.49, -0.92, -0.723, -0.23, 0.08, 0.49, -0.386, -0.64],
            ]
        )
        exp = (sams, otus, vals, [])  # no lineages
        # because float comps in arrays always errors
        self.assertEqual(obs[0], exp[0])
        self.assertEqual(obs[1], exp[1])
        self.assertEqual(obs[3], exp[3])
        self.assertTrue(all((obs[2] == exp[2]).tolist()))
Example #5
0
    def test_parse_classic_otu_table(self):
        """parse_classic_otu_table functions as expected with new-style OTU table
        """
        data = self.otu_table1
        data_f = (data.split('\n'))
        obs = parse_classic_otu_table(data_f)
        exp = (['Fing', 'Key', 'NA'], ['0', '1', '2', '3', '4'],
               array([[19111, 44536, 42], [1216, 3500, 6], [1803, 1184, 2],
                      [1722, 4903, 17], [589, 2074,
                                         34]]), self.expected_lineages1)

        # divide the comparisons into their four elements
        self.assertEqual(obs[0], exp[0])
        self.assertEqual(obs[1], exp[1])
        assert_almost_equal(obs[2], exp[2])
        self.assertEqual(obs[3], exp[3])

        # test that the modified parse_classic performs correctly on OTU tables
        # without leading comments
        data = self.otu_table_without_leading_comment
        data_f = (data.split('\n'))
        obs = parse_classic_otu_table(data_f)
        sams = [
            'let-7i', 'miR-7', 'miR-17n', 'miR-18a', 'miR-19a', 'miR-22',
            'miR-25', 'miR-26a'
        ]
        otus = ['A2M', 'AAAS', 'AACS', 'AADACL1']
        vals = array([\
            [-0.2,  0.03680505,  0.205,  0.23,  0.66,  0.08,  -0.373,  0.26],
            [-0.09,  -0.25,  0.274,  0.15,  0.12,  0.29,  0.029,  -0.1148452],
            [0.33,  0.19,  0.27,  0.28,  0.19,  0.25,  0.089,  0.14],
            [0.49,  -0.92,  -0.723,  -0.23,  0.08,  0.49,  -0.386,  -0.64]])
        exp = (sams, otus, vals, [])  # no lineages
        # because float comps in arrays always errors
        self.assertEqual(obs[0], exp[0])
        self.assertEqual(obs[1], exp[1])
        self.assertEqual(obs[3], exp[3])
        self.assertTrue(all((obs[2] == exp[2]).tolist()))
Example #6
0
    def test_parse_classic_otu_table_floats_in_table(self):
        """parse_classic_otu_table functions using an OTU table containing floats
           but cast as int....this will automatically cast into floats"""

        data = self.otu_table1_floats
        data_f = (data.split('\n'))
        obs = parse_classic_otu_table(data_f)
        exp = (['Fing', 'Key', 'NA'], ['0', '1', '2', '3', '4'],
               array([[19111.0, 44536.0, 42.0], [1216.0, 3500.0, 6.0],
                      [1803.0, 1184.0, 2.0], [1722.1, 4903.2, 17.0],
                      [589.6, 2074.4, 34.5]]), self.expected_lineages1)
        # because float comps in arrays always errors
        self.assertEqual(obs[0], exp[0])
        self.assertEqual(obs[1], exp[1])
        self.assertEqual(obs[3], exp[3])
        self.assertTrue(all((obs[2] == exp[2]).tolist()))
Example #7
0
    def test_parse_classic_otu_table_legacy(self):
        """parse_classic_otu_table functions as expected with legacy OTU table
        """
        data = self.legacy_otu_table1
        data_f = (data.split('\n'))
        obs = parse_classic_otu_table(data_f)
        exp = (['Fing', 'Key', 'NA'], ['0', '1', '2', '3', '4'],
               array([[19111, 44536, 42], [1216, 3500, 6], [1803, 1184, 2],
                      [1722, 4903, 17], [589, 2074,
                                         34]]), self.expected_lineages1)

        # divide the comparisons into their four elements
        self.assertEqual(obs[0], exp[0])
        self.assertEqual(obs[1], exp[1])
        assert_almost_equal(obs[2], exp[2])
        self.assertEqual(obs[3], exp[3])
    def test_parse_classic_otu_table_float_counts(self):
        """parse_classic_otu_table should return correct result from small table"""
        data = """#Full OTU Counts
#OTU ID	Fing	Key	NA	Consensus Lineage
0	19111	44536	42	Bacteria; Actinobacteria; Actinobacteridae; Propionibacterineae; Propionibacterium
1	1216	3500	6	Bacteria; Firmicutes; Alicyclobacillaceae; Bacilli; Lactobacillales; Lactobacillales; Streptococcaceae; Streptococcus
2	1803	1184	2	Bacteria; Actinobacteria; Actinobacteridae; Gordoniaceae; Corynebacteriaceae
3	1722	4903	17	Bacteria; Firmicutes; Alicyclobacillaceae; Bacilli; Staphylococcaceae
4	589	2074	34	Bacteria; Cyanobacteria; Chloroplasts; vectors"""
        data_f = data.split("\n")
        obs = parse_classic_otu_table(data_f, count_map_f=float)
        exp = (
            ["Fing", "Key", "NA"],
            ["0", "1", "2", "3", "4"],
            array(
                [
                    [19111.0, 44536.0, 42.0],
                    [1216.0, 3500.0, 6.0],
                    [1803.0, 1184.0, 2.0],
                    [1722.0, 4903.0, 17.0],
                    [589, 2074.0, 34.0],
                ]
            ),
            [
                ["Bacteria", "Actinobacteria", "Actinobacteridae", "Propionibacterineae", "Propionibacterium"],
                [
                    "Bacteria",
                    "Firmicutes",
                    "Alicyclobacillaceae",
                    "Bacilli",
                    "Lactobacillales",
                    "Lactobacillales",
                    "Streptococcaceae",
                    "Streptococcus",
                ],
                ["Bacteria", "Actinobacteria", "Actinobacteridae", "Gordoniaceae", "Corynebacteriaceae"],
                ["Bacteria", "Firmicutes", "Alicyclobacillaceae", "Bacilli", "Staphylococcaceae"],
                ["Bacteria", "Cyanobacteria", "Chloroplasts", "vectors"],
            ],
        )

        # because float comps in arrays always errors
        self.assertEqual(obs[0], exp[0])
        self.assertEqual(obs[1], exp[1])
        self.assertEqual(obs[3], exp[3])
        self.assertTrue(all((obs[2] == exp[2]).tolist()))
    def test_parse_classic_otu_table_legacy(self):
        """parse_classic_otu_table functions as expected with legacy OTU table
        """
        data = self.legacy_otu_table1
        data_f = data.split("\n")
        obs = parse_classic_otu_table(data_f)
        exp = (
            ["Fing", "Key", "NA"],
            ["0", "1", "2", "3", "4"],
            array([[19111, 44536, 42], [1216, 3500, 6], [1803, 1184, 2], [1722, 4903, 17], [589, 2074, 34]]),
            self.expected_lineages1,
        )

        # divide the comparisons into their four elements
        self.assertEqual(obs[0], exp[0])
        self.assertEqual(obs[1], exp[1])
        assert_almost_equal(obs[2], exp[2])
        self.assertEqual(obs[3], exp[3])
    def test_parse_classic_otu_table_consensus_lineage(self):
        """parse_classic_otu_table should accept 'consensusLineage'"""
        data = """#Full OTU Counts
#OTU ID	Fing	Key	NA	consensusLineage
0	19111	44536	42	Bacteria; Actinobacteria; Actinobacteridae; Propionibacterineae; Propionibacterium
1	1216	3500	6	Bacteria; Firmicutes; Alicyclobacillaceae; Bacilli; Lactobacillales; Lactobacillales; Streptococcaceae; Streptococcus
2	1803	1184	2	Bacteria; Actinobacteria; Actinobacteridae; Gordoniaceae; Corynebacteriaceae
3	1722	4903	17	Bacteria; Firmicutes; Alicyclobacillaceae; Bacilli; Staphylococcaceae
4	589	2074	34	Bacteria; Cyanobacteria; Chloroplasts; vectors"""
        data_f = StringIO(data)
        obs = parse_classic_otu_table(data_f)
        exp = (
            ["Fing", "Key", "NA"],
            ["0", "1", "2", "3", "4"],
            array([[19111, 44536, 42], [1216, 3500, 6], [1803, 1184, 2], [1722, 4903, 17], [589, 2074, 34]]),
            [
                ["Bacteria", "Actinobacteria", "Actinobacteridae", "Propionibacterineae", "Propionibacterium"],
                [
                    "Bacteria",
                    "Firmicutes",
                    "Alicyclobacillaceae",
                    "Bacilli",
                    "Lactobacillales",
                    "Lactobacillales",
                    "Streptococcaceae",
                    "Streptococcus",
                ],
                ["Bacteria", "Actinobacteria", "Actinobacteridae", "Gordoniaceae", "Corynebacteriaceae"],
                ["Bacteria", "Firmicutes", "Alicyclobacillaceae", "Bacilli", "Staphylococcaceae"],
                ["Bacteria", "Cyanobacteria", "Chloroplasts", "vectors"],
            ],
        )
        # because float comps in arrays always errors
        self.assertEqual(obs[0], exp[0])
        self.assertEqual(obs[1], exp[1])
        self.assertEqual(obs[3], exp[3])
        self.assertTrue(all((obs[2] == exp[2]).tolist()))