<commit_before>//
//
// <NAME> <<EMAIL>> June 2013
//
;
// Creates an oncoprint on the div.
// The parameters is an object that contains:
// clinicalData, clinical_attrs (list), genes (list), geneData,
//
// and width (number) for the width of the oncoprint
// and legend (undefined or div element)
define("Oncoprint",
        [           "OncoprintUtils",  "MemoSort"],
        function(   utils,              MemoSort) {
            return function(div, params) {
                params.clinicalData = params.clinicalData || [];        // initialize
                params.clinical_attrs = params.clinical_attrs || [];

                // make strings of numbers into numbers
                var clinicalData = params.clinicalData.map(function(i) {
                    if (!utils.is_discrete(i.attr_val)) {
                        i.attr_val = parseInt(i.attr_val);
                    }
                    return i;
                });

                var data = clinicalData.concat(params.geneData);

                var clinical_attrs = params.clinical_attrs      // extract attr_ids
                    .map(function(attr) { return attr.attr_id; });

                // handle the case when a list of strings is passed instead of proper
                // clinical attribute objects
                clinical_attrs = clinical_attrs.filter(function(i) { return i !== undefined; });
                clinical_attrs = clinical_attrs || params.clinical_attrs;

                var attributes = clinical_attrs.concat(params.genes);

                data = utils.process_data(data, attributes);

                // keeps track of the order specified by the user (translates to vertical
                // order in the visualization)
                var attr2index = (function() {
                    var to_return = {};

                    attributes.forEach(function(attr, i) {
                        to_return[attr] = i;
                    });

                    return to_return;
                }());

                // returns the vertical position of the attr
                var vertical_pos = function(attr) {
                    return dims.vert_space * attr2index[attr];
                };

                if (clinicalData === []
                        && params.clinical_attrs !== undefined) {
                    throw {
                        name: "Data Mismatch Error",
                            message: "There are clinical attributes for nonexistant clinical data"
                    }
                }

                var id2ClinicalAttr = utils.createId2ClinicalAttr(params.clinical_attrs);

                var dims = (function() {
                    var rect_height = 23;
                    var mut_height = rect_height / 3;
                    var vert_padding = 6;
                    var label_width = utils.label_width(attributes.map(
                            function(attr) {
                                var maybe = utils.maybe_map(id2ClinicalAttr);
                                var value = maybe(attr);
                                return value === attr ? value : value.display_name;

                            }));

                    var clinical_height = (2/3) * rect_height;
                    var clinical_offset = (1/6) * rect_height;

                    return {
                        width: data.length * (5.5 + 3),
                    height: (rect_height + vert_padding) * attributes.length,
                    rect_height: rect_height,
                    rect_width: 5.5,
                    vert_padding: vert_padding,
                    vert_space: rect_height + vert_padding,
                    hor_padding: 3,
                    mut_height: mut_height,
                    label_width: label_width,
                    clinical_height: clinical_height,
                    clinical_offset: clinical_offset
                    };
                }());
                //    var margin = { top: 80, right: 80, left: 80, bottom: 80 };
                    
                // make labels and set up the table for proper scrolling, etc.
                var table = d3.select(div)
                    .append('table')
                    .append('tr')
                    .attr('valign','top');
                    
                var remove_oncoprint = function() {
                    d3.select("#" + div.id + ' table').remove();
                };

                // hack to get the label flush with the tracks in Firefox
                // the discrepancy is due to the difference in the way browsers display
                // <table>.  Assume that other browsers behave like chrome and that Firefox
                // is the exception.
                var is_firefox = navigator.userAgent.indexOf("Firefox") !== -1;
                var browser_offset = is_firefox ? 16 : 0;

                var label_svg = table
                    .append('td')
                    .append('svg')
                    .attr('height', dims.height + browser_offset)
                    .attr('width', '' + dims.label_width)
                    .attr('id', 'label');

                var label = label_svg.selectAll('text')
                    .data(attributes)
                    .enter()
                    .append('text')
                    .attr('font-size', '12px')
                    .attr('x', 0)
                    .attr('y', function(d) {
                        return (dims.vert_space / 1.80) + vertical_pos(d); });

                var gene2percent = utils.percent_altered(params.geneData);

                label.append('tspan')       // name
                    .attr('text-anchor', 'start')
                    .attr('font-weight', 'bold')
                    .text(function(d) {
                        var maybe = utils.maybe_map(id2ClinicalAttr);
                        var value = maybe(d);
                        return value === d ? value : value.display_name;
                    });

                label.append('tspan')       // percent_altered
                    .text(function(d) {
                        return (d in gene2percent) ? gene2percent[d].toString() + "%" : "X"; })
                    .attr('fill',function(d){ return (d in gene2percent) ? 'black':'blue'})
                    .attr('class',function(d){ return (d in gene2percent) ? 'regular':'special_delete'})
                    .attr('x', '' + dims.label_width)
                    .attr('text-anchor', 'end');
                    // remove the tspan that would have contained the percent altered
                    // because it messes with the label placement in the pdf download
//                    .filter(function(d) { return gene2percent[d] === undefined; }).remove();

//                label.append('tspan')       // percent_altered
//                    .text(function(d) {
//                        return (d in gene2percent) ? gene2percent[d].toString() + "%" : " "; })
//                    .attr('text-anchor', 'end')
//                    // remove the tspan that would have contained the percent altered
//                    // because it messes with the label placement in the pdf download
//                    .filter(function(d) { return gene2percent[d] === undefined; }).remove();

                var container_width = $('#td-content').width();              // snatch this from the main portal page
                container_width = (container_width ? container_width : params.width);    // see if this has specified by user
                container_width = (container_width ? container_width : 1250);            // default setting
                var main_svg = table
                    .append('td')
                    .append('div')      // control overflow to the right
                    .style('width', container_width - 70 - dims.label_width + 'px') // buffer of, say, 70
                    .style('display', 'inline-block')
                    .style('overflow-x', 'auto')
                    .style('overflow-y', 'hidden')
                    .append("svg")
                    .attr('width', dims.width)
                    .attr('height', dims.height);

                var colors = utils.colors;     // alias

                // helper function
                // *signature:* number, number -> string
                var translate = function(x,y) {
                    return "translate(" + x + "," + y + ")";<commit_msg>update without deleting attributes from Oncoprint Table<commit_after>//
//
// <NAME> <<EMAIL>> June 2013
//
;
// Creates an oncoprint on the div.
// The parameters is an object that contains:
// clinicalData, clinical_attrs (list), genes (list), geneData,
//
// and width (number) for the width of the oncoprint
// and legend (undefined or div element)
define("Oncoprint",
        [           "OncoprintUtils",  "MemoSort"],
        function(   utils,              MemoSort) {
            return function(div, params) {
                params.clinicalData = params.clinicalData || [];        // initialize
                params.clinical_attrs = params.clinical_attrs || [];

                // make strings of numbers into numbers
                var clinicalData = params.clinicalData.map(function(i) {
                    if (!utils.is_discrete(i.attr_val)) {
                        i.attr_val = parseInt(i.attr_val);
                    }
                    return i;
                });

                var data = clinicalData.concat(params.geneData);

                var clinical_attrs = params.clinical_attrs      // extract attr_ids
                    .map(function(attr) { return attr.attr_id; });

                // handle the case when a list of strings is passed instead of proper
                // clinical attribute objects
                clinical_attrs = clinical_attrs.filter(function(i) { return i !== undefined; });
                clinical_attrs = clinical_attrs || params.clinical_attrs;

                var attributes = clinical_attrs.concat(params.genes);

                data = utils.process_data(data, attributes);

                // keeps track of the order specified by the user (translates to vertical
                // order in the visualization)
                var attr2index = (function() {
                    var to_return = {};

                    attributes.forEach(function(attr, i) {
                        to_return[attr] = i;
                    });

                    return to_return;
                }());

                // returns the vertical position of the attr
                var vertical_pos = function(attr) {
                    return dims.vert_space * attr2index[attr];
                };

                if (clinicalData === []
                        && params.clinical_attrs !== undefined) {
                    throw {
                        name: "Data Mismatch Error",
                            message: "There are clinical attributes for nonexistant clinical data"
                    }
                }

                var id2ClinicalAttr = utils.createId2ClinicalAttr(params.clinical_attrs);

                var dims = (function() {
                    var rect_height = 23;
                    var mut_height = rect_height / 3;
                    var vert_padding = 6;
                    var label_width = utils.label_width(attributes.map(
                            function(attr) {
                                var maybe = utils.maybe_map(id2ClinicalAttr);
                                var value = maybe(attr);
                                return value === attr ? value : value.display_name;

                            }));

                    var clinical_height = (2/3) * rect_height;
                    var clinical_offset = (1/6) * rect_height;

                    return {
                        width: data.length * (5.5 + 3),
                    height: (rect_height + vert_padding) * attributes.length,
                    rect_height: rect_height,
                    rect_width: 5.5,
                    vert_padding: vert_padding,
                    vert_space: rect_height + vert_padding,
                    hor_padding: 3,
                    mut_height: mut_height,
                    label_width: label_width,
                    clinical_height: clinical_height,
                    clinical_offset: clinical_offset
                    };
                }());
                //    var margin = { top: 80, right: 80, left: 80, bottom: 80 };
                    
                // make labels and set up the table for proper scrolling, etc.
                var table = d3.select(div)
                    .append('table')
                    .append('tr')
                    .attr('valign','top');
                    
                var remove_oncoprint = function() {
                    d3.select("#" + div.id + ' table').remove();
                };

                // hack to get the label flush with the tracks in Firefox
                // the discrepancy is due to the difference in the way browsers display
                // <table>.  Assume that other browsers behave like chrome and that Firefox
                // is the exception.
                var is_firefox = navigator.userAgent.indexOf("Firefox") !== -1;
                var browser_offset = is_firefox ? 16 : 0;

                var label_svg = table
                    .append('td')
                    .append('svg')
                    .attr('height', dims.height + browser_offset)
                    .attr('width', '' + dims.label_width)
                    .attr('id', 'label');

                var label = label_svg.selectAll('text')
                    .data(attributes)
                    .enter()
                    .append('text')
                    .attr('font-size', '12px')
                    .attr('x', 0)
                    .attr('y', function(d) {
                        return (dims.vert_space / 1.80) + vertical_pos(d); });

                var gene2percent = utils.percent_altered(params.geneData);

                label.append('tspan')       // name
                    .attr('text-anchor', 'start')
                    .attr('font-weight', 'bold')
                    .text(function(d) {
                        var maybe = utils.maybe_map(id2ClinicalAttr);
                        var value = maybe(d);
                        return value === d ? value : value.display_name;
                    });

                label.append('tspan')       // percent_altered
                    .text(function(d) {
                        return (d in gene2percent) ? gene2percent[d].toString() + "%" : "X"; })
                    .attr('fill',function(d){ return (d in gene2percent) ? 'black':'blue'})
                    .attr('class',function(d){ return (d in gene2percent) ? 'regular':'special_delete'})
                    .attr('x', '' + dims.label_width)
                    .attr('text-anchor', 'end')
                    // remove the tspan that would have contained the percent altered
                    // because it messes with the label placement in the pdf download
                    .filter(function(d) { return gene2percent[d] === undefined; }).remove();

//                label.append('tspan')       // percent_altered
//                    .text(function(d) {
//                        return (d in gene2percent) ? gene2percent[d].toString() + "%" : " "; })
//                    .attr('text-anchor', 'end')
//                    // remove the tspan that would have contained the percent altered
//                    // because it messes with the label placement in the pdf download
//                    .filter(function(d) { return gene2percent[d] === undefined; }).remove();

                var container_width = $('#td-content').width();              // snatch this from the main portal page
                container_width = (container_width ? container_width : params.width);    // see if this has specified by user
                container_width = (container_width ? container_width : 1250);            // default setting
                var main_svg = table
                    .append('td')
                    .append('div')      // control overflow to the right
                    .style('width', container_width - 70 - dims.label_width + 'px') // buffer of, say, 70
                    .style('display', 'inline-block')
                    .style('overflow-x', 'auto')
                    .style('overflow-y', 'hidden')
                    .append("svg")
                    .attr('width', dims.width)
                    .attr('height', dims.height);

                var colors = utils.colors;     // alias

                // helper function
                // *signature:* number, number -> string
                var translate = function(x,y) {
                    return "translate(" + x + "," + y + ")";
{'fraction_non_alphanumeric': 0.10548423356800568, 'fraction_numerical': 0.0072176536709459855, 'mean_word_length': 1.2356831106996429, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '974644', 'n_tokens_mistral': 4290, 'n_tokens_neox': 3832, 'n_words': 1052}