From c277a136f595004ff504ed393dab209e06517960 Mon Sep 17 00:00:00 2001 From: zsloan Date: Fri, 26 Jul 2019 12:44:02 -0500 Subject: Fixed the intercept line and added information to top of figure --- wqflask/wqflask/correlation/corr_scatter_plot.py | 36 +++--------- .../static/new/javascript/draw_corr_scatterplot.js | 65 ++++++++++++++++++++-- 2 files changed, 66 insertions(+), 35 deletions(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/correlation/corr_scatter_plot.py b/wqflask/wqflask/correlation/corr_scatter_plot.py index 4090b70e..07aa947e 100644 --- a/wqflask/wqflask/correlation/corr_scatter_plot.py +++ b/wqflask/wqflask/correlation/corr_scatter_plot.py @@ -37,9 +37,7 @@ class CorrScatterPlot(object): vals_2.append(samples_2[sample].value) self.data.append(vals_2) - x = np.array(vals_1) - y = np.array(vals_2) - slope, intercept, r_value, p_value, std_err = stats.linregress(x, y) + slope, intercept, r_value, p_value, std_err = stats.linregress(vals_1, vals_2) x_buffer = (max(vals_1) - min(vals_1))*0.1 y_buffer = (max(vals_2) - min(vals_2))*0.1 @@ -49,8 +47,8 @@ class CorrScatterPlot(object): intercept_coords = get_intercept_coords(slope, intercept, x_range, y_range) - rx = stats.rankdata(x) - ry = stats.rankdata(y) + rx = stats.rankdata(vals_1) + ry = stats.rankdata(vals_2) self.rdata = [] self.rdata.append(rx.tolist()) self.rdata.append(ry.tolist()) @@ -111,31 +109,11 @@ def get_intercept_coords(slope, intercept, x_range, y_range): intercept_coords = [] y1 = slope*x_range[0] + intercept - if slope > 0: - if (y1 < y_range[0]): - x1 = (y_range[0] - intercept)/slope - else: - x1 = x_range[0] - intercept_coords.append([x1, y1]) - - x2 = (y_range[1] - intercept)/slope - if (x2 > x_range[1]): - y2 = slope*x_range[1] + intercept - else: - y2 = y_range[1] - else: - if (y1 > y_range[1]): - x1 = (y_range[0] - intercept)/slope - else: - x1 = x_range[0] - intercept_coords.append([x1, y1]) - - x2 = (y_range[0] - intercept)/slope - if (x2 > x_range[1]): - y2 = slope*x_range[1] + intercept - else: - y2 = y_range[0] + y2 = slope*x_range[1] + intercept + x1 = (y1-intercept)/slope + x2 = (y2-intercept)/slope + intercept_coords.append([x1, y1]) intercept_coords.append([x2, y2]) return intercept_coords \ No newline at end of file diff --git a/wqflask/wqflask/static/new/javascript/draw_corr_scatterplot.js b/wqflask/wqflask/static/new/javascript/draw_corr_scatterplot.js index 7cc89304..23f41c66 100644 --- a/wqflask/wqflask/static/new/javascript/draw_corr_scatterplot.js +++ b/wqflask/wqflask/static/new/javascript/draw_corr_scatterplot.js @@ -4,10 +4,9 @@ var srchart; x_val_range = js_data.x_range[1] - js_data.x_range[0] y_val_range = js_data.y_range[1] - js_data.y_range[0] - -if (x_val_range < 4 || y_val_range < 4){ +if (x_val_range < 9 || y_val_range < 9){ tick_digits = '.1f' -} else if (x_val_range < 0.4 || y_val_range < 0.4) { +} else if (x_val_range < 2 || y_val_range < 2) { tick_digits = '.2f' } else { tick_digits = 'f' @@ -19,7 +18,7 @@ var layout = { margin: { l: 60, r: 30, - t: 80, + t: 90, b: 50 }, xaxis: { @@ -29,6 +28,7 @@ var layout = { visible: true, linecolor: 'black', linewidth: 1, + ticklen: 4, tickformat: tick_digits }, yaxis: { @@ -38,10 +38,37 @@ var layout = { visible: true, linecolor: 'black', linewidth: 1, + ticklen: 4, tickformat: tick_digits }, hovermode: "closest", - showlegend: false + showlegend: false, + annotations:[{ + xref: 'paper', + yref: 'paper', + x: 1, + xanchor: 'right', + y: 1.05, + yanchor: 'top', + text: 'r = ' + js_data.r_value.toFixed(3) + ' P = ' + js_data.p_value.toExponential(), + showarrow: false, + font: { + size: 14 + }, + }, { + xref: 'paper', + yref: 'paper', + x: 0, + xanchor: 'left', + y: 1.05, + yanchor: 'top', + text: 'N=' + js_data.num_overlap, + showarrow: false, + font: { + size: 14 + }, + } + ] } var sr_layout = { @@ -70,7 +97,33 @@ var sr_layout = { linewidth: 1, }, hovermode: "closest", - showlegend: false + showlegend: false, + annotations:[{ + xref: 'paper', + yref: 'paper', + x: 1, + xanchor: 'right', + y: 1.05, + yanchor: 'top', + text: 'r = ' + js_data.srr_value.toFixed(3) + ' P = ' + js_data.srp_value.toExponential(), + showarrow: false, + font: { + size: 14 + }, + }, { + xref: 'paper', + yref: 'paper', + x: 0, + xanchor: 'left', + y: 1.05, + yanchor: 'top', + text: 'N=' + js_data.num_overlap, + showarrow: false, + font: { + size: 14 + }, + } +] } cofactor1_dict = {} -- cgit v1.2.3