def test_taxa_by_level(self):
        """ Test the taxa by level function """

        taxa = ["k__k1;p__p1;c__c1", "k__k1;p__p1;c__c2", "k__k1;p__p2;c__c3"]
        data = [[1, 2], [1, 2], [1, 2]]
        expected_taxa = ["k__k1;p__p1", "k__k1;p__p2"]
        expected_data = [[2, 4], [1, 2]]

        actual_taxa, actual_data = utilities.taxa_by_level(taxa, data, 1)

        self.assertEqual(actual_taxa, expected_taxa)
        self.assertEqual(actual_data, expected_data)
    def test_taxa_by_level_kingdom(self):
        """ Test the taxa by level function set to merge to kingdom level"""

        taxa = ["k__k1;p__p1;c__c1", "k__k1;p__p1;c__c2", "k__k1;p__p2;c__c3"]
        data = [[1, 2], [1, 2], [1, 2]]
        expected_taxa = ["k__k1"]
        expected_data = [[3, 6]]

        actual_taxa, actual_data = utilities.taxa_by_level(taxa, data, 0)

        self.assertEqual(actual_taxa, expected_taxa)
        self.assertEqual(actual_data, expected_data)
    def test_taxa_by_level_unknown(self):
        """ Test the taxa by level function with one taxon that does not include that level"""

        taxa = ["k__k1;p__p1", "k__k1;p__p1;c__c2", "k__k1;p__p2;c__c3"]
        data = [[1, 2], [1, 2], [1, 2]]
        expected_taxa = ["k__k1;p__p1;c__c2", "k__k1;p__p2;c__c3"]
        expected_data = [[1, 2], [1, 2]]

        actual_taxa, actual_data = utilities.taxa_by_level(taxa, data, 2)

        self.assertEqual(sorted(actual_taxa), sorted(expected_taxa))
        self.assertEqual(actual_data, expected_data)
    def test_taxa_by_level_strain_missing(self):
        """ Test the taxa by level function set to merge to strain level
            though there is no strain level input data """

        taxa = [
            "k__k1;p__p1;c__c1;o__o1;f__f1;g__g1;s__s1", "k__k1;p__p1;c__c2"
        ]
        data = [[1, 2], [1, 2]]
        expected_taxa = []
        expected_data = []

        actual_taxa, actual_data = utilities.taxa_by_level(taxa, data, 7)

        self.assertEqual(actual_taxa, expected_taxa)
        self.assertEqual(actual_data, expected_data)
    def test_taxa_by_level_strain(self):
        """ Test the taxa by level function set to merge to strain level"""

        taxa = [
            "k__k1;p__p1;c__c1;o__o1;f__f1;g__g1;s__s1;t__t1",
            "k__k1;p__p1;c__c2"
        ]
        data = [[1, 2], [1, 2]]
        expected_taxa = ["k__k1;p__p1;c__c1;o__o1;f__f1;g__g1;s__s1;t__t1"]
        expected_data = [[1, 2]]

        actual_taxa, actual_data = utilities.taxa_by_level(taxa, data, 7)

        self.assertEqual(actual_taxa, expected_taxa)
        self.assertEqual(actual_data, expected_data)