4 selection population upload from lists
5 and files. Run prediction model on uploaded selection population
12 JSAN.use("CXGN.List");
13 JSAN.use("jquery.blockUI");
16 jQuery(document).ready( function() {
17 var list = new CXGN.List();
18 var listMenu = list.listSelect("prediction_genotypes", ["accessions"]);
21 if (listMenu.match(/option/) != null) {
23 jQuery("#prediction_genotypes_list").append(listMenu);
27 jQuery("#prediction_genotypes_list").append("<select><option>no lists found</option></select>");
33 jQuery(document).ready( function() {
36 jQuery("<option>", {value: '', selected: true}).prependTo("#prediction_genotypes_list_select");
37 jQuery("#prediction_genotypes_list_select").change(function() {
39 listId = jQuery(this).find("option:selected").val();
43 jQuery("#prediction_genotypes_list_upload").click(function() {
45 loadGenotypesList(listId);
54 function getGenotypesList(listId) {
56 var list = new CXGN.List();
60 genotypesList = list.getListData(listId);
63 var listName = list.listNameById(listId);
64 var listType;// = list.getListType(listId);
66 return {'name' : listName,
67 'list' : genotypesList.elements,
68 'list_type' : listType,
73 function loadGenotypesList(listId) {
75 var genoList = getGenotypesList(listId);
76 var listName = genoList.name;
77 var list = genoList.list;
78 var modelId = getModelId();
79 var traitId = getTraitId();
80 var selectionPopId = listId;
82 if ( list.length === 0) {
83 alert('The list is empty. Please select a list with content.' );
87 jQuery.blockUI.defaults.applyPlatformOpacityRules = false;
88 jQuery.blockUI({message: 'Please wait..'});
90 list = JSON.stringify(list);
95 data: {'id': 'uploaded_' + listId, 'name': listName, 'list': list},
96 url: '/solgs/upload/prediction/genotypes/list',
98 success: function(response) {
100 if (response.status == 'success') {
102 var uploadedSelPops = jQuery("#uploaded_selection_pops_table").doesExist();
104 if (uploadedSelPops == false) {
106 uploadedSelPops = getUserUploadedSelPop(listId);
107 jQuery("#uploaded_selection_populations").append(uploadedSelPops).show();
112 var url = '\'/solgs/model/'+ modelId + '/uploaded/prediction/'+ selectionPopId + '\'' ;
113 var listIdArg = '\'' + listId +'\'';
114 var listSource = '\'from_db\'';
116 var popIdName = {id : 'uploaded_' + listId, name: listName, pop_type: 'list_selection'};
117 popIdName = JSON.stringify(popIdName);
118 var hiddenInput = '<input type="hidden" value=\'' + popIdName + '\'/>';
120 var addRow = '<tr><td>'
121 +'<a href="#" onclick="javascript:loadPredictionOutput(' + url + ','
122 + listIdArg + ',' + listSource + '); return false;">' + '<data>'+ hiddenInput + '</data>'
125 + '<td id="list_prediction_output_' + listId + '">'
126 + '<a href="#" onclick="javascript:loadPredictionOutput(' + url + ','
127 + listIdArg + ',' + listSource + '); return false;">'
128 + '[ Predict ]'+ '</a>'
131 var tdId = '#list_prediction_output_' + listId;
132 var addedRow = jQuery(tdId).doesExist();
134 if (addedRow == false) {
135 jQuery("#uploaded_selection_pops_table tr:last").after(addRow);
143 alert("Error occured while uploading the list of selection genotypes.");
148 error: function(res) {
151 alert("Error occured while uploading the list of selection genotypes.\n\n" + res.responseText);
158 jQuery.fn.doesExist = function(){
159 return jQuery(this).length > 0;
163 function getModelId () {
166 var modelIdExists = jQuery("#model_id").doesExist();
167 var comboPopsIdExists = jQuery("#combo_pops_id").doesExist();
169 if ( modelIdExists == true ) {
170 modelId = jQuery("#model_id").val();
172 else if ( comboPopsIdExists == true ) {
173 modelId = jQuery("#combo_pops_id").val();
180 function getTraitId () {
183 var traitIdExists = jQuery("#trait_id").doesExist();
185 if ( traitIdExists == true ) {
186 traitId = jQuery("#trait_id").val();
193 function getUserUploadedSelPop (listId) {
195 var genoList = getGenotypesList(listId);
196 var listName = genoList.name;
197 var list = genoList.list;
198 var modelId = getModelId();
199 var traitId = getTraitId();
200 var selectionPopId = listId;
202 var url = '\'/solgs/model/'+ modelId + '/uploaded/prediction/'+ selectionPopId + '\'' ;
203 var listIdArg = '\'' + listId +'\'';
204 var listSource = '\'from_db\'';
205 var popIdName = {'id' : 'uploaded_' + listId, 'name' : listName, 'pop_type': 'list_selection'};
206 popIdName = JSON.stringify(popIdName);
207 var hiddenInput = '<input type="hidden" value=\'' + popIdName + '\'/>';
209 var uploadedSelPop ='<table id="uploaded_selection_pops_table" style="width:100%;text-align:left"><tr>'
210 + '<th>List-based selection population</th>'
211 + '<th>Predict GEBVs</th>'
215 + '<a href="#" onclick="javascript:loadPredictionOutput(' + url + ','
216 + listIdArg + ',' + listSource + '); return false;">' + '<data>'+ hiddenInput + '</data>'
219 + '<td id="list_prediction_output_' + listId + '">'
220 + '<a href="#" onclick="javascript:loadPredictionOutput(' + url + ','
221 + listIdArg + ',' + listSource + '); return false;">'
222 + '[ Predict ]'+ '</a>'
223 + '</td></tr></table>';
225 return uploadedSelPop;
229 function loadPredictionOutput (url, listId, listSource) {
231 var traitId = getTraitId();
232 var modelId = getModelId();
234 jQuery.blockUI.defaults.applyPlatformOpacityRules = false;
235 jQuery.blockUI({message: 'Please wait..'});
242 'uploaded_prediction': 1,
245 'prediction_id': listId,
246 'list_source': listSource,
249 success: function (response) {
251 if (response.status == 'success') {
253 var tdId = '#list_prediction_output_' + listId;
254 jQuery(tdId).html(response.output);
256 var page = document.URL;
258 if (page.match('/traits/all/population/') != null) {
259 listSelectionIndexPopulations();
260 listGenCorPopulations();
266 if(response.status == 'failed') {
267 alert("Error occured while uploading the list of selection genotypes.");
269 alert(response.status);
276 error: function(response) {
277 alert('error: ' + res.responseText);