$coord_length) ? strlen($hsp['Hsp_query-to']) + 3 : $coord_length;
// We need to take into account that 3 nucleotides encode 1 amino acid when we are
// carying out a BLAST where query and subject types are different.
// Thus we use the blast program here to determine if the type of query != subject.
$query_multiplier = 1;
$hit_multiplier = 1;
// tblastn: query = protein, subject = nucleotide.
// Thus we need to adjust the hit/subject coordinates.
if ($blast_program == 'tblastn'){
$hit_multiplier = 3;
}
// blastx: query = nucleotide, subject = protein.
// Thus we need to adjust the query coordinates.
elseif ($blast_program == 'blastx'){
$query_multiplier = 3;
}
// Take into account that coordinates can increase or decrease
// from start to finish of the match (either query and/or subject/hit).
// By default, we assume everything is increasing then adjust as neccessary.
$h_from = $hsp['Hsp_hit-from'];
$h_to = $hsp['Hsp_hit-to'];
$q_from = $hsp['Hsp_query-from'];
$q_to = $hsp['Hsp_query-to'];
if ( $h_from > $h_to){
$h_to = $hsp['Hsp_hit-from'];
$h_from = $hsp['Hsp_hit-to'];
}
if ( $q_from > $q_to){
$q_to = $hsp['Hsp_query-from'];
$q_from = $hsp['Hsp_query-to'];
}
// Now foreach chink determined above...
foreach (array_keys($query) as $k) {
// Determine the query coordinates.
$qgap_count = substr_count($query[$k],'-');
// We also need to take into account the frame when determining the direction
// of the match. This if the frame is positive then when go from -> to...
if ($hsp['Hsp_query-frame'] >= 0){
$coord['qstart'] = ($k == 0) ? $q_from : $coord['qstop'] + 1;
$coord['qstop'] = $coord['qstart'] + strlen($query[$k]) * $query_multiplier - $qgap_count - 1;
}
// whereas, if the frame is negative then we go to -> from.
else{
$coord['qstart'] = ($k == 0) ? $q_to : $coord['qstop'] - 1;
$coord['qstop'] = $coord['qstart'] - strlen($query[$k]) * $query_multiplier - $qgap_count + 1;
}
// Determine the subject/hit coordinates.
$hgap_count = substr_count($hit[$k],'-');
// We also need to take into account the frame when determining the direction
// of the match. This if the frame is positive then when go from -> to...
if ($hsp['Hsp_hit-frame'] >= 0){
$coord['hstart'] = ($k == 0) ? $h_from : $coord['hstop'] + 1;
$coord['hstop'] = $coord['hstart'] + strlen($hit[$k]) * $hit_multiplier - $hgap_count - 1;
}
// whereas, if the frame is negative then we go to -> from.
else{
$coord['hstart'] = ($k == 0) ? $h_to : $coord['hstop'] - 1;
$coord['hstop'] = $coord['hstart'] - strlen($hit[$k]) * $hit_multiplier - $hgap_count + 1;
}
// Pad these coordinates to ensure columned display.
foreach ($coord as $ck => $val) {
$pad_type = (preg_match('/start/', $ck)) ? STR_PAD_LEFT : STR_PAD_RIGHT;
$coord_formatted[$ck] = str_pad($val, $coord_length, '#', $pad_type);
$coord_formatted[$ck] = str_replace('#', ' ', $coord_formatted[$ck]);
}
?>