def plot_heatmap(df_confusion, sample_id, output_dir, label, separate_bar=False, log_scale=False):
    if log_scale:
        df_confusion = df_confusion.apply(np.log10, inplace=True).replace(-np.inf, 0)
    fig, axs = plt.subplots(figsize=(10, 8))
    fontsize = 20

    # replace columns and rows labels by numbers
    d = {value: key for (key, value) in enumerate(df_confusion.columns.tolist(), 1)}
    df_confusion = df_confusion.rename(index=str, columns=d)
    df_confusion.index = range(1, len(df_confusion) + 1)

    xticklabels = int(round(df_confusion.shape[1] / 10, -1))
    yticklabels = int(round(df_confusion.shape[0] / 10, -1))
    sns_plot = sns.heatmap(df_confusion, ax=axs, annot=False, cmap="YlGnBu_r", xticklabels=xticklabels, yticklabels=yticklabels, cbar=False, rasterized=True)

    # sns_plot = sns.heatmap(df_confusion, ax=axs, annot=False, cmap="YlGnBu_r", xticklabels=False, yticklabels=False, cbar=True, rasterized=True)
    sns_plot.set_xlabel("Genomes", fontsize=fontsize)
    sns_plot.set_ylabel("Predicted bins", fontsize=fontsize)
    plt.yticks(fontsize=12, rotation=0)
    plt.xticks(fontsize=12)

    mappable = sns_plot.get_children()[0]

    cbar_ax = fig.add_axes([.915, .11, .017, .77])
    cbar = plt.colorbar(mappable, ax=axs, cax=cbar_ax, orientation='vertical')
    if log_scale:
        cbar.set_label(fontsize=fontsize, label='log$_{10}$(# bp)')
    else:
        fmt = lambda x, pos: '{:.0f}'.format(x / 1000000)
        cbar = plt.colorbar(mappable, ax=axs, cax=cbar_ax, orientation='vertical', format=ticker.FuncFormatter(fmt))
        cbar.set_label(fontsize=fontsize, label='Millions of base pairs')

    cbar.ax.tick_params(labelsize=fontsize)
    cbar.outline.set_edgecolor(None)

    axs.set_title(label, fontsize=fontsize, pad=10)

    axs.set_ylim([len(df_confusion), 0])

    # plt.yticks(fontsize=14, rotation=0)
    # plt.xticks(fontsize=14)

    output_dir = os.path.join(output_dir, 'genome', label)

    fig.savefig(os.path.join(output_dir, 'heatmap_' + sample_id + '.pdf'), dpi=100, format='pdf', bbox_inches='tight')
    fig.savefig(os.path.join(output_dir, 'heatmap_' + sample_id + '.png'), dpi=200, format='png', bbox_inches='tight')
    plt.close(fig)

    if not separate_bar:
        return

    # create separate figure for bar
    fig = plt.figure(figsize=(6, 6))
    mappable = sns_plot.get_children()[0]
    fmt = lambda x, pos: '{:.0f}'.format(x / 1000000)

    cbar = plt.colorbar(mappable, orientation='vertical', label='[millions of base pairs]', format=ticker.FuncFormatter(fmt))

    text = cbar.ax.yaxis.label
    font = matplotlib.font_manager.FontProperties(size=16)
    text.set_font_properties(font)

    cbar.outline.set_visible(False)
    cbar.ax.tick_params(labelsize=14)

    # store separate bar figure
    plt.gca().set_visible(False)
    fig.savefig(os.path.join(output_dir, 'heatmap_bar.pdf'), dpi=100, format='pdf', bbox_inches='tight')

    plt.close(fig)