Merge pull request #4106 from solgenomics/topic/wishlist
[sgn.git] / mason / analyses / upload_analysis_dialogs.mas
blob8d0b07c399f51a5c3e962efb7b0f9e76a153a3ee
1 <%args>
2 </%args>
4 <& /util/import_javascript.mas, classes => [ 'jquery', 'jquery.iframe-post-form' ], entries => [ ] &>
6 <div class="modal fade" id="upload_new_analysis_dialog" name="upload_new_analysis_dialog" tabindex="-1" role="dialog" aria-labelledby="uploadNewAnalysisDialog">
7     <div class="modal-dialog modal-xl" role="document">
8         <div class="modal-content">
9             <div class="modal-header" style="text-align: center">
10                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
11                 <h4 class="modal-title" id="uploadNewAnalysisDialog">Upload Analysis</h4>
12             </div>
13             <div class="modal-body">
14                 <div class="container-fluid">
16                     <form class="form-horizontal" method="post" enctype="multipart/form-data" encoding="multipart/form-data" id="upload_new_analysis_dialog_form" name="upload_new_analysis_dialog_form">
17                     
18                         <&| /util/workflow.mas, id=> "upload_new_analysis_workflow" &>
19                             <&| /util/workflow.mas:step, title=> "Intro" &>
20                                 <& /page/page_title.mas, title=>"This workflow will guide you through uploading an analysis to the database" &>
21                                 <p>You should have a spreadsheet (.csv) where the first column names the accession names or plots, and the subsequent columns have result values.</p>
22                                 <p>The header row should have 'stock_name' in the first column and subsequent column headers should be for a trait variable e.g. 'plant height|CO_323:0000123'</p>
24                                 <br/><br/>
25                                 <center>
26                                 <button class="btn btn-primary" onclick="Workflow.complete(this); return false;">Go to Next Step</button>
27                                 </center>
28                             </&>
29                             <&| /util/workflow.mas:step, title=> "Analysis" &>
30                                 <& /page/page_title.mas, title=>"Define the analysis" &>
32                                 <div class="form-group form-group-sm">
33                                     <label class="col-sm-3 control-label">Analysis Name (must be unique): </label>
34                                     <div class="col-sm-9">
35                                         <input class="form-control" id="upload_new_analysis_name" name="upload_new_analysis_name" type="text" />
36                                     </div>
37                                 </div>
38                                 <div class="form-group form-group-sm">
39                                     <label class="col-sm-3 control-label">Analysis Description: </label>
40                                     <div class="col-sm-9">
41                                         <input class="form-control" id="upload_new_analysis_description" name="upload_new_analysis_description" type="text" />
42                                     </div>
43                                 </div>
44                                 <div class="form-group form-group-sm">
45                                     <label class="col-sm-3 control-label">Analysis Protocol (describe the analysis as a formula arbitrarily) (e.g. lme4(t1 ~ rep + accession)): </label>
46                                     <div class="col-sm-9">
47                                         <input class="form-control" id="upload_new_analysis_protocol" name="upload_new_analysis_protocol" type="text" />
48                                     </div>
49                                 </div>
50                                 <div class="form-group form-group-sm">
51                                     <label class="col-sm-3 control-label">Analysis Of: </label>
52                                     <div class="col-sm-9">
53                                         <select class="form-control" id="upload_new_analysis_result_values_type" name="upload_new_analysis_result_values_type" >
54                                             <option value='analysis_result_values_match_accession_names'>Accession Names (for genetic blups, genetic results)</option>
55                                             <option value='analysis_result_values_match_precomputed_design'>Plot Names (for plot predictions, spatial, temporal results)</option>
56                                         </select>
57                                     </div>
58                                 </div>
59                                 <div class="form-group form-group-sm">
60                                     <label class="col-sm-3 control-label">Breeding Program: </label>
61                                     <div class="col-sm-9">
62                                         <div id="upload_new_analysis_breeding_program_div"></div>
63                                     </div>
64                                 </div>
65                                 <div class="form-group form-group-sm">
66                                     <label class="col-sm-3 control-label">Year: </label>
67                                     <div class="col-sm-9">
68                                         <div id="upload_new_analysis_year_div"></div>
69                                     </div>
70                                 </div>
71                                 <div class="form-group form-group-sm">
72                                     <label class="col-sm-3 control-label">Statistical Ontology Term (from SGNSTAT): </label>
73                                     <div class="col-sm-9">
74                                         <div id="upload_new_analysis_stat_term_div"></div>
75                                     </div>
76                                 </div>
77                                 <div class="form-group form-group-sm">
78                                     <label class="col-sm-3 control-label">Results File (.csv): </label>
79                                     <div class="col-sm-9" >
80                                         <input type="file" name="upload_new_analysis_file" id="upload_new_analysis_file" encoding="multipart/form-data" />
81                                     </div>
82                                 </div>
83                                 <div class="form-group form-group-sm">
84                                     <label class="col-sm-3 control-label">Dataset ID (optional): </label>
85                                     <div class="col-sm-9">
86                                         <input class="form-control" id="upload_new_analysis_dataset_id" name="upload_new_analysis_dataset_id" type="text" />
87                                     </div>
88                                 </div>
89                                 <div class="form-group form-group-sm">
90                                     <label class="col-sm-3 control-label">Result Summary (optional) (key:value comma separated. e.g. genetic_variance:0.6,phenotypic_variance:0.8): </label>
91                                     <div class="col-sm-9">
92                                         <input class="form-control" id="upload_new_analysis_result_summary_string" name="upload_new_analysis_result_summary_string" type="text" />
93                                     </div>
94                                 </div>
95                                 <div class="form-group form-group-sm">
96                                     <label class="col-sm-3 control-label">Compose Trait Info With Time Term (optional) (key||||value comma separated. e.g. harvest info|CO_323:0000101||||day 10|TIME:0002020) (all uploaded variables must be represented here): </label>
97                                     <div class="col-sm-9">
98                                         <input class="form-control" id="upload_new_analysis_result_trait_compose_info_string" name="upload_new_analysis_result_trait_compose_info_string" type="text"/>
99                                     </div>
100                                 </div>
102                                 <br/><br/>
103                                 <center>
104                                 <button class="btn btn-primary" id="upload_new_analysis_analysis_continue">Go to Next Step</button>
105                                 </center>
106                             </&>
107                             <&| /util/workflow.mas:step, title=> "Model" &>
108                                 <& /page/page_title.mas, title=>"Define the model used to generate the analysis results" &>
110                                 <div class="form-group form-group-sm">
111                                     <label class="col-sm-3 control-label">Select a Model: </label>
112                                     <div class="col-sm-9">
113                                         <div id="upload_new_analysis_model_select_div"></div>
114                                     </div>
115                                 </div>
117                                 <center>
118                                     <button type="button" class="btn btn-default" id="upload_new_analysis_model_button" >Create a New Model if Needed</button>
119                                 </center>
120                                 <hr>
122                                 <div id="upload_new_analysis_model_div" style="display:none">
123                                 
124                                     <div class="form-group form-group-sm">
125                                         <label class="col-sm-3 control-label">Model Name (must be unique): </label>
126                                         <div class="col-sm-9">
127                                             <input class="form-control" id="upload_new_analysis_model_name" name="upload_new_analysis_model_name" type="text" />
128                                         </div>
129                                     </div>
130                                     <div class="form-group form-group-sm">
131                                         <label class="col-sm-3 control-label">Model Description: </label>
132                                         <div class="col-sm-9">
133                                             <input class="form-control" id="upload_new_analysis_model_description" name="upload_new_analysis_model_description" type="text" />
134                                         </div>
135                                     </div>
136                                     <div class="form-group form-group-sm">
137                                         <label class="col-sm-3 control-label">Model Is Public: </label>
138                                         <div class="col-sm-9">
139                                             <select class="form-control" id="upload_new_analysis_model_is_public" name="upload_new_analysis_model_is_public" >
140                                                 <option value="yes">Yes</option>
141                                                 <option value="no">No</option>
142                                             </select>
143                                         </div>
144                                     </div>
145                                     <div class="form-group form-group-sm">
146                                         <label class="col-sm-3 control-label">Model Language (e.g. R, Python, F90): </label>
147                                         <div class="col-sm-9">
148                                             <input class="form-control" id="upload_new_analysis_model_language" name="upload_new_analysis_model_language" type="text"/>
149                                         </div>
150                                     </div>
151                                     <div class="form-group form-group-sm">
152                                         <label class="col-sm-3 control-label">Model Properties (required) (key:value comma separated e.g. conversion_criteria:0.01,protocol_id:2): </label>
153                                         <div class="col-sm-9">
154                                             <input class="form-control" id="upload_new_analysis_model_properties_string" name="upload_new_analysis_model_properties_string" type="text"/>
155                                         </div>
156                                     </div>
157                                     <div class="form-group form-group-sm">
158                                         <label class="col-sm-3 control-label">Application Name (e.g. MyAmazingPipeline): </label>
159                                         <div class="col-sm-9">
160                                             <input class="form-control" id="upload_new_analysis_model_application_name" name="upload_new_analysis_model_application_name" type="text"/>
161                                         </div>
162                                     </div>
163                                     <div class="form-group form-group-sm">
164                                         <label class="col-sm-3 control-label">Application Version (e.g. v1.01): </label>
165                                         <div class="col-sm-9">
166                                             <input class="form-control" id="upload_new_analysis_model_application_version" name="upload_new_analysis_model_application_version" type="text"/>
167                                         </div>
168                                     </div>
170                                 </div>
172                                 <div class="well well-sm">
173                                     <h4>Data files from this analysis model</h4>
174                                     
175                                     <table class="table table-bordered">
176                                         <thead>
177                                             <tr>
178                                                 <th>File Upload</th>
179                                                 <th>File Type</th>
180                                             </tr>
181                                         </thead>
182                                         <tbody>
183                                             <tr>
184                                                 <td>
185                                                     <div class="form-group form-group-sm">
186                                                         <label class="col-sm-3 control-label">Main Phenotype Data File To Archive (required) (this should be the primary data file input into the model e.g. MyPhenotypes.csv): </label>
187                                                         <div class="col-sm-9">
188                                                             <input id="upload_new_analysis_model_training_data_file" name="upload_new_analysis_model_training_data_file" type="file" encoding="multipart/form-data"/>
189                                                         </div>
190                                                     </div>
191                                                 </td>
192                                                 <td>
193                                                     <div class="form-group form-group-sm">
194                                                         <label class="col-sm-3 control-label">Archive Main Phenotype Data File Type (required) (e.g. MyAmazingPipeline_MainPhenotypeFile): </label>
195                                                         <div class="col-sm-9">
196                                                             <input class="form-control" id="upload_new_analysis_model_training_data_file_type" name="upload_new_analysis_model_training_data_file_type" type="text"/>
197                                                         </div>
198                                                     </div>
199                                                 </td>
200                                             </tr>
201                                             <tr>
202                                                 <td>
203                                                     <div class="form-group form-group-sm">
204                                                         <label class="col-sm-3 control-label">Model File To Archive (optional) (this should be a model weights file): </label>
205                                                         <div class="col-sm-9">
206                                                             <input id="upload_new_analysis_model_file" name="upload_new_analysis_model_file" type="file" encoding="multipart/form-data"/>
207                                                         </div>
208                                                     </div>
209                                                 </td>
210                                                 <td>
211                                                     <div class="form-group form-group-sm">
212                                                         <label class="col-sm-3 control-label">Archive Model File Type (optional) (e.g. MyAmazingPipeline_ModelWeights.Rds or MyAmazingPipeline_CNNWeights.hdf5): </label>
213                                                         <div class="col-sm-9">
214                                                             <input class="form-control" id="upload_new_analysis_model_file_type" name="upload_new_analysis_model_file_type" type="text"/>
215                                                         </div>
216                                                     </div>
217                                                 </td>
218                                             </tr>
219                                             <tr>
220                                                 <td>
221                                                     <div class="form-group form-group-sm">
222                                                         <label class="col-sm-3 control-label">(1) Auxiliary File To Archive (optional) (e.g. log file, param file, grm input file): </label>
223                                                         <div class="col-sm-9">
224                                                             <input id="upload_new_analysis_model_auxiliary_file_1" name="upload_new_analysis_model_auxiliary_file_1" type="file" encoding="multipart/form-data"/>
225                                                         </div>
226                                                     </div>
227                                                 </td>
228                                                 <td>
229                                                     <div class="form-group form-group-sm">
230                                                         <label class="col-sm-3 control-label">(1) Auxiliary File Type (optional): </label>
231                                                         <div class="col-sm-9">
232                                                             <input class="form-control" id="upload_new_analysis_model_auxiliary_file_type_1" name="upload_new_analysis_model_auxiliary_file_type_1" type="text"/>
233                                                         </div>
234                                                     </div>
235                                                 </td>
236                                             </tr>
237                                             <tr>
238                                                 <td>
239                                                     <div class="form-group form-group-sm">
240                                                         <label class="col-sm-3 control-label">(2) Auxiliary File To Archive (optional) (e.g. log file, param file, grm input file): </label>
241                                                         <div class="col-sm-9">
242                                                             <input id="upload_new_analysis_model_auxiliary_file_2" name="upload_new_analysis_model_auxiliary_file_2" type="file" encoding="multipart/form-data"/>
243                                                         </div>
244                                                     </div>
245                                                 </td>
246                                                 <td>
247                                                     <div class="form-group form-group-sm">
248                                                         <label class="col-sm-3 control-label">(2) Auxiliary File Type (optional): </label>
249                                                         <div class="col-sm-9">
250                                                             <input class="form-control" id="upload_new_analysis_model_auxiliary_file_type_2" name="upload_new_analysis_model_auxiliary_file_type_2" type="text"/>
251                                                         </div>
252                                                     </div>
253                                                 </td>
254                                             </tr>
255                                             <tr>
256                                                 <td>
257                                                     <div class="form-group form-group-sm">
258                                                         <label class="col-sm-3 control-label">(3) Auxiliary File To Archive (optional) (e.g. log file, param file, grm input file): </label>
259                                                         <div class="col-sm-9">
260                                                             <input id="upload_new_analysis_model_auxiliary_file_3" name="upload_new_analysis_model_auxiliary_file_3" type="file" encoding="multipart/form-data"/>
261                                                         </div>
262                                                     </div>
263                                                 </td>
264                                                 <td>
265                                                     <div class="form-group form-group-sm">
266                                                         <label class="col-sm-3 control-label">(3) Auxiliary File Type (optional): </label>
267                                                         <div class="col-sm-9">
268                                                             <input class="form-control" id="upload_new_analysis_model_auxiliary_file_type_3" name="upload_new_analysis_model_auxiliary_file_type_3" type="text"/>
269                                                         </div>
270                                                     </div>
271                                                 </td>
272                                             </tr>
273                                         </tbody>
274                                     </table>
275                                 </div>
277                                 <center>
278                                     <button type="button" class="btn btn-primary" id="upload_new_analysis_submit" >Submit</button>
279                                 </center>
280                             </&>
281                         </&>
282                     </form>
284                 </div>
285             </div>
286             <div class="modal-footer">
287                 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
288             </div>
289         </div>
290     </div>
291 </div>
293 <script>
295 jQuery(document).ready(function () {
297     jQuery('button[name="upload_new_analysis_button"]').click(function(){
298         get_select_box('years', 'upload_new_analysis_year_div', {'auto_generate': 1, 'id':'upload_new_analysis_year', 'name':'upload_new_analysis_year'});
299         get_select_box('breeding_programs', 'upload_new_analysis_breeding_program_div', { 'name' : 'upload_new_analysis_breeding_program_id', 'id' : 'upload_new_analysis_breeding_program_id' });
300         get_select_box('ontology_children', 'upload_new_analysis_stat_term_div', { 'selectbox_name' : 'upload_new_analysis_statistical_ontology_term', 'selectbox_id' : 'upload_new_analysis_statistical_ontology_term', 'parent_node_cvterm':'SGNSTAT:0000000', 'rel_cvterm': 'is_a', 'rel_cv': 'relationship', 'value_format':'names' });
301         get_select_box('models', 'upload_new_analysis_model_select_div', { 'id':'upload_new_analysis_model_id', 'name':'upload_new_analysis_model_id', 'empty':1 });
303         jQuery('#upload_new_analysis_dialog').modal('show');
304     });
306     jQuery('#upload_new_analysis_model_button').click(function(){
307         jQuery('#upload_new_analysis_model_div').show();
308     });
310     jQuery('#upload_new_analysis_analysis_continue').click(function(){
311         var upload_new_analysis_name = jQuery('#upload_new_analysis_name').val();
312         var upload_new_analysis_description = jQuery('#upload_new_analysis_description').val();
313         var upload_new_analysis_protocol = jQuery('#upload_new_analysis_protocol').val();
314         var upload_new_analysis_result_values_type = jQuery('#upload_new_analysis_result_values_type').val();
315         var upload_new_analysis_breeding_program_id = jQuery('#upload_new_analysis_breeding_program_id').val();
316         var upload_new_analysis_statistical_ontology_term = jQuery('#upload_new_analysis_statistical_ontology_term').val();
317         var upload_new_analysis_file = jQuery('#upload_new_analysis_file').val();
319         if (upload_new_analysis_name == '' || upload_new_analysis_description == '') {
320             alert('Please give an analysis name and description');
321             return false;
322         }
323         else if (upload_new_analysis_protocol == '') {
324             alert('Please give an analysis protocol');
325             return false;
326         }
327         else if (upload_new_analysis_result_values_type == '') {
328             alert('Please select result values type');
329             return false;
330         }
331         else if (upload_new_analysis_breeding_program_id == '') {
332             alert('Please select a breeding program');
333             return false;
334         }
335         else if (upload_new_analysis_statistical_ontology_term == '') {
336             alert('Please select a statistical ontology term');
337             return false;
338         }
339         else if (upload_new_analysis_file === '') {
340             alert('Please select a results file');
341             return false;
342         }
343         else {
344             Workflow.complete('#upload_new_analysis_analysis_continue');
345             Workflow.focus('#upload_new_analysis_workflow', 2);
346             return false;
347         }
348     });
350     jQuery('#upload_new_analysis_submit').click( function() {
351         var uploadFile = jQuery("#upload_new_analysis_file").val();
352         jQuery('#upload_new_analysis_dialog_form').attr("action", "/ajax/analysis/store/spreadsheet");
353         if (uploadFile === '') {
354             alert("Please select a file");
355             return;
356         }
358         var upload_new_analysis_model_id = jQuery('#upload_new_analysis_model_id').val();
359         var upload_new_analysis_model_name = jQuery('#upload_new_analysis_model_name').val();
360         var upload_new_analysis_model_description = jQuery('#upload_new_analysis_model_description').val();
361         var upload_new_analysis_model_is_public = jQuery('#upload_new_analysis_model_is_public').val();
362         var upload_new_analysis_model_language = jQuery('#upload_new_analysis_model_language').val();
363         var upload_new_analysis_model_properties_string = jQuery('#upload_new_analysis_model_properties_string').val();
364         var upload_new_analysis_model_application_name = jQuery('#upload_new_analysis_model_application_name').val();
365         var upload_new_analysis_model_application_version = jQuery('#upload_new_analysis_model_application_version').val();
366         var upload_new_analysis_model_training_data_file = jQuery('#upload_new_analysis_model_training_data_file').val();
367         var upload_new_analysis_model_training_data_file_type = jQuery('#upload_new_analysis_model_training_data_file_type').val();
368         var upload_new_analysis_model_file = jQuery('#upload_new_analysis_model_file').val();
369         var upload_new_analysis_model_file_type = jQuery('#upload_new_analysis_model_file_type').val();
370         var upload_new_analysis_model_auxiliary_file_1 = jQuery('#upload_new_analysis_model_auxiliary_file_1').val();
371         var upload_new_analysis_model_auxiliary_file_type_1 = jQuery('#upload_new_analysis_model_auxiliary_file_type_1').val();
372         var upload_new_analysis_model_auxiliary_file_2 = jQuery('#upload_new_analysis_model_auxiliary_file_2').val();
373         var upload_new_analysis_model_auxiliary_file_type_2 = jQuery('#upload_new_analysis_model_auxiliary_file_type_2').val();
374         var upload_new_analysis_model_auxiliary_file_3 = jQuery('#upload_new_analysis_model_auxiliary_file_3').val();
375         var upload_new_analysis_model_auxiliary_file_type_3 = jQuery('#upload_new_analysis_model_auxiliary_file_type_3').val();
377         if (upload_new_analysis_model_id != '' && upload_new_analysis_model_name != '') {
378             alert('Please select a model or create a new model, not both!');
379             return false;
380         }
381         if (upload_new_analysis_model_id == '' && upload_new_analysis_model_name == '') {
382             alert('Please select a saved model or give a new model name');
383             return false;
384         }
385         if (upload_new_analysis_model_id == '' && upload_new_analysis_model_description == '') {
386             alert('Please give a new model description');
387             return false;
388         }
389         if (upload_new_analysis_model_id == '' && upload_new_analysis_model_is_public == '') {
390             alert('Please give a new model is public');
391             return false;
392         }
393         if (upload_new_analysis_model_id == '' && upload_new_analysis_model_language == '') {
394             alert('Please give a new model language');
395             return false;
396         }
397         if (upload_new_analysis_model_id == '' && upload_new_analysis_model_properties_string == '') {
398             alert('Please give a new model properties. At least one key:value!');
399             return false;
400         }
401         if (upload_new_analysis_model_id == '' && upload_new_analysis_model_application_name == '') {
402             alert('Please give a new model application name');
403             return false;
404         }
405         if (upload_new_analysis_model_id == '' && upload_new_analysis_model_application_version == '') {
406             alert('Please give a new model application version');
407             return false;
408         }
409         if (upload_new_analysis_model_training_data_file === '') {
410             alert('Please give a new model training data file (or the main phenotype file you used to do the analysis)');
411             return false;
412         }
413         if (upload_new_analysis_model_training_data_file_type == '') {
414             alert('Please give a new model training data file type (or the main phenotype file you used to do the analysis)');
415             return false;
416         }
417         if ( (upload_new_analysis_model_file == '' && upload_new_analysis_model_file_type != '') || (upload_new_analysis_model_file != '' && upload_new_analysis_model_file_type == '') ) {
418             alert('If you give a new model file, please give a new model file type also');
419             return false;
420         }
421         if ( (upload_new_analysis_model_auxiliary_file_1 == '' && upload_new_analysis_model_auxiliary_file_type_1 != '') || (upload_new_analysis_model_auxiliary_file_1 != '' && upload_new_analysis_model_auxiliary_file_type_1 == '') ) {
422             alert('If you give a new model aux file 1, please give a new model aux file 1 type also');
423             return false;
424         }
425         if ( (upload_new_analysis_model_auxiliary_file_2 == '' && upload_new_analysis_model_auxiliary_file_type_2 != '') || (upload_new_analysis_model_auxiliary_file_2 != '' && upload_new_analysis_model_auxiliary_file_type_2 == '') ) {
426             alert('If you give a new model aux file 2, please give a new model aux file 2 type also');
427             return false;
428         }
429         if ( (upload_new_analysis_model_auxiliary_file_3 == '' && upload_new_analysis_model_auxiliary_file_type_3 != '') || (upload_new_analysis_model_auxiliary_file_3 != '' && upload_new_analysis_model_auxiliary_file_type_3 == '') ) {
430             alert('If you give a new model aux file 3, please give a new model aux file 3 type also');
431             return false;
432         }
434         jQuery("#upload_new_analysis_dialog_form").submit();
435     });
437     jQuery('#upload_new_analysis_dialog_form').iframePostForm({
438         json: true,
439         post: function () {
440             jQuery('#working_modal').modal("show");
441         },
442         complete: function (response) {
443             jQuery('#working_modal').modal("hide");
444             console.log(response);
445             if (response.error) {
446                 alert(response.error);
447             }
448             else if (response.error_messages) {
449                 alert(response.error_messages);
450             }
451             else {
452                 alert('Successfully saved! Page will now refresh!')
453                 location.reload();
454             }
455         },
456         error: function(response) {
457             jQuery('#working_modal').modal("hide");
458             alert("An error occurred uploading analysis");
459         }
460     });
464 </script>