16 <& '/util/import_javascript.mas', classes => ['jquery', 'jqueryui', 'CXGN.Login', 'd3.d3v4Min.js', 'CXGN.BreedersToolbox.HTMLSelect'] &>
18 <script src="https://cdn.jsdelivr.net/npm/vega@4"></script>
19 <script src="https://cdn.jsdelivr.net/npm/vega-lite@2"></script>
20 <script src="https://cdn.jsdelivr.net/npm/vega-embed@4"></script>
22 <& /page/page_title.mas, title=>"Heritability" &>
25 <&| /page/info_section.mas, id=>"input_dataset_section", title=>"Select Input Data", collapsible=>1, collapsed=>0, subtitle=>'<a class="btn btn-link pull-right" href="/help/heritability" target="_blank">Help <span class="glyphicon glyphicon-question-sign"></span></a>' &>
26 <input type="hidden" name="outformat" value="0" />
29 <div class="form-group form-inline">
30 <label for="dataset_select">Available Datasets: </label><div id="dataset_select"></div>
33 <button class="btn btn-primary" id="selectDataset" type="submit" name="selectDataset" value="selectDataset">Select Dataset</button>
40 <div class="form-group form-inline">
41 <label class="blast_select_label" for="pheno_select">Available Traits: </label>
42 <& /page/html_select.mas, name=>'pheno_select', id=>'pheno_select', params=>"class\=\"form-control input-sm blast_select_box\"", choices=>"" &>
43 <button class="btn btn-primary" id="preview_trait_histogram_btn" type="submit" name="preview_trait_histogram_btn" value="preview_trait_histogram_btn">View Trait Histogram</button>
44 <img id="loading-spinner" src="/img/wheel.gif" alt="loading" style="visibility: hidden;">
46 <input type="checkbox" id="dataset_trait_outliers" />
47 <label>Exclude dataset outliers </label>
52 <div id="trait_histogram_plot">
60 <!-- <label class="blast_select_label" for="geno_select">Genotypes </label>
61 <& /page/html_select.mas, name=>'geno_select', id=>'geno_select', params=>"class\=\"form-control input-sm blast_select_box\"", choices=>"" &> -->
66 <div style="text-align: center">
67 <button class="btn btn-primary" id="runH2" type="submit" name="runH2" value="runH2">Run Heritability</button>
71 <div id="tempfile" style="display:none" >
82 <&| /page/info_section.mas, title=>"Instructions", collapsible=>1, collapsed=>1, subtitle=>'<a id="download_table" class="download_tag" target="_blank" href="javascript:download_table();" title="Download results in tabular format">Table⇣</a> <a id="download_basic" class="download_tag" target="_blank" href="javascript:download();" title="Download results in basic format">Basic⇣</a>' &>
87 <div id="sgn_blast_graph" style="display:none">
89 Your browser does not support the HTML5 canvas
94 <h5><b>Dataset:</b></h5>
95 <h5>1. The dataset must contain trails and numerical traits. Inclusion of accession, plots, locations, and years is optional.</h5>
96 <h5>2. The model will adapt to your dataset. For instance, if the dataset has more than one location, then the model will take the interaction among locations and accessions.</h5>
97 <h5>3. Traits with more than 60% of missing data are removed from the analysis.</h5>
98 <h5>4. Outliers can be removed by accessing the <a href="/search/datasets" target="_blank"> Datasets tab </a>. </h5>
99 <h5>5. Selecting the 'Exclude dataset outliers', heritability is calculated using filtered data.</h5>
105 <&| /page/info_section.mas, title=>"Output", collapsible=>1, collapsed=>0, subtitle=>'<a id="download_table" class="download_tag" target="_blank" href="javascript:download_table();" title="Download results in tabular format">Table⇣</a> <a id="download_basic" class="download_tag" target="_blank" href="javascript:download();" title="Download results in basic format">Basic⇣</a>' &>
110 <div id="sgn_blast_graph" style="display:none">
112 Your browser does not support the HTML5 canvas
118 <div id="heritability_output"></div>
120 <button class="btn btn-primary" id="download-button">Download CSV</button>
122 <div id="Overview_output"></div>
123 <div id="Coverage_output"></div>
124 <div id="Table_output" style="min-width:900px;"></div>
125 <div id="Bioperl_output"></div>
126 <div id="Basic_output"></div>
133 jQuery(document).ready(function() {
135 get_select_box("datasets", "dataset_select", {"checkbox_name":"dataset_select_checkbox"});
138 alert('You must be logged in to use Heritability');
140 $('#pheno_select').attr("disabled",true).html('');
141 jQuery('#dataset_select').click(function() {
142 $('#pheno_select').attr("disabled",true).html('');
143 $('#trait_histogram_plot').html('');
144 $('#heritability_output').empty();
147 jQuery('#selectDataset').click(function() {
148 var dataset_id = get_dataset_id();
152 var dataset_trait_outliers = $('#dataset_trait_outliers').is(':checked') ? 1 : 0;
153 document.getElementById("preview_trait_histogram_btn").disabled = true;
154 document.getElementById("loading-spinner").style.visibility = 'visible';
156 url: '/ajax/heritability/shared_phenotypes',
158 'dataset_id': dataset_id,
159 'dataset_trait_outliers': dataset_trait_outliers,
161 success: function(response) {
162 if (response.error) {
163 $('#dataset_select').val('ERROR');
164 document.getElementById("loading-spinner").style.visibility = 'hidden';
167 var option_html = '<option selected="selected" value=""> </option>';
168 for (var i = 0; i < response.options.length; i++) {
169 option_html += '<option value="'+response.options[i][1]+'">'+(response.options[i][1])+'</option>';
171 $('#pheno_select').attr("disabled",false).html(option_html);
172 jQuery('#tempfile').html(response.tempfile);
173 document.getElementById("preview_trait_histogram_btn").disabled = false;
174 document.getElementById("loading-spinner").style.visibility = 'hidden';
178 error: function(response) {
179 alert("An error occurred, the service may temporarily be unavailable, ponto 1 selectDataset ");
180 document.getElementById("preview_trait_histogram_btn").disabled = false;
181 document.getElementById("loading-spinner").style.visibility = 'hidden';
186 jQuery('#preview_trait_histogram_btn').on('click', function() {
187 if (!jQuery('#pheno_select').val()) {
188 alert("Please select a dataset and trait.")
190 //alert("Inside trait preview");
191 var tempfile = jQuery('#tempfile').html();
192 var trait = jQuery('#pheno_select').val();
195 url: '/ajax/heritability/getdata',
196 data: { 'file' : tempfile },
197 success: function(r) {
198 //alert("data grabbed "+JSON.stringify(r.data));
200 "$schema": "https://vega.github.io/schema/vega-lite/v2.json",
204 "data": { 'values': r.data },
210 "type": "quantitative"
213 "aggregate": "count",
214 "type": "quantitative"
218 vegaEmbed("#trait_histogram_plot", v);
220 error: function(e) { alert('error!'); }
225 jQuery('#dataset_trait_outliers').on('click', function() {
226 var dataset_id = get_dataset_id();
230 var dataset_trait_outliers = $('#dataset_trait_outliers').is(':checked') ? 1 : 0;
231 document.getElementById("preview_trait_histogram_btn").disabled = true;
232 document.getElementById("loading-spinner").style.visibility = 'visible';
234 url: '/ajax/heritability/shared_phenotypes',
236 'dataset_id': dataset_id,
237 'dataset_trait_outliers': dataset_trait_outliers,
239 success: function(response) {
240 if (response.error) {
241 $('#dataset_select').val('ERROR');
242 alert("An error occurred, the is some problem with data");
243 document.getElementById("loading-spinner").style.visibility = 'hidden';
246 jQuery('#tempfile').html(response.tempfile);
247 document.getElementById("preview_trait_histogram_btn").disabled = false;
248 document.getElementById("loading-spinner").style.visibility = 'hidden';
251 error: function(response) {
252 alert("An error occurred, the service may temporarily be unavailable");
253 document.getElementById("preview_trait_histogram_btn").disabled = false;
254 document.getElementById("loading-spinner").style.visibility = 'hidden';
261 jQuery('#runH2').click( function () {
262 if (!jQuery('#pheno_select').val()) {
263 alert("Please select a dataset and trait.");
264 $('#heritability_output').empty();
266 $('#heritability_output').empty();
268 if ($('#pheno_select').val() != ""){
269 var dataset_id = get_dataset_id();
270 console.log("dataset_id", dataset_id);
271 var trait_id = $('#pheno_select').val();
273 console.log("trait_id", trait_id);
274 var dataset_trait_outliers = $('#dataset_trait_outliers').is(':checked') ? 1 : 0;
277 url: '/ajax/heritability/generate_results',
279 'dataset_id': dataset_id,
280 'trait_id': trait_id,
281 'dataset_trait_outliers': dataset_trait_outliers,
283 beforeSend: function() {
284 jQuery("#working_modal").modal("show");
288 success: function(response) {
289 jQuery("#working_modal").modal("hide");
291 if (response.error) {
292 alert(response.error);
295 $.getJSON(response.h2Table, function(data){
296 var parsedData = JSON.parse(data);
303 var table = '<table>';
304 table += '<thead><tr><th>Trait</th><th>Vg</th><th>Ve</th><th>Vres</th><th>Heritability</th></tr></thead>';
307 for (var i = 0; i < parsedData.length; i++) {
308 traitValue = parsedData[i].trait;
309 varG = parsedData[i].Vg;
310 varE = parsedData[i].Ve;
311 varRes = parsedData[i].Vres;
312 herit = parsedData[i].Hert;
314 // Create a row for each data point
316 table += '<td>' + traitValue + '</td>';
317 table += '<td>' + varG + '</td>';
318 table += '<td>' + varE + '</td>';
319 table += '<td>' + varRes + '</td>';
320 table += '<td>' + herit + '</td>';
323 $('#heritability_output').append(table);
325 $('#download-button').click(function() {
326 var csvContent = "data:text/csv;charset=utf-8,";
328 // Add table headers to CSV content
329 csvContent += "Trait,Vg,Ve,Vres,Heritability\n";
331 // Add table data to CSV content
332 for (var i = 0; i < parsedData.length; i++) {
333 var row = parsedData[i];
334 csvContent += row.trait + "," + row.Vg + "," + row.Ve + "," + row.Vres + "," + row.Hert + "\n";
337 // Create a data URI for the CSV content
338 var encodedUri = encodeURI(csvContent);
340 // Create a download link
341 var link = document.createElement("a");
342 link.setAttribute("href", encodedUri);
343 link.setAttribute("download", "heritability_data.csv");
344 link.innerHTML = "Download CSV";
346 // Trigger the click event to download the file
351 console.log("An error has occurred.");
354 error: function(xhr, status, error) {
355 var err = eval("(" + xhr.responseText + ")");
363 function get_dataset_id() {
364 var selected_datasets = [];
365 jQuery('input[name="dataset_select_checkbox"]:checked').each(function() {
366 selected_datasets.push(jQuery(this).val());
368 if (selected_datasets.length < 1){
369 alert('Please select at least one dataset!');
371 } else if (selected_datasets.length > 1){
372 alert('Please select only one dataset!');
375 var dataset_id=selected_datasets[0];
404 .blast_select_label {
416 vertical-align:middle;
427 background-color:#EEEEFE;
446 /* BLAST canvas Graph */
458 border-collapse: collapse;
463 border: 1px solid black;
472 background-color: #f2f2f2;