blast_report_alignment_row.tpl.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 round($hsp['Hsp_identity']/$hsp['Hsp_align-len']*100, 2, PHP_ROUND_HALF_EVEN);?>%)
  20. </span>,&nbsp;
  21. <span class="positive">
  22. Positive=&nbsp;
  23. <?php print $hsp['Hsp_positive']; ?>/<?php print $hsp['Hsp_align-len']; ?> (<?php print round($hsp['Hsp_positive']/$hsp['Hsp_align-len']*100, 2, PHP_ROUND_HALF_EVEN);?>%)
  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'];
  46. // code added to fix the range issue
  47. // Cordinates can increase or decrease
  48. if($hsp['Hsp_hit-from'] < $hsp['Hsp_hit-to']) {
  49. $coord['hstart'] = $hsp['Hsp_hit-from'] + ($k * 60);
  50. }
  51. else {
  52. $coord['hstart'] = $hsp['Hsp_hit-from'] - ($k * 60);
  53. }
  54. // $coord['qstop'] = $hsp['Hsp_query-from'] + (($k + 1) * 60) - 1;
  55. // $coord['qstop'] = ($coord['qstop'] > $hsp['Hsp_query-to']) ? $hsp['Hsp_query-to'] : $coord['qstop'];
  56. if ($hsp['Hsp_hit-from'] < $hsp['Hsp_hit-to']) {
  57. $coord['hstop'] = $hsp['Hsp_hit-from'] + (($k + 1) * 60) - 1;
  58. $coord['hstop'] = ($coord['hstop'] > $hsp['Hsp_hit-to']) ? $hsp['Hsp_hit-to'] : $coord['hstop'];
  59. }
  60. else {
  61. $coord['hstop'] = $hsp['Hsp_hit-from'] - (($k + 1) * 60) + 1;
  62. $coord['hstop'] = ($coord['hstop'] < $hsp['Hsp_hit-to']) ? $hsp['Hsp_hit-to'] : $coord['hstop'];
  63. }
  64. // Pad these coordinates to ensure columned display.
  65. foreach ($coord as $ck => $val) {
  66. $pad_type = (preg_match('/start/', $ck)) ? STR_PAD_LEFT : STR_PAD_RIGHT;
  67. $coord[$ck] = str_pad($val, $coord_length, '#', $pad_type);
  68. $coord[$ck] = str_replace('#', '&nbsp', $coord[$ck]);
  69. }
  70. ?>
  71. <div class="alignment-subrow">
  72. <div class="query">
  73. <span class="alignment-title">Query:</span>&nbsp;&nbsp;
  74. <span class="alignment-start-coord"><?php print $coord['qstart']; ?></span>
  75. <span class="alignment-residues"><?php print $query[$k]; ?></span>
  76. <span class="alignment-stop-coord"><?php print $coord['qstop']; ?></span>
  77. </div>
  78. <div class="matches">
  79. <?php print str_repeat('&nbsp;', 8); ?>
  80. <?php print str_repeat('&nbsp;', $coord_length); ?>
  81. <span class="alignment-residues"><?php print str_replace(' ', '&nbsp', $matches[$k]); ?></span>
  82. </div>
  83. <div class="hit">
  84. <span class="alignment-title">Sbjct:</span>&nbsp;&nbsp;
  85. <span class="alignment-start-coord"><?php print $coord['hstart']; ?></span>
  86. <span class="alignment-residues"><?php print $hit[$k]; ?></span>
  87. <span class="alignment-stop-coord"><?php print $coord['hstop']; ?></span>
  88. </div>
  89. </div>
  90. <?php } ?>
  91. </div>
  92. </div>
  93. <?php
  94. }
  95. ?>