def format_barplots(table: biom.Table, normalize: bool): barplots = [] barplots.append('DATASET_MULTIBAR') barplots.append('SEPARATOR TAB') barplots.append('DATASET_LABEL\tRelative Abundance') if normalize: table = table.norm(axis='observation', inplace=False) table = table.to_dataframe(dense=True) field_labels = list(table.columns) field_colors = values_to_colors(field_labels, 'husl').values() barplots.append('FIELD_COLORS\t' + '\t'.join(field_colors)) barplots.append('FIELD_LABELS\t' + '\t'.join(field_labels)) barplots.append('LEGEND_TITLE\tRelative Abundance') barplots.append('LEGEND_SHAPES\t' + '\t'.join(['1'] * len(field_colors))) barplots.append('LEGEND_COLORS\t' + '\t'.join(field_colors)) barplots.append('LEGEND_LABELS\t' + '\t'.join(field_labels)) barplots.append('WIDTH\t100') barplots.append('DATA') table = table.reset_index() for idx in table.index: barplots.append('\t'.join(table.loc[idx].apply(str))) return '\n'.join(barplots)