blast_report.tpl.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. /**
  3. * Display the results of a BLAST job execution
  4. *
  5. * Variables Available in this template:
  6. * $xml_filename: The full path & filename of XML file containing the BLAST results
  7. */
  8. // Set ourselves up to do link-out if our blast database is configured to do so.
  9. $linkout = FALSE;
  10. if ($blastdb->linkout->none === FALSE) {
  11. $linkout = TRUE;
  12. $linkout_regex = $blastdb->linkout->regex;
  13. if (isset($blastdb->linkout->db_id->urlprefix) AND !empty($blastdb->linkout->db_id->urlprefix)) {
  14. $linkout_urlprefix = $blastdb->linkout->db_id->urlprefix;
  15. }
  16. else {
  17. $linkout = FALSE;
  18. }
  19. }
  20. // Handle no hits. This following array will hold the names of all query
  21. // sequences which didn't have any hits.
  22. $query_with_no_hits = array();
  23. // Furthermore, if no query sequences have hits we don't want to bother listing
  24. // them all but just want to give a single, all-include "No Results" message.
  25. $no_hits = TRUE;
  26. ?>
  27. <!-- JQuery controlling display of the alignment information (hidden by default) -->
  28. <script type="text/javascript">
  29. $(document).ready(function(){
  30. // Hide the alignment rows in the table
  31. // (ie: all rows not labelled with the class "result-summary" which contains the tabular
  32. // summary of the hit)
  33. $("#blast_report tr:not(.result-summary)").hide();
  34. $("#blast_report tr:first-child").show();
  35. // When a results summary row is clicked then show the next row in the table
  36. // which should be corresponding the alignment information
  37. $("#blast_report tr.result-summary").click(function(){
  38. $(this).next("tr").toggle();
  39. $(this).find(".arrow").toggleClass("up");
  40. });
  41. });
  42. </script>
  43. <style>
  44. .no-hits-message {
  45. color: red;
  46. font-style: italic;
  47. }
  48. </style>
  49. <p><strong>Download</strong>:
  50. <a href="<?php print '../../' . $html_filename; ?>">HTML</a>,
  51. <a href="<?php print '../../' . $tsv_filename; ?>">Tab-Delimited</a>,
  52. <a href="<?php print '../../' . $xml_filename; ?>">XML</a>
  53. </p>
  54. <p>The following table summarizes the results of your BLAST. To see additional information
  55. about each hit including the alignment, click on that row in the table to expand it.</p>
  56. <?php
  57. // Load the XML file
  58. $xml = simplexml_load_file($xml_filename);
  59. /**
  60. * We are using the drupal table theme functionality to create this listing
  61. * @see theme_table() for additional documentation
  62. */
  63. if ($xml) {
  64. // Specify the header of the table
  65. $header = array(
  66. 'number' => array('data' => '#', 'class' => array('number')),
  67. 'query' => array('data' => 'Query Name', 'class' => array('query')),
  68. 'hit' => array('data' => 'Hit Name', 'class' => array('hit')),
  69. 'evalue' => array('data' => 'E-Value', 'class' => array('evalue')),
  70. 'arrow-col' => array('data' => '', 'class' => array('arrow-col'))
  71. );
  72. $rows = array();
  73. $count = 0;
  74. // Parse the BLAST XML to generate the rows of the table
  75. // where each hit results in two rows in the table: 1) A summary of the query/hit and
  76. // significance and 2) additional information including the alignment
  77. foreach($xml->{'BlastOutput_iterations'}->children() as $iteration) {
  78. $children_count = $iteration->{'Iteration_hits'}->children()->count();
  79. if($children_count != 0) {
  80. foreach($iteration->{'Iteration_hits'}->children() as $hit) {
  81. if (is_object($hit)) {
  82. $count +=1;
  83. $zebra_class = ($count % 2 == 0) ? 'even' : 'odd';
  84. $no_hits = FALSE;
  85. // SUMMARY ROW
  86. // If the id is of the form gnl|BL_ORD_ID|### then the parseids flag
  87. // to makeblastdb did a really poor job. In thhis case we want to use
  88. // the def to provide the original FASTA header.
  89. $hit_name = (preg_match('/BL_ORD_ID/', $hit->{'Hit_id'})) ? $hit->{'Hit_def'} : $hit->{'Hit_id'};
  90. // If our BLAST DB is configured to handle link-outs then use the
  91. // regex & URL prefix provided to create one.
  92. if ($linkout) {
  93. if (preg_match($linkout_regex, $hit_name, $linkout_match)) {
  94. $hit_name = l(
  95. $linkout_match[1],
  96. $linkout_urlprefix . $linkout_match[1],
  97. array('attributes' => array('target' => '_blank'))
  98. );
  99. }
  100. }
  101. $score = $hit->{'Hit_hsps'}->{'Hsp'}->{'Hsp_score'};
  102. $evalue = $hit->{'Hit_hsps'}->{'Hsp'}->{'Hsp_evalue'};
  103. $query_name = $iteration->{'Iteration_query-def'};
  104. $row = array(
  105. 'data' => array(
  106. 'number' => array('data' => $count, 'class' => array('number')),
  107. 'query' => array('data' => $query_name, 'class' => array('query')),
  108. 'hit' => array('data' => $hit_name, 'class' => array('hit')),
  109. 'evalue' => array('data' => $evalue, 'class' => array('evalue')),
  110. 'arrow-col' => array('data' => '<div class="arrow"></div>', 'class' => array('arrow-col'))
  111. ),
  112. 'class' => array('result-summary')
  113. );
  114. $rows[] = $row;
  115. // ALIGNMENT ROW (collapsed by default)
  116. // Process HSPs
  117. $HSPs = array();
  118. foreach ($hit->{'Hit_hsps'}->children() as $hsp_xml) {
  119. $HSPs[] = (array) $hsp_xml;
  120. }
  121. $row = array(
  122. 'data' => array(
  123. 'number' => '',
  124. 'query' => array(
  125. 'data' => theme('blast_report_alignment_row', array('HSPs' => $HSPs)),
  126. 'colspan' => 4,
  127. )
  128. ),
  129. 'class' => array('alignment-row', $zebra_class),
  130. 'no_striping' => TRUE
  131. );
  132. $rows[] = $row;
  133. }// end of if - checks $hit
  134. } //end of foreach - iteration_hits
  135. } // end of if - check for iteration_hits
  136. else {
  137. // Currently where the "no results" is added.
  138. $query_name = $iteration->{'Iteration_query-def'};
  139. $query_with_no_hits[] = $query_name;
  140. } // end of else
  141. }
  142. if ($no_hits) {
  143. print '<p class="no-hits-message">No results found.</p>';
  144. }
  145. else {
  146. // We want to warn the user if some of their query sequences had no hits.
  147. if (!empty($query_with_no_hits)) {
  148. print '<p class="no-hits-message">Some of your query sequences did not '
  149. . 'match to the database/template. They are: '
  150. . implode(', ', $query_with_no_hits) . '.</p>';
  151. }
  152. // Actually print the table.
  153. if (!empty($rows)) {
  154. print theme('table', array(
  155. 'header' => $header,
  156. 'rows' => $rows,
  157. 'attributes' => array('id' => 'blast_report'),
  158. ));
  159. }
  160. }
  161. }
  162. else {
  163. drupal_set_title('BLAST: Error Encountered');
  164. print '<p>We encountered an error and are unable to load your BLAST results.</p>';
  165. }
  166. ?>