Merge pull request #5205 from solgenomics/topic/generic_trial_upload
[sgn.git] / mason / tools / nirs / nirs_analysis_predict_dialogs.mas
blob8b86850439e9de1ba1b18420983b684a615ba5e6
2 <!--button class="btn btn-primary" id="nirs_analysis_prediction_dialog_show">Predict Phenotypes From Spectral Model</button-->
4 <div class="modal fade" id="nirs_analysis_prediction_dialog" name="nirs_analysis_prediction_dialog" tabindex="-1" role="dialog" aria-labelledby="nirsAnalysisPredictionDialog" data-backdrop="static">
5   <div class="modal-dialog modal-xl" role="document">
6     <div class="modal-content">
7       <div class="modal-header">
8         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
9         <h4 class="modal-title" id="nirsAnalysisPredictionDialog">Predict Phenotypes From Spectral Model</h4>
10       </div>
11       <div class="modal-body">
12         <div class="container-fluid">
14             <&| /util/workflow.mas, id=> "nirs_analysis_prediction_workflow" &>
15                 <&| /util/workflow.mas:step, title=> "Intro" &>
16                     <& /page/page_title.mas, title=>"This workflow will guide you through predicting phenotypes from trained spectral models in the database." &>
17                     <br/><br/>
18                     <center>
19                     <button class="btn btn-primary" onclick="Workflow.complete(this); return false;">Go to Next Step</button>
20                     </center>
21                 </&>
22                 <&| /util/workflow.mas:step, title=> "Test Dataset" &>
23                     <& /page/page_title.mas, title=>"Select the dataset you are interested in predicting phenotypes for (the accessions or plots or tissues samples in the dataset need to have spectra uploaded):" &>
24                     <br/><br/>
25                     <form class="form-horizontal">
26                         <div class="form-group">
27                             <label class="col-sm-1 control-label">Dataset: </label>
28                             <div class="col-sm-11" >
29                                 <div id="nirs_analysis_prediction_dataset_select_div"></div>
30                             </div>
31                         </div>
32                     </form>
33                     <center>
34                     <button class="btn btn-primary" id="nirs_analysis_prediction_dataset_select_step">Go to Next Step</button>
35                     </center>
36                 </&>
37                 <&| /util/workflow.mas:step, title=> "Spectral Model" &>
38                     <& /page/page_title.mas, title=>"Select the spectral model to use in predictions" &>
40                     <center>
41                     <button class="btn btn-info" id="nirs_analysis_prediction_dataset_info">More Info</button>
42                     </center>
43                     <hr>
45                     <div id="nirs_analysis_prediction_model_select_div"></div>
47                     <center>
48                     <button class="btn btn-primary" id="nir_analysis_prediction_model_step">Predict</button>
49                     </center>
50                 </&>
51                 <&| /util/workflow.mas:step, title=> "Summary" &>
52                     <& /page/page_title.mas, title=>"Summary of the predictions" &>
54                     <div class="form-horizontal">
55                         <div class="form-group">
56                             <label class="col-sm-3 control-label">Do you want to save the prediction results?: </label>
57                             <div class="col-sm-9" >
58                                 <button class="btn btn-primary" id="nir_analysis_prediction_analysis_save_step">Save the Results</button>
59                             </div>
60                         </div>
61                     </div>
63                     <div id="nir_analysis_prediction_analysis_predictions"></div>
65                 </&>
66             </&>
68         </div>
70       </div>
71       <div class="modal-footer">
72         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
73       </div>
74     </div>
75   </div>
76 </div>
78 <div class="modal fade" id="nirs_analysis_prediction_dialog_info" name="nirs_analysis_prediction_dialog_info" tabindex="-1" role="dialog" aria-labelledby="nirsAnalysisPredictionInfoDialog" data-backdrop="static">
79   <div class="modal-dialog" role="document">
80     <div class="modal-content">
81       <div class="modal-header">
82         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
83         <h4 class="modal-title" id="nirsAnalysisPredictionInfoDialog">Predict Phenotypes from Spectral Model</h4>
84       </div>
85       <div class="modal-body">
86         <div class="container-fluid">
88             <h1>More </h1>
90         </div>
91       </div>
92       <div class="modal-footer">
93         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
94       </div>
95     </div>
96   </div>
97 </div>
99 <script>
100 jQuery(document).ready(function(){
102     jQuery('#nirs_analysis_prediction_dataset_info').click(function(){
103         jQuery('#nirs_analysis_prediction_dialog_info').modal('show');
104     });
106     jQuery('#nirs_analysis_prediction_dialog_show').click(function(){
107         jQuery('#nirs_analysis_prediction_dialog').modal('show');
109         get_select_box('datasets','nirs_analysis_prediction_dataset_select_div', {'checkbox_name':'nirs_analysis_prediction_dataset_select_id'});
110     });
112     var nirs_analysis_prediction_dataset_id;
113     jQuery('#nirs_analysis_prediction_dataset_select_step').click(function(){
114         var selected = [];
115         jQuery('input[name="nirs_analysis_prediction_dataset_select_id"]:checked').each(function() {
116             selected.push(jQuery(this).val());
117         });
119         if(selected.length > 1 || selected.length == 0) {
120             alert('Please select one dataset!');
121             return false;
122         }
123         else {
124             nirs_analysis_prediction_dataset_id = selected[0];
126             get_select_box('trained_nirs_models','nirs_analysis_prediction_model_select_div', {'checkbox_name':'nirs_analysis_prediction_model_select_id'});
128             Workflow.complete("#nirs_analysis_prediction_dataset_select_step");
129             Workflow.focus('#nirs_analysis_prediction_workflow', 2);
130             window.scrollTo(0,0);
131         }
132     });
134     var nirs_analysis_prediction_model_id;
135     jQuery('#nir_analysis_prediction_model_step').click(function(){
136         var selected = [];
137         jQuery('input[name="nirs_analysis_prediction_model_select_id"]:checked').each(function() {
138             selected.push(jQuery(this).val());
139         });
141         if(selected.length > 1 || selected.length == 0) {
142             alert('Please select one model!');
143             return false;
144         }
145         else {
146             nirs_analysis_prediction_model_id = selected[0];
148             jQuery.ajax({
149                 url : '/ajax/Nirs/generate_predictions',
150                 type : 'POST',
151                 data : {
152                     'model_id' : nirs_analysis_prediction_model_id,
153                     'dataset_id' : nirs_analysis_prediction_dataset_id,
154                 },
155                 beforeSend: function(){
156                     jQuery('#working_modal').modal('show');
157                 },
158                 success: function(response){
159                     console.log(response);
160                     jQuery('#working_modal').modal('hide');
162                     if (response.error) {
163                         alert(response.error);
164                         return false;
165                     }
167                     var html = "<table class='table table-bordered table-hover'><thead><tr><th>Stock</th><th>Prediction</th></tr></thead><tbody>";
168                     for (var i=0; i<response.unique_plots.length; i++) {
169                         html = html + '<tr><td>'+response.unique_plots[i]+'</td><td>'+response.result_predictions[response.unique_plots[i]][response.unique_traits[0]][0]+'</td></tr>';
170                     }
171                     html = html + "</tbody></table>";
172                     jQuery('#nir_analysis_prediction_analysis_predictions').html(html);
174                     jQuery('#generic_save_analysis_protocol').val(response.protocol);
175                     jQuery('#generic_save_analysis_dataset_id').val(nirs_analysis_prediction_dataset_id);
176                     jQuery('#generic_save_analysis_accession_names').val(JSON.stringify(response.unique_accessions));
177                     jQuery('#generic_save_analysis_trait_names').val(JSON.stringify(response.unique_traits));
178                     jQuery('#generic_save_analysis_statistical_ontology_term').val(response.stat_term);
179                     jQuery('#generic_save_analysis_design').val(JSON.stringify(response.analysis_design));
180                     jQuery('#generic_save_analysis_result_values').val(JSON.stringify(response.result_predictions));
181                     jQuery('#generic_save_analysis_result_values_type').val('analysis_result_values_match_precomputed_design');
182                     jQuery('#generic_save_analysis_result_summary_values').val(JSON.stringify(response.result_summary));
183                     jQuery('#generic_save_analysis_model_type').val('waves_nirs_spectral_predictions');
185                     jQuery('#generic_save_analysis_model_select_form').hide();
186                     jQuery('#generic_save_analysis_model_name_div').hide();
187                     jQuery('#generic_save_analysis_model_description_div').hide();
188                     jQuery('#generic_save_analysis_model_is_public_div').hide();
189                     jQuery('#generic_save_analysis_model_id').val(nirs_analysis_prediction_model_id);
191                     jQuery('#generic_save_analysis_model_training_data_file').val(response.training_data_file);
192                     jQuery('#generic_save_analysis_model_archived_training_data_file_type').val(response.training_data_file_type);
194                     Workflow.complete("#nir_analysis_prediction_model_step");
195                     Workflow.focus('#nirs_analysis_prediction_workflow', 3);
196                     window.scrollTo(0,0);
197                 },
198                 error: function(response){
199                     alert('Error predicting phenotypes from NIRS!');
200                     jQuery('#working_modal').modal('hide');
201                 }
202             });
203         }
204     });
206     jQuery('#nir_analysis_prediction_analysis_save_step').click(function(){
207         jQuery('#generic_save_analysis_dialog').modal('show');
208     });
211 </script>