sub to_string
{ my ($self,$result) = @_;
return '' unless defined $result;
my ($resultfilter,$hitfilter,
$hspfilter) = ( $self->filter('RESULT'),
$self->filter('HIT'),
$self->filter('HSP'));
return '' if( defined $resultfilter && ! &{$resultfilter}($result) );
my $type = ( $result->algorithm =~ /(P|X|Y)$/i ) ? 'PROTEIN' : 'NUCLEOTIDE';
my $str = sprintf(
qq{%s %s
Bioperl Reformatted BLAST Format report of %s Search output
with Bio::SearchIO Bioperl Reformatted BLAST Format Module %s
%s
Query=%s %s
(%d letters)
Database: %s
%d sequences; %d total letters
Sequences producing significant alignments: Score E
(bits) value
},
$result->algorithm, $result->algorithm_version,
$result->algorithm, ref($result),
$result->program_reference() || $self->algorithm_reference($result),
$result->query_name, $result->query_description,
$result->query_length,
$result->database_name(),
$result->database_entries(),
$result->database_letters(),
);
my $hspstr = '';
$result->rewind();
while( my $hit = $result->next_hit ) {
next if( defined $hitfilter && ! &{$hitfilter}($hit) );
my $nm = $hit->name();
my $id_parser = $self->id_parser;
print STDERR "no $nm for name (",$hit->description(), ")\n" unless $nm;
my ($gi,$acc) = &$id_parser($nm);
my $p = "%-".$MaxDescLen. "s";
my $descsub = $hit->name . " " . $hit->description;
if( length($descsub) > ($MaxDescLen) ) {
$descsub = substr($descsub,0,$MaxDescLen-3) . "...";
}
$str .= sprintf("$p %s %-4s %s\n",
$descsub,
defined $hit->raw_score ? $hit->raw_score : ' ',
defined $hit->significance ? $hit->significance : '?');
$hspstr .= sprintf(">%s %s\n%9sLength = %d\n\n",
$hit->name,
defined $hit->description ? $hit->description : '',
'', $hit->length);
$hit->rewind(); while( my $hsp = $hit->next_hsp ) {
next if( defined $hspfilter && ! &{$hspfilter}($hsp) );
$hspstr .= sprintf(" Score = %4s bits (%s), Expect = %s",
$hsp->bits, $hsp->score, $hsp->evalue);
if( $hsp->pvalue ) {
$hspstr .= ", P = ".$hsp->pvalue;
}
$hspstr .= "\n";
$hspstr .= sprintf(" Identities = %d/%d (%d%%)",
( $hsp->frac_identical('total') *
$hsp->length('total')),
$hsp->length('total'),
POSIX::floor($hsp->frac_identical('total') * 100));
if( $hit->algorithm =~ /(T)?BLAST(X|P)/ ||
$hit->algorithm =~ /(T)?FAST(X|Y|P)/ ||
$hit->algorithm eq 'TBLASTN' ||
$hit->algorithm eq 'TFASTN'
) {
$hspstr .= sprintf(", Positives = %d/%d (%d%%)",
( $hsp->frac_conserved('total') *
$hsp->length('total')),
$hsp->length('total'),
POSIX::floor($hsp->frac_conserved('total') * 100));
}
if( $hsp->gaps ) {
$hspstr .= sprintf(", Gaps = %d/%d (%d%%)\n",
$hsp->gaps('total'),
$hsp->length('total'),
POSIX::floor(100 * $hsp->gaps('total') / $hsp->length('total'))); }
my ($h,$q) = ( $hsp->hit->frame ,$hsp->query->frame);
if( $h || $q ) {
$hspstr .= " Frame = ";
if( $h && ! $q) { $hspstr .= $h }
elsif( $q && ! $h) { $hspstr .= $q }
else {
$hspstr .= " $h / $q\n ";
}
}
$hspstr .= "\n";
my @hspvals = ( {'name' => 'Query:',
'seq' => $hsp->query_string,
'start' => $hsp->query->strand >= 0 ?
$hsp->query->start : $hsp->query->end,
'end' => $hsp->query->strand >= 0 ?
$hsp->query->end : $hsp->query->start,
'index' => 0,
'direction' => $hsp->query->strand || 1
},
{ 'name' => ' 'x6,
'seq' => $hsp->homology_string,
'start' => undef,
'end' => undef,
'index' => 0,
'direction' => 1
},
{ 'name' => 'Sbjct:',
'seq' => $hsp->hit_string,
'start' => $hsp->hit->strand >= 0 ? $hsp->hit->start : $hsp->hit->end,
'end' => $hsp->hit->strand >= 0 ? $hsp->hit->end : $hsp->hit->start,
'index' => 0,
'direction' => $hsp->query->strand || 1
}
);
my ($numwidth) = sort { $b <=> $a }(length($hspvals[0]->{'start'}),
length($hspvals[0]->{'end'}),
length($hspvals[2]->{'start'}),
length($hspvals[2]->{'end'}));
my $count = 0;
while ( $count <= $hsp->length('total') ) {
foreach my $v ( @hspvals ) {
my $piece = substr($v->{'seq'}, $v->{'index'} +$count,
$AlignmentLineWidth);
my $cp = $piece;
my $plen = scalar ( $cp =~ tr/\-//);
my ($start,$end) = ('','');
if( defined $v->{'start'} ) {
$start = $v->{'start'};
my $d = ( ( $v->{'direction'} ) *
( $AlignmentLineWidth - $plen ));
if( length($piece) < $AlignmentLineWidth ) {
$d = (length($piece) - $plen) * $v->{'direction'};
}
$end = $v->{'start'} + $d - 1;
$v->{'start'} += $d;
}
$hspstr .= sprintf("%s %-".$numwidth."s %s %s\n",
$v->{'name'},
$start,
$piece,
$end
);
}
$count += $AlignmentLineWidth;
$hspstr .= "\n";
}
}
$hspstr .= "\n";
}
$str .= "\n\n".$hspstr;
foreach my $param ( $result->available_parameters ) {
$str .= "$param: ". $result->get_parameter($param) ."\n";
}
$str .= "Search Statistics\n";
foreach my $stat ( sort $result->available_statistics ) {
$str .= "$stat: ". $result->get_statistic($stat). "\n";
}
$str .= "\n\n";
return $str;} |
sub algorithm_reference
{ my ($self,$result) = @_;
return '' if( ! defined $result || !ref($result) ||
! $result->isa('Bio::Search::Result::ResultI')) ;
if( $result->algorithm =~ /BLAST/i ) {
my $res = $result->algorithm . ' '. $result->algorithm_version. "\n";
if( $result->algorithm_version =~ /WashU/i ) {
return $res .qq{
Copyright (C) 1996-2000 Washington University, Saint Louis, Missouri USA.
All Rights Reserved.
Reference: Gish, W. (1996-2000) http://blast.wustl.edu
};
} else {
return $res . qq{
Reference: Altschul, Stephen F., Thomas L. Madden, Alejandro A. Schaffer,
Jinghui Zhang, Zheng Zhang, Webb Miller, and David J. Lipman (1997),
"Gapped BLAST and PSI-BLAST: a new generation of protein database search
programs", Nucleic Acids Res. 25:3389-3402.
};
}
} elsif( $result->algorithm =~ /FAST/i ) {
return $result->algorithm. " ". $result->algorithm_version . "\n".
"\nReference: Pearson et al, Genomics (1997) 46:24-36\n";
} else {
return '';
}} |
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _