From cced8bc03e6b32f561e554d021710486ac138df0 Mon Sep 17 00:00:00 2001 From: Lei Yan Date: Tue, 5 Nov 2013 17:41:38 +0000 Subject: Add Correlation Scatter plot --- wqflask/wqflask/correlation/corr_scatter_plot.py | 11 +--- .../wqflask/static/new/css/corr_scatter_plot.css | 17 ++++++ .../static/new/javascript/corr_scatter_plot.js | 63 ++++++++++++++++++++++ wqflask/wqflask/templates/corr_scatter_plot.html | 22 ++++++++ wqflask/wqflask/templates/correlation_page.html | 2 +- wqflask/wqflask/views.py | 3 ++ 6 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 wqflask/wqflask/static/new/css/corr_scatter_plot.css create mode 100644 wqflask/wqflask/static/new/javascript/corr_scatter_plot.js create mode 100644 wqflask/wqflask/templates/corr_scatter_plot.html (limited to 'wqflask') diff --git a/wqflask/wqflask/correlation/corr_scatter_plot.py b/wqflask/wqflask/correlation/corr_scatter_plot.py index dd4e439a..13022b44 100644 --- a/wqflask/wqflask/correlation/corr_scatter_plot.py +++ b/wqflask/wqflask/correlation/corr_scatter_plot.py @@ -7,25 +7,18 @@ from utility import corr_result_helpers class CorrScatterPlot(object): def __init__(self, params): - print("params are:", params) self.data_set_1 = data_set.create_dataset(params['dataset_1']) self.data_set_2 = data_set.create_dataset(params['dataset_2']) self.trait_1 = GeneralTrait(name=params['trait_1'], dataset=self.data_set_1) self.trait_2 = GeneralTrait(name=params['trait_2'], dataset=self.data_set_2) - vals_1 = [] for sample in self.trait_1.data.keys(): vals_1.append(self.trait_1.data[sample].value) vals_2 = [] for sample in self.trait_2.data.keys(): vals_2.append(self.trait_2.data[sample].value) - - samples_1, samples_2, num_overlap = corr_result_helpers.normalize_values_with_samples( - self.trait_1.data, self.trait_2.data) - + samples_1, samples_2, num_overlap = corr_result_helpers.normalize_values_with_samples(self.trait_1.data, self.trait_2.data) self.js_data = dict( samples_1 = samples_1, samples_2 = samples_2 - ) - - print("Self.js_data:", self.js_data) \ No newline at end of file + ) \ No newline at end of file diff --git a/wqflask/wqflask/static/new/css/corr_scatter_plot.css b/wqflask/wqflask/static/new/css/corr_scatter_plot.css new file mode 100644 index 00000000..602c7297 --- /dev/null +++ b/wqflask/wqflask/static/new/css/corr_scatter_plot.css @@ -0,0 +1,17 @@ +.chart { + +} + +.main text { + font: 10px sans-serif; +} + +.axis line, .axis path { + shape-rendering: crispEdges; + stroke: black; + fill: none; +} + +circle { + fill: steelblue; +} \ No newline at end of file diff --git a/wqflask/wqflask/static/new/javascript/corr_scatter_plot.js b/wqflask/wqflask/static/new/javascript/corr_scatter_plot.js new file mode 100644 index 00000000..180e6240 --- /dev/null +++ b/wqflask/wqflask/static/new/javascript/corr_scatter_plot.js @@ -0,0 +1,63 @@ +var data = new Array(); +samples_1 = js_data.samples_1; +samples_2 = js_data.samples_2; +i = 0; +for (var samplename in samples_1){ + sample1 = samples_1[samplename]; + sample2 = samples_2[samplename]; + data[i] = [sample1.value, sample2.value]; + i++; +} + + var margin = {top: 20, right: 15, bottom: 60, left: 60} + , width = 800 - margin.left - margin.right + , height = 600 - margin.top - margin.bottom; + + var x = d3.scale.linear() + .domain([d3.min(data, function(d){return d[0];})*0.95, d3.max(data, function(d) { return d[0]; })*1.05]) + .range([ 0, width ]); + + var y = d3.scale.linear() + .domain([d3.min(data, function(d){return d[1];})*0.95, d3.max(data, function(d) { return d[1]; })*1.05]) + .range([ height, 0 ]); + + var chart = d3.select('#scatter_plot') + .append('svg:svg') + .attr('width', width + margin.right + margin.left) + .attr('height', height + margin.top + margin.bottom) + .attr('class', 'chart') + + var main = chart.append('g') + .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')') + .attr('width', width) + .attr('height', height) + .attr('class', 'main') + + // draw the x axis + var xAxis = d3.svg.axis() + .scale(x) + .orient('bottom'); + + main.append('g') + .attr('transform', 'translate(0,' + height + ')') + .attr('class', 'main axis date') + .call(xAxis); + + // draw the y axis + var yAxis = d3.svg.axis() + .scale(y) + .orient('left'); + + main.append('g') + .attr('transform', 'translate(0,0)') + .attr('class', 'main axis date') + .call(yAxis); + + var g = main.append("svg:g"); + + g.selectAll("scatter-dots") + .data(data) + .enter().append("svg:circle") + .attr("cx", function (d,i) { return x(d[0]); } ) + .attr("cy", function (d) { return y(d[1]); } ) + .attr("r", 6); \ No newline at end of file diff --git a/wqflask/wqflask/templates/corr_scatter_plot.html b/wqflask/wqflask/templates/corr_scatter_plot.html new file mode 100644 index 00000000..b25110d7 --- /dev/null +++ b/wqflask/wqflask/templates/corr_scatter_plot.html @@ -0,0 +1,22 @@ +{% extends "base.html" %} + +{% block css %} + + + + + +{% endblock %} + +{% block content %} +
+{% endblock %} + +{% block js %} + + + + +{% endblock %} \ No newline at end of file diff --git a/wqflask/wqflask/templates/correlation_page.html b/wqflask/wqflask/templates/correlation_page.html index f3bb5531..3f6b7936 100644 --- a/wqflask/wqflask/templates/correlation_page.html +++ b/wqflask/wqflask/templates/correlation_page.html @@ -48,7 +48,7 @@ {{'%0.3f'|format(trait.mean)}} {{'%0.3f'|format(trait.lrs)}} Chr{{ trait.locus_chr }}:{{'%0.6f'|format(trait.locus_mb)}} - {{'%0.3f'|format(trait.sample_r)}} + {{'%0.3f'|format(trait.sample_r)}} {{ trait.num_overlap }} {{'%0.3e'|format(trait.sample_p)}} {{'%0.3f'|format(trait.lit_corr)}} diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index 4cf540f6..ce213c93 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -302,6 +302,9 @@ def corr_compute_page(): @app.route("/corr_scatter_plot") def corr_scatter_plot_page(): template_vars = corr_scatter_plot.CorrScatterPlot(request.args) + template_vars.js_data = json.dumps(template_vars.js_data, + default=json_default_handler, + indent=" ") return render_template("corr_scatter_plot.html", **template_vars.__dict__) @app.route("/int_mapping", methods=('POST',)) -- cgit v1.2.3