4 <& /util/import_javascript.mas, classes => [ 'brapi.Table' ] &>
6 <& /page/page_title.mas, title=>"Phenotype Retrieval" &>
8 <h4>Database Select</h4>
9 <select name="brapi_home_phenotypes_url_select" id="brapi_home_phenotypes_url_select" class="form-control" />
10 <option value="">local</option>
11 <option value="https://cassbase.org">cassbase.org</option>
12 <option value="https://cassavabase.org">cassavabase.org</option>
13 <option value="https://musabase.org">musabase.org</option>
14 <option value="https://sweetpotatobase.org">sweetpotatobase.org</option>
15 <option value="https://yambase.org">yambase.org</option>
16 <option value="https://fernbase.org">fernbase.org</option>
17 <option value="https://solgenomics.net">solgenomics.net</option>
18 <option value="https://www.crop-diversity.org/mgis">crop-diversity.org</option>
21 <h4>Phenotype Search</h4>
23 <div id="brapi_home_phenotype_search_div" class="well">
25 <input name="brapi_home_phenosearch_germplasmDbIds" id="brapi_home_phenosearch_germplasmDbIds" class="form-control" type="text" placeholder="GermplasmDbIds e.g. 139" />
26 <input name="brapi_home_phenosearch_studyDbIds" id="brapi_home_phenosearch_studyDbIds" class="form-control" type="text" placeholder="StudyDbIds e.g. 139,137" />
27 <input name="brapi_home_phenosearch_observationVariableDbIds" id="brapi_home_phenoseach_observationVariableDbIds" class="form-control" type="text" placeholder="ObservationDbIds e.g. 70741,70666,70773" />
28 <input name="brapi_home_phenosearch_locationDbIds" id="brapi_home_phenosearch_locationDbIds" class="form-control" type="text" placeholder="LocationDbIds e.g. 23" value="23"/>
29 <input name="brapi_home_phenosearch_years" id="brapi_home_phenosearch_years" class="form-control" type="text" placeholder="Years e.g. 2014,2015" />
30 <select name="brapi_home_phenosearch_observations_level" id="brapi_home_phenosearch_observations_level" class="form-control" />
31 <option value="all">All</option>
32 <option value="plot">Plot</option>
33 <option value="plant">Plant</option>
36 <button class="btn btn-primary" name="brapi_home_phenosearch_submit" id="brapi_home_phenosearch_submit">Search Phenotypes</button>
38 <div id="brapi_phenosearch_data_result_div">
44 <h4>Phenotypes For a Study in Table Format</h4>
46 <div id="brapi_home_phenotype_study_table_div" class="well">
48 <select name="brapi_phenotype_studies_table_format" id="brapi_phenotype_studies_table_format" class="form-control" />
49 <option value="csv">CSV</option>
50 <option value="tsv">TSV</option>
51 <option value="xls">Excel (xls)</option>
52 <option value="json">JSON</option>
55 <div id="brapi_home_phenotype_study_table_studies_div">
58 <div id="brapi_pheno_studies_table_data_result_div">
64 <h4>Phenotypes For a Study in ObservationUnits Format</h4>
66 <div id="brapi_home_phenotype_study_observation_units_div" class="well">
68 <div id="brapi_home_phenotype_study_observation_units_studies_div">
71 <div id="brapi_pheno_studies_observation_units_data_result_div">
77 <h4>Phenotypes For a Study in Granular Format</h4>
79 <div id="brapi_home_phenotype_study_granular_div" class="well">
81 <div id="brapi_home_phenotype_study_granular_studies_div">
84 <div id="brapi_pheno_studies_granular_data_result_div">
91 var selected_results = [];
92 var studies_return_url;
94 jQuery(document).ready(function() {
96 brapi_phenotypes_get_studies(jQuery('#brapi_home_phenotypes_url_select').val(), 'brapi_home_phenotype_study_table_studies_div');
97 brapi_phenotypes_get_studies(jQuery('#brapi_home_phenotypes_url_select').val(), 'brapi_home_phenotype_study_observation_units_studies_div');
98 brapi_phenotypes_get_studies(jQuery('#brapi_home_phenotypes_url_select').val(), 'brapi_home_phenotype_study_granular_studies_div');
100 jQuery('#brapi_home_phenotypes_url_select').change(function(){
101 brapi_phenotypes_get_studies(jQuery('#brapi_home_phenotypes_url_select').val(), 'brapi_home_phenotype_study_table_studies_div');
102 brapi_phenotypes_get_studies(jQuery('#brapi_home_phenotypes_url_select').val(), 'brapi_home_phenotype_study_observation_units_studies_div');
103 brapi_phenotypes_get_studies(jQuery('#brapi_home_phenotypes_url_select').val(), 'brapi_home_phenotype_study_granular_studies_div');
106 jQuery("#brapi_home_phenosearch_submit").click(function() {
108 var observationVariableDbIds = jQuery('#brapi_home_phenosearch_observationVariableDbIds').val();
109 if (observationVariableDbIds){
110 observationVariableDbIds = observationVariableDbIds.split(',');
112 observationVariableDbIds = [];
114 var germplasmDbIds = jQuery('#brapi_home_phenosearch_germplasmDbIds').val();
116 germplasmDbIds = germplasmDbIds.split(',');
120 var studyDbIds = jQuery('#brapi_home_phenosearch_studyDbIds').val();
122 studyDbIds = studyDbIds.split(',');
126 var locationDbIds = jQuery('#brapi_home_phenosearch_locationDbIds').val();
128 locationDbIds = locationDbIds.split(',');
132 var seasonDbIds = jQuery('#brapi_home_phenosearch_years').val();
134 seasonDbIds = seasonDbIds.split(',');
139 var return_url = jQuery('#brapi_home_phenotypes_url_select').val()+'/brapi/v1/phenotypes-search';
143 'observationVariableDbIds':observationVariableDbIds,
144 'germplasmDbIds':germplasmDbIds,
145 'observationLevel':jQuery('#brapi_home_phenosearch_observations_level').val(),
146 'studyDbIds':studyDbIds,
147 'locationDbIds':locationDbIds,
148 'seasonDbIds':seasonDbIds
151 'beforeSend': function() {
152 jQuery('#working_modal').modal('show');
154 'success': function(response) {
155 jQuery('#working_modal').modal('hide');
156 console.log(response);
157 brapi_create_paginated_table(response.result.data, response.metadata.pagination, 'brapi_phenosearch_data_result_div', return_url, undefined, {}, ['observationUnitName','replicate','germplasmName','blockNumber', 'X', 'Y', 'entryType', 'studyName','studyLocation','observationLevel','observations'], 'observationUnitName', []);
160 error: function(response) {
161 jQuery('#working_modal').modal('hide');
162 alert('An error occurred');
167 jQuery(document).on('click', '#brapi_table_select_submit_brapi_home_phenotype_study_table_studies_div', function(){
168 jQuery.each(jQuery('input[name="brapi_table_select_'+studies_return_url+'"]:checked'), function(){
169 if (jQuery.inArray(jQuery(this).val(), selected_results) == -1){
170 selected_results.push(jQuery(this).val());
173 console.log(selected_results);
175 var format = jQuery('#brapi_phenotype_studies_table_format').val();
176 var return_url = jQuery('#brapi_home_phenotypes_url_select').val()+'/brapi/v1/studies/'+selected_results[0]+'/table?format='+format;
179 'beforeSend': function(){
180 jQuery('#working_modal').modal('show');
182 'success': function(response) {
183 //console.log(response);
184 if (response.metadata.datafiles.length > 0){
185 var html = "<h4>Download Study Phenotype File(s) From Here: <br/>";
186 for (var j=0; j<response.metadata.datafiles.length; j++){
187 html = html + "<a href='"+response.metadata.datafiles[j]+"'>"+response.metadata.datafiles[j]+"</a><br/>";
189 jQuery('#brapi_pheno_studies_table_data_result_div').html(html);
191 brapi_create_paginated_table(response.result.data, response.metadata.pagination, 'brapi_pheno_studies_table_data_result_div', return_url, undefined, {}, ['headerRow','observationVariableDbIds','observationVariableNames','data'], 'observationVariableNames', []);
193 jQuery('#working_modal').modal('hide');
195 error: function(response) {
196 jQuery('#working_modal').modal('hide');
197 alert('An error occurred');
203 jQuery(document).on('click', '#brapi_table_select_submit_brapi_home_phenotype_study_observation_units_studies_div', function(){
204 jQuery.each(jQuery('input[name="brapi_table_select_'+studies_return_url+'"]:checked'), function(){
205 if (jQuery.inArray(jQuery(this).val(), selected_results) == -1){
206 selected_results.push(jQuery(this).val());
209 console.log(selected_results);
211 var return_url = jQuery('#brapi_home_phenotypes_url_select').val()+'/brapi/v1/studies/'+selected_results[0]+'/observationunits';
214 'beforeSend': function(){
215 jQuery('#working_modal').modal('show');
217 'success': function(response) {
218 //console.log(response);
219 if (response.metadata.datafiles.length > 0){
220 var html = "<h4>Download Study Phenotype File(s) From Here: <br/>";
221 for (var j=0; j<response.metadata.datafiles.length; j++){
222 html = html + "<a href='"+response.metadata.datafiles[j]+"'>"+response.metadata.datafiles[j]+"</a><br/>";
224 jQuery('#brapi_pheno_studies_observation_units_data_result_div').html(html);
226 brapi_create_paginated_table(response.result.data, response.metadata.pagination, 'brapi_pheno_studies_observation_units_data_result_div', return_url, undefined, {}, ['observationUnitName','replicate','germplasmName','blockNumber', 'X', 'Y', 'entryType', 'plotNumber','observations'], 'observationUnitName', []);
228 jQuery('#working_modal').modal('hide');
230 error: function(response) {
231 jQuery('#working_modal').modal('hide');
232 alert('An error occurred');
238 jQuery(document).on('click', '#brapi_table_select_submit_brapi_home_phenotype_study_granular_studies_div', function(){
239 jQuery.each(jQuery('input[name="brapi_table_select_'+studies_return_url+'"]:checked'), function(){
240 if (jQuery.inArray(jQuery(this).val(), selected_results) == -1){
241 selected_results.push(jQuery(this).val());
244 console.log(selected_results);
246 var return_url = jQuery('#brapi_home_phenotypes_url_select').val()+'/brapi/v1/studies/'+selected_results[0]+'/observations';
249 'beforeSend': function(){
250 jQuery('#working_modal').modal('show');
252 'success': function(response) {
253 //console.log(response);
254 if (response.metadata.datafiles.length > 0){
255 var html = "<h4>Download Study Phenotype File(s) From Here: <br/>";
256 for (var j=0; j<response.metadata.datafiles.length; j++){
257 html = html + "<a href='"+response.metadata.datafiles[j]+"'>"+response.metadata.datafiles[j]+"</a><br/>";
259 jQuery('#brapi_pheno_studies_granular_data_result_div').html(html);
261 brapi_create_paginated_table(response.result.data, response.metadata.pagination, 'brapi_pheno_studies_granular_data_result_div', return_url, undefined, {}, ['observationUnitName','observationLevel','observationDbId','observationVariableName','germplasmName','observationTimestamp', 'operator', 'value'], 'observationDbId', []);
263 jQuery('#working_modal').modal('hide');
265 error: function(response) {
266 jQuery('#working_modal').modal('hide');
267 alert('An error occurred');
276 function brapi_phenotypes_get_studies(url, div_id) {
277 studies_return_url = url+'/brapi/v1/studies-search';
279 'url': url+'/brapi/v1/studies-search',
280 'beforeSend': function(){
281 jQuery('#working_modal').modal('show');
283 'success': function(response) {
284 //console.log(response);
285 brapi_create_paginated_table(response.result.data, response.metadata.pagination, div_id, studies_return_url, undefined, {}, ['studyName','trialName','programName','locationName'], 'studyDbId', []);
286 jQuery('#working_modal').modal('hide');
288 error: function(response) {
289 jQuery('#working_modal').modal('hide');
290 alert('An error occurred');