blast_report.tpl.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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>The following table summarizes the results of your BLAST. To see additional information
  26. about each hit including the alignment, click on that row in the table to expand it.</p>
  27. <?php
  28. // Load the XML file
  29. $xml = simplexml_load_file($xml_filename);
  30. /**
  31. * We are using the drupal table theme functionality to create this listing
  32. * @see theme_table() for additional documentation
  33. */
  34. if ($xml) {
  35. // Specify the header of the table
  36. $header = array(
  37. 'number' => array('data' => '#', 'class' => array('number')),
  38. 'query' => array('data' => 'Query Name', 'class' => array('query')),
  39. 'hit' => array('data' => 'Hit Name', 'class' => array('hit')),
  40. 'evalue' => array('data' => 'E-Value', 'class' => array('evalue')),
  41. 'arrow-col' => array('data' => '', 'class' => array('arrow-col'))
  42. );
  43. $rows = array();
  44. $count = 0;
  45. // Parse the BLAST XML to generate the rows of the table
  46. // where each hit results in two rows in the table: 1) A summary of the query/hit and
  47. // significance and 2) additional information including the alignment
  48. foreach($xml->{'BlastOutput_iterations'}->children() as $iteration) {
  49. foreach($iteration->{'Iteration_hits'}->children() as $hit) {
  50. if (is_object($hit)) {
  51. $count +=1;
  52. $zebra_class = ($count % 2 == 0) ? 'even' : 'odd';
  53. // SUMMARY ROW
  54. $hit_name = $hit->Hit_id;
  55. $score = $hit->{'Hit_hsps'}->{'Hsp'}->{'Hsp_score'};
  56. $evalue = $hit->{'Hit_hsps'}->{'Hsp'}->{'Hsp_evalue'};
  57. $query_name = $iteration->{'Iteration_query-def'};
  58. $row = array(
  59. 'data' => array(
  60. 'number' => array('data' => $count, 'class' => array('number')),
  61. 'query' => array('data' => $query_name, 'class' => array('query')),
  62. 'hit' => array('data' => $hit_name, 'class' => array('hit')),
  63. 'evalue' => array('data' => $evalue, 'class' => array('evalue')),
  64. 'arrow-col' => array('data' => '<div class="arrow"></div>', 'class' => array('arrow-col'))
  65. ),
  66. 'class' => array('result-summary')
  67. );
  68. $rows[] = $row;
  69. // ALIGNMENT ROW (collapsed by default)
  70. // Process HSPs
  71. $HSPs = array();
  72. foreach ($hit->{'Hit_hsps'}->children() as $hsp_xml) {
  73. $HSPs[] = (array) $hsp_xml;
  74. }
  75. $row = array(
  76. 'data' => array(
  77. 'number' => '',
  78. 'query' => array(
  79. 'data' => theme('blast_report_alignment_row', array('HSPs' => $HSPs)),
  80. 'colspan' => 4,
  81. )
  82. ),
  83. 'class' => array('alignment-row', $zebra_class),
  84. 'no_striping' => TRUE
  85. );
  86. $rows[] = $row;
  87. }
  88. }
  89. }
  90. print theme('table', array(
  91. 'header' => $header,
  92. 'rows' => $rows,
  93. 'attributes' => array('id' => 'blast_report'),
  94. ));
  95. }
  96. else {
  97. drupal_set_title('BLAST: Error Encountered');
  98. print '<p>We encountered an error and are unable to load your BLAST results.</p>';
  99. }
  100. ?>