def test_taxa_file(self): filtered_sample_ids, taxa_labels, collapsed_taxa_table = \ get_filtered_taxa_summary(TEST_MAPPING_FILE, TEST_TAXA_FILE, self.metadata_category, self.metadata_value, select_taxa=self.taxa_ids) # Make sure we only get out the matching sample self.assertEqual(len(filtered_sample_ids), 1) self.assertEqual(filtered_sample_ids[0], 'sample_a') # Should get back our desired labels + "Others" self.assertEqual(set(self.taxa_labels), set(taxa_labels)) # Should get the slide of the table corresponding to the matching # sample npt.assert_equal(collapsed_taxa_table, self.table[:, 0, None])
# Sample ticks to be labeled in the stack plot if args.samples_file: special_labels = get_sample_ids_to_label(args.samples_file) else: special_labels = [] # Specify taxa, otherwise the top N most abundant if args.key_taxa_file: select_taxa = get_key_taxa(args.key_taxa_file) else: select_taxa = None filtered_sample_ids, taxa_labels, collapsed_taxa_table = \ get_filtered_taxa_summary(args.mapping_file, args.taxa_file, args.metadata_category, args.metadata_value, select_taxa=select_taxa) colors = brewer2mpl.get_map('Spectral', 'Diverging', len(taxa_labels)).mpl_colors # Create stack plot output = args.output_prefix + 'stack.' + args.output_type make_stacked_plot(output, filtered_sample_ids, taxa_labels, collapsed_taxa_table, args.ylabel, colors, sample_ticks=special_labels) # Create pie chart output = args.output_prefix + 'pie.' + args.output_type make_pie_chart(output, collapsed_taxa_table, colors)