blast_report_alignment_row.tpl.php 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * This Template generates the HTML for a single Alignment row in a BLAST report
  4. *
  5. * Variables Available in this template:
  6. * $HSPs: an array of HSPs for the current BLAST result. This follows the structure
  7. * layed out in the XML file but has been made an array instead of a SimpleXML object
  8. * for ease of processing and abstration.
  9. */
  10. ?>
  11. <div class="title">Alignment</div>
  12. <?php
  13. foreach($HSPs as $hsp) {
  14. ?>
  15. <div class="hsp-title">HSP <?php print $hsp['Hsp_num']?></div>
  16. <div class="alignment-metrics">
  17. <span class="identity">
  18. Identity=&nbsp;
  19. <?php print $hsp['Hsp_identity']; ?>/<?php print $hsp['Hsp_align-len']; ?> (<?php print $hsp['Hsp_identity']/$hsp['Hsp_align-len']*100;?>%)
  20. </span>,&nbsp;
  21. <span class="positive">
  22. Positive=&nbsp;
  23. <?php print $hsp['Hsp_positive']; ?>/<?php print $hsp['Hsp_align-len']; ?> (<?php print $hsp['Hsp_positive']/$hsp['Hsp_align-len']*100;?>%)
  24. </span>
  25. <span class="coord-summary">
  26. Query Matches <?php print $hsp['Hsp_query-from'] . ' to ' . $hsp['Hsp_query-to']; ?>
  27. Hit Matches = <?php print $hsp['Hsp_hit-from'] . ' to ' . $hsp['Hsp_hit-to']; ?>
  28. </span>
  29. </div>
  30. <div class="alignment">
  31. <div class="alignment-row">
  32. <?php
  33. // We want to display the alignment with a max 60 residues per line with line numbers indicated.
  34. // First break up the strings.
  35. $query = str_split($hsp['Hsp_qseq'], 60);
  36. $matches = str_split($hsp['Hsp_midline'], 60);
  37. $hit = str_split($hsp['Hsp_hseq'], 60);
  38. // determine the max length of the coordinate string to use when padding.
  39. $coord_length = strlen($hsp['Hsp_hit-from']) + 3;
  40. $coord_length = (strlen($hsp['Hsp_query-to']) + 3 > $coord_length) ? strlen($hsp['Hsp_query-to']) + 3 : $coord_length;
  41. // Now foreach chink determined above...
  42. foreach (array_keys($query) as $k) {
  43. // Determine the current coordinates.
  44. $coord['qstart'] = $hsp['Hsp_query-from'] + ($k * 60);
  45. $coord['qstart'] = ($k == 0) ? $coord['qstart'] : $coord['qstart'] + 1;
  46. $coord['hstart'] = $hsp['Hsp_hit-from'] + ($k * 60);
  47. $coord['hstart'] = ($k == 0) ? $coord['hstart'] : $coord['hstart'] + 1;
  48. $coord['qstop'] = $hsp['Hsp_query-from'] + (($k + 1) * 60);
  49. $coord['qstop'] = ($coord['qstop'] > $hsp['Hsp_query-to']) ? $hsp['Hsp_query-to'] : $coord['qstop'];
  50. $coord['hstop'] = $hsp['Hsp_hit-from'] + (($k + 1) * 60);
  51. $coord['hstop'] = ($coord['hstop'] > $hsp['Hsp_hit-to']) ? $hsp['Hsp_hit-to'] : $hsp['Hsp_hit-from'];
  52. // Pad these coordinates to ensure columned display.
  53. foreach ($coord as $ck => $val) {
  54. $pad_type = (preg_match('/start/', $ck)) ? STR_PAD_LEFT : STR_PAD_RIGHT;
  55. $coord[$ck] = str_pad($val, $coord_length, '#', $pad_type);
  56. $coord[$ck] = str_replace('#', '&nbsp', $coord[$ck]);
  57. }
  58. ?>
  59. <div class="alignment-subrow">
  60. <div class="query">
  61. <span class="alignment-title">Query:</span>&nbsp;&nbsp;
  62. <span class="alignment-start-coord"><?php print $coord['qstart']; ?></span>
  63. <span class="alignment-residues"><?php print $query[$k]; ?></span>
  64. <span class="alignment-stop-coord"><?php print $coord['qstop']; ?></span>
  65. </div>
  66. <div class="matches">
  67. <?php print str_repeat('&nbsp;', 8); ?>
  68. <?php print str_repeat('&nbsp;', $coord_length); ?>
  69. <span class="alignment-residues"><?php print str_replace(' ', '&nbsp', $matches[$k]); ?></span>
  70. </div>
  71. <div class="hit">
  72. <span class="alignment-title">Hit:</span>&nbsp;&nbsp;&nbsp;&nbsp;
  73. <span class="alignment-start-coord"><?php print $coord['hstart']; ?></span>
  74. <span class="alignment-residues"><?php print $hit[$k]; ?></span>
  75. <span class="alignment-stop-coord"><?php print $coord['hstop']; ?></span>
  76. </div>
  77. </div>
  78. <?php } ?>
  79. </div>
  80. </div>
  81. <?php
  82. }
  83. ?>