$coord_length) ? strlen($hsp['Hsp_query-to']) + 3 : $coord_length;
// use blast program type to determine multiplier for coords
$query_multiplier = 1;
$hit_multiplier = 1;
// only need to do this when the query and sbj are of different types
if ($blast_program == 'tblastn'){
$hit_multiplier = 3;
} elseif ($blast_program == 'blastx'){
$query_multiplier = 3;
}
$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 current coordinates.
$qgap_count = substr_count($query[$k],'-');
$hgap_count = substr_count($hit[$k],'-');
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;
}else{
$coord['qstart'] = ($k == 0) ? $q_to : $coord['qstop'] - 1;
$coord['qstop'] = $coord['qstart'] - strlen($query[$k]) * $query_multiplier - $qgap_count + 1;
}
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;
}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[$ck] = str_pad($val, $coord_length, '#', $pad_type);
$coord[$ck] = str_replace('#', ' ', $coord[$ck]);
}
?>