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">×</span></button>
10 <h4 class="modal-title" id="nirsAnalysisTrainingDialog">Train Spectral Model</h4>
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." &>
20 <button class="btn btn-primary" onclick="Workflow.complete(this); return false;">Go to Next Step</button>
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)" &>
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>
36 <button class="btn btn-primary" id="nirs_analysis_training_dataset_train_select_step">Go to Next Step</button>
39 <&| /util/workflow.mas:step, title=> "Test Dataset" &>
40 <& /page/page_title.mas, title=>"Select the dataset you are interested in testing (optional)" &>
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>
56 <button class="btn btn-primary" id="nirs_analysis_training_dataset_test_select_step">Go to Next Step</button>
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>
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!" &>
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>
83 <button class="btn btn-primary" id="nirs_analysis_training_trait_select_step">Go to Next Step</button>
86 <&| /util/workflow.mas:step, title=> "Model Settings" &>
87 <& /page/page_title.mas, title=>"Select parameters for spectral modeling" &>
90 <button class="btn btn-info" id="nirs_analysis_training_dataset_info">More Info</button>
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>
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>
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>
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">
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">
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" >
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" >
168 <button class="btn btn-primary" id="nir_analysis_training_model_step">Train the Model</button>
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>
191 <div class="modal-footer">
192 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
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">×</span></button>
203 <h4 class="modal-title" id="nirsAnalysisTrainingInfoDialog">Train Spectral Model</h4>
205 <div class="modal-body">
206 <div class="container-fluid">
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>
217 <div class="modal-footer">
218 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
225 jQuery(document).ready(function(){
227 jQuery('#nirs_analysis_training_dataset_info').click(function(){
228 jQuery('#nirs_analysis_training_dialog_info').modal('show');
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'});
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());
245 if(selected_train.length > 1 || selected_train.length == 0) {
246 alert('Please select one dataset!');
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);
256 jQuery('#nirs_analysis_training_dataset_test_select_option').change(function(){
257 var opt = jQuery(this).val();
259 jQuery('#nirs_analysis_training_dataset_test_div').show();
262 jQuery('#nirs_analysis_training_dataset_test_div').hide();
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());
274 if(selected_test.length > 1) {
275 alert('Please select one dataset!');
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);
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);
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;
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;
322 url : '/ajax/Nirs/generate_results',
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
336 beforeSend: function(){
337 jQuery('#working_modal').modal('show');
339 success: function(response){
340 console.log(response);
341 if (response.error) {
342 alert(response.error);
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);
353 error: function(response){
354 alert('Error training NIRS!');
355 jQuery('#working_modal').modal('hide');
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');