=cut
#--------
sub p {
#--------
# Some duplication of logic for p(), expect() and signif() for the sake of performance.
my ($self, $fmt) = @_;
my ($val);
$fmt ||= $_signif_fmt;
# $val can be zero.
if(not defined($val = $self->{'_p'})) {
## P-value not defined, must be a NCBI Blast2 report.
my $note = '';
if($self->parent->_layout() == 2) {
$note = "Blast2 does not report P-values. Use expect() instead.";
}
$self->throw("Can't get P-value: undefined.", $note);
}
return $val if not $fmt or $fmt =~ /^raw/i;
## Special formats: exponent-only or as list.
return &get_exponent($val) if $fmt =~ /^exp/i;
return (split (/eE/, $val)) if $fmt =~ /^parts/i;
## Default: return the raw P-value.
return $val;
}
=head2 expect
Usage : $sbjct_object->expect( [format] );
Purpose : Get the Expect value for the given BLAST hit.
Example : $e = $sbjct->expect;
: $e = $sbjct->expect('exp'); # get exponent only.
: ($num, $exp) = $sbjct->expect('parts'); # split sci notation into parts
Returns : Float or scientific notation number (the raw expect value, DEFAULT).
: Integer if format == 'exp' (the magnitude of the base 10 exponent).
: 2-element list (float, int) if format == 'parts' and Expect
: is in scientific notation (see Comments).
Argument : format: string of 'raw' | 'exp' | 'parts'
: 'raw' returns value given in report. Default. (1.2e-34)
: 'exp' returns exponent value only (34)
: 'parts' returns the decimal and exponent as a
: 2-element list (1.2, -34) (see Comments).
Throws : Exception if the Expect value is not defined.
Comments : Using the 'parts' argument is not recommended since it will not
: work as expected if the expect value is not in scientific notation.
: That is, floats are not converted into sci notation before
: splitting into parts.
See Also : L, L, L
=cut
#-----------
sub expect {
#-----------
# Some duplication of logic for p(), expect() and signif() for the sake of performance.
my ($self, $fmt) = @_;
my $val = $self->{'_expect'};
$fmt ||= $_signif_fmt;
# $val can be zero.
defined($val) or $self->throw("Can't get Expect value: HSPs may not have been set.");
return $val if not $fmt or $fmt =~ /^raw/i;
## Special formats: exponent-only or as list.
return &get_exponent($val) if $fmt =~ /^exp/i;
return (split (/eE/, $val)) if $fmt =~ /^parts/i;
## Default: return the raw Expect-value.
return $val;
}
=head2 signif
Usage : $sbjct_object->signif( [format] );
Purpose : Get the P or Expect value for the given BLAST hit.
: The value returned is the one which is reported in the description
: section of the Blast report. For Blast1 and WU-Blast2, this
: is a P-value, for Blast2, it is an Expect value.
Example : $obj->signif() # returns 1.3e-34
: $obj->signif('exp') # returns -34
: $obj->signif('parts') # returns (1.3, -34)
Returns : Float or scientific notation number (the raw P/Expect value, DEFAULT).
: Integer if format == 'exp' (the magnitude of the base 10 exponent).
: 2-element list (float, int) if format == 'parts' and P/Expect value
: is in scientific notation (see Comments).
Argument : format: string of 'raw' | 'exp' | 'parts'
: 'raw' returns value given in report. Default. (1.2e-34)
: 'exp' returns exponent value only (34)
: 'parts' returns the decimal and exponent as a
: 2-element list (1.2, -34) (see Comments).
Throws : n/a
Status : Deprecated. Use p() or expect().
Comments : The signif() method provides a way to deal with the fact that
: Blast1 and Blast2 formats differ in what is reported in the
: description lines of each hit in the Blast report. The signif()
: method frees any client code from having to know if this is a P-value
: or an Expect value, making it easier to write code that can process
: both Blast1 and Blast2 reports. This is not necessarily a good thing, since
: one should always know when one is working with P-values or
: Expect values (hence the deprecated status).
: Use of expect() is recommended since all hits will have an Expect value.
:
: Using the 'parts' argument is not recommended since it will not
: work as expected if the expect value is not in scientific notation.
: That is, floats are not converted into sci notation before
: splitting into parts.
See Also : L, L, L
=cut
#-------------
sub signif {
#-------------
# Some duplication of logic for p(), expect() and signif() for the sake of performance.
my ($self, $fmt) = @_;
my $val = defined($self->{'_p'}) ? $self->{'_p'} : $self->{'_expect'};
$fmt ||= $_signif_fmt;
# $val can be zero.
defined($val) or $self->throw("Can't get P- or Expect value: HSPs may not have been set.");
return $val if not $fmt or $fmt =~ /^raw/i;
## Special formats: exponent-only or as list.
return &get_exponent($val) if $fmt =~ /^exp/i;
return (split (/eE/, $val)) if $fmt =~ /^parts/i;
## Default: return the raw P/Expect-value.
return $val;
}
=head2 desc
Usage : $sbjct_object->desc( [integer] );
Purpose : Get the description for the given BLAST hit.
Example : (see usage)
Returns : String
Argument : Integer (optional) indicating the desired length of the
: description string to be returned.
Throws : n/a
See Also : L<_set_desc()|_set_desc>
=cut
#---------
sub desc {
#---------
my( $self, $len ) = @_;
$len = (defined $len) ? $len : (CORE::length $self->{'_desc'});
substr( $self->{'_desc'}, 0 ,$len );
}
=head2 database
Usage : $sbjct_object->database();
Purpose : Get the name of the database for the hit sequence.
Example : (see usage)
Returns : String
Argument : n/a
Throws : n/a
Status : Deprecated. Use Bio::Tools::Blast::database()
Extracting database name from the seq identifier is error prone.
Comments : Database id should be the same for all hits in a given
: BLAST report, however, they do not always have the same
: name as the database name extraced by the Blast.pm object.
: The Sbjct.pm database id is obtained from the summary line.
=cut
#--------------
sub database {
my $self = shift;
$self->warn("Bio::Tools::Sbjct::database() is deprecated.\nNo useful information is provided by this method.\nUse Bio::Tools::Blast::database().\n");
return $self->{'_db'};
}
#--------------
=head2 hsps
Usage : $sbjct_object->hsps();
Purpose : Get a list containing all HSP objects.
: Get the numbers of HSPs for the current hit.
Example : @hsps = $sbjct_object->hsps();
: $num = $sbjct_object->hsps(); # alternatively, use num_hsps()
Returns : Array context : list of Bio::Tools::Blast::HSP.pm objects.
: Scalar context: integer (number of HSPs).
: (Equivalent to num_hsps()).
Argument : n/a. Relies on wantarray
Throws : Exception if the HSPs have not been collected.
See Also : L, L, L<_set_hsps()|_set_hsps>
=cut
#---------
sub hsps {
#---------
my $self = shift;
if (not ref $self->{'_hsps'}) {
$self->throw("Can't get HSPs: data not collected.");
}
return wantarray
# returning list containing all HSPs.
? @{$self->{'_hsps'}}
# returning number of HSPs.
: scalar(@{$self->{'_hsps'}});
}
=head2 hsp
Usage : $sbjct_object->hsp( [string] );
Purpose : Get a single HSP.pm object for the present Sbjct.pm object.
Example : $hspObj = $sbjct_object->hsp; # same as 'best'
: $hspObj = $sbjct_object->hsp('best');
: $hspObj = $sbjct_object->hsp('worst');
Returns : Object reference for a Bio::Tools::Blast::HSP.pm object.
Argument : String (or no argument).
: No argument (default) = highest scoring HSP (same as 'best').
: 'best' or 'first' = highest scoring HSP.
: 'worst' or 'last' = lowest scoring HSP.
Throws : Exception if the HSPs have not been collected.
: Exception if an unrecognized argument is used.
See Also : L, L, L<_set_hsps()|_set_hsps>
=cut
#----------
sub hsp {
#----------
my( $self, $option ) = @_;
$option ||= 'best';
if (not ref $self->{'_hsps'}) {
$self->throw("Can't get HSPs: data not collected.");
}
my @hsps = @{$self->{'_hsps'}};
return $hsps[0] if $option =~ /best|first|1/i;
return $hsps[$#hsps] if $option =~ /worst|last/i;
$self->throw("Can't get HSP for: $option",
"Valid arguments: 'best', 'worst'");
}
=head2 num_hsps
Usage : $sbjct_object->num_hsps();
Purpose : Get the number of HSPs for the present Blast hit.
Example : $nhsps = $sbjct_object->num_hsps();
Returns : Integer
Argument : n/a
Throws : Exception if the HSPs have not been collected.
See Also : L
=cut
#-------------
sub num_hsps {
#-------------
my $self = shift;
if (not defined $self->{'_hsps'}) {
$self->throw("Can't get HSPs: data not collected.");
}
return scalar(@{$self->{'_hsps'}});
}
=head2 length
Usage : $sbjct_object->length();
Purpose : Get the total length of the hit sequence.
Example : $len = $sbjct_object->length();
Returns : Integer
Argument : n/a
Throws : n/a
Comments : Developer note: when using the built-in length function within
: this module, call it as CORE::length().
See Also : L, L
=cut
#-----------
sub length {
#-----------
my $self = shift;
$self->{'_length'};
}
=head2 logical_length
Usage : $sbjct_object->logical_length( [seq_type] );
: (mostly intended for internal use).
Purpose : Get the logical length of the hit sequence.
: If the Blast is a TBLASTN or TBLASTX, the returned length
: is the length of the would-be amino acid sequence (length/3).
: For all other BLAST flavors, this function is the same as length().
Example : $len = $sbjct_object->logical_length();
Returns : Integer
Argument : seq_type = 'query' or 'sbjct' (default = 'query')
Throws : n/a
Comments : This is important for functions like frac_aligned_query()
: which need to operate in amino acid coordinate space when dealing
: with [T]BLAST[NX] type reports.
See Also : L, L, L
=cut
#--------------------
sub logical_length {
#--------------------
my $self = shift;
my $seqType = shift || 'query';
# Return logical sbjct length
$seqType eq 'sbjct' and return
$self->{'_logical_length'} || $self->{'_length'};
# Otherwise, return logical query length
my $qlen = $self->parent->length;
# Adjust length based on BLAST flavor.
my $prog = $self->parent->program;
if($prog =~ /T?BLASTX/ ) {
$qlen /= 3;
}
return $qlen;
}
=head2 length_aln
Usage : $sbjct_object->length_aln( [seq_type] );
Purpose : Get the total length of the aligned region for query or sbjct seq.
: This number will include all HSPs
Example : $len = $sbjct_object->length_aln(); # default = query
: $lenAln = $sbjct_object->length_aln('query');
Returns : Integer
Argument : seq_Type = 'query' | 'sbjct' (Default = 'query')
Throws : Exception if the argument is not recognized.
Comments : This method will report the logical length of the alignment,
: meaning that for TBLAST[NX] reports, the length is reported
: using amino acid coordinate space (i.e., nucleotides / 3).
:
: This method requires that all HSPs be tiled. If they have not
: already been tiled, they will be tiled first.
: If you don't want the tiled data, iterate through each HSP
: calling length() on each (use hsps() to get the HSPs).
See Also : L, L, L, L, L<_tile_hsps()|_tile_hsps>, B
=cut
#---------------'
sub length_aln {
#---------------
my( $self, $type ) = @_;
$type ||= 'query';
$self->_tile_hsps() if not $self->{'_tile_hsps'};
my $data = $self->{'_length_aln_'.$type};
## If we don't have data, figure out what went wrong.
if(!$data) {
$self->throw("Can't get length aln for sequence type \"$type\"",
"Valid types are 'query', 'sbjct'");
}
$data;
}
=head2 gaps
Usage : $sbjct_object->gaps( [seq_type] );
Purpose : Get the number of gaps in the aligned query, sbjct, or both sequences.
: Data is summed across all HSPs.
Example : $qgaps = $sbjct_object->gaps('query');
: $sgaps = $sbjct_object->gaps('sbjct');
: $tgaps = $sbjct_object->gaps(); # default = total (query + sbjct)
Returns : scalar context: integer
: array context without args: two-element list of integers
: (queryGaps, sbjctGaps)
: Array context can be "induced" by providing an argument of 'list' or 'array'.
Argument : seq_type: 'query' | 'sbjct' | 'total' | 'list' (default = 'total')
Throws : n/a
Comments : If you need data for each HSP, use hsps() and then interate
: through each HSP object.
: This method requires that all HSPs be tiled. If they have not
: already been tiled, they will be tiled first.
: Not relying on wantarray since that will fail in situations
: such as printf "%d", $hit->gaps() in which you might expect to
: be printing the total gaps, but evaluates to array context.
See Also : L
=cut
#----------
sub gaps {
#----------
my( $self, $seqType ) = @_;
$seqType ||= (wantarray ? 'list' : 'total');
$self->_tile_hsps() if not $self->{'_tile_hsps'};
$seqType = lc($seqType);
if($seqType =~ /list|array/i) {
return ($self->{'_gaps_query'}, $self->{'_gaps_sbjct'});
}
if($seqType eq 'total') {
return ($self->{'_gaps_query'} + $self->{'_gaps_sbjct'}) || 0;
} else {
return $self->{'_gaps_'.$seqType} || 0;
}
}
=head2 matches
Usage : $sbjct_object->matches( [class] );
Purpose : Get the total number of identical or conserved matches
: (or both) across all HSPs.
: (Note: 'conservative' matches are indicated as 'positives'
: in the Blast report.)
Example : ($id,$cons) = $sbjct_object->matches(); # no argument
: $id = $sbjct_object->matches('id');
: $cons = $sbjct_object->matches('cons');
Returns : Integer or a 2-element array of integers
Argument : class = 'id' | 'cons' OR none.
: If no argument is provided, both identical and conservative
: numbers are returned in a two element list.
: (Other terms can be used to refer to the conservative
: matches, e.g., 'positive'. All that is checked is whether or
: not the supplied string starts with 'id'. If not, the
: conservative matches are returned.)
Throws : Exception if the requested data cannot be obtained.
Comments : If you need data for each HSP, use hsps() and then interate
: through the HSP objects.
: Does not rely on wantarray to return a list. Only checks for
: the presence of an argument (no arg = return list).
See Also : B, L
=cut
#---------------
sub matches {
#---------------
my( $self, $arg) = @_;
my(@data,$data);
if(!$arg) {
@data = ($self->{'_totalIdentical'}, $self->{'_totalConserved'});
return @data if @data;
} else {
if($arg =~ /^id/i) {
$data = $self->{'_totalIdentical'};
} else {
$data = $self->{'_totalConserved'};
}
return $data if $data;
}
## Something went wrong if we make it to here.
$self->throw("Can't get identical or conserved data: no data.");
}
=head2 start
Usage : $sbjct->start( [seq_type] );
Purpose : Gets the start coordinate for the query, sbjct, or both sequences
: in the Sbjct object. If there is more than one HSP, the lowest start
: value of all HSPs is returned.
Example : $qbeg = $sbjct->start('query');
: $sbeg = $sbjct->start('sbjct');
: ($qbeg, $sbeg) = $sbjct->start();
Returns : scalar context: integer
: array context without args: list of two integers (queryStart, sbjctStart)
: Array context can be "induced" by providing an argument of 'list' or 'array'.
Argument : In scalar context: seq_type = 'query' or 'sbjct'
: (case insensitive). If not supplied, 'query' is used.
Throws : n/a
Comments : This method requires that all HSPs be tiled. If there is more than one
: HSP and they have not already been tiled, they will be tiled first.
: Remember that the start and end coordinates of all HSPs are
: normalized so that start < end. Strand information can only be
: obtained on an HSP-by-HSP basis by calling $hsp->strand().
See Also : L, L, L, B()
=cut
#----------
sub start {
#----------
my ($self, $seqType) = @_;
$seqType ||= (wantarray ? 'list' : 'query');
# If there is only one HSP, defer this call to the solitary HSP.
if($self->num_hsps == 1) {
return $self->hsp->start($seqType);
} else {
$self->_tile_hsps() if not $self->{'_tile_hsps'};
if($seqType =~ /list|array/i) {
return ($self->{'_queryStart'}, $self->{'_sbjctStart'});
} else {
## Sensitive to member name changes.
$seqType = "_\L$seqType\E";
return $self->{$seqType.'Start'};
}
}
}
=head2 end
Usage : $sbjct->end( [seq_type] );
Purpose : Gets the end coordinate for the query, sbjct, or both sequences
: in the Sbjct object. If there is more than one HSP, the largest end
: value of all HSPs is returned.
Example : $qend = $sbjct->end('query');
: $send = $sbjct->end('sbjct');
: ($qend, $send) = $sbjct->end();
Returns : scalar context: integer
: array context without args: list of two integers (queryEnd, sbjctEnd)
: Array context can be "induced" by providing an argument of 'list' or 'array'.
Argument : In scalar context: seq_type = 'query' or 'sbjct'
: (case insensitive). If not supplied, 'query' is used.
Throws : n/a
Comments : This method requires that all HSPs be tiled. If there is more than one
: HSP and they have not already been tiled, they will be tiled first.
: Remember that the start and end coordinates of all HSPs are
: normalized so that start < end. Strand information can only be
: obtained on an HSP-by-HSP basis by calling $hsp->strand().
See Also : L, L, L, B()
=cut
#----------
sub end {
#----------
my ($self, $seqType) = @_;
$seqType ||= (wantarray ? 'list' : 'query');
# If there is only one HSP, defer this call to the solitary HSP.
if($self->num_hsps == 1) {
return $self->hsp->end($seqType);
} else {
$self->_tile_hsps() if not $self->{'_tile_hsps'};
if($seqType =~ /list|array/i) {
return ($self->{'_queryStop'}, $self->{'_sbjctStop'});
} else {
## Sensitive to member name changes.
$seqType = "_\L$seqType\E";
return $self->{$seqType.'Stop'};
}
}
}
=head2 range
Usage : $sbjct->range( [seq_type] );
Purpose : Gets the (start, end) coordinates for the query or sbjct sequence
: in the HSP alignment.
Example : ($qbeg, $qend) = $sbjct->range('query');
: ($sbeg, $send) = $sbjct->range('sbjct');
Returns : Two-element array of integers
Argument : seq_type = string, 'query' or 'sbjct' (default = 'query')
: (case insensitive).
Throws : n/a
See Also : L, L
=cut
#----------
sub range {
#----------
my ($self, $seqType) = @_;
$seqType ||= 'query';
return ($self->start($seqType), $self->end($seqType));
}
=head2 frac_identical
Usage : $sbjct_object->frac_identical( [seq_type] );
Purpose : Get the overall fraction of identical positions across all HSPs.
: The number refers to only the aligned regions and does not
: account for unaligned regions in between the HSPs, if any.
Example : $frac_iden = $sbjct_object->frac_identical('query');
Returns : Float (2-decimal precision, e.g., 0.75).
Argument : seq_type: 'query' | 'sbjct' | 'total'
: default = 'total' (but see comments below).
Throws : n/a
Comments : Different versions of Blast report different values for the total
: length of the alignment. This is the number reported in the
: denominators in the stats section:
: "Identical = 34/120 Positives = 67/120".
: BLAST-GP uses the total length of the alignment (with gaps)
: WU-BLAST uses the length of the query sequence (without gaps).
: Therefore, when called without an argument or an argument of 'total',
: this method will report different values depending on the
: version of BLAST used.
:
: To get the fraction identical among only the aligned residues,
: ignoring the gaps, call this method with an argument of 'query'
: or 'sbjct'.
:
: If you need data for each HSP, use hsps() and then iterate
: through the HSP objects.
: This method requires that all HSPs be tiled. If they have not
: already been tiled, they will be tiled first.
See Also : L, L, L, L<_tile_hsps()|_tile_hsps>
=cut
#------------------
sub frac_identical {
#------------------
my ($self, $seqType) = @_;
$seqType ||= 'total';
## Sensitive to member name format.
$seqType = lc($seqType);
$self->_tile_hsps() if not $self->{'_tile_hsps'};
sprintf( "%.2f", $self->{'_totalIdentical'}/$self->{'_length_aln_'.$seqType});
}
=head2 frac_conserved
Usage : $sbjct_object->frac_conserved( [seq_type] );
Purpose : Get the overall fraction of conserved positions across all HSPs.
: The number refers to only the aligned regions and does not
: account for unaligned regions in between the HSPs, if any.
Example : $frac_cons = $sbjct_object->frac_conserved('sbjct');
Returns : Float (2-decimal precision, e.g., 0.75).
Argument : seq_type: 'query' | 'sbjct' | 'total'
: default = 'total' (but see comments below).
Throws : n/a
Comments : Different versions of Blast report different values for the total
: length of the alignment. This is the number reported in the
: denominators in the stats section:
: "Identical = 34/120 Positives = 67/120".
: BLAST-GP uses the total length of the alignment (with gaps)
: WU-BLAST uses the length of the query sequence (without gaps).
: Therefore, when called without an argument or an argument of 'total',
: this method will report different values depending on the
: version of BLAST used.
:
: To get the fraction conserved among only the aligned residues,
: ignoring the gaps, call this method with an argument of 'query'
: or 'sbjct'.
:
: If you need data for each HSP, use hsps() and then interate
: through the HSP objects.
: This method requires that all HSPs be tiled. If they have not
: already been tiled, they will be tiled first.
See Also : L, L, L<_tile_hsps()|_tile_hsps>
=cut
#--------------------
sub frac_conserved {
#--------------------
my ($self, $seqType) = @_;
$seqType ||= 'total';
## Sensitive to member name format.
$seqType = lc($seqType);
$self->_tile_hsps() if not $self->{'_tile_hsps'};
sprintf( "%.2f", $self->{'_totalConserved'}/$self->{'_length_aln_'.$seqType});
}
=head2 frac_aligned_query
Usage : $sbjct_object->frac_aligned_query();
Purpose : Get the fraction of the query sequence which has been aligned
: across all HSPs (not including intervals between non-overlapping
: HSPs).
Example : $frac_alnq = $sbjct_object->frac_aligned_query();
Returns : Float (2-decimal precision, e.g., 0.75).
Argument : n/a
Throws : n/a
Comments : If you need data for each HSP, use hsps() and then interate
: through the HSP objects.
: To compute the fraction aligned, the logical length of the query
: sequence is used, meaning that for [T]BLASTX reports, the
: full length of the query sequence is converted into amino acids
: by dividing by 3. This is necessary because of the way
: the lengths of aligned sequences are computed.
: This method requires that all HSPs be tiled. If they have not
: already been tiled, they will be tiled first.
See Also : L, L<_tile_hsps()|_tile_hsps>, L, L
=cut
#----------------------
sub frac_aligned_query {
#----------------------
my $self = shift;
$self->_tile_hsps() if not $self->{'_tile_hsps'};
sprintf( "%.2f", $self->{'_length_aln_query'}/$self->logical_length('query'));
}
=head2 frac_aligned_hit
Usage : $sbjct_object->frac_aligned_hit();
Purpose : Get the fraction of the hit (sbjct) sequence which has been aligned
: across all HSPs (not including intervals between non-overlapping
: HSPs).
Example : $frac_alnq = $sbjct_object->frac_aligned_hit();
Returns : Float (2-decimal precision, e.g., 0.75).
Argument : n/a
Throws : n/a
Comments : If you need data for each HSP, use hsps() and then interate
: through the HSP objects.
: To compute the fraction aligned, the logical length of the sbjct
: sequence is used, meaning that for TBLAST[NX] reports, the
: full length of the sbjct sequence is converted into amino acids
: by dividing by 3. This is necessary because of the way
: the lengths of aligned sequences are computed.
: This method requires that all HSPs be tiled. If they have not
: already been tiled, they will be tiled first.
See Also : L, L, L<_tile_hsps()|_tile_hsps>, L, L
=cut
#--------------------
sub frac_aligned_hit {
#--------------------
my $self = shift;
$self->_tile_hsps() if not $self->{'_tile_hsps'};
sprintf( "%.2f", $self->{'_length_aln_sbjct'}/$self->logical_length('sbjct'));
}
# Safety-net methods for those who try don't read or remember the API.
# Redirecting to the proper method. These 'sbjct' versions may be more
# consistent with the API of this module since there are numerous other
# instances of using 'sbjct' in arguments. However, 'sbjct' is a bit tech-ee.
#-----------------------
sub frac_aligned_sbjct { my $self=shift; $self->frac_aligned_hit(@_); }
#-----------------------
sub num_unaligned_sbjct { my $self=shift; $self->num_unaligned_hit(@_); }
#-----------------------
=head2 num_unaligned_hit
Usage : $sbjct_object->num_unaligned_hit();
Purpose : Get the number of the unaligned residues in the hit sequence.
: Sums across all all HSPs.
Example : $num_unaln = $sbjct_object->num_unaligned_hit();
Returns : Integer
Argument : n/a
Throws : n/a
Comments : See notes regarding logical lengths in the comments for frac_aligned_hit().
: They apply here as well.
: If you need data for each HSP, use hsps() and then interate
: through the HSP objects.
: This method requires that all HSPs be tiled. If they have not
: already been tiled, they will be tiled first.
See Also : L, L<_tile_hsps()|_tile_hsps>, L
=cut
#---------------------
sub num_unaligned_hit {
#---------------------
my $self = shift;
$self->_tile_hsps() if not $self->{'_tile_hsps'};
my $num = $self->logical_length('sbjct') - $self->{'_length_aln_sbjct'};
($num < 0 ? 0 : $num );
}
=head2 num_unaligned_query
Usage : $sbjct_object->num_unaligned_query();
Purpose : Get the number of the unaligned residues in the query sequence.
: Sums across all all HSPs.
Example : $num_unaln = $sbjct_object->num_unaligned_query();
Returns : Integer
Argument : n/a
Throws : n/a
Comments : See notes regarding logical lengths in the comments for frac_aligned_query().
: They apply here as well.
: If you need data for each HSP, use hsps() and then interate
: through the HSP objects.
: This method requires that all HSPs be tiled. If they have not
: already been tiled, they will be tiled first.
See Also : L, L<_tile_hsps()|_tile_hsps>, L
=cut
#-----------------------
sub num_unaligned_query {
#-----------------------
my $self = shift;
$self->_tile_hsps() if not $self->{'_tile_hsps'};
my $num = $self->logical_length('query') - $self->{'_length_aln_query'};
($num < 0 ? 0 : $num );
}
=head2 seq_inds
Usage : $hit->seq_inds( seq_type, class, collapse );
Purpose : Get a list of residue positions (indices) across all HSPs
: for identical or conserved residues in the query or sbjct sequence.
Example : @ind = $hit->seq_inds('query', 'identical');
: @ind = $hit->seq_inds('sbjct', 'conserved');
: @ind = $hit->seq_inds('sbjct', 'conserved', 1);
Returns : Array of integers
: May include ranges if collapse is non-zero.
Argument : seq_type = 'query' or 'sbjct' (default = query)
: class = 'identical' or 'conserved' (default = identical)
: (can be shortened to 'id' or 'cons')
: (actually, anything not 'id' will evaluate to 'conserved').
: collapse = boolean, if non-zero, consecutive positions are merged
: using a range notation, e.g., "1 2 3 4 5 7 9 10 11"
: collapses to "1-5 7 9-11". This is useful for
: consolidating long lists. Default = no collapse.
Throws : n/a.
See Also : B
=cut
#-------------
sub seq_inds {
#-------------
my ($self, $seq, $class, $collapse) = @_;
$seq ||= 'query';
$class ||= 'identical';
$collapse ||= 0;
my (@inds, $hsp);
foreach $hsp ($self->hsps) {
# This will merge data for all HSPs together.
push @inds, $hsp->seq_inds($seq, $class);
}
# Need to remove duplicates and sort the merged positions.
if(@inds) {
my %tmp = map { $_, 1 } @inds;
@inds = sort {$a <=> $b} keys %tmp;
}
require Bio::Tools::Blast::HSP;
$collapse ? &Bio::Tools::Blast::HSP::collapse_nums(@inds) : @inds;
}
#####################################################################################
## INSTANCE METHODS ##
#####################################################################################
=head2 display
Usage : $sbjct_object->display( %named_parameters );
Purpose : Display information about Bio::Tools::Blast::Sbjct.pm data members
Example : $object->display(-SHOW=>'stats');
Argument : Named parameters: -SHOW => 'hsp',
: -WHERE => filehandle (default = STDOUT)
Returns : n/a
Status : Deprecated, Buggy.
: Use Blast::table() or Blast::table_tiled() instead.
See Also : L<_display_stats()|_display_stats>, L<_display_hsps()|_display_hsps>, B::display
=cut
#------------
sub display {
#------------
my( $self, %param) = @_;
$param{-HEADER} = 0;
$self->SUPER::display(%param);
$self->show =~ /hsp/i and $self->_display_hsps( %param);
}
=head2 _display_stats
Usage : n/a; called automatically by display()
Purpose : Display information about Bio::Tools::Blast.pm data members.
: Not tab-delimited.
: Prints the rank, name, database, score, p, n, length
: of the hit sequence, length of the aligned region,
: fraction identical, fraction conserved, and the fraction aligned
: for both the query and hit sequences.
Example : n/a
Argument : one argument = filehandle object.
Returns : printf call.
Status : Deprecated, Buggy.
: Use Blast::table() or Blast::table_tiled() instead.
See Also : L
=cut
#-------------------
sub _display_stats {
#-------------------
my( $self, $OUT) = @_;
my $layout = $self->parent->_layout();
if($layout == 1) {
printf( $OUT "%-3d %-20s %-11s %-5d %-5d %-9.1e %-9.1e %-4d %-3d %-5d %-5d %-5s %-6.2f %-6.2f %-4d(%.2f) %-4d(%.2f)\n",
$self->rank(), $self->name(),
($self->database() || 'UNKNOWN DB') ,
$self->score(),$self->bits(),$self->p(),$self->expect(),
$self->gaps(), $self->n(),
$self->length(), $self->length_aln('query'),
$self->ambiguous_aln(),
$self->frac_aligned_query, $self->frac_aligned_hit,
$self->matches('iden'), $self->frac_identical('query'),
$self->matches('cons'), $self->frac_conserved('query'));
} else {
printf( $OUT "%-3d %-20s %-11s %-5d %-5d %-9.1e %-4d %-3d %-5d %-5d %-5s %-6.2f %-6.2f %-4d(%.2f) %-4d(%.2f)\n",
$self->rank(), $self->name(),
($self->database() || 'UNKNOWN DB'),
$self->score(),$self->bits(),$self->expect(),
$self->gaps(), $self->num_hsps,
$self->length(), $self->length_aln('query'),
$self->ambiguous_aln(),
$self->frac_aligned_query, $self->frac_aligned_hit,
$self->matches('iden'), $self->frac_identical('query'),
$self->matches('cons'), $self->frac_conserved('query') );
}
}
=head2 _display_hsps
Usage : n/a; called automatically by display()
Purpose : Display information about each HSP in the current BLAST hit.
Example : n/a
Argument : one argument = filehandle object.
Returns : printf call.
Status : Experimental
See Also : L, B
=cut
#----------------
sub _display_hsps {
#----------------
my( $self, %param) = @_;
my $OUT = $self->fh();
my $hspCount = 0;
my $reply = undef;
not defined $self->{'_hsps'} and do{ print $OUT "\nHSP data not loaded.\n\n"; return; };
# print $OUT "\n",$self->num_hsps, " HSPs\n\n";
my($hsp);
foreach $hsp ( $self->hsps() ) {
$hspCount++;
print $OUT "\n ", '-'x25, "< HSP #$hspCount >", '-'x25, "\n";
$hsp->display( %param );
if( $hspCount < $self->num_hsps ) {
print "\n\n\t--------> FOR NEXT HSP, q TO QUIT <--------\n";
chop( $reply = );
$reply =~ /^q/i and return;
}
}
}
=head2 homol_data
Usage : $data = $sbjct_object->homo_data( %named_params );
Purpose : Gets specific similarity data about all HSPs.
Returns : String
Argument : named parameters forwarded to Bio::Tools::Blast::HSP::homol_data().
Throws : n/a
Status : Experimental
Comments : This is an experimental method used for obtaining an
: indication of:
: 1) how many HSPs are in a Blast alignment
: 2) how strong the similarity is between sequences in the HSP
: 3) the endpoints of the alignment (sequence monomer numbers)
: "Homology data" for each HSP is in the format:
: " "
: Data for different HSPs are tab-delimited.
See Also : B, B
=cut
#---------------
sub homol_data {
#---------------
my ($self,%param) = @_;
my $data = $self->name();
foreach ($self->hsps) {
$data .="\t".$_->homol_data(%param);
}
## Record ambiguous alignment status.
$data .= "\t".$self->ambiguous_aln();
$data;
}
=head2 is_signif
Usage : $sbjct_object->is_signif();
Purpose : Determine if the given BLAST hit is significant.
Example :
Returns : Boolean
Argument : n/a
Throws : n/a
Comments : Uses criteria defined in the parent Blast.pm object
: to assess significance. Currently, only relies on
: P-value and length criteria.
: This mehtod is largely obsolete since are hits are now by
: definition significant.
=cut
#---------------
sub is_signif {
#---------------
my $self = shift;
return ($self->{'_significance'} <= $self->parent->signif and
$self->length > $self->parent->signif_len);
}
#####################################################################################
## CLASS METHODS ##
#####################################################################################
=head1 CLASS METHODS
=head2 get_exponent
Usage : &get_exponent( number );
Purpose : Determines the power of 10 exponent of an integer, float,
: or scientific notation number.
Example : &get_exponent("4.0e-206");
: &get_exponent("0.00032");
: &get_exponent("10.");
: &get_exponent("1000.0");
: &get_exponent("e+83");
Argument : Float, Integer, or scientific notation number
Returns : Integer representing the exponent part of the number (+ or -).
: If argument == 0 (zero), return value is "-999".
Comments : Exponents are rounded up (less negative) if the mantissa is >= 5.
: Exponents are rounded down (more negative) if the mantissa is <= -5.
: This method probably belongs in a more general utility class.
=cut
#------------------
sub get_exponent {
#------------------
my $data = shift;
my($num, $exp) = split /[eE]/, $data;
if( defined $exp) {
$num = 1 if not $num;
$num >= 5 and $exp++;
$num <= -5 and $exp--;
} elsif( $num == 0) {
$exp = -999;
} elsif( not $num =~ /\./) {
$exp = CORE::length($num) -1;
} else {
$exp = 0;
$num .= '0' if $num =~ /\.$/;
my ($c);
my $rev = 0;
if($num !~ /^0/) {
$num = reverse($num);
$rev = 1;
}
do { $c = chop($num);
$c == 0 && $exp++;
} while( $c ne '.');
$exp = -$exp if $num == 0 and not $rev;
$exp -= 1 if $rev;
}
return $exp;
}
1;
__END__
#####################################################################################
# END OF CLASS #
#####################################################################################
=head1 FOR DEVELOPERS ONLY
=head2 Data Members
Information about the various data members of this module is provided for those
wishing to modify or understand the code. Two things to bear in mind:
=over 4
=item 1 Do NOT rely on these in any code outside of this module.
All data members are prefixed with an underscore to signify that they are private.
Always use accessor methods. If the accessor doesn't exist or is inadequate,
create or modify an accessor (and let me know, too!). (An exception to this might
be for HSP.pm which is more tightly coupled to Sbjct.pm and
may access Sbjct data members directly for efficiency purposes, but probably
should not).
=item 2 This documentation may be incomplete and out of date.
It is easy for these data member descriptions to become obsolete as
this module is still evolving. Always double check this info and search
for members not described here.
=back
An instance of Bio::Tools::Blast::Sbjct.pm is a blessed reference to a hash containing
all or some of the following fields:
FIELD VALUE
--------------------------------------------------------------
_hsps : Array ref for a list of Bio::Tools::Blast::HSP.pm objects.
:
_db : Database identifier from the summary line.
:
_desc : Description data for the hit from the summary line.
:
_length : Total length of the hit sequence.
:
_score : BLAST score.
:
_bits : BLAST score (in bits). Matrix-independent.
:
_p : BLAST P value. Obtained from summary section. (Blast1/WU-Blast only)
:
_expect : BLAST Expect value. Obtained from summary section.
:
_n : BLAST N value (number of HSPs) (Blast1/WU-Blast2 only)
:
_frame : Reading frame for TBLASTN and TBLASTX analyses.
:
_totalIdentical: Total number of identical aligned monomers.
:
_totalConserved: Total number of conserved aligned monomers (a.k.a. "positives").
:
_overlap : Maximum number of overlapping residues between adjacent HSPs
: before considering the alignment to be ambiguous.
:
_ambiguous_aln : Boolean. True if the alignment of all HSPs is ambiguous.
:
_length_aln_query : Length of the aligned region of the query sequence.
:
_length_aln_sbjct : Length of the aligned region of the sbjct sequence.
INHERITED DATA MEMBERS
----------------------
_name : From Bio::Root::Object.pm. String representing the name of the
: sbjct sequence obtained from the BLAST report.
:
_parent : From Bio::Root::Object.pm. This member contains a reference to the
: Bio::Tools::Blast.pm object to which this hit belongs.
=cut
1;