2 * trials search, selections to combine etc...
3 * @author Isaak Y Tecle <iyt2@cornell.edu>
8 JSAN.use('jquery.blockUI');
11 var solGS = solGS || function solGS () {};
13 solGS.combinedTrials = {
15 getPopIds: function () {
16 var searchedPopsList = jQuery("#searched_trials_table tr").length;
19 if (searchedPopsList) {
20 tableId = 'searched_trials_table';
22 tableId = 'all_trials_table';
26 jQuery("#trial_search_result_select").show();
29 jQuery('#' +tableId + ' tr')
30 .filter(':has(:checkbox:checked)')
31 .bind('click', function() {
33 jQuery("#select_trials_btn").val('Done selecting');
34 var td = jQuery(this).html();
36 var selectedTrial = '<tr>' + td + '</tr>';
38 jQuery("#selected_trials_table tr:last").after(selectedTrial);
40 jQuery("#selected_trials_table tr").each( function() {
41 jQuery(this).find("input[type=checkbox]")
42 .attr('onclick', 'solGS.combinedTrials.removeSelectedTrial()')
43 .prop('checked', true);
47 jQuery("#selected_trials").show();
48 jQuery("#combine_trials_div").show();
49 jQuery("#search_again_div").hide();
54 hideTrialsList: function() {
55 jQuery("#trial_search_result").empty();
56 // jQuery("#trial_search_result").empty();
57 jQuery("#trial_search_result_select").hide();
58 jQuery("#trial_search_result_message").hide();
63 removeSelectedTrial: function() {
65 jQuery("#selected_trials_table tr").on("change", function() {
67 jQuery(this).remove();
69 if (jQuery("#selected_trials_table td").length == 0) {
70 jQuery("#selected_trials").hide();
71 jQuery("#combine_trials_div").hide();
72 jQuery("#search_again_div").hide();
73 jQuery("#select_trials_btn").val('Select');
82 searchAgain: function () {
84 var url = window.location.pathname;
86 if (url.match(/solgs\/search\/trials\/trait\//) != null) {
87 var traitId = jQuery("input[name='trait_id']").val();
88 url = '/solgs/search/result/populations/' + traitId;
90 url = '/solgs/search/trials/';
93 // jQuery('#trial_search_result').empty();
94 jQuery("#trial_search_result").empty();
96 jQuery("#trial_search_result_message").show();
97 jQuery("#trial_search_result_select").show();
98 jQuery("#select_trials_btn").val('Select');
103 combineTraitTrials: function () {
104 var trId = this.getTraitId();
105 var protocolId = jQuery('#genotyping_protocol_id').val();
107 var trialIds = this.getSelectedTrials();
109 var action = "/solgs/combine/trials/trait/" + trId + '/gp/' + protocolId;
110 var selectedPops = trId + "=" + trialIds + '&' + 'combine=combine';
112 jQuery.blockUI.defaults.applyPlatformOpacityRules = false;
113 jQuery.blockUI({message: 'Please wait..'});
120 success: function(res) {
124 var comboPopsId = res.combo_pops_id;
125 var newUrl = '/solgs/model/combined/trials/' + comboPopsId + '/trait/' + trId + '/gp/' + protocolId;;
128 window.location.href = newUrl;
130 } else if (res.pop_id) {
131 var args = {'pop_id': res.pop_id,
133 'genotyping_protocol_id': res.genotyping_protocol_id
136 this.goToSingleTrialTrainingPopPage(args);
142 if (res.not_matching_pops){
143 alert('populations ' + res.not_matching_pops +
144 ' were genotyped using different marker sets. ' +
145 'Please make new selections to combine.' );
146 window.location.href = '/solgs/search/result/populations/' + trId;
149 if (res.redirect_url) {
150 window.location.href = res.redirect_url;
159 getCombinedPopsId: function (comboPopsList) {
161 if (!comboPopsList) {
162 comboPopsList = this.getSelectedTrials();
165 comboPopsList = comboPopsList.unique();
167 var protocolId = jQuery('#genotyping_protocol_id').val();
168 var traitId = this.getTraitId();
169 var referer = window.location.href;
174 'trials': comboPopsList,
175 'genotyping_protocol_id': protocolId
178 if (comboPopsList.length > 1) {
182 url: "/solgs/get/combined/populations/id",
184 success: function(res) {
186 var comboPopsId = res.combo_pops_id;
188 if (window.Prototype) {
189 delete Array.prototype.toJSON;
193 'combo_pops_id' : [ comboPopsId ],
194 'combo_pops_list' : comboPopsList,
195 'trait_id' : traitId,
196 'genotyping_protocol_id': res.genotyping_protocol_id
199 solGS.combinedTrials.downloadCombinedTrialsTrainingPopData(args);
203 error: function(res) {
204 alert('Error occured getting combined trials unique id');
210 var popId = comboPopsList;
214 'genotyping_protocol_id': protocolId
217 this.downloadSingleTrialTrainingPopData(args);
223 downloadCombinedTrialsTrainingPopData: function (args) {
225 if (window.Prototype) {
226 delete Array.prototype.toJSON;
229 args['analysis_type'] = 'combine_populations';
230 args['data_set_type'] = 'multiple_populations';
232 var comboPopsId = args.combo_pops_id;
233 comboPopsId = comboPopsId[0];
234 var protocolId = args.genotyping_protocol_id;
236 var referer = window.location.href;
239 if (referer.match(/search\/trials\/trait\//)) {
240 var traitId = args.trait_id;
242 page = '/solgs/model/combined/trials/' + comboPopsId
243 + '/trait/' + traitId
244 + '/gp/' + protocolId;
247 page = '/solgs/populations/combined/' + comboPopsId + '/gp/' + protocolId;
250 solGS.waitPage(page, args);
255 displayCombinedTrialsTrainingPopPage: function(args) {
257 var trialsIds = args.combo_pops_list;
258 var protocolId = args.genotyping_protocol_id;
261 trialsIds = this.getSelectedTrials();
264 var action = "/solgs/retrieve/populations/data";
266 jQuery.blockUI.defaults.applyPlatformOpacityRules = false;
267 jQuery.blockUI({message: 'Please wait..'});
273 data: {'trials': trialsIds, 'genotyping_protocol_id': protocolId},
274 success: function(res) {
275 if (res.not_matching_pops == null) {
277 var combinedPopsId = res.combined_pops_id;
278 var protocolId = res.genotyping_protocol_id;
280 if (combinedPopsId) {
281 solGS.combinedTrials.goToCombinedTrialsTrainingPopPage(combinedPopsId, protocolId);
283 } else if (res.pop_id) {
286 'pop_id': res.pop_id,
288 'genotyping_protocol_id': res.genotyping_protocol_id
291 solGS.combinedTrials.goToSingleTrialTrainingPopPage(args);
295 } else if(res.not_matching_pops ) {
298 alert('populations ' + res.not_matching_pops +
299 ' were genotyped using different marker sets. ' +
300 'Please make new selections to combine.' );
304 error: function(res) {
306 alert('An error occured retrieving phenotype' +
307 'and genotype data for trials..');
314 getSelectedTrials: function () {
318 if (jQuery("#selected_trials_table").length) {
319 jQuery("#selected_trials_table tr")
322 var trialId = jQuery(this)
323 .find("input[type=checkbox]")
327 trialIds.push(trialId);
332 return trialIds.sort();
337 goToCombinedTrialsTrainingPopPage: function (comboPopsId, protocolId) {
339 var page = '/solgs/populations/combined/' + comboPopsId + '/gp/' + protocolId;
342 window.location = page;
344 alert('combined Trials id missing.')
349 goToSingleTrialTrainingPopPage: function (args) {
351 var referer = window.location.href;
353 var protocolId = args.genotyping_protocol_id;
355 if (referer.match(/search\/trials\/trait\//)) {
356 page = '/solgs/trait/' + args.trait_id + '/population/' + args.pop_id + '/gp/' + protocolId;
360 //var hostName = window.location.protocol + '//' + window.location.host;
361 page = '/solgs/population/' + args.pop_id + '/gp/' + protocolId ;
364 window.location = page;
369 downloadSingleTrialTrainingPopData: function (args) {
371 var referer = window.location.href;
373 var popId = args.trial_id;
374 var traitId = args.trait_id;
375 var protocolId = args.genotyping_protocol_id;
377 if (referer.match(/search\/trials\/trait\//)) {
378 page = '/solgs/trait/' + traitId + '/population/' + popId + '/gp/' + protocolId;
381 //var hostName = window.location.protocol + '//' + window.location.host;
382 page = '/solgs/population/' + popId + '/gp/' + protocolId;
386 'population_id' : [ popId],
387 'analysis_type' : 'training_dataset',
388 'data_set_type' : 'single_population',
389 'trait_id' : traitId,
390 'genotyping_protocol_id': args.genotyping_protocol_id,
393 solGS.waitPage(page, pageArgs);
398 getTraitId: function() {
400 var id = jQuery("input[name='trait_id']").val();
410 Array.prototype.unique =
414 for(var i=0; i<l; i++) {
415 for(var j=i+1; j<l; j++) {
416 // If this[i] is fo3und later in the array
417 if (this[i] === this[j])
426 jQuery(document).ready(function() {
427 jQuery('#select_trials_btn').on('click', function() {
428 solGS.combinedTrials.hideTrialsList();
434 jQuery(document).ready(function() {
435 jQuery('#combine_trait_trials').on('click', function() {
436 //combineTraitTrials();
437 solGS.combinedTrials.getCombinedPopsId();
443 jQuery(document).ready(function() {
444 jQuery('#combine_trials').on('click', function() {
446 solGS.combinedTrials.getCombinedPopsId();
451 // jQuery(document).ready(function() {
452 // jQuery('#search_again').on('click', function() {
458 jQuery(document).ready(function() {
460 var tableId = "#searched_trials_table";
461 var table = document.querySelector(tableId);
464 var rowsCount = table.rows.length;
467 jQuery("#trial_search_result_select").show();