aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wqflask/utility/corr_result_helpers.py26
-rw-r--r--wqflask/wqflask/correlation/corr_scatter_plot.py24
-rw-r--r--wqflask/wqflask/static/new/css/corr_scatter_plot.css17
-rw-r--r--wqflask/wqflask/static/new/javascript/corr_scatter_plot.js63
-rw-r--r--wqflask/wqflask/templates/corr_scatter_plot.html22
-rw-r--r--wqflask/wqflask/templates/correlation_page.html10
-rw-r--r--wqflask/wqflask/views.py9
7 files changed, 162 insertions, 9 deletions
diff --git a/wqflask/utility/corr_result_helpers.py b/wqflask/utility/corr_result_helpers.py
index edf32449..a253026c 100644
--- a/wqflask/utility/corr_result_helpers.py
+++ b/wqflask/utility/corr_result_helpers.py
@@ -25,6 +25,32 @@ def normalize_values(a_values, b_values):
return a_new, b_new, num_overlap
+def common_keys(a_samples, b_samples):
+ """
+ >>> a = dict(BXD1 = 9.113, BXD2 = 9.825, BXD14 = 8.985, BXD15 = 9.300)
+ >>> b = dict(BXD1 = 9.723, BXD3 = 9.825, BXD14 = 9.124, BXD16 = 9.300)
+ >>> sorted(common_keys(a, b))
+ ['BXD1', 'BXD14']
+ """
+ return set(a_samples.keys()).intersection(set(b_samples.keys()))
+
+
+def normalize_values_with_samples(a_samples, b_samples):
+ common_samples = common_keys(a_samples, b_samples)
+
+ a_new = {}
+ b_new = {}
+ for sample in common_samples:
+ a_new[sample] = a_samples[sample]
+ b_new[sample] = b_samples[sample]
+
+ num_overlap = len(a_new)
+ assert num_overlap == len(b_new), "Lengths should be the same"
+
+ return a_new, b_new, num_overlap
+
+
+
if __name__ == '__main__':
import doctest
doctest.testmod() \ No newline at end of file
diff --git a/wqflask/wqflask/correlation/corr_scatter_plot.py b/wqflask/wqflask/correlation/corr_scatter_plot.py
new file mode 100644
index 00000000..13022b44
--- /dev/null
+++ b/wqflask/wqflask/correlation/corr_scatter_plot.py
@@ -0,0 +1,24 @@
+from __future__ import absolute_import, print_function, division
+
+from base.trait import GeneralTrait
+from base import data_set
+from utility import corr_result_helpers
+
+class CorrScatterPlot(object):
+
+ def __init__(self, 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)
+ self.js_data = dict(
+ samples_1 = samples_1,
+ samples_2 = samples_2
+ ) \ 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 %}
+ <link rel="stylesheet" type="text/css" href="/static/packages/jqplot/jquery.jqplot.min.css" />
+ <link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/css/jquery.dataTables.css" />
+ <link rel="stylesheet" type="text/css" href="/static/packages/DT_bootstrap/DT_bootstrap.css" />
+ <link rel="stylesheet" type="text/css" href="/static/packages/TableTools/media/css/TableTools.css" />
+ <link rel="stylesheet" type="text/css" href="/static/new/css/corr_scatter_plot.css" />
+{% endblock %}
+
+{% block content %}
+<div id='scatter_plot'></div>
+{% endblock %}
+
+{% block js %}
+ <script>
+ js_data = {{ js_data | safe }}
+ </script>
+ <script language="javascript" type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
+ <script language="javascript" type="text/javascript" src="/static/packages/underscore/underscore-min.js"></script>
+ <script language="javascript" type="text/javascript" src="/static/new/javascript/corr_scatter_plot.js"></script>
+{% endblock %} \ No newline at end of file
diff --git a/wqflask/wqflask/templates/correlation_page.html b/wqflask/wqflask/templates/correlation_page.html
index d675b801..e4819d61 100644
--- a/wqflask/wqflask/templates/correlation_page.html
+++ b/wqflask/wqflask/templates/correlation_page.html
@@ -59,7 +59,7 @@
<td>{{'%0.3f'|format(trait.mean)}}</td>
<td>{{'%0.3f'|format(trait.lrs)}}</td>
<td>Chr{{ trait.locus_chr }}: {{'%0.3f'|format(trait.locus_mb) }}</td>
- <td>{{'%0.3f'|format(trait.sample_r)}}</td>
+ <td><a target="_blank" href="corr_scatter_plot?dataset_1={{dataset.name}}&dataset_2={{trait.dataset.name}}&trait_1={{this_trait.name}}&trait_2={{trait.name}}">{{'%0.3f'|format(trait.sample_r)}}</a></td>
<td>{{ trait.num_overlap }}</td>
<td>{{'%0.3e'|format(trait.sample_p)}}</td>
<td>{{'%0.3f'|format(trait.lit_corr)}}</td>
@@ -69,14 +69,6 @@
{% endfor %}
</tbody>
</table>
-
- <br />
-
-<!-- <button class="btn"><i class="icon-ok"></i> Select</button>
- <button class="btn"><i class="icon-remove"></i> Deselect</button>
- <button class="btn"><i class="icon-resize-vertical"></i> Invert</button>
- <button class="btn"><i class="icon-plus-sign"></i> Add</button>
- <button class="btn btn-primary pull-right"><i class="icon-download icon-white"></i> Download Table</button>-->
</div>
</div>
{% endblock %}
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index 22973045..b2f08ca0 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -34,6 +34,7 @@ from wqflask.show_trait import export_trait_data
from wqflask.marker_regression import marker_regression
#from wqflask.interval_mapping import interval_mapping
from wqflask.correlation import show_corr_results
+from wqflask.correlation import corr_scatter_plot
from utility import temp_data
from wqflask.dataSharing import SharingInfo, SharingInfoPage
@@ -299,6 +300,14 @@ def corr_compute_page():
template_vars = show_corr_results.CorrelationResults(request.form)
return render_template("correlation_page.html", **template_vars.__dict__)
+@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',))
def interval_mapping_page():
template_vars = interval_mapping.IntervalMapping(request.args)