blast_report_alignment_row.tpl.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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="alignment-row-section hit-visualization" title="Your query sequence is shown at the bottom and the target sequence it aligned to is shown at the top. The shape connecting them indicates how much of the target and query are represented by the hit.">
  12. <div class="title">Hit Visualization</div>
  13. <img src="data:image/png;base64,<?php print $hit_visualization;?>"/>
  14. <p>The image above shows the relationship between query and target for this
  15. particular BLAST hit.</p>
  16. </div>
  17. <div class="alignment-row-section alignment">
  18. <div class="title">Alignment</div>
  19. <?php
  20. foreach($HSPs as $hsp) {
  21. ?>
  22. <div class="hsp-title">HSP <?php print $hsp['Hsp_num']?></div>
  23. <div class="alignment-metrics">
  24. <span class="identity">
  25. Identity=&nbsp;
  26. <?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);?>%)
  27. </span>,&nbsp;
  28. <span class="positive">
  29. Positive=&nbsp;
  30. <?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);?>%)
  31. </span>
  32. <span class="coord-summary">
  33. Query Matches <?php print $hsp['Hsp_query-from'] . ' to ' . $hsp['Hsp_query-to']; ?>
  34. Hit Matches = <?php print $hsp['Hsp_hit-from'] . ' to ' . $hsp['Hsp_hit-to']; ?>
  35. </span>
  36. </div>
  37. <div class="alignment">
  38. <div class="alignment-row">
  39. <?php
  40. // We want to display the alignment with a max 60 residues per line with line numbers indicated.
  41. // First break up the strings.
  42. $query = str_split($hsp['Hsp_qseq'], 60);
  43. $matches = str_split($hsp['Hsp_midline'], 60);
  44. $hit = str_split($hsp['Hsp_hseq'], 60);
  45. // determine the max length of the coordinate string to use when padding.
  46. $coord_length = strlen($hsp['Hsp_hit-from']) + 3;
  47. $coord_length = (strlen($hsp['Hsp_query-to']) + 3 > $coord_length) ? strlen($hsp['Hsp_query-to']) + 3 : $coord_length;
  48. // Now foreach chink determined above...
  49. foreach (array_keys($query) as $k) {
  50. // Determine the current coordinates.
  51. $coord['qstart'] = $hsp['Hsp_query-from'] + ($k * 60);
  52. $coord['qstart'] = ($k == 0) ? $coord['qstart'] : $coord['qstart'];
  53. // code added to fix the range issue
  54. // Cordinates can increase or decrease
  55. if($hsp['Hsp_hit-from'] < $hsp['Hsp_hit-to']) {
  56. $coord['hstart'] = $hsp['Hsp_hit-from'] + ($k * 60);
  57. }
  58. else {
  59. $coord['hstart'] = $hsp['Hsp_hit-from'] - ($k * 60);
  60. }
  61. $coord['qstop'] = $hsp['Hsp_query-from'] + (($k + 1) * 60) - 1;
  62. $coord['qstop'] = ($coord['qstop'] > $hsp['Hsp_query-to']) ? $hsp['Hsp_query-to'] : $coord['qstop'];
  63. if ($hsp['Hsp_hit-from'] < $hsp['Hsp_hit-to']) {
  64. $coord['hstop'] = $hsp['Hsp_hit-from'] + (($k + 1) * 60) - 1;
  65. $coord['hstop'] = ($coord['hstop'] > $hsp['Hsp_hit-to']) ? $hsp['Hsp_hit-to'] : $coord['hstop'];
  66. }
  67. else {
  68. $coord['hstop'] = $hsp['Hsp_hit-from'] - (($k + 1) * 60) + 1;
  69. $coord['hstop'] = ($coord['hstop'] < $hsp['Hsp_hit-to']) ? $hsp['Hsp_hit-to'] : $coord['hstop'];
  70. }
  71. // Pad these coordinates to ensure columned display.
  72. foreach ($coord as $ck => $val) {
  73. $pad_type = (preg_match('/start/', $ck)) ? STR_PAD_LEFT : STR_PAD_RIGHT;
  74. $coord[$ck] = str_pad($val, $coord_length, '#', $pad_type);
  75. $coord[$ck] = str_replace('#', '&nbsp', $coord[$ck]);
  76. }
  77. ?>
  78. <div class="alignment-subrow">
  79. <div class="query">
  80. <span class="alignment-title">Query:</span>&nbsp;&nbsp;
  81. <span class="alignment-start-coord"><?php print $coord['qstart']; ?></span>
  82. <span class="alignment-residues"><?php print $query[$k]; ?></span>
  83. <span class="alignment-stop-coord"><?php print $coord['qstop']; ?></span>
  84. </div>
  85. <div class="matches">
  86. <?php print str_repeat('&nbsp;', 8); ?>
  87. <?php print str_repeat('&nbsp;', $coord_length); ?>
  88. <span class="alignment-residues"><?php print str_replace(' ', '&nbsp', $matches[$k]); ?></span>
  89. </div>
  90. <div class="hit">
  91. <span class="alignment-title">Sbjct:</span>&nbsp;&nbsp;
  92. <span class="alignment-start-coord"><?php print $coord['hstart']; ?></span>
  93. <span class="alignment-residues"><?php print $hit[$k]; ?></span>
  94. <span class="alignment-stop-coord"><?php print $coord['hstop']; ?></span>
  95. </div>
  96. </div>
  97. <?php } ?>
  98. </div>
  99. </div>
  100. <?php
  101. }
  102. ?>
  103. </div>