<commit_before>
import numpy 
import pandas 
import matplotlib.pyplot as plt

import bz2 
import cPickle 

from scipy.signal import argrelextrema


def plot_distance_matrix(distance_csv_file, outfile="similarity_matrix_plot.pdf"):
    """
    plotting distance matrix between organisms 

    the distance between the organisms are calculated based on the difference in their sequence composition 
    """

    import pylab 

    distance = pandas.read_csv(distance_csv_file, header=0)
    C = numpy.tril(distance)
    sim = 1-distance
    C = numpy.tril(sim)
    N = sim.shape[1]
    C = numpy.ma.masked_array(C, C == 0)

    A = numpy.array([(y, x) for x in range(N, -1, -1) for y in range(N + 1)])
    t = numpy.array([[0.5, 1], [0.5, -1]])
    A = numpy.dot(A, t)
    X = A[:, 1].reshape(N + 1, N + 1)
    Y = A[:, 0].reshape(N + 1, N + 1)
    fig = pylab.figure(figsize=(20,20))
    ax = fig.add_subplot(121, frame_on=False, aspect=2.0)
    ax.set_xticks([])
    ax.set_yticks([])
    caxes = pylab.pcolormesh(X, Y, np.flipud(C), axes=ax)
    ax.set_xlim(right=0)
    fig.savefig(outfile, bbox_inches='tight')


def bar_chart_auroc(file, fout_name, plot_title="performance"):
    """
    plot a bar chart based on the test performance from diff CV
    """

    ## loading the data 
    data = data_process(file)

    method = 'individual'
    org_code = 'H_sapiens'
    numb_cvs =  len(data[method][0][org_code])

    ## fetching the best performance based on the validation and test 
    best_eval = numpy.argmax(data[method][0][org_code], axis=1)
    test_perf = numpy.zeros(numb_cvs) 
    for idx, v_idx in enumerate(best_eval):
        test_perf[idx] = data[method][1][org_code][idx][v_idx]

    ## plot settings 
    import pylab
    pylab.figure(figsize=(5,4))
    pylab.rcParams.update({'figure.autolayout':True})

    offset = 0 
    width = 0.10
    seperator = 0.10 

    xlocations = [] 
    min_max = [] 
    rects = [] 

    x_axis_marks = []
    for idk, ele in enumerate(test_perf):
        xlocations.append(offset + 0.05)
        min_max.append(ele) 
        rects.append(pylab.bar(offset, ele, width, color="#73C6B6", edgecolor="white"))
        offset += width

        idk += 1 
        cvname = "fold_%d" % idk
        x_axis_marks.append(cvname) 
        
    ## mean bar 
    rects.append(pylab.bar(offset, test_perf.mean(), width, color="#EC7063", edgecolor="white")) 
    xlocations.append(offset + 0.05)
    offset += width

    x_axis_marks.append('mean')

    ## adjusting the axis range 
    min_max.sort()
    ymax = min_max[-1]*1.05 
    ymin = min_max[0]*0.98

    ## set the ticks
    tick_step = 0.02 
    ticks = [tick_step*i for i in xrange(int(round(ymax/tick_step)+1))]<commit_msg>adjust the plotting y axis tick points<commit_after>
import numpy 
import pandas 
import matplotlib.pyplot as plt

import bz2 
import cPickle 

from scipy.signal import argrelextrema


def plot_distance_matrix(distance_csv_file, outfile="similarity_matrix_plot.pdf"):
    """
    plotting distance matrix between organisms 

    the distance between the organisms are calculated based on the difference in their sequence composition 
    """

    import pylab 

    distance = pandas.read_csv(distance_csv_file, header=0)
    C = numpy.tril(distance)
    sim = 1-distance
    C = numpy.tril(sim)
    N = sim.shape[1]
    C = numpy.ma.masked_array(C, C == 0)

    A = numpy.array([(y, x) for x in range(N, -1, -1) for y in range(N + 1)])
    t = numpy.array([[0.5, 1], [0.5, -1]])
    A = numpy.dot(A, t)
    X = A[:, 1].reshape(N + 1, N + 1)
    Y = A[:, 0].reshape(N + 1, N + 1)
    fig = pylab.figure(figsize=(20,20))
    ax = fig.add_subplot(121, frame_on=False, aspect=2.0)
    ax.set_xticks([])
    ax.set_yticks([])
    caxes = pylab.pcolormesh(X, Y, np.flipud(C), axes=ax)
    ax.set_xlim(right=0)
    fig.savefig(outfile, bbox_inches='tight')


def bar_chart_auroc(file, fout_name, plot_title="performance"):
    """
    plot a bar chart based on the test performance from diff CV
    """

    ## loading the data 
    data = data_process(file)

    method = 'individual'
    org_code = 'H_sapiens'
    numb_cvs =  len(data[method][0][org_code])

    ## fetching the best performance based on the validation and test 
    best_eval = numpy.argmax(data[method][0][org_code], axis=1)
    test_perf = numpy.zeros(numb_cvs) 
    for idx, v_idx in enumerate(best_eval):
        test_perf[idx] = data[method][1][org_code][idx][v_idx]

    ## plot settings 
    import pylab
    pylab.figure(figsize=(5,4))
    pylab.rcParams.update({'figure.autolayout':True})

    offset = 0 
    width = 0.10
    seperator = 0.10 

    xlocations = [] 
    min_max = [] 
    rects = [] 

    x_axis_marks = []
    for idk, ele in enumerate(test_perf):
        xlocations.append(offset + 0.05)
        min_max.append(ele) 
        rects.append(pylab.bar(offset, ele, width, color="#73C6B6", edgecolor="white"))
        offset += width

        idk += 1 
        cvname = "fold_%d" % idk
        x_axis_marks.append(cvname) 
        
    ## mean bar 
    rects.append(pylab.bar(offset, test_perf.mean(), width, color="#EC7063", edgecolor="white")) 
    xlocations.append(offset + 0.05)
    offset += width

    x_axis_marks.append('mean')

    ## adjusting the axis range 
    min_max.sort()

    ymax = min_max[-1]*1.03 
    ymin = min_max[0]*0.98

    ## set the ticks
    tick_step = 0.01 
    ticks = [tick_step*i for i in xrange(int(round(ymax/tick_step)+1))]
{'fraction_non_alphanumeric': 0.13486842105263158, 'fraction_numerical': 0.025584795321637425, 'mean_word_length': 2.9261119081779055, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5431199', 'n_tokens_mistral': 2150, 'n_tokens_neox': 1977, 'n_words': 455}