diff options
author | Zachary Sloan | 2013-01-10 15:16:05 -0600 |
---|---|---|
committer | Zachary Sloan | 2013-01-10 15:16:05 -0600 |
commit | 218acb47ddb528f2fc0866197175687fedf7341a (patch) | |
tree | 87365cc2ae9ad8dd53e4bb9ec59e6dea9ce47a16 /wqflask | |
parent | 8e4d7024dbdf56625ace33881f30245395d4c18f (diff) | |
download | genenetwork2-218acb47ddb528f2fc0866197175687fedf7341a.tar.gz |
Made Chromosome class in marker_regression.coffee; current
it writes each chromosome's manhattan plot on top of each
other. This commit is before trying to fix that.
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/wqflask/static/new/javascript/marker_regression.coffee | 95 | ||||
-rw-r--r-- | wqflask/wqflask/static/new/javascript/marker_regression.js | 92 |
2 files changed, 136 insertions, 51 deletions
diff --git a/wqflask/wqflask/static/new/javascript/marker_regression.coffee b/wqflask/wqflask/static/new/javascript/marker_regression.coffee index 9f2eb8d7..2f653f98 100644 --- a/wqflask/wqflask/static/new/javascript/marker_regression.coffee +++ b/wqflask/wqflask/static/new/javascript/marker_regression.coffee @@ -72,28 +72,16 @@ $ -> #bars_ordered = process_lrs_array() #display_permutation_histogram(bars_ordered) - class Manhattan_Plot - constructor: -> - #@chromosomes = {} # Hash of chromosomes - # - #@init_chromosomes() - - @process_data() - @display_graph() + class Chromosome + constructor: (@name) -> + @max_mb = 0 + @plot_points = [] + process_point: (mb, lrs) -> + if mb > @max_mb + @max_mb = mb + @plot_points.push([mb, lrs]) - process_data: -> - qtl_results = js_data.qtl_results - #console.log("qtl_results: ", qtl_results) - @plot_points = [] - @max_mb = 0 - for result in qtl_results - if result.locus.chromosome == '1' - mb = parseInt(result.locus.mb) - if mb > @max_mb - @max_mb = mb - @plot_points.push([mb, result.lrs]) - display_graph: -> x_axis_max = Math.ceil(@max_mb/25) * 25 x_axis_ticks = [] @@ -101,11 +89,8 @@ $ -> while (x_tick <= x_axis_max) x_axis_ticks.push(x_tick) x_tick += 25 - console.log("x_axis_ticks:", x_axis_ticks) - console.log("type of x_axis ticks:", typeof(x_axis_ticks[0]), typeof(x_axis_ticks[2])) - #console.log("@plot_points is:", @plot_points) $.jqplot('manhattan_plot', [@plot_points], - title: '1' + title: @name seriesDefaults: showLine: false markerRenderer: $.jqplot.MarkerRenderer @@ -131,6 +116,68 @@ $ -> tickOptions: showGridline: false ) + + + + + + class Manhattan_Plot + constructor: -> + @chromosomes = {} # Hash of chromosomes + + @build_chromosomes() + + #@process_data() + @display_graphs() + + build_chromosomes: -> + for result in js_data.qtl_results + #if result.locus.chromosome == '1' + chromosome = result.locus.chromosome + if chromosome not of @chromosomes + @chromosomes[chromosome] = new Chromosome(chromosome) + mb = parseInt(result.locus.mb) + @chromosomes[chromosome].process_point(mb, result.lrs) + + #if mb > @max_mb + # @max_mb = mb + #@plot_points.push([mb, result.lrs]) + + display_graphs: -> + ### Call display_graph for each chromosome ### + + # First get everything in the right order + numbered_keys = [] + extra_keys = [] + for key of @chromosomes + if isNaN(key) + extra_keys.push(key) + else + numbered_keys.push(key) + + numbered_keys.sort(sort_number) + extra_keys.sort() + keys = numbered_keys + extra_keys + console.log("keys are:", keys) + + for chromosome in key + @chromosomes[chromosome].display_graph() + + + + #process_data: -> + # qtl_results = js_data.qtl_results + # #console.log("qtl_results: ", qtl_results) + # @plot_points = [] + # @max_mb = 0 + # for result in qtl_results + # if result.locus.chromosome == '1' + # mb = parseInt(result.locus.mb) + # if mb > @max_mb + # @max_mb = mb + # @plot_points.push([mb, result.lrs]) + + new Permutation_Histogram new Manhattan_Plot
\ No newline at end of file diff --git a/wqflask/wqflask/static/new/javascript/marker_regression.js b/wqflask/wqflask/static/new/javascript/marker_regression.js index c69d0340..7553721c 100644 --- a/wqflask/wqflask/static/new/javascript/marker_regression.js +++ b/wqflask/wqflask/static/new/javascript/marker_regression.js @@ -2,7 +2,7 @@ (function() { $(function() { - var Manhattan_Plot, Permutation_Histogram, sort_number; + var Chromosome, Manhattan_Plot, Permutation_Histogram, sort_number; sort_number = function(a, b) { return a - b; }; @@ -72,35 +72,22 @@ return Permutation_Histogram; })(); - Manhattan_Plot = (function() { + Chromosome = (function() { - function Manhattan_Plot() { - this.process_data(); - this.display_graph(); + function Chromosome(name) { + this.name = name; + this.max_mb = 0; + this.plot_points = []; } - Manhattan_Plot.prototype.process_data = function() { - var mb, qtl_results, result, _i, _len, _results; - qtl_results = js_data.qtl_results; - this.plot_points = []; - this.max_mb = 0; - _results = []; - for (_i = 0, _len = qtl_results.length; _i < _len; _i++) { - result = qtl_results[_i]; - if (result.locus.chromosome === '1') { - mb = parseInt(result.locus.mb); - if (mb > this.max_mb) { - this.max_mb = mb; - } - _results.push(this.plot_points.push([mb, result.lrs])); - } else { - _results.push(void 0); - } + Chromosome.prototype.process_point = function(mb, lrs) { + if (mb > this.max_mb) { + this.max_mb = mb; } - return _results; + return this.plot_points.push([mb, lrs]); }; - Manhattan_Plot.prototype.display_graph = function() { + Chromosome.prototype.display_graph = function() { var x_axis_max, x_axis_ticks, x_tick; x_axis_max = Math.ceil(this.max_mb / 25) * 25; x_axis_ticks = []; @@ -109,10 +96,8 @@ x_axis_ticks.push(x_tick); x_tick += 25; } - console.log("x_axis_ticks:", x_axis_ticks); - console.log("type of x_axis ticks:", typeof x_axis_ticks[0], typeof x_axis_ticks[2]); return $.jqplot('manhattan_plot', [this.plot_points], { - title: '1', + title: this.name, seriesDefaults: { showLine: false, markerRenderer: $.jqplot.MarkerRenderer, @@ -148,6 +133,59 @@ }); }; + return Chromosome; + + })(); + Manhattan_Plot = (function() { + + function Manhattan_Plot() { + this.chromosomes = {}; + this.build_chromosomes(); + this.display_graphs(); + } + + Manhattan_Plot.prototype.build_chromosomes = function() { + var chromosome, mb, result, _i, _len, _ref, _results; + _ref = js_data.qtl_results; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + result = _ref[_i]; + chromosome = result.locus.chromosome; + if (!(chromosome in this.chromosomes)) { + this.chromosomes[chromosome] = new Chromosome(chromosome); + } + mb = parseInt(result.locus.mb); + _results.push(this.chromosomes[chromosome].process_point(mb, result.lrs)); + } + return _results; + }; + + Manhattan_Plot.prototype.display_graphs = function() { + /* Call display_graph for each chromosome + */ + + var chromosome, extra_keys, key, keys, numbered_keys, _i, _len, _results; + numbered_keys = []; + extra_keys = []; + for (key in this.chromosomes) { + if (isNaN(key)) { + extra_keys.push(key); + } else { + numbered_keys.push(key); + } + } + numbered_keys.sort(sort_number); + extra_keys.sort(); + keys = numbered_keys + extra_keys; + console.log("keys are:", keys); + _results = []; + for (_i = 0, _len = key.length; _i < _len; _i++) { + chromosome = key[_i]; + _results.push(this.chromosomes[chromosome].display_graph()); + } + return _results; + }; + return Manhattan_Plot; })(); |