tripal_analysis_blast_htmlreport.inc 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. function tripal_get_blast_report ($analysis_id, $currentpage, $sort, $descending, $per_page) {
  3. $report_object = new stdClass;
  4. $symbol = "&and;";
  5. $sort_key = "ASC";
  6. if ($descending == 1) {
  7. $symbol = "&or;";
  8. $sort_key = "DESC";
  9. }
  10. $header = 'analysis_blast_besthit_query';
  11. $convert = 0;
  12. if ($sort == 1) {
  13. $header = 'analysis_blast_besthit_match';
  14. } else if ($sort == 2) {
  15. $header = 'analysis_blast_besthit_description';
  16. } else if ($sort == 3) {
  17. $header = 'analysis_blast_besthit_evalue';
  18. $convert = 1;
  19. } else if ($sort == 4) {
  20. $header = 'analysis_blast_besthit_identity';
  21. $convert = 1;
  22. } else if ($sort == 5) {
  23. $header = 'analysis_blast_besthit_length';
  24. $convert = 1;
  25. }
  26. $previous_db = tripal_db_set_active('chado');
  27. // Get analysis information including 'Time', 'Name', and 'DB Settings'
  28. $sql = "SELECT value, name, to_char(timeexecuted, 'MM-DD-YYYY') AS time
  29. FROM {analysis} A
  30. INNER JOIN {analysisprop} AP ON A.analysis_id = AP.analysis_id
  31. WHERE A.analysis_id = %d
  32. AND type_id= (SELECT cvterm_id
  33. FROM {cvterm}
  34. WHERE name = 'analysis_blast_blastdb')";
  35. $analysis = db_fetch_object(db_query($sql, $analysis_id));
  36. $db_id = $analysis->value;
  37. // Get db 'urlprefix'
  38. $sql = "SELECT urlprefix FROM {db} WHERE db_id=%d";
  39. $urlprefix = db_result(db_query($sql, $db_id));
  40. // Get all analysisfeature_id's sorted by the selected header for this blast analysis
  41. $sql = "SELECT AFP.analysisfeature_id
  42. FROM {analysisfeature} AF
  43. INNER JOIN {analysisfeatureprop} AFP ON AF.analysisfeature_id = AFP.analysisfeature_id
  44. WHERE analysis_id = %d
  45. AND AFP.type_id = (SELECT cvterm_id FROM {cvterm} WHERE name = '%s' AND cv_id = (SELECT cv_id FROM {cv} WHERE name = 'tripal'))
  46. ORDER BY value ";
  47. // Convert string to number for evalue, %identity, and length before SQL sorting
  48. if ($convert == 1) {
  49. $sql .= "::numeric ";
  50. }
  51. $sql .= "$sort_key";
  52. $result = db_query($sql, $analysis_id, $header);
  53. tripal_db_set_active($previous_db);
  54. $analysisfeatureSet = array();
  55. // Count how many analysisfeature_id we have and store them in order in $analysisfeatureSet
  56. $counter = 0;
  57. while ($feature = db_fetch_object($result)) {
  58. $analysisfeatureSet [$counter] = $feature->analysisfeature_id;
  59. $counter ++;
  60. }
  61. // Get analysis node id
  62. $ana_nid = db_result(db_query("SELECT nid FROM {chado_analysis} WHERE analysis_id = %d", $analysis_id));
  63. $ana_url = url("node/".$ana_nid);
  64. // Get pager info
  65. $no_page = (int) ($counter / $per_page);
  66. if ($counter % $per_page != 0) {
  67. $no_page ++;
  68. }
  69. $first_item = ($currentpage - 1)* $per_page;
  70. $report_object->time = $analysis->time;
  71. $report_object->name = $analysis->name;
  72. $report_object->url = $ana_url;
  73. $report_object->counter = $counter;
  74. $report_object->currentpage = $currentpage;
  75. $report_object->no_page = $no_page;
  76. $report_object->symbol = $symbol;
  77. $report_object->sort = $sort;
  78. // Construct URL path for different sorting column
  79. $path = "tripal_blast_report/$analysis_id/1/0/";
  80. if ($descending == 0 && $sort == 0) {
  81. $path .= "1";
  82. } else {
  83. $path .= "0";
  84. }
  85. $path .= "/$per_page";
  86. $url_path = url ($path);
  87. $report_object->byQuery = $url_path;
  88. $path = "tripal_blast_report/$analysis_id/1/1/";
  89. if ($descending == 0 && $sort == 1) {
  90. $path .= "1";
  91. } else {
  92. $path .= "0";
  93. }
  94. $path .= "/$per_page";
  95. $url_path = url ($path);
  96. $report_object->byMatchName =$url_path;
  97. $path = "tripal_blast_report/$analysis_id/1/2/";
  98. if ($descending == 0 && $sort == 2) {
  99. $path .= "1";
  100. } else {
  101. $path .= "0";
  102. }
  103. $path .= "/$per_page";
  104. $url_path = url ($path);
  105. $report_object->byDescription = $url_path;
  106. $path = "tripal_blast_report/$analysis_id/1/3/";
  107. if ($descending == 0 && $sort == 3) {
  108. $path .= "1";
  109. } else {
  110. $path .= "0";
  111. }
  112. $path .= "/$per_page";
  113. $url_path = url ($path);
  114. $report_object->byEvalue = $url_path;
  115. $path = "tripal_blast_report/$analysis_id/1/4/";
  116. if ($descending == 0 && $sort == 4) {
  117. $path .= "1";
  118. } else {
  119. $path .= "0";
  120. }
  121. $path .= "/$per_page";
  122. $url_path = url ($path);
  123. $report_object->byIdentity = $url_path;
  124. $path = "tripal_blast_report/$analysis_id/1/5/";
  125. if ($descending == 0 && $sort == 5) {
  126. $path .= "1";
  127. } else {
  128. $path .= "0";
  129. }
  130. $path .= "/$per_page";
  131. $url_path = url ($path);
  132. $report_object->byLength = $url_path;
  133. // Get table content
  134. $sql = "SELECT value
  135. FROM {analysisfeatureprop}
  136. WHERE analysisfeature_id = %d
  137. AND type_id = (SELECT cvterm_id FROM {cvterm} WHERE name = '%s' AND cv_id = (SELECT cv_id FROM {cv} WHERE name = 'tripal'))";
  138. $j = 0;
  139. $hits = array ();
  140. for ($i = $first_item; $i < $first_item +$per_page; $i ++) {
  141. $previous_db = tripal_db_set_active('chado');
  142. $query = db_result(db_query($sql, $analysisfeatureSet[$i], 'analysis_blast_besthit_query'));
  143. $match = db_result(db_query($sql, $analysisfeatureSet[$i], 'analysis_blast_besthit_match'));
  144. $desc = db_result(db_query($sql, $analysisfeatureSet[$i], 'analysis_blast_besthit_description'));
  145. $evalue = db_result(db_query($sql, $analysisfeatureSet[$i], 'analysis_blast_besthit_evalue'));
  146. $identity = db_result(db_query($sql, $analysisfeatureSet[$i], 'analysis_blast_besthit_identity'));
  147. $length = db_result(db_query($sql, $analysisfeatureSet[$i], 'analysis_blast_besthit_length'));
  148. $sql_fid = "SELECT feature_id FROM analysisfeature WHERE analysisfeature_id = %d";
  149. $fid = db_result(db_query($sql_fid, $analysisfeatureSet[$i]));
  150. tripal_db_set_active($previous_db);
  151. $q_url = url("ID$fid");
  152. $class = 'tripal_analysis_blast-table-odd-row tripal-table-odd-row';
  153. if($j % 2 == 0 ){
  154. $class = 'tripal_analysis_blast-table-even-row tripal-table-even-row';
  155. }
  156. $hit = new stdClass();
  157. if ($query) {
  158. $hit->class = $class;
  159. $hit->q_url = $q_url;
  160. $hit->query = $query;
  161. $hit->urlprefix = $urlprefix;
  162. $hit->match = $match;
  163. $hit->desc = $desc;
  164. $hit->evalue = $evalue;
  165. $hit->identity = $identity;
  166. $hit->length = $length;
  167. $hits [$j] = $hit;
  168. }
  169. $j ++;
  170. }
  171. $report_object->hits = $hits;
  172. // The number of items to show on the page
  173. $path = "tripal_blast_report/$analysis_id/1/$sort/$descending/";
  174. $report_object->path = $path;
  175. $report_object->per_page = $per_page;
  176. // Make AJAX call to update the page which user selected
  177. $report_object->analysis_id = $analysis_id;
  178. $report_object->sort = $sort;
  179. $report_object->descending = $descending;
  180. $report_object->per_page = $per_page;
  181. $report_object->no_page = $no_page;
  182. return theme('tripal_analysis_blast_report',$report_object);
  183. }