<commit_before>## Copyright (C) 2012-2013 <NAME>
## Computational Genomics Group (http://bioinformatics.bris.ac.uk/)
## Department of Computer Science
## University of Bristol

## NOTE: Based on code found in the following link: http://stackoverflow.com/questions/2455761/reordering-matrix-elements-to-reflect-column-and-row-clustering-in-naiive-python/3017704#3017704

################################################################################

import numpy                    as np
import pylab                    as pl
import matplotlib.gridspec      as gr
import scipy.cluster.hierarchy  as hr

################################################################################

def plotHeatmap(D, method = 'average', metric = 'euclidean', xticklabels = None, yticklabels = None, cmap = pl.cm.coolwarm): 
    grid = gr.GridSpec(2,2, width_ratios=[1,3.5], height_ratios=[1,3.5], wspace=0, hspace=0)
    
    ## normalize D
    D = ( D - D.min() ) / ( D.max() - D.min() )
        
    # Compute and plot first dendrogram
    ax2 = pl.subplot(grid[1])
    Y2  = hr.linkage(D, method = method, metric = metric);
    Z2  = hr.dendrogram(Y2)
    ax2.set_xticks([])
    ax2.set_yticks([])
    ax2.set_frame_on(False)

    # Compute and plot second dendrogram
    ax1 = pl.subplot(grid[2]); 
    Y1  = hr.linkage(D, method = method, metric = metric);
    Z1  = hr.dendrogram(Y1, orientation = 'right')
    ax1.set_xticks([])
    ax1.set_yticks([])
    ax1.set_frame_on(False)
    
    # Plot distance matrix
    axmatrix = pl.subplot(grid[3])
    idx1 = Z1['leaves']
    idx2 = Z2['leaves']
    yticklabels = np.asarray(yticklabels)[idx2].tolist()
    xticklabels = np.asarray(xticklabels)[idx1].tolist()
    D    = D[idx1,:]
    D    = D[:,idx2]
    
    im = axmatrix.matshow(D, aspect = 'auto', origin = 'lower', cmap = cmap)   
    axmatrix.set_xticks(range(len(xticklabels)))
    axmatrix.set_yticks(range(len(yticklabels)))<commit_msg>Minor changes<commit_after>## Copyright (C) 2012-2013 <NAME>
## Computational Genomics Group (http://bioinformatics.bris.ac.uk/)
## Department of Computer Science
## University of Bristol

## NOTE: Based on code found in the following link: http://stackoverflow.com/questions/2455761/reordering-matrix-elements-to-reflect-column-and-row-clustering-in-naiive-python/3017704#3017704

################################################################################

import numpy                    as np
import pylab                    as pl
import matplotlib.gridspec      as gr
import scipy.cluster.hierarchy  as hr

################################################################################

def plotHeatmap(D, method = 'average', metric = 'euclidean', xticklabels = None, yticklabels = None, cmap = pl.cm.coolwarm): 
    grid = gr.GridSpec(2, 2, width_ratios=[1,3.5], height_ratios=[1,3.5], wspace=0, hspace=0)

    # Compute and plot y-axis dendrogram
    ax1 = pl.subplot(grid[2]); 
    Y1  = hr.linkage(D, method = method, metric = metric);
    Z1  = hr.dendrogram(Y1, orientation = 'right')
    ax1.set_xticks([])
    ax1.set_yticks([])
    ax1.set_frame_on(False)
                
    # Compute and plot x-axis dendrogram
    ax2 = pl.subplot(grid[1])
    Y2  = Y1 
    Z2  = hr.dendrogram(Y2)
    ax2.set_xticks([])
    ax2.set_yticks([])
    ax2.set_frame_on(False)

    # Plot distance matrix
    axmatrix = pl.subplot(grid[3])
    idx1 = Z1['leaves']
    idx2 = Z2['leaves']
    yticklabels = np.asarray(yticklabels)[idx2].tolist()
    xticklabels = np.asarray(xticklabels)[idx1].tolist()
    D = D[idx1,:]
    D = D[:,idx2]
    
    im = axmatrix.matshow(D, aspect = 'auto', origin = 'lower', cmap = cmap)   
    axmatrix.set_xticks(range(len(xticklabels)))
    axmatrix.set_yticks(range(len(yticklabels)))
{'fraction_non_alphanumeric': 0.21381142098273573, 'fraction_numerical': 0.034262948207171316, 'mean_word_length': 3.5047846889952154, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6509753', 'n_tokens_mistral': 1363, 'n_tokens_neox': 1264, 'n_words': 254}