Bio/Search/HSP/PullHSPI.pm

filter: Statementstmt 48.7% 99 / 203 Branchbran 32.2% 38 / 118 Conditioncond 23.7% 14 / 59 MC/DCmcdc 3.1% 1 / 32 Subroutinesub 53.1% 17 / 32 Podpod 100% 28 / 28 totaltotal 41.7% 197 / 472 CC 83 SCAR 36.5
CC
83
Cov
40%
matches
182.0
frac_conserved
56.0
gaps
56.0
CRAP 38.4
« Bio/Matrix/PSM/ProtMatrix.pm ↑ Summary Bio/CodonUsage/IO.pm »
1 #
2 # BioPerl module for Bio::Search::HSP::PullHSPI
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Sendu Bala <bix@sendu.me.uk>
7 #
8 # You may distribute this module under the same terms as perl itself
9  
10 # POD documentation - main docs before the code
11  
12 =head1 NAME
13  
14 Bio::Search::HSP::PullHSPI - Bio::Search::HSP::HSPI interface for pull parsers.
15  
16 =head1 SYNOPSIS
17  
18 # This is an interface and cannot be instantiated
19  
20 # generally we use Bio::SearchIO to build these objects
21 use Bio::SearchIO;
22 my $in = Bio::SearchIO->new(-format => 'hmmer_pull',
23 -file => 'result.hmmer');
24  
25 while (my $result = $in->next_result) {
26 while (my $hit = $result->next_hit) {
27 while (my $hsp = $hit->next_hsp) {
28 $r_type = $hsp->algorithm;
29 $pvalue = $hsp->p();
30 $evalue = $hsp->evalue();
31 $frac_id = $hsp->frac_identical( ['query'|'hit'|'total'] );
32 $frac_cons = $hsp->frac_conserved( ['query'|'hit'|'total'] );
33 $gaps = $hsp->gaps( ['query'|'hit'|'total'] );
34 $qseq = $hsp->query_string;
35 $hseq = $hsp->hit_string;
36 $homo_string = $hsp->homology_string;
37 $len = $hsp->length( ['query'|'hit'|'total'] );
38 $len = $hsp->length( ['query'|'hit'|'total'] );
39 $rank = $hsp->rank;
40 }
41 }
42 }
43  
44  
45 =head1 DESCRIPTION
46  
47 PullHSP is for fast implementations that only do parsing work on the hsp
48 data when you actually request information by calling one of the HSPI
49 methods.
50  
51 Many methods of HSPI are implemented in a way suitable for inheriting classes
52 that use Bio::PullParserI. It only really makes sense for PullHSP modules to be
53 created by (and have as a -parent) PullHit modules.
54  
55 In addition to the usual -chunk and -parent, -hsp_data is all you should supply
56 when making a PullHSP object. This will store that data and make it accessible
57 via _raw_hsp_data, which you can access in your subclass. It would be best to
58 simply provide the data as the input -chunk instead, if the raw data is large
59 enough.
60  
61 =head1 SEE ALSO
62  
63 This module inherits methods from these other modules:
64  
65 L<Bio::SeqFeatureI>,
66 L<Bio::SeqFeature::FeaturePair>
67 L<Bio::SeqFeature::SimilarityPair>
68  
69 Please refer to these modules for documentation of the
70 many additional inherited methods.
71  
72 =head1 FEEDBACK
73  
74 =head2 Mailing Lists
75  
76 User feedback is an integral part of the evolution of this and other
77 Bioperl modules. Send your comments and suggestions preferably to
78 the Bioperl mailing list. Your participation is much appreciated.
79  
80 bioperl-l@bioperl.org - General discussion
81 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
82  
83 =head2 Support
84  
85 Please direct usage questions or support issues to the mailing list:
86  
87 I<bioperl-l@bioperl.org>
88  
89 rather than to the module maintainer directly. Many experienced and
90 reponsive experts will be able look at the problem and quickly
91 address it. Please include a thorough description of the problem
92 with code and data examples if at all possible.
93  
94 =head2 Reporting Bugs
95  
96 Report bugs to the Bioperl bug tracking system to help us keep track
97 of the bugs and their resolution. Bug reports can be submitted via the
98 web:
99  
100 https://github.com/bioperl/bioperl-live/issues
101  
102 =head1 AUTHOR - Sendu Bala
103  
104 Email bix@sendu.me.uk
105  
106 =head1 COPYRIGHT
107  
108 Copyright (c) 2006 Sendu Bala. All Rights Reserved.
109  
110 =head1 DISCLAIMER
111  
112 This software is provided "as is" without warranty of any kind.
113  
114 =head1 APPENDIX
115  
116 The rest of the documentation details each of the object methods.
117 Internal methods are usually preceded with a _
118  
119 =cut
120  
121 # Let the code begin...
122  
123 package Bio::Search::HSP::PullHSPI;
124 6 $Bio::Search::HSP::PullHSPI::VERSION = '1.7.8';
125  
126 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
127  
128 6 ▶use base qw(Bio::Search::HSP::HSPI Bio::PullParserI);
Subroutine BEGIN: called CC=1 SCAR=0.0
129  
130 =head2 _setup
131  
132 Title : _setup
133 Usage : $self->_setup(@args)
134 Function: Implementers should call this to setup common fields and deal with
135 common arguments to new().
136 Returns : n/a
137 Args : @args received in new().
138  
139 =cut
140  
141 145 ▶sub _setup {
Subroutine _setup: called CC=7 SCAR=21.1
142 145 my ($self, @args) = @_;
143
144 # fields most subclasses probably will want
145 145 $self->_fields( { ( hsp_length => undef,
146 identical => undef,
147 percent_identity => undef,
148 conserved => undef,
149 hsp_gaps => undef,
150 query_gaps => undef,
151 hit_gaps => undef,
152 evalue => undef,
153 pvalue => undef,
154 score => undef,
155 query_start => undef,
156 query_end => undef,
157 query_string => undef,
158 hit_start => undef,
159 hit_end => undef,
160 hit_string => undef,
161 homology_string => undef,
162 rank => undef,
163 seq_inds => undef,
164 hit_identical_inds => undef,
165 hit_conserved_inds => undef,
166 hit_nomatch_inds => undef,
167 hit_gap_inds => undef,
168 query_identical_inds => undef,
169 query_conserved_inds => undef,
170 query_nomatch_inds => undef,
171 query_gap_inds => undef ) } );
172
173 145 my ($parent, $chunk, $hsp_data) = $self->_rearrange([qw(PARENT
174 CHUNK
175 HSP_DATA)], @args);
176
177 145 ▶ $self->throw("Need -parent or -chunk to be defined") unless defined $parent || $chunk;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parent or $chunk 0 145 145
Condition33%1/3
defined $parent or $chunk
l!l&&r!l&&!r
14500
MC/DC0%0/2
defined $parent or $chunk
defined $parent $chunk
Truth table33%1/3
A or B
A= defined $parentB= $chunk
ABresult
1X1
011
000
178
179 145 ▶ $self->parent($parent) if $parent;
Branch: 1 branch
BranchTrueFalseTotal
if $parent 145 0 145
180
181 145 ▶ if ($chunk) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk) 145 0 145
182 145 my ($io, $start, $end) = (undef, 0, undef);
183 145 ▶ if (ref($chunk) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $chunk eq 'ARRAY') { } 145 0 145
184 145 ($io, $start, $end) = @{$chunk};
185 }
186 else {
187 0 $io = $chunk;
188 }
189 145 $self->chunk($io, -start => $start, -end => $end);
190 }
191
192 145 ▶ $self->_raw_hsp_data($hsp_data) if $hsp_data;
Branch: 1 branch
BranchTrueFalseTotal
if $hsp_data 0 145 145
193
194 145 return $self;
195 }
196  
197 0 ▶sub _raw_hsp_data {
Subroutine _raw_hsp_data: not called CC=2 SCAR=17.9
198 0 my $self = shift;
199 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
200 0 $self->{_raw_hsp_data} = shift;
201 }
202 0 return $self->{_raw_hsp_data};
203 }
204  
205 #
206 # Some of these methods are written explitely to avoid HSPI throwing not
207 # implemented or the wrong ancestor class being used to answer the method;
208 # if it didn't do that then PullParserI AUTOLOAD would have cought them.
209 #
210  
211 =head2 algorithm
212  
213 Title : algorithm
214 Usage : my $r_type = $hsp->algorithm
215 Function: Obtain the name of the algorithm used to obtain the HSP
216 Returns : string (e.g., BLASTP)
217 Args : none
218  
219 =cut
220  
221 0 ▶sub algorithm {
Subroutine algorithm: not called CC=1 SCAR=6.9
Pod documented
222 0 return shift->get_field('algorithm');
223 }
224  
225 =head2 pvalue
226  
227 Title : pvalue
228 Usage : my $pvalue = $hsp->pvalue();
229 Function: Returns the P-value for this HSP or undef
230 Returns : float or exponential (2e-10)
231 Args : none
232  
233 =cut
234  
235 0 ▶sub pvalue {
Subroutine pvalue: not called CC=1 SCAR=6.9
Pod documented
236 0 return shift->get_field('pvalue');
237 }
238  
239 =head2 evalue
240  
241 Title : evalue
242 Usage : my $evalue = $hsp->evalue();
243 Function: Returns the e-value for this HSP
244 Returns : float or exponential (2e-10)
245 Args : none
246  
247 =cut
248  
249 4 ▶sub evalue {
Subroutine evalue: called CC=1 SCAR=0.0
Pod documented
250 4 return shift->get_field('evalue');
251 }
252  
253 6 *expect = \&evalue;
254  
255 =head2 frac_identical
256  
257 Title : frac_identical
258 Usage : my $frac_id = $hsp->frac_identical( ['query'|'hit'|'total'] );
259 Function: Returns the fraction of identitical positions for this HSP
260 Returns : Float in range 0.0 -> 1.0
261 Args : 'query' = num identical / length of query seq (without gaps)
262 'hit' = num identical / length of hit seq (without gaps)
263 'total' = num identical / length of alignment (with gaps)
264 default = 'total'
265  
266 =cut
267  
268 12 ▶sub frac_identical {
Subroutine frac_identical: called CC=7 SCAR=21.0
Pod documented
269 12 my ($self, $type) = @_;
270
271 12 ▶ $type = lc $type if defined $type;
Branch: 1 branch
BranchTrueFalseTotal
if defined $type 12 0 12
272 12 ▶ $type = 'hit' if (defined $type && $type =~ /subject|sbjct/);
Branch: 1 branch
BranchTrueFalseTotal
if defined $type and $type =~ /subject|sbjct/ 0 12 12
Condition33%1/3
defined $type and $type =~ /subject|sbjct/
!ll&&!rl&&r
0120
MC/DC0%0/2
defined $type and $type =~ /subject|sbjct/
defined $type $type =~ /subject|sbjct/
Truth table33%1/3
A and B
A= defined $typeB= $type =~ /subject|sbjct/
ABresult
0X0
100
111
273 12 ▶ $type = 'total' if (! defined $type || $type eq 'hsp' || $type !~ /query|hit|subject|sbjct|total/);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $type or $type eq "hsp" or not $type =~ /query|hit|subject|sbjct|total/ 4 8 12
Condition66%4/6
not defined $type or $type eq "hsp" or not $type =~ /query|hit|subject|sbjct|total/
l!l&&r!l&&!r
408
not defined $type or $type eq "hsp"
l!l&&r!l&&!r
048
MC/DC33%1/3
not defined $type or $type eq "hsp" or not $type =~ /query|hit|subject|sbjct|total/
not defined $type $type eq "hsp" not $type =~ /query|hit|subject|sbjct|total/
Truth table50%2/4
not(A) or B or not(C)
A= not defined $typeB= $type eq "hsp"C= not $type =~ /query|hit|subject|sbjct|total/
ABCresult
1XX1
01X1
0011
0000
274
275 12 my $ratio = $self->num_identical($type) / $self->length($type);
276 12 return sprintf( "%.4f", $ratio);
277 }
278  
279 =head2 frac_conserved
280  
281 Title : frac_conserved
282 Usage : my $frac_cons = $hsp->frac_conserved( ['query'|'hit'|'total'] );
283 Function : Returns the fraction of conserved positions for this HSP.
284 This is the fraction of symbols in the alignment with a
285 positive score.
286 Returns : Float in range 0.0 -> 1.0
287 Args : 'query' = num conserved / length of query seq (without gaps)
288 'hit' = num conserved / length of hit seq (without gaps)
289 'total' = num conserved / length of alignment (with gaps)
290 default = 'total'
291  
292 =cut
293  
294 0 ▶sub frac_conserved {
Subroutine frac_conserved: not called CC=7 SCAR=40.3
Pod documented
295 0 my ($self, $type) = @_;
296
297 0 ▶ $type = lc $type if defined $type;
Branch: 1 branch
BranchTrueFalseTotal
if defined $type 0 0 0
298 0 ▶ $type = 'hit' if (defined $type && $type =~ /subject|sbjct/);
Branch: 1 branch
BranchTrueFalseTotal
if defined $type and $type =~ /subject|sbjct/ 0 0 0
Condition0%0/3
defined $type and $type =~ /subject|sbjct/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $type and $type =~ /subject|sbjct/
defined $type $type =~ /subject|sbjct/
Truth table0%0/3
A and B
A= defined $typeB= $type =~ /subject|sbjct/
ABresult
0X0
100
111
299 0 ▶ $type = 'total' if (! defined $type || $type eq 'hsp' || $type !~ /query|hit|subject|sbjct|total/);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $type or $type eq "hsp" or not $type =~ /query|hit|subject|sbjct|total/ 0 0 0
Condition0%0/6
not defined $type or $type eq "hsp" or not $type =~ /query|hit|subject|sbjct|total/
l!l&&r!l&&!r
000
not defined $type or $type eq "hsp"
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $type or $type eq "hsp" or not $type =~ /query|hit|subject|sbjct|total/
not defined $type $type eq "hsp" not $type =~ /query|hit|subject|sbjct|total/
Truth table0%0/4
not(A) or B or not(C)
A= not defined $typeB= $type eq "hsp"C= not $type =~ /query|hit|subject|sbjct|total/
ABCresult
1XX1
01X1
0011
0000
300
301 0 my $ratio = $self->num_conserved($type) / $self->length($type);
302 0 return sprintf( "%.4f", $ratio);
303 }
304  
305 =head2 num_identical
306  
307 Title : num_identical
308 Usage : $obj->num_identical($newval)
309 Function: returns the number of identical residues in the alignment
310 Returns : integer
311 Args : integer (optional)
312  
313 =cut
314  
315 12 ▶sub num_identical {
Subroutine num_identical: called CC=1 SCAR=0.0
Pod documented
316 12 my $self = shift;
317 12 return scalar($self->seq_inds('hit', 'identical'));
318 }
319  
320 =head2 num_conserved
321  
322 Title : num_conserved
323 Usage : $obj->num_conserved($newval)
324 Function: returns the number of conserved residues in the alignment
325 Returns : inetger
326 Args : integer (optional)
327  
328 =cut
329  
330 0 ▶sub num_conserved {
Subroutine num_conserved: not called CC=1 SCAR=6.9
Pod documented
331 0 my $self = shift;
332 0 return scalar($self->seq_inds('hit', 'conserved-not-identical'));
333 }
334  
335 =head2 gaps
336  
337 Title : gaps
338 Usage : my $gaps = $hsp->gaps( ['query'|'hit'|'total'] );
339 Function : Get the number of gap characters in the query, hit, or total alignment.
340 Returns : Integer, number of gap characters or 0 if none
341 Args : 'query', 'hit' or 'total'; default = 'total'
342  
343 =cut
344  
345 0 ▶sub gaps {
Subroutine gaps: not called CC=7 SCAR=40.3
Pod documented
346 0 my ($self, $type) = @_;
347 0 ▶ $type = lc $type if defined $type;
Branch: 1 branch
BranchTrueFalseTotal
if defined $type 0 0 0
348 0 ▶ $type = 'total' if (! defined $type || $type eq 'hsp' || $type !~ /query|hit|subject|sbjct|total/);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $type or $type eq "hsp" or not $type =~ /query|hit|subject|sbjct|total/ 0 0 0
Condition0%0/6
not defined $type or $type eq "hsp" or not $type =~ /query|hit|subject|sbjct|total/
l!l&&r!l&&!r
000
not defined $type or $type eq "hsp"
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $type or $type eq "hsp" or not $type =~ /query|hit|subject|sbjct|total/
not defined $type $type eq "hsp" not $type =~ /query|hit|subject|sbjct|total/
Truth table0%0/4
not(A) or B or not(C)
A= not defined $typeB= $type eq "hsp"C= not $type =~ /query|hit|subject|sbjct|total/
ABCresult
1XX1
01X1
0011
0000
349 0 ▶ $type = 'hit' if $type =~ /sbjct|subject/;
Branch: 1 branch
BranchTrueFalseTotal
if $type =~ /sbjct|subject/ 0 0 0
350
351 0 ▶ if ($type eq 'total') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "total") 0 0 0
352 0 return scalar($self->seq_inds('hit', 'gap')) + scalar($self->seq_inds('query', 'gap'));
353 }
354 0 return scalar($self->seq_inds($type, 'gap'));
355 }
356  
357 =head2 query_string
358  
359 Title : query_string
360 Usage : my $qseq = $hsp->query_string;
361 Function: Retrieves the query sequence of this HSP as a string
362 Returns : string
363 Args : none
364  
365 =cut
366  
367 3 ▶sub query_string {
Subroutine query_string: called CC=1 SCAR=0.0
Pod documented
368 3 return shift->get_field('query_string');
369 }
370  
371 =head2 hit_string
372  
373 Title : hit_string
374 Usage : my $hseq = $hsp->hit_string;
375 Function: Retrieves the hit sequence of this HSP as a string
376 Returns : string
377 Args : none
378  
379 =cut
380  
381 3 ▶sub hit_string {
Subroutine hit_string: called CC=1 SCAR=0.0
Pod documented
382 3 return shift->get_field('hit_string');
383 }
384  
385 =head2 homology_string
386  
387 Title : homology_string
388 Usage : my $homo_string = $hsp->homology_string;
389 Function: Retrieves the homology sequence for this HSP as a string.
390 : The homology sequence is the string of symbols in between the
391 : query and hit sequences in the alignment indicating the degree
392 : of conservation (e.g., identical, similar, not similar).
393 Returns : string
394 Args : none
395  
396 =cut
397  
398 1 ▶sub homology_string {
Subroutine homology_string: called CC=1 SCAR=0.0
Pod documented
399 1 return shift->get_field('homology_string');
400 }
401  
402 =head2 length
403  
404 Title : length
405 Usage : my $len = $hsp->length( ['query'|'hit'|'total'] );
406 Function : Returns the length of the query or hit in the alignment (without gaps)
407 or the aggregate length of the HSP (including gaps;
408 this may be greater than either hit or query )
409 Returns : integer
410 Args : 'query' = length of query seq (without gaps)
411 'hit' = length of hit seq (without gaps)
412 'total' = length of alignment (with gaps)
413 default = 'total'
414 Args : none
415  
416 =cut
417  
418 16 ▶sub length {
Subroutine length: called CC=4 SCAR=13.9
Pod documented
419 16 my ($self, $type) = @_;
420 16 ▶ $type = 'total' unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 16 16
421 16 $type = lc $type;
422  
423 16 ▶ if ($type =~ /^q/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type =~ /^q/i) { } 4 12 16
elsif ($type =~ /^(hit|subject|sbjct)/) { } 4 8 12
424 4 return $self->query->length;
425 }
426 elsif ($type =~ /^(hit|subject|sbjct)/) {
427 4 return $self->hit->length;
428 }
429 else {
430 8 return $self->hit->length + $self->gaps('hit');
431 }
432 }
433  
434 =head2 hsp_length
435  
436 Title : hsp_length
437 Usage : my $len = $hsp->hsp_length()
438 Function: shortcut length('hsp')
439 Returns : floating point between 0 and 100
440 Args : none
441  
442 =cut
443  
444 0 ▶sub hsp_length {
Subroutine hsp_length: not called CC=1 SCAR=6.9
Pod documented
445 0 return shift->length('total');
446 }
447  
448 =head2 percent_identity
449  
450 Title : percent_identity
451 Usage : my $percentid = $hsp->percent_identity()
452 Function: Returns the calculated percent identity for an HSP
453 Returns : floating point between 0 and 100
454 Args : none
455  
456 =cut
457  
458 4 ▶sub percent_identity{
Subroutine percent_identity: called CC=1 SCAR=0.0
Pod documented
459 4 my ($self) = @_;
460 4 return $self->frac_identical('hsp') * 100;
461 }
462  
463 =head2 get_aln
464  
465 Title : get_aln
466 Usage : my $aln = $hsp->get_aln
467 Function: Returns a Bio::SimpleAlign representing the HSP alignment
468 Returns : Bio::SimpleAlign
469 Args : none
470  
471 =cut
472  
473 2 ▶sub get_aln {
Subroutine get_aln: called CC=3 SCAR=11.4
Pod documented
474 2 my $self = shift;
475
476 2 require Bio::LocatableSeq;
477 2 require Bio::SimpleAlign;
478 2 my $aln = Bio::SimpleAlign->new();
479 2 my $hs = $self->seq('hit');
480 2 my $qs = $self->seq('query');
481 2 ▶ if ($hs && $qs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hs and $qs) 2 0 2
Condition33%1/3
$hs and $qs
!ll&&!rl&&r
002
MC/DC0%0/2
$hs and $qs
$hs $qs
Truth table33%1/3
A and B
A= $hsB= $qs
ABresult
0X0
100
111
482 2 $aln->add_seq($hs);
483 2 $aln->add_seq($qs);
484 2 return $aln;
485 }
486 0 return;
487 }
488  
489 =head2 seq_inds
490  
491 Title : seq_inds
492 Purpose : Get a list of residue positions (indices) for all identical
493 : or conserved residues in the query or sbjct sequence.
494 Example : @s_ind = $hsp->seq_inds('query', 'identical');
495 : @h_ind = $hsp->seq_inds('hit', 'conserved');
496 : @h_ind = $hsp->seq_inds('hit', 'conserved', 1);
497 Returns : List of integers
498 : May include ranges if collapse is true.
499 Argument : seq_type = 'query' or 'hit' or 'sbjct' (default = query)
500 ('sbjct' is synonymous with 'hit')
501 class = 'identical' or 'conserved' or 'nomatch' or 'gap'
502 (default = identical)
503 (can be shortened to 'id' or 'cons')
504 Note that 'conserved' includes identical unless you
505 use 'conserved-not-identical'
506  
507 collapse = boolean, if true, consecutive positions are merged
508 using a range notation, e.g., "1 2 3 4 5 7 9 10 11"
509 collapses to "1-5 7 9-11". This is useful for
510 consolidating long lists. Default = no collapse.
511 Throws : n/a.
512 Comments :
513  
514 See Also : L<Bio::Search::BlastUtils::collapse_nums()|Bio::Search::BlastUtils>, L<Bio::Search::Hit::HitI::seq_inds()|Bio::Search::Hit::HitI>
515  
516 =cut
517  
518 134 ▶sub seq_inds {
Subroutine seq_inds: called CC=15 SCAR=29.1
Pod documented
519 134 my ($self, $seqType, $class, $collapse) = @_;
520
521 134 ▶ $seqType ||= 'query';
Condition50%1/2
$seqType ||= "query"
l!l
1340
MC/DC0%0/1
$seqType ||= "query"
$seqType
Truth table50%1/2
A
A= $seqType
Aresult
11
00
522 134 ▶ $class ||= 'identical';
Condition50%1/2
$class ||= "identical"
l!l
1340
MC/DC0%0/1
$class ||= "identical"
$class
Truth table50%1/2
A
A= $class
Aresult
11
00
523 134 ▶ $collapse ||= 0;
Condition50%1/2
$collapse ||= 0
l!l
0134
MC/DC0%0/1
$collapse ||= 0
$collapse
Truth table50%1/2
A
A= $collapse
Aresult
11
00
524 134 $seqType = lc($seqType);
525 134 $class = lc($class);
526 134 ▶ $seqType = 'hit' if $seqType eq 'sbjct';
Branch: 1 branch
BranchTrueFalseTotal
if $seqType eq "sbjct" 0 134 134
527
528 134 my $t = substr($seqType,0,1);
529 134 ▶ if ($t eq 'q') {
Branch: 2 branches
BranchTrueFalseTotal
if ($t eq 'q') { } 92 42 134
elsif ($t eq 's' or $t eq 'h') { } 42 0 42
530 92 $seqType = 'query';
531 }
532 ▶ elsif ($t eq 's' || $t eq 'h') {
Condition33%1/3
$t eq "s" or $t eq "h"
l!l&&r!l&&!r
0420
MC/DC0%0/2
$t eq "s" or $t eq "h"
$t eq "s" $t eq "h"
Truth table33%1/3
A or B
A= $t eq "s"B= $t eq "h"
ABresult
1X1
011
000
533 42 $seqType = 'hit';
534 }
535 else {
536 0 $self->warn("unknown seqtype $seqType using 'query'");
537 0 $seqType = 'query';
538 }
539
540 134 $t = substr($class,0,1);
541 134 ▶ if ($t eq 'c') {
Branch: 4 branches
BranchTrueFalseTotal
if ($t eq 'c') { } 61 73 134
elsif ($t eq 'i') { } 42 31 73
elsif ($t eq 'n') { } 31 0 31
elsif ($t eq 'g') { } 0 0 0
542 61 ▶ if ($class eq 'conserved-not-identical') {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq 'conserved-not-identical') { } 30 31 61
543 30 $class = 'conserved';
544 }
545 else {
546 31 $class = 'conservedall';
547 }
548 }
549 elsif ($t eq 'i') {
550 42 $class = 'identical';
551 }
552 elsif ($t eq 'n') {
553 31 $class = 'nomatch';
554 }
555 elsif ($t eq 'g') {
556 0 $class = 'gap';
557 }
558 else {
559 0 $self->warn("unknown sequence class $class using 'identical'");
560 0 $class = 'identical';
561 }
562
563 134 $seqType .= '_';
564 134 $class .= '_inds';
565
566 134 my @ary;
567 134 ▶ if ($class eq 'conservedall_inds') {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq 'conservedall_inds') { } 31 103 134
568 5282 my %tmp = map { $_, 1 } @{$self->get_field($seqType.'conserved_inds')},
569 31 @{$self->get_field($seqType.'identical_inds')};
570 31 @ary = sort {$a <=> $b} keys %tmp;
571 }
572 else {
573 103 @ary = @{$self->get_field($seqType.$class)};
574 }
575
576 134 ▶ return $collapse ? &Bio::Search::SearchUtils::collapse_nums(@ary) : @ary;
Branch: 1 branch
BranchTrueFalseTotal
$collapse ? : 0 134 134
577 }
578  
579 =head2 Inherited from L<Bio::SeqFeature::SimilarityPair>
580  
581 These methods come from L<Bio::SeqFeature::SimilarityPair>
582  
583 =head2 query
584  
585 Title : query
586 Usage : my $query = $hsp->query
587 Function: Returns a SeqFeature representing the query in the HSP
588 Returns : Bio::SeqFeature::Similarity
589 Args : [optional] new value to set
590  
591  
592 =head2 hit
593  
594 Title : hit
595 Usage : my $hit = $hsp->hit
596 Function: Returns a SeqFeature representing the hit in the HSP
597 Returns : Bio::SeqFeature::Similarity
598 Args : [optional] new value to set
599  
600  
601 =head2 significance
602  
603 Title : significance
604 Usage : $evalue = $obj->significance();
605 $obj->significance($evalue);
606 Function: Get/Set the significance value (see Bio::SeqFeature::SimilarityPair)
607 Returns : significance value (scientific notation string)
608 Args : significance value (sci notation string)
609  
610 =cut
611  
612 0 ▶sub significance {
Subroutine significance: not called CC=1 SCAR=6.9
Pod documented
613 0 return shift->get_field('evalue');
614 }
615  
616 =head2 score
617  
618 Title : score
619 Usage : my $score = $hsp->score();
620 Function: Returns the score for this HSP or undef
621 Returns : numeric
622 Args : [optional] numeric to set value
623  
624 =cut
625  
626 4 ▶sub score {
Subroutine score: called CC=1 SCAR=0.0
Pod documented
627 4 return shift->get_field('score');
628 }
629  
630 =head2 bits
631  
632 Title : bits
633 Usage : my $bits = $hsp->bits();
634 Function: Returns the bit value for this HSP or undef
635 Returns : numeric
636 Args : none
637  
638 =cut
639  
640 4 ▶sub bits {
Subroutine bits: called CC=1 SCAR=0.0
Pod documented
641 4 return shift->get_field('bits');
642 }
643  
644 # override
645  
646 =head2 strand
647  
648 Title : strand
649 Usage : $hsp->strand('query')
650 Function: Retrieves the strand for the HSP component requested
651 Returns : +1 or -1 (0 if unknown)
652 Args : 'hit' or 'subject' or 'sbjct' to retrieve the strand of the subject
653 'query' to retrieve the query strand (default)
654 'list' or 'array' to retrieve both query and hit together
655  
656 =cut
657  
658 0 ▶sub strand {
Subroutine strand: not called CC=5 SCAR=34.0
Pod documented
659 0 my $self = shift;
660 0 my $val = shift;
661 0 ▶ $val = 'query' unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
662 0 $val =~ s/^\s+//;
663  
664 0 ▶ if ($val =~ /^q/i) {
Branch: 3 branches
BranchTrueFalseTotal
if ($val =~ /^q/i) { } 0 0 0
elsif ($val =~ /^hi|^s/i) { } 0 0 0
elsif ($val =~ /^list|array/i) { } 0 0 0
665 0 return $self->query->strand(@_);
666 }
667 elsif ($val =~ /^hi|^s/i) {
668 0 return $self->hit->strand(@_);
669 }
670 elsif ($val =~ /^list|array/i) {
671 0 return ($self->query->strand(@_), $self->hit->strand(@_) );
672 }
673 else {
674 0 $self->warn("unrecognized component '$val' requested\n");
675 }
676 0 return 0;
677 }
678  
679 =head2 start
680  
681 Title : start
682 Usage : $hsp->start('query')
683 Function: Retrieves the start for the HSP component requested
684 Returns : integer, or list of two integers (query start and subject start) in
685 list context
686 Args : 'hit' or 'subject' or 'sbjct' to retrieve the start of the subject
687 'query' to retrieve the query start (default)
688  
689 =cut
690  
691 0 ▶sub start {
Subroutine start: not called CC=6 SCAR=37.4
Pod documented
692 0 my $self = shift;
693 0 my $val = shift;
694 0 ▶ $val = (wantarray ? 'list' : 'query') unless defined $val;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $val 0 0 0
wantarray ? : 0 0 0
695 0 $val =~ s/^\s+//;
696  
697 0 ▶ if ($val =~ /^q/i) {
Branch: 3 branches
BranchTrueFalseTotal
if ($val =~ /^q/i) { } 0 0 0
elsif ($val =~ /^(hi|s)/i) { } 0 0 0
elsif ($val =~ /^list|array/i) { } 0 0 0
698 0 return $self->query->start(@_);
699 }
700 elsif ($val =~ /^(hi|s)/i) {
701 0 return $self->hit->start(@_);
702 }
703 elsif ($val =~ /^list|array/i) {
704 0 return ($self->query->start(@_), $self->hit->start(@_) );
705 }
706 else {
707 0 $self->warn("unrecognized component '$val' requested\n");
708 }
709 0 return 0;
710 }
711  
712 =head2 end
713  
714 Title : end
715 Usage : $hsp->end('query')
716 Function: Retrieves the end for the HSP component requested
717 Returns : integer, or list of two integers (query end and subject end) in
718 list context
719 Args : 'hit' or 'subject' or 'sbjct' to retrieve the end of the subject
720 'query' to retrieve the query end (default)
721  
722 =cut
723  
724 0 ▶sub end {
Subroutine end: not called CC=6 SCAR=37.4
Pod documented
725 0 my $self = shift;
726 0 my $val = shift;
727 0 ▶ $val = (wantarray ? 'list' : 'query') unless defined $val;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $val 0 0 0
wantarray ? : 0 0 0
728 0 $val =~ s/^\s+//;
729  
730 0 ▶ if ($val =~ /^q/i) {
Branch: 3 branches
BranchTrueFalseTotal
if ($val =~ /^q/i) { } 0 0 0
elsif ($val =~ /^(hi|s)/i) { } 0 0 0
elsif ($val =~ /^list|array/i) { } 0 0 0
731 0 return $self->query->end(@_);
732 }
733 elsif ($val =~ /^(hi|s)/i) {
734 0 return $self->hit->end(@_);
735 }
736 elsif ($val =~ /^list|array/i) {
737 0 return ($self->query->end(@_), $self->hit->end(@_) );
738 }
739 else {
740 0 $self->warn("unrecognized end component '$val' requested\n");
741 }
742 0 return 0;
743 }
744  
745 =head2 seq
746  
747 Usage : $hsp->seq( [seq_type] );
748 Purpose : Get the query or sbjct sequence as a Bio::Seq.pm object.
749 Example : $seqObj = $hsp->seq('query');
750 Returns : Object reference for a Bio::LocatableSeq object.
751 Argument : seq_type = 'query' or 'hit' or 'sbjct' (default = 'query').
752 : ('sbjct' is synonymous with 'hit')
753 : default is 'query'
754  
755 =cut
756  
757 4 ▶sub seq {
Subroutine seq: called CC=7 SCAR=20.4
Pod documented
758 4 my ($self, $seqType) = @_;
759 4 ▶ $seqType ||= 'query';
Condition50%1/2
$seqType ||= "query"
l!l
40
MC/DC0%0/1
$seqType ||= "query"
$seqType
Truth table50%1/2
A
A= $seqType
Aresult
11
00
760 4 ▶ $seqType = 'hit' if $seqType eq 'sbjct';
Branch: 1 branch
BranchTrueFalseTotal
if $seqType eq "sbjct" 0 4 4
761 4 ▶ if ($seqType =~ /^(m|ho)/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seqType =~ /^(m|ho)/i) 0 4 4
762 0 $self->throw("cannot call seq on the homology match string, it isn't really a sequence, use get_aln to convert the HSP to a Bio::AlignIO and generate a consensus from that.");
763 }
764
765 4 ▶ my $str = $self->seq_str($seqType) || return;
Condition50%1/2
$self->seq_str($seqType) || (return)
l!l
40
MC/DC0%0/1
$self->seq_str($seqType) || (return)
$self->seq_str($seqType)
Truth table50%1/2
A
A= $self->seq_str($seqType)
Aresult
11
00
766 4 require Bio::LocatableSeq;
767 4 ▶ my $id = ($seqType =~ /^q/i) ? $self->query->seq_id : $self->hit->seq_id;
Branch: 1 branch
BranchTrueFalseTotal
$seqType =~ /^q/i ? : 2 2 4
768 4 ▶ return Bio::LocatableSeq->new( -ID => $id,
Branch: 1 branch
BranchTrueFalseTotal
$id ? : 2 2 4
769 -SEQ => $str,
770 -START => $self->start($seqType),
771 -END => $self->end($seqType),
772 -STRAND => $self->strand($seqType),
773 -FORCE_NSE => $id ? 0 : 1,
774 -DESC => "$seqType sequence " );
775  
776 }
777  
778 =head2 seq_str
779  
780 Usage : $hsp->seq_str( seq_type );
781 Purpose : Get the full query, sbjct, or 'match' sequence as a string.
782 : The 'match' sequence is the string of symbols in between the
783 : query and sbjct sequences.
784 Example : $str = $hsp->seq_str('query');
785 Returns : String
786 Argument : seq_Type = 'query' or 'hit' or 'sbjct' or 'match'
787 : ('sbjct' is synonymous with 'hit')
788 : default is 'query'
789 Throws : Exception if the argument does not match an accepted seq_type.
790 Comments :
791  
792 See Also : L<seq()|seq>, L<seq_inds()|seq_inds>, B<_set_match_seq()>
793  
794 =cut
795  
796 4 ▶sub seq_str {
Subroutine seq_str: called CC=5 SCAR=19.6
Pod documented
797 4 my $self = shift;
798 4 ▶ my $type = shift || 'query';
Condition50%1/2
shift() || 'query'
l!l
40
MC/DC0%0/1
shift() || 'query'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
799  
800 4 ▶ if ($type =~ /^q/i) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type =~ /^q/i) { } 2 2 4
elsif ($type =~ /^(s)|(hi)/i) { } 2 0 2
elsif ($type =~ /^(ho)|(ma)/i) { } 0 0 0
801 2 return $self->query_string(@_);
802 }
803 elsif ($type =~ /^(s)|(hi)/i) {
804 2 return $self->hit_string(@_);
805 }
806 elsif ($type =~ /^(ho)|(ma)/i) {
807 0 return $self->homology_string(@_);
808 }
809 else {
810 0 $self->warn("unknown sequence type $type");
811 }
812 0 return '';
813 }
814  
815 =head2 rank
816  
817 Usage : $hsp->rank( [string] );
818 Purpose : Get the rank of the HSP within a given Blast hit.
819 Example : $rank = $hsp->rank;
820 Returns : Integer (1..n) corresponding to the order in which the HSP
821 appears in the BLAST report.
822  
823 =cut
824  
825 0 ▶sub rank {
Subroutine rank: not called CC=1 SCAR=6.9
Pod documented
826 0 return shift->get_field('rank');
827 }
828  
829 =head2 matches
830  
831 Usage : $hsp->matches(-seq => 'hit'|'query',
832 -start => $start,
833 -stop => $stop);
834 Purpose : Get the total number of identical and conservative matches
835 : in the query or sbjct sequence for the given HSP. Optionally can
836 : report data within a defined interval along the seq.
837 Example : ($id,$cons) = $hsp_object->matches(-seq => 'hit');
838 : ($id,$cons) = $hsp_object->matches(-seq => 'query',
839 -start => 300,
840 -stop => 400);
841 Returns : 2-element array of integers
842 Argument : (1) seq_type = 'query' or 'hit' or 'sbjct' (default = query)
843 : ('sbjct' is synonymous with 'hit')
844 : (2) start = Starting coordinate (optional)
845 : (3) stop = Ending coordinate (optional)
846  
847 =cut
848  
849 0 ▶sub matches {
Subroutine matches: not called CC=13 SCAR=52.0
Pod documented
850 0 my ($self, @args) = @_;
851 0 my($seqType, $beg, $end) = $self->_rearrange([qw(SEQ START STOP)], @args);
852 0 ▶ $seqType ||= 'query';
Condition0%0/2
$seqType ||= "query"
l!l
00
MC/DC0%0/1
$seqType ||= "query"
$seqType
Truth table0%0/2
A
A= $seqType
Aresult
11
00
853 0 ▶ $seqType = 'hit' if $seqType eq 'sbjct';
Branch: 1 branch
BranchTrueFalseTotal
if $seqType eq "sbjct" 0 0 0
854
855 0 my @data;
856 0 ▶ if ((!defined $beg && !defined $end) || ! $self->seq_str('match')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not +(defined $beg || defined $end) && $self->seq_str('match')) { } 0 0 0
Condition0%0/6
(defined $beg || defined $end) && $self->seq_str('match')
!ll&&!rl&&r
000
defined $beg or defined $end
l!l&&r!l&&!r
000
MC/DC0%0/3
(defined $beg || defined $end) && $self->seq_str('match')
defined $beg defined $end $self->seq_str('match')
Truth table0%0/5
A or B && C
A= defined $begB= defined $endC= $self->seq_str('match')
ABCresult
00X0
1X00
0100
1X11
0111
857 0 push @data, ($self->num_identical, $self->num_conserved);
858 }
859 else {
860 0 ▶ $beg ||= 0;
Condition0%0/2
$beg ||= 0
l!l
00
MC/DC0%0/1
$beg ||= 0
$beg
Truth table0%0/2
A
A= $beg
Aresult
11
00
861 0 ▶ $end ||= 0;
Condition0%0/2
$end ||= 0
l!l
00
MC/DC0%0/1
$end ||= 0
$end
Truth table0%0/2
A
A= $end
Aresult
11
00
862 0 my ($start, $stop) = $self->range($seqType);
863
864 0 ▶ if ($beg == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($beg == 0) { } 0 0 0
elsif ($end == 0) { } 0 0 0
865 0 $beg = $start;
866 0 $end = $beg+$end;
867 }
868 elsif ($end == 0) {
869 0 $end = $stop;
870 0 $beg = $end-$beg;
871 }
872
873 0 ▶ if ($end >= $stop) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end >= $stop) { } 0 0 0
874 0 $end = $stop;
875 }
876 else {
877 0 $end += 1;
878 }
879 0 ▶ if ($beg < $start) {
Branch: 1 branch
BranchTrueFalseTotal
if ($beg < $start) 0 0 0
880 0 $beg = $start;
881 }
882
883 0 my $seq = substr($self->seq_str('homology'), $beg-$start, ($end-$beg));
884
885 0 ▶ if (!CORE::length $seq) {
Branch: 1 branch
BranchTrueFalseTotal
unless (CORE::length $seq) 0 0 0
886 0 $self->throw("Undefined sub-sequence ($beg,$end). Valid range = $start - $stop");
887 }
888 ## Get data for a substring.
889 0 $seq =~ s/ //g; # remove space (no info).
890 0 my $len_cons = CORE::length $seq;
891 0 $seq =~ s/\+//g; # remove '+' characters (conservative substitutions)
892 0 my $len_id = CORE::length $seq;
893 0 push @data, ($len_id, $len_cons);
894 }
895
896 0 return @data;
897 }
898  
899 =head2 n
900  
901 Usage : $hsp_obj->n()
902 Purpose : Get the N value (num HSPs on which P/Expect is based).
903 Returns : Integer or null string if not defined.
904 Argument : n/a
905 Throws : n/a
906 Comments : The 'N' value is listed in parenthesis with P/Expect value:
907 : e.g., P(3) = 1.2e-30 ---> (N = 3).
908 : Not defined in NCBI Blast2 with gaps.
909 : This typically is equal to the number of HSPs but not always.
910  
911 =cut
912  
913 0 ▶sub n {
Subroutine n: not called CC=1 SCAR=6.9
Pod documented
914 0 return shift->get_field('num_hsps');
915 }
916  
917 =head2 range
918  
919 Usage : $hsp->range( [seq_type] );
920 Purpose : Gets the (start, end) coordinates for the query or sbjct sequence
921 : in the HSP alignment.
922 Example : ($query_beg, $query_end) = $hsp->range('query');
923 : ($hit_beg, $hit_end) = $hsp->range('hit');
924 Returns : Two-element array of integers
925 Argument : seq_type = string, 'query' or 'hit' or 'sbjct' (default = 'query')
926 : ('sbjct' is synonymous with 'hit')
927 Throws : n/a
928 Comments : This is a convenience method for constructions such as
929 ($hsp->query->start, $hsp->query->end)
930  
931 =cut
932  
933 0 ▶sub range {
Subroutine range: not called CC=3 SCAR=24.8
Pod documented
934 0 my ($self, $seqType) = @_;
935 0 ▶ $seqType ||= 'query';
Condition0%0/2
$seqType ||= "query"
l!l
00
MC/DC0%0/1
$seqType ||= "query"
$seqType
Truth table0%0/2
A
A= $seqType
Aresult
11
00
936
937 0 my ($start, $end);
938 0 ▶ if ($seqType eq 'query') {
Branch: 1 branch
BranchTrueFalseTotal
if ($seqType eq 'query') { } 0 0 0
939 0 $start = $self->query->start;
940 0 $end = $self->query->end;
941 }
942 else {
943 0 $start = $self->hit->start;
944 0 $end = $self->hit->end;
945 }
946 0 return ($start, $end);
947 }
948  
949 #*** would want cigar stuff from GenericHSP - move to HSPI?
950  
951 6 1;
952  
« Bio/Matrix/PSM/ProtMatrix.pm ↑ Summary Bio/CodonUsage/IO.pm »