add a few more observation levels.
[sgn.git] / mason / breeders_toolbox / breeder_search_page.mas
blobe231c72751ba4d068c33e37b5fbf93045b00c24b
2 <%args>
3 $dataset_id => undef
4 </%args>
6 <& /util/import_javascript.mas, entries => ["wizard"] &>
7 <& /util/import_css.mas, paths => ['wizard.css'] &>
9 <& /page/page_title.mas, title=>"Search Wizard" &>
11 <div class="row">
12   <div class="col-md-12" style="margin-bottom:1em; text-align:right;">
13     Don't see your data? <button id="update_wizard_lists" class="btn btn-default">Refresh Lists</button>
14     <button id="update_wizard_show" class="btn btn-default">Update Wizard</button>
15   </div>
16 </div>
18 <& /breeders_toolbox/breeder_search_page_dataset_overlay.mas &>
20 <div id="wizard" class="row">
21   <span class="wizard-main">
22     <span class="wizard-columns"></span>
23     <div class="templates" style="display: none !important;">
25       <div class="wizard-unselected">
26         <div class="btn-group wizard-list-item">
27           <button type="button" class="btn btn-xs btn-success wizard-list-add">&#x2b;</button>
28           <a target="_blank" class="btn btn-xs btn-default wizard-list-name"></a>
29         </div>
30       </div>
32       <div class="wizard-selected">
33         <div class="btn-group wizard-list-item">
34           <button type="button" class="btn btn-xs btn-danger wizard-list-rem">&#10005;</button>
35           <a target="_blank" class="btn btn-xs btn-default wizard-list-name"></a>
36         </div>
37       </div>
39       <div class="wizard-column">
40         <div class="wizard-panel panel panel-default">
42           <span class="wizard-loader glyphicon glyphicon-refresh" aria-hidden="true"></span>
44           <div class="panel-heading">
45             <select class="wizard-type-select form-control input-sm form-inline">
46               <option value="" disabled selected>Select Column Type</option>
47               <optgroup class="wizard-types-group" label="--------------------"></optgroup>
48               <optgroup class="wizard-lists-group" label="Load Selection from List:"></optgroup>
49             </select>
50           </div>
52           <div class="panel-heading">
53             <input type="text" class="wizard-search form-control input-sm" placeholder="Search">
54           </div>
56           <div class="panel-body">
58             <div class="wizard-btn-center">
59               <div class="btn-group">
60                 <button class="wizard-select-all btn btn-default btn-xs">Select All</button
61                 ><button class="wizard-btn-tag btn btn-primary btn-xs">
62                   <span class="wizard-count-selected">0</span>/<span class="wizard-count-all">0</span>
63                 </button
64                 ><button class="wizard-select-clear btn btn-default btn-xs">Clear</button>
65               </div>
66             </div>
68             <ul class="wizard-list-unselected wizard-list well"></ul>
69             <ul class="wizard-list-selected wizard-list well"></ul>
71             <div class="wizard-btn-center wizard-union-toggle">
72               <div class="btn-group wizard-union-toggle-btn-group">
73                 <button type="button" class="btn btn-xs btn-default disabled">Match</button>
74                 <button type="button" class="btn btn-xs wizard-union-toggle-btn wizard-union-toggle-btn-any btn-primary active">ANY</button>
75                 <button type="button" class="btn btn-xs wizard-union-toggle-btn wizard-union-toggle-btn-min btn-default">MIN</button>
76                 <button type="button" class="btn btn-xs wizard-union-toggle-btn wizard-union-toggle-btn-all btn-default">ALL</button>
77               </div>
78               <div class="input-group input-group-sm wizard-union-toggle-min-group">
79                 <span class="input-group-btn">
80                   <button class="btn btn-default disabled" type="button">>=</button>
81                 </span>
82                 <input type="text" class="form-control wizard-union-toggle-min-value">
83                 <span class="input-group-btn">
84                   <button class="btn btn-xs wizard-union-toggle-min-type wizard-union-toggle-min-type-percent btn-primary active" type="button">%</button>
85                   <button class="btn btn-xs wizard-union-toggle-min-type wizard-union-toggle-min-type-count btn-default" type="button">#</button>
86                 </span>
87               </div>
88             </div>
90           </div>
92           <table class="wizard-save-to-list table panel-footer">
93             <&| /util/user.mas:logged_in &>
94               <tr>
95                 <td>
96                   <select class="wizard-add-to-list-id form-control input-sm">
97                     <option selected value="" disabled>Add to List...</option>
98                     <optgroup class="wizard-lists-group" label="--------------------"></optgroup>
99                   </select>
100                 </td>
101                 <td>
102                   <button class="wizard-add-to-list btn btn-sm btn-primary btn-block">Add</button>
103                 </td>
104               </tr>
105               <tr>
106                 <td>
107                   <input class="wizard-create-list-name form-control input-sm" type="text" placeholder="Create New List..."></input>
108                 </td>
109                 <td>
110                   <button class="wizard-create-list btn btn-primary btn-sm btn-block">Create</button>
111                 </td>
112               </tr>
113             </&>
114             <&| /util/user.mas:logged_out &>
115               <tr>
116                 <td><button class="btn btn-xs btn-primary" name="site_login_button">Log In</button> to save lists.</td>
117               </tr>
118             </&>
119           </table>
121         </div>
122       </div>
124     </div>
125   </span>
127   <div class="clearfix col-xs-12"></div>
129   <div class="wizard-datasets panel-group col-sm-12 col-md-6">
130     <div class="panel panel-default wizard-panel">
131       <div class="panel-heading">
132         <&| /util/user.mas:logged_out &><button class="btn btn-xs btn-primary" name="site_login_button">Log In</button> to</&>
133         Load/Create Datasets using <button class="btn btn-xs btn-default disabled wizard-btn-tag">Match</button> Columns
134       </div>
135       <&| /util/user.mas:logged_in &>
136         <div class="panel-body">
137           <div class="input-group">
138             <select class="form-control input-sm wizard-dataset-select">
139               <option selected value="" disabled>Load Dataset</option>
140               <optgroup class="wizard-dataset-group" label="--------------------"></optgroup>
141             </select>
142             <span class="input-group-btn">
143               <span><button style="width:5em;margin-left:4px;" class="btn btn-sm btn-primary wizard-dataset-load">Load</button></span>
144               <span><button style="width:9em;margin-left:4px;" class="btn btn-sm btn-primary wizard-dataset-public">Make Public</button></span>
145               <span><button style="width:5em;margin-left:4px;" class="btn btn-sm btn-danger wizard-dataset-delete">Delete</button></span>
146             </span>
147           </div>
148         </div>
149         <div class="panel-body" style="margin-top:-1px;">
150           <div class="input-group">
151             <input type="text" placeholder="Create New Dataset" class="form-control input-sm wizard-dataset-name" />
152             <span class="input-group-btn">
153               <span><button style="width:5em;margin-left:4px;" class="btn btn-sm btn-primary wizard-dataset-create">Create</button></span>
154             </span>
155           </div>
156         </div>
157       </&>
158     </div>
159   </div>
161   <div class="wizard-downloads panel-group col-sm-12 col-md-6" id="wiz-down-group" role="tablist" aria-multiselectable="true">
162     <&| /util/user.mas:logged_out &>
163       <div class="panel panel-default">
164         <div class="panel-heading">
165           <button class="btn btn-xs btn-primary" name="site_login_button">Log In</button> to download related data.
166         </div>
167       </div>
168     </&>
169     <&| /util/user.mas:logged_in &>
170       <div class="panel panel-default">
171         <div class="panel-heading" role="button" data-toggle="collapse" data-parent="#wiz-down-group" href="#wiz-down-1-c" aria-controls="wiz-down-1-c">
172           <span class="btnn btn-link">Related Genotype Data</span>
173         </div>
174         <div id="wiz-down-1-c" class="panel-collapse collapse" role="tabpanel">
175           <p style="margin: 15px; text-color: #999; font-size: 90%">Download matching genotype records from the database.  Select a <strong>single genotyping protocol</strong> and <strong>one or more accessions</strong> to download the matching genotype data.</p>
176           <table class="table">
177             <tr>
178               <td colspan="4">
179                 <span class="glyphicon glyphicon-info-sign" title="To download related genotype data, select 1 or more Accessions and optionally no more than 1 Genotyping Protocol in the wizard. If no genotyping protocol is selected, the database default protocol will be used. Click the checkbox here to compute genotypes for the selected accessions from genotypes of parents; this works for downloading genotypes, downloading the GRM, and performing GWAS."></span>
180                 <span>Download Genotype Data</span>
181                 <input class="wizard-download-genotypes-info form-control input-sm" type="text" disabled></input>
182               </td>
183               <td colspan="4">
184                   <span>Compute From Parents</span><br/>
185                   <input type="checkbox" class="wizard-download-genotypes-parents-compute">
186               </td>
187               <td colspan="4">
188                   <span>Include Duplicate Genotypes</span><br/>
189                   <input type="checkbox" class="wizard-download-genotypes-duplicates-include">
190               </td>
191             </tr>
192           </table>
193           <div class="panel-footer" style="border-top: 1px solid #ddd;">
194             <table class="table">
195                 <tr>
196                     <td colspan="12">
197                         <span class="glyphicon glyphicon-info-sign" title="You can use either chromosome or markers (markerset) to filter genotyping data. You cannot use both criteria at the same time."></span>
198                         <span>Filter by Chromosome or Markerset</span>
199                     </td>
200                 </tr>
201                 <tr>
202                     <td colspan="4">
203                         <span>Chromosome</span>
204                         <select class="wizard-download-genotypes-chromosome-number form-control input-sm"></select>
205                     </td>
206                     <td colspan="4">
207                         <span>Start Position</span>
208                         <input placeholder="" type="number" class="wizard-download-genotypes-start-position form-control input-sm">
209                     </td>
210                     <td colspan="4">
211                         <span>End Position</span>
212                         <input placeholder="" type="number" class="wizard-download-genotypes-end-position form-control input-sm">
213                     </td>
214                 </tr>
215                 <tr>
216                     <td colspan="6">
217                         <span>Marker / Markerset Filter</span>
218                         <select class="wizard-download-genotypes-marker-set-list-id form-control input-sm" id="wizard-download-genotypes-marker-set-list-id"></select>
219                     </td>
220                     <td colspan="6">
221                         <br/>
222                         <button class="btn btn-sm btn-default" onClick="window.open('/breeders/markers', '_blank');">Manage Markersets</button>
223                     </td>
224                 </tr>
225                 <tr>
226                     <td colspan="6">
227                         <span>Genotypes Download Format</span>
228                         <select class="wizard-download-genotypes-format form-control input-sm" >
229                             <option value="VCF">VCF File Format</option>
230                             <option value="DosageMatrix">Dosage Matrix File Format (.tsv)</option>
231                         </select>
232                     </td>
233                     <td colspan="6">
234                     </td>
235                 </tr>
236                 <tr>
237                     <td colspan="8">
238                         <span class="glyphicon glyphicon-info-sign" title="Select accessions, and optionally a genotyping protocol. If no genotyping protocol is selected, the default genotyping protocol is used in your system. If you want to filter genotypes, use the chromosome, start position, end position, or markerset. Can compute genotypes from parents if the parents of the accessions you selected have genotypes by checking the checkbox. Genotypes can be downloaded in VCF and Dosage Matrix Formats."></span>
239                         <span>Download Genotypes</span><br/>
240                         <button class="wizard-download-genotypes btn btn-sm btn-primary">
241                             <span class="glyphicon glyphicon-download" aria-hidden="true"></span>
242                             Download Genotypes
243                         </button>
244                         <input class="wizard-download-genotypes-info2 form-control btn-warning" type="text"></input>  <!-- warn too many genotype protocols-->
245                         <input class="wizard-download-genotypes-info3 form-control btn-warning" type="text"></input>  <!-- show default protocol -->
246                         <input class="wizard-download-genotypes-info4 form-control btn-warning" type="text"></input>  <!-- show slow download warning -->
247                     </td>
248                     <td colspan="4">
249                     </td>
250                 </tr>
251             </table>
252           </div>
253           <div class="panel-footer" style="border-top: 1px solid #ddd;">
254             <table class="table">
255                 <tr>
256                     <td colspan="6">
257                       <span>Minor Allele Frequency</span>
258                       <input placeholder="0.05" value="0.05" type="number" class="wizard-download-genotypes-grm-maf form-control input-sm">
259                     </td>
260                     <td colspan="3">
261                       <span>Marker Filter</span>
262                       <input placeholder="0.60" value="0.60" type="number" class="wizard-download-genotypes-grm-marker-filter form-control input-sm">
263                     </td>
264                     <td colspan="3">
265                       <span>Individuals Filter</span>
266                       <input placeholder="0.80" value="0.80" type="number" class="wizard-download-genotypes-grm-individuals-filter form-control input-sm">
267                     </td>
268                 </tr>
269               <tr>
270                 <td colspan="12">
271                   <span>Genomic Relationship Matrix (GRM) Download Format</span>
272                   <select class="wizard-download-genotypes-grm-format form-control input-sm" >
273                       <option value="matrix_uniquenames">Matrix Stock Names (.tsv)</option>
274                       <option value="three_column_uniquenames">3-Column Stock Names (.tsv)</option>
275                       <option value="three_column_reciprocal_uniquenames">3-Column Reciprocal Stock Names (.tsv)</option>
276                       <option value="heatmap">Heatmap (.pdf)</option>
277                       <option value="matrix">Matrix Stock IDs (.tsv)</option>
278                       <option value="three_column">3-Column Stock IDs(.tsv)</option>
279                       <option value="three_column_stock_id_integer">3-Column Stock IDs Integer (.tsv)</option>
280                       <option value="three_column_reciprocal">3-Column Reciprocal Stock IDs (.tsv)</option>
281                       <option value="three_column_reciprocal_stock_id_integer">3-Column Reciprocal Stock IDs Integer (.tsv)</option>
282                   </select>
283                   <br/>
284                     <span class="glyphicon glyphicon-info-sign" title="Select accessions, and optionally a genotyping protocol. If no genotyping protocol is selected, the default genotyping protocol is used in your system. Specify minor allele frequency (MAF), marker filter, and individuals filter. Can compute genotypes from parents if the parents of the accessions you selected have genotypes by checking the checkbox. GRM can be downloaded in a matrix format (.tsv) and a three column format."></span>
285                     <span>Download GRM</span><br/>
286                     <button class="wizard-download-genetic-relationship-matrix btn btn-sm btn-primary">
287                         <span class="glyphicon glyphicon-download" aria-hidden="true"></span>
288                         Download GRM
289                     </button>
290                 </td>
291               </tr>
292               <tr>
293                   <td colspan="12">
294                     <span>Genome Wide Association Study (GWAS) Download Format</span>
295                     <select class="wizard-download-genotypes-gwas-format form-control input-sm" >
296                         <option value="manhattan_qq_plots">Manhattan + QQ Plots (.pdf)</option>
297                         <option value="results_tsv">GWAS Results (.tsv)</option>
298                     </select>
299                     <br/>
300                     <span>Selected Traits Are All Repeated Measurements</span>
301                     <select class="wizard-download-genotypes-gwas-repeated-measurements form-control input-sm" >
302                         <option value="no">No</option>
303                         <option value="yes">Yes</option>
304                     </select>
305                     <br/>
306                         <span class="glyphicon glyphicon-info-sign" title="Select accessions, traits, and optionally a genotyping protocol. If no genotyping protocol is selected, the default genotyping protocol is used in your system. When many traits are selected and these traits are not treated as repeated measurements, the traits are treated separately and distinct results are returned e.g. several Manhattan plots are returned. If the selected traits are in fact repeated measurements, then select 'yes'; a single GWAS will be run against all of the phenotypes e.g. a single Manhattan plot is returned. Specify minor allele frequency (MAF), marker filter, and individuals filter. Can compute genotypes from parents if the parents of the accessions you selected have genotypes by checking the checkbox. GWAS uses a fixed effect for different field trials and a fixed effect for replicate. GWAS uses Kinship matrix calculated from the genotype data. MAF and missing data used to filter prior to GWAS and Kinship matrix calculation. Can select whether to return results in Manhattan and QQ Plot (.pdf) form or as the tabular results (.tsv)."></span>
307                         <span>Run GWAS</span><br/>
308                       <button class="wizard-download-gwas btn btn-sm btn-primary">
309                           <span class="glyphicon glyphicon-download" aria-hidden="true"></span>
310                           Download GWAS
311                       </button>
312                   </td>
313               </tr>
314             </table>
316           </div>
317         </div>
318       </div>
320       <div class="panel panel-default">
321         <div class="panel-heading" role="button" data-toggle="collapse" data-parent="#wiz-down-group" href="#wiz-down-1-c-a" aria-controls="wiz-down-1-c-a">
322           <span class="btnn btn-link">Archived Genotype Data</span>
323         </div>
324         <div id="wiz-down-1-c-a" class="panel-collapse collapse" role="tabpanel">
325           <p style="margin: 15px; text-color: #999; font-size: 90%">Download the original archived VCF files of entire genotyping projects.  Select <strong>one or more genotyping projects and/or genotyping protocols</strong> to download a VCF file of any matching project(s).</p>
326           <div id="wiz-down-1-c-a-body" style="min-height: 50px"></div>
327         </div>
328       </div>
330       <div class="panel panel-default">
331         <div class="panel-heading" role="button" data-toggle="collapse" data-parent="#wiz-down-group" href="#wiz-down-2-c" aria-controls="wiz-down-2-c">
332           <span class="btnn btn-link">Related Trial Metadata</span>
333         </div>
334         <div id="wiz-down-2-c" class="panel-collapse collapse" role="tabpanel">
335           <table class="table">
336             <tr>
337               <td>
338                 <input class="wizard-download-tmetadata-info form-control input-sm" type="text" disabled value="No Trials Selected"></input>
339               </td>
340               <td>
341                 <select class="wizard-download-tmetadata-format form-control input-sm">
342                   <option value="" disabled>Format</option>
343                   <option selected value="csv">CSV</option>
344                   <option value="xlsx">XLSX</option>
345                 </select>
346               </td>
347             </tr>
348           </table>
349           <div class="panel-footer" style="border-top: 1px solid #ddd;">
350             <button class="wizard-download-tmetadata btn btn-sm btn-primary">
351                 <span class="glyphicon glyphicon-download" aria-hidden="true"></span>
352                 Metadata
353             </button>
354           </div>
355         </div>
356       </div>
358       <div class="panel panel-default">
359         <div class="panel-heading" role="button" data-toggle="collapse" data-parent="#wiz-down-group" href="#wiz-down-3-c" aria-controls="wiz-down-3-c">
360           <span class="btnn btn-link">Related Trial Phenotypes</span>
361         </div>
362         <div id="wiz-down-3-c" class="panel-collapse collapse" role="tabpanel">
363           <table class="table">
364             <tr>
365               <td colspan="3">
366                 <input class="wizard-download-phenotypes-info form-control input-sm" type="text" disabled></input>
367               </td>
368             </tr>
369             <tr>
370             <td colspan="1">
371               <select class="wizard-download-phenotypes-speed form-control input-sm">
372                 <option value="" disabled>Download Type</option>
373                 <option selected value="Native">Default</option>
374                 <option value="MaterializedViewTable">Fast (Improves speed but may miss recent changes)</option>
375               </select>
376             </td>
377               <td colspan="1">
378                 <select class="wizard-download-phenotypes-format form-control input-sm">
379                   <option value="" disabled>Download Format</option>
380                   <option selected value="csv">CSV</option>
381                   <option value="xlsx">XLSX</option>
382                 </select>
383               </td>
384               <td colspan="1">
385                 <select class="wizard-download-phenotypes-level form-control input-sm">
386                   <option value="" disabled>Data Level</option>
387                   <option selected value="all">All</option>
388                   <option value="plot">Plots</option>
389                   <option value="plant">Plants</option>
390                 </select>
391               </td>
392             </tr>
393             <tr>
394               <td>
395                 <div class="checkbox">
396                   <label>
397                     <input class="wizard-download-phenotypes-timestamp" type="checkbox">
398                     Include timestamps
399                   </label>
400                 </div>
401               </td>
402               <td colspan="2">
403                 <div class="checkbox">
404                   <label>
405                     <input class="wizard-download-phenotypes-entry-numbers" type="checkbox">
406                     Include accession entry numbers
407                   </label>
408                 </div>
409               </td>
410             </tr>
411             <tr>
412               <td colspan="3" style="border-top: none; padding-top: 0">
413                 <div class="checkbox">
414                   <label>
415                     <input class="wizard-download-phenotypes-outliers" type="checkbox">
416                     Supress user defined phenotype outliers
417                   </label>
418                 </div>
419               </td>
420             </tr>
421             <tr>
422               <td>
423                 <span>Trait Name Contains</span>
424                 <input placeholder="e.g. plant height" type="text" class="wizard-download-phenotypes-name form-control">
425               </td>
426               <td>
427                 <span>Min Value</span>
428                 <input placeholder="-&#8734;" type="text" class="wizard-download-phenotypes-min form-control">
429               </td>
430               <td>
431                 <span>Max Value</span>
432                 <input placeholder="&#8734;" type="text" class="wizard-download-phenotypes-max form-control">
433               </td>
434             </tr>
435           </table>
436           <div class="panel-footer" style="border-top: 1px solid #ddd;">
437             <button class="wizard-download-phenotypes btn btn-sm btn-primary">
438                 <span class="glyphicon glyphicon-download" aria-hidden="true"></span>
439                 Download Phenotypes
440             </button>
441           </div>
442         </div>
443       </div>
444     </&>
445   </div>
447 </div>
449 <script>
450   window.sWizard = jsMod['wizard'].WizardSetup("#wizard");
451 </script>
453 <div class="modal fade" id="update_wizard_dialog" name="update_wizard_dialog" tabindex="-1" role="dialog" aria-labelledby="updateWizardDialog">
454   <div class="modal-dialog" role="document">
455     <div class="modal-content">
456       <div class="modal-header">
457         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
458         <h3 class="modal-title" id="updateWizardDialog">Update Search Wizard</h3>
459       </div>
460       <div class="modal-body">
461         <div class="container-fluid">
462              <h4>How the wizard works</h4>
463                      <p>For the search wizard to be fast and flexible, it avoids querying the database directly. Instead, it stores a copy of the data from the database in a temporary format that is optimized for the types of queries the wizard makes.</p><p>For this to be practical, the copy must be updated regularly. Updates usually start every time new data is uploaded, however users with submitter status or higher can also initiate them manually.</p><p>If an update isn't already in progress, you can initiate one below. It will run independently on the server without any additional input required from the user. Depending on the size of the database, it will take from a few minutes to a few hours to complete.</p>
464         <div><h4>Current status:</h4><p id="wizard_status"></p></div>
465         </div>
466       </div>
467       <div class="modal-footer">
468         <div class="well well-sm" id="update_wizard_error" style="display:none;"></div>
469         <button type="button" class="btn btn-primary wiz-update" name="update_wizard" data-loading-text="Working..." id="update_wizard">Update search wizard</button>
470         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
471       </div>
472     </div>
473   </div>
474 </div>
476 <script>
478   jQuery(document).ready(function (){
479 %  if ($dataset_id){
480       document.getElementsByClassName("wizard-dataset-select")[0].value = <% $dataset_id %>;
481       document.getElementsByClassName("wizard-dataset-load")[0].click();
482 %  }
483    $(".wizard-download-genotypes-info2").hide();
484    $(".wizard-download-genotypes-info3").hide();
485    $(".wizard-download-genotypes-info4").hide();
486   });
488   d3.select('#update_wizard_show').on('click', function () {
489     $('#update_wizard_dialog').modal("show");
490     jsMod['wizard'].updateStatus("#wizard_status")
491       .then(function(isLoading){
492         if(isLoading) {
493           d3.select("#update_wizard")
494           .attr("title","A search wizard update is already in progress...")
495           .attr("disabled",true);
496         }
497         else {
498           d3.select("#update_wizard")
499           .attr("title","Refresh the search wizard to include newly uploaded data")
500           .attr("disabled",null)
501         }
502       });
503   });
505   d3.select("#update_wizard").on('click',function(){
506     jsMod['wizard'].refreshMatviews("fullview",this);
507   });
509   d3.select("#update_wizard_lists").on('click',function(){
510     window.sWizard.reload_lists();
511   });
514   // Wizard Callback: get archived vcf files available for selected genotyping protocol / project
515   window.sWizard.wizard.on_change(function(categories, selections, operations) {
516     var protocols = (selections.genotyping_protocols || []).map((i) => i.id);
517     var projects = (selections.genotyping_projects || []).map((i) => i.id);
518     if ( protocols.length === 0 && projects.length === 0 ) {
519       updateArchivedVCFFiles({ no_geno_selected: true });
520     }
521     else {
522       updateArchivedVCFFiles({ loading: true });
523       jQuery.ajax({
524         url: '/ajax/genotyping_project/has_archived_vcf',
525         method: 'GET',
526         data: {
527           genotyping_protocol_id: !projects || projects.length === 0 ? (protocols.length > 0 ? protocols.join(',') : undefined) : undefined,
528           genotyping_project_id: projects.length > 0 ? projects.join(',') : undefined,
529           limit: true
530         },
531         error: function(response) {
532           console.log(`ERROR: Could not query database for archived vcf files [protocols: ${protocols.join(',')}, projects: ${projects.join(',')}]`);
533           console.log(response);
534           updateArchivedVCFFiles({ error: true });
535         },
536         success: function(response) {
537           updateArchivedVCFFiles({ data: response });
538         }
539       });
540     }
541   });
542   updateArchivedVCFFiles({ no_geno_selected: true });
543   
544   // Set the display of the Archived Genotype Data section
545   function updateArchivedVCFFiles({ no_geno_selected = false, loading = false, error = false, data = {} } = {}) {
546     let html = '';
547     if ( no_geno_selected ) {
548       html += "<p style='text-align: center; margin: 15px; font-size: 90%'>Select one or more <em>genotyping protocols</em> and/or <em>genotyping projects</em>...</p>";
549     }
550     else if ( loading ) {
551       html += "<p style='text-align: center; margin: 15px'>Loading...</p>";
552     }
553     else if ( error ) {
554       html += "<p style='text-align: center; margin: 15px'>Error: Could not check for archived files</p>";
555     }
556     else if ( data ) {
557       html += "<table class='table table-hover table-striped'>";
558       html += "<thead><tr><th>Protocol</th><th>Project</th><th>VCF File</th></tr></thead>";
559       html += "<tbody>";
560       Object.keys(data).forEach((proj_id) => {
561         const files = data[proj_id];
562         files.forEach((file) => {
563           html += "<tr>";
564           html += `<td><a href="/breeders_toolbox/protocol/${file.genotyping_protocol_id}" target="_blank">${file.genotyping_protocol_name}</td>`;
565           html += `<td><a href="/breeders/trial/${file.genotyping_project_id}" target="_blank">${file.genotyping_project_name}</td>`;
566           if ( file.exists === 'true' ) {
567             html += `<td><a href="/ajax/genotyping_project/download_archived_vcf?genotyping_project_id=${file.genotyping_project_id}&basename=${file.basename}" target="_blank">Download</a></td>`;
568           }
569           else {
570             html += "<td>File not found</td>";
571           }
572           html += "</tr>";
573         });
574       });
575       html += "</tbody>";
576       html += "</table>";
577     }
579     jQuery('#wiz-down-1-c-a-body').html(html);
580   }
582   // Wizard Callback: get chromosome names for a single selected genotyping protocol
583   var SELECTED_GENOTYPING_PROTOCOL = undefined;
584   var SELECTED_GENOTYPING_PROJECT = undefined;
585   var SELECTED_ACCESSIONS = undefined;
586   var num_markers = 0;
587   var download_units = 0;
588   window.sWizard.wizard.on_change(function(categories, selections, operations) {
589     var selected_genotyping_protocols = selections.hasOwnProperty('genotyping_protocols') ? selections.genotyping_protocols : [];
590     var selected_genotyping_projects = selections.hasOwnProperty('genotyping_projects') ? selections.genotyping_projects : [];
591     var selected_accessions = selections.hasOwnProperty('accessions') ? selections.accessions : [];
592     selected_accessions = selected_accessions.length;
593     if ( selected_genotyping_protocols.length >= 1 ) {
594       $(".wizard-download-genotypes-info3").hide();
595       var selected_genotyping_protocol = selected_genotyping_protocols.length === 1 ? selected_genotyping_protocols[0].id : "";
596       if ( selected_genotyping_protocol != SELECTED_GENOTYPING_PROTOCOL ) {
597         SELECTED_GENOTYPING_PROTOCOL = selected_genotyping_protocol;
598         jQuery.ajax({
599           url: '/ajax/breeder/search/genotyping_protocol_chromosomes',
600           method: "GET",
601           data: { 'genotyping_protocol': SELECTED_GENOTYPING_PROTOCOL },
602           error: function(response) {
603             console.log("ERROR: Could not get chromosome names for genotyping protocol #" + SELECTED_GENOTYPING_PROTOCOL);
604             console.log(response);
605             updateChromosomeNames();
606           },
607           success: function(response) {
608             if (response.error) {
609               console.log("ERROR: Server returned an error trying to get the chromosome names for genotyping protocol #" + SELECTED_GENOTYPING_PROTOCOL);
610               console.log(repsonse.error);
611               updateChromosomeNames();
612             } else {
613               updateChromosomeNames(response.chromosome_names);
614             }
615           }
616         });
617         jQuery.ajax({
618           url: '/ajax/genotyping_protocol/num_markers',
619           method: "GET",
620           data: { 'protocol_ids': SELECTED_GENOTYPING_PROTOCOL },
621           error: function(response) {
622             console.log("ERROR: Could not get markers for genotyping protocol #" + SELECTED_GENOTYPING_PROTOCOL);
623             console.log(response);
624           },
625           success: function(response) {
626             if (response.error) {
627               console.log("ERROR: Server returned an error trying to get markers for genotyping protocol #" + SELECTED_GENOTYPING_PROTOCOL);
628               console.log(repsonse.error);
629             } else {
630               num_markers = response.data;
631             }
632           }
633         });
634       }
635       if ( selected_genotyping_protocols.length > 1 ) {
636         $(".wizard-download-genotypes-info2").show();
637         $(".wizard-download-genotypes-info2").val("too many genotype protocols");
638       } else {
639         $(".wizard-download-genotypes-info2").hide();
640       }
641     } else if ( selected_genotyping_projects.length >= 1 ) {
642       var selected_genotyping_project = selected_genotyping_projects[0].id;
643       if ( selected_genotyping_project !== SELECTED_GENOTYPING_PROJECT ) {
644         console.log("project new " + selected_genotyping_project);
645         SELECTED_GENOTYPING_PROJECT = selected_genotyping_project;
646         jQuery.ajax({
647           url: '/ajax/genotyping_project/protocols',
648           method: "GET",
649           data: { 'genotyping_project_id': SELECTED_GENOTYPING_PROJECT },
650           error: function(response) {
651             console.log("ERROR: Could not get protocol for genotyping project #" + SELECTED_GENOTYPING_PROJECT);
652             console.log(response);
653           },
654           success: function(response) {
655             if (response.error) {
656               console.log("ERROR: Server returned an error trying to get protocol for genotyping project #" + SELECTED_GENOTYPING_PROJECT);
657               console.log(response.error);
658             }
659             else {
660               genotyping_protocol = response.data;
661               SELECTED_GENOTYPING_PROTOCOL = genotyping_protocol[0]["protocol_id"];
662               // console.log(genotyping_protocol[0]["protocol_id"]);
663               // console.log(genotyping_protocol[0]["protocol_name"]);
664               console.log("genotype protocol from project = " + SELECTED_GENOTYPING_PROTOCOL);
665               if ( selected_genotyping_protocols.length < 1 ) {
666                 $(".wizard-download-genotypes-info3").show();
667                 $(".wizard-download-genotypes-info3").val("genotype protocol \"" + genotyping_protocol[0]["protocol_name"] + "\""); 
668               }
669             }
670             jQuery.ajax({
671               url: '/ajax/breeder/search/genotyping_protocol_chromosomes',
672               method: "GET",
673               data: { 'genotyping_protocol': SELECTED_GENOTYPING_PROTOCOL },
674               error: function(response) {
675                 console.log("ERROR: Could not get chromosome names for genotyping protocol #" + SELECTED_GENOTYPING_PROTOCOL);
676                 console.log(response);
677                 updateChromosomeNames();
678               },
679               success: function(response) {
680                 if (response.error) {
681                   console.log("ERROR: Server returned an error trying to get the chromosome names for genotyping protocol #" + SELECTED_GENOTYPING_PROTOCOL);
682                   console.log(repsonse.error);
683                   updateChromosomeNames();
684                 } else {
685                   updateChromosomeNames(response.chromosome_names);
686                 }
687               }
688             });
689             // console.log("calling ajax " + SELECTED_GENOTYPING_PROTOCOL);
690             jQuery.ajax({
691               url: '/ajax/genotyping_protocol/num_markers',
692               method: "GET",
693               data: { 'protocol_ids': SELECTED_GENOTYPING_PROTOCOL },
694               error: function(response) {
695                 console.log("ERROR: Could not get markers for genotyping protocol #" + SELECTED_GENOTYPING_PROTOCOL);
696                 console.log(response);
697               },
698               success: function(response) {
699                 if (response.error) {
700                   console.log("ERROR: Server returned an error trying to get markers for genotyping protocol #" + SELECTED_GENOTYPING_PROTOCOL);
701                   console.log(repsonse.error);
702                 } else {
703                   num_markers = response.data;
704                 }
705              }
706             });
707           }
708         });
709       }
710     } else {
711       var protocol_name = '<% $c->config->{default_genotyping_protocol} %>';
712       $(".wizard-download-genotypes-info3").show();
713       $(".wizard-download-genotypes-info3").val("genotype protocol \"" + protocol_name + "\""); 
714       jQuery.ajax({
715           url: '/get/genotyping/protocols/',
716           method: "POST",
717           dataType: "json",
718           error: function(response) {
719             console.log("ERROR: Could not get genotyping protocol");
720             console.log(response);
721           },
722           success: function(response) {
723            if (response.error) {
724               console.log("ERROR: Server returned an error trying to get genotyping protocol #" + SELECTED_GENOTYPING_PROTOCOL);
725               console.log(repsonse.error);
726             } else {
727               SELECTED_GENOTYPING_PROTOCOL = response.default_protocol.protocol_id;
728               console.log(response.default_protocol.protocol_id);
729               jQuery.ajax({
730                 url: '/ajax/genotyping_protocol/num_markers',
731                 method: "GET",
732                 data: { 'protocol_ids': SELECTED_GENOTYPING_PROTOCOL },
733                 error: function(response) {
734                   console.log("ERROR: Could not get markers for genotyping protocol #" + SELECTED_GENOTYPING_PROTOCOL);
735                   console.log(response);
736                 },
737                 success: function(response) {
738                   if (response.error) {
739                     console.log("ERROR: Server returned an error trying to get markers for genotyping protocol #" + SELECTED_GENOTYPING_PROTOCOL);
740                     console.log(repsonse.error);
741                   } else {
742                     num_markers = response.data;
743                   }
744                }
745               });
746             }
747           }
748       });
749     }
750     if ( selected_accessions !== SELECTED_ACCESSIONS ) {
751       SELECTED_ACCESSIONS = selected_accessions;
752       download_units = parseInt((num_markers * selected_accessions) / 1000000);
753       if (download_units > 1) {
754             $(".wizard-download-genotypes-info4").show();
755             $(".wizard-download-genotypes-info4").val(download_units + "M values, download will be slow");
756             // console.log("download units " + download_units);
757       } else {
758             $(".wizard-download-genotypes-info4").hide();
759             $(".wizard-download-genotypes-info4").val(download_units.toString());
760       }
761     }
762   });
763   // updateChromosomeNames();
765   // Set the chromosome names for the select dropdown menu
766   function updateChromosomeNames(names) {
767     var html = "";
768     if ( names )  {
769       html += "<option value=''>All</option>";
770       for ( var i = 0; i < names.length; i++ ) {
771         html += "<option value='" + names[i] + "'>" + names[i] + "</option>";
772       }
773     }
774     $(".wizard-download-genotypes-chromosome-number").html(html);
775   }
777 </script>