blast_report.tpl.php 5.1 KB

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