~ubuntu-branches/ubuntu/oneiric/bioperl/oneiric

« back to all changes in this revision

Viewing changes to Bio/Search/Hit/BlastHit.pm

  • Committer: Bazaar Package Importer
  • Author(s): Matt Hope
  • Date: 2004-04-18 14:24:11 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040418142411-gr92uexquw4w8liq
Tags: 1.4-1
* New upstream release
* Examples and working code are installed by default to usr/bin,
  this has been moved to usr/share/doc/bioperl/bin

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#-----------------------------------------------------------------
2
 
# $Id: BlastHit.pm,v 1.9 2002/01/23 11:30:25 heikki Exp $
3
 
#
4
 
# BioPerl module Bio::Search::Hit::BlastHit
5
 
#
6
 
# (This module was originally called Bio::Tools::Blast::Sbjct)
7
 
#
8
 
# Cared for by Steve Chervitz <sac@bioperl.org>
 
1
# $Id: BlastHit.pm,v 1.14 2003/04/09 03:28:11 sac Exp $
 
2
#
 
3
# BioPerl module for Bio::Search::Hit::GenericHit
 
4
#
 
5
# Cared for by Jason Stajich <jason@bioperl.org>
 
6
#
 
7
# Copyright Jason Stajich
9
8
#
10
9
# You may distribute this module under the same terms as perl itself
11
 
#-----------------------------------------------------------------
12
10
 
13
 
## POD Documentation:
 
11
# POD documentation - main docs before the code
14
12
 
15
13
=head1 NAME
16
14
 
17
 
Bio::Search::Hit::BlastHit - Bioperl BLAST Hit object
 
15
Bio::Search::Hit::BlastHit - Blast-specific subclass of Bio::Search::Hit::GenericHit
18
16
 
19
17
=head1 SYNOPSIS
20
18
 
21
 
The construction of BlastHit objects is performed by
22
 
Bio::SearchIO::blast::BlastHitFactory in a process that is
23
 
orchestrated by the Blast parser (B<Bio::SearchIO::blast::blast>).
24
 
The resulting BlastHits are then accessed via
25
 
B<Bio::Search::Result::BlastResult>). Therefore, you do not need to
26
 
use B<Bio::Search::Hit::BlastHit>) directly. If you need to construct
27
 
BlastHits directly, see the new() function for details.
28
 
 
29
 
For B<Bio::SearchIO> BLAST parsing usage examples, see the
30
 
B<examples/search-blast> directory of the Bioperl distribution.
31
 
 
 
19
    use Bio::Search::Hit::BlastHit;
 
20
    my $hit = new Bio::Search::Hit::BlastHit(-algorithm => 'blastp');
 
21
 
 
22
# See Bio::Search::Hit::GenericHit for information about working with Hits.
 
23
 
 
24
# TODO: Describe how to configure a SearchIO stream so that it generates
 
25
#       GenericHit objects.
32
26
 
33
27
=head1 DESCRIPTION
34
28
 
35
 
The Bio::Search::Hit::BlastHit.pm module encapsulates data and methods
36
 
for manipulating "hits" from a BLAST report. A BLAST hit is a
37
 
collection of HSPs along with other metadata such as sequence name
38
 
and score information. Hit objects are accessed via
39
 
B<Bio::Search::Result::BlastResult> objects after parsing a BLAST report using
40
 
the B<Bio::SearchIO> system.
41
 
 
42
 
In Blast lingo, the "sbjct" sequences are all the sequences 
43
 
in a target database which were compared against a "query" sequence.
44
 
The terms "sbjct" and "hit" will be used interchangeably in this module.
45
 
All methods that take 'sbjct' as an argument also support 'hit' as a
46
 
synonym.
47
 
 
48
 
This module supports BLAST versions 1.x and 2.x, gapped and ungapped,
49
 
and PSI-BLAST.
50
 
 
51
 
 
52
 
=head2 HSP Tiling and Ambiguous Alignments
53
 
 
54
 
If a Blast hit has more than one HSP, the Bio::Search::Hit::BlastHit.pm
55
 
object has the ability to merge overlapping HSPs into contiguous
56
 
blocks. This permits the BlastHit object to sum data across all HSPs
57
 
without counting data in the overlapping regions multiple times, which
58
 
would happen if data from each overlapping HSP are simply summed.  HSP
59
 
tiling is performed automatically when methods of the BlastHit object
60
 
that rely on tiled data are invoked. These include
61
 
L<frac_identical()|frac_identical>, L<frac_conserved()|frac_conserved>, L<gaps()|gaps>,
62
 
L<frac_aligned_query()|frac_aligned_query>, L<frac_aligned_hit()|frac_aligned_hit>,
63
 
L<num_unaligned_query()|num_unaligned_query>, L<num_unaligned_hit()|num_unaligned_hit>.
64
 
 
65
 
It also permits the assessment of an "ambiguous alignment" if the
66
 
query (or sbjct) sequences from different HSPs overlap 
67
 
(see L<ambiguous_aln()|ambiguous_aln>). The existence
68
 
of an overlap could indicate a biologically interesting region in the
69
 
sequence, such as a repeated domain.  The BlastHit object uses the
70
 
C<-OVERLAP> parameter to determine when two sequences overlap; if this is
71
 
set to 2 -- the default -- then any two sbjct or query HSP sequences
72
 
must overlap by more than two residues to get merged into the same
73
 
contig and counted as an overlap. See the L<BUGS | BUGS> section below for
74
 
"issues" with HSP tiling.
75
 
 
76
 
 
77
 
The results of the HSP tiling is reported with the following ambiguity codes:
78
 
 
79
 
   'q' = Query sequence contains multiple sub-sequences matching
80
 
         a single region in the sbjct sequence. 
81
 
 
82
 
   's' = Subject (BlastHit) sequence contains multiple sub-sequences matching
83
 
         a single region in the query sequence. 
84
 
 
85
 
   'qs' = Both query and sbjct sequences contain more than one
86
 
          sub-sequence with similarity to the other sequence.
87
 
 
88
 
 
89
 
For addition information about ambiguous BLAST alignments, see
90
 
L<Bio::Search::BlastUtils::tile_hsps()|Bio::Search::BlastUtils> and 
91
 
 
92
 
 http://www-genome.stanford.edu/Sacch3D/help/ambig_aln.html
93
 
 
94
 
=head1 DEPENDENCIES
95
 
 
96
 
Bio::Search::Hit::BlastHit.pm is a concrete class that inherits from
97
 
B<Bio::Root::Root> and B<Bio::Search::Hit::HitI>.  and relies on
98
 
B<Bio::Search::HSP::BlastHSP>.
99
 
 
100
 
 
101
 
=head1 BUGS
102
 
 
103
 
One consequence of the HSP tiling is that methods that rely on HSP
104
 
tiling such as L<frac_identical()|frac_identical>, L<frac_conserved()|frac_conserved>, L<gaps()|gaps>
105
 
etc. may report misleading numbers when C<-OVERLAP> is set to a large
106
 
number.  For example, say we have two HSPs and the query sequence tile
107
 
as follows:
108
 
 
109
 
            1      8             22      30        40             60 
110
 
 Full seq:  ------------------------------------------------------------
111
 
                    *  ** *   **
112
 
 HSP1:             ---------------                    (6 identical matches)
113
 
                              **   **  **
114
 
 HSP2:                        -------------           (6 identical matches)
115
 
 
116
 
 
117
 
If C<-OVERLAP> is set to some number over 4, HSP1 and HSP2 will not be
118
 
tiled into a single contig and their numbers of identical matches will
119
 
be added, giving a total of 12, not 10 if they had be combined into
120
 
one contig. This can lead to number greater than 1.0 for methods
121
 
L<frac_identical()|frac_identical> and L<frac_conserved()|frac_conserved>. This is less of an issue
122
 
with gapped Blast since it tends to combine HSPs that would be listed
123
 
separately without gapping.  (Fractions E<gt>1.0 can be viewed as a
124
 
signal for an interesting alignment that warrants further inspection,
125
 
thus turning this bug into a feature :-).
126
 
 
127
 
Using large values for C<-OVERLAP> can lead to incorrect numbers
128
 
reported by methods that rely on HSP tiling but can be useful if you
129
 
care more about detecting ambiguous alignments.  Setting C<-OVERLAP>
130
 
to zero will lead to the most accurate numbers for the
131
 
tiling-dependent methods but will be useless for detecting overlapping
132
 
HSPs since all HSPs will appear to overlap.
133
 
 
134
 
 
135
 
=head1 SEE ALSO
136
 
 
137
 
 Bio::Search::HSP::BlastHSP.pm         - Blast HSP object.
138
 
 Bio::Search::Result::BlastResult.pm   - Blast Result object.
139
 
 Bio::Search::Hit::HitI.pm             - Interface implemented by BlastHit.pm
140
 
 Bio::Root::Root.pm                    - Base class for BlastHit.pm
141
 
 
142
 
Links:
143
 
 
144
 
 http://bio.perl.org/Core/POD/Search/Hit/Blast/BlastHSP.pm.html
145
 
 
146
 
 http://bio.perl.org/Projects/modules.html  - Online module documentation
147
 
 http://bio.perl.org/Projects/Blast/        - Bioperl Blast Project     
148
 
 http://bio.perl.org/                       - Bioperl Project Homepage
149
 
 
 
29
This object is a subclass of Bio::Search::Hit::GenericHit
 
30
and provides some operations that facilitate working with BLAST
 
31
and PSI-BLAST Hits.
 
32
 
 
33
For general information about working with Hits, see 
 
34
Bio::Search::Hit::GenericHit.
150
35
 
151
36
=head1 FEEDBACK
152
37
 
153
 
=head2 Mailing Lists 
 
38
=head2 Mailing Lists
154
39
 
155
40
User feedback is an integral part of the evolution of this and other
156
 
Bioperl modules.  Send your comments and suggestions preferably to one
157
 
of the Bioperl mailing lists.  Your participation is much appreciated.
 
41
Bioperl modules. Send your comments and suggestions preferably to
 
42
the Bioperl mailing list.  Your participation is much appreciated.
158
43
 
159
 
    bioperl-l@bioperl.org              - General discussion
160
 
    http://bio.perl.org/MailList.html  - About the mailing lists
 
44
  bioperl-l@bioperl.org              - General discussion
 
45
  http://bioperl.org/MailList.shtml  - About the mailing lists
161
46
 
162
47
=head2 Reporting Bugs
163
48
 
164
49
Report bugs to the Bioperl bug tracking system to help us keep track
165
 
the bugs and their resolution. Bug reports can be submitted via email
166
 
or the web:
167
 
 
168
 
    bioperl-bugs@bio.perl.org                   
169
 
    http://bio.perl.org/bioperl-bugs/           
170
 
 
171
 
=head1 AUTHOR 
172
 
 
173
 
Steve Chervitz E<lt>sac@bioperl.orgE<gt>
174
 
 
175
 
See L<the FEEDBACK section | FEEDBACK> for where to send bug reports and comments.
176
 
 
177
 
=head1 ACKNOWLEDGEMENTS
178
 
 
179
 
This software was originally developed in the Department of Genetics
180
 
at Stanford University. I would also like to acknowledge my
181
 
colleagues at Affymetrix for useful feedback.
182
 
 
183
 
=head1 COPYRIGHT
184
 
 
185
 
Copyright (c) 1996-2001 Steve Chervitz. All Rights Reserved.
186
 
 
187
 
=head1 DISCLAIMER
188
 
 
189
 
This software is provided "as is" without warranty of any kind.
 
50
of the bugs and their resolution. Bug reports can be submitted via
 
51
email or the web:
 
52
 
 
53
  bioperl-bugs@bioperl.org
 
54
  http://bugzilla.bioperl.org/
 
55
 
 
56
=head1 AUTHOR - Jason Stajich and Steve Chervitz
 
57
 
 
58
Email jason@bioperl.org
 
59
Email sac@bioperl.org
 
60
 
 
61
=head1 CONTRIBUTORS
 
62
 
 
63
Additional contributors names and emails here
190
64
 
191
65
=head1 APPENDIX
192
66
 
198
72
 
199
73
# Let the code begin...
200
74
 
 
75
 
201
76
package Bio::Search::Hit::BlastHit;
202
 
 
 
77
use vars qw(@ISA);
203
78
use strict;
204
 
use Bio::Search::Hit::HitI;
205
 
use Bio::Root::Root;
206
 
require Bio::Search::BlastUtils;
207
 
use vars qw( @ISA %SUMMARY_OFFSET $Revision);
208
 
 
209
 
use overload 
210
 
    '""' => \&to_string;
211
 
 
212
 
@ISA = qw( Bio::Root::Root Bio::Search::Hit::HitI );
213
 
 
214
 
$Revision = '$Id: BlastHit.pm,v 1.9 2002/01/23 11:30:25 heikki Exp $';  #'
215
 
 
 
79
 
 
80
use Bio::Search::Hit::GenericHit;
 
81
require Bio::Search::SearchUtils;
 
82
 
 
83
@ISA = qw(Bio::Search::Hit::GenericHit);
216
84
 
217
85
=head2 new
218
86
 
219
 
 Usage     : $hit = Bio::Search::Hit::BlastHit->new( %named_params );
220
 
           : Bio::Search::Hit::BlastHit.pm objects are constructed 
221
 
           : automatically by Bio::SearchIO::BlastHitFactory.pm, 
222
 
           : so there is no need for direct instantiation.
223
 
 Purpose   : Constructs a new BlastHit object and Initializes key variables 
224
 
           : for the hit.
225
 
 Returns   : A Bio::Search::Hit::BlastHit object
226
 
 Argument  : Named Parameters:
227
 
           : Parameter keys are case-insensitive.
228
 
           :     -RAW_DATA   => array reference holding raw BLAST report data 
229
 
           :                    for a single hit. This includes all lines 
230
 
           :                    within the HSP alignment listing section of a 
231
 
           :                    traditional BLAST or PSI-BLAST (non-XML) report,
232
 
           :                    starting at (or just after) the leading '>'.
233
 
           :     -HOLD_RAW_DATA => boolean, should -RAW_DATA be saved within the object.
234
 
           :     -QUERY_LEN  => Length of the query sequence
235
 
           :     -ITERATION  => integer (PSI-BLAST iteration number in which hit was found)
236
 
           :     -OVERLAP    => integer (maximum overlap between adjacent
237
 
           :                    HSPs when tiling)
238
 
           :     -PROGRAM    => string (type of Blast: BLASTP, BLASTN, etc)
239
 
           :     -SIGNIF     => significance
240
 
           :     -IS_PVAL    => boolean, true if -SIGNIF contains a P-value
241
 
           :     -SCORE      => raw BLAST score
242
 
           :     -FOUND_AGAIN   => boolean, true if this was a hit from the
243
 
           :                       section of a PSI-BLAST with iteration > 1 
244
 
           :                       containing sequences that were also found 
245
 
           :                       in iteration 1.
246
 
 Comments  : This object accepts raw Blast report data not because it 
247
 
           : is required for parsing, but in order to retrieve it
248
 
           : (only available if -HOLD_RAW_DATA is set to true).
249
 
 
250
 
See Also   : L<Bio::Search::BlastUtils::tile_hsps()|Bio::Search::BlastUtils>, L<Bio::Root::Root::new()|Bio::Root::Root>
 
87
 Title   : new
 
88
 Usage   : my $obj = new Bio::Search::Hit::GenericHit();
 
89
 Function: Builds a new Bio::Search::Hit::GenericHit object 
 
90
 Returns : Bio::Search::Hit::GenericHit
 
91
 Args    : See Bio::Search::Hit::GenericHit() for other args.
 
92
           Here are the BLAST-specific args that can be used when
 
93
           creating BlastHit objects:
 
94
           -iteration    => integer for the PSI-Blast iteration number
 
95
           -found_again  => boolean, true if hit appears in a 
 
96
                            "previously found" section of a PSI-Blast report.
251
97
 
252
98
=cut
253
99
 
254
 
#-------------------
255
100
sub new {
256
 
#-------------------
257
 
    my ($class, @args ) = @_;
258
 
    my $self = $class->SUPER::new( @args );
259
 
 
260
 
    my ($raw_data, $signif, $is_pval, $hold_raw);
261
 
 
262
 
    ($self->{'_blast_program'}, $self->{'_query_length'}, $raw_data, $hold_raw,
263
 
     $self->{'_overlap'}, $self->{'_iteration'}, $signif, $is_pval, 
264
 
     $self->{'_score'}, $self->{'_found_again'} ) = 
265
 
       $self->_rearrange( [qw(PROGRAM
266
 
                              QUERY_LEN
267
 
                              RAW_DATA
268
 
                              HOLD_RAW_DATA
269
 
                              OVERLAP
270
 
                              ITERATION
271
 
                              SIGNIF
272
 
                              IS_PVAL
273
 
                              SCORE
274
 
                              FOUND_AGAIN )], @args );
275
 
 
276
 
    $self->_set_id( $raw_data->[0] );
277
 
 
278
 
    if($is_pval) {
279
 
        $self->{'_p'} = $signif;
280
 
    } else {
281
 
        $self->{'_expect'} = $signif;
282
 
    }
283
 
 
284
 
    if( $hold_raw ) {
285
 
        $self->{'_hit_data'} = $raw_data;
286
 
    }
287
 
 
288
 
    return $self;
289
 
}
290
 
 
291
 
sub DESTROY {
292
 
    my $self=shift; 
293
 
    #print STDERR "-->DESTROYING $self\n";
294
 
}
295
 
 
296
 
 
297
 
#=================================================
298
 
# Begin Bio::Search::Hit::HitI implementation
299
 
#=================================================
300
 
 
301
 
=head2 algorithm
302
 
 
303
 
 Title   : algorithm
304
 
 Usage   : $alg = $hit->algorithm();
305
 
 Function: Gets the algorithm specification that was used to obtain the hit
306
 
           For BLAST, the algorithm denotes what type of sequence was aligned 
307
 
           against what (BLASTN: dna-dna, BLASTP prt-prt, BLASTX translated 
308
 
           dna-prt, TBLASTN prt-translated dna, TBLASTX translated 
309
 
           dna-translated dna).
310
 
 Returns : a scalar string 
311
 
 Args    : none
312
 
 
313
 
=cut
314
 
 
315
 
#----------------
316
 
sub algorithm {
317
 
#----------------
318
 
    my ($self,@args) = @_;
319
 
    return $self->{'_blast_program'};
320
 
}
321
 
 
322
 
=head2 name
323
 
 
324
 
 Usage     : $hit->name([string]);
325
 
 Purpose   : Set/Get a string to identify the hit.
326
 
             This is parsed out of the "Query=" line as the first chunk of 
327
 
             non-whitespace text. If you want the rest of the line, use
328
 
             $hit->description().
329
 
 Example   : $name = $hit->name;
330
 
           : $hit->name('M81707');
331
 
 Returns   : String consisting of the hit's name or undef if not set.
332
 
 
333
 
=cut
334
 
 
335
 
#'
336
 
 
337
 
#----------------
338
 
sub name {
339
 
#----------------
340
 
    my $self = shift;
341
 
    if (@_) { 
342
 
        my $name = shift;
343
 
        $name =~ s/^\s+|(\s+|,)$//g;
344
 
        $self->{'_name'} = $name;
345
 
    }
346
 
    return $self->{'_name'};
347
 
}
348
 
 
349
 
=head2 description
350
 
 
351
 
 Usage     : $hit_object->description( [integer] );
352
 
 Purpose   : Set/Get a description string for the hit.
353
 
             This is parsed out of the "Query=" line as everything after 
354
 
             the first chunk of non-whitespace text. Use $hit->name()
355
 
             to get the first chunk (the ID of the sequence).
356
 
 Example   : $description = $hit->description;
357
 
           : $desc_60char = $hit->description(60);
358
 
 Argument  : Integer (optional) indicating the desired length of the
359
 
           : description string to be returned.
360
 
 Returns   : String consisting of the hit's description or undef if not set.
361
 
 
362
 
=cut
363
 
 
364
 
#'
365
 
 
366
 
#----------------
367
 
sub description {
368
 
#----------------
369
 
    my( $self, $len ) = @_; 
370
 
    $len = (defined $len) ? $len : (CORE::length $self->{'_description'});
371
 
    return substr( $self->{'_description'}, 0 ,$len ); 
372
 
}
373
 
 
374
 
=head2 raw_score
375
 
 
376
 
 Usage     : $hit_object->raw_score();
377
 
 Purpose   : Gets the BLAST score of the best HSP for the current Blast hit.
378
 
 Example   : $score = $hit_object->raw_score();
379
 
 Returns   : Integer
380
 
 Argument  : n/a
381
 
 Throws    : n/a
382
 
 
383
 
See Also   : L<bits()|bits>
384
 
 
385
 
=cut
386
 
 
387
 
#----------
388
 
sub raw_score { 
389
 
#----------
390
 
    my $self = shift;  
391
 
 
392
 
    # The check for $self->{'_score'} is a remnant from the 'query' mode days
393
 
    # in which the sbjct object would collect data from the description line only.
394
 
 
395
 
    my ($score);
396
 
    if(not defined($self->{'_score'})) {
397
 
        $score = $self->hsp->score;
398
 
    } else {
399
 
        $score = $self->{'_score'}; 
400
 
    } 
401
 
    return $score;
402
 
}
403
 
 
404
 
 
405
 
=head2 length
406
 
 
407
 
 Usage     : $hit_object->length();
408
 
 Purpose   : Get the total length of the hit sequence.
409
 
 Example   : $len = $hit_object->length();
410
 
 Returns   : Integer 
411
 
 Argument  : n/a
412
 
 Throws    : n/a
413
 
 Comments  : Developer note: when using the built-in length function within
414
 
           : this module, call it as CORE::length().
415
 
 
416
 
See Also   : L<logical_length()|logical_length>,  L<length_aln()|length_aln>
417
 
 
418
 
=cut
419
 
 
420
 
#-----------
421
 
sub length {
422
 
#-----------
423
 
    my $self = shift;
424
 
    return $self->{'_length'}; 
425
 
}
426
 
 
427
 
=head2 significance
428
 
 
429
 
Equivalent to L<signif()|signif>
430
 
 
431
 
=cut
432
 
 
433
 
#----------------
434
 
sub significance { shift->signif( @_ ); }
435
 
#----------------
436
 
 
437
 
 
438
 
=head2 next_hsp
439
 
 
440
 
 Title    : next_hsp
441
 
 Usage    : $hsp = $obj->next_hsp();
442
 
 Function : returns the next available High Scoring Pair object
443
 
 Example  : 
444
 
 Returns  : Bio::Search::HSP::BlastHSP or undef if finished
445
 
 Args     : none
446
 
 
447
 
=cut
448
 
 
449
 
#----------------
450
 
sub next_hsp {
451
 
#----------------
452
 
    my $self = shift;
453
 
 
454
 
    unless($self->{'_hsp_queue_started'}) {
455
 
        $self->{'_hsp_queue'} = [$self->hsps()];
456
 
        $self->{'_hsp_queue_started'} = 1;
457
 
    }
458
 
    pop @{$self->{'_hsp_queue'}};
459
 
}
460
 
 
461
 
#=================================================
462
 
# End Bio::Search::Hit::HitI implementation
463
 
#=================================================
464
 
 
465
 
 
466
 
# Providing a more explicit method for getting name of hit
467
 
# (corresponds with column name in HitTableWriter)
468
 
#----------------
469
 
sub hit_name {
470
 
#----------------
471
 
    my $self = shift;
472
 
    $self->name( @_ );
473
 
}
474
 
 
475
 
# Older method Delegates to description()
476
 
#----------------
477
 
sub desc { 
478
 
#----------------
479
 
    my $self = shift;
480
 
    return $self->description( @_ );
481
 
}
482
 
 
483
 
# Providing a more explicit method for getting description of hit
484
 
# (corresponds with column name in HitTableWriter)
485
 
#----------------
486
 
sub hit_description { 
487
 
#----------------
488
 
    my $self = shift;
489
 
    return $self->description( @_ );
490
 
}
491
 
 
492
 
=head2 score
493
 
 
494
 
Equivalent to L<raw_score()|raw_score>
495
 
 
496
 
=cut
497
 
 
498
 
#----------------
499
 
sub score { shift->raw_score( @_ ); }
500
 
#----------------
501
 
 
502
 
 
503
 
=head2 hit_length
504
 
 
505
 
Equivalent to L<length()|length>
506
 
 
507
 
=cut
508
 
 
509
 
# Providing a more explicit method for getting length of hit
510
 
#----------------
511
 
sub hit_length { shift->length( @_ ); }
512
 
#----------------
513
 
 
514
 
 
515
 
=head2 signif
516
 
 
517
 
 Usage     : $hit_object->signif( [format] );
518
 
 Purpose   : Get the P or Expect value for the best HSP of the given BLAST hit.
519
 
           : The value returned is the one which is reported in the description
520
 
           : section of the Blast report. For Blast1 and WU-Blast2, this
521
 
           : is a P-value, for Blast2, it is an Expect value.
522
 
 Example   : $obj->signif()        # returns 1.3e-34
523
 
           : $obj->signif('exp')   # returns -34
524
 
           : $obj->signif('parts') # returns (1.3, -34)
525
 
 Returns   : Float or scientific notation number (the raw P/Expect value, DEFAULT).
526
 
           : Integer if format == 'exp' (the magnitude of the base 10 exponent).
527
 
           : 2-element list (float, int) if format == 'parts' and P/Expect value
528
 
           :                is in scientific notation (see Comments).
529
 
 Argument  : format: string of 'raw' | 'exp' | 'parts'
530
 
           :    'raw' returns value given in report. Default. (1.2e-34)
531
 
           :    'exp' returns exponent value only (34)
532
 
           :    'parts' returns the decimal and exponent as a 
533
 
           :            2-element list (1.2, -34)  (see Comments).
534
 
 Throws    : n/a
535
 
 Comments  : The signif() method provides a way to deal with the fact that
536
 
           : Blast1 and Blast2 formats (and WU- vs. NCBI-BLAST) differ in 
537
 
           : what is reported in the description lines of each hit in the 
538
 
           : Blast report. The signif() method frees any client code from 
539
 
           : having to know if this is a P-value or an Expect value, 
540
 
           : making it easier to write code that can process both 
541
 
           : Blast1 and Blast2 reports. This is not necessarily a good thing, 
542
 
           : since one should always know when one is working with P-values or
543
 
           : Expect values (hence the deprecated status).
544
 
           : Use of expect() is recommended since all hits will have an Expect value.
545
 
           :
546
 
           : Using the 'parts' argument is not recommended since it will not
547
 
           : work as expected if the expect value is not in scientific notation.
548
 
           : That is, floats are not converted into sci notation before
549
 
           : splitting into parts.
550
 
 
551
 
See Also   : L<p()|p>, L<expect()|expect>, L<Bio::Search::BlastUtils::get_exponent()|Bio::Search::BlastUtils>
552
 
 
553
 
=cut
554
 
 
555
 
#-------------
556
 
sub signif {
557
 
#-------------
558
 
# Some duplication of logic for p(), expect() and signif() for the sake of performance.
559
 
    my ($self, $fmt) = @_;
560
 
 
561
 
    my $val = defined($self->{'_p'}) ? $self->{'_p'} : $self->{'_expect'};
562
 
 
563
 
    # $val can be zero.
564
 
    defined($val) or $self->throw("Can't get P- or Expect value: HSPs may not have been set.");
565
 
 
566
 
    return $val if not $fmt or $fmt =~ /^raw/i;
567
 
    ## Special formats: exponent-only or as list.
568
 
    return &Bio::Search::BlastUtils::get_exponent($val) if $fmt =~ /^exp/i;
569
 
    return (split (/eE/, $val)) if $fmt =~ /^parts/i;
570
 
 
571
 
    ## Default: return the raw P/Expect-value.
572
 
    return $val;
573
 
}
574
 
 
575
 
#----------------
576
 
sub raw_hit_data {
577
 
#----------------
578
 
    my $self = shift;
579
 
    my $data = '>';
580
 
    # Need to add blank lines where we've removed them.
581
 
    foreach( @{$self->{'_hit_data'}} ) {
582
 
        if( $_ eq 'end') {
583
 
            $data .= "\n";
584
 
        }
585
 
        else {
586
 
            $data .= /^\s*(Score|Query)/ ? "\n$_" : $_;
587
 
        }
588
 
    }
589
 
    return $data;
590
 
}
591
 
 
592
 
 
593
 
#=head2 _set_length
594
 
#
595
 
# Usage     : $hit_object->_set_length( "233" );
596
 
# Purpose   : Set the total length of the hit sequence.
597
 
# Example   : $hit_object->_set_length( $len );
598
 
# Returns   : n/a
599
 
# Argument  : Integer (only when setting). Any commas will be stripped out.
600
 
# Throws    : n/a
601
 
#
602
 
#=cut
603
 
 
604
 
#-----------
605
 
sub _set_length {
606
 
#-----------
607
 
    my ($self, $len) = @_;
608
 
    $len =~ s/,//g; # get rid of commas
609
 
    $self->{'_length'} = $len;
610
 
}
611
 
 
612
 
#=head2 _set_description
613
 
#
614
 
# Usage     : Private method; called automatically during construction
615
 
# Purpose   : Sets the description of the hit sequence.
616
 
#           : For sequence without descriptions, does not set any description.
617
 
# Argument  : Array containing description (multiple lines).
618
 
# Comments  : Processes the supplied description:
619
 
#                1. Join all lines into one string.
620
 
#                2. Remove sequence id at the beginning of description.
621
 
#                3. Removes junk charactes at begin and end of description.
622
 
#
623
 
#=cut
624
 
 
625
 
#--------------
626
 
sub _set_description {
627
 
#--------------
628
 
    my( $self, @desc ) = @_;
629
 
    my( $desc);
630
 
    
631
 
#    print STDERR "BlastHit: RAW DESC:\n@desc\n";
632
 
    
633
 
    $desc = join(" ", @desc);
634
 
    
635
 
    my $name = $self->name;
636
 
 
637
 
    if($desc) {
638
 
        $desc =~ s/^\s*\S+\s+//; # remove the sequence ID(s)
639
 
                                 # This won't work if there's no description.
640
 
        $desc =~ s/^\s*$name//;  # ...but this should.
641
 
        $desc =~ s/^[\s!]+//;
642
 
        $desc =~ s/ \d+$//;
643
 
        $desc =~ s/\.+$//;
644
 
        $self->{'_description'} = $desc;
645
 
    }
646
 
 
647
 
#    print STDERR "BlastHit: _set_description =  $desc\n";
648
 
}
649
 
 
650
 
=head2 to_string
651
 
 
652
 
 Title   : to_string
653
 
 Usage   : print $hit->to_string;
654
 
 Function: Returns a string representation for the Blast Hit.
655
 
           Primarily intended for debugging purposes.
656
 
 Example : see usage
657
 
 Returns : A string of the form:
658
 
           [BlastHit] <name> <description>
659
 
           e.g.:
660
 
           [BlastHit] emb|Z46660|SC9725 S.cerevisiae chromosome XIII cosmid
661
 
 Args    : None
662
 
 
663
 
=cut
664
 
 
665
 
#----------------
666
 
sub to_string {
667
 
#----------------
668
 
    my $self = shift;
669
 
    return "[BlastHit] " . $self->name . " " . $self->description;
670
 
}
671
 
 
672
 
 
673
 
#=head2 _set_id
674
 
#
675
 
# Usage     : Private method; automatically called by new()
676
 
# Purpose   : Sets the name of the BlastHit sequence from the BLAST summary line.
677
 
#           : The identifier is assumed to be the first
678
 
#           : chunk of non-whitespace characters in the description line
679
 
#           : Does not assume any semantics in the structure of the identifier
680
 
#           : (Formerly, this method attempted to extract database name from
681
 
#           : the seq identifiers, but this was prone to break).
682
 
# Returns   : n/a
683
 
# Argument  : String containing description line of the hit from Blast report
684
 
#           : or first line of an alignment section (with or without the leading '>').
685
 
# Throws    : Warning if cannot locate sequence ID.
686
 
#
687
 
#See Also   : L<new()|new>
688
 
#
689
 
#=cut
690
 
 
691
 
#---------------
692
 
sub _set_id {
693
 
#---------------
694
 
    my( $self, $desc ) = @_;
695
 
 
696
 
    # New strategy: Assume only that the ID is the first white space
697
 
    # delimited chunk. Not attempting to extract database name.
698
 
    # Clients will have to interpret it as necessary.
699
 
    if($desc =~ /^>?(\S+)\s*(.*)/) {
700
 
        $self->name($1);
701
 
        $self->{'_description'} = $2;
702
 
        # Note that this description comes from the summary section of the
703
 
        # BLAST report and so may be truncated. The full description will be
704
 
        # set from the alignment section. We're setting description here in case
705
 
        # the alignment section isn't being parsed.
706
 
    }
707
 
    else {
708
 
        $self->warn("Can't locate sequence identifier in summary line.", "Line = $desc");
709
 
        $desc = 'Unknown sequence ID' if not $desc;
710
 
        $self->name($desc);
711
 
    }
712
 
}
713
 
 
714
 
 
715
 
=head2 ambiguous_aln
716
 
 
717
 
 Usage     : $ambig_code = $hit_object->ambiguous_aln();
718
 
 Purpose   : Sets/Gets ambiguity code data member.
719
 
 Example   : (see usage)
720
 
 Returns   : String = 'q', 's', 'qs', '-'
721
 
           :   'q'  = query sequence contains overlapping sub-sequences 
722
 
           :          while sbjct does not.
723
 
           :   's'  = sbjct sequence contains overlapping sub-sequences 
724
 
           :          while query does not.
725
 
           :   'qs' = query and sbjct sequence contains overlapping sub-sequences
726
 
           :          relative to each other.
727
 
           :   '-'  = query and sbjct sequence do not contains multiple domains 
728
 
           :          relative to each other OR both contain the same distribution
729
 
           :          of similar domains.
730
 
 Argument  : n/a
731
 
 Throws    : n/a
732
 
 Status    : Experimental
733
 
 
734
 
See Also   : L<Bio::Search::BlastUtils::tile_hsps>, L<HSP Tiling and Ambiguous Alignments>
735
 
 
736
 
=cut
737
 
 
738
 
#--------------------
739
 
sub ambiguous_aln { 
740
 
#--------------------
741
 
    my $self = shift;
742
 
    if(@_) { $self->{'_ambiguous_aln'} = shift; }
743
 
    $self->{'_ambiguous_aln'} || '-';
744
 
}
745
 
 
746
 
 
747
 
 
748
 
=head2 overlap
749
 
 
750
 
 Usage     : $blast_object->overlap( [integer] );
751
 
 Purpose   : Gets/Sets the allowable amount overlap between different HSP sequences.
752
 
 Example   : $blast_object->overlap(5);
753
 
           : $overlap = $blast_object->overlap;
754
 
 Returns   : Integer.
755
 
 Argument  : integer.
756
 
 Throws    : n/a
757
 
 Status    : Experimental
758
 
 Comments  : Any two HSPs whose sequences overlap by less than or equal
759
 
           : to the overlap() number of resides will be considered separate HSPs
760
 
           : and will not get tiled by Bio::Search::BlastUtils::_adjust_contigs().
761
 
 
762
 
See Also   : L<Bio::Search::BlastUtils::_adjust_contigs()|Bio::Search::BlastUtils>, L<BUGS | BUGS>
763
 
 
764
 
=cut
765
 
 
766
 
#-------------
767
 
sub overlap { 
768
 
#-------------
769
 
    my $self = shift; 
770
 
    if(@_) { $self->{'_overlap'} = shift; }
771
 
    defined $self->{'_overlap'} ? $self->{'_overlap'} : 0;
772
 
}
773
 
 
774
 
 
775
 
 
776
 
 
777
 
 
778
 
 
779
 
=head2 bits
780
 
 
781
 
 Usage     : $hit_object->bits();
782
 
 Purpose   : Gets the BLAST bit score of the best HSP for the current Blast hit.
783
 
 Example   : $bits = $hit_object->bits();
784
 
 Returns   : Integer
785
 
 Argument  : n/a
786
 
 Throws    : Exception if bit score is not set.
787
 
 Comments  : For BLAST1, the non-bit score is listed in the summary line.
788
 
 
789
 
See Also   : L<score()|score>
790
 
 
791
 
=cut
792
 
 
793
 
#---------
794
 
sub bits { 
795
 
#---------
796
 
    my $self = shift; 
797
 
 
798
 
    # The check for $self->{'_bits'} is a remnant from the 'query' mode days
799
 
    # in which the sbjct object would collect data from the description line only.
800
 
 
801
 
    my ($bits);
802
 
    if(not defined($self->{'_bits'})) {
803
 
        $bits = $self->hsp->bits;
804
 
    } else {
805
 
        $bits = $self->{'_bits'}; 
806
 
    } 
807
 
    return $bits;
808
 
}
809
 
 
810
 
 
811
 
 
812
 
=head2 n
813
 
 
814
 
 Usage     : $hit_object->n();
815
 
 Purpose   : Gets the N number for the current Blast hit.
816
 
           : This is the number of HSPs in the set which was ascribed
817
 
           : the lowest P-value (listed on the description line).
818
 
           : This number is not the same as the total number of HSPs.
819
 
           : To get the total number of HSPs, use num_hsps().
820
 
 Example   : $n = $hit_object->n();
821
 
 Returns   : Integer
822
 
 Argument  : n/a
823
 
 Throws    : Exception if HSPs have not been set (BLAST2 reports).
824
 
 Comments  : Note that the N parameter is not reported in gapped BLAST2.
825
 
           : Calling n() on such reports will result in a call to num_hsps().
826
 
           : The num_hsps() method will count the actual number of
827
 
           : HSPs in the alignment listing, which may exceed N in
828
 
           : some cases.
829
 
 
830
 
See Also   : L<num_hsps()|num_hsps>
831
 
 
832
 
=cut
833
 
 
834
 
#-----
835
 
sub n { 
836
 
#-----
837
 
    my $self = shift; 
838
 
 
839
 
    # The check for $self->{'_n'} is a remnant from the 'query' mode days
840
 
    # in which the sbjct object would collect data from the description line only.
841
 
 
842
 
    my ($n);
843
 
    if(not defined($self->{'_n'})) {
844
 
        $n = $self->hsp->n;
845
 
    } else {
846
 
        $n = $self->{'_n'}; 
847
 
    } 
848
 
    $n ||= $self->num_hsps;
849
 
 
850
 
    return $n;
851
 
}
852
 
 
853
 
 
854
 
 
855
 
=head2 frame
856
 
 
857
 
 Usage     : $hit_object->frame();
858
 
 Purpose   : Gets the reading frame for the hit sequence (TBLASTN/X only).
859
 
 Example   : $frame = $hit_object->frame();
860
 
 Returns   : Integer (-3 .. +3).
861
 
 Argument  : n/a
862
 
 Throws    : Exception if HSPs have not been set (BLAST2 reports).
863
 
 
864
 
See Also   : L<hsps()|hsps>
865
 
 
866
 
=cut
867
 
 
868
 
#----------
869
 
sub frame { 
870
 
#----------
871
 
    my $self = shift; 
872
 
 
873
 
    # The check for $self->{'_frame'} is a remnant from the 'query' mode days
874
 
    # in which the sbjct object would collect data from the description line only.
875
 
 
876
 
    my ($frame);
877
 
    if(not defined($self->{'_frame'})) {
878
 
        $frame = $self->hsp->frame;
879
 
    } else {
880
 
        $frame = $self->{'_frame'}; 
881
 
    } 
882
 
    return $frame;
883
 
}
884
 
 
885
 
 
886
 
 
887
 
 
888
 
 
889
 
=head2 p
890
 
 
891
 
 Usage     : $hit_object->p( [format] );
892
 
 Purpose   : Get the P-value for the best HSP of the given BLAST hit.
893
 
           : (Note that P-values are not provided with NCBI Blast2 reports).
894
 
 Example   : $p =  $sbjct->p;
895
 
           : $p =  $sbjct->p('exp');  # get exponent only.
896
 
           : ($num, $exp) =  $sbjct->p('parts');  # split sci notation into parts
897
 
 Returns   : Float or scientific notation number (the raw P-value, DEFAULT).
898
 
           : Integer if format == 'exp' (the magnitude of the base 10 exponent).
899
 
           : 2-element list (float, int) if format == 'parts' and P-value
900
 
           :                is in scientific notation (See Comments).
901
 
 Argument  : format: string of 'raw' | 'exp' | 'parts'
902
 
           :    'raw' returns value given in report. Default. (1.2e-34)
903
 
           :    'exp' returns exponent value only (34)
904
 
           :    'parts' returns the decimal and exponent as a 
905
 
           :            2-element list (1.2, -34) (See Comments).
906
 
 Throws    : Warns if no P-value is defined. Uses expect instead.
907
 
 Comments  : Using the 'parts' argument is not recommended since it will not
908
 
           : work as expected if the P-value is not in scientific notation.
909
 
           : That is, floats are not converted into sci notation before
910
 
           : splitting into parts.
911
 
 
912
 
See Also   : L<expect()|expect>, L<signif()|signif>, L<Bio::Search::BlastUtils::get_exponent()|Bio::Search::BlastUtils>
913
 
 
914
 
=cut
915
 
 
916
 
#--------
917
 
sub p { 
918
 
#--------
919
 
# Some duplication of logic for p(), expect() and signif() for the sake of performance.
920
 
    my ($self, $fmt) = @_;
921
 
 
922
 
    my $val = $self->{'_p'};
923
 
 
924
 
    # $val can be zero.
925
 
    if(not defined $val) {
926
 
        # P-value not defined, must be a NCBI Blast2 report.
927
 
        # Use expect instead.
928
 
        $self->warn( "P-value not defined. Using expect() instead.");
929
 
        $val = $self->{'_expect'};
930
 
    }
931
 
 
932
 
    return $val if not $fmt or $fmt =~ /^raw/i;
933
 
    ## Special formats: exponent-only or as list.
934
 
    return &Bio::Search::BlastUtils::get_exponent($val) if $fmt =~ /^exp/i;
935
 
    return (split (/eE/, $val)) if $fmt =~ /^parts/i;
936
 
 
937
 
    ## Default: return the raw P-value.
938
 
    return $val;
939
 
}
940
 
 
941
 
 
942
 
 
943
 
=head2 expect
944
 
 
945
 
 Usage     : $hit_object->expect( [format] );
946
 
 Purpose   : Get the Expect value for the best HSP of the given BLAST hit.
947
 
 Example   : $e =  $sbjct->expect;
948
 
           : $e =  $sbjct->expect('exp');  # get exponent only.
949
 
           : ($num, $exp) = $sbjct->expect('parts');  # split sci notation into parts
950
 
 Returns   : Float or scientific notation number (the raw expect value, DEFAULT).
951
 
           : Integer if format == 'exp' (the magnitude of the base 10 exponent).
952
 
           : 2-element list (float, int) if format == 'parts' and Expect 
953
 
           :                is in scientific notation (see Comments).
954
 
 Argument  : format: string of 'raw' | 'exp' | 'parts'
955
 
           :    'raw' returns value given in report. Default. (1.2e-34)
956
 
           :    'exp' returns exponent value only (34)
957
 
           :    'parts' returns the decimal and exponent as a 
958
 
           :            2-element list (1.2, -34)  (see Comments).
959
 
 Throws    : Exception if the Expect value is not defined.
960
 
 Comments  : Using the 'parts' argument is not recommended since it will not
961
 
           : work as expected if the expect value is not in scientific notation.
962
 
           : That is, floats are not converted into sci notation before
963
 
           : splitting into parts.
964
 
 
965
 
See Also   : L<p()|p>, L<signif()|signif>, L<Bio::Search::BlastUtils::get_exponent()|Bio::Search::BlastUtils>
966
 
 
967
 
=cut
968
 
 
969
 
#-----------
970
 
sub expect { 
971
 
#-----------
972
 
# Some duplication of logic for p(), expect() and signif() for the sake of performance.
973
 
    my ($self, $fmt) = @_;
974
 
 
975
 
    my $val;
976
 
 
977
 
    # For Blast reports that list the P value on the description line,
978
 
    # getting the expect value requires fully parsing the HSP data.
979
 
    # For NCBI blast, there's no problem.
980
 
    if(not defined($self->{'_expect'})) {
981
 
        if( defined $self->{'_hsps'}) {
982
 
            $self->{'_expect'} = $val = $self->hsp->expect;
983
 
        } else {
984
 
            # If _expect is not set and _hsps are not set, 
985
 
            # then this must be a P-value-based report that was
986
 
            # run without setting the HSPs (shallow parsing).
987
 
            $self->throw("Can't get expect value. HSPs have not been set.");
988
 
        }
989
 
    } else {
990
 
        $val = $self->{'_expect'};
991
 
    }
992
 
 
993
 
    # $val can be zero.
994
 
    defined($val) or $self->throw("Can't get Expect value.");
995
 
 
996
 
    return $val if not $fmt or $fmt =~ /^raw/i;
997
 
    ## Special formats: exponent-only or as list.
998
 
    return &Bio::Search::BlastUtils::get_exponent($val) if $fmt =~ /^exp/i;
999
 
    return (split (/eE/, $val)) if $fmt =~ /^parts/i;
1000
 
 
1001
 
    ## Default: return the raw Expect-value.
1002
 
    return $val;
1003
 
}
1004
 
 
1005
 
 
1006
 
=head2 hsps
1007
 
 
1008
 
 Usage     : $hit_object->hsps();
1009
 
 Purpose   : Get a list containing all HSP objects.
1010
 
           : Get the numbers of HSPs for the current hit.
1011
 
 Example   : @hsps = $hit_object->hsps();
1012
 
           : $num  = $hit_object->hsps();  # alternatively, use num_hsps()
1013
 
 Returns   : Array context : list of Bio::Search::HSP::BlastHSP.pm objects.
1014
 
           : Scalar context: integer (number of HSPs).
1015
 
           :                 (Equivalent to num_hsps()).
1016
 
 Argument  : n/a. Relies on wantarray
1017
 
 Throws    : Exception if the HSPs have not been collected.
1018
 
 
1019
 
See Also   : L<hsp()|hsp>, L<num_hsps()|num_hsps>
1020
 
 
1021
 
=cut
1022
 
 
1023
 
#---------
1024
 
sub hsps {
1025
 
#---------
1026
 
    my $self = shift;
1027
 
 
1028
 
    if (not ref $self->{'_hsps'}) {
1029
 
        $self->throw("Can't get HSPs: data not collected.");
1030
 
    }
1031
 
 
1032
 
    return wantarray 
1033
 
        #  returning list containing all HSPs.
1034
 
        ? @{$self->{'_hsps'}}
1035
 
        #  returning number of HSPs.
1036
 
        : scalar(@{$self->{'_hsps'}});
1037
 
}
1038
 
 
1039
 
 
1040
 
 
1041
 
=head2 hsp
1042
 
 
1043
 
 Usage     : $hit_object->hsp( [string] );
1044
 
 Purpose   : Get a single BlastHSP.pm object for the present BlastHit.pm object.
1045
 
 Example   : $hspObj  = $hit_object->hsp;  # same as 'best'
1046
 
           : $hspObj  = $hit_object->hsp('best');
1047
 
           : $hspObj  = $hit_object->hsp('worst');
1048
 
 Returns   : Object reference for a Bio::Search::HSP::BlastHSP.pm object.
1049
 
 Argument  : String (or no argument).
1050
 
           :   No argument (default) = highest scoring HSP (same as 'best').
1051
 
           :   'best' or 'first' = highest scoring HSP.
1052
 
           :   'worst' or 'last' = lowest scoring HSP.
1053
 
 Throws    : Exception if the HSPs have not been collected.
1054
 
           : Exception if an unrecognized argument is used.
1055
 
 
1056
 
See Also   : L<hsps()|hsps>, L<num_hsps>()
1057
 
 
1058
 
=cut
1059
 
 
1060
 
#----------
1061
 
sub hsp {
1062
 
#----------
1063
 
    my( $self, $option ) = @_;
1064
 
    $option ||= 'best';
1065
 
    
1066
 
    if (not ref $self->{'_hsps'}) {
1067
 
        $self->throw("Can't get HSPs: data not collected.");
1068
 
    }
1069
 
 
1070
 
    my @hsps = @{$self->{'_hsps'}};
1071
 
    
1072
 
    return $hsps[0]      if $option =~ /best|first|1/i;
1073
 
    return $hsps[$#hsps] if $option =~ /worst|last/i;
1074
 
 
1075
 
    $self->throw("Can't get HSP for: $option\n" .
1076
 
                 "Valid arguments: 'best', 'worst'");
1077
 
}
1078
 
 
1079
 
 
1080
 
 
1081
 
=head2 num_hsps
1082
 
 
1083
 
 Usage     : $hit_object->num_hsps();
1084
 
 Purpose   : Get the number of HSPs for the present Blast hit.
1085
 
 Example   : $nhsps = $hit_object->num_hsps();
1086
 
 Returns   : Integer
1087
 
 Argument  : n/a
1088
 
 Throws    : Exception if the HSPs have not been collected.
1089
 
 
1090
 
See Also   : L<hsps()|hsps>
1091
 
 
1092
 
=cut
1093
 
 
1094
 
#-------------
1095
 
sub num_hsps {
1096
 
#-------------
1097
 
    my $self = shift;
1098
 
    
1099
 
    if (not defined $self->{'_hsps'}) {
1100
 
        $self->throw("Can't get HSPs: data not collected.");
1101
 
    }
1102
 
 
1103
 
    return scalar(@{$self->{'_hsps'}});
1104
 
}
1105
 
 
1106
 
 
1107
 
 
1108
 
=head2 logical_length
1109
 
 
1110
 
 Usage     : $hit_object->logical_length( [seq_type] );
1111
 
           : (mostly intended for internal use).
1112
 
 Purpose   : Get the logical length of the hit sequence.
1113
 
           : If the Blast is a TBLASTN or TBLASTX, the returned length 
1114
 
           : is the length of the would-be amino acid sequence (length/3).
1115
 
           : For all other BLAST flavors, this function is the same as length().
1116
 
 Example   : $len    = $hit_object->logical_length();
1117
 
 Returns   : Integer 
1118
 
 Argument  : seq_type = 'query' or 'hit' or 'sbjct' (default = 'query')
1119
 
             ('sbjct' is synonymous with 'hit')
1120
 
 Throws    : n/a
1121
 
 Comments  : This is important for functions like frac_aligned_query()
1122
 
           : which need to operate in amino acid coordinate space when dealing
1123
 
           : with [T]BLAST[NX] type reports.
1124
 
 
1125
 
See Also   : L<length()|length>, L<frac_aligned_query()|frac_aligned_query>, L<frac_aligned_hit()|frac_aligned_hit>
1126
 
 
1127
 
=cut
1128
 
 
1129
 
#--------------------
1130
 
sub logical_length {
1131
 
#--------------------
1132
 
    my $self = shift;
1133
 
    my $seqType = shift || 'query';
1134
 
    $seqType = 'sbjct' if $seqType eq 'hit';
1135
 
 
1136
 
    my $length;
1137
 
 
1138
 
    # For the sbjct, return logical sbjct length
1139
 
    if( $seqType eq 'sbjct' ) {
1140
 
        $length = $self->{'_logical_length'} || $self->{'_length'};
1141
 
    }
1142
 
    else {
1143
 
        # Otherwise, return logical query length
1144
 
        $length = $self->{'_query_length'};
1145
 
 
1146
 
        # Adjust length based on BLAST flavor.
1147
 
        if($self->{'_blast_program'} =~ /T?BLASTX/ ) {
1148
 
            $length /= 3;
1149
 
        }
1150
 
    }
1151
 
    return $length;
1152
 
}
1153
 
 
1154
 
 
1155
 
=head2 length_aln
1156
 
 
1157
 
 Usage     : $hit_object->length_aln( [seq_type] );
1158
 
 Purpose   : Get the total length of the aligned region for query or sbjct seq.
1159
 
           : This number will include all HSPs
1160
 
 Example   : $len    = $hit_object->length_aln(); # default = query
1161
 
           : $lenAln = $hit_object->length_aln('query');
1162
 
 Returns   : Integer 
1163
 
 Argument  : seq_Type = 'query' or 'hit' or 'sbjct' (Default = 'query')
1164
 
             ('sbjct' is synonymous with 'hit')
1165
 
 Throws    : Exception if the argument is not recognized.
1166
 
 Comments  : This method will report the logical length of the alignment,
1167
 
           : meaning that for TBLAST[NX] reports, the length is reported
1168
 
           : using amino acid coordinate space (i.e., nucleotides / 3).
1169
 
           : 
1170
 
           : This method requires that all HSPs be tiled. If they have not
1171
 
           : already been tiled, they will be tiled first automatically..
1172
 
           : If you don't want the tiled data, iterate through each HSP
1173
 
           : calling length() on each (use hsps() to get all HSPs).
1174
 
 
1175
 
See Also   : L<length()|length>, L<frac_aligned_query()|frac_aligned_query>, L<frac_aligned_hit()|frac_aligned_hit>, L<gaps()|gaps>, L<Bio::Search::BlastUtils::tile_hsps()|Bio::Search::BlastUtils>, L<Bio::Search::HSP::BlastHSP::length()|Bio::Search::HSP::BlastHSP>
1176
 
 
1177
 
=cut
1178
 
 
1179
 
#---------------'
1180
 
sub length_aln {
1181
 
#---------------
1182
 
    my( $self, $seqType ) = @_;
1183
 
    
1184
 
    $seqType ||= 'query';
1185
 
    $seqType = 'sbjct' if $seqType eq 'hit';
1186
 
 
1187
 
    Bio::Search::BlastUtils::tile_hsps($self) if not $self->{'_tile_hsps'};
1188
 
 
1189
 
    my $data = $self->{'_length_aln_'.$seqType};
1190
 
    
1191
 
    ## If we don't have data, figure out what went wrong.
1192
 
    if(!$data) {
1193
 
        $self->throw("Can't get length aln for sequence type \"$seqType\"" . 
1194
 
                     "Valid types are 'query', 'hit', 'sbjct' ('sbjct' = 'hit')");
1195
 
    }           
1196
 
    $data;
1197
 
}    
1198
 
 
1199
 
 
1200
 
=head2 gaps
1201
 
 
1202
 
 Usage     : $hit_object->gaps( [seq_type] );
1203
 
 Purpose   : Get the number of gaps in the aligned query, sbjct, or both sequences.
1204
 
           : Data is summed across all HSPs.
1205
 
 Example   : $qgaps = $hit_object->gaps('query');
1206
 
           : $hgaps = $hit_object->gaps('hit');
1207
 
           : $tgaps = $hit_object->gaps();    # default = total (query + hit)
1208
 
 Returns   : scalar context: integer
1209
 
           : array context without args: two-element list of integers  
1210
 
           :    (queryGaps, sbjctGaps)
1211
 
           : Array context can be forced by providing an argument of 'list' or 'array'.
1212
 
           :
1213
 
           : CAUTION: Calling this method within printf or sprintf is arrray context.
1214
 
           : So this function may not give you what you expect. For example:
1215
 
           :          printf "Total gaps: %d", $hit->gaps();
1216
 
           : Actually returns a two-element array, so what gets printed 
1217
 
           : is the number of gaps in the query, not the total
1218
 
           :
1219
 
 Argument  : seq_type: 'query' | 'hit' or 'sbjct' | 'total' | 'list'  (default = 'total')
1220
 
             ('sbjct' is synonymous with 'hit')
1221
 
 Throws    : n/a
1222
 
 Comments  : If you need data for each HSP, use hsps() and then interate
1223
 
           : through each HSP object.
1224
 
           : This method requires that all HSPs be tiled. If they have not
1225
 
           : already been tiled, they will be tiled first automatically..
1226
 
           : Not relying on wantarray since that will fail in situations 
1227
 
           : such as printf "%d", $hit->gaps() in which you might expect to 
1228
 
           : be printing the total gaps, but evaluates to array context.
1229
 
 
1230
 
See Also   : L<length_aln()|length_aln>
1231
 
 
1232
 
=cut
1233
 
 
1234
 
#----------
1235
 
sub gaps {
1236
 
#----------
1237
 
    my( $self, $seqType ) = @_;
1238
 
 
1239
 
    $seqType ||= (wantarray ? 'list' : 'total');
1240
 
    $seqType = 'sbjct' if $seqType eq 'hit';
1241
 
 
1242
 
    Bio::Search::BlastUtils::tile_hsps($self) if not $self->{'_tile_hsps'};
1243
 
 
1244
 
    $seqType = lc($seqType);
1245
 
 
1246
 
    if($seqType =~ /list|array/i) {
1247
 
        return ($self->{'_gaps_query'}, $self->{'_gaps_sbjct'});
1248
 
    }
1249
 
 
1250
 
    if($seqType eq 'total') {
1251
 
        return ($self->{'_gaps_query'} + $self->{'_gaps_sbjct'}) || 0;
1252
 
    } else {
1253
 
        return $self->{'_gaps_'.$seqType} || 0;
1254
 
    }
1255
 
}    
1256
 
 
1257
 
 
1258
 
 
1259
 
=head2 matches
1260
 
 
1261
 
 Usage     : $hit_object->matches( [class] );
1262
 
 Purpose   : Get the total number of identical or conserved matches 
1263
 
           : (or both) across all HSPs.
1264
 
           : (Note: 'conservative' matches are indicated as 'positives' 
1265
 
           :         in the Blast report.)
1266
 
 Example   : ($id,$cons) = $hit_object->matches(); # no argument
1267
 
           : $id = $hit_object->matches('id');
1268
 
           : $cons = $hit_object->matches('cons'); 
1269
 
 Returns   : Integer or a 2-element array of integers 
1270
 
 Argument  : class = 'id' | 'cons' OR none. 
1271
 
           : If no argument is provided, both identical and conservative 
1272
 
           : numbers are returned in a two element list.
1273
 
           : (Other terms can be used to refer to the conservative
1274
 
           :  matches, e.g., 'positive'. All that is checked is whether or
1275
 
           :  not the supplied string starts with 'id'. If not, the 
1276
 
           : conservative matches are returned.)
1277
 
 Throws    : Exception if the requested data cannot be obtained.
1278
 
 Comments  : If you need data for each HSP, use hsps() and then interate
1279
 
           : through the HSP objects.
1280
 
           : Does not rely on wantarray to return a list. Only checks for
1281
 
           : the presence of an argument (no arg = return list).
1282
 
 
1283
 
See Also   : L<Bio::Search::HSP::BlastHSP::matches()|Bio::Search::HSP::BlastHSP>, L<hsps()|hsps>
1284
 
 
1285
 
=cut
1286
 
 
1287
 
#---------------
1288
 
sub matches {
1289
 
#---------------
1290
 
    my( $self, $arg) = @_;
1291
 
    my(@data,$data);
1292
 
 
1293
 
    if(!$arg) {
1294
 
        @data = ($self->{'_totalIdentical'}, $self->{'_totalConserved'});
1295
 
 
1296
 
        return @data if @data;
1297
 
 
1298
 
    } else {
1299
 
 
1300
 
        if($arg =~ /^id/i) { 
1301
 
            $data = $self->{'_totalIdentical'};
1302
 
        } else {
1303
 
            $data = $self->{'_totalConserved'};
1304
 
        }
1305
 
        return $data if $data;
1306
 
    }
1307
 
    
1308
 
    ## Something went wrong if we make it to here.
1309
 
    $self->throw("Can't get identical or conserved data: no data.");
1310
 
}
1311
 
 
1312
 
 
1313
 
=head2 start
1314
 
 
1315
 
 Usage     : $sbjct->start( [seq_type] );
1316
 
 Purpose   : Gets the start coordinate for the query, sbjct, or both sequences
1317
 
           : in the BlastHit object. If there is more than one HSP, the lowest start
1318
 
           : value of all HSPs is returned.
1319
 
 Example   : $qbeg = $sbjct->start('query');
1320
 
           : $sbeg = $sbjct->start('hit');
1321
 
           : ($qbeg, $sbeg) = $sbjct->start();
1322
 
 Returns   : scalar context: integer 
1323
 
           : array context without args: list of two integers (queryStart, sbjctStart)
1324
 
           : Array context can be "induced" by providing an argument of 'list' or 'array'.
1325
 
 Argument  : In scalar context: seq_type = 'query' or 'hit' or 'sbjct' (default = 'query')
1326
 
             ('sbjct' is synonymous with 'hit')
1327
 
 Throws    : n/a
1328
 
 Comments  : This method requires that all HSPs be tiled. If there is more than one
1329
 
           : HSP and they have not already been tiled, they will be tiled first automatically..
1330
 
           : Remember that the start and end coordinates of all HSPs are 
1331
 
           : normalized so that start < end. Strand information can be
1332
 
           : obtained by calling $hit->strand().
1333
 
 
1334
 
See Also   : L<end()|end>, L<range()|range>, L<strand()|strand>, L<HSP Tiling and Ambiguous Alignments>, L<Bio::Search::HSP::BlastHSP::start|Bio::Search::HSP::BlastHSP>
1335
 
 
1336
 
=cut
1337
 
 
1338
 
#----------
1339
 
sub start {
1340
 
#----------
1341
 
    my ($self, $seqType) = @_;
1342
 
 
1343
 
    $seqType ||= (wantarray ? 'list' : 'query');
1344
 
    $seqType = 'sbjct' if $seqType eq 'hit';
1345
 
 
1346
 
    # If there is only one HSP, defer this call to the solitary HSP.
1347
 
    if($self->num_hsps == 1) {
1348
 
        return $self->hsp->start($seqType);
1349
 
    } else {
1350
 
        Bio::Search::BlastUtils::tile_hsps($self) if not $self->{'_tile_hsps'};
1351
 
        if($seqType =~ /list|array/i) {
1352
 
            return ($self->{'_queryStart'}, $self->{'_sbjctStart'});
1353
 
        } else {
1354
 
            ## Sensitive to member name changes.
1355
 
            $seqType = "_\L$seqType\E";
1356
 
            return $self->{$seqType.'Start'};
1357
 
        }
1358
 
    }
1359
 
}
1360
 
 
1361
 
 
1362
 
=head2 end
1363
 
 
1364
 
 Usage     : $sbjct->end( [seq_type] );
1365
 
 Purpose   : Gets the end coordinate for the query, sbjct, or both sequences
1366
 
           : in the BlastHit object. If there is more than one HSP, the largest end
1367
 
           : value of all HSPs is returned.
1368
 
 Example   : $qend = $sbjct->end('query');
1369
 
           : $send = $sbjct->end('hit');
1370
 
           : ($qend, $send) = $sbjct->end();
1371
 
 Returns   : scalar context: integer
1372
 
           : array context without args: list of two integers (queryEnd, sbjctEnd)
1373
 
           : Array context can be "induced" by providing an argument of 'list' or 'array'.
1374
 
 Argument  : In scalar context: seq_type = 'query' or 'sbjct'
1375
 
           :  (case insensitive). If not supplied, 'query' is used.
1376
 
 Throws    : n/a
1377
 
 Comments  : This method requires that all HSPs be tiled. If there is more than one
1378
 
           : HSP and they have not already been tiled, they will be tiled first automatically..
1379
 
           : Remember that the start and end coordinates of all HSPs are 
1380
 
           : normalized so that start < end. Strand information can be
1381
 
           : obtained by calling $hit->strand().
1382
 
 
1383
 
See Also   : L<start()|start>, L<range()|range>, L<strand()|strand>, L<HSP Tiling and Ambiguous Alignments>, L<Bio::Search::HSP::BlastHSP::end|Bio::Search::HSP::BlastHSP>
1384
 
 
1385
 
=cut
1386
 
 
1387
 
#----------
1388
 
sub end {
1389
 
#----------
1390
 
    my ($self, $seqType) = @_;
1391
 
 
1392
 
    $seqType ||= (wantarray ? 'list' : 'query');
1393
 
    $seqType = 'sbjct' if $seqType eq 'hit';
1394
 
 
1395
 
    # If there is only one HSP, defer this call to the solitary HSP.
1396
 
    if($self->num_hsps == 1) {
1397
 
        return $self->hsp->end($seqType);
1398
 
    } else {
1399
 
        Bio::Search::BlastUtils::tile_hsps($self) if not $self->{'_tile_hsps'};
1400
 
        if($seqType =~ /list|array/i) {
1401
 
            return ($self->{'_queryStop'}, $self->{'_sbjctStop'});
1402
 
        } else {
1403
 
            ## Sensitive to member name changes.
1404
 
            $seqType = "_\L$seqType\E";
1405
 
            return $self->{$seqType.'Stop'};
1406
 
        }
1407
 
    }
1408
 
}
1409
 
 
1410
 
=head2 range
1411
 
 
1412
 
 Usage     : $sbjct->range( [seq_type] );
1413
 
 Purpose   : Gets the (start, end) coordinates for the query or sbjct sequence
1414
 
           : in the HSP alignment.
1415
 
 Example   : ($qbeg, $qend) = $sbjct->range('query');
1416
 
           : ($sbeg, $send) = $sbjct->range('hit');
1417
 
 Returns   : Two-element array of integers 
1418
 
 Argument  : seq_type = string, 'query' or 'hit' or 'sbjct'  (default = 'query')
1419
 
             ('sbjct' is synonymous with 'hit')
1420
 
 Throws    : n/a
1421
 
 
1422
 
See Also   : L<start()|start>, L<end()|end>
1423
 
 
1424
 
=cut
1425
 
 
1426
 
#----------
1427
 
sub range {
1428
 
#----------
1429
 
    my ($self, $seqType) = @_;
1430
 
    $seqType ||= 'query';
1431
 
    $seqType = 'sbjct' if $seqType eq 'hit';
1432
 
    return ($self->start($seqType), $self->end($seqType));
1433
 
}
1434
 
 
1435
 
 
1436
 
=head2 frac_identical
1437
 
 
1438
 
 Usage     : $hit_object->frac_identical( [seq_type] );
1439
 
 Purpose   : Get the overall fraction of identical positions across all HSPs.
1440
 
           : The number refers to only the aligned regions and does not
1441
 
           : account for unaligned regions in between the HSPs, if any.
1442
 
 Example   : $frac_iden = $hit_object->frac_identical('query');
1443
 
 Returns   : Float (2-decimal precision, e.g., 0.75).
1444
 
 Argument  : seq_type: 'query' | 'hit' or 'sbjct' | 'total'
1445
 
           : default = 'query' (but see comments below).
1446
 
           : ('sbjct' is synonymous with 'hit')
1447
 
 Throws    : n/a
1448
 
 Comments  : Different versions of Blast report different values for the total
1449
 
           : length of the alignment. This is the number reported in the
1450
 
           : denominators in the stats section:
1451
 
           : "Identical = 34/120 Positives = 67/120".
1452
 
           : NCBI BLAST uses the total length of the alignment (with gaps)
1453
 
           : WU-BLAST uses the length of the query sequence (without gaps).
1454
 
           :
1455
 
           : Therefore, when called with an argument of 'total',
1456
 
           : this method will report different values depending on the
1457
 
           : version of BLAST used. Total does NOT take into account HSP
1458
 
           : tiling, so it should not be used.
1459
 
           :
1460
 
           : To get the fraction identical among only the aligned residues,
1461
 
           : ignoring the gaps, call this method without an argument or 
1462
 
           : with an argument of 'query' or 'hit'.
1463
 
           :
1464
 
           : If you need data for each HSP, use hsps() and then iterate
1465
 
           : through the HSP objects.
1466
 
           : This method requires that all HSPs be tiled. If they have not
1467
 
           : already been tiled, they will be tiled first automatically.
1468
 
 
1469
 
See Also   : L<frac_conserved()|frac_conserved>, L<frac_aligned_query()|frac_aligned_query>, L<matches()|matches>, L<Bio::Search::BlastUtils::tile_hsps()|Bio::Search::BlastUtils>
1470
 
 
1471
 
=cut
1472
 
 
1473
 
#------------------
1474
 
sub frac_identical {
1475
 
#------------------
1476
 
    my ($self, $seqType) = @_;
1477
 
    $seqType ||= 'query';
1478
 
    $seqType = 'sbjct' if $seqType eq 'hit';
1479
 
 
1480
 
    ## Sensitive to member name format.
1481
 
    $seqType = lc($seqType);
1482
 
 
1483
 
    Bio::Search::BlastUtils::tile_hsps($self) if not $self->{'_tile_hsps'};
1484
 
 
1485
 
    sprintf( "%.2f", $self->{'_totalIdentical'}/$self->{'_length_aln_'.$seqType});
1486
 
}
1487
 
 
1488
 
 
1489
 
 
1490
 
=head2 frac_conserved
1491
 
 
1492
 
 Usage     : $hit_object->frac_conserved( [seq_type] );
1493
 
 Purpose   : Get the overall fraction of conserved positions across all HSPs.
1494
 
           : The number refers to only the aligned regions and does not
1495
 
           : account for unaligned regions in between the HSPs, if any.
1496
 
 Example   : $frac_cons = $hit_object->frac_conserved('hit');
1497
 
 Returns   : Float (2-decimal precision, e.g., 0.75).
1498
 
 Argument  : seq_type: 'query' | 'hit' or 'sbjct' | 'total'
1499
 
           : default = 'query' (but see comments below).
1500
 
           : ('sbjct' is synonymous with 'hit')
1501
 
 Throws    : n/a
1502
 
 Comments  : Different versions of Blast report different values for the total
1503
 
           : length of the alignment. This is the number reported in the
1504
 
           : denominators in the stats section:
1505
 
           : "Positives = 34/120 Positives = 67/120".
1506
 
           : NCBI BLAST uses the total length of the alignment (with gaps)
1507
 
           : WU-BLAST uses the length of the query sequence (without gaps).
1508
 
           :
1509
 
           : Therefore, when called with an argument of 'total',
1510
 
           : this method will report different values depending on the
1511
 
           : version of BLAST used. Total does NOT take into account HSP
1512
 
           : tiling, so it should not be used.
1513
 
           :
1514
 
           : To get the fraction conserved among only the aligned residues,
1515
 
           : ignoring the gaps, call this method without an argument or 
1516
 
           : with an argument of 'query' or 'hit'.
1517
 
           :
1518
 
           : If you need data for each HSP, use hsps() and then interate
1519
 
           : through the HSP objects.
1520
 
           : This method requires that all HSPs be tiled. If they have not
1521
 
           : already been tiled, they will be tiled first automatically.
1522
 
 
1523
 
See Also   : L<frac_identical()|frac_identical>, L<matches()|matches>, L<Bio::Search::BlastUtils::tile_hsps()|Bio::Search::BlastUtils>
1524
 
 
1525
 
=cut
1526
 
 
1527
 
#--------------------
1528
 
sub frac_conserved {
1529
 
#--------------------
1530
 
    my ($self, $seqType) = @_;
1531
 
    $seqType ||= 'query';
1532
 
    $seqType = 'sbjct' if $seqType eq 'hit';
1533
 
 
1534
 
    ## Sensitive to member name format.
1535
 
    $seqType = lc($seqType);
1536
 
 
1537
 
    Bio::Search::BlastUtils::tile_hsps($self) if not $self->{'_tile_hsps'};
1538
 
 
1539
 
    sprintf( "%.2f", $self->{'_totalConserved'}/$self->{'_length_aln_'.$seqType});
1540
 
}
1541
 
 
1542
 
 
1543
 
 
1544
 
 
1545
 
=head2 frac_aligned_query
1546
 
 
1547
 
 Usage     : $hit_object->frac_aligned_query();
1548
 
 Purpose   : Get the fraction of the query sequence which has been aligned
1549
 
           : across all HSPs (not including intervals between non-overlapping
1550
 
           : HSPs).
1551
 
 Example   : $frac_alnq = $hit_object->frac_aligned_query();
1552
 
 Returns   : Float (2-decimal precision, e.g., 0.75).
1553
 
 Argument  : n/a
1554
 
 Throws    : n/a
1555
 
 Comments  : If you need data for each HSP, use hsps() and then interate
1556
 
           : through the HSP objects.
1557
 
           : To compute the fraction aligned, the logical length of the query
1558
 
           : sequence is used, meaning that for [T]BLASTX reports, the 
1559
 
           : full length of the query sequence is converted into amino acids
1560
 
           : by dividing by 3. This is necessary because of the way 
1561
 
           : the lengths of aligned sequences are computed.
1562
 
           : This method requires that all HSPs be tiled. If they have not
1563
 
           : already been tiled, they will be tiled first automatically.
1564
 
 
1565
 
See Also   : L<frac_aligned_hit()|frac_aligned_hit>, L<logical_length()|logical_length>, L<length_aln()|length_aln>,  L<Bio::Search::BlastUtils::tile_hsps()|Bio::Search::BlastUtils>
1566
 
 
1567
 
=cut
1568
 
 
1569
 
#----------------------
1570
 
sub frac_aligned_query {
1571
 
#----------------------
1572
 
    my $self = shift;
1573
 
 
1574
 
    Bio::Search::BlastUtils::tile_hsps($self) if not $self->{'_tile_hsps'};
1575
 
 
1576
 
    sprintf( "%.2f", $self->{'_length_aln_query'}/$self->logical_length('query'));
1577
 
}
1578
 
 
1579
 
 
1580
 
 
1581
 
=head2 frac_aligned_hit
1582
 
 
1583
 
 Usage     : $hit_object->frac_aligned_hit();
1584
 
 Purpose   : Get the fraction of the hit (sbjct) sequence which has been aligned
1585
 
           : across all HSPs (not including intervals between non-overlapping
1586
 
           : HSPs).
1587
 
 Example   : $frac_alnq = $hit_object->frac_aligned_hit();
1588
 
 Returns   : Float (2-decimal precision, e.g., 0.75).
1589
 
 Argument  : n/a
1590
 
 Throws    : n/a
1591
 
 Comments  : If you need data for each HSP, use hsps() and then interate
1592
 
           : through the HSP objects.
1593
 
           : To compute the fraction aligned, the logical length of the sbjct
1594
 
           : sequence is used, meaning that for TBLAST[NX] reports, the 
1595
 
           : full length of the sbjct sequence is converted into amino acids
1596
 
           : by dividing by 3. This is necessary because of the way 
1597
 
           : the lengths of aligned sequences are computed.
1598
 
           : This method requires that all HSPs be tiled. If they have not
1599
 
           : already been tiled, they will be tiled first automatically.
1600
 
 
1601
 
See Also   : L<frac_aligned_query()|frac_aligned_query>, L<matches()|matches>, , L<logical_length()|logical_length>, L<length_aln()|length_aln>,  L<Bio::Search::BlastUtils::tile_hsps()|Bio::Search::BlastUtils>
1602
 
 
1603
 
=cut
1604
 
 
1605
 
#--------------------
1606
 
sub frac_aligned_hit {
1607
 
#--------------------
1608
 
    my $self = shift;
1609
 
 
1610
 
    Bio::Search::BlastUtils::tile_hsps($self) if not $self->{'_tile_hsps'};
1611
 
 
1612
 
    sprintf( "%.2f", $self->{'_length_aln_sbjct'}/$self->logical_length('sbjct'));
1613
 
}
1614
 
 
1615
 
 
1616
 
## These methods are being maintained for backward compatibility. 
1617
 
 
1618
 
=head2 frac_aligned_sbjct
1619
 
 
1620
 
Same as L<frac_aligned_hit()|frac_aligned_hit>
1621
 
 
1622
 
=cut
1623
 
 
1624
 
#----------------
1625
 
sub frac_aligned_sbjct {  my $self=shift; $self->frac_aligned_hit(@_); }
1626
 
#----------------
1627
 
 
1628
 
=head2 num_unaligned_sbjct
1629
 
 
1630
 
Same as L<num_unaligned_hit()|num_unaligned_hit>
1631
 
 
1632
 
=cut
1633
 
 
1634
 
#----------------
1635
 
sub num_unaligned_sbjct {  my $self=shift; $self->num_unaligned_hit(@_); }
1636
 
#----------------
1637
 
 
1638
 
 
1639
 
 
1640
 
=head2 num_unaligned_hit
1641
 
 
1642
 
 Usage     : $hit_object->num_unaligned_hit();
1643
 
 Purpose   : Get the number of the unaligned residues in the hit sequence.
1644
 
           : Sums across all all HSPs.
1645
 
 Example   : $num_unaln = $hit_object->num_unaligned_hit();
1646
 
 Returns   : Integer
1647
 
 Argument  : n/a
1648
 
 Throws    : n/a
1649
 
 Comments  : See notes regarding logical lengths in the comments for frac_aligned_hit().
1650
 
           : They apply here as well.
1651
 
           : If you need data for each HSP, use hsps() and then interate
1652
 
           : through the HSP objects.
1653
 
           : This method requires that all HSPs be tiled. If they have not
1654
 
           : already been tiled, they will be tiled first automatically..
1655
 
 
1656
 
See Also   : L<num_unaligned_query()|num_unaligned_query>,  L<Bio::Search::BlastUtils::tile_hsps()|Bio::Search::BlastUtils>, L<frac_aligned_hit()|frac_aligned_hit>
1657
 
 
1658
 
=cut
1659
 
 
1660
 
#---------------------
1661
 
sub num_unaligned_hit {
1662
 
#---------------------
1663
 
    my $self = shift;
1664
 
 
1665
 
    Bio::Search::BlastUtils::tile_hsps($self) if not $self->{'_tile_hsps'};
1666
 
 
1667
 
    my $num = $self->logical_length('sbjct') - $self->{'_length_aln_sbjct'};
1668
 
    ($num < 0 ? 0 : $num );
1669
 
}
1670
 
 
1671
 
 
1672
 
=head2 num_unaligned_query
1673
 
 
1674
 
 Usage     : $hit_object->num_unaligned_query();
1675
 
 Purpose   : Get the number of the unaligned residues in the query sequence.
1676
 
           : Sums across all all HSPs.
1677
 
 Example   : $num_unaln = $hit_object->num_unaligned_query();
1678
 
 Returns   : Integer
1679
 
 Argument  : n/a
1680
 
 Throws    : n/a
1681
 
 Comments  : See notes regarding logical lengths in the comments for frac_aligned_query().
1682
 
           : They apply here as well.
1683
 
           : If you need data for each HSP, use hsps() and then interate
1684
 
           : through the HSP objects.
1685
 
           : This method requires that all HSPs be tiled. If they have not
1686
 
           : already been tiled, they will be tiled first automatically..
1687
 
 
1688
 
See Also   : L<num_unaligned_hit()|num_unaligned_hit>, L<frac_aligned_query()|frac_aligned_query>,  L<Bio::Search::BlastUtils::tile_hsps()|Bio::Search::BlastUtils>
1689
 
 
1690
 
=cut
1691
 
 
1692
 
#-----------------------
1693
 
sub num_unaligned_query {
1694
 
#-----------------------
1695
 
    my $self = shift;
1696
 
 
1697
 
    Bio::Search::BlastUtils::tile_hsps($self) if not $self->{'_tile_hsps'};
1698
 
 
1699
 
    my $num = $self->logical_length('query') - $self->{'_length_aln_query'};
1700
 
    ($num < 0 ? 0 : $num );
1701
 
}
1702
 
 
1703
 
 
1704
 
 
1705
 
=head2 seq_inds
1706
 
 
1707
 
 Usage     : $hit->seq_inds( seq_type, class, collapse );
1708
 
 Purpose   : Get a list of residue positions (indices) across all HSPs
1709
 
           : for identical or conserved residues in the query or sbjct sequence.
1710
 
 Example   : @s_ind = $hit->seq_inds('query', 'identical');
1711
 
           : @h_ind = $hit->seq_inds('hit', 'conserved');
1712
 
           : @h_ind = $hit->seq_inds('hit', 'conserved', 1);
1713
 
 Returns   : Array of integers 
1714
 
           : May include ranges if collapse is non-zero.
1715
 
 Argument  : [0] seq_type  = 'query' or 'hit' or 'sbjct'  (default = 'query')
1716
 
           :                 ('sbjct' is synonymous with 'hit')
1717
 
           : [1] class     = 'identical' or 'conserved' (default = 'identical')
1718
 
           :              (can be shortened to 'id' or 'cons')
1719
 
           :              (actually, anything not 'id' will evaluate to 'conserved').
1720
 
           : [2] collapse  = boolean, if non-zero, consecutive positions are merged
1721
 
           :             using a range notation, e.g., "1 2 3 4 5 7 9 10 11" 
1722
 
           :             collapses to "1-5 7 9-11". This is useful for 
1723
 
           :             consolidating long lists. Default = no collapse.
1724
 
 Throws    : n/a.
1725
 
 
1726
 
See Also   : L<Bio::Search::HSP::BlastHSP::seq_inds()|Bio::Search::HSP::BlastHSP>
1727
 
 
1728
 
=cut
1729
 
 
1730
 
#-------------
1731
 
sub seq_inds {
1732
 
#-------------
1733
 
    my ($self, $seqType, $class, $collapse) = @_;
1734
 
 
1735
 
    $seqType  ||= 'query';
1736
 
    $class ||= 'identical';
1737
 
    $collapse ||= 0;
1738
 
 
1739
 
    $seqType = 'sbjct' if $seqType eq 'hit';
1740
 
 
1741
 
    my (@inds, $hsp);
1742
 
    foreach $hsp ($self->hsps) {
1743
 
        # This will merge data for all HSPs together.
1744
 
        push @inds, $hsp->seq_inds($seqType, $class);
1745
 
    }
1746
 
    
1747
 
    # Need to remove duplicates and sort the merged positions.
1748
 
    if(@inds) {
1749
 
        my %tmp = map { $_, 1 } @inds;
1750
 
        @inds = sort {$a <=> $b} keys %tmp;
1751
 
    }
1752
 
 
1753
 
    $collapse ?  &Bio::Search::BlastUtils::collapse_nums(@inds) : @inds; 
1754
 
}
1755
 
 
 
101
  my($class,@args) = @_;
 
102
 
 
103
  my $self = $class->SUPER::new(@args);
 
104
  my ($iter,$found) = $self->_rearrange([qw(ITERATION 
 
105
                                            FOUND_AGAIN
 
106
                                           )], @args);
 
107
 
 
108
  defined $iter   && $self->iteration($iter);
 
109
  defined $found  && $self->found_again($found);
 
110
 
 
111
  return $self;
 
112
}
1756
113
 
1757
114
=head2 iteration
1758
115
 
1759
 
 Usage     : $sbjct->iteration( );
 
116
 Usage     : $hit->iteration( $iteration_num );
1760
117
 Purpose   : Gets the iteration number in which the Hit was found.
1761
118
 Example   : $iteration_num = $sbjct->iteration();
1762
119
 Returns   : Integer greater than or equal to 1
1763
120
             Non-PSI-BLAST reports will report iteration as 1, but this number
1764
121
             is only meaningful for PSI-BLAST reports.
1765
 
 Argument  : none
 
122
 Argument  : iteration_num (optional, used when setting only)
1766
123
 Throws    : none
1767
124
 
1768
125
See Also   : L<found_again()|found_again>
1769
126
 
1770
127
=cut
1771
128
 
1772
 
#----------------
1773
 
sub iteration { shift->{'_iteration'} }
1774
 
#----------------
1775
 
 
 
129
sub iteration{
 
130
   my ($self,$value) = @_;
 
131
   if( defined $value) {
 
132
      $self->{'_psiblast_iteration'} = $value;
 
133
    }
 
134
    return $self->{'_psiblast_iteration'};
 
135
}
1776
136
 
1777
137
=head2 found_again
1778
138
 
1779
 
 Usage     : $sbjct->found_again;
 
139
 Title     : found_again
 
140
 Usage     : $hit->found_again;
 
141
             $hit->found_again(1);
1780
142
 Purpose   : Gets a boolean indicator whether or not the hit has
1781
143
             been found in a previous iteration.
1782
144
             This is only applicable to PSI-BLAST reports.
1783
145
 
1784
 
             This method indicates if the hit was reported in the 
1785
 
             "Sequences used in model and found again" section of the
1786
 
             PSI-BLAST report or if it was reported in the
1787
 
             "Sequences not found previously or not previously below threshold"
1788
 
             section of the PSI-BLAST report. Only for hits in iteration > 1.
 
146
              This method indicates if the hit was reported in the 
 
147
              "Sequences used in model and found again" section of the
 
148
              PSI-BLAST report or if it was reported in the
 
149
              "Sequences not found previously or not previously below threshold"
 
150
              section of the PSI-BLAST report. Only for hits in iteration > 1.
1789
151
 
1790
 
 Example   : if( $sbjct->found_again()) { ... };
1791
 
 Returns   : Boolean (1 or 0) for PSI-BLAST report iterations greater than 1.
1792
 
             Returns undef for PSI-BLAST report iteration 1 and non PSI_BLAST
1793
 
             reports.
1794
 
 Argument  : none
 
152
 Example   : if( $hit->found_again()) { ... };
 
153
 Returns   : Boolean, true (1) if the hit has been found in a 
 
154
             previous PSI-BLAST iteration.
 
155
             Returns false (0 or undef) for hits that have not occurred in a
 
156
             previous PSI-BLAST iteration.
 
157
 Argument  : Boolean (1 or 0). Only used for setting.
1795
158
 Throws    : none
1796
159
 
1797
 
See Also   : L<found_again()|found_again>
1798
 
 
1799
 
=cut
1800
 
 
1801
 
#----------------
1802
 
sub found_again { shift->{'_found_again'} }
1803
 
#----------------
1804
 
 
1805
 
 
1806
 
=head2 strand
1807
 
 
1808
 
 Usage     : $sbjct->strand( [seq_type] );
1809
 
 Purpose   : Gets the strand(s) for the query, sbjct, or both sequences
1810
 
           : in the BlastHit object. 
1811
 
 Example   : $qstrand = $sbjct->strand('query');
1812
 
           : $sstrand = $sbjct->strand('hit');
1813
 
           : ($qstrand, $sstrand) = $sbjct->strand();
1814
 
 Returns   : scalar context: integer '1', '-1', or '-1/1'
1815
 
           : if there are HSPs on both strands.
1816
 
           : array context without args: list of two strings (queryStrand, sbjctStrand)
1817
 
           : Array context can be "induced" by providing an argument of 'list' or 'array'.
1818
 
 Argument  : In scalar context: seq_type = 'query' or 'hit' or 'sbjct' (default = 'query')
1819
 
             ('sbjct' is synonymous with 'hit')
1820
 
 Throws    : n/a
1821
 
 
1822
 
See Also   : B<Bio::Search::HSP::BlastHSP::strand>()
1823
 
 
1824
 
=cut
1825
 
 
1826
 
#----------
1827
 
sub strand {
1828
 
#----------
1829
 
    my ($self, $seqType) = @_;
1830
 
 
1831
 
    $seqType ||= (wantarray ? 'list' : 'query');
1832
 
    $seqType = 'sbjct' if $seqType eq 'hit';
1833
 
 
1834
 
    # If there is only one HSP, defer this call to the solitary HSP.
1835
 
    if($self->num_hsps == 1) {
1836
 
        return $self->hsp->strand($seqType);
1837
 
    } else {
1838
 
        # otherwise, iterate through all HSPs collecting strand info.
1839
 
        my (%qstr, %hstr);
1840
 
        foreach my $hsp( $self->hsps ) {
1841
 
            my ( $q, $h ) = $hsp->strand();
1842
 
            $qstr{ $q }++;
1843
 
            $hstr{ $h }++;
1844
 
        }
1845
 
        my $qstr = join( '/', sort keys %qstr);
1846
 
        my $hstr = join( '/', sort keys %hstr);
1847
 
        if($seqType =~ /list|array/i) {
1848
 
            return ($qstr, $hstr);
1849
 
        } elsif( $seqType eq 'query' ) {
1850
 
            return $qstr;
1851
 
        } else {
1852
 
            return $hstr;
1853
 
        }
1854
 
    }
 
160
See Also   : L<iteration()|iteration>
 
161
 
 
162
=cut
 
163
 
 
164
sub found_again {
 
165
   my $self = shift;
 
166
   return $self->{'_found_again'} = shift if @_;
 
167
   return $self->{'_found_again'};
1855
168
}
1856
169
 
1857
170
 
1858
 
1;
1859
 
__END__
1860
 
 
1861
 
#####################################################################################
1862
 
#                                END OF CLASS                                       #
1863
 
#####################################################################################
1864
 
 
1865
 
 
1866
 
=head1 FOR DEVELOPERS ONLY
1867
 
 
1868
 
=head2 Data Members
1869
 
 
1870
 
Information about the various data members of this module is provided for those 
1871
 
wishing to modify or understand the code. Two things to bear in mind: 
1872
 
 
1873
 
=over 4
1874
 
 
1875
 
=item 1 Do NOT rely on these in any code outside of this module. 
1876
 
 
1877
 
All data members are prefixed with an underscore to signify that they are private.
1878
 
Always use accessor methods. If the accessor doesn't exist or is inadequate, 
1879
 
create or modify an accessor (and let me know, too!). (An exception to this might
1880
 
be for BlastHSP.pm which is more tightly coupled to BlastHit.pm and
1881
 
may access BlastHit data members directly for efficiency purposes, but probably 
1882
 
should not).
1883
 
 
1884
 
=item 2 This documentation may be incomplete and out of date.
1885
 
 
1886
 
It is easy for these data member descriptions to become obsolete as 
1887
 
this module is still evolving. Always double check this info and search 
1888
 
for members not described here.
1889
 
 
1890
 
=back
1891
 
 
1892
 
An instance of Bio::Search::Hit::BlastHit.pm is a blessed reference to a hash containing
1893
 
all or some of the following fields:
1894
 
 
1895
 
 FIELD           VALUE
1896
 
 --------------------------------------------------------------
1897
 
 _hsps          : Array ref for a list of Bio::Search::HSP::BlastHSP.pm objects.
1898
 
                :
1899
 
 _db            : Database identifier from the summary line.
1900
 
                :
1901
 
 _desc          : Description data for the hit from the summary line.
1902
 
                :
1903
 
 _length        : Total length of the hit sequence. 
1904
 
                :
1905
 
 _score         : BLAST score.
1906
 
                :
1907
 
 _bits          : BLAST score (in bits). Matrix-independent.
1908
 
                :
1909
 
 _p             : BLAST P value. Obtained from summary section. (Blast1/WU-Blast only)
1910
 
                :
1911
 
 _expect        : BLAST Expect value. Obtained from summary section.
1912
 
                :
1913
 
 _n             : BLAST N value (number of HSPs) (Blast1/WU-Blast2 only)
1914
 
                :
1915
 
 _frame         : Reading frame for TBLASTN and TBLASTX analyses.
1916
 
                :
1917
 
 _totalIdentical: Total number of identical aligned monomers.
1918
 
                :
1919
 
 _totalConserved: Total number of conserved aligned monomers (a.k.a. "positives").
1920
 
                :
1921
 
 _overlap       : Maximum number of overlapping residues between adjacent HSPs
1922
 
                : before considering the alignment to be ambiguous. 
1923
 
                :
1924
 
 _ambiguous_aln : Boolean. True if the alignment of all HSPs is ambiguous.
1925
 
                :
1926
 
 _length_aln_query : Length of the aligned region of the query sequence.
1927
 
                   :
1928
 
 _length_aln_sbjct : Length of the aligned region of the sbjct sequence.
1929
 
 
1930
 
 
1931
 
=cut
 
171
sub expect { shift->significance(@_) }
 
172
 
1932
173
 
1933
174
1;