2 # BioPerl module Bio::Search::Hit::PullHitI
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Sendu Bala <bix@sendu.me.uk>
8 # You may distribute this module under the same terms as perl itself
10 # POD documentation - main docs before the code
14 Bio::Search::Hit::PullHitI - Bio::Search::Hit::HitI interface for pull parsers.
18 # This is an interface and cannot be instantiated
20 # typically one gets HitI objects from a SearchIO stream via a ResultI
22 my $parser = Bio::SearchIO->new(-format => 'hmmer_pull',
23 -file => 't/data/hmmpfam.out');
25 my $result = $parser->next_result;
26 my $hit = $result->next_hit;
28 $hit_name = $hit->name();
30 $desc = $hit->description();
34 $alg = $hit->algorithm();
36 $score = $hit->raw_score();
38 $significance = $hit->significance();
40 $rank = $hit->rank(); # the Nth hit for a specific query
42 while( $hsp = $obj->next_hsp()) { ... } # process in iterator fashion
44 for my $hsp ( $obj->hsps()()) { ... } # process in list fashion
48 This object handles the hit data from a database sequence search.
50 PullHitI is for fast implementations that only do parsing work on the hit
51 data when you actually request information by calling one of the HitI
54 Many methods of HitI are implemented in a way suitable for inheriting classes
55 that use Bio::PullParserI. It only really makes sense for PullHit modules to be
56 created by (and have as a -parent) PullResult modules.
58 In addition to the usual -chunk and -parent, -hit_data is all you should supply
59 when making a PullHit object. This will store that data and make it accessible
60 via _raw_hit_data, which you can access in your subclass. It would be best to
61 simply provide the data as the input -chunk instead, if the raw data is large
68 User feedback is an integral part of the evolution of this and other
69 Bioperl modules. Send your comments and suggestions preferably to one
70 of the Bioperl mailing lists. Your participation is much appreciated.
72 bioperl-l@bioperl.org - General discussion
73 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
77 Please direct usage questions or support issues to the mailing list:
79 I<bioperl-l@bioperl.org>
81 rather than to the module maintainer directly. Many experienced and
82 reponsive experts will be able look at the problem and quickly
83 address it. Please include a thorough description of the problem
84 with code and data examples if at all possible.
88 Report bugs to the Bioperl bug tracking system to help us keep track
89 the bugs and their resolution. Bug reports can be submitted via the
92 https://github.com/bioperl/bioperl-live/issues
94 =head1 AUTHOR - Sendu Bala
100 Copyright (c) 2006 Sendu Bala. All Rights Reserved.
104 This software is provided "as is" without warranty of any kind.
108 The rest of the documentation details each of the object
109 methods. Internal methods are usually preceded with a _
113 # Let the code begin...
115 package Bio
::Search
::Hit
::PullHitI
;
117 use Bio
::Search
::SearchUtils
;
121 use base
qw(Bio::PullParserI Bio::Search::Hit::HitI);
126 Usage : $self->_setup(@args)
127 Function: Implementers should call this to setup common fields and deal with
128 common arguments to new().
130 Args : @args received in new().
135 my ($self, @args) = @_;
137 # fields most subclasses probably will want
138 $self->_fields( { ( next_hsp
=> undef,
142 query_start
=> undef,
147 accession
=> undef ) } );
149 my ($parent, $chunk, $hit_data) = $self->_rearrange([qw(PARENT
152 $self->throw("Need -parent or -chunk to be defined") unless $parent || $chunk;
154 $self->parent($parent) if $parent;
157 my ($io, $start, $end) = (undef, 0, undef);
158 if (ref($chunk) eq 'ARRAY') {
159 ($io, $start, $end) = @
{$chunk};
164 $self->chunk($io, -start
=> $start, -end
=> $end);
167 $self->_raw_hit_data($hit_data) if $hit_data;
173 $self->{_raw_hit_data
} = shift;
175 return $self->{_raw_hit_data
};
179 # Some of these methods are written explitely to avoid HitI throwing not
180 # implemented; if it didn't do that then PullParserI AUTOLOAD would have
187 Usage : $hit_name = $hit->name();
188 Function: returns the name of the Hit sequence
189 Returns : a scalar string
192 The B<name> of a hit is unique within a Result or within an Iteration.
197 return shift->get_field('name');
203 Usage : $desc = $hit->description();
204 Function: Retrieve the description for the hit
205 Returns : a scalar string
211 return shift->get_field('description');
217 Usage : $acc = $hit->accession();
218 Function: Retrieve the accession (if available) for the hit
219 Returns : a scalar string (empty string if not set)
225 return shift->get_field('accession');
231 Usage : $acc = $hit->locus();
232 Function: Retrieve the locus(if available) for the hit
233 Returns : a scalar string (empty string if not set)
239 return shift->get_field('locus');
245 Usage : my $len = $hit->length
246 Function: Returns the length of the hit
253 return shift->get_field('length');
259 Usage : $alg = $hit->algorithm();
260 Function: Gets the algorithm specification that was used to obtain the hit
261 For BLAST, the algorithm denotes what type of sequence was aligned
262 against what (BLASTN: dna-dna, BLASTP prt-prt, BLASTX translated
263 dna-prt, TBLASTN prt-translated dna, TBLASTX translated
265 Returns : a scalar string
271 return shift->get_field('algorithm');
277 Usage : $score = $hit->raw_score();
278 Function: Gets the "raw score" generated by the algorithm. What
279 this score is exactly will vary from algorithm to algorithm,
280 returning undef if unavailable.
281 Returns : a scalar value
287 return shift->get_field('score');
292 Equivalent to L<raw_score()|raw_score>
297 return shift->get_field('score');
303 Usage : $significance = $hit->significance();
304 Function: Used to obtain the E or P value of a hit, i.e. the probability that
305 this particular hit was obtained purely by random chance. If
306 information is not available (nor calculatable from other
307 information sources), return undef.
308 Returns : a scalar value or undef if unavailable
314 return shift->get_field('significance');
319 Usage : $hit_object->bits();
320 Purpose : Gets the bit score of the best HSP for the current hit.
321 Example : $bits = $hit_object->bits();
322 Returns : Integer or double for FASTA reports
324 Comments : For BLAST1, the non-bit score is listed in the summary line.
326 See Also : L<score()|score>
331 return shift->get_field('bits');
337 Usage : while( $hsp = $obj->next_hsp()) { ... }
338 Function : Returns the next available High Scoring Pair
340 Returns : L<Bio::Search::HSP::HSPI> object or null if finished
346 return shift->get_field('next_hsp');
351 Usage : $hit_object->hsps();
352 Purpose : Get a list containing all HSP objects.
353 : Get the numbers of HSPs for the current hit.
354 Example : @hsps = $hit_object->hsps();
355 : $num = $hit_object->hsps(); # alternatively, use num_hsps()
356 Returns : Array context : list of L<Bio::Search::HSP::BlastHSP> objects.
357 : Scalar context: integer (number of HSPs).
358 : (Equivalent to num_hsps()).
359 Argument : n/a. Relies on wantarray
360 Throws : Exception if the HSPs have not been collected.
362 See Also : L<hsp()|hsp>, L<num_hsps()|num_hsps>
367 return shift->get_field('hsps');
372 Usage : $hit_object->num_hsps();
373 Purpose : Get the number of HSPs for the present Blast hit.
374 Example : $nhsps = $hit_object->num_hsps();
377 Throws : Exception if the HSPs have not been collected.
379 See Also : L<hsps()|hsps>
384 return shift->get_field('num_hsps');
388 # HitI/ GenericHit methods that are unrelated to simply parsing information
389 # directly out of a file, but need more complex calculation; mostly not
395 Usage : $hit->seq_inds( seq_type, class, collapse );
396 Purpose : Get a list of residue positions (indices) across all HSPs
397 : for identical or conserved residues in the query or sbjct sequence.
398 Example : @s_ind = $hit->seq_inds('query', 'identical');
399 : @h_ind = $hit->seq_inds('hit', 'conserved');
400 : @h_ind = $hit->seq_inds('hit', 'conserved', 1);
401 Returns : Array of integers
402 : May include ranges if collapse is non-zero.
403 Argument : [0] seq_type = 'query' or 'hit' or 'sbjct' (default = 'query')
404 : ('sbjct' is synonymous with 'hit')
405 : [1] class = 'identical' or 'conserved' or 'nomatch' or 'gap'
406 : (default = 'identical')
407 : (can be shortened to 'id' or 'cons')
408 : Note that 'conserved' includes identical unless you use
409 : 'conserved-not-identical'
410 : [2] collapse = boolean, if non-zero, consecutive positions are
411 : merged using a range notation, e.g.,
412 : "1 2 3 4 5 7 9 10 11" collapses to "1-5 7 9-11". This
413 : is useful for consolidating long lists. Default = no
417 See Also : L<Bio::Search::HSP::HSPI::seq_inds()|Bio::Search::HSP::HSPI>
422 my ($self, $seqType, $class, $collapse) = @_;
424 $seqType ||= 'query';
425 $class ||= 'identical';
428 $seqType = 'hit' if $seqType eq 'sbjct';
430 my $storage_name = '_seq_inds_'.$seqType.'_'.$class;
431 unless (defined $self->{$storage_name}) {
433 foreach my $hsp ($self->hsps) {
434 # This will merge data for all HSPs together.
435 push @inds, $hsp->seq_inds($seqType, $class);
438 # Need to remove duplicates and sort the merged positions, unless gaps.
439 if (@inds && $class ne 'gap') {
440 my %tmp = map { $_, 1 } @inds;
441 @inds = sort {$a <=> $b} keys %tmp;
444 $self->{$storage_name} = \
@inds;
447 my @inds = @
{$self->{$storage_name}};
448 $collapse ?
&Bio
::Search
::SearchUtils
::collapse_nums
(@inds) : @inds;
454 Usage : $hit->rewind;
455 Function: Allow one to reset the HSP iterator to the beginning if possible
462 shift->throw_not_implemented();
467 Usage : $hit_object->overlap( [integer] );
468 Purpose : Gets/Sets the allowable amount overlap between different HSP
470 Example : $hit_object->overlap(5);
471 : $overlap = $hit_object->overlap;
476 Comments : This value isn't used for anything
482 if (@_) { $self->{_overlap
} = shift }
483 return $self->{_overlap
} || 0;
488 Usage : $hit_object->n();
489 Purpose : Gets the N number for the current Blast hit.
490 : This is the number of HSPs in the set which was ascribed
491 : the lowest P-value (listed on the description line).
492 : This number is not the same as the total number of HSPs.
493 : To get the total number of HSPs, use num_hsps().
494 Example : $n = $hit_object->n();
497 Throws : Exception if HSPs have not been set (BLAST2 reports).
498 Comments : Note that the N parameter is not reported in gapped BLAST2.
499 : Calling n() on such reports will result in a call to num_hsps().
500 : The num_hsps() method will count the actual number of
501 : HSPs in the alignment listing, which may exceed N in
504 See Also : L<num_hsps()|num_hsps>
509 return shift->get_field('num_hsps');
514 Usage : $hit_object->p( [format] );
515 Purpose : Get the P-value for the best HSP of the given BLAST hit.
516 : (Note that P-values are not provided with NCBI Blast2 reports).
517 Example : $p = $sbjct->p;
518 : $p = $sbjct->p('exp'); # get exponent only.
519 : ($num, $exp) = $sbjct->p('parts'); # split sci notation into parts
520 Returns : Float or scientific notation number (the raw P-value, DEFAULT).
521 : Integer if format == 'exp' (the magnitude of the base 10 exponent).
522 : 2-element list (float, int) if format == 'parts' and P-value
523 : is in scientific notation (See Comments).
524 Argument : format: string of 'raw' | 'exp' | 'parts'
525 : 'raw' returns value given in report. Default. (1.2e-34)
526 : 'exp' returns exponent value only (34)
527 : 'parts' returns the decimal and exponent as a
528 : 2-element list (1.2, -34) (See Comments).
529 Throws : Warns if no P-value is defined. Uses expect instead.
530 Comments : Using the 'parts' argument is not recommended since it will not
531 : work as expected if the P-value is not in scientific notation.
532 : That is, floats are not converted into sci notation before
533 : splitting into parts.
535 See Also : L<expect()|expect>, L<signif()|signif>,
536 L<Bio::Search::BlastUtils::get_exponent()|Bio::Search::BlastUtils>
541 shift->throw_not_implemented;
546 Usage : $hit_object->hsp( [string] );
547 Purpose : Get a single HSPI object for the present HitI object.
548 Example : $hspObj = $hit_object->hsp; # same as 'best'
549 : $hspObj = $hit_object->hsp('best');
550 : $hspObj = $hit_object->hsp('worst');
551 Returns : Object reference for a L<Bio::Search::HSP::HSPI> object.
552 Argument : String (or no argument).
553 : No argument (default) = highest scoring HSP (same as 'best').
554 : 'best' = highest scoring HSP.
555 : 'worst' = lowest scoring HSP.
556 Throws : Exception if an unrecognized argument is used.
558 See Also : L<hsps()|hsps>, L<num_hsps>()
563 shift->throw_not_implemented;
566 =head2 logical_length
568 Usage : $hit_object->logical_length( [seq_type] );
569 : (mostly intended for internal use).
570 Purpose : Get the logical length of the hit sequence.
571 : If the Blast is a TBLASTN or TBLASTX, the returned length
572 : is the length of the would-be amino acid sequence (length/3).
573 : For all other BLAST flavors, this function is the same as length().
574 Example : $len = $hit_object->logical_length();
576 Argument : seq_type = 'query' or 'hit' or 'sbjct' (default = 'query')
577 ('sbjct' is synonymous with 'hit')
579 Comments : This is important for functions like frac_aligned_query()
580 : which need to operate in amino acid coordinate space when dealing
581 : with [T]BLAST[NX] type reports.
583 See Also : L<length()|length>, L<frac_aligned_query()|frac_aligned_query>,
584 L<frac_aligned_hit()|frac_aligned_hit>
589 my ($self, $type) = @_;
592 $type = 'hit' if $type eq 'sbjct';
593 if ($type eq 'query') {
594 return $self->get_field('query_length');
596 elsif ($type eq 'hit') {
597 return $self->get_field('length');
604 Usage : $obj->rank($newval)
605 Function: Get/Set the rank of this Hit in the Query search list
606 i.e. this is the Nth hit for a specific query
607 Returns : value of rank
608 Args : newvalue (optional)
613 return shift->get_field('rank');
616 =head2 each_accession_number
618 Title : each_accession_number
619 Usage : $obj->each_accession_number
620 Function: Get each accession number listed in the description of the hit.
621 If there are no alternatives, then only the primary accession will
622 be given (if there is one).
623 Returns : list of all accession numbers in the description
628 sub each_accession_number
{
630 my $accession = $self->get_field('accession') if $self->has_field('accession');
631 my $desc = $self->get_field('description') if $self->has_field('description');
632 return unless $accession || $desc;
635 push (@accnums, $accession) if $accession;
638 while ($desc =~ /(\b\S+\|\S*\|\S*\s?)/g) {
641 if ($id =~ /(?:gb|emb|dbj|sp|pdb|bbs|ref|tp[gde])\|(.*)\|(?:.*)/) {
642 ($acc) = split /\./, $1;
644 elsif ($id =~ /(?:pir|prf|pat|gnl)\|(?:.*)\|(.*)/) {
645 ($acc) = split /\./, $1;
647 elsif ($id =~ /(?:gim|gi|bbm|bbs|lcl)\|(?:\d*)/) {
650 elsif ($id =~ /(?:oth)\|(.*)\|(?:.*)\|(?:.*)/ ) { # discontinued...
656 push(@accnums, $acc);
664 Usage : $hit_object->tiled_hsps( [integer] );
665 Purpose : Gets/Sets an indicator for whether or not the HSPs in this Hit
667 Example : $hit_object->tiled_hsps(1);
668 : if( $hit_object->tiled_hsps ) { # do something }
669 Returns : Boolean (1 or 0)
670 Argument : integer (optional)
673 Notes : This value is not used for anything
679 if (@_) { $self->{_hsps_are_tiled
} = shift }
680 return $self->{_hsps_are_tiled
} || 0;
685 Usage : $sbjct->strand( [seq_type] );
686 Purpose : Gets the strand(s) for the query, sbjct, or both sequences
687 : in the best HSP of the BlastHit object after HSP tiling.
688 : Only valid for BLASTN, TBLASTX, BLASTX-query, TBLASTN-hit.
689 Example : $qstrand = $sbjct->strand('query');
690 : $sstrand = $sbjct->strand('hit');
691 : ($qstrand, $sstrand) = $sbjct->strand();
692 Returns : scalar context: integer '1', '-1', or '0'
693 : array context without args: list of two strings (queryStrand, sbjctStrand)
694 : Array context can be "induced" by providing an argument of 'list' or 'array'.
695 Argument : In scalar context: seq_type = 'query' or 'hit' or 'sbjct' (default = 'query')
696 ('sbjct' is synonymous with 'hit')
698 Comments : This method requires that all HSPs be tiled. If they have not
699 : already been tiled, they will be tiled first automatically..
700 : If you don't want the tiled data, iterate through each HSP
701 : calling strand() on each (use hsps() to get all HSPs).
703 : Formerly (prior to 10/21/02), this method would return the
704 : string "-1/1" for hits with HSPs on both strands.
705 : However, now that strand and frame is properly being accounted
706 : for during HSP tiling, it makes more sense for strand()
707 : to return the strand data for the best HSP after tiling.
709 : If you really want to know about hits on opposite strands,
710 : you should be iterating through the HSPs using methods on the
713 : A possible use case where knowing whether a hit has HSPs
714 : on both strands would be when filtering via SearchIO for hits with
715 : this property. However, in this case it would be better to have a
716 : dedicated method such as $hit->hsps_on_both_strands(). Similarly
717 : for frame. This could be provided if there is interest.
719 See Also : L<Bio::Search::HSP::HSPI::strand>()
724 shift->throw_not_implemented;
729 Usage : $hit_object->frame();
730 Purpose : Gets the reading frame for the best HSP after HSP tiling.
731 : This is only valid for BLASTX and TBLASTN/X type reports.
732 Example : $frame = $hit_object->frame();
733 Returns : Integer (-2 .. +2)
735 Throws : Exception if HSPs have not been set.
736 Comments : This method requires that all HSPs be tiled. If they have not
737 : already been tiled, they will be tiled first automatically..
738 : If you don't want the tiled data, iterate through each HSP
739 : calling frame() on each (use hsps() to get all HSPs).
741 See Also : L<hsps()|hsps>
746 shift->throw_not_implemented;
751 Usage : $hit_object->length_aln( [seq_type] );
752 Purpose : Get the total length of the aligned region for query or sbjct seq.
753 : This number will include all HSPs, and excludes gaps.
754 Example : $len = $hit_object->length_aln(); # default = query
755 : $lenAln = $hit_object->length_aln('query');
757 Argument : seq_Type = 'query' or 'hit' or 'sbjct' (Default = 'query')
758 ('sbjct' is synonymous with 'hit')
759 Throws : Exception if the argument is not recognized.
760 Comments : This method will report the logical length of the alignment,
761 : meaning that for TBLAST[NX] reports, the length is reported
762 : using amino acid coordinate space (i.e., nucleotides / 3).
764 See Also : L<length()|length>, L<frac_aligned_query()|frac_aligned_query>,
765 L<frac_aligned_hit()|frac_aligned_hit>, L<gaps()|gaps>,
766 L<Bio::Search::SearchUtils::tile_hsps()|Bio::Search::SearchUtils>,
767 L<Bio::Search::HSP::BlastHSP::length()|Bio::Search::HSP::BlastHSP>
772 my ($self, $seqType) = @_;
773 $seqType ||= 'query';
774 $seqType = 'hit' if $seqType eq 'sbjct';
776 my %non_gaps = map { $_, 1 } $self->seq_inds($seqType, 'conserved'),
777 $self->seq_inds($seqType, 'no_match');
778 return scalar(keys %non_gaps);
783 Usage : $hit_object->gaps( [seq_type] );
784 Purpose : Get the number of gaps in the aligned query, hit, or both sequences.
785 : Data is summed across all HSPs.
786 Example : $qgaps = $hit_object->gaps('query');
787 : $hgaps = $hit_object->gaps('hit');
788 : $tgaps = $hit_object->gaps(); # default = total (query + hit)
789 Returns : scalar context: integer
790 : array context without args: two-element list of integers
791 : (queryGaps, hitGaps)
792 : Array context can be forced by providing an argument of 'list' or
795 : CAUTION: Calling this method within printf or sprintf is arrray
797 : So this function may not give you what you expect. For example:
798 : printf "Total gaps: %d", $hit->gaps();
799 : Actually returns a two-element array, so what gets printed
800 : is the number of gaps in the query, not the total
802 Argument : seq_type: 'query' | 'hit' or 'sbjct' | 'total' | 'list'
803 : (default = 'total') ('sbjct' is synonymous with 'hit')
804 Comments : If you need data for each HSP, use hsps() and then interate
805 : through each HSP object.
810 my ($self, $seqType) = @_;
812 $seqType ||= (wantarray ?
'list' : 'total');
813 $seqType = 'hit' if $seqType eq 'sbjct';
815 if ($seqType =~ /list|array/i) {
816 return (scalar($self->seq_inds('query', 'gap')), scalar($self->seq_inds('hit', 'gap')));
818 elsif ($seqType eq 'total') {
819 return (scalar($self->seq_inds('query', 'gap')) + scalar($self->seq_inds('hit', 'gap'))) || 0;
822 return scalar($self->seq_inds($seqType, 'gap')) || 0;
828 Usage : $hit_object->matches( [class] );
829 Purpose : Get the total number of identical or conserved matches
830 : (or both) across all HSPs.
831 : (Note: 'conservative' matches are indicated as 'positives'
833 Example : ($id,$cons) = $hit_object->matches(); # no argument
834 : $id = $hit_object->matches('id');
835 : $cons = $hit_object->matches('cons');
836 Returns : Integer or a 2-element array of integers
837 Argument : [0] class = 'id' | 'cons' OR none.
838 : [1] seq_type = 'query' or 'hit' or 'sbjct' (default = 'query')
839 : ('sbjct' is synonymous with 'hit')
840 : If no argument is provided, both identical and conservative
841 : numbers are returned in a two element list.
842 : (Other terms can be used to refer to the conservative
843 : matches, e.g., 'positive'. All that is checked is whether or
844 : not the supplied string starts with 'id'. If not, the
845 : conservative matches are returned.)
850 my ($self, $class, $seqType) = @_;
852 # no query/hit choice? The answer differs depending on sequence, since
853 # hsps could overlap on one sequence and not the other. Added an option,
854 # but otherwise will assume 'hit'
856 $seqType = 'hit' if $seqType eq 'sbjct';
858 unless (exists $self->{_id_matches
}) {
859 $self->{_id_matches
}->{hit
} = scalar($self->seq_inds('hit', 'identical'));
860 $self->{_id_matches
}->{query
} = scalar($self->seq_inds('query', 'identical'));
862 unless (exists $self->{_con_matches
}) {
863 foreach my $type ('hit', 'query') {
864 # 'conserved-not-identical' can give us 'identical' matches if hsps
865 # overlapped so have to get the difference
866 my %identicals = map { $_ => 1 } $self->seq_inds($type, 'identical');
867 my @conserved = $self->seq_inds($type, 'conserved-not-identical');
870 foreach (@conserved) {
871 unless (exists $identicals{$_}) {
875 $self->{_con_matches
}->{$type} = $real_conserved;
881 return ($self->{_id_matches
}->{$seqType}, $self->{_con_matches
}->{$seqType});
884 if ($class =~ /^id/i) {
885 return $self->{_id_matches
}->{$seqType};
888 return $self->{_con_matches
}->{$seqType};
896 Usage : $sbjct->start( [seq_type] );
897 Purpose : Gets the start coordinate for the query, sbjct, or both sequences
898 : in the object. If there is more than one HSP, the lowest start
899 : value of all HSPs is returned.
900 Example : $qbeg = $sbjct->start('query');
901 : $sbeg = $sbjct->start('hit');
902 : ($qbeg, $sbeg) = $sbjct->start();
903 Returns : scalar context: integer
904 : array context without args: list of two integers (queryStart,
906 : Array context can be "induced" by providing an argument of 'list'
908 Argument : 'query' or 'hit' or 'sbjct' (default = 'query') ('sbjct' is
909 synonymous with 'hit')
914 my ($self, $seqType) = @_;
916 unless ($self->get_field('num_hsps')) {
917 Bio
::Search
::SearchUtils
::_warn_about_no_hsps
($self);
921 $seqType ||= (wantarray ?
'list' : 'query');
922 $seqType = 'hit' if $seqType eq 'sbjct';
924 if ($seqType =~ /list|array/i) {
925 return ($self->get_field('query_start'), $self->get_field('hit_start'));
927 elsif ($seqType eq 'hit') {
928 return $self->get_field('hit_start');
930 elsif ($seqType eq 'query') {
931 return $self->get_field('query_start');
934 $self->throw("Unknown sequence type '$seqType'");
940 Usage : $sbjct->end( [seq_type] );
941 Purpose : Gets the end coordinate for the query, sbjct, or both sequences
942 : in the object. If there is more than one HSP, the largest end
943 : value of all HSPs is returned.
944 Example : $qend = $sbjct->end('query');
945 : $send = $sbjct->end('hit');
946 : ($qend, $send) = $sbjct->end();
947 Returns : scalar context: integer
948 : array context without args: list of two integers
949 : (queryEnd, sbjctEnd)
950 : Array context can be "induced" by providing an argument
951 : of 'list' or 'array'.
952 Argument : 'query' or 'hit' or 'sbjct' (default = 'query') ('sbjct' is
953 synonymous with 'hit')
958 my ($self, $seqType) = @_;
960 unless ($self->get_field('num_hsps')) {
961 Bio
::Search
::SearchUtils
::_warn_about_no_hsps
($self);
965 $seqType ||= (wantarray ?
'list' : 'query');
966 $seqType = 'hit' if $seqType eq 'sbjct';
968 if ($seqType =~ /list|array/i) {
969 return ($self->get_field('query_end'), $self->get_field('hit_end'));
971 elsif ($seqType eq 'hit') {
972 return $self->get_field('hit_end');
974 elsif ($seqType eq 'query') {
975 return $self->get_field('query_end');
978 $self->throw("Unknown sequence type '$seqType'");
984 Usage : $sbjct->range( [seq_type] );
985 Purpose : Gets the (start, end) coordinates for the query or sbjct sequence
986 : in the HSP alignment.
987 Example : ($qbeg, $qend) = $sbjct->range('query');
988 : ($sbeg, $send) = $sbjct->range('hit');
989 Returns : Two-element array of integers
990 Argument : seq_type = string, 'query' or 'hit' or 'sbjct' (default = 'query')
991 ('sbjct' is synonymous with 'hit')
994 See Also : L<start()|start>, L<end()|end>
999 my ($self, $seqType) = @_;
1000 $seqType ||= 'query';
1001 $seqType = 'hit' if $seqType eq 'sbjct';
1002 return ($self->start($seqType), $self->end($seqType));
1005 =head2 frac_identical
1007 Usage : $hit_object->frac_identical( [seq_type] );
1008 Purpose : Get the overall fraction of identical positions across all HSPs.
1009 : The number refers to only the aligned regions and does not
1010 : account for unaligned regions in between the HSPs, if any.
1011 Example : $frac_iden = $hit_object->frac_identical('query');
1012 Returns : Float (2-decimal precision, e.g., 0.75).
1013 Argument : seq_type: 'query' | 'hit' or 'sbjct' | 'total'
1014 : default = 'query' (but see comments below).
1015 : ('sbjct' is synonymous with 'hit')
1019 sub frac_identical
{
1020 my ($self, $seqType) = @_;
1021 $seqType ||= 'query';
1022 $seqType = lc($seqType);
1023 $seqType = 'hit' if $seqType eq 'sbjct';
1025 my $ident = $self->matches('id', $seqType);
1026 my $total = $self->length_aln($seqType);
1027 my $ratio = $ident / $total;
1028 my $ratio_rounded = sprintf( "%.3f", $ratio);
1030 # Round down if normal rounding yields 1 (just like blast)
1031 $ratio_rounded = 0.999 if (($ratio_rounded == 1) && ($ratio < 1));
1032 return $ratio_rounded;
1035 =head2 frac_conserved
1037 Usage : $hit_object->frac_conserved( [seq_type] );
1038 Purpose : Get the overall fraction of conserved positions across all HSPs.
1039 : The number refers to only the aligned regions and does not
1040 : account for unaligned regions in between the HSPs, if any.
1041 Example : $frac_cons = $hit_object->frac_conserved('hit');
1042 Returns : Float (2-decimal precision, e.g., 0.75).
1043 Argument : seq_type: 'query' | 'hit' or 'sbjct' | 'total'
1044 : default = 'query' (but see comments below).
1045 : ('sbjct' is synonymous with 'hit')
1049 sub frac_conserved
{
1050 my ($self, $seqType) = @_;
1051 $seqType ||= 'query';
1052 $seqType = lc($seqType);
1053 $seqType = 'hit' if $seqType eq 'sbjct';
1055 my $consv = $self->matches('cons');
1056 my $total = $self->length_aln($seqType);
1057 my $ratio = $consv / $total;
1058 my $ratio_rounded = sprintf( "%.3f", $ratio);
1060 # Round down iff normal rounding yields 1 (just like blast)
1061 $ratio_rounded = 0.999 if (($ratio_rounded == 1) && ($ratio < 1));
1062 return $ratio_rounded;
1065 =head2 frac_aligned_query
1067 Usage : $hit_object->frac_aligned_query();
1068 Purpose : Get the fraction of the query sequence which has been aligned
1069 : across all HSPs (not including intervals between non-overlapping
1071 Example : $frac_alnq = $hit_object->frac_aligned_query();
1072 Returns : Float (2-decimal precision, e.g., 0.75).
1074 Comments : If you need data for each HSP, use hsps() and then interate
1075 : through the HSP objects.
1079 sub frac_aligned_query
{
1081 return sprintf("%.2f", $self->length_aln('query') / $self->logical_length('query'));
1084 =head2 frac_aligned_hit
1086 Usage : $hit_object->frac_aligned_hit();
1087 Purpose : Get the fraction of the hit (sbjct) sequence which has been aligned
1088 : across all HSPs (not including intervals between non-overlapping
1090 Example : $frac_alnq = $hit_object->frac_aligned_hit();
1091 Returns : Float (2-decimal precision, e.g., 0.75).
1093 Comments : If you need data for each HSP, use hsps() and then interate
1094 : through the HSP objects.
1098 sub frac_aligned_hit
{
1100 return sprintf( "%.2f", $self->length_aln('sbjct') / $self->logical_length('sbjct'));
1103 =head2 num_unaligned_hit
1105 Usage : $hit_object->num_unaligned_hit();
1106 Purpose : Get the number of the unaligned residues in the hit sequence.
1107 : Sums across all all HSPs.
1108 Example : $num_unaln = $hit_object->num_unaligned_hit();
1111 Comments : If you need data for each HSP, use hsps() and then interate
1112 : through the HSP objects.
1116 sub num_unaligned_hit
{
1118 # why does this method even exist?!
1119 return $self->gaps('hit');
1122 =head2 num_unaligned_query
1124 Usage : $hit_object->num_unaligned_query();
1125 Purpose : Get the number of the unaligned residues in the query sequence.
1126 : Sums across all all HSPs.
1127 Example : $num_unaln = $hit_object->num_unaligned_query();
1130 Comments : If you need data for each HSP, use hsps() and then interate
1131 : through the HSP objects.
1135 sub num_unaligned_query
{
1137 # why does this method even exist?!
1138 return $self->gaps('query');
1141 # aliasing for Steve's method names
1142 *hit_description
= \
&description
;
1143 *hit_length
= \
&length;