Bio/Search/Tiling/MapTiling.pm

filter: Statementstmt 83.7% 398 / 475 Branchbran 68.3% 93 / 136 Conditioncond 50.9% 26 / 51 MC/DCmcdc 18.1% 6 / 33 Subroutinesub 91.4% 43 / 47 Podpod 91.6% 22 / 24 totaltotal 76.7% 588 / 766 CC 112 SCAR 24.1
CC
112
Cov
78%
coverage_map_as_text
42.0
get_tiled_alns
24.1
frac
16.2
CRAP 11.1
« Bio/SearchIO/psl.pm ↑ Summary Bio/Annotation/Target.pm »
1 #
2 # BioPerl module for Bio::Search::Tiling::MapTiling
3 #
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
5 #
6 # Cared for by Mark A. Jensen <maj@fortinbras.us>
7 #
8 # Copyright Mark A. Jensen
9 #
10 # You may distribute this module under the same terms as perl itself
11  
12 # POD documentation - main docs before the code
13  
14 =head1 NAME
15  
16 Bio::Search::Tiling::MapTiling - An implementation of an HSP tiling
17 algorithm, with methods to obtain frequently-requested statistics
18  
19 =head1 SYNOPSIS
20  
21 # get a BLAST $hit from somewhere, then
22 $tiling = Bio::Search::Tiling::MapTiling->new($hit);
23  
24 # stats
25 $numID = $tiling->identities();
26 $numCons = $tiling->conserved();
27 $query_length = $tiling->length('query');
28 $subject_length = $tiling->length('subject'); # or...
29 $subject_length = $tiling->length('hit');
30  
31 # get a visual on the coverage map
32 print $tiling->coverage_map_as_text('query',$context,'LEGEND');
33  
34 # tilings
35 $context = $tiling->_context( -type => 'subject', -strand=> 1, -frame=>1);
36 @covering_hsps_for_subject = $tiling->next_tiling('subject',$context);
37 $context = $tiling->_context( -type => 'query', -strand=> -1, -frame=>0);
38 @covering_hsps_for_query = $tiling->next_tiling('query', $context);
39  
40 =head1 DESCRIPTION
41  
42 Frequently, users want to use a set of high-scoring pairs (HSPs)
43 obtained from a BLAST or other search to assess the overall level of
44 identity, conservation, or coverage represented by matches between a
45 subject and a query sequence. Because a set of HSPs frequently
46 describes multiple overlapping sequence fragments, a simple summation of
47 statistics over the HSPs will generally overestimate those
48 statistics. To obtain an accurate estimate of global hit statistics, a
49 'tiling' of HSPs onto either the subject or the query sequence must be
50 performed, in order to properly correct for this.
51  
52 This module will execute a tiling algorithm on a given hit based on an
53 interval decomposition I'm calling the "coverage map". Internal object
54 methods compute the various statistics, which are then stored in
55 appropriately-named public object attributes. See
56 L<Bio::Search::Tiling::MapTileUtils> for more info on the algorithm.
57  
58 =head2 STRAND/FRAME CONTEXTS
59  
60 In BLASTX, TBLASTN, and TBLASTX reports, strand and frame information
61 are reported for the query, subject, or query and subject,
62 respectively, for each HSP. Tilings for these sequence types are only
63 meaningful when they include HSPs in the same strand and frame, or
64 "context". So, in these situations, the context must be specified
65 in the method calls or the methods will throw.
66  
67 Contexts are specified as strings: C<[ 'all' | [m|p][_|0|1|2] ]>, where
68 C<all> = all HSPs (will throw if context must be specified), C<m> = minus
69 strand, C<p> = plus strand, and C<_> = no frame info, C<0,1,2> = respective
70 (absolute) frame. The L</_make_context_key> method will convert a (strand,
71 frame) specification to a context string, e.g.:
72  
73 $context = $self->_context(-type=>'query', -strand=>-1, -frame=>-2);
74  
75 returns C<m2>.
76  
77 The contexts present among the HSPs in a hit are identified and stored
78 for convenience upon object construction. These are accessed off the
79 object with the L</contexts> method. If contexts don't apply for the
80 given report, this returns C<('all')>.
81  
82 =head1 TILED ALIGNMENTS
83  
84 The experimental method L<ALIGNMENTS/get_tiled_alns> will use a tiling
85 to concatenate tiled hsps into a series of L<Bio::SimpleAlign>
86 objects:
87  
88 @alns = $tiling->get_tiled_alns($type, $context);
89  
90 Each alignment contains two sequences with ids 'query' and 'subject',
91 and consists of a concatenation of tiling HSPs which overlap or are
92 directly adjacent. The alignment are returned in C<$type> sequence
93 order. When HSPs overlap, the alignment sequence is taken from the HSP
94 which comes first in the coverage map array.
95  
96 The sequences in each alignment contain features (even though they are
97 L<Bio::LocatableSeq> objects) which map the original query/subject
98 coordinates to the new alignment sequence coordinates. You can
99 determine the original BLAST fragments this way:
100  
101 $aln = ($tiling->get_tiled_alns)[0];
102 $qseq = $aln->get_seq_by_id('query');
103 $hseq = $aln->get_seq_by_id('subject');
104 foreach my $feat ($qseq->get_SeqFeatures) {
105 $org_start = ($feat->get_tag_values('query_start'))[0];
106 $org_end = ($feat->get_tag_values('query_end'))[0];
107 # original fragment as represented in the tiled alignment:
108 $org_fragment = $feat->seq;
109 }
110 foreach my $feat ($hseq->get_SeqFeatures) {
111 $org_start = ($feat->get_tag_values('subject_start'))[0];
112 $org_end = ($feat->get_tag_values('subject_end'))[0];
113 # original fragment as represented in the tiled alignment:
114 $org_fragment = $feat->seq;
115 }
116  
117 =head1 DESIGN NOTE
118  
119 The major calculations are made just-in-time, and then memoized. So,
120 for example, for a given MapTiling object, a coverage map would
121 usually be calculated only once (for the query), and at most twice (if
122 the subject perspective is also desired), and then only when a
123 statistic is first accessed. Afterward, the map and/or any statistic
124 is read from storage. So feel free to call the statistic methods
125 frequently if it suits you.
126  
127 =head1 FEEDBACK
128  
129 =head2 Mailing Lists
130  
131 User feedback is an integral part of the evolution of this and other
132 Bioperl modules. Send your comments and suggestions preferably to
133 the Bioperl mailing list. Your participation is much appreciated.
134  
135 bioperl-l@bioperl.org - General discussion
136 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
137  
138 =head2 Support
139  
140 Please direct usage questions or support issues to the mailing list:
141  
142 I<bioperl-l@bioperl.org>
143  
144 rather than to the module maintainer directly. Many experienced and
145 reponsive experts will be able look at the problem and quickly
146 address it. Please include a thorough description of the problem
147 with code and data examples if at all possible.
148  
149 =head2 Reporting Bugs
150  
151 Report bugs to the Bioperl bug tracking system to help us keep track
152 of the bugs and their resolution. Bug reports can be submitted via
153 the web:
154  
155 https://github.com/bioperl/bioperl-live/issues
156  
157 =head1 AUTHOR - Mark A. Jensen
158  
159 Email maj -at- fortinbras -dot- us
160  
161 =head1 APPENDIX
162  
163 The rest of the documentation details each of the object methods.
164 Internal methods are usually preceded with a _
165  
166 =cut
167  
168 # Let the code begin...
169  
170 package Bio::Search::Tiling::MapTiling;
171 2 $Bio::Search::Tiling::MapTiling::VERSION = '1.7.8';
172 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
173 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
174  
175 2 ▶use Bio::Root::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
176 2 ▶use Bio::Search::Tiling::TilingI;
Subroutine BEGIN: called CC=1 SCAR=0.0
177 2 ▶use Bio::Search::Tiling::MapTileUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
178 2 ▶use Bio::LocatableSeq;
Subroutine BEGIN: called CC=1 SCAR=0.0
179  
180 # use base qw(Bio::Root::Root Bio::Search::Tiling::TilingI);
181 2 ▶use base qw(Bio::Root::Root Bio::Search::Tiling::TilingI);
Subroutine BEGIN: called CC=1 SCAR=0.0
182  
183 =head1 CONSTRUCTOR
184  
185 =head2 new
186  
187 Title : new
188 Usage : my $obj = new Bio::Search::Tiling::GenericTiling();
189 Function: Builds a new Bio::Search::Tiling::GenericTiling object
190 Returns : an instance of Bio::Search::Tiling::GenericTiling
191 Args : -hit => $a_Bio_Search_Hit_HitI_object
192 general filter function:
193 -hsp_filter => sub { my $this_hsp = shift;
194 ...;
195 return 1 if $wanted;
196 return 0; }
197  
198 =cut
199  
200 519 ▶sub new {
Subroutine new: called CC=11 SCAR=26.6
Pod documented
201 519 my $class = shift;
202 519 my @args = @_;
203 519 my $self = $class->SUPER::new(@args);
204 519 my($hit, $filter) = $self->_rearrange( [qw( HIT HSP_FILTER)],@args );
205  
206 519 ▶ $self->throw("HitI object required") unless $hit;
Branch: 1 branch
BranchTrueFalseTotal
unless $hit 0 519 519
207 519 ▶ $self->throw("Argument must be HitI object") unless ( ref $hit && $hit->isa('Bio::Search::Hit::HitI') );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $hit and $hit->isa("Bio::Search::Hit::HitI") 0 519 519
Condition33%1/3
ref $hit and $hit->isa("Bio::Search::Hit::HitI")
!ll&&!rl&&r
00519
MC/DC0%0/2
ref $hit and $hit->isa("Bio::Search::Hit::HitI")
ref $hit $hit->isa("Bio::Search::Hit::HitI")
Truth table33%1/3
A and B
A= ref $hitB= $hit->isa("Bio::Search::Hit::HitI")
ABresult
0X0
100
111
208 519 $self->{hit} = $hit;
209 519 $self->_set_attributes();
210 519 $self->{"_algorithm"} = $hit->algorithm;
211  
212 519 my @hsps = $hit->hsps;
213 # apply filter function if requested
214 519 ▶ if ( defined $filter ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $filter) 0 519 519
215 0 ▶ if ( ref($filter) eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $filter eq 'CODE') { } 0 0 0
216 0 ▶ @hsps = map { $filter->($_) ? $_ : () } @hsps;
Branch: 1 branch
BranchTrueFalseTotal
&$filter($_) ? : 0 0 0
217 }
218 else {
219 0 $self->warn("-filter is not a coderef; ignoring");
220 }
221 }
222
223 # identify available contexts
224 519 for my $t (qw( query hit )) {
225 1038 my %contexts;
226 1038 for my $i (0..$#hsps) {
227 546 my $ctxt = $self->_context(
228 -type => $t,
229 -strand => $hsps[$i]->strand($t),
230 -frame => $hsps[$i]->frame($t));
231 546 ▶ $contexts{$ctxt} ||= [];
Condition100%2/2
$contexts{$ctxt} ||= []
l!l
326220
MC/DC100%1/1
$contexts{$ctxt} ||= []
$contexts{$ctxt}
Truth table100%2/2
A
A= $contexts{$ctxt}
Aresult
11
00
232 546 push @{$contexts{$ctxt}}, $i;
233 }
234 1038 $self->{"_contexts_${t}"} = \%contexts;
235 }
236  
237 519 ▶ $self->warn("No HSPs present in hit after filtering") unless (@hsps);
Branch: 1 branch
BranchTrueFalseTotal
unless @hsps 415 104 519
238 519 $self->hsps(\@hsps);
239 519 return $self;
240 }
241  
242 # a tiling is based on the set of hsps contained in a single hit.
243 # check all the boundaries - zero hsps, one hsp, all disjoint hsps
244  
245 =head1 TILING ITERATORS
246  
247 =head2 next_tiling
248  
249 Title : next_tiling
250 Usage : @hsps = $self->next_tiling($type);
251 Function: Obtain a tiling: a minimal set of HSPs covering the $type
252 ('hit', 'subject', 'query') sequence
253 Example :
254 Returns : an array of HSPI objects
255 Args : scalar $type: one of 'hit', 'subject', 'query', with
256 'subject' an alias for 'hit'
257  
258 =cut
259  
260 268 ▶sub next_tiling{
Subroutine next_tiling: called CC=1 SCAR=0.0
Pod documented
261 268 my $self = shift;
262 268 my ($type, $context) = @_;
263 268 $self->_check_type_arg(\$type);
264 268 $self->_check_context_arg($type, \$context);
265 268 return $self->_tiling_iterator($type, $context)->();
266 }
267  
268 =head2 rewind_tilings
269  
270 Title : rewind_tilings
271 Usage : $self->rewind_tilings($type)
272 Function: Reset the next_tilings($type) iterator
273 Example :
274 Returns : True on success
275 Args : scalar $type: one of 'hit', 'subject', 'query';
276 default is 'query'
277  
278 =cut
279  
280 2 ▶sub rewind_tilings{
Subroutine rewind_tilings: called CC=1 SCAR=0.0
Pod documented
281 2 my $self = shift;
282 2 my ($type,$context) = @_;
283 2 $self->_check_type_arg(\$type);
284 2 $self->_check_context_arg($type, \$context);
285 2 return $self->_tiling_iterator($type, $context)->('REWIND');
286 }
287  
288 =head1 ALIGNMENTS
289  
290 =head2 get_tiled_alns()
291  
292 Title : get_tiled_alns
293 Usage : @alns = $tiling->get_tiled_alns($type, $context)
294 Function: Use a tiling to construct a minimal set of alignment
295 objects covering the region specified by $type/$context
296 by splicing adjacent HSP tiles
297 Returns : an array of Bio::SimpleAlign objects; see Note below
298 Args : scalar $type: one of 'hit', 'subject', 'query'
299 default is 'query'
300 scalar $context: strand/frame context string
301 Following $type and $context, an array of
302 ordered, tiled HSP objects can be specified; this is
303 the tiling that will directly the alignment construction
304 default -- the first tiling provided by a tiling iterator
305 Notes : Each returned alignment is a concatenation of adjacent tiles.
306 The set of alignments will cover all regions described by the
307 $type/$context pair in the hit. The pair of sequences in each
308 alignment have ids 'query' and 'subject', and each sequence
309 possesses SeqFeatures that map the original query or subject
310 coordinates to the sequence coordinates in the tiled alignment.
311
312 =cut
313  
314 1 ▶sub get_tiled_alns {
Subroutine get_tiled_alns: called CC=18 SCAR=31.8
Pod documented
315 1 my $self = shift;
316 1 my ($type, $context) = @_;
317 1 $self->_check_type_arg(\$type);
318 1 $self->_check_context_arg($type, \$context);
319 1 my $t = shift; # first arg after type/context, arrayref to a tiling
320 1 my @tiling;
321 1 ▶ if ($t && (ref($t) eq 'ARRAY')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t and ref $t eq 'ARRAY') { } 0 1 1
Condition33%1/3
$t and ref $t eq "ARRAY"
!ll&&!rl&&r
100
MC/DC0%0/2
$t and ref $t eq "ARRAY"
$t ref $t eq "ARRAY"
Truth table33%1/3
A and B
A= $tB= ref $t eq "ARRAY"
ABresult
0X0
100
111
322 0 @tiling = @$t;
323 }
324 else { # otherwise, take the first tiling available
325  
326 1 @tiling = $self->_make_tiling_iterator($type,$context)->();
327 }
328 1 my @ret;
329  
330 1 my @map = $self->coverage_map($type, $context);
331 1 my @intervals = map {$_->[0]} @map; # disjoint decomp
332 # divide into disjoint covering groups
333 1 my @groups = covering_groups(@intervals);
334  
335 1 require Bio::SimpleAlign;
336 1 require Bio::SeqFeature::Generic;
337 # cut hsp aligns along the disjoint decomp
338 # look for gaps...or add gaps?
339 1 my ($q_start, $h_start, $q_strand, $h_strand);
340 # build seqs
341 1 for my $grp (@groups) {
342 6 my $taln = Bio::SimpleAlign->new();
343 6 my (@qfeats, @hfeats);
344 6 my $query_string = '';
345 6 my $hit_string = '';
346 6 my ($qlen,$hlen) = (0,0);
347 6 my ($qinc, $hinc, $qstart, $hstart);
348 6 for my $intvl (@$grp) {
349 # following just chooses the first available hsp containing the
350 # interval -- this is arbitrary, could be smarter.
351 12 my $aln = ( containing_hsps($intvl, @tiling) )[0]->get_aln;
352 12 my $qseq = $aln->get_seq_by_pos(1);
353 12 my $hseq = $aln->get_seq_by_pos(2);
354 12 ▶ $qstart ||= $qseq->start;
Condition66%2/3
$qstart ||= $qseq->start
l!l&&r!l&&!r
660
MC/DC0%0/2
$qstart ||= $qseq->start
$qstart $qseq->start
Truth table66%2/3
A ||= B
A= $qstartB= $qseq->start
ABresult
1X1
011
000
355 12 ▶ $hstart ||= $hseq->start;
Condition66%2/3
$hstart ||= $hseq->start
l!l&&r!l&&!r
660
MC/DC0%0/2
$hstart ||= $hseq->start
$hstart $hseq->start
Truth table66%2/3
A ||= B
A= $hstartB= $hseq->start
ABresult
1X1
011
000
356 # calculate the slice boundaries
357 12 my ($beg, $end);
358 12 for ($type) {
359 12 ▶ /query/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/query/ and do { $beg = $aln->column_from_residue_number($qseq->id, $intvl->[0]); $end = $aln->column_from_residue_number($qseq->id, $intvl->[1]); last } 12 0 12
360 12 $beg = $aln->column_from_residue_number($qseq->id, $intvl->[0]);
361 12 $end = $aln->column_from_residue_number($qseq->id, $intvl->[1]);
362 12 last;
363 };
364 0 ▶ /subject|hit/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/subject|hit/ and do { $beg = $aln->column_from_residue_number($hseq->id, $intvl->[0]); $end = $aln->column_from_residue_number($hseq->id, $intvl->[1]); last } 0 0 0
365 0 $beg = $aln->column_from_residue_number($hseq->id, $intvl->[0]);
366 0 $end = $aln->column_from_residue_number($hseq->id, $intvl->[1]);
367 0 last;
368 };
369 }
370 12 $aln = $aln->slice($beg, $end);
371 12 $qseq = $aln->get_seq_by_pos(1);
372 12 $hseq = $aln->get_seq_by_pos(2);
373 12 $qinc = $qseq->length - $qseq->num_gaps($Bio::LocatableSeq::GAP_SYMBOLS);
374 12 $hinc = $hseq->length - $hseq->num_gaps($Bio::LocatableSeq::GAP_SYMBOLS);
375  
376 12 ▶ push @qfeats, Bio::SeqFeature::Generic->new(
Branch: 2 branches
BranchTrueFalseTotal
$qseq->strand && $qseq->strand < 0 ? : 0 12 12
$qseq->strand && $qseq->strand < 0 ? : 0 12 12
Condition33%2/6
$qseq->strand and $qseq->strand < 0
!ll&&!rl&&r
1200
$qseq->strand and $qseq->strand < 0
!ll&&!rl&&r
1200
MC/DC0%0/2
$qseq->strand and $qseq->strand < 0
$qseq->strand $qseq->strand < 0
MC/DC0%0/2
$qseq->strand and $qseq->strand < 0
$qseq->strand $qseq->strand < 0
Truth table33%1/3
A and B
A= $qseq->strandB= $qseq->strand < 0
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= $qseq->strandB= $qseq->strand < 0
ABresult
0X0
100
111
377 -start => $qlen+1,
378 -end => $qlen+$qinc,
379 -strand => $qseq->strand,
380 -primary => 'query',
381 -source_tag => 'BLAST',
382 -display_name => 'query coordinates',
383 -tag => { query_id => $qseq->id,
384 query_desc => $qseq->desc,
385 query_start => $qstart + (($qseq->strand && $qseq->strand < 0) ? -1 : 1)*$qlen,
386 query_end => $qstart + (($qseq->strand && $qseq->strand < 0) ? -1 : 1)*($qlen+$qinc-1),
387 }
388 );
389 12 ▶ push @hfeats, Bio::SeqFeature::Generic->new(
Branch: 2 branches
BranchTrueFalseTotal
$hseq->strand && $hseq->strand < 0 ? : 0 12 12
$hseq->strand && $hseq->strand < 0 ? : 0 12 12
Condition33%2/6
$hseq->strand and $hseq->strand < 0
!ll&&!rl&&r
1200
$hseq->strand and $hseq->strand < 0
!ll&&!rl&&r
1200
MC/DC0%0/2
$hseq->strand and $hseq->strand < 0
$hseq->strand $hseq->strand < 0
MC/DC0%0/2
$hseq->strand and $hseq->strand < 0
$hseq->strand $hseq->strand < 0
Truth table33%1/3
A and B
A= $hseq->strandB= $hseq->strand < 0
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= $hseq->strandB= $hseq->strand < 0
ABresult
0X0
100
111
390 -start => $hlen+1,
391 -end => $hlen+$hinc,
392 -strand => $hseq->strand,
393 -primary => 'subject/hit',
394 -source_tag => 'BLAST',
395 -display_name => 'subject/hit coordinates',
396 -tag => { subject_id => $hseq->id,
397 subject_desc => $hseq->desc,
398 subject_start => $hstart + (($hseq->strand && $hseq->strand < 0) ? -1 : 1)*$hlen,
399 subject_end => $hstart + (($hseq->strand && $hseq->strand < 0) ? -1 : 1)*($hlen+$hinc-1)
400 }
401 );
402 12 $query_string .= $qseq->seq;
403 12 $hit_string .= $hseq->seq;
404 12 $qlen += $qinc;
405 12 $hlen += $hinc;
406 }
407 # create the LocatableSeqs and add the features to each
408 # then add the seqs to the new aln
409 # note in MapTileUtils, Bio::FeatureHolderI methods have been
410 # mixed into Bio::LocatableSeq
411 6 my $qseq = Bio::LocatableSeq->new( -id => 'query',
412 -seq => $query_string);
413 6 $qseq->add_SeqFeature(@qfeats);
414 6 my $hseq = Bio::LocatableSeq->new( -id => 'subject',
415 -seq => $hit_string );
416 6 $hseq->add_SeqFeature(@hfeats);
417 6 $taln->add_seq($qseq);
418 6 $taln->add_seq($hseq);
419 6 push @ret, $taln;
420 }
421
422 1 return @ret;
423 }
424  
425 =head1 STATISTICS
426  
427 =head2 identities
428  
429 Title : identities
430 Usage : $tiling->identities($type, $action, $context)
431 Function: Retrieve the calculated number of identities for the invocant
432 Example :
433 Returns : value of identities (a scalar)
434 Args : scalar $type: one of 'hit', 'subject', 'query'
435 default is 'query'
436 option scalar $action: one of 'exact', 'est', 'fast', 'max'
437 default is 'exact'
438 option scalar $context: strand/frame context string
439 Note : getter only
440  
441 =cut
442  
443 538 ▶sub identities{
Subroutine identities: called CC=2 SCAR=6.9
Pod documented
444 538 my $self = shift;
445 538 my ($type, $action, $context) = @_;
446 538 $self->_check_type_arg(\$type);
447 538 $self->_check_action_arg(\$action);
448 538 $self->_check_context_arg($type, \$context);
449 538 ▶ if (!defined $self->{"identities_${type}_${action}_${context}"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $$self{"identities_${type}_${action}_$context"}) 531 7 538
450 531 $self->_calc_stats($type, $action, $context);
451 }
452 538 return $self->{"identities_${type}_${action}_${context}"};
453 }
454  
455 =head2 conserved
456  
457 Title : conserved
458 Usage : $tiling->conserved($type, $action)
459 Function: Retrieve the calculated number of conserved sites for the invocant
460 Example :
461 Returns : value of conserved (a scalar)
462 Args : scalar $type: one of 'hit', 'subject', 'query'
463 default is 'query'
464 option scalar $action: one of 'exact', 'est', 'fast', 'max'
465 default is 'exact'
466 option scalar $context: strand/frame context string
467 Note : getter only
468  
469 =cut
470  
471 538 ▶sub conserved{
Subroutine conserved: called CC=2 SCAR=7.1
Pod documented
472 538 my $self = shift;
473 538 my ($type, $action, $context) = @_;
474 538 $self->_check_type_arg(\$type);
475 538 $self->_check_action_arg(\$action);
476 538 $self->_check_context_arg($type, \$context);
477 538 ▶ if (!defined $self->{"conserved_${type}_${action}_${context}"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $$self{"conserved_${type}_${action}_$context"}) 0 538 538
478 0 $self->_calc_stats($type, $action, $context);
479 }
480 538 return $self->{"conserved_${type}_${action}_${context}"};
481 }
482  
483 =head2 length
484  
485 Title : length
486 Usage : $tiling->length($type, $action, $context)
487 Function: Retrieve the total length of aligned residues for
488 the seq $type
489 Example :
490 Returns : value of length (a scalar)
491 Args : scalar $type: one of 'hit', 'subject', 'query'
492 default is 'query'
493 option scalar $action: one of 'exact', 'est', 'fast', 'max'
494 default is 'exact'
495 option scalar $context: strand/frame context string
496 Note : getter only
497  
498 =cut
499  
500 1051 ▶sub length{
Subroutine length: called CC=2 SCAR=6.9
Pod documented
501 1051 my $self = shift;
502 1051 my ($type,$action,$context) = @_;
503 1051 $self->_check_type_arg(\$type);
504 1051 $self->_check_action_arg(\$action);
505 1051 $self->_check_context_arg($type, \$context);
506 1051 ▶ if (!defined $self->{"length_${type}_${action}_${context}"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $$self{"length_${type}_${action}_$context"}) 1 1050 1051
507 1 $self->_calc_stats($type, $action, $context);
508 }
509 1051 return $self->{"length_${type}_${action}_${context}"};
510 }
511  
512 =head2 frac
513  
514 Title : frac
515 Usage : $tiling->frac($type, $denom, $action, $context, $method)
516 Function: Return the fraction of sequence length consisting
517 of desired kinds of pairs (given by $method),
518 with respect to $denom
519 Returns : scalar float
520 Args : -type => one of 'hit', 'subject', 'query'
521 -denom => one of 'total', 'aligned'
522 -action => one of 'exact', 'est', 'fast', 'max'
523 -context => strand/frame context string
524 -method => one of 'identical', 'conserved'
525 Note : $denom == 'aligned', return desired_stat/num_aligned
526 $denom == 'total', return desired_stat/_reported_length
527 (i.e., length of the original input sequences)
528 Note : In keeping with the spirit of Bio::Search::HSP::HSPI,
529 reported lengths of translated dna are reduced by
530 a factor of 3, to provide fractions relative to
531 amino acid coordinates.
532  
533 =cut
534  
535 1058 ▶sub frac {
Subroutine frac: called CC=12 SCAR=27.8
Pod documented
536 1058 my $self = shift;
537 1058 my @args = @_;
538 1058 my ($type, $denom, $action, $context, $method) = $self->_rearrange([qw(TYPE DENOM ACTION CONTEXT METHOD)],@args);
539 1058 $self->_check_type_arg(\$type);
540 1058 $self->_check_action_arg(\$action);
541 1058 $self->_check_context_arg($type, \$context);
542 1058 ▶ unless ($method and grep(/^$method$/, qw( identical conserved ))) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($method and grep /^$method$/, ("identical", "conserved")) 0 1058 1058
Condition33%1/3
$method and grep /^$method$/, ("identical", "conserved")
!ll&&!rl&&r
001058
MC/DC0%0/2
$method and grep /^$method$/, ("identical", "conserved")
$method grep /^$method$/, ("identical", "conserved")
Truth table33%1/3
A and B
A= $methodB= grep /^$method$/, ("identical", "conserved")
ABresult
0X0
100
111
543 0 $self->throw("-method must specified; one of ('identical', 'conserved')");
544 }
545 1058 ▶ $denom ||= 'total';
Condition50%1/2
$denom ||= "total"
l!l
10580
MC/DC0%0/1
$denom ||= "total"
$denom
Truth table50%1/2
A
A= $denom
Aresult
11
00
546 1058 ▶ unless (grep /^$denom/, qw( total aligned )) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep /^$denom/, ("total", "aligned")) 0 1058 1058
547 0 $self->throw("Denominator selection must be one of ('total', 'aligned'), not '$denom'");
548 }
549 1058 my $key = "frac_${method}_${type}_${denom}_${action}_${context}";
550 1058 my $stat;
551 1058 for ($method) {
552 1058 ▶ $_ eq 'identical' && do {
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "identical" and do { $stat = $self->identities($type, $action, $context); last } 529 529 1058
553 529 $stat = $self->identities($type, $action, $context);
554 529 last;
555 };
556 529 ▶ $_ eq 'conserved' && do {
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "conserved" and do { $stat = $self->conserved($type, $action, $context); last } 529 0 529
557 529 $stat = $self->conserved($type, $action, $context);
558 529 last;
559 };
560 0 do {
561 0 $self->throw("What are YOU doing here?");
562 };
563 }
564 1058 ▶ if (!defined $self->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{$key}) 1046 12 1058
565 1046 for ($denom) {
566 1046 ▶ /total/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/total/ and do { $self->{$key} = $stat / $self->_reported_length($type); last } 0 1046 1046
567 0 $self->{$key} =
568 $stat/$self->_reported_length($type); # need fudge fac??
569 0 last;
570 };
571 1046 ▶ /aligned/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/aligned/ and do { $self->{$key} = $stat / $self->length($type, $action, $context); last } 1046 0 1046
572 1046 $self->{$key} =
573 $stat/$self->length($type,$action,$context);
574 1046 last;
575 };
576 0 do {
577 0 $self->throw("What are YOU doing here?");
578 };
579 }
580 }
581 1058 return $self->{$key};
582 }
583  
584 =head2 frac_identical
585  
586 Title : frac_identical
587 Usage : $tiling->frac_identical($type, $denom, $action, $context)
588 Function: Return the fraction of sequence length consisting
589 of identical pairs, with respect to $denom
590 Returns : scalar float
591 Args : -type => one of 'hit', 'subject', 'query'
592 -denom => one of 'total', 'aligned'
593 -action => one of 'exact', 'est', 'fast', 'max'
594 -context => strand/frame context string
595 Note : $denom == 'aligned', return conserved/num_aligned
596 $denom == 'total', return conserved/_reported_length
597 (i.e., length of the original input sequences)
598 Note : In keeping with the spirit of Bio::Search::HSP::HSPI,
599 reported lengths of translated dna are reduced by
600 a factor of 3, to provide fractions relative to
601 amino acid coordinates.
602 Note : This an alias that calls frac()
603  
604 =cut
605  
606 3 ▶sub frac_identical{
Subroutine frac_identical: called CC=1 SCAR=0.0
Pod documented
607 3 my $self = shift;
608 3 my @args = @_;
609 3 my ($type, $denom, $action,$context) = $self->_rearrange( [qw[ TYPE DENOM ACTION CONTEXT]],@args );
610 3 $self->frac( -type=>$type, -denom=>$denom, -action=>$action, -method=>'identical', -context=>$context);
611 }
612  
613 =head2 frac_conserved
614  
615 Title : frac_conserved
616 Usage : $tiling->frac_conserved($type, $denom, $action, $context)
617 Function: Return the fraction of sequence length consisting
618 of conserved pairs, with respect to $denom
619 Returns : scalar float
620 Args : -type => one of 'hit', 'subject', 'query'
621 -denom => one of 'total', 'aligned'
622 -action => one of 'exact', 'est', 'fast', 'max'
623 -context => strand/frame context string
624 Note : $denom == 'aligned', return conserved/num_aligned
625 $denom == 'total', return conserved/_reported_length
626 (i.e., length of the original input sequences)
627 Note : In keeping with the spirit of Bio::Search::HSP::HSPI,
628 reported lengths of translated dna are reduced by
629 a factor of 3, to provide fractions relative to
630 amino acid coordinates.
631 Note : This an alias that calls frac()
632  
633 =cut
634  
635 3 ▶sub frac_conserved{
Subroutine frac_conserved: called CC=1 SCAR=0.0
Pod documented
636 3 my $self = shift;
637 3 my @args = @_;
638 3 my ($type, $denom, $action, $context) = $self->_rearrange( [qw[ TYPE DENOM ACTION CONTEXT]],@args );
639 3 $self->frac( -type=>$type, -denom=>$denom, -action=>$action, -context=>$context, -method=>'conserved');
640 }
641  
642 =head2 frac_aligned
643  
644 Title : frac_aligned
645 Aliases : frac_aligned_query - frac_aligned(-type=>'query',...)
646 frac_aligned_hit - frac_aligned(-type=>'hit',...)
647 Usage : $tiling->frac_aligned(-type=>$type,
648 -action=>$action,
649 -context=>$context)
650 Function: Return the fraction of input sequence length
651 that was aligned by the algorithm
652 Returns : scalar float
653 Args : -type => one of 'hit', 'subject', 'query'
654 -action => one of 'exact', 'est', 'fast', 'max'
655 -context => strand/frame context string
656  
657 =cut
658  
659 4 ▶sub frac_aligned{
Subroutine frac_aligned: called CC=2 SCAR=7.0
Pod documented
660 4 my ($self, @args) = @_;
661 4 my ($type, $action, $context) = $self->_rearrange([qw(TYPE ACTION CONTEXT)],@args);
662 4 $self->_check_type_arg(\$type);
663 4 $self->_check_action_arg(\$action);
664 4 $self->_check_context_arg($type, \$context);
665 4 ▶ if (!$self->{"frac_aligned_${type}_${action}_${context}"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$self{"frac_aligned_${type}_${action}_$context"}) 4 0 4
666 4 $self->{"frac_aligned_${type}_${action}_${context}"} = $self->num_aligned($type,$action,$context)/$self->_reported_length($type);
667 }
668 4 return $self->{"frac_aligned_${type}_${action}_${context}"};
669 }
670  
671 2 ▶sub frac_aligned_query { shift->frac_aligned(-type=>'query', @_) }
Subroutine frac_aligned_query: called CC=1 SCAR=0.0
Pod undocumented
672 2 ▶sub frac_aligned_hit { shift->frac_aligned(-type=>'hit', @_) }
Subroutine frac_aligned_hit: called CC=1 SCAR=0.0
Pod undocumented
673
674  
675 =head2 num_aligned
676  
677 Title : num_aligned
678 Usage : $tiling->num_aligned(-type=>$type)
679 Function: Return the number of residues of sequence $type
680 that were aligned by the algorithm
681 Returns : scalar int
682 Args : -type => one of 'hit', 'subject', 'query'
683 -action => one of 'exact', 'est', 'fast', 'max'
684 -context => strand/frame context string
685 Note : Since this is calculated from reported coordinates,
686 not symbol string counts, it is already in terms of
687 "logical length"
688 Note : Aliases length()
689  
690 =cut
691  
692 4 ▶sub num_aligned { shift->length( @_ ) };
Subroutine num_aligned: called CC=1 SCAR=0.0
Pod documented
693  
694 =head2 num_unaligned
695  
696 Title : num_unaligned
697 Usage : $tiling->num_unaligned(-type=>$type)
698 Function: Return the number of residues of sequence $type
699 that were left unaligned by the algorithm
700 Returns : scalar int
701 Args : -type => one of 'hit', 'subject', 'query'
702 -action => one of 'exact', 'est', 'fast', 'max'
703 -context => strand/frame context string
704 Note : Since this is calculated from reported coordinates,
705 not symbol string counts, it is already in terms of
706 "logical length"
707  
708 =cut
709  
710 0 ▶sub num_unaligned {
Subroutine num_unaligned: not called CC=2 SCAR=17.9
Pod documented
711 0 my $self = shift;
712 0 my ($type,$action,$context) = @_;
713 0 my $ret;
714 0 $self->_check_type_arg(\$type);
715 0 $self->_check_action_arg(\$action);
716 0 $self->_check_context_arg($type, \$context);
717 0 ▶ if (!defined $self->{"num_unaligned_${type}_${action}_${context}"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $$self{"num_unaligned_${type}_${action}_$context"}) 0 0 0
718 0 $self->{"num_unaligned_${type}_${action}_${context}"} = $self->_reported_length($type)-$self->num_aligned($type,$action,$context);
719 }
720 0 return $self->{"num_unaligned_${type}_${action}_${context}"};
721 }
722
723  
724 =head2 range
725  
726 Title : range
727 Usage : $tiling->range(-type=>$type)
728 Function: Returns the extent of the longest tiling
729 as ($min_coord, $max_coord)
730 Returns : array of two scalar integers
731 Args : -type => one of 'hit', 'subject', 'query'
732 -context => strand/frame context string
733  
734 =cut
735  
736 8 ▶sub range {
Subroutine range: called CC=1 SCAR=0.0
Pod documented
737 8 my ($self, $type, $context) = @_;
738 8 $self->_check_type_arg(\$type);
739 8 $self->_check_context_arg($type, \$context);
740 8 my @a = $self->_contig_intersection($type,$context);
741 8 return ($a[0][0], $a[-1][1]);
742 }
743  
744  
745  
746 =head1 ACCESSORS
747  
748 =head2 coverage_map
749  
750 Title : coverage_map
751 Usage : $map = $tiling->coverage_map($type)
752 Function: Property to contain the coverage map calculated
753 by _calc_coverage_map() - see that for
754 details
755 Example :
756 Returns : value of coverage_map_$type as an array
757 Args : scalar $type: one of 'hit', 'subject', 'query'
758 default is 'query'
759 Note : getter
760  
761 =cut
762  
763 332 ▶sub coverage_map{
Subroutine coverage_map: called CC=3 SCAR=11.2
Pod documented
764 332 my $self = shift;
765 332 my ($type, $context) = @_;
766 332 $self->_check_type_arg(\$type);
767 332 $self->_check_context_arg($type, \$context);
768  
769 332 ▶ if (!defined $self->{"coverage_map_${type}_${context}"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $$self{"coverage_map_${type}_$context"}) 203 129 332
770 # following calculates coverage maps in all strands/frames
771 # if necessary
772 203 $self->_calc_coverage_map($type, $context);
773 }
774 # if undef is returned, then there were no hsps for given strand/frame
775 332 ▶ if (!defined $self->{"coverage_map_${type}_${context}"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $$self{"coverage_map_${type}_$context"}) 0 332 332
776 0 $self->warn("No HSPS present for type '$type' in context '$context' for this hit");
777 0 return undef;
778 }
779 332 return @{$self->{"coverage_map_${type}_${context}"}};
780 }
781  
782 =head2 coverage_map_as_text
783  
784 Title : coverage_map_as_text
785 Usage : $tiling->coverage_map_as_text($type, $legend_flag)
786 Function: Format a text-graphic representation of the
787 coverage map
788 Returns : an array of scalar strings, suitable for printing
789 Args : $type: one of 'query', 'hit', 'subject'
790 $context: strand/frame context string
791 $legend_flag: boolean; add a legend indicating
792 the actual interval coordinates for each component
793 interval and hsp (in the $type sequence context)
794 Example : print $tiling->coverage_map_as_text('query',1);
795  
796 =cut
797  
798 0 ▶sub coverage_map_as_text{
Subroutine coverage_map_as_text: not called CC=6 SCAR=37.4
Pod documented
799 0 my $self = shift;
800 0 my ($type, $context, $legend_q) = @_;
801 0 $self->_check_type_arg(\$type);
802 0 $self->_check_context_arg($type, \$context);
803  
804 0 my @map = $self->coverage_map($type, $context);
805 0 my @ret;
806 0 my @hsps = $self->hit->hsps;
807 0 my %hsps_i;
808 0 require Tie::RefHash;
809 0 tie %hsps_i, 'Tie::RefHash';
810 0 @hsps_i{@hsps} = (0..$#hsps);
811 0 my @mx;
812 0 foreach (0..$#map) {
813 0 my @hspx = ('') x @hsps;
814 0 my @these_hsps = @{$map[$_]->[1]};
815 0 @hspx[@hsps_i{@these_hsps}] = ('*') x @these_hsps;
816 0 $mx[$_] = \@hspx;
817 }
818 0 untie %hsps_i;
819  
820 0 push @ret, "\tIntvl\n";
821 0 push @ret, "HSPS\t", join ("\t", (0..$#map)), "\n";
822 0 foreach my $h (0..$#hsps) {
823 0 push @ret, join("\t", $h, map { $mx[$_][$h] } (0..$#map) ),"\n";
824 }
825 0 ▶ if ($legend_q) {
Branch: 1 branch
BranchTrueFalseTotal
if ($legend_q) 0 0 0
826 0 push @ret, "Interval legend\n";
827 0 foreach (0..$#map) {
828 0 push @ret, sprintf("%d\t[%d, %d]\n", $_, @{$map[$_][0]});
829 }
830 0 push @ret, "HSP legend\n";
831 0 my @ints = get_intervals_from_hsps($type,@hsps);
832 0 foreach (0..$#hsps) {
833 0 push @ret, sprintf("%d\t[%d, %d]\n", $_, @{$ints[$_]});
834 }
835 }
836 0 return @ret;
837 }
838  
839 =head2 hit
840  
841 Title : hit
842 Usage : $tiling->hit
843 Function:
844 Example :
845 Returns : The HitI object associated with the invocant
846 Args : none
847 Note : getter only
848  
849 =cut
850  
851 5229 ▶sub hit{
Subroutine hit: called CC=2 SCAR=7.1
Pod documented
852 5229 my $self = shift;
853 5229 ▶ $self->warn("Getter only") if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 5229 5229
854 5229 return $self->{'hit'};
855 }
856  
857 =head2 hsps
858  
859 Title : hsps
860 Usage : $tiling->hsps()
861 Function: Container for the HSP objects associated with invocant
862 Example :
863 Returns : an array of hsps associated with the hit
864 Args : on set, new value (an arrayref or undef, optional)
865  
866 =cut
867  
868 1768 ▶sub hsps{
Subroutine hsps: called CC=2 SCAR=6.9
Pod documented
869 1768 my $self = shift;
870 1768 ▶ return $self->{'hsps'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 519 1249 1768
871 1249 return @{$self->{'hsps'}};
872 }
873  
874 =head2 contexts
875  
876 Title : contexts
877 Usage : @contexts = $tiling->context($type) or
878 @indices = $tiling->context($type, $context)
879 Function: Retrieve the set of available contexts in the hit,
880 or the indices of hsps having the given context
881 (integer indices for the array returned by $self->hsps)
882 Returns : array of scalar context strings or
883 array of scalar positive integers
884 undef if no hsps in given context
885 Args : $type: one of 'query', 'hit', 'subject'
886 optional $context: context string
887  
888 =cut
889  
890 1032 ▶sub contexts{
Subroutine contexts: called CC=3 SCAR=11.0
Pod documented
891 1032 my $self = shift;
892 1032 my ($type, $context) = @_;
893 1032 $self->_check_type_arg(\$type);
894 1032 ▶ return keys %{$self->{"_contexts_$type"}} unless defined $context;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $context 403 629 1032
895 629 ▶ return undef unless $self->{"_contexts_$type"}{$context};
Branch: 1 branch
BranchTrueFalseTotal
unless $$self{"_contexts_$type"}{$context} 0 629 629
896 629 return @{$self->{"_contexts_$type"}{$context}};
897 }
898  
899 =head2 mapping
900  
901 Title : mapping
902 Usage : $tiling->mapping($type)
903 Function: Retrieve the mapping coefficient for the sequence type
904 based on the underlying algorithm
905 Returns : scalar integer (mapping coefficient)
906 Args : $type: one of 'query', 'hit', 'subject'
907 Note : getter only (set in constructor)
908  
909 =cut
910  
911 505 ▶sub mapping{
Subroutine mapping: called CC=1 SCAR=0.0
Pod documented
912 505 my $self = shift;
913 505 my $type = shift;
914 505 $self->_check_type_arg(\$type);
915 505 return $self->{"_mapping_${type}"};
916 }
917  
918 =head2 default_context
919  
920 Title : default_context
921 Usage : $tiling->default_context($type)
922 Function: Retrieve the default strand/frame context string
923 for the sequence type based on the underlying algorithm
924 Returns : scalar string (context string)
925 Args : $type: one of 'query', 'hit', 'subject'
926 Note : getter only (set in constructor)
927  
928 =cut
929  
930 298 ▶sub default_context{
Subroutine default_context: called CC=1 SCAR=0.0
Pod documented
931 298 my $self = shift;
932 298 my $type = shift;
933 298 $self->_check_type_arg(\$type);
934 298 return $self->{"_def_context_${type}"};
935 }
936  
937 =head2 algorithm
938  
939 Title : algorithm
940 Usage : $tiling->algorithm
941 Function: Retrieve the algorithm name associated with the
942 invocant's hit object
943 Returns : scalar string
944 Args : none
945 Note : getter only (set in constructor)
946  
947 =cut
948  
949 0 ▶sub algorithm{
Subroutine algorithm: not called CC=2 SCAR=17.9
Pod documented
950 0 my $self = shift;
951 0 ▶ $self->warn("Getter only") if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
952 0 return $self->{"_algorithm"};
953 }
954  
955 =head1 "PRIVATE" METHODS
956  
957 =head2 Calculators
958  
959 See L<Bio::Search::Tiling::MapTileUtils> for lower level
960 calculation methods.
961  
962 =head2 _calc_coverage_map
963  
964 Title : _calc_coverage_map
965 Usage : $tiling->_calc_coverage_map($type)
966 Function: Calculates the coverage map for the object's associated
967 hit from the perspective of the desired $type (see Args:)
968 and sets the coverage_map() property
969 Returns : True on success
970 Args : optional scalar $type: one of 'hit'|'subject'|'query'
971 default is 'query'
972 Note : The "coverage map" is an array with the following format:
973 ( [ $component_interval => [ @containing_hsps ] ], ... ),
974 where $component_interval is a closed interval (see
975 DESCRIPTION) of the form [$a0, $a1] with $a0 <= $a1, and
976 @containing_hsps is an array of all HspI objects in the hit
977 which completely contain the $component_interval.
978 The set of $component_interval's is a disjoint decomposition
979 of the minimum set of minimal intervals that completely
980 cover the hit's HSPs (from the perspective of the $type)
981 Note : This calculates the map for all strand/frame contexts available
982 in the hit
983  
984 =cut
985  
986 207 ▶sub _calc_coverage_map {
Subroutine _calc_coverage_map: called CC=8 SCAR=20.8
987 207 my $self = shift;
988 207 my ($type) = @_;
989 207 $self->_check_type_arg(\$type);
990  
991 # obtain the [start, end] intervals for all hsps in the hit (relative
992 # to the type)
993 207 ▶ unless ($self->{'hsps'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"hsps"}) 0 207 207
994 0 $self->warn("No HSPs for this hit");
995 0 return;
996 }
997  
998 207 my (@map, @hsps, %filters, @intervals);
999
1000  
1001 # conversion here?
1002 207 my $c = $self->mapping($type);
1003
1004 # create the possible maps
1005 207 for my $context ($self->contexts($type)) {
1006 219 @map = ();
1007 219 @hsps = ($self->hsps)[$self->contexts($type, $context)];
1008 219 @intervals = get_intervals_from_hsps( $type, @hsps );
1009 # the "frame"
1010 219 my $f = ($intervals[0]->[0] - 1) % $c;
1011  
1012 # convert interval endpoints...
1013 219 for (@intervals) {
1014 536 $$_[0] = ($$_[0] - $f + $c - 1)/$c;
1015 536 $$_[1] = ($$_[1] - $f)/$c;
1016 }
1017
1018 # determine the minimal set of disjoint intervals that cover the
1019 # set of hsp intervals
1020 219 my @dj_set = interval_tiling(\@intervals);
1021  
1022 # decompose each disjoint interval into another set of disjoint
1023 # intervals, each of which is completely contained within the
1024 # original hsp intervals with which it overlaps
1025 219 my $i=0;
1026 219 my @decomp;
1027 219 for my $dj_elt (@dj_set) {
1028 432 my ($covering, $indices) = @$dj_elt;
1029 432 my @covering_hsps = @hsps[@$indices];
1030 432 my @coverers = @intervals[@$indices];
1031 432 @decomp = decompose_interval( \@coverers );
1032 432 for (@decomp) {
1033 638 my ($component, $container_indices) = @{$_};
1034 638 push @map, [ $component,
1035 [@covering_hsps[@$container_indices]] ];
1036 }
1037 432 1;
1038 }
1039
1040 # unconvert the components:
1041 #####
1042 219 foreach (@map) {
1043 638 $$_[0][0] = $c*$$_[0][0] - $c + 1 + $f;
1044 638 $$_[0][1] = $c*$$_[0][1] + $f;
1045 }
1046 219 foreach (@dj_set) {
1047 432 $$_[0][0] = $c*$$_[0][0] - $c + 1 + $f;
1048 432 $$_[0][1] = $c*$$_[0][1] + $f;
1049 }
1050  
1051 # sort the map on the interval left-ends
1052 219 @map = sort { $a->[0][0]<=>$b->[0][0] } @map;
1053 219 $self->{"coverage_map_${type}_${context}"} = [@map];
1054 # set the _contig_intersection attribute here (side effect)
1055 219 $self->{"_contig_intersection_${type}_${context}"} = [map { $$_[0] } @map];
1056 }
1057  
1058 207 return 1; # success
1059 }
1060  
1061 =head2 _calc_stats
1062  
1063 Title : _calc_stats
1064 Usage : $tiling->_calc_stats($type, $action, $context)
1065 Function: Calculates [estimated] tiling statistics (identities, conserved sites
1066 length) and sets the public accessors
1067 Returns : True on success
1068 Args : scalar $type: one of 'hit', 'subject', 'query'
1069 default is 'query'
1070 optional scalar $action: requests calculation method
1071 currently one of 'exact', 'est', 'fast', 'max'
1072 option scalar $context: strand/frame context string
1073 Note : Action: The statistics are calculated by summing quantities
1074 over the disjoint component intervals, taking into account
1075 coverage of those intervals by multiple HSPs. The action
1076 tells the algorithm how to obtain those quantities--
1077 'exact' will use Bio::Search::HSP::HSPI::matches
1078 to count the appropriate segment of the homology string;
1079 'est' will estimate the statistics by multiplying the
1080 fraction of the HSP overlapped by the component interval
1081 (see MapTileUtils) by the BLAST-reported identities/postives
1082 (this may be convenient for BLAST summary report formats)
1083 * Both exact and est take the average over the number of HSPs
1084 that overlap the component interval.
1085 'max' uses the exact method to calculate the statistics,
1086 and returns only the maximum identites/positives over
1087 overlapping HSP for the component interval. No averaging
1088 is involved here.
1089 'fast' doesn't involve tiling at all (hence the name),
1090 but it seems like a very good estimate, and uses only
1091 reported values, and so does not require sequence data. It
1092 calculates an average of reported identities, conserved
1093 sites, and lengths, over unmodified hsps in the hit,
1094 weighted by the length of the hsps.
1095  
1096 =cut
1097  
1098 532 ▶sub _calc_stats {
Subroutine _calc_stats: called CC=15 SCAR=27.1
1099 532 my $self = shift;
1100 532 my ($type, $action, $context) = @_;
1101 # need to check args here, in case method is called internally.
1102 532 $self->_check_type_arg(\$type);
1103 532 $self->_check_action_arg(\$action);
1104 532 $self->_check_context_arg($type, \$context);
1105 532 my ($ident, $cons, $length) = (0,0,0);
1106  
1107 # fast : avoid coverage map altogether, get a pretty damn
1108 # good estimate with a weighted average of reported hsp
1109 # statistics
1110  
1111 532 ▶ ($action eq 'fast') && do {
Branch: 1 branch
BranchTrueFalseTotal
$action eq "fast" and do { my(@hsps) = $self->hit->hsps; @hsps = @hsps[$self->contexts($type, $context)]; my(@wt) = map({$_->length($type);} @hsps); my $sum = eval join("+", @wt); $_ /= $sum foreach (@wt); foreach $_ (@hsps) { my $wt = shift @wt; $ident += $wt * $_->matches_MT($type, "identities"); $cons += $wt * $_->matches_MT($type, "conserved"); $length += $wt * $_->length($type); } } 204 328 532
1112 204 my @hsps = $self->hit->hsps;
1113 204 @hsps = @hsps[$self->contexts($type, $context)];
1114 # weights for averages
1115 204 my @wt = map {$_->length($type)} @hsps;
1116 204 my $sum = eval( join('+',@wt) );
1117 204 $_ /= $sum for (@wt);
1118 204 for (@hsps) {
1119 450 my $wt = shift @wt;
1120 450 $ident += $wt*$_->matches_MT($type,'identities');
1121 450 $cons += $wt*$_->matches_MT($type,'conserved');
1122 450 $length += $wt*$_->length($type);
1123 }
1124 };
1125  
1126 # or, do tiling
1127  
1128 # calculate identities/conserved sites in tiling
1129 # estimate based on the fraction of the component interval covered
1130 # and ident/cons reported by the HSPs
1131 532 ▶ ($action ne 'fast') && do {
Branch: 1 branch
BranchTrueFalseTotal
$action ne "fast" and do { foreach $_ ($self->coverage_map($type, $context)) { () = @{$_;}; my $len = $intvl->[1] - $intvl->[0] + 1; my $ncover = $action eq "max" ? 1 : scalar @$hsps; () = (0, 0); foreach my $hsp (@$hsps) { foreach $_ ($action) { $_ eq "est" and do { () = $hsp->matches_MT("-type", $type, "-action", "searchutils"); my $frac = $len / $hsp->length($type); $acc_i += $inc_i * $frac; $acc_c += $inc_c * $frac; last }; $_ eq "max" and do { () = $hsp->matches_MT("-type", $type, "-action", "searchutils", "-start", $intvl->[0], "-end", $intvl->[1]); $acc_i = $acc_i > $inc_i ? $acc_i : $inc_i; $acc_c = $acc_c > $inc_c ? $acc_c : $inc_c; last }; !$_ || $_ eq "exact" and do { () = $hsp->matches_MT("-type", $type, "-action", "searchutils", "-start", $intvl->[0], "-end", $intvl->[1]); $acc_i += $inc_i; $acc_c += $inc_c; last }; } ; } ; $ident += $acc_i / $ncover; $cons += $acc_c / $ncover; $length += $len; } } 328 204 532
1132 328 foreach ($self->coverage_map($type, $context)) {
1133 1384 my ($intvl, $hsps) = @{$_};
1134 1384 my $len = ($$intvl[1]-$$intvl[0]+1);
1135 1384 ▶ my $ncover = ($action eq 'max') ? 1 : scalar @$hsps;
Branch: 1 branch
BranchTrueFalseTotal
$action eq 'max' ? : 393 991 1384
1136 1384 my ($acc_i, $acc_c) = (0,0);
1137 1384 foreach my $hsp (@$hsps) {
1138 1764 for ($action) {
1139 1764 ▶ ($_ eq 'est') && do {
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "est" and do { () = $hsp->matches_MT("-type", $type, "-action", "searchutils"); my $frac = $len / $hsp->length($type); $acc_i += $inc_i * $frac; $acc_c += $inc_c * $frac; last } 788 976 1764
1140 788 my ($inc_i, $inc_c) = $hsp->matches_MT(
1141 -type => $type,
1142 -action => 'searchutils',
1143 );
1144 788 my $frac = $len/$hsp->length($type);
1145 788 $acc_i += $inc_i * $frac;
1146 788 $acc_c += $inc_c * $frac;
1147 788 last;
1148 };
1149 976 ▶ ($_ eq 'max') && do {
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "max" and do { () = $hsp->matches_MT("-type", $type, "-action", "searchutils", "-start", $intvl->[0], "-end", $intvl->[1]); $acc_i = $acc_i > $inc_i ? $acc_i : $inc_i; $acc_c = $acc_c > $inc_c ? $acc_c : $inc_c; last } 483 493 976
1150 483 my ($inc_i, $inc_c) = $hsp->matches_MT(
1151 -type => $type,
1152 -action => 'searchutils',
1153 -start => $$intvl[0],
1154 -end => $$intvl[1]
1155 );
1156 483 ▶ $acc_i = ($acc_i > $inc_i) ? $acc_i : $inc_i;
Branch: 1 branch
BranchTrueFalseTotal
$acc_i > $inc_i ? : 40 443 483
1157 483 ▶ $acc_c = ($acc_c > $inc_c) ? $acc_c : $inc_c;
Branch: 1 branch
BranchTrueFalseTotal
$acc_c > $inc_c ? : 49 434 483
1158 483 last;
1159 };
1160 493 ▶ (!$_ || ($_ eq 'exact')) && do {
Branch: 1 branch
BranchTrueFalseTotal
!$_ || $_ eq "exact" and do { () = $hsp->matches_MT("-type", $type, "-action", "searchutils", "-start", $intvl->[0], "-end", $intvl->[1]); $acc_i += $inc_i; $acc_c += $inc_c; last } 493 0 493
Condition33%1/3
not $_ or $_ eq "exact"
l!l&&r!l&&!r
04930
MC/DC0%0/2
not $_ or $_ eq "exact"
not $_ $_ eq "exact"
Truth table33%1/3
not(A) or B
A= not $_B= $_ eq "exact"
ABresult
1X1
011
000
1161 493 my ($inc_i, $inc_c) = $hsp->matches_MT(
1162 -type => $type,
1163 -action => 'searchutils',
1164 -start => $$intvl[0],
1165 -end => $$intvl[1]
1166 );
1167 493 $acc_i += $inc_i;
1168 493 $acc_c += $inc_c;
1169 493 last;
1170 };
1171 }
1172 }
1173 1384 $ident += ($acc_i/$ncover);
1174 1384 $cons += ($acc_c/$ncover);
1175 1384 $length += $len;
1176 }
1177 };
1178
1179 532 $self->{"identities_${type}_${action}_${context}"} = $ident;
1180 532 $self->{"conserved_${type}_${action}_${context}"} = $cons;
1181 532 $self->{"length_${type}_${action}_${context}"} = $length;
1182
1183 532 return 1;
1184 }
1185  
1186 =head2 Tiling Helper Methods
1187  
1188 =cut
1189  
1190 # coverage_map is of the form
1191 # ( [ $interval, \@containing_hsps ], ... )
1192  
1193 # so, for each interval, pick one of the containing hsps,
1194 # and return the union of all the picks.
1195  
1196 # use the combinatorial generating iterator, with
1197 # the urns containing the @containing_hsps for each
1198 # interval
1199  
1200 =head2 _make_tiling_iterator
1201  
1202 Title : _make_tiling_iterator
1203 Usage : $self->_make_tiling_iterator($type)
1204 Function: Create an iterator code ref that will step through all
1205 minimal combinations of HSPs that produce complete coverage
1206 of the $type ('hit', 'subject', 'query') sequence,
1207 and set the correct iterator property of the invocant
1208 Example :
1209 Returns : The iterator
1210 Args : scalar $type, one of 'hit', 'subject', 'query';
1211 default is 'query'
1212  
1213 =cut
1214  
1215 3 ▶sub _make_tiling_iterator {
Subroutine _make_tiling_iterator: called CC=1 SCAR=0.0
1216 ### create the urns
1217 3 my $self = shift;
1218 3 my ($type, $context) = @_;
1219 3 $self->_check_type_arg(\$type);
1220 3 $self->_check_context_arg($type, \$context);
1221  
1222 # initialize the urns
1223 3 my @urns = map { [0, $$_[1]] } $self->coverage_map($type, $context);
1224  
1225 3 my $FINISHED = 0;
1226 271 ▶ my $iter = sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
1227 # rewind?
1228 271 ▶ if (my $rewind = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rewind = shift()) 2 269 271
1229 # reinitialize urn indices
1230 2 $$_[0] = 0 for (@urns);
1231 2 $FINISHED = 0;
1232 2 return 1;
1233 }
1234 # check if done...
1235 269 ▶ return if $FINISHED;
Branch: 1 branch
BranchTrueFalseTotal
if $FINISHED 3 266 269
1236  
1237 266 my $finished_incrementing = 0;
1238 # @ret is the collector of urn choices
1239 266 my @ret;
1240  
1241 266 for my $urn (@urns) {
1242 4482 my ($n, $hsps) = @$urn;
1243 4482 push @ret, $$hsps[$n];
1244 4482 ▶ unless ($finished_incrementing) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($finished_incrementing) 1086 3396 4482
1245 1086 ▶ if ($n == $#$hsps) { $$urn[0] = 0; }
Branch: 1 branch
BranchTrueFalseTotal
if ($n == $hsps->$#*) { } 823 263 1086
1246 263 else { ($$urn[0])++; $finished_incrementing = 1 }
1247 }
1248 }
1249  
1250 # backstop...
1251 266 ▶ $FINISHED = 1 unless $finished_incrementing;
Branch: 1 branch
BranchTrueFalseTotal
unless $finished_incrementing 3 263 266
1252 # uniquify @ret
1253 # $hsp->rank is a unique identifier for an hsp in a hit.
1254 # preserve order in @ret
1255
1256 266 my (%order, %uniq);
1257 266 @order{(0..$#ret)} = @ret;
1258 266 $uniq{$order{$_}->rank} = $_ for (0..$#ret);
1259 266 @ret = @order{ sort {$a<=>$b} values %uniq };
1260  
1261 266 return @ret;
1262 3 };
1263 3 return $iter;
1264 }
1265  
1266 =head2 _tiling_iterator
1267  
1268 Title : _tiling_iterator
1269 Usage : $tiling->_tiling_iterator($type,$context)
1270 Function: Retrieve the tiling iterator coderef for the requested
1271 $type ('hit', 'subject', 'query')
1272 Example :
1273 Returns : coderef to the desired iterator
1274 Args : scalar $type, one of 'hit', 'subject', 'query'
1275 default is 'query'
1276 option scalar $context: strand/frame context string
1277 Note : getter only
1278  
1279 =cut
1280  
1281 270 ▶sub _tiling_iterator {
Subroutine _tiling_iterator: called CC=2 SCAR=6.9
1282 270 my $self = shift;
1283 270 my ($type, $context) = @_;
1284 270 $self->_check_type_arg(\$type);
1285 270 $self->_check_context_arg($type, \$context);
1286  
1287 270 ▶ if (!defined $self->{"_tiling_iterator_${type}_${context}"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $$self{"_tiling_iterator_${type}_$context"}) 2 268 270
1288 2 $self->{"_tiling_iterator_${type}_${context}"} =
1289 $self->_make_tiling_iterator($type,$context);
1290 }
1291 270 return $self->{"_tiling_iterator_${type}_${context}"};
1292 }
1293 =head2 Construction Helper Methods
1294  
1295 See also L<Bio::Search::Tiling::MapTileUtils>.
1296  
1297 =cut
1298  
1299 8297 ▶sub _check_type_arg {
Subroutine _check_type_arg: called CC=4 SCAR=13.9
1300 8297 my $self = shift;
1301 8297 my $typeref = shift;
1302 8297 ▶ $$typeref ||= 'query';
Condition100%2/2
$$typeref ||= "query"
l!l
7743554
MC/DC100%1/1
$$typeref ||= "query"
$$typeref
Truth table100%2/2
A
A= $$typeref
Aresult
11
00
1303 8297 ▶ $self->throw("Unknown type '$$typeref'") unless grep(/^$$typeref$/, qw( hit query subject ));
Branch: 1 branch
BranchTrueFalseTotal
unless grep /^$$typeref$/, ("hit", "query", "subject") 0 8297 8297
1304 8297 ▶ $$typeref = 'hit' if $$typeref eq 'subject';
Branch: 1 branch
BranchTrueFalseTotal
if $$typeref eq "subject" 266 8031 8297
1305 8297 return 1;
1306 }
1307  
1308 3721 ▶sub _check_action_arg {
Subroutine _check_action_arg: called CC=6 SCAR=17.9
1309 3721 my $self = shift;
1310 3721 my $actionref = shift;
1311 3721 ▶ if (!$$actionref) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $$actionref) { } 17 3704 3721
1312 17 ▶ $$actionref = ($self->_has_sequence_data ? 'exact' : 'est');
Branch: 1 branch
BranchTrueFalseTotal
$self->_has_sequence_data ? : 13 4 17
1313 }
1314 else {
1315 3704 ▶ $self->throw("Calc action '$$actionref' unrecognized") unless grep /^$$actionref$/, qw( est exact fast max );
Branch: 1 branch
BranchTrueFalseTotal
unless grep /^$$actionref$/, ("est", "exact", "fast", "max") 0 3704 3704
1316 3704 ▶ if ($$actionref ne 'est' and !$self->_has_sequence_data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$actionref ne "est" and not $self->_has_sequence_data) 12 3692 3704
Condition100%3/3
$$actionref ne "est" and not $self->_has_sequence_data
!ll&&!rl&&r
1468222412
MC/DC100%2/2
$$actionref ne "est" and not $self->_has_sequence_data
$$actionref ne "est" not $self->_has_sequence_data
Truth table100%3/3
A and not(B)
A= $$actionref ne "est"B= not $self->_has_sequence_data
ABresult
0X0
100
111
1317 12 $self->warn("Blast file did not possess sequence data; defaulting to 'est' action");
1318 12 $$actionref = 'est';
1319 }
1320 }
1321 3721 return 1;
1322 }
1323  
1324 4613 ▶sub _check_context_arg {
Subroutine _check_context_arg: called CC=5 SCAR=16.8
1325 4613 my $self = shift;
1326 4613 my ($type, $contextref) = @_;
1327 4613 ▶ if (!$$contextref) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $$contextref) { } 298 4315 4613
1328 298 ▶ $self->throw("Type '$type' requires strand/frame context for algorithm ".$self->algorithm) unless ($self->mapping($type) == 1);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->mapping($type) == 1 0 298 298
1329 # set default according to default_context attrib
1330 298 $$contextref = $self->default_context($type);
1331 }
1332 else {
1333 0 ▶ ($$contextref =~ /^[mp]$/) && do { $$contextref .= '_' };
Branch: 1 branch
BranchTrueFalseTotal
$$contextref =~ /^[mp]$/ and do { $$contextref .= '_' } 0 4315 4315
1334 4315 ▶ $self->throw("Context '$$contextref' unrecognized") unless
Branch: 1 branch
BranchTrueFalseTotal
unless $$contextref =~ /all|[mp][0-2_]/ 0 4315 4315
1335 $$contextref =~ /all|[mp][0-2_]/;
1336 }
1337
1338 }
1339  
1340 =head2 _make_context_key
1341  
1342 Title : _make_context_key
1343 Alias : _context
1344 Usage : $tiling->_make_context_key(-strand => $strand, -frame => $frame)
1345 Function: create a string indicating strand/frame context; serves as
1346 component of memoizing hash keys
1347 Returns : scalar string
1348 Args : -type => one of ('query', 'hit', 'subject')
1349 -strand => one of (1,0,-1)
1350 -frame => one of (-2, 1, 0, 1, -2)
1351 called w/o args: returns 'all'
1352  
1353 =cut
1354  
1355 546 ▶sub _make_context_key {
Subroutine _make_context_key: called CC=11 SCAR=25.9
1356 546 my $self = shift;
1357 546 my @args = @_;
1358 546 my ($type, $strand, $frame) = $self->_rearrange([qw(TYPE STRAND FRAME)], @args);
1359 546 _check_type_arg(\$type);
1360 546 ▶ return 'all' unless (defined $strand or defined $frame);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $strand or defined $frame 0 546 546
Condition33%1/3
defined $strand or defined $frame
l!l&&r!l&&!r
54600
MC/DC0%0/2
defined $strand or defined $frame
defined $strand defined $frame
Truth table33%1/3
A or B
A= defined $strandB= defined $frame
ABresult
1X1
011
000
1361 546 ▶ if ( defined $strand && $self->_has_strand($type) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $strand and $self->_has_strand($type)) { } 211 335 546
Condition66%2/3
defined $strand and $self->_has_strand($type)
!ll&&!rl&&r
0335211
MC/DC50%1/2
defined $strand and $self->_has_strand($type)
defined $strand $self->_has_strand($type)
Truth table66%2/3
A and B
A= defined $strandB= $self->_has_strand($type)
ABresult
0X0
100
111
1362 211 ▶ if (defined $frame && $self->_has_frame($type)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $frame and $self->_has_frame($type)) { } 94 117 211
Condition66%2/3
defined $frame and $self->_has_frame($type)
!ll&&!rl&&r
011794
MC/DC50%1/2
defined $frame and $self->_has_frame($type)
defined $frame $self->_has_frame($type)
Truth table66%2/3
A and B
A= defined $frameB= $self->_has_frame($type)
ABresult
0X0
100
111
1363 94 ▶ return ($strand >= 0 ? 'p' : 'm').abs($frame);
Branch: 1 branch
BranchTrueFalseTotal
$strand >= 0 ? : 53 41 94
1364 }
1365 else {
1366 117 ▶ return ($strand >= 0 ? 'p_' : 'm_');
Branch: 1 branch
BranchTrueFalseTotal
$strand >= 0 ? : 86 31 117
1367 }
1368 }
1369 else {
1370 335 ▶ if (defined $frame && $self->_has_frame($type)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $frame and $self->_has_frame($type)) { } 0 335 335
Condition33%1/3
defined $frame and $self->_has_frame($type)
!ll&&!rl&&r
03350
MC/DC0%0/2
defined $frame and $self->_has_frame($type)
defined $frame $self->_has_frame($type)
Truth table33%1/3
A and B
A= defined $frameB= $self->_has_frame($type)
ABresult
0X0
100
111
1371 0 $self->warn("Frame defined without strand; punting with plus strand");
1372 0 return 'p'.abs($frame);
1373 }
1374 else {
1375 335 return 'all';
1376 }
1377 }
1378 }
1379  
1380 =head2 _context
1381  
1382 Title : _context
1383 Alias : _make_context_key
1384 Usage : $tiling->_make_context_key(-strand => $strand, -frame => $frame)
1385 Function: create a string indicating strand/frame context; serves as
1386 component of memoizing hash keys
1387 Returns : scalar string
1388 Args : -type => one of ('query', 'hit', 'subject')
1389 -strand => one of (1,0,-1)
1390 -frame => one of (-2, 1, 0, 1, -2)
1391 called w/o args: returns 'all'
1392  
1393 =cut
1394  
1395 546 ▶sub _context { shift->_make_context_key(@_) }
Subroutine _context: called CC=1 SCAR=0.0
1396  
1397 =head2 Predicates
1398  
1399 Most based on a reading of the algorithm name with a configuration lookup.
1400  
1401 =over
1402  
1403 =item _has_sequence_data()
1404  
1405 =cut
1406  
1407 2253 ▶sub _has_sequence_data {
Subroutine _has_sequence_data: called CC=3 SCAR=11.1
1408 2253 my $self = shift;
1409 2253 ▶ $self->throw("Hit attribute not yet set") unless defined $self->hit;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->hit 0 2253 2253
1410 2253 ▶ return (($self->hit->hsps)[0]->seq_str('match') ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
($self->hit->hsps)[0]->seq_str('match') ? : 2237 16 2253
1411 }
1412  
1413 =item _has_logical_length()
1414  
1415 =cut
1416  
1417 0 ▶sub _has_logical_length {
Subroutine _has_logical_length: not called CC=2 SCAR=17.9
1418 0 my $self = shift;
1419 0 my $type = shift;
1420 0 $self->_check_type_arg(\$type);
1421 # based on mapping coeff
1422 0 ▶ $self->throw("Mapping coefficients not yet set") unless defined $self->mapping($type);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->mapping($type) 0 0 0
1423 0 return ($self->mapping($type) > 1);
1424 }
1425  
1426 =item _has_strand()
1427  
1428 =cut
1429  
1430 546 ▶sub _has_strand {
Subroutine _has_strand: called CC=1 SCAR=0.0
1431 546 my $self = shift;
1432 546 my $type = shift;
1433 546 $self->_check_type_arg(\$type);
1434 546 return $self->{"_has_strand_${type}"};
1435 }
1436  
1437 =item _has_frame()
1438  
1439 =cut
1440  
1441 546 ▶sub _has_frame {
Subroutine _has_frame: called CC=1 SCAR=0.0
1442 546 my $self = shift;
1443 546 my $type = shift;
1444 546 $self->_check_type_arg(\$type);
1445 546 return $self->{"_has_frame_${type}"};
1446 }
1447  
1448 =back
1449  
1450 =head1 Private Accessors
1451  
1452 =head2 _contig_intersection
1453  
1454 Title : _contig_intersection
1455 Usage : $tiling->_contig_intersection($type)
1456 Function: Return the minimal set of $type coordinate intervals
1457 covered by the invocant's HSPs
1458 Returns : array of intervals (2-member arrayrefs; see MapTileUtils)
1459 Args : scalar $type: one of 'query', 'hit', 'subject'
1460  
1461 =cut
1462  
1463 8 ▶sub _contig_intersection {
Subroutine _contig_intersection: called CC=2 SCAR=6.9
1464 8 my $self = shift;
1465 8 my ($type, $context) = @_;
1466 8 $self->_check_type_arg(\$type);
1467 8 $self->_check_context_arg($type, \$context);
1468 8 ▶ if (!defined $self->{"_contig_intersection_${type}_${context}"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $$self{"_contig_intersection_${type}_$context"}) 4 4 8
1469 4 $self->_calc_coverage_map($type);
1470 }
1471 8 return @{$self->{"_contig_intersection_${type}_${context}"}};
1472 }
1473  
1474 =head2 _reported_length
1475  
1476 Title : _reported_length
1477 Usage : $tiling->_reported_length($type)
1478 Function: Get the total length of the seq $type
1479 for the invocant's hit object, as reported
1480 by (not calculated from) the input data file
1481 Returns : scalar int
1482 Args : scalar $type: one of 'query', 'hit', 'subject'
1483 Note : This is kludgy; the hit object does not currently
1484 maintain accessors for these values, but the
1485 hsps possess these attributes. This is a wrapper
1486 that allows a consistent access method in the
1487 MapTiling code.
1488 Note : Since this number is based on a reported length,
1489 it is already a "logical length".
1490  
1491 =cut
1492  
1493 4 ▶sub _reported_length {
Subroutine _reported_length: called CC=1 SCAR=0.0
1494 4 my $self = shift;
1495 4 my $type = shift;
1496 4 $self->_check_type_arg(\$type);
1497 4 my $key = uc( $type."_LENGTH" );
1498 4 return ($self->hsps)[0]->{$key};
1499 }
1500  
1501 2 1;
1502
« Bio/SearchIO/psl.pm ↑ Summary Bio/Annotation/Target.pm »