Bio::Search::Result HmmpfamResult
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Toolbar
WebCvs
Summary
Bio::Search::Result::HmmpfamResult - A parser and result object for hmmpfam
results
Package variables
No package variables defined.
Included modules
Bio::Search::Hit::HmmpfamHit
Inherit
Bio::Root::Root Bio::Search::Result::PullResultI
Synopsis
    # generally we use Bio::SearchIO to build these objects
use Bio::SearchIO;
my $in = Bio::SearchIO->new(-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
newDescriptionCode
_discover_header
No description
Code
_discover_hit_table
No description
Code
_discover_hsp_table
No description
Code
_discover_alignments
No description
Code
_next_alignment
No description
Code
_discover_next_hit
No description
Code
next_hitDescriptionCode
hitsDescriptionCode
sort_hitsDescriptionCode
rewindDescriptionCode
Methods description
newcode    nextTop
 Title   : new
Usage : my $obj = Bio::SearchIO::Result::hmmpfam->new();
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)
next_hitcodeprevnextTop
 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
hitscodeprevnextTop
 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
sort_hitscodeprevnextTop
 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]);
rewindcodeprevnextTop
 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
newdescriptionprevnextTop
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;
}

#
# PullParserI discovery methods so we can answer all ResultI questions
#
}
_discover_headerdescriptionprevnextTop
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; # stop this method being called again
}
_discover_hit_tabledescriptionprevnextTop
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); # consistency for tests under Windows
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;
}
_discover_hsp_tabledescriptionprevnextTop
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"); # A0 reports
$self->{_after_hsp_table} = $self->_chunk_tell; my %table; # can't save this regex work for the hsp object because the hit object needs
# its length, so may as well just do all the work here
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) { # rank query_start query_end hit_start hit_end score evalue
my $evalue = abs($9); # consistency for tests under Windows
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;
}
_discover_alignmentsdescriptionprevnextTop
sub _discover_alignments {
	my $self = shift;
	$self->_fields->{alignments} = { };
}
_next_alignmentdescriptionprevnextTop
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;
		return $self->_next_alignment;
	}
	
	$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;
}
_discover_next_hitdescriptionprevnextTop
sub _discover_next_hit {
	my $self = shift;
	my @hit_table = @{$self->get_field('hit_table')};
	return if $self->{_next_hit_index} == -1;
	
	#[name description score significance num_hsps rank]
my @hit_data = (@{$hit_table[$self->{_next_hit_index}++]}, $self->{_next_hit_index}); $self->_fields->{next_hit} = Bio::Search::Hit::HmmpfamHit->new(-parent => $self, -hit_data =>\@ hit_data); if ($self->{_next_hit_index} > $#hit_table) { $self->{_next_hit_index} = -1; }
}
next_hitdescriptionprevnextTop
sub next_hit {
	my $self = shift;
    my $hit = $self->get_field('next_hit');
	undef $self->_fields->{next_hit};
	return $hit;
}
hitsdescriptionprevnextTop
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;
}
sort_hitsdescriptionprevnextTop
sub sort_hits {
    my ($self, $code_ref) = @_;
	$code_ref ||= sub { $a->[3] <=> $b->[3] };
	
	# avoid creating hit objects just to sort, hence force user to sort on
# the array references in hit table
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;
}
rewinddescriptionprevnextTop
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;
}

1;
}
General documentation
FEEDBACKTop
Mailing ListsTop
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
Support Top
Please direct usage questions or support issues to the mailing list:
bioperl-l@bioperl.org
rather than to the module maintainer directly. Many experienced and
reponsive experts will be able look at the problem and quickly
address it. Please include a thorough description of the problem
with code and data examples if at all possible.
Reporting BugsTop
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:
  https://redmine.open-bio.org/projects/bioperl/
AUTHOR - Sendu BalaTop
Email bix@sendu.me.uk
APPENDIXTop
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _
next_modelTop
 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
modelsTop
 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