3 * Isaak Y Tecle <iyt2@cornell.edu>
8 jQuery(document).ready( function() {
10 var url = document.URL;
12 if (url.match(/\/breeders_toolbox\/trial|breeders\/trial|\/solgs\/population\//)) {
19 function allowAnova () {
26 function checkDesign () {
28 var trialId = getTrialId();
33 data: {'trial_id': trialId},
34 url: '/anova/check/design/',
35 success: function(response) {
38 showMessage(response.Error);
39 jQuery("#run_anova").hide();
45 error: function(response) {
46 showMessage("Error occured running the ANOVA.");
47 jQuery("#run_anova").show();
54 jQuery(document).ready(function () {
55 jQuery(document).on("click", "#run_anova", function() {
57 var traitId = jQuery("#anova_selected_trait_id").val();
61 queryPhenoData(traitId);
63 jQuery("#run_anova").hide();
65 showMessage("Running anova analysis...");
67 var msg = 'You need to select a trait first.'
76 function anovaAlert(msg) {
86 jQuery(this).dialog('close');
88 class: 'btn btn-success',
97 function queryPhenoData(traitId) {
99 var trialId = getTrialId();
104 data: {'trial_id': trialId, 'traits_ids': [traitId]},
105 url: '/anova/phenotype/data/',
106 success: function(response) {
108 if (response.Error) {
109 showMessage(response.Error);
110 jQuery("#run_anova").show();
112 var traitsAbbrs = response.traits_abbrs;
113 runAnovaAnalysis(traitsAbbrs);
116 error: function(response) {
117 showMessage("Error occured running the ANOVA.");
118 jQuery("#run_anova").show();
124 function showMessage (msg) {
125 jQuery("#anova_message")
126 .css({"padding-left": '0px'})
132 function runAnovaAnalysis(traits) {
134 var trialId = getTrialId();
136 var captions = jQuery('#anova_table table').find('caption').text();
137 var analyzedTraits = captions.replace(/ANOVA result:/g, ' ');
139 for (var i = 0; i < traits.length; i++) {
140 var traitAbbr = traits[i].trait_abbr;
142 if (analyzedTraits.match(traitAbbr) == null) {
143 var anovaTraits = JSON.stringify(traits);
148 data: {'trial_id': trialId, 'traits': [anovaTraits]},
149 url: '/anova/analysis/',
150 success: function(response) {
153 jQuery("#anova_message").empty();
154 showMessage(response.Error);
155 jQuery("#run_anova").show();
158 var anovaTable = response.anova_html_table;
160 jQuery("#anova_table").append('<div style="margin-top: 20px">' + anovaTable + '</div>').show();
162 var anovaFile = response.anova_table_file;
163 var modelFile = response.anova_model_file;
164 var meansFile = response.adj_means_file;
165 var diagnosticsFile = response.anova_diagnostics_file;
167 var fileNameAnova = anovaFile.split('/').pop();
168 var fileNameModel = modelFile.split('/').pop();
169 var fileNameMeans = meansFile.split('/').pop();
170 var fileNameDiagnostics = diagnosticsFile.split('/').pop()
172 anovaFile = "<a href=\"" + anovaFile + "\" download=" + fileNameAnova + ">[Anova table]</a>";
173 modelFile = "<a href=\"" + modelFile + "\" download=" + fileNameModel + ">[Model Summary]</a>";
174 meansFile = "<a href=\"" + meansFile + "\" download=" + fileNameMeans + ">[Adjusted Means]</a>";
176 diagnosticsFile = "<a href=\"" + diagnosticsFile
177 + "\" download=" + fileNameDiagnostics + ">[Model Diagnostics]</a>";
179 jQuery("#anova_table")
180 .append('<br /> <strong>Download:</strong> '
187 jQuery("#anova_message").empty();
189 jQuery("#run_anova").show();
192 // showMessage("There is no anova output for this dataset.");
193 jQuery("#run_anova").show();
195 clearTraitSelection();
198 error: function(response) {
199 showMessage("Error occured running the anova analysis.");
200 jQuery("#run_anova").show();
201 clearTraitSelection();
205 jQuery("#anova_message").empty();
206 jQuery("#run_anova").show();
207 clearTraitSelection();
214 function listAnovaTraits () {
216 var trialId = getTrialId();
221 data: {'trial_id': trialId},
222 url: '/anova/traits/list/',
223 success: function(response) {
224 var traits = response.anova_traits;
227 formatAnovaTraits(traits);
228 jQuery("#run_anova").show();
230 showMessage('This trial has no phenotyped traits.');
231 jQuery("#run_anova").hide();
234 error: function(response) {
235 showMessage("Error occured listing anova traits.");
236 jQuery("#run_anova").hide();
243 function formatAnovaTraits(traits) {
247 for (var i = 0; i < traits.length; i++) {
248 var traitName = traits[i].trait_name;
250 var idName = JSON.stringify(traits[i]);
252 + '<a href="#">' + traitName + '<span class=value>' + idName + '</span></a>'
256 var traitsList = '<dl id="anova_selected_trait" class="anova_dropdown">'
257 + '<dt> <a href="#"><span>Select a trait</span></a></dt>'
263 jQuery("#anova_select_a_trait_div").empty().append(traitsList).show();
265 jQuery(".anova_dropdown dt a").click(function() {
266 jQuery(".anova_dropdown dd ul").toggle();
269 jQuery(".anova_dropdown dd ul li a").click(function() {
271 var text = jQuery(this).html();
273 jQuery(".anova_dropdown dt a span").html(text);
274 jQuery(".anova_dropdown dd ul").hide();
276 var traitIdName = jQuery("#anova_selected_trait").find("dt a span.value").html();
277 traitIdName = JSON.parse(traitIdName);
279 var traitId = traitIdName.trait_id;
280 var traitName = traitIdName.trait_name;
282 console.log('id ' + traitId + ' name ' + traitName)
284 jQuery("#anova_selected_trait_name").val(traitName);
285 jQuery("#anova_selected_trait_id").val(traitId);
289 jQuery(".anova_dropdown").bind('click', function(e) {
290 var clicked = jQuery(e.target);
292 if (!clicked.parents().hasClass("anova_dropdown"))
293 jQuery(".anova_dropdown dd ul").hide();
303 function clearTraitSelection () {
305 jQuery("#anova_selected_trait_name").val('');
306 jQuery("#anova_selected_trait_id").val('');
311 function getTrialId () {
313 var trialId = jQuery("#trial_id").val();
317 trialId = jQuery("#population_id").val();