def test_terminal_taxa_duplicate(self):
        """ Test the terminal taxa function with two duplicate terminal taxa"""

        taxa = [
            "k__k1;p__p1", "k__k1;p__p1;c__c1", "k__k2;p__p2",
            "k__k3;p__p3;c__c2;o__o3", "k__k3;p__p3;c__c2;o__o3"
        ]
        data = [[1], [2], [3], [4], [5]]

        # it is expected that order of the taxa will stay the same as the original input
        expected_taxa = [
            "k__k1;p__p1;c__c1", "k__k2;p__p2", "k__k3;p__p3;c__c2;o__o3"
        ]
        expected_data = [[2], [3], [9]]

        actual_taxa, actual_data = utilities.terminal_taxa(taxa, data)

        self.assertEqual(actual_taxa, expected_taxa)
        self.assertEqual(actual_data, expected_data)
    def test_terminal_taxa_unclassified_species(self):
        """ Test the terminal taxa function with a taxon with unclassified at species level"""

        taxa = [
            "k__k3;p__p3;c__c2;o__o3;f__f1;g__g1;s__",
            "k__k3;p__p3;c__c2;o__o3;f__f1;g__g1;s__s1"
        ]
        data = [[1], [2]]

        # it is expected that order of the taxa will stay the same as the original input
        expected_taxa = [
            "k__k3;p__p3;c__c2;o__o3;f__f1;g__g1;s__",
            "k__k3;p__p3;c__c2;o__o3;f__f1;g__g1;s__s1"
        ]
        expected_data = [[1], [2]]

        actual_taxa, actual_data = utilities.terminal_taxa(taxa, data)

        self.assertEqual(actual_taxa, expected_taxa)
        self.assertEqual(actual_data, expected_data)
    def test_terminal_taxa_unclassified_family(self):
        """ Test the terminal taxa function with a taxon with unclassified at family level"""

        taxa = [
            "k__k1;p__p1", "k__k1;p__p1;c__c1", "k__k2;p__p2",
            "k__k3;p__p3;c__c2;o__o3;f__;g__;s__",
            "k__k3;p__p3;c__c2;o__o3;f__f1"
        ]
        data = [[1], [2], [3], [4], [5]]

        # it is expected that order of the taxa will stay the same as the original input
        expected_taxa = [
            "k__k1;p__p1;c__c1", "k__k2;p__p2",
            "k__k3;p__p3;c__c2;o__o3;f__;g__;s__",
            "k__k3;p__p3;c__c2;o__o3;f__f1"
        ]
        expected_data = [[2], [3], [4], [5]]

        actual_taxa, actual_data = utilities.terminal_taxa(taxa, data)

        self.assertEqual(actual_taxa, expected_taxa)
        self.assertEqual(actual_data, expected_data)
Beispiel #4
0
    vars,
    sorted_samples,
    sorted_top_data_plus_other,
    top_taxa_short_names_plus_other,
    max_taxa,
    feature="genera")

#' <% if pdf_format: print("\clearpage") %>

#' ## Terminal Taxa

#+ echo=False

# plot the relative abundance of the top terminal taxa
# get the terminal taxa
terminal_taxa_relab, terminal_data_relab = utilities.terminal_taxa(
    taxonomy, relab_data)
# get the top rows of terminal taxa
top_terminal_taxa, top_terminal_data = utilities.top_rows(terminal_taxa_relab,
                                                          terminal_data_relab,
                                                          max_taxa,
                                                          function="average")

# reduce the taxa names to just the most specific identifier
shorted_names = utilities.taxonomy_trim(top_terminal_taxa)

# sort the data with the samples with the top terminal taxa first
sorted_samples_terminal, sorted_data_terminal = utilities.sort_data(
    top_terminal_data[0], samples)
transpose_top_terminal_data = numpy.transpose(top_terminal_data)
sorted_top_terminal_data = numpy.transpose([
    transpose_top_terminal_data[samples.index(sample)]