Merge pull request #4272 from solgenomics/topic/fix-vcf-download
[sgn.git] / mason / tools / nirs / nirs_analysis_train_dialogs.mas
blob5a4b852e1c29dfa2c3a34a8b7c6e541722807dd9
3 <!--button class="btn btn-success" id="nirs_analysis_training_dialog_show">Train NIRS Model</button-->
5 <div class="modal fade" id="nirs_analysis_training_dialog" name="nirs_analysis_training_dialog" tabindex="-1" role="dialog" aria-labelledby="nirsAnalysisTrainingDialog" data-backdrop="static">
6   <div class="modal-dialog modal-xl" role="document">
7     <div class="modal-content">
8       <div class="modal-header">
9         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
10         <h4 class="modal-title" id="nirsAnalysisTrainingDialog">Train Spectral Model</h4>
11       </div>
12       <div class="modal-body">
13         <div class="container-fluid">
15             <&| /util/workflow.mas, id=> "nirs_analysis_training_workflow" &>
16                 <&| /util/workflow.mas:step, title=> "Intro" &>
17                     <& /page/page_title.mas, title=>"This workflow will guide you through the training of a model using spectra and phenotypes in the database." &>
18                     <br/><br/>
19                     <center>
20                     <button class="btn btn-primary" onclick="Workflow.complete(this); return false;">Go to Next Step</button>
21                     </center>
22                 </&>
23                 <&| /util/workflow.mas:step, title=> "Train Dataset" &>
24                     <& /page/page_title.mas, title=>"Select the dataset you are interested in training (the accessions or plots or tissues samples in the dataset need to have spectra uploaded)" &>
25                     <br/><br/>
26                     <form class="form-horizontal">
27                         <div class="form-group">
28                             <label class="col-sm-1 control-label">Dataset: </label>
29                             <div class="col-sm-11" >
30                                 <div id="nirs_analysis_training_dataset_train_select_div"></div>
31                             </div>
32                         </div>
33                     </form>
34                     <br/><br/>
35                     <center>
36                     <button class="btn btn-primary" id="nirs_analysis_training_dataset_train_select_step">Go to Next Step</button>
37                     </center>
38                 </&>
39                 <&| /util/workflow.mas:step, title=> "Test Dataset" &>
40                     <& /page/page_title.mas, title=>"Select the dataset you are interested in testing (optional)" &>
41                     <br/><br/>
43                     <div class="form-horizontal" >
44                         <div class="form-group">
45                             <label class="col-sm-7 control-label">Select Custom Dataset for Testing? If No, the training and test set will be partitioned from the training dataset you already selected: </label>
46                             <div class="col-sm-5" >
47                                 <select class="form-control" id="nirs_analysis_training_dataset_test_select_option">
48                                     <option value="No">No</option>
49                                     <option value="Yes">Yes</option>
50                                 </select>
51                             </div>
52                         </div>
53                     </div>
55                     <center>
56                     <button class="btn btn-primary" id="nirs_analysis_training_dataset_test_select_step">Go to Next Step</button>
57                     </center>
58                     <br/><br/>
60                     <div class="form-horizontal" id="nirs_analysis_training_dataset_test_div" style="display:none">
61                         <div class="form-group">
62                             <label class="col-sm-1 control-label">Dataset (Optional) (the accessions or plots or tissues samples in the dataset need to have spectra uploaded): </label>
63                             <div class="col-sm-11" >
64                                 <div id="nirs_analysis_training_dataset_test_select_div"></div>
65                             </div>
66                         </div>
67                     </div>
69                 </&>
70                 <&| /util/workflow.mas:step, title=> "Trait" &>
71                     <& /page/page_title.mas, title=>"Select the trait you are interested in. If there are no available options, the training and test datasets you selected do not share any traits in common!" &>
72                     <br/><br/>
73                     <form class="form-horizontal">
74                         <div class="form-group">
75                             <label class="col-sm-1 control-label">Trait: </label>
76                             <div class="col-sm-11" >
77                                 <div id="nirs_analysis_training_trait_select_div"></div>
78                             </div>
79                         </div>
80                     </form>
81                     <br/><br/>
82                     <center>
83                     <button class="btn btn-primary" id="nirs_analysis_training_trait_select_step">Go to Next Step</button>
84                     </center>
85                 </&>
86                 <&| /util/workflow.mas:step, title=> "Model Settings" &>
87                     <& /page/page_title.mas, title=>"Select parameters for spectral modeling" &>
89                     <center>
90                     <button class="btn btn-info" id="nirs_analysis_training_dataset_info">More Info</button>
91                     </center>
92                     <hr>
94                     <div class="form-horizontal">
95                         <div class="form-group">
96                             <label class="col-sm-3 control-label">Spectrometer format: </label>
97                             <div class="col-sm-9" >
99                                 <select class="form-control input-sm" id="nirs_analysis_training_format_select">
100                                     <option value="">Select spectrometer format</option>
101                                     <option selected value="SCIO">SCIO</option>
102                                     <option value="QST">QST</option>
103                                     <option value="Foss6500">Foss6500</option>
104                                     <option value="Foss DS2500">Foss DS2500</option>
105                                     <option value="Foss XDS">Foss XDS</option>
106                                     <option value="BunchiN500">BunchiN500</option>
107                                     <option value="LinkSquare">LinkSquare</option>
108                                     <option value="ASD Qualityspec">ASD Qualityspec</option>
109                                     <option value="ASD LabSpec">ASD LabSpec</option>
110                                     <option value="Specim FX17">Specim FX17</option>
111                                 </select>
112                             </div>
113                         </div>
114                         <div class="form-group">
115                             <label class="col-sm-3 control-label">Cross-validation methods: </label>
116                             <div class="col-sm-9" >
118                                 <select class="form-control input-sm" id="nirs_analysis_training_cv_select">
119                                     <option value="">Select cross-validation</option>
120                                     <option selected value="random">Random</option>
121                                     <option value="stratified">Stratified</option>
122                                     <option value="CV1">CV1</option>
123                                     <option value="CV2">CV2</option>
124                                     <option value="CV0">CV0</option>
125                                     <option value="CV00">CV00</option>
126                                 </select>
127                             </div>
128                         </div>
129                         <div class="form-group">
130                             <label class="col-sm-3 control-label">Algorithm: </label>
131                             <div class="col-sm-9" >
132                                 <select class="form-control" id="nirs_analysis_training_nirs_model_algorithm">
133                                     <option value="pls">PLSR</option>
134                                     <option value="rf">Random Forest</option>
135                                     <option value="svmLinear">SVM with Linear Kernel</option>
136                                     <option value="svmRadial">SVM with Radial Kernel</option>
137                                 </select>
138                             </div>
139                         </div>
140                         <div class="form-group">
141                             <label class="col-sm-3 control-label">Number of sampling iterations: </label>
142                             <div class="col-sm-9" >
143                                 <input class="form-control" type="number" id="nirs_analysis_training_niter_select" name="niter_select" min="1" max="100" step="1" value="10">
144                             </div>
145                         </div>
146                         <div class="form-group">
147                             <label class="col-sm-3 control-label">Tuning length: </label>
148                             <div class="col-sm-9" >
149                                 <input class="form-control" type="number" id="nirs_analysis_training_tuneLength_select" name="tuneLength_select" min="1" max="30" step="1" value="10">
150                             </div>
151                         </div>
152                         <div class="form-group">
153                             <label class="col-sm-3 control-label">Include preprocessing?: </label>
154                             <div class="col-sm-9" >
155                                 <input type="checkbox" id="nirs_analysis_training_preprocessing_select" name="preprocessing_select" >
156                             </div>
157                         </div>
158                         <div class="form-group">
159                             <label class="col-sm-3 control-label">Show random forest variable importance? (Note this may take a long time to run): </label>
160                             <div class="col-sm-9" >
161                                 <input type="checkbox" id="nirs_analysis_training_rf_var_imp_select" name="rf_var_imp_select" >
162                             </div>
163                         </div>
164                     </div>
166                     <br/><br/>
167                     <center>
168                     <button class="btn btn-primary" id="nir_analysis_training_model_step">Train the Model</button>
169                     </center>
170                 </&>
171                 <&| /util/workflow.mas:step, title=> "Summary" &>
172                     <& /page/page_title.mas, title=>"Summary of the parameters selected for model creation" &>
174                     <div id="nir_analysis_training_model_performance_results"></div>
176                     <div class="form-horizontal">
177                         <div class="form-group">
178                             <label class="col-sm-3 control-label">Do you want to save the model for future predictions?: </label>
179                             <div class="col-sm-9" >
180                                 <button class="btn btn-primary" id="nir_analysis_training_model_save_step">Save the Model</button>
181                             </div>
182                         </div>
183                     </div>
185                 </&>
186             </&>
188         </div>
190       </div>
191       <div class="modal-footer">
192         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
193       </div>
194     </div>
195   </div>
196 </div>
198 <div class="modal fade" id="nirs_analysis_training_dialog_info" name="nirs_analysis_training_dialog_info" tabindex="-1" role="dialog" aria-labelledby="nirsAnalysisTrainingInfoDialog" data-backdrop="static">
199   <div class="modal-dialog" role="document">
200     <div class="modal-content">
201       <div class="modal-header">
202         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
203         <h4 class="modal-title" id="nirsAnalysisTrainingInfoDialog">Train Spectral Model</h4>
204       </div>
205       <div class="modal-body">
206         <div class="container-fluid">
208             <h1>More </h1>
209             <ul>
210               <li>"CV1": untested lines in tested environments</li>
211               <li>"CV2": tested lines in tested environments</li>
212               <li>"CV0": tested lines in untested environments</li>
213               <li>"CV00": untested lines in untested environments</li>
214             </ul>
215         </div>
216       </div>
217       <div class="modal-footer">
218         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
219       </div>
220     </div>
221   </div>
222 </div>
224 <script>
225 jQuery(document).ready(function(){
227     jQuery('#nirs_analysis_training_dataset_info').click(function(){
228         jQuery('#nirs_analysis_training_dialog_info').modal('show');
229     });
231     jQuery('#nirs_analysis_training_dialog_show').click(function(){
232         jQuery('#nirs_analysis_training_dialog').modal('show');
234         get_select_box('datasets','nirs_analysis_training_dataset_train_select_div', {'checkbox_name':'nirs_analysis_training_dataset_train_select_id'});
235         get_select_box('datasets','nirs_analysis_training_dataset_test_select_div', {'checkbox_name':'nirs_analysis_training_dataset_test_select_id'});
236     });
238     var nirs_analysis_training_dataset_train_id;
239     jQuery('#nirs_analysis_training_dataset_train_select_step').click(function(){
240         var selected_train = [];
241         jQuery('input[name="nirs_analysis_training_dataset_train_select_id"]:checked').each(function() {
242             selected_train.push(jQuery(this).val());
243         });
245         if(selected_train.length > 1 || selected_train.length == 0) {
246             alert('Please select one dataset!');
247             return false;
248         }
249         else {
250             nirs_analysis_training_dataset_train_id = selected_train[0];
251             Workflow.complete("#nirs_analysis_training_dataset_train_select_step");
252             Workflow.focus('#nirs_analysis_training_workflow', 2);
253         }
254     });
256     jQuery('#nirs_analysis_training_dataset_test_select_option').change(function(){
257         var opt = jQuery(this).val();
258         if (opt == 'Yes') {
259             jQuery('#nirs_analysis_training_dataset_test_div').show();
260         }
261         else {
262             jQuery('#nirs_analysis_training_dataset_test_div').hide();
263         }
264     });
266     var nirs_analysis_training_dataset_test_id;
267     jQuery('#nirs_analysis_training_dataset_test_select_step').click(function(){
269         var selected_test = [];
270         jQuery('input[name="nirs_analysis_training_dataset_test_select_id"]:checked').each(function() {
271             selected_test.push(jQuery(this).val());
272         });
274         if(selected_test.length > 1) {
275             alert('Please select one dataset!');
276             return false;
277         }
278         else {
279             nirs_analysis_training_dataset_test_id = selected_test[0];
281             get_select_box('datasets_intersect', 'nirs_analysis_training_trait_select_div', {'name':'nirs_analysis_training_trait_select_id', 'id':'nirs_analysis_training_trait_select_id', 'param':'traits', 'dataset_ids':JSON.stringify([nirs_analysis_training_dataset_train_id,nirs_analysis_training_dataset_test_id]) });
283             Workflow.complete("#nirs_analysis_training_dataset_test_select_step");
284             Workflow.focus('#nirs_analysis_training_workflow', 3);
285         }
286     });
288     var nirs_analysis_training_trait_id;
289     jQuery('#nirs_analysis_training_trait_select_step').click(function(){
290         nirs_analysis_training_trait_id = jQuery('#nirs_analysis_training_trait_select_id').val();
291         console.log(nirs_analysis_training_trait_id);
293         Workflow.complete("#nirs_analysis_training_trait_select_step");
294         Workflow.focus('#nirs_analysis_training_workflow', 4);
295     });
297     var nirs_analysis_training_format_select;
298     var nirs_analysis_training_cv_select;
299     var nirs_analysis_training_nirs_model_algorithm;
300     var nirs_analysis_training_tuneLength_select;
301     var nirs_analysis_training_preprocessing_select;
302     var nirs_analysis_training_niter_select;
303     var nirs_analysis_training_rf_var_imp_select;
304     var nirs_analysis_training_response;
306     jQuery('#nir_analysis_training_model_step').click(function(){
307         nirs_analysis_training_format_select = jQuery('#nirs_analysis_training_format_select').val();
308         nirs_analysis_training_cv_select = jQuery('#nirs_analysis_training_cv_select').val();
309         nirs_analysis_training_nirs_model_algorithm = jQuery('#nirs_analysis_training_nirs_model_algorithm').val();
310         nirs_analysis_training_tuneLength_select = jQuery('#nirs_analysis_training_tuneLength_select').val();
311         nirs_analysis_training_preprocessing_select = 0;
312         if (jQuery('#nirs_analysis_training_preprocessing_select').is(":checked")) {
313             nirs_analysis_training_preprocessing_select = 1;
314         }
315         nirs_analysis_training_niter_select = jQuery('#nirs_analysis_training_niter_select').val();
316         nirs_analysis_training_rf_var_imp_select = 0;
317         if (jQuery('#nirs_analysis_training_rf_var_imp_select').is(":checked")) {
318             nirs_analysis_training_rf_var_imp_select = 1;
319         }
321         jQuery.ajax({
322             url : '/ajax/Nirs/generate_results',
323             type : 'POST',
324             data : {
325                 'train_dataset_id' : nirs_analysis_training_dataset_train_id,
326                 'test_dataset_id' : nirs_analysis_training_dataset_test_id,
327                 'trait_id' : nirs_analysis_training_trait_id,
328                 'format' : nirs_analysis_training_format_select,
329                 'cv' : nirs_analysis_training_cv_select,
330                 'algorithm' : nirs_analysis_training_nirs_model_algorithm,
331                 'niter' : nirs_analysis_training_niter_select,
332                 'tune' : nirs_analysis_training_tuneLength_select,
333                 'preprocessing' : nirs_analysis_training_preprocessing_select,
334                 'rf' : nirs_analysis_training_rf_var_imp_select
335             },
336             beforeSend: function(){
337                 jQuery('#working_modal').modal('show');
338             },
339             success: function(response){
340                 console.log(response);
341                 if (response.error) {
342                     alert(response.error);
343                 }
344                 nirs_analysis_training_response = response;
346                 jQuery('#working_modal').modal('hide');
348                 jQuery('#nir_analysis_training_model_performance_results').html("<div class='well'>"+response.performance_output+"</div>");
350                 Workflow.complete("#nir_analysis_training_model_step");
351                 Workflow.focus('#nirs_analysis_training_workflow', 5);
352             },
353             error: function(response){
354                 alert('Error training NIRS!');
355                 jQuery('#working_modal').modal('hide');
356             }
357         });
358     });
361     jQuery('#nir_analysis_training_model_save_step').click(function(){
362         jQuery('#generic_save_analysis_analysis_to_save').prop('disabled', 'disabled');
363         jQuery('#generic_save_analysis_model_language').val('R');
364         jQuery('#generic_save_analysis_model_type').val('waves_nirs_spectral_predictions');
365         jQuery('#generic_save_analysis_model_properties').val(JSON.stringify(nirs_analysis_training_response.model_properties));
366         jQuery('#generic_save_analysis_model_application_name').val("Jenna's Waves R Package NIRs Analysis");
367         jQuery('#generic_save_analysis_model_application_version').val("V1.01");
368         jQuery('#generic_save_analysis_model_file').val(nirs_analysis_training_response.model_file);
369         jQuery('#generic_save_analysis_model_archived_model_file_type').val(nirs_analysis_training_response.model_file_type);
370         jQuery('#generic_save_analysis_model_training_data_file').val(nirs_analysis_training_response.training_data_file);
371         jQuery('#generic_save_analysis_model_archived_training_data_file_type').val(nirs_analysis_training_response.training_data_file_type);
372         jQuery('#generic_save_analysis_model_auxiliary_files').val(JSON.stringify(nirs_analysis_training_response.model_aux_files));
373         jQuery('#generic_save_analysis_dataset_id').val(nirs_analysis_training_dataset_train_id);
375         jQuery('#generic_save_analysis_dialog').modal('show');
376     });
379 </script>