<commit_before>
var color_scale_colors = {}

color_scale_colors.red = {red:255, green:0, blue: 0};
color_scale_colors.red = {red:195, green:74, blue: 54};
color_scale_colors.blue = {red:0, green:0, blue: 255};
color_scale_colors.blue = {red:0, green:140, blue: 204};
color_scale_colors.green = {red:0, green:255, blue: 0};
color_scale_colors.green = {red:0, green:201, blue: 167};
color_scale_colors.white = {red:255, green:255, blue: 255};
color_scale_colors.yellow = {red:255, green:255, blue: 0};
color_scale_colors.yellow = {red:255, green:255, blue: 0};
color_scale_colors.black = { red: 0, green: 0, blue: 0 };
color_scale_colors.orange = { red: 255, green: 150, blue: 113 };
color_scale_colors.purple = { red: 128, green: 0, blue: 128 };
color_scale_colors.false = false;

function color_by_category(value, possibilities) {
    rgb = d3.rgb(d3.interpolateSpectral(value / possibilities));
    return rgb.hex();
}

function color_by_scale(scale, color1, color2, color3) {

    // case "rwb": // red-white-blue
    // case "bwr": // blue-white-red
    // case "ryg": // red-yellow-green
    // case "gyr": // green-yellow-red
    // case "rgb":
    // case "wr": // white-red
    // case "wg": // white-green
    // case "wb": // white-blue
    // case "rb": // red-blue
    // case "br": // blue-red
    // case "wp": // white-purple
    // case "grey": // grey

    // return numberToColorGradient(scale, 1, color)

    // var colors = {}

    // colors.red = {red:255, green:0, blue: 0};
    // colors.red = {red:195, green:74, blue: 54};
    // colors.blue = {red:0, green:0, blue: 255};
    // colors.blue = {red:0, green:140, blue: 204};
    // colors.green = {red:0, green:255, blue: 0};
    // colors.green = {red:0, green:201, blue: 167};
    // colors.white = {red:255, green:255, blue: 255};
    // colors.yellow = {red:255, green:255, blue: 0};
    // colors.yellow = {red:255, green:255, blue: 0};
    // colors.black = { red: 0, green: 0, blue: 0 };
    // colors.orange = { red: 255, green: 150, blue: 113 };
    // colors.purple = { red: 128, green: 0, blue: 128 };
    // colors.false = false;
    
    return colorGradient(scale, color_scale_colors[color1], color_scale_colors[color2], color_scale_colors[color3])
}

function createSnakeplot(data, containerSelector) {


    $(containerSelector).html('')
    $(containerSelector).addClass("snakeplot");
    $(containerSelector).css("position","relative");

    $(containerSelector).html(data['snakeplot']);

    max_x = $(containerSelector).find("svg").attr("width");
    max_y = $(containerSelector).find("svg").attr("height");
    
    var svgContainer = $(containerSelector).find("svg").closest("svg")
        .attr("viewBox", 0 + " " + 0 + " " + (max_x) + " " + (max_y))
        .attr("width", "100%")
        .attr("style", "height: 500px");
    
    $(containerSelector).find(".long").hide();
    maxmin();
    create_legend();

    $(containerSelector).find("text").tooltip({
        'container': 'body',
        'placement': 'top',
        'animation': false,
        'html' : true
    });

    $(containerSelector).find("circle").tooltip({
        'container': 'body',
        'placement': 'top',
        'animation': false,
        'html' : true
    });

    $(containerSelector).find("circle").hover(function(){
        $('.tooltip').css('top',parseInt($('.tooltip').css('top')) + 2.8 + 'px')
    });

    var colors = {}
    colors['distance'] = {}
    colors['distance_abs'] = {}
    colors['network'] = {}
    colors['set_presence'] = {}
    colors['ligand'] = {}
    colors['complex'] = {}
    colors['mutations'] = {}
    colors['conservation'] = {}

    index_names = { 0: 'core_distance', 1: 'a_angle', 2: 'outer_angle', 3: 'tau', 4: 'phi', 5: 'psi', 6: 'sasa', 7: 'rsa', 8: 'theta', 9: 'hse', 10: 'tau_angle', 11:'rotation_angle' }
    neg_and_positives = ['core_distance','sasa','rsa', 'hse']
    nice_index_names = {
        'a_angle' : 'Angle to helix&7TM axes',
        'outer_angle': 'Rotamer',
        'rotation_angle': 'Rotation angle',
        'tau': 'Tau',
        'phi': 'Phi',
        'psi': 'Psi',
        'sasa': 'SASA',
        'sasa_abs': 'SASA (abs)',
        'rsa': 'RSA',
        'rsa_abs': 'RSA (abs)',
        'theta': 'Theta',
        'hse': 'HSE',
        'hse_abs': 'HSE (abs)',
        'tau_angle': 'Tau dihedral',
        'distance': 'Distance',
        'distance_abs': 'Distance (abs)',
        'core_distance': 'Distance to 7TM axis',
        'core_distance_abs': 'Distance to 7TM axis (abs)',  
        'network' : 'Network group no.',
        'set_presence' : 'Set specific presense',
        'ligand' : 'Ligand interactions freq',
        'complex' : 'G protein interactions',
        'mutations' : 'Mutations with >5 fold effect',
        'conservation' : 'Conservation of set(s) consensus AA in class'
    }
    path_groups = {}
    path_groups_lookup = {}
    $(containerSelector).find('.helix_path').each(function () {
        path_id = $(this).attr('id');
        res_ids = $(this).attr('previous_res');
        path_groups[path_id] = { 'distance': [], 'distance_abs': [] };
        
        $.each(index_names, function (i, name) {
            path_groups[path_id][name] = [];
            if (neg_and_positives.includes(name)) {
                path_groups[path_id][name+"_abs"] = [];
            }
        })

        $.each(res_ids.split(","), function (i, res_id) {
            path_groups_lookup[res_id] = path_id;
        });
    });

    $.each(data['snakeplot_lookup_aa_cons'], function (gn, cons) {
        seq_pos = data['snakeplot_lookup'][gn];
        scale = cons / 100
        colors['conservation'][seq_pos] = [cons,scale,100];
    } )


    $.each(filtered_cluster_groups, function (id, group) {
        $.each(group, function (i, gn) {
            seq_pos = data['snakeplot_lookup'][gn];
            scale = id / filtered_cluster_groups.length
            colors['network'][seq_pos] = [id,scale,filtered_cluster_groups.length];
        })
    })

    $.each(filtered_gns_presence, function (gn, value) {
        seq_pos = data['snakeplot_lookup'][gn];
        scale = value / 1
        colors['set_presence'][seq_pos] = [value,scale,1];
    })

    max_ligand_interactions = Math.max(...Object.values(data['class_ligand_interactions'])) 
    $.each(data['class_ligand_interactions'], function (gn, value) {
        seq_pos = data['snakeplot_lookup'][gn];
        scale = value / max_ligand_interactions;
        colors['ligand'][seq_pos] = [value,scale,max_ligand_interactions];
    })


    max_complex_interactions = Math.max(...Object.values(data['class_complex_interactions'])) 
    $.each(data['class_complex_interactions'], function (gn, value) {
        seq_pos = data['snakeplot_lookup'][gn];
        scale = value / max_complex_interactions;
        colors['complex'][seq_pos] = [value,scale,max_complex_interactions];
    })

    max_mutations = Math.max(...Object.values(data['class_mutations'])) 
    $.each(data['class_mutations'], function (gn, value) {
        seq_pos = data['snakeplot_lookup'][gn];
        scale = value / max_mutations;
        colors['mutations'][seq_pos] = [value,scale,max_mutations];
    })

    $.each(data['distances'], function (gn, dis) {
        seq_pos = data['snakeplot_lookup'][gn];
        // console.log(gn, dis['avg'], seq_pos);
        value = dis['avg'];
        scale = Math.abs(value) / data['ngl_max_diff_distance'];
        if (value < 0) {
            // if the header is a set two, then make it red
            scale_abs = (1-scale)*0.5;
        } else if (value >= 0) {<commit_msg>Small changes to snakeplot for David<commit_after>
var color_scale_colors = {}

color_scale_colors.red = {red:255, green:0, blue: 0};
color_scale_colors.red = {red:195, green:74, blue: 54};
color_scale_colors.blue = {red:0, green:0, blue: 255};
color_scale_colors.blue = {red:0, green:140, blue: 204};
color_scale_colors.green = {red:0, green:255, blue: 0};
color_scale_colors.green = {red:0, green:201, blue: 167};
color_scale_colors.white = {red:255, green:255, blue: 255};
color_scale_colors.yellow = {red:255, green:255, blue: 0};
color_scale_colors.yellow = {red:255, green:255, blue: 0};
color_scale_colors.black = { red: 0, green: 0, blue: 0 };
color_scale_colors.orange = { red: 255, green: 150, blue: 113 };
color_scale_colors.purple = { red: 128, green: 0, blue: 128 };
color_scale_colors.false = false;

function color_by_category(value, possibilities) {
    rgb = d3.rgb(d3.interpolateSpectral(value / possibilities));
    return rgb.hex();
}

function color_by_scale(scale, color1, color2, color3) {

    // case "rwb": // red-white-blue
    // case "bwr": // blue-white-red
    // case "ryg": // red-yellow-green
    // case "gyr": // green-yellow-red
    // case "rgb":
    // case "wr": // white-red
    // case "wg": // white-green
    // case "wb": // white-blue
    // case "rb": // red-blue
    // case "br": // blue-red
    // case "wp": // white-purple
    // case "grey": // grey

    // return numberToColorGradient(scale, 1, color)

    // var colors = {}

    // colors.red = {red:255, green:0, blue: 0};
    // colors.red = {red:195, green:74, blue: 54};
    // colors.blue = {red:0, green:0, blue: 255};
    // colors.blue = {red:0, green:140, blue: 204};
    // colors.green = {red:0, green:255, blue: 0};
    // colors.green = {red:0, green:201, blue: 167};
    // colors.white = {red:255, green:255, blue: 255};
    // colors.yellow = {red:255, green:255, blue: 0};
    // colors.yellow = {red:255, green:255, blue: 0};
    // colors.black = { red: 0, green: 0, blue: 0 };
    // colors.orange = { red: 255, green: 150, blue: 113 };
    // colors.purple = { red: 128, green: 0, blue: 128 };
    // colors.false = false;
    
    return colorGradient(scale, color_scale_colors[color1], color_scale_colors[color2], color_scale_colors[color3])
}

function createSnakeplot(data, containerSelector) {


    $(containerSelector).html('')
    $(containerSelector).addClass("snakeplot");
    $(containerSelector).css("position","relative");

    $(containerSelector).html(data['snakeplot']);

    max_x = $(containerSelector).find("svg").attr("width");
    max_y = $(containerSelector).find("svg").attr("height");
    
    var svgContainer = $(containerSelector).find("svg").closest("svg")
        .attr("viewBox", 0 + " " + 0 + " " + (max_x) + " " + (max_y))
        .attr("width", "100%")
        .attr("style", "height: 500px");
    
    $(containerSelector).find(".long").hide();
    maxmin();
    create_legend();

    $(containerSelector).find("text").tooltip({
        'container': 'body',
        'placement': 'top',
        'animation': false,
        'html' : true
    });

    $(containerSelector).find("circle").tooltip({
        'container': 'body',
        'placement': 'top',
        'animation': false,
        'html' : true
    });

    $(containerSelector).find("circle").hover(function(){
        $('.tooltip').css('top',parseInt($('.tooltip').css('top')) + 2.8 + 'px')
    });

    var colors = {}
    colors['distance'] = {}
    colors['distance_abs'] = {}
    colors['network'] = {}
    colors['set_presence'] = {}
    colors['ligand'] = {}
    colors['complex'] = {}
    colors['ligandcomplex'] = {}
    colors['mutations'] = {}
    colors['conservation'] = {}

    index_names = { 0: 'core_distance', 1: 'a_angle', 2: 'outer_angle', 3: 'tau', 4: 'phi', 5: 'psi', 6: 'sasa', 7: 'rsa', 8: 'theta', 9: 'hse', 10: 'tau_angle', 11:'rotation_angle' }
    neg_and_positives = ['core_distance','sasa','rsa', 'hse']
    nice_index_names = {
        'a_angle' : 'Angle to helix&7TM axes',
        'outer_angle': 'Rotamer',
        'rotation_angle': 'Rotation angle',
        'tau': 'Tau',
        'phi': 'Phi',
        'psi': 'Psi',
        'sasa': 'SASA',
        'sasa_abs': 'SASA (abs)',
        'rsa': 'RSA',
        'rsa_abs': 'RSA (abs)',
        'theta': 'Theta',
        'hse': 'HSE',
        'hse_abs': 'HSE (abs)',
        'tau_angle': 'Tau dihedral',
        'distance': 'Distance',
        'distance_abs': 'Distance (abs)',
        'core_distance': 'Distance to 7TM axis',
        'core_distance_abs': 'Distance to 7TM axis (abs)',  
        'network' : 'Network group no.',
        'set_presence' : 'Set specific presense',
        'ligand' : 'Ligand interactions freq',
        'complex' : 'G protein interactions',
        'ligandcomplex' : 'Ligand and G protein interactions',
        'mutations' : 'Mutations with >5 fold effect',
        'conservation' : 'Conservation of set(s) consensus AA in class'
    }
    path_groups = {}
    path_groups_lookup = {}
    $(containerSelector).find('.helix_path').each(function () {
        path_id = $(this).attr('id');
        res_ids = $(this).attr('previous_res');
        path_groups[path_id] = { 'distance': [], 'distance_abs': [] };
        
        $.each(index_names, function (i, name) {
            path_groups[path_id][name] = [];
            if (neg_and_positives.includes(name)) {
                path_groups[path_id][name+"_abs"] = [];
            }
        })

        $.each(res_ids.split(","), function (i, res_id) {
            path_groups_lookup[res_id] = path_id;
        });
    });

    $.each(data['snakeplot_lookup_aa_cons'], function (gn, cons) {
        seq_pos = data['snakeplot_lookup'][gn];
        scale = cons / 100
        colors['conservation'][seq_pos] = [cons,scale,100];
    } )


    $.each(filtered_cluster_groups, function (id, group) {
        $.each(group, function (i, gn) {
            seq_pos = data['snakeplot_lookup'][gn];
            scale = id / filtered_cluster_groups.length
            colors['network'][seq_pos] = [id,scale,filtered_cluster_groups.length];
        })
    })

    $.each(filtered_gns_presence, function (gn, value) {
        seq_pos = data['snakeplot_lookup'][gn];
        scale = value / 1
        colors['set_presence'][seq_pos] = [value,scale,1];
    })

    max_ligand_interactions = Math.max(...Object.values(data['class_ligand_interactions'])) 
    $.each(data['class_ligand_interactions'], function (gn, value) {
        seq_pos = data['snakeplot_lookup'][gn];
        scale = value / max_ligand_interactions;
        colors['ligand'][seq_pos] = [value,scale,max_ligand_interactions];
    })


    max_complex_interactions = Math.max(...Object.values(data['class_complex_interactions'])) 
    $.each(data['class_complex_interactions'], function (gn, value) {
        seq_pos = data['snakeplot_lookup'][gn];
        scale = value / max_complex_interactions;
        colors['complex'][seq_pos] = [value,scale,max_complex_interactions];
    })

    $.each(data['snakeplot_lookup'], function (gn, seq_pos) {
        complex_value = gn in data['class_complex_interactions'] ? data['class_complex_interactions'][gn] : 0;
        ligand_value = gn in data['class_ligand_interactions'] ? data['class_ligand_interactions'][gn] : 0;

        if (complex_value == 0 && ligand_value == 0) {
            // either do nothing or put in 0 value
            // colors['ligandcomplex'][seq_pos] = [value,scale,max_mutations];
        } else {
            if (complex_value/max_complex_interactions >= ligand_value/max_ligand_interactions) {
                // treat complex values 0.5-1 range
                value = complex_value
                scale = 0.5+(0.5)*(value / max_complex_interactions);
                colors['ligandcomplex'][seq_pos] = [value,scale,max_complex_interactions];
            } else {
                // treat ligand values 0-0.5 range
                value = ligand_value
                scale = 0.5-(0.5)*(value / max_ligand_interactions);
                colors['ligandcomplex'][seq_pos] = [value,scale,max_ligand_interactions];
            }
            console.log(gn,complex_value/max_complex_interactions,ligand_value/max_ligand_interactions, colors['ligandcomplex'][seq_pos])
        }
    })

    max_mutations = Math.max(...Object.values(data['class_mutations'])) 
    $.each(data['snakeplot_lookup'], function (gn, seq_pos) {
        if (gn in data['class_mutations']) {
            value = data['class_mutations'][gn];
        } else {
            value = 0;
        }
        scale = value / max_mutations;
        colors['mutations'][seq_pos] = [value,scale,max_mutations];
    })

    $.each(data['distances'], function (gn, dis) {
        seq_pos = data['snakeplot_lookup'][gn];
        // console.log(gn, dis['avg'], seq_pos);
        value = dis['avg'];
        scale = Math.abs(value) / data['ngl_max_diff_distance'];
        if (value < 0) {
            // if the header is a set two, then make it red
            scale_abs = (1-scale)*0.5;
        } else if (value >= 0) {
{'fraction_non_alphanumeric': 0.1804046346881191, 'fraction_numerical': 0.025935042324548237, 'mean_word_length': 2.8435625288417166, 'pattern_counts': {'":': 24, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3821615', 'n_tokens_mistral': 5872, 'n_tokens_neox': 5453, 'n_words': 1083}