Bio::Search::Result
HmmpfamResult
Summary
Bio::Search::Result::HmmpfamResult - A parser and result object for hmmpfam
results
Package variables
No package variables defined.
Included modules
Inherit
Synopsis
# generally we use Bio::SearchIO to build these objects
use Bio::SearchIO;
my $in = new Bio::SearchIO(-format => 'hmmer_pull',
-file => 'result.hmmer');
while (my $result = $in->next_result) {
print $result->query_name, " ", $result->algorithm, " ", $result->num_hits(), " hits\n";
}
Description
This object implements a parser for hmmpfam result output, a program in the HMMER
package.
Methods
Methods description
Title : new Usage : my $obj = new Bio::SearchIO::Result::hmmpfam(); Function: Builds a new Bio::SearchIO::Result::hmmpfam object Returns : Bio::SearchIO::Result::hmmpfam Args : -chunk => [Bio::Root::IO, $start, $end] (required if no -parent) -parent => Bio::PullParserI object (required if no -chunk) -parameters => hash ref of search parameters (key => value), optional -statistics => hash ref of search statistics (key => value), optional
where the array ref provided to -chunk contains an IO object
for a filehandle to something representing the raw data of the
result, and $start and $end define the tell() position within the
filehandle that the result data starts and ends (optional; defaults
to start and end of the entire thing described by the filehandle) |
Title : next_hit Usage : while( $hit = $result->next_hit()) { ... } Function: Returns the next available Hit object, representing potential matches between the query and various entities from the database. Returns : a Bio::Search::Hit::HitI object or undef if there are no more. Args : none |
Title : hits Usage : my @hits = $result->hits Function: Returns the HitI objects contained within this Result Returns : Array of Bio::Search::Hit::HitI objects Args : none
See Also: Bio::Search::Hit::HitI |
Title : sort_hits Usage : $result->sort_hits('<score') Function : Sorts the hits so that they come out in the desired order when hits() or next_hit() is called. Returns : n/a Args : A coderef for the sort function. See the documentation on the Perl sort() function for guidelines on writing sort functions. You will be sorting array references, not HitI objects. The references contain name as element 0, description as element 1, score as element 2, significance as element 3 and number of hsps as element 4. By default the sort order is ascending significance value (ie. most significant hits first). Note : To access the special variables $a and $b used by the Perl sort() function the user function must access Bio::Search::Result::HmmpfamResult namespace. For example, use : $result->sort_hits( sub{$Bio::Search::Result::HmmpfamResult::a->[2] <=> $Bio::Search::Result::HmmpfamResult::b->[2]}); NOT $result->sort_hits($a->[2] <=> $b->[2]); |
Title : rewind Usage : $result->rewind; Function: Allow one to reset the Hit iterator to the beginning, so that next_hit() will subsequently return the first hit and so on. Returns : n/a Args : none |
Methods code
sub new
{ my ($class, @args) = @_;
my $self = $class->SUPER::new(@args);
$self->_setup(@args);
foreach my $field (qw( header hit_table hsp_table alignments next_model models query_length )) {
$self->_fields->{$field} = undef;
}
$self->_dependencies( { ( query_name => 'header',
query_accession => 'header',
query_description => 'header',
hit_table => 'header',
num_hits => 'hit_table',
no_hits_found => 'hit_table',
hsp_table => 'hit_table',
next_alignment => 'hsp_table' ) } );
return $self;} |
sub _discover_header
{ my $self = shift;
$self->_chunk_seek(0);
my $header = $self->_get_chunk_by_end("all domains):\n");
$self->{_after_header} = $self->_chunk_tell;
$header || $self->throw("Could not find hmmer header, is file really hmmer format?");
($self->_fields->{query_name}) = $header =~ /^Query(?:\s+sequence)?:\s+(\S+)/m;
($self->_fields->{query_accession}) = $header =~ /^Accession:\s+(\S+)/m;
($self->_fields->{query_description}) = $header =~ /^Description:\s+(\S.+)/m;
$self->_fields->{query_accession} ||= '';
$self->_fields->{query_description} ||= '';
$self->_fields->{header} = 1;
} |
sub _discover_hit_table
{ my $self = shift;
$self->_chunk_seek($self->{_after_header});
my $table = $self->_get_chunk_by_end("for domains:\n");
$self->{_after_hit_table} = $self->_chunk_tell;
my $evalue_cutoff = $self->get_field('evalue_cutoff');
undef $evalue_cutoff if $evalue_cutoff eq '[unset]';
my $score_cutoff = $self->get_field('score_cutoff');
undef $score_cutoff if $score_cutoff eq '[unset]';
my $hsps_cutoff = $self->get_field('hsps_cutoff');
undef $hsps_cutoff if $hsps_cutoff eq '[unset]';
my @table;
my $no_hit = 1;
while ($table =~ /^(\S+)\s+(\S.+?)?\s+(\S+)\s+(\S+)\s+(\d+)\n/gm) {
$no_hit = 0;
my $evalue = abs($4); next if ($evalue_cutoff && $evalue > $evalue_cutoff);
next if ($score_cutoff && $3 < $score_cutoff);
next if ($hsps_cutoff && $5 < $hsps_cutoff);
push(@table, [$1, $2, $3, $evalue, $5]);
}
$self->_fields->{hit_table} =\@ table;
$self->{_next_hit_index} = @table > 0 ? 0 : -1;
$self->_fields->{no_hits_found} = $no_hit;
$self->_fields->{num_hits} = @table;} |
sub _discover_hsp_table
{ my $self = shift;
$self->_chunk_seek($self->{_after_hit_table});
my $table = $self->_get_chunk_by_end("top-scoring domains:\n");
$table ||= $self->_get_chunk_by_end("//\n"); $self->{_after_hsp_table} = $self->_chunk_tell;
my %table;
while ($table =~ /^(\S+)\s+(\d+)\/\d+\s+(\d+)\s+(\d+)\s+\S\S\s+(\d+)\s+(\d+)\s+\S(\S)\s+(\S+)\s+(\S+)/gm) {
my $evalue = abs($9); push(@{$table{$1}->{hsp_data}}, [$2, $3, $4, $5, $6, $8, $evalue]);
if ($7 eq ']') {
$table{$1}->{hit_length} = $6;
}
}
$self->_fields->{hsp_table} =\% table;} |
sub _discover_alignments
{ my $self = shift;
$self->_fields->{alignments} = { };} |
sub _next_alignment
{ my $self = shift;;
return if $self->{_no_more_alignments};
my $aligns = $self->_fields->{alignments};
unless (defined $self->{_after_previous_alignment}) {
$self->_chunk_seek($self->{_after_hsp_table});
my $chunk = $self->_get_chunk_by_end(": domain");
unless ($chunk) {
$self->{_no_more_alignments} = 1;
return;
}
$self->{_after_previous_alignment} = $self->_chunk_tell;
$self->{_next_alignment_start_text} = $chunk;
$self->_next_alignment;
return;
}
$self->_chunk_seek($self->{_after_previous_alignment});
my $chunk = $self->_get_chunk_by_end(": domain");
unless ($chunk) {
$self->_chunk_seek($self->{_after_previous_alignment});
$chunk = $self->_get_chunk_by_end("//");
unless ($chunk) {
$self->{_no_more_alignments} = 1;
return;
}
}
$self->{_after_previous_alignment} = $self->_chunk_tell;
if (defined $self->{_next_alignment_start_text}) {
$chunk = $self->{_next_alignment_start_text}.$chunk;
}
$chunk =~ s/(\S+: domain)$//;
$self->{_next_alignment_start_text} = $1;
my ($name, $domain) = $chunk =~ /^(\S+): domain (\d+)/;
$aligns->{$name.'~~~~'.$domain} = $chunk;
return 1;} |
sub _discover_next_hit
{ my $self = shift;
my @hit_table = @{$self->get_field('hit_table')};
return if $self->{_next_hit_index} == -1;
my @hit_data = (@{$hit_table[$self->{_next_hit_index}++]}, $self->{_next_hit_index});
$self->_fields->{next_hit} = new Bio::Search::Hit::HmmpfamHit(-parent => $self,
-hit_data =>\@ hit_data);
if ($self->{_next_hit_index} > $#hit_table) {
$self->{_next_hit_index} = -1;
}} |
sub next_hit
{ my $self = shift;
my $hit = $self->get_field('next_hit');
undef $self->_fields->{next_hit};
return $hit;} |
sub hits
{ my $self = shift;
my $old = $self->{_next_hit_index} || 0;
$self->rewind;
my @hits;
while (defined(my $hit = $self->next_hit)) {
push(@hits, $hit);
}
$self->{_next_hit_index} = @hits > 0 ? $old : -1;
return @hits;} |
sub sort_hits
{ my ($self, $code_ref) = @_;
$code_ref ||= sub { $a->[3] <=> $b->[3] };
my $table_ref = $self->get_field('hit_table');
@{$table_ref} > 1 || return;
my @sorted = sort $code_ref @{$table_ref};
@sorted == @{$table_ref} || $self->throw("Your sort routine failed to give back all hits!");
$self->_fields->{hit_table} =\@ sorted;} |
sub rewind
{ my $self = shift;
unless ($self->_fields->{hit_table}) {
$self->get_field('hit_table');
}
$self->{_next_hit_index} = @{$self->_fields->{hit_table}} > 0 ? 0 : -1;} |
General documentation
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to
the Bioperl mailing list. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
Report bugs to the Bioperl bug tracking system to help us keep track
of the bugs and their resolution. Bug reports can be submitted via the
web:
http://bugzilla.open-bio.org/
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _
Title : next_model
Usage : my $domain = $result->next_model
Function: Returns the next domain - this is an alias for next_hit()
Returns : Bio::Search::Hit::HitI object
Args : none
Title : models
Usage : my @domains = $result->models;
Function: Returns the list of HMM models seen - this is an alias for hits()
Returns : Array of Bio::Search::Hit::HitI objects
Args : none