diff options
author | zsloan | 2019-06-28 15:59:15 -0500 |
---|---|---|
committer | zsloan | 2019-06-28 15:59:15 -0500 |
commit | f271a933abf5e20cc137f2ac730012ac10eb6172 (patch) | |
tree | 0d92065a5919110740cfc325e49130ad68c47a44 | |
parent | d249d8fa90eabd47020926fdadbfe22ac2bba900 (diff) | |
download | genenetwork2-f271a933abf5e20cc137f2ac730012ac10eb6172.tar.gz |
Added regression lines to correlation scatterplots
Fixed bug when doing correlations of non-phenotype traits against phenotype datasets
Changed color of manhattan plot points (subject to change)
4 files changed, 133 insertions, 17 deletions
diff --git a/wqflask/wqflask/correlation/corr_scatter_plot.py b/wqflask/wqflask/correlation/corr_scatter_plot.py index 925e8783..4090b70e 100644 --- a/wqflask/wqflask/correlation/corr_scatter_plot.py +++ b/wqflask/wqflask/correlation/corr_scatter_plot.py @@ -1,5 +1,7 @@ from __future__ import absolute_import, print_function, division +import math + from flask import g from base.trait import GeneralTrait @@ -39,6 +41,14 @@ class CorrScatterPlot(object): y = np.array(vals_2) slope, intercept, r_value, p_value, std_err = stats.linregress(x, y) + x_buffer = (max(vals_1) - min(vals_1))*0.1 + y_buffer = (max(vals_2) - min(vals_2))*0.1 + + x_range = [min(vals_1) - x_buffer, max(vals_1) + x_buffer] + y_range = [min(vals_2) - y_buffer, max(vals_2) + y_buffer] + + intercept_coords = get_intercept_coords(slope, intercept, x_range, y_range) + rx = stats.rankdata(x) ry = stats.rankdata(y) self.rdata = [] @@ -46,6 +56,13 @@ class CorrScatterPlot(object): self.rdata.append(ry.tolist()) srslope, srintercept, srr_value, srp_value, srstd_err = stats.linregress(rx, ry) + x_buffer = (max(rx) - min(rx))*0.1 + y_buffer = (max(ry) - min(ry))*0.1 + + sr_range = [min(rx) - x_buffer, max(rx) + x_buffer] + + sr_intercept_coords = get_intercept_coords(srslope, srintercept, sr_range, sr_range) + #vals_3 = [] #for sample in self.trait_3.data: # vals_3.append(self.trait_3.data[sample].value) @@ -68,6 +85,11 @@ class CorrScatterPlot(object): num_overlap = num_overlap, vals_1 = vals_1, vals_2 = vals_2, + x_range = x_range, + y_range = y_range, + sr_range = sr_range, + intercept_coords = intercept_coords, + sr_intercept_coords = sr_intercept_coords, slope = slope, intercept = intercept, @@ -83,3 +105,37 @@ class CorrScatterPlot(object): #vals_3 = vals_3 ) self.jsdata = self.js_data + + +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] + + intercept_coords.append([x2, y2]) + + return intercept_coords
\ No newline at end of file diff --git a/wqflask/wqflask/correlation/show_corr_results.py b/wqflask/wqflask/correlation/show_corr_results.py index 6e9abcd6..75cf5f7f 100644 --- a/wqflask/wqflask/correlation/show_corr_results.py +++ b/wqflask/wqflask/correlation/show_corr_results.py @@ -179,8 +179,9 @@ class CorrelationResults(object): #ZS: Convert min/max chromosome to an int for the location range option range_chr_as_int = None for order_id, chr_info in self.dataset.species.chromosomes.chromosomes.iteritems(): - if chr_info.name == self.location_chr: - range_chr_as_int = order_id + if 'loc_chr' in start_vars: + if chr_info.name == self.location_chr: + range_chr_as_int = order_id for _trait_counter, trait in enumerate(self.correlation_data.keys()[:self.return_number]): trait_object = GeneralTrait(dataset=self.target_dataset, name=trait, get_qtl_info=True, get_sample_info=False) diff --git a/wqflask/wqflask/marker_regression/display_mapping_results.py b/wqflask/wqflask/marker_regression/display_mapping_results.py index 91fdae8f..3bcd613f 100644 --- a/wqflask/wqflask/marker_regression/display_mapping_results.py +++ b/wqflask/wqflask/marker_regression/display_mapping_results.py @@ -1865,9 +1865,9 @@ class DisplayMappingResults(object): if self.manhattan_plot == True: if self.selectedChr == -1 and (previous_chr_as_int % 2 == 1): - point_color = pid.grey + point_color = pid.red else: - point_color = pid.black + point_color = pid.blue final_x_pos = Xc-canvas.stringWidth("5",font=symbolFont)/2+1 if final_x_pos > (xLeftOffset + plotWidth): diff --git a/wqflask/wqflask/static/new/javascript/draw_corr_scatterplot.js b/wqflask/wqflask/static/new/javascript/draw_corr_scatterplot.js index a74c99d3..a29e751e 100644 --- a/wqflask/wqflask/static/new/javascript/draw_corr_scatterplot.js +++ b/wqflask/wqflask/static/new/javascript/draw_corr_scatterplot.js @@ -11,6 +11,7 @@ var layout = { b: 50 }, xaxis: { + range: [js_data.x_range[0], js_data.x_range[1]], title: js_data.trait_1, zeroline: false, visible: true, @@ -18,6 +19,7 @@ var layout = { linewidth: 1, }, yaxis: { + range: [js_data.y_range[0], js_data.y_range[1]], title: js_data.trait_2, zeroline: false, visible: true, @@ -27,6 +29,34 @@ var layout = { hovermode: "closest" } +var sr_layout = { + height: 700, + width: 800, + margin: { + l: 60, + r: 30, + t: 80, + b: 50 + }, + xaxis: { + range: [js_data.sr_range[0], js_data.sr_range[1]], + title: js_data.trait_1, + zeroline: false, + visible: true, + linecolor: 'black', + linewidth: 1, + }, + yaxis: { + range: [js_data.sr_range[0], js_data.sr_range[1]], + title: js_data.trait_2, + zeroline: false, + visible: true, + linecolor: 'black', + linewidth: 1, + }, + hovermode: "closest" +} + cofactor1_dict = {} ranked_cofactor1_dict = {} //cofactor1_values = [] @@ -48,14 +78,23 @@ function drawg() { sample_names.push(js_data.indIDs[j]) } - var trace = { + var trace1 = { x: x_values, y: y_values, mode: 'markers', text: sample_names } - Plotly.newPlot('scatterplot2', [trace], layout) + var trace2 = { + x: [js_data.intercept_coords[0][0], js_data.intercept_coords[1][0]], + y: [js_data.intercept_coords[0][1], js_data.intercept_coords[1][1]], + mode: 'lines', + line: { + color: 'rgb(250, 60, 73)' + } + } + + Plotly.newPlot('scatterplot2', [trace2, trace1], layout) } @@ -69,14 +108,14 @@ function srdrawg() { sample_names.push(js_data.indIDs[j]) } - var trace = { + var trace1 = { x: x_values, y: y_values, mode: 'markers', text: sample_names } - Plotly.newPlot('srscatterplot2', [trace], layout) + Plotly.newPlot('srscatterplot2', [trace1], sr_layout) } function getdata() { @@ -256,32 +295,41 @@ function getdata() { point_text.push(this_text) } - console.log("symbol list:", symbol_list) - if (symbol_list.length > 0) { - var trace = { + var trace1 = { x: x_values, y: y_values, mode: 'markers', text: point_text, marker: { + color: 'rgb(66, 66, 245)', symbol: symbol_list, size: sizes } } } else { - var trace = { + var trace1 = { x: x_values, y: y_values, mode: 'markers', text: point_text, marker: { + color: 'rgb(66, 66, 245)', size: sizes } } } - return [trace]; + var trace2 = { + x: [js_data.intercept_coords[0][0], js_data.intercept_coords[1][0]], + y: [js_data.intercept_coords[0][1], js_data.intercept_coords[1][1]], + mode: 'lines', + line: { + color: 'rgb(250, 60, 73)' + } + } + + return [trace2, trace1]; } function map1to2 (min1, max1, min2, max2, v1) { @@ -465,18 +513,28 @@ function srgetdata() { point_text.push(this_text) } - var trace = { + var trace1 = { x: x_values, y: y_values, mode: 'markers', text: point_text, marker: { + color: 'rgb(66, 66, 245)', symbol: symbol_list, size: sizes } } - return [trace]; + var trace2 = { + x: [js_data.sr_intercept_coords[0][0], js_data.sr_intercept_coords[1][0]], + y: [js_data.sr_intercept_coords[0][1], js_data.sr_intercept_coords[1][1]], + mode: 'lines', + line: { + color: 'rgb(250, 60, 73)' + } + } + + return [trace2, trace1]; } function chartupdatewh() { @@ -490,7 +548,8 @@ function chartupdatewh() { Plotly.newPlot('scatterplot2', getdata(), layout) Plotly.relayout('scatterplot2', width_height_update) - Plotly.newPlot('srscatterplot2', srgetdata(), layout) + + Plotly.newPlot('srscatterplot2', srgetdata(), sr_layout) Plotly.relayout('srscatterplot2', width_height_update) } @@ -567,7 +626,7 @@ function chartupdatedata() { Plotly.newPlot('scatterplot2', getdata(), layout) Plotly.relayout('scatterplot2', pearson_title_update) - Plotly.newPlot('srscatterplot2', srgetdata(), layout) + Plotly.newPlot('srscatterplot2', srgetdata(), sr_layout) Plotly.relayout('srscatterplot2', spearman_title_update) if ($('#cofactor1_type option:selected').val() == "color"){ |