tripal_analysis_blast.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. if (Drupal.jsEnabled) {
  2. $(document).ready(function(){
  3. // If Anlaysis admin page is shown, get the settings for selected database
  4. if ($("#edit-blastdb")[0]) {
  5. tripal_update_regex($("#edit-blastdb")[0]);
  6. tripal_set_genbank_style();
  7. }
  8. // hide the alignment information on the blast results box
  9. $(".tripal_analysis_blast-info-hsp-desc").hide();
  10. });
  11. //------------------------------------------------------------
  12. // Update the blast results based on the user selection
  13. function tripal_update_blast(link,db_id){
  14. tripal_startAjax();
  15. $.ajax({
  16. url: link.href,
  17. dataType: 'json',
  18. type: 'POST',
  19. success: function(data){
  20. $("#blast_db_" + db_id).html(data.update);
  21. $(".tripal_analysis_blast-info-hsp-desc").hide();
  22. tripal_stopAjax();
  23. }
  24. });
  25. return false;
  26. }
  27. //------------------------------------------------------------
  28. // Update the blast results based on the user selection
  29. function tripal_blast_toggle_alignment(analysis_id,hit_id){
  30. var alignment_box = $("#tripal_analysis_blast-info-hsp-desc-"+analysis_id+"-"+hit_id);
  31. var toggle_img = $("#tripal_analysis_blast-info-toggle-image-"+analysis_id+"-"+hit_id);
  32. var icon_url = toggle_img.attr("src");
  33. if (alignment_box.is(':visible')) {
  34. alignment_box.fadeOut('fast');
  35. var changed_icon_url = icon_url.replace(/arrow_d.png/,"arrow_r.png");
  36. toggle_img.attr("src", changed_icon_url);
  37. } else {
  38. var width = alignment_box.parent().width();
  39. alignment_box.css("width", width+'px');
  40. alignment_box.fadeIn('slow');
  41. var icon_url = icon_url.replace(/arrow_r.png/,"arrow_d.png");
  42. toggle_img.attr("src", icon_url);
  43. }
  44. return false;
  45. }
  46. //------------------------------------------------------------
  47. // Update regular expression for selected database
  48. function tripal_update_regex(options){
  49. // Get the dbname from DOM
  50. var index = options.selectedIndex;
  51. var dbid = options[index].value;
  52. // Form the link for the following ajax call
  53. var baseurl = tripal_get_base_url();
  54. var link = baseurl + '/tripal_blast_regex/' + dbid;
  55. // Make ajax call to retrieve regular expressions
  56. $.ajax( {
  57. url : link,
  58. dataType : 'json',
  59. type : 'POST',
  60. success : tripal_set_parser,
  61. });
  62. }
  63. // Set parser for the admin page
  64. function tripal_set_parser(data) {
  65. // Set title if it exists
  66. if (data.name) {
  67. $("#edit-displayname").val(data.name);
  68. } else {
  69. $("#edit-displayname").val("");
  70. }
  71. // If genbank_style is TRUE, check the Genbank style box, clear all regular expressions, and disable
  72. // the text fields
  73. if (data.genbank_style == 1) {
  74. $("#edit-gb-style-parser").attr("checked", true);
  75. $("#edit-hit-id").val("");
  76. $("#edit-hit-def").val("");
  77. $("#edit-hit-accession").val("");
  78. // Otherwise, uncheck the Genbank style box and set the regular expressions
  79. } else {
  80. $("#edit-gb-style-parser").attr("checked", false);
  81. if (data.reg1) {
  82. $("#edit-hit-id").val(data.reg1);
  83. // Show default hit-id parser if it's not set
  84. } else {
  85. $("#edit-hit-id").val("^(.*?)\s.*$");
  86. }
  87. if (data.reg2) {
  88. $("#edit-hit-def").val(data.reg2);
  89. // Show default hit-def parser if it's not set
  90. } else {
  91. $("#edit-hit-def").val("^.*?\s(.*)$");
  92. }
  93. if (data.reg3) {
  94. $("#edit-hit-accession").val(data.reg3);
  95. // Show default hit-accession parser if it's not set
  96. } else {
  97. $("#edit-hit-accession").val("^(.*?)\s.*$");
  98. }
  99. }
  100. tripal_set_genbank_style();
  101. }
  102. // ------------------------------------------------------------
  103. // Use genbank style parser. Hide regular expression text feilds
  104. function tripal_set_genbank_style (){
  105. // Disable regular expressions if genbank style parser is used (checked)
  106. if ($("#edit-gb-style-parser").is(":checked")) {
  107. $("#edit-hit-id-wrapper > label").css("color", "grey");
  108. $("#edit-hit-def-wrapper > label").css("color", "grey");
  109. $("#edit-hit-accession-wrapper > label").css("color", "grey");
  110. $("#edit-hit-id").attr('disabled', 'disabled');
  111. $("#edit-hit-def").attr('disabled', 'disabled');
  112. $("#edit-hit-accession").attr('disabled', 'disabled');
  113. } else {
  114. $("#edit-hit-id-wrapper > label").css("color", "black");
  115. $("#edit-hit-def-wrapper > label").css("color", "black");
  116. $("#edit-hit-accession-wrapper > label").css("color", "black");
  117. $("#edit-hit-id").removeAttr('disabled');
  118. $("#edit-hit-def").removeAttr('disabled');
  119. $("#edit-hit-accession").removeAttr('disabled');
  120. }
  121. }
  122. // -------------------------------------------------------------
  123. // Function that toggles the blast droppable subbox content
  124. function tripal_set_blast_subbox(db_id){
  125. $('.blast-hit-arrow-icon').hover(
  126. function() {
  127. $(this).css("cursor", "pointer");
  128. },
  129. function() {
  130. $(this).css("cursor", "pointer");
  131. }
  132. );
  133. $('.blast-hit-arrow-icon').click(function() {
  134. });
  135. }
  136. //------------------------------------------------------------
  137. // Update the blast best hit report for selected page and sorting
  138. function tripal_update_best_hit_report(obj, analysis_id, sort, descending, per_page){
  139. var page = obj.selectedIndex + 1;
  140. var baseurl = location.href.substring(0,location.href.lastIndexOf('/tripal_blast_report/'));
  141. var link = baseurl + '/tripal_blast_report/' + analysis_id + "/" + page + "/" + sort + "/" + descending + "/" + per_page;
  142. tripal_startAjax();
  143. $.ajax({
  144. url: link,
  145. dataType: 'html',
  146. type: 'POST',
  147. success: function(data){
  148. var d = document.createElement('div');
  149. d.innerHTML = data;
  150. var divs = d.getElementsByTagName("div");
  151. for (var i = 0; i < divs.length; i ++) {
  152. if (divs[i].getAttribute('id') == 'blast-hits-report') {
  153. var report_table = document.getElementById('blast-hits-report');
  154. report_table.innerHTML = divs[i].innerHTML;
  155. var table_breport = document.getElementById('tripal_blast_report_table');
  156. var sel = document.getElementById('tripal_blast_report_page_selector');
  157. sel.options[page - 1].selected = true;
  158. tripal_stopAjax();
  159. }
  160. }
  161. }
  162. });
  163. return false;
  164. }
  165. }