blast_report.tpl.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. ?>
  21. <!-- JQuery controlling display of the alignment information (hidden by default) -->
  22. <script type="text/javascript">
  23. $(document).ready(function(){
  24. // Hide the alignment rows in the table
  25. // (ie: all rows not labelled with the class "result-summary" which contains the tabular
  26. // summary of the hit)
  27. $("#blast_report tr:not(.result-summary)").hide();
  28. $("#blast_report tr:first-child").show();
  29. // When a results summary row is clicked then show the next row in the table
  30. // which should be corresponding the alignment information
  31. $("#blast_report tr.result-summary").click(function(){
  32. $(this).next("tr").toggle();
  33. $(this).find(".arrow").toggleClass("up");
  34. });
  35. });
  36. </script>
  37. <p><strong>Download</strong>:
  38. <a href="<?php print '../../' . $html_filename; ?>">HTML</a>,
  39. <a href="<?php print '../../' . $tsv_filename; ?>">Tab-Delimited</a>,
  40. <a href="<?php print '../../' . $xml_filename; ?>">XML</a>
  41. </p>
  42. <p>The following table summarizes the results of your BLAST. To see additional information
  43. about each hit including the alignment, click on that row in the table to expand it.</p>
  44. <?php
  45. // Load the XML file
  46. $xml = simplexml_load_file($xml_filename);
  47. /**
  48. * We are using the drupal table theme functionality to create this listing
  49. * @see theme_table() for additional documentation
  50. */
  51. if ($xml) {
  52. // Specify the header of the table
  53. $header = array(
  54. 'number' => array('data' => '#', 'class' => array('number')),
  55. 'query' => array('data' => 'Query Name', 'class' => array('query')),
  56. 'hit' => array('data' => 'Hit Name', 'class' => array('hit')),
  57. 'evalue' => array('data' => 'E-Value', 'class' => array('evalue')),
  58. 'arrow-col' => array('data' => '', 'class' => array('arrow-col'))
  59. );
  60. $rows = array();
  61. $count = 0;
  62. // Parse the BLAST XML to generate the rows of the table
  63. // where each hit results in two rows in the table: 1) A summary of the query/hit and
  64. // significance and 2) additional information including the alignment
  65. foreach($xml->{'BlastOutput_iterations'}->children() as $iteration) {
  66. $children_count = $iteration->{'Iteration_hits'}->children()->count();
  67. if($children_count != 0) {
  68. foreach($iteration->{'Iteration_hits'}->children() as $hit) {
  69. if (is_object($hit)) {
  70. $count +=1;
  71. $zebra_class = ($count % 2 == 0) ? 'even' : 'odd';
  72. // SUMMARY ROW
  73. // If the id is of the form gnl|BL_ORD_ID|### then the parseids flag
  74. // to makeblastdb did a really poor job. In thhis case we want to use
  75. // the def to provide the original FASTA header.
  76. $hit_name = (preg_match('/BL_ORD_ID/', $hit->{'Hit_id'})) ? $hit->{'Hit_def'} : $hit->{'Hit_id'};
  77. // If our BLAST DB is configured to handle link-outs then use the
  78. // regex & URL prefix provided to create one.
  79. if ($linkout) {
  80. if (preg_match($linkout_regex, $hit_name, $linkout_match)) {
  81. $hit_name = l(
  82. $linkout_match[1],
  83. $linkout_urlprefix . $linkout_match[1],
  84. array('attributes' => array('target' => '_blank'))
  85. );
  86. }
  87. }
  88. $score = $hit->{'Hit_hsps'}->{'Hsp'}->{'Hsp_score'};
  89. $evalue = $hit->{'Hit_hsps'}->{'Hsp'}->{'Hsp_evalue'};
  90. $query_name = $iteration->{'Iteration_query-def'};
  91. $row = array(
  92. 'data' => array(
  93. 'number' => array('data' => $count, 'class' => array('number')),
  94. 'query' => array('data' => $query_name, 'class' => array('query')),
  95. 'hit' => array('data' => $hit_name, 'class' => array('hit')),
  96. 'evalue' => array('data' => $evalue, 'class' => array('evalue')),
  97. 'arrow-col' => array('data' => '<div class="arrow"></div>', 'class' => array('arrow-col'))
  98. ),
  99. 'class' => array('result-summary')
  100. );
  101. $rows[] = $row;
  102. // ALIGNMENT ROW (collapsed by default)
  103. // Process HSPs
  104. $HSPs = array();
  105. foreach ($hit->{'Hit_hsps'}->children() as $hsp_xml) {
  106. $HSPs[] = (array) $hsp_xml;
  107. }
  108. $row = array(
  109. 'data' => array(
  110. 'number' => '',
  111. 'query' => array(
  112. 'data' => theme('blast_report_alignment_row', array('HSPs' => $HSPs)),
  113. 'colspan' => 4,
  114. )
  115. ),
  116. 'class' => array('alignment-row', $zebra_class),
  117. 'no_striping' => TRUE
  118. );
  119. $rows[] = $row;
  120. }// end of if - checks $hit
  121. } //end of foreach - iteration_hits
  122. } // end of if - check for iteration_hits
  123. else {
  124. // Currently where the "no results" is added.
  125. $count +=1;
  126. $query_id = $iteration->{'Iteration_query-ID'};
  127. $query_name = $iteration->{'Iteration_query-def'};
  128. $row = array(
  129. 'data' => array(
  130. 'number' => array('data' => $count , 'class' => array('number')),
  131. 'query' => array('data' => $query_name, 'class' => array('query')),
  132. 'hit' => array('data' => $iteration->{'Iteration_message'}, 'class' => array('hit')),
  133. 'evalue' => array('data' => "-", 'class' => array('evalue')),
  134. 'arrow-col' => array('data' => '', 'class' => array('arrow-col'))
  135. ),
  136. 'class' => array('result-summary')
  137. );
  138. $rows[] = $row;
  139. } // end of else
  140. }
  141. // Actually print the table.
  142. print theme('table', array(
  143. 'header' => $header,
  144. 'rows' => $rows,
  145. 'attributes' => array('id' => 'blast_report'),
  146. ));
  147. }
  148. else {
  149. drupal_set_title('BLAST: Error Encountered');
  150. print '<p>We encountered an error and are unable to load your BLAST results.</p>';
  151. }
  152. ?>