blast_report_alignment_row.tpl.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. // We need to take into account that 3 nucleotides encode 1 amino acid when we are
  49. // carying out a BLAST where query and subject types are different.
  50. // Thus we use the blast program here to determine if the type of query != subject.
  51. $query_multiplier = 1;
  52. $hit_multiplier = 1;
  53. // tblastn: query = protein, subject = nucleotide.
  54. // Thus we need to adjust the hit/subject coordinates.
  55. if ($blast_program == 'tblastn'){
  56. $hit_multiplier = 3;
  57. }
  58. // blastx: query = nucleotide, subject = protein.
  59. // Thus we need to adjust the query coordinates.
  60. elseif ($blast_program == 'blastx'){
  61. $query_multiplier = 3;
  62. }
  63. // Take into account that coordinates can increase or decrease
  64. // from start to finish of the match (either query and/or subject/hit).
  65. // By default, we assume everything is increasing then adjust as neccessary.
  66. $h_from = $hsp['Hsp_hit-from'];
  67. $h_to = $hsp['Hsp_hit-to'];
  68. $q_from = $hsp['Hsp_query-from'];
  69. $q_to = $hsp['Hsp_query-to'];
  70. if ( $h_from > $h_to){
  71. $h_to = $hsp['Hsp_hit-from'];
  72. $h_from = $hsp['Hsp_hit-to'];
  73. }
  74. if ( $q_from > $q_to){
  75. $q_to = $hsp['Hsp_query-from'];
  76. $q_from = $hsp['Hsp_query-to'];
  77. }
  78. // Now foreach chink determined above...
  79. foreach (array_keys($query) as $k) {
  80. // Determine the query coordinates.
  81. $qgap_count = substr_count($query[$k],'-');
  82. // We also need to take into account the frame when determining the direction
  83. // of the match. This if the frame is positive then when go from -> to...
  84. if ($hsp['Hsp_query-frame'] >= 0){
  85. $coord['qstart'] = ($k == 0) ? $q_from : $coord['qstop'] + 1;
  86. $coord['qstop'] = $coord['qstart'] + strlen($query[$k]) * $query_multiplier - $qgap_count - 1;
  87. }
  88. // whereas, if the frame is negative then we go to -> from.
  89. else{
  90. $coord['qstart'] = ($k == 0) ? $q_to : $coord['qstop'] - 1;
  91. $coord['qstop'] = $coord['qstart'] - strlen($query[$k]) * $query_multiplier - $qgap_count + 1;
  92. }
  93. // Determine the subject/hit coordinates.
  94. $hgap_count = substr_count($hit[$k],'-');
  95. // We also need to take into account the frame when determining the direction
  96. // of the match. This if the frame is positive then when go from -> to...
  97. if ($hsp['Hsp_hit-frame'] >= 0){
  98. $coord['hstart'] = ($k == 0) ? $h_from : $coord['hstop'] + 1;
  99. $coord['hstop'] = $coord['hstart'] + strlen($hit[$k]) * $hit_multiplier - $hgap_count - 1;
  100. }
  101. // whereas, if the frame is negative then we go to -> from.
  102. else{
  103. $coord['hstart'] = ($k == 0) ? $h_to : $coord['hstop'] - 1;
  104. $coord['hstop'] = $coord['hstart'] - strlen($hit[$k]) * $hit_multiplier - $hgap_count + 1;
  105. }
  106. // Pad these coordinates to ensure columned display.
  107. foreach ($coord as $ck => $val) {
  108. $pad_type = (preg_match('/start/', $ck)) ? STR_PAD_LEFT : STR_PAD_RIGHT;
  109. $coord_formatted[$ck] = str_pad($val, $coord_length, '#', $pad_type);
  110. $coord_formatted[$ck] = str_replace('#', '&nbsp', $coord_formatted[$ck]);
  111. }
  112. ?>
  113. <div class="alignment-subrow">
  114. <div class="query">
  115. <span class="alignment-title">Query:</span>&nbsp;&nbsp;
  116. <span class="alignment-start-coord"><?php print $coord_formatted['qstart']; ?></span>
  117. <span class="alignment-residues"><?php print $query[$k]; ?></span>
  118. <span class="alignment-stop-coord"><?php print $coord_formatted['qstop']; ?></span>
  119. </div>
  120. <div class="matches">
  121. <?php print str_repeat('&nbsp;', 8); ?>
  122. <?php print str_repeat('&nbsp;', $coord_length); ?>
  123. <span class="alignment-residues"><?php print str_replace(' ', '&nbsp', $matches[$k]); ?></span>
  124. </div>
  125. <div class="hit">
  126. <span class="alignment-title">Sbjct:</span>&nbsp;&nbsp;
  127. <span class="alignment-start-coord"><?php print $coord_formatted['hstart']; ?></span>
  128. <span class="alignment-residues"><?php print $hit[$k]; ?></span>
  129. <span class="alignment-stop-coord"><?php print $coord_formatted['hstop']; ?></span>
  130. </div>
  131. </div>
  132. <?php } ?>
  133. </div>
  134. </div>
  135. <?php
  136. }
  137. ?>
  138. </div>