2 * visualize and compare gebvs of a training population
3 * and a selection population.
4 * normal distribution plotting using d3.
5 * uses methods from solGS.normalDistribution and solGS.linePlot js libraries
6 * Isaak Y Tecle <iyt2@cornell.edu>
11 jQuery(document).ready(function () {
12 jQuery('#compare_gebvs').on('click', function () {
18 function gebvsComparison () {
20 var gebvParams = getGebvsParams();
22 var trainingGEBVs = '';
23 var selectionGEBVs = '';
26 if (!gebvParams.training_pop_id) {
27 missing = 'training population id';
30 if (!gebvParams.selection_pop_id) {
31 missing += ', selection population id';
34 if (!gebvParams.trait_id) {
35 missing += ', trait id';
39 jQuery('#compare_gebvs_message')
40 .html('Can not compare GEBVs. I am missing ' + missing + '.')
44 getTrainingPopulationGEBVs(gebvParams);
48 function getGebvsParams () {
50 var trainingPopId = jQuery('#training_pop_id').val();
51 var selectionPopId = jQuery('#selection_pop_id').val();
52 var traitId = jQuery('#trait_id').val();
55 'training_pop_id' : trainingPopId,
56 'selection_pop_id' : selectionPopId,
64 function getTrainingPopulationGEBVs (gebvParams) {
70 url : '/solgs/get/gebvs/training/population',
71 success: function (res) {
72 if (res.gebv_exists) {
73 jQuery('#compare_gebvs_message').empty();
74 trainingGEBVs = res.gebv_arrayref;
77 getSelectionPopulationGEBVs(gebvParams)
81 jQuery('#compare_gebvs_message')
82 .html('There is no GEBV data for the training population.')
87 jQuery('#compare_gebvs_message')
88 .html('Error occured checking for GEBV data for the training population.')
96 function getSelectionPopulationGEBVs (gebvParams) {
102 url : '/solgs/get/gebvs/selection/population',
103 success: function (res) {
104 if (res.gebv_exists) {
105 jQuery('#compare_gebvs_message').empty();
107 selectionGEBVs = res.gebv_arrayref;
109 if (selectionGEBVs && trainingGEBVs) {
110 jQuery('#compare_gebvs_message')
111 .html('Please wait... plotting gebvs')
114 plotGEBVs(trainingGEBVs, selectionGEBVs);
116 jQuery('#compare_gebvs_message').empty();
117 jQuery('#compare_gebvs').hide();
120 jQuery('#compare_gebvs_message')
121 .html('There is no GEBV data for the selection population.')
126 jQuery('#compare_gebvs_message')
127 .html('Error occured checking for GEBV data for the selection population.')
135 function plotGEBVs (trainingGEBVs, selectionGEBVs) {
137 var normalDistTraining = new solGS.normalDistribution();
139 var trainingNormalDistData = normalDistTraining
140 .getNormalDistData(trainingGEBVs);
142 var gebvZScoresT = normalDistTraining
143 .getYValuesZScores(trainingNormalDistData);
145 var yValuesT = normalDistTraining
146 .getPValues(trainingNormalDistData);
148 var zScoresPT = normalDistTraining
149 .getZScoresP(trainingNormalDistData);
151 var xYT = normalDistTraining
152 .getYValuesP(trainingNormalDistData);
154 var xValuesT = normalDistTraining
155 .getYValues(trainingGEBVs);
157 var trMean = ss.mean(xValuesT);
159 var stdT = trMean <= 0 ? -1.0 : 1.0;
161 var xMT = normalDistTraining.getObsValueZScore(gebvZScoresT, stdT);
163 var normalDistSelection = new solGS.normalDistribution();
165 var selectionNormalDistData = normalDistSelection
166 .getNormalDistData(selectionGEBVs);
168 var gebvZScoresS = normalDistSelection
169 .getYValuesZScores(selectionNormalDistData);
171 var yValuesS = normalDistSelection
172 .getPValues(selectionNormalDistData);
174 var zScoresPS = normalDistSelection
175 .getZScoresP(selectionNormalDistData);
177 var xYS = normalDistSelection
178 .getYValuesP(selectionNormalDistData);
180 var xValuesS = normalDistSelection
181 .getYValues(selectionGEBVs);
183 var slMean = ss.mean(xValuesS);
185 var stdS = slMean <= 0 ? -1.0 : 1.0;
187 var xMS = normalDistTraining.getObsValueZScore(gebvZScoresS, stdS);
189 var svgId = '#compare_gebvs_canvas';
190 var plotId = '#compare_gebvs_plot';
192 var trColor = '#02bcff';
193 var slColor = '#ff1302';
194 var axLabelColor = '#ff8d02';
195 var yLabel = 'Probability';
196 var xLabel = 'GEBVs';
198 var title = 'Normal distribution curves of GEBVs '
199 + 'for the training and selection populations.';
204 'x_axis_label': xLabel,
205 'y_axis_label': yLabel,
206 'axis_label_color': axLabelColor,
211 'legend': 'Training population' ,
216 'legend': 'Selection population',
224 var linePlot = solGS.linePlot(allData);
226 var trainingMidlineData = [
228 [trMean, d3.max(yValuesT)]
231 var selectionMidlineData = [
233 [slMean, d3.max(yValuesS)]
236 var midLine = d3.svg.line()
238 return linePlot.xScale(d[0]);
241 return linePlot.yScale(d[1]);
244 linePlot.graph.append("path")
245 .attr("d", midLine(trainingMidlineData))
246 .attr("stroke", trColor)
247 .attr("stroke-width", "3")
248 .attr("fill", "none")
249 .on("mouseover", function (d) {
251 linePlot.graph.append("text")
252 .attr("id", "tr_mean")
253 .text(d3.format(".2f")(trMean))
256 "font-weight": "bold"
258 .attr("x", linePlot.xScale(xMT[0]))
259 .attr("y", linePlot.yScale(d3.max(yValuesT) * 0.5))
262 .on("mouseout", function() {
263 d3.selectAll("text#tr_mean").remove();
266 linePlot.graph.append("path")
267 .attr("d", midLine(selectionMidlineData))
268 .attr("stroke", slColor)
269 .attr("stroke-width", "3")
270 .attr("fill", "none")
271 .on("mouseover", function (d) {
273 linePlot.graph.append("text")
274 .attr("id", "sl_mean")
275 .text(d3.format(".2f")(slMean))
278 "font-weight": "bold"
280 .attr("x", linePlot.xScale(xMS[0]))
281 .attr("y", linePlot.yScale(d3.max(yValuesS) * 0.5))
285 .on("mouseout", function() {
286 d3.selectAll("text#sl_mean").remove();