tripal_analysis_blast_htmlreport.inc 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. function tripal_get_blast_report ($analysis_id, $currentpage, $sort, $descending, $per_page) {
  3. /*
  4. if (!tripal_check_permission_by_analysis_id($analysis_id)) {
  5. $html_out = "Access denied. You are not authorized to access this report.";
  6. return $html_out;
  7. }
  8. */
  9. $symbol = "&and;";
  10. $sort_key = "ASC";
  11. if ($descending == 1) {
  12. $symbol = "&or;";
  13. $sort_key = "DESC";
  14. }
  15. $header = 'analysis_blast_besthit_query';
  16. $convert = 0;
  17. if ($sort == 1) {
  18. $header = 'analysis_blast_besthit_match';
  19. } else if ($sort == 2) {
  20. $header = 'analysis_blast_besthit_description';
  21. } else if ($sort == 3) {
  22. $header = 'analysis_blast_besthit_evalue';
  23. $convert = 1;
  24. } else if ($sort == 4) {
  25. $header = 'analysis_blast_besthit_identity';
  26. $convert = 1;
  27. } else if ($sort == 5) {
  28. $header = 'analysis_blast_besthit_length';
  29. $convert = 1;
  30. }
  31. $previous_db = tripal_db_set_active('chado');
  32. // Get analysis information including 'Time', 'Name', and 'DB Settings'
  33. $sql = "SELECT value, name, to_char(timeexecuted, 'MM-DD-YYYY') AS time
  34. FROM {analysis} A
  35. INNER JOIN {analysisprop} AP ON A.analysis_id = AP.analysis_id
  36. WHERE A.analysis_id = %d
  37. AND type_id= (SELECT cvterm_id
  38. FROM {cvterm}
  39. WHERE name = 'analysis_blast_settings')";
  40. $analysis = db_fetch_object(db_query($sql, $analysis_id));
  41. // Parse the blast settings
  42. $blastsettings = explode("|", $analysis->value);
  43. $db_id = $blastsettings [0];
  44. // Get db 'urlprefix'
  45. $sql = "SELECT urlprefix FROM {db} WHERE db_id=%d";
  46. $urlprefix = db_result(db_query($sql, $db_id));
  47. // Get all analysisfeature_id's sorted by the selected header for this blast analysis
  48. $sql = "SELECT AFP.analysisfeature_id
  49. FROM {analysisfeature} AF
  50. INNER JOIN {analysisfeatureprop} AFP ON AF.analysisfeature_id = AFP.analysisfeature_id
  51. WHERE analysis_id = %d
  52. AND AFP.type_id = (SELECT cvterm_id FROM {cvterm} WHERE name = '%s' AND cv_id = (SELECT cv_id FROM {cv} WHERE name = 'tripal'))
  53. ORDER BY value ";
  54. // Convert string to number for evalue, %identity, and length before SQL sorting
  55. if ($convert == 1) {
  56. $sql .= "::numeric ";
  57. }
  58. $sql .= "$sort_key";
  59. $result = db_query($sql, $analysis_id, $header);
  60. tripal_db_set_active($previous_db);
  61. $analysisfeatureSet = array();
  62. // Count how many analysisfeature_id we have and store them in order in $analysisfeatureSet
  63. $counter = 0;
  64. while ($feature = db_fetch_object($result)) {
  65. $analysisfeatureSet [$counter] = $feature->analysisfeature_id;
  66. $counter ++;
  67. }
  68. // Get analysis node id
  69. $ana_nid = db_result(db_query("SELECT nid FROM {chado_analysis} WHERE analysis_id = %d", $analysis_id));
  70. $ana_url = url("node/".$ana_nid);
  71. // Get pager info
  72. $no_page = (int) ($counter / $per_page);
  73. if ($counter % $per_page != 0) {
  74. $no_page ++;
  75. }
  76. $first_item = ($currentpage - 1)* $per_page;
  77. $url = url(drupal_get_path('theme', 'tripal')."/images/ajax-loader.gif");
  78. $html_out .= "<div id=\"tripal_ajaxLoading\" style=\"display:none\">".
  79. "<div id=\"loadingText\">Loading...</div>".
  80. "<img src=\"$url\"></div>";
  81. $html_out .= "<div id=\"blast-hits-report\">
  82. <strong>Analysis Date: </strong>$analysis->time (<a href=$ana_url>$analysis->name</a>)<br>
  83. There are <strong>$counter</strong> records. <div id=tripal_blast_report_current_page>page <strong>$currentpage</strong> of <strong>$no_page</strong></div>
  84. <table id=\"tripal_analysi_blast-report-table\" class=\"tripal_analysis_blast-table tripal-table tripal-table-horz\">
  85. <tr class=\"tripal_analysis_blast-table-odd-row tripal-table-odd-row\">";
  86. $html_out .= " <th nowrap>"; if ($sort == 0) {$html_out .= $symbol;}
  87. // Construct URL path for different sorting column
  88. $path = "tripal_blast_report/$analysis_id/1/0/";
  89. if ($descending == 0 && $sort == 0) {
  90. $path .= "1";
  91. } else {
  92. $path .= "0";
  93. }
  94. $path .= "/$per_page";
  95. $url_path = url ($path);
  96. $html_out.="<a href=$url_path>Query</a></th><th nowrap>"; if ($sort == 1) {$html_out .= $symbol;}
  97. $path = "tripal_blast_report/$analysis_id/1/1/";
  98. if ($descending == 0 && $sort == 1) {
  99. $path .= "1";
  100. } else {
  101. $path .= "0";
  102. }
  103. $path .= "/$per_page";
  104. $url_path = url ($path);
  105. $html_out.="<a href=$url_path>Match Name</a></th><th nowrap>"; if ($sort == 2) {$html_out .= $symbol;}
  106. $path = "tripal_blast_report/$analysis_id/1/2/";
  107. if ($descending == 0 && $sort == 2) {
  108. $path .= "1";
  109. } else {
  110. $path .= "0";
  111. }
  112. $path .= "/$per_page";
  113. $url_path = url ($path);
  114. $html_out.="<a href=$url_path>Description</a></th><th nowrap>"; if ($sort == 3) {$html_out .= $symbol;}
  115. $path = "tripal_blast_report/$analysis_id/1/3/";
  116. if ($descending == 0 && $sort == 3) {
  117. $path .= "1";
  118. } else {
  119. $path .= "0";
  120. }
  121. $path .= "/$per_page";
  122. $url_path = url ($path);
  123. $html_out.="<a href=$url_path>E-value</a></th><th nowrap>"; if ($sort == 4) {$html_out .= $symbol;}
  124. $path = "tripal_blast_report/$analysis_id/1/4/";
  125. if ($descending == 0 && $sort == 4) {
  126. $path .= "1";
  127. } else {
  128. $path .= "0";
  129. }
  130. $path .= "/$per_page";
  131. $url_path = url ($path);
  132. $html_out.="<a href=$url_path>%Identity</a></th><th nowrap>"; if ($sort == 5) {$html_out .= $symbol;}
  133. $path = "tripal_blast_report/$analysis_id/1/5/";
  134. if ($descending == 0 && $sort == 5) {
  135. $path .= "1";
  136. } else {
  137. $path .= "0";
  138. }
  139. $path .= "/$per_page";
  140. $url_path = url ($path);
  141. $html_out.="<a href=$url_path>Length</a></th>";
  142. $html_out .= "</tr>";
  143. // Get table content
  144. $sql = "SELECT value
  145. FROM {analysisfeatureprop}
  146. WHERE analysisfeature_id = %d
  147. AND type_id = (SELECT cvterm_id FROM {cvterm} WHERE name = '%s' AND cv_id = (SELECT cv_id FROM {cv} WHERE name = 'tripal'))";
  148. $j = 0;
  149. for ($i = $first_item; $i < $first_item +$per_page; $i ++) {
  150. $previous_db = tripal_db_set_active('chado');
  151. $query = db_result(db_query($sql, $analysisfeatureSet[$i], 'analysis_blast_besthit_query'));
  152. $match = db_result(db_query($sql, $analysisfeatureSet[$i], 'analysis_blast_besthit_match'));
  153. $desc = db_result(db_query($sql, $analysisfeatureSet[$i], 'analysis_blast_besthit_description'));
  154. $evalue = db_result(db_query($sql, $analysisfeatureSet[$i], 'analysis_blast_besthit_evalue'));
  155. $identity = db_result(db_query($sql, $analysisfeatureSet[$i], 'analysis_blast_besthit_identity'));
  156. $length = db_result(db_query($sql, $analysisfeatureSet[$i], 'analysis_blast_besthit_length'));
  157. $sql_fid = "SELECT feature_id FROM analysisfeature WHERE analysisfeature_id = %d";
  158. $fid = db_result(db_query($sql_fid, $analysisfeatureSet[$i]));
  159. tripal_db_set_active($previous_db);
  160. $q_url = url("ID$fid");
  161. $class = 'tripal_analysis_blast-table-odd-row tripal-table-odd-row';
  162. if($j % 2 == 0 ){
  163. $class = 'tripal_analysis_blast-table-even-row tripal-table-even-row';
  164. }
  165. if ($query) {
  166. $html_out .= "<tr class=\"$class\">
  167. <td nowrap><a href=$q_url>$query</a></td>
  168. <td nowrap><a href=\"$urlprefix$match\" target=\"_blank\">$match</td>
  169. <td>$desc</td>
  170. <td nowrap>$evalue</td>
  171. <td nowrap>$identity</td>
  172. <td nowrap>$length</td>
  173. </tr>";
  174. }
  175. $j ++;
  176. }
  177. // The number of items to show on the page
  178. $path = "tripal_blast_report/$analysis_id/1/$sort/$descending/";
  179. $html_out .= '</table>
  180. <div id=tripal_blast_report_per_page>Show ';
  181. if ($per_page == 10) {
  182. $html_out .= "<strong>10</strong> | ";
  183. } else {
  184. $url_path = url($path."10");
  185. $html_out .= "<a href=$url_path>10</a> | ";
  186. }
  187. if ($per_page == 20) {
  188. $html_out .= "<strong>20</strong> | ";
  189. } else {
  190. $url_path = url($path."20");
  191. $html_out .= "<a href=$url_path>20</a> | ";
  192. }
  193. if ($per_page == 50) {
  194. $html_out .= "<strong>50</strong> | ";
  195. } else {
  196. $url_path = url($path."50");
  197. $html_out .= "<a href=$url_path>50</a> | ";
  198. }
  199. if ($per_page == 100) {
  200. $html_out .= "<strong>100</strong> | ";
  201. } else {
  202. $url_path = url($path."100");
  203. $html_out .= "<a href=$url_path>100</a> | ";
  204. }
  205. if ($per_page == 200) {
  206. $html_out .= "<strong>200</strong> | ";
  207. } else {
  208. $url_path = url($path."200");
  209. $html_out .= "<a href=$url_path>200</a>";
  210. }
  211. // Make AJAX call to update the page which user selected
  212. $html_out .= ' records per page
  213. </div>
  214. <div id=tripal_blast_report_pager>page
  215. <select id=tripal_blast_report_page_selector onChange="tripal_update_best_hit_report(this,'.$analysis_id.','.$sort.','.$descending.','.$per_page.')">';
  216. for ($i = 1; $i <= $no_page; $i ++) {
  217. $html_out .= "<option value=$i>$i</option>";
  218. }
  219. $html_out .= '</select></div>
  220. </div>';
  221. return $html_out;
  222. }