Bio/Search/Tiling/MapTileUtils.pm

filter: Statementstmt 69.6% 225 / 323 Branchbran 57.8% 74 / 128 Conditioncond 52.7% 19 / 36 MC/DCmcdc 25.0% 5 / 20 Subroutinesub 84.0% 21 / 25 Podpod 58.3% 7 / 12 totaltotal 64.5% 351 / 544 CC 93 SCAR 32.1
CC
93
Cov
65%
_allowable_filters
90.0
_ints_as_text
56.0
matches_MT
39.1
CRAP 24.7
« Bio/Tools/Prints.pm ↑ Summary Bio/Tree/Node.pm »
1 #$Id$
2 package Bio::Search::Tiling::MapTileUtils;
3 3 $Bio::Search::Tiling::MapTileUtils::VERSION = '1.7.8';
4  
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 our @ISA = qw( Exporter );
11 3 our @EXPORT = qw( get_intervals_from_hsps
12 interval_tiling
13 decompose_interval
14 containing_hsps
15 covering_groups
16 _allowable_filters
17 _set_attributes
18 _mapping_coeff);
19 }
20  
21 # tiling trials
22 # assumed: intervals are [$a0, $a1], with $a0 <= $a1
23 =head1 NAME
24  
25 Bio::Search::Tiling::MapTileUtils - utilities for manipulating closed intervals for an HSP tiling algorithm
26  
27 =head1 SYNOPSIS
28  
29 Not used directly.
30  
31 =head1 DESCRIPTION
32  
33 Not used directly.
34  
35 =head1 NOTE
36  
37 An "interval" in this module is defined as an arrayref C<[$a0, $a1]>, where
38 C<$a0, $a1> are scalar numbers satisfying C<$a0 E<lt>= $a1>.
39  
40 =head1 AUTHOR
41  
42 Mark A. Jensen - maj -at- fortinbras -dot- us
43  
44 =head1 APPENDIX
45  
46 =head2 interval_tiling
47  
48 Title : interval_tiling()
49 Usage : @tiling = interval_tiling( \@array_of_intervals )
50 Function: Find minimal set of intervals covering the input set
51 Returns : array of arrayrefs of the form
52 ( [$interval => [ @indices_of_collapsed_input_intervals ]], ...)
53 Args : arrayref of intervals
54  
55 =cut
56  
57 219 ▶sub interval_tiling {
Subroutine interval_tiling: called CC=7 SCAR=19.5
Pod documented
58 219 ▶ return unless $_[0]; # no input
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 0 219 219
59 219 my $n = scalar @{$_[0]};
60 219 my %input;
61 219 @input{(0..$n-1)} = @{$_[0]};
62 219 my @active = (0..$n-1);
63 219 my @hold;
64 my @tiled_ints;
65 219 my @ret;
66 219 ▶ while (@active) {
Branch: 1 branch
BranchTrueFalseTotal
if (@active) 432 219 651
67 432 my $tgt = $input{my $tgt_i = shift @active};
68 432 push @tiled_ints, $tgt_i;
69 432 my $tgt_not_disjoint = 1;
70 432 ▶ while ($tgt_not_disjoint) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tgt_not_disjoint) 499 432 931
71 499 $tgt_not_disjoint = 0;
72 499 ▶ while (my $try_i = shift @active) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $try_i = shift @active) 971 499 1470
73 971 my $try = $input{$try_i};
74 971 ▶ if ( !are_disjoint($tgt, $try) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not are_disjoint($tgt, $try)) { } 104 867 971
75 104 $tgt = min_covering_interval($tgt,$try);
76 104 push @tiled_ints, $try_i;
77 104 $tgt_not_disjoint = 1;
78 }
79 else {
80 867 push @hold, $try_i;
81 }
82 }
83 499 ▶ if (!$tgt_not_disjoint) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tgt_not_disjoint) 432 67 499
84 432 push @ret, [ $tgt => [@tiled_ints] ];
85 432 @tiled_ints = ();
86 }
87 499 @active = @hold;
88 499 @hold = ();
89 }
90 }
91 219 return @ret;
92 }
93  
94 =head2 decompose_interval
95  
96 Title : decompose_interval
97 Usage : @decomposition = decompose_interval( \@overlappers )
98 Function: Calculate the disjoint decomposition of a set of
99 overlapping intervals, each annotated with a list of
100 covering intervals
101 Returns : array of arrayrefs of the form
102 ( [[@interval] => [@indices_of_coverers]], ... )
103 Args : arrayref of intervals (arrayrefs like [$a0, $a1], with
104 Note : Each returned interval is associated with a list of indices of the
105 original intervals that cover that decomposition component
106 (scalar size of this list could be called the 'coverage coefficient')
107 Note : Coverage: each component of the decomp is completely contained
108 in the input intervals that overlap it, by construction.
109 Caveat : This routine expects the members of @overlappers to overlap,
110 but doesn't check this.
111  
112 =cut
113  
114 ### what if the input intervals don't overlap?? They MUST overlap; that's
115 ### what interval_tiling() is for.
116  
117 432 ▶sub decompose_interval {
Subroutine decompose_interval: called CC=13 SCAR=25.7
Pod documented
118 432 ▶ return unless $_[0]; # no input
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 0 432 432
119 432 my @ints = @{$_[0]};
120 432 my (%flat,@flat);
121 ### this is ok, but need to handle the case where a lh and rh endpoint
122 ### coincide...
123 # decomposition --
124 # flatten:
125 # every lh endpoint generates (lh-1, lh)
126 # every rh endpoint generates (rh, rh+)
127 432 foreach (@ints) {
128 536 $flat{$$_[0]-1}++;
129 536 $flat{$$_[0]}++;
130 536 $flat{$$_[1]}++;
131 536 $flat{$$_[1]+1}++;
132 }
133 # sort, create singletons if nec.
134 432 my @a;
135 432 @a = sort {$a<=>$b} keys %flat;
136 # throw out first and last (meeting a boundary condition)
137 432 shift @a; pop @a;
138 # look for singletons
139 432 @flat = (shift @a, shift @a);
140 432 ▶ if ( $flat[1]-$flat[0] == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flat[1] - $flat[0] == 1) 1 431 432
141 1 @flat = ($flat[0],$flat[0], $flat[1]);
142 }
143 432 ▶ while (my $a = shift @a) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $a = shift @a) 394 432 826
144 394 ▶ if ($a-$flat[-2]==2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a - $flat[-2] == 2) 17 377 394
145 17 push @flat, $flat[-1]; # create singleton interval
146 }
147 394 push @flat, $a;
148 }
149 432 ▶ if ($flat[-1]-$flat[-2]==1 and @flat % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flat[-1] - $flat[-2] == 1 and @flat % 2) 0 432 432
Condition33%1/3
$flat[-1] - $flat[-2] == 1 and @flat % 2
!ll&&!rl&&r
43200
MC/DC0%0/2
$flat[-1] - $flat[-2] == 1 and @flat % 2
$flat[-1] - $flat[-2] == 1 @flat % 2
Truth table33%1/3
A and B
A= $flat[-1] - $flat[-2] == 1B= @flat % 2
ABresult
0X0
100
111
150 0 push @flat, $flat[-1];
151 }
152 # component intervals are consecutive pairs
153 432 my @decomp;
154 432 ▶ while (my $a = shift @flat) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $a = shift @flat) 638 432 1070
155 638 push @decomp, [$a, shift @flat];
156 }
157  
158 # for each component, return a list of the indices of the input intervals
159 # that cover the component.
160 432 my @coverage;
161 432 foreach my $i (0..$#decomp) {
162 638 foreach my $j (0..$#ints) {
163 1316 ▶ unless (are_disjoint($decomp[$i], $ints[$j])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (are_disjoint($decomp[$i], $ints[$j])) 846 470 1316
164 846 ▶ if (defined $coverage[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coverage[$i]) { } 208 638 846
165 208 push @{$coverage[$i]}, $j;
166 }
167 else {
168 638 $coverage[$i] = [$j];
169 }
170 }
171 }
172 }
173 432 return map { [$decomp[$_] => $coverage[$_]] } (0..$#decomp);
174 }
175  
176 =head2 are_disjoint
177  
178 Title : are_disjoint
179 Usage : are_disjoint( [$a0, $a1], [$b0, $b1] )
180 Function: Determine if two intervals are disjoint
181 Returns : True if the intervals are disjoint, false if they overlap
182 Args : array of two intervals
183  
184 =cut
185  
186 2287 ▶sub are_disjoint {
Subroutine are_disjoint: called CC=3 SCAR=11.0
Pod documented
187 2287 my ($int1, $int2) = @_;
188 2287 ▶ return 1 if ( $$int1[1] < $$int2[0] ) || ( $$int2[1] < $$int1[0]);
Branch: 1 branch
BranchTrueFalseTotal
if $int1->[1] < $int2->[0] or $int2->[1] < $int1->[0] 1337 950 2287
Condition100%3/3
$int1->[1] < $int2->[0] or $int2->[1] < $int1->[0]
l!l&&r!l&&!r
724613950
MC/DC100%2/2
$int1->[1] < $int2->[0] or $int2->[1] < $int1->[0]
$int1->[1] < $int2->[0] $int2->[1] < $int1->[0]
Truth table100%3/3
A or B
A= $int1->[1] < $int2->[0]B= $int2->[1] < $int1->[0]
ABresult
1X1
011
000
189 950 return 0;
190 }
191  
192 =head2 min_covering_interval
193  
194 Title : min_covering_interval
195 Usage : $interval = min_covering_interval( [$a0,$a1],[$b0,$b1] )
196 Function: Determine the minimal covering interval for two intervals
197 Returns : an interval
198 Args : two intervals
199  
200 =cut
201  
202 104 ▶sub min_covering_interval {
Subroutine min_covering_interval: called CC=1 SCAR=0.0
Pod documented
203 104 my ($int1, $int2) = @_;
204 104 my @a = sort {$a <=> $b} (@$int1, @$int2);
205 104 return [$a[0],$a[-1]];
206 }
207  
208 =head2 get_intervals_from_hsps
209  
210 Title : get_intervals_from_hsps
211 Usage : @intervals = get_intervals_from_hsps($type, @hsp_objects)
212 Function: Return array of intervals of the form [ $start, $end ],
213 from an array of hsp objects
214 Returns : an array of intervals
215 Args : scalar $type, array of HSPI objects; where $type is one of 'hit',
216 'subject', 'query'
217  
218 =cut
219  
220 219 ▶sub get_intervals_from_hsps {
Subroutine get_intervals_from_hsps: called CC=5 SCAR=17.8
Pod documented
221 219 my $type = shift;
222 219 my @hsps;
223 219 ▶ if (ref($type) =~ /HSP/) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref($type) =~ /HSP/) { } 0 219 219
elsif (not grep(/^$type$/, ('hit', 'subject', 'query'))) { } 0 219 219
224 0 push @hsps, $type;
225 0 $type = 'query';
226 }
227 elsif ( !grep /^$type$/,qw( hit subject query ) ) {
228 0 die "Unknown HSP type '$type'";
229 }
230 219 ▶ $type = 'hit' if $type eq 'subject';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "subject" 0 219 219
231 219 push @hsps, @_;
232 219 my @ret;
233 219 foreach (@hsps) {
234 # push @ret, [ $_->start($type), $_->end($type)];
235 536 push @ret, [ $_->range($type) ];
236 }
237 219 return @ret;
238 }
239  
240 # fast, clear, nasty, brutish and short.
241 # for _allowable_filters(), _set_mapping()
242 # covers BLAST, FAST families
243 # FASTA is ambiguous (nt or aa) based on alg name only
244  
245 3 my $alg_lookup = {
246 'N' => { 'mapping' => [1,1],
247 'def_context' => ['p_','p_'],
248 'has_strand' => [1, 1],
249 'has_frame' => [0, 0]},
250 'P' => { 'mapping' => [1,1],
251 'def_context' => ['all','all'],
252 'has_strand' => [0, 0],
253 'has_frame' => [0, 0]},
254 'X' => { 'mapping' => [3, 1],
255 'def_context' => [undef,'all'],
256 'has_strand' => [1, 0],
257 'has_frame' => [1, 0]},
258 'Y' => { 'mapping' => [3, 1],
259 'def_context' => [undef,'all'],
260 'has_strand' => [1, 0],
261 'has_frame' => [1, 0]},
262 'TA' => { 'mapping' => [1, 3],
263 'def_context' => ['all',undef],
264 'has_strand' => [0, 1],
265 'has_frame' => [0, 1]},
266 'TN' => { 'mapping' => [1, 3],
267 'def_context' => ['p_',undef],
268 'has_strand' => [1,1],
269 'has_frame' => [0, 1]},
270 'TX' => { 'mapping' => [3, 3],
271 'def_context' => [undef,undef],
272 'has_strand' => [1, 1],
273 'has_frame' => [1, 1]},
274 'TY' => { 'mapping' => [3, 3],
275 'def_context' => [undef,undef],
276 'has_strand' => [1, 1],
277 'has_frame' => [1, 1]}
278 };
279
280 =head2 _allowable_filters
281
282 Title : _allowable_filters
283 Usage : _allowable_filters($Bio_Search_Hit_HitI, $type)
284 Function: Return the HSP filters (strand, frame) allowed,
285 based on the reported algorithm
286 Returns : String encoding allowable filters:
287 s = strand, f = frame
288 Empty string if no filters allowed
289 undef if algorithm unrecognized
290 Args : A Bio::Search::Hit::HitI object,
291 scalar $type, one of 'hit', 'subject', 'query';
292 default is 'query'
293  
294 =cut
295  
296 0 ▶sub _allowable_filters {
Subroutine _allowable_filters: not called CC=9 SCAR=45.0
297 0 my $hit = shift;
298 0 my $type = shift;
299 0 ▶ $type ||= 'q';
Condition0%0/2
$type ||= "q"
l!l
00
MC/DC0%0/1
$type ||= "q"
$type
Truth table0%0/2
A
A= $type
Aresult
11
00
300 0 ▶ unless (grep /^$type$/, qw( h q s ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep /^$type$/, ("h", "q", "s")) 0 0 0
301 0 warn("Unknown type '$type'; returning ''");
302 0 return '';
303 }
304 0 ▶ $type = 'h' if $type eq 's';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "s" 0 0 0
305 0 my $alg = $hit->algorithm;
306  
307 # pretreat (i.e., kludge it)
308 0 ▶ $alg =~ /^RPS/ and ($alg) = ($alg =~ /\(([^)]+)\)/);
Branch: 1 branch
BranchTrueFalseTotal
$alg =~ /^RPS/ and ($alg) = $alg =~ /\(([^)]+)\)/ 0 0 0
309  
310 0 for ($hit->algorithm) {
311 0 ▶ /MEGABLAST/i && do {
Branch: 1 branch
BranchTrueFalseTotal
/MEGABLAST/i and do { return qr/[s]/ } 0 0 0
312 0 return qr/[s]/;
313 };
314 0 ▶ /(.?)BLAST(.?)/i && do {
Branch: 1 branch
BranchTrueFalseTotal
/(.?)BLAST(.?)/i and do { return $$alg_lookup{$1 . $2}{$type} } 0 0 0
315 0 return $$alg_lookup{$1.$2}{$type};
316 };
317 0 ▶ /(.?)FAST(.?)/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/(.?)FAST(.?)/ and do { return $$alg_lookup{$1 . $2}{$type} } 0 0 0
318 0 return $$alg_lookup{$1.$2}{$type};
319 };
320 0 do { # unrecognized
321 0 last;
322 };
323 }
324 0 return;
325 }
326  
327  
328 =head2 _set_attributes
329  
330 Title : _set_attributes
331 Usage : $tiling->_set_attributes()
332 Function: Sets attributes for invocant
333 that depend on algorithm name
334 Returns : True on success
335 Args : none
336 Note : setting based on the configuration table
337 %alg_lookup
338  
339 =cut
340  
341 519 ▶sub _set_attributes {
Subroutine _set_attributes: called CC=6 SCAR=22.7
342 519 my $self = shift;
343 519 my $alg = $self->hit->algorithm;
344  
345 # pretreat (i.e., kludge it)
346 519 ▶ $alg =~ /^RPS/ and ($alg) = ($alg =~ /\(([^)]+)\)/);
Branch: 1 branch
BranchTrueFalseTotal
$alg =~ /^RPS/ and ($alg) = $alg =~ /\(([^)]+)\)/ 0 519 519
347
348 519 for ($alg) {
349 519 ▶ /MEGABLAST/i && do {
Branch: 1 branch
BranchTrueFalseTotal
/MEGABLAST/i and do { ($self->{"_mapping_query"}, $self->{"_mapping_hit"}) = (1, 1); ($self->{"_def_context_query"}, $self->{"_def_context_hit"}) = ("p_", "p_"); ($self->{"_has_frame_query"}, $self->{"_has_frame_hit"}) = (0, 0); ($self->{"_has_strand_query"}, $self->{"_has_strand_hit"}) = (1, 1); last } 4 515 519
350 4 ($self->{_mapping_query},$self->{_mapping_hit}) = (1,1);
351 4 ($self->{_def_context_query},$self->{_def_context_hit}) =
352 ('p_','p_');
353 4 ($self->{_has_frame_query},$self->{_has_frame_hit}) =
354 (0, 0);
355 4 ($self->{_has_strand_query},$self->{_has_strand_hit}) =
356 (1, 1);
357 4 last;
358 };
359 515 ▶ /(.?)BLAST(.?)/i && do {
Branch: 1 branch
BranchTrueFalseTotal
/(.?)BLAST(.?)/i and do { ($self->{"_mapping_query"}, $self->{"_mapping_hit"}) = @{$$alg_lookup{$1 . $2}{"mapping"};}; ($self->{"_def_context_query"}, $self->{"_def_context_hit"}) = @{$$alg_lookup{$1 . $2}{"def_context"};}; ($self->{"_has_frame_query"}, $self->{"_has_frame_hit"}) = @{$$alg_lookup{$1 . $2}{"has_frame"};}; ($self->{"_has_strand_query"}, $self->{"_has_strand_hit"}) = @{$$alg_lookup{$1 . $2}{"has_strand"};}; last } 515 0 515
360 ($self->{_mapping_query},$self->{_mapping_hit}) =
361 515 @{$$alg_lookup{$1.$2}{mapping}};
362 ($self->{_def_context_query},$self->{_def_context_hit}) =
363 515 @{$$alg_lookup{$1.$2}{def_context}};
364 ($self->{_has_frame_query},$self->{_has_frame_hit}) =
365 515 @{$$alg_lookup{$1.$2}{has_frame}};
366 ($self->{_has_strand_query},$self->{_has_strand_hit}) =
367 515 @{$$alg_lookup{$1.$2}{has_strand}};
368 515 last;
369 };
370 0 ▶ /(.?)FAST(.?)/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/(.?)FAST(.?)/ and do { ($self->{"_mapping_query"}, $self->{"_mapping_hit"}) = @{$$alg_lookup{$1 . $2}{"mapping"};}; ($self->{"_def_context_query"}, $self->{"_def_context_hit"}) = @{$$alg_lookup{$1 . $2}{"def_context"};}; ($self->{"_has_frame_query"}, $self->{"_has_frame_hit"}) = @{$$alg_lookup{$1 . $2}{"has_frame"};}; ($self->{"_has_strand_query"}, $self->{"_has_strand_hit"}) = @{$$alg_lookup{$1 . $2}{"has_strand"};}; last } 0 0 0
371 ($self->{_mapping_query},$self->{_mapping_hit}) =
372 0 @{$$alg_lookup{$1.$2}{mapping}};
373 ($self->{_def_context_query},$self->{_def_context_hit}) =
374 0 @{$$alg_lookup{$1.$2}{def_context}};
375 ($self->{_has_frame_query},$self->{_has_frame_hit}) =
376 0 @{$$alg_lookup{$1.$2}{has_frame}};
377 ($self->{_has_strand_query},$self->{_has_strand_hit}) =
378 0 @{$$alg_lookup{$1.$2}{has_strand}};
379 0 last;
380 };
381 0 do { # unrecognized
382 0 $self->warn("Unrecognized algorithm '$alg'; defaults may not work");
383 0 ($self->{_mapping_query},$self->{_mapping_hit}) = (1,1);
384 0 ($self->{_def_context_query},$self->{_def_context_hit}) =
385 ('all','all');
386 0 ($self->{_has_frame_query},$self->{_has_frame_hit}) =
387 (0,0);
388 0 ($self->{_has_strand_query},$self->{_has_strand_hit}) =
389 (0,0);
390 0 return 0;
391 0 last;
392 };
393 }
394 519 return 1;
395 }
396
397 6568 ▶sub _mapping_coeff {
Subroutine _mapping_coeff: called CC=11 SCAR=31.0
398 6568 my $obj = shift;
399 6568 my $type = shift;
400 6568 my %type_i = ( 'query' => 0, 'hit' => 1 );
401 6568 ▶ unless ( ref($obj) && $obj->can('algorithm') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $obj and $obj->can("algorithm")) 0 6568 6568
Condition33%1/3
ref $obj and $obj->can("algorithm")
!ll&&!rl&&r
006568
MC/DC0%0/2
ref $obj and $obj->can("algorithm")
ref $obj $obj->can("algorithm")
Truth table33%1/3
A and B
A= ref $objB= $obj->can("algorithm")
ABresult
0X0
100
111
402 0 $obj->warn("Object type unrecognized");
403 0 return undef;
404 }
405 6568 ▶ $type ||= 'query';
Condition50%1/2
$type ||= "query"
l!l
65680
MC/DC0%0/1
$type ||= "query"
$type
Truth table50%1/2
A
A= $type
Aresult
11
00
406 6568 ▶ unless ( grep(/^$type$/, qw( query hit subject ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep /^$type$/, ("query", "hit", "subject")) 0 6568 6568
407 0 $obj->warn("Sequence type unrecognized");
408 0 return undef;
409 }
410 6568 ▶ $type = 'hit' if $type eq 'subject';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "subject" 0 6568 6568
411 6568 my $alg = $obj->algorithm;
412  
413 # pretreat (i.e., kludge it)
414 6568 ▶ $alg =~ /^RPS/ and ($alg) = ($alg =~ /\(([^)]+)\)/);
Branch: 1 branch
BranchTrueFalseTotal
$alg =~ /^RPS/ and ($alg) = $alg =~ /\(([^)]+)\)/ 0 6568 6568
415
416 6568 for ($alg) {
417 6568 ▶ /MEGABLAST/i && do {
Branch: 1 branch
BranchTrueFalseTotal
/MEGABLAST/i and do { return 1 } 520 6048 6568
418 520 return 1;
419 };
420 6048 ▶ /(.?)BLAST(.?)/i && do {
Branch: 1 branch
BranchTrueFalseTotal
/(.?)BLAST(.?)/i and do { return $$alg_lookup{$1 . $2}{"mapping"}[$type_i{$type}] } 6048 0 6048
421 6048 return $$alg_lookup{$1.$2}{'mapping'}[$type_i{$type}];
422 };
423 0 ▶ /(.?)FAST(.?)/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/(.?)FAST(.?)/ and do { return $$alg_lookup{$1 . $2}{"mapping"}[$type_i{$type}] } 0 0 0
424 0 return $$alg_lookup{$1.$2}{'mapping'}[$type_i{$type}];
425 };
426 0 do { # unrecognized
427 0 last;
428 };
429 }
430 0 return;
431 }
432  
433 # a graphical depiction of a set of intervals
434 0 ▶sub _ints_as_text {
Subroutine _ints_as_text: not called CC=7 SCAR=40.3
435 0 my $ints = shift;
436 0 my @ints = @$ints;
437 0 my %pos;
438 0 for (@ints) {
439 0 $pos{$$_[0]}++;
440 0 $pos{$$_[1]}++;
441 }
442
443 0 my @pos = sort {$a<=>$b} keys %pos;
444 0 @pos = map {sprintf("%03d",$_)} @pos;
445 #header
446 0 my $max=0;
447 0 ▶ $max = (length > $max) ? length : $max for (@pos);
Branch: 1 branch
BranchTrueFalseTotal
length $_ > $max ? : 0 0 0
448 0 for my $j (0..$max-1) {
449 0 my $i = $max-1-$j;
450 0 ▶ my @line = map { substr($_, $j, 1) || '0' } @pos;
Condition0%0/2
substr($_, $j, 1) || '0'
l!l
00
MC/DC0%0/1
substr($_, $j, 1) || '0'
substr($_, $j, 1)
Truth table0%0/2
A
A= substr($_, $j, 1)
Aresult
11
00
451 0 print join('', @line), "\n";
452 }
453 0 print '-' x @pos, "\n";
454 0 undef %pos;
455 0 @pos{map {sprintf("%d",$_)} @pos} = (0..@pos);
456 0 foreach (@ints) {
457 0 print ' ' x $pos{$$_[0]}, '[', ' ' x ($pos{$$_[1]}-$pos{$$_[0]}-1), ']', ' ' x (@pos-$pos{$$_[1]}), "\n";
458 }
459 }
460  
461  
462  
463 =head2 containing_hsps()
464  
465 Title : containing_hsps
466 Usage : @hsps = containing_hsps($interval, @hsps_to_search)
467 Function: Return a list of hsps whose coordinates completely contain the
468 given $interval
469 Returns : Array of HSP objects
470 Args : $interval : [$int1, $int2],
471 array of HSP objects
472  
473 =cut
474 # could be more efficient if hsps are assumed ordered...
475 12 ▶sub containing_hsps {
Subroutine containing_hsps: called CC=4 SCAR=13.9
Pod documented
476 12 my $intvl = shift;
477 12 my @hsps = @_;
478 12 my @ret;
479 12 my ($beg, $end) = @$intvl;
480 12 foreach my $hsp (@hsps) {
481 96 my ($start, $stop) = ($hsp->start, $hsp->end);
482 96 ▶ push @ret, $hsp if ( $start <= $beg and $end <= $stop );
Branch: 1 branch
BranchTrueFalseTotal
if $start <= $beg and $end <= $stop 13 83 96
Condition100%3/3
$start <= $beg and $end <= $stop
!ll&&!rl&&r
562713
MC/DC100%2/2
$start <= $beg and $end <= $stop
$start <= $beg $end <= $stop
Truth table100%3/3
A and B
A= $start <= $begB= $end <= $stop
ABresult
0X0
100
111
483 }
484 12 return @ret;
485 }
486  
487  
488  
489 =head2 covering_groups()
490  
491 Title : covering_groups
492 Usage :
493 Function: divide a list of **ordered,disjoint** intervals (as from a
494 coverage map) into a set of disjoint covering groups
495 Returns : array of arrayrefs, each arrayref a covering set of
496 intervals
497 Args : array of intervals
498  
499 =cut
500  
501 1 ▶sub covering_groups {
Subroutine covering_groups: called CC=4 SCAR=13.9
Pod documented
502 1 my @intervals = @_;
503 1 ▶ return unless @intervals;
Branch: 1 branch
BranchTrueFalseTotal
unless @intervals 0 1 1
504 1 my (@groups, $grp);
505 1 push @{$groups[0]}, shift @intervals;
506 1 $grp = $groups[0];
507 1 ▶ for (my $intvl = shift @intervals; @intervals; $intvl = shift @intervals) {
Branch: 1 branch
BranchTrueFalseTotal
if (@intervals) 11 1 12
508 11 ▶ if ( $intvl->[0] - $grp->[-1][1] == 1 ) { # intervals are direcly adjacent
Branch: 1 branch
BranchTrueFalseTotal
if ($intvl->[0] - $grp->[-1][1] == 1) { } 6 5 11
509 6 push @$grp, $intvl;
510 }
511 else {
512 5 $grp = [$intvl];
513 5 push @groups, $grp;
514 }
515 }
516 1 return @groups;
517 }
518  
519 3 1;
520 # need our own subsequencer for hsps.
521  
522 package Bio::Search::HSP::HSPI;
523 3 $Bio::Search::HSP::HSPI::VERSION = '1.7.8';
524  
525  
526 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
527 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
528  
529 =head2 matches_MT
530  
531 Title : matches_MT
532 Usage : $hsp->matches($type, $action, $start, $end)
533 Purpose : Get the total number of identical or conserved matches
534 in the query or sbjct sequence for the given HSP. Optionally can
535 report data within a defined interval along the seq.
536 Returns : scalar int
537 Args :
538 Comments : Relies on seq_str('match') to get the string of alignment symbols
539 between the query and sbjct lines which are used for determining
540 the number of identical and conservative matches.
541 Note : Modeled on Bio::Search::HSP::HSPI::matches
542  
543 =cut
544  
545 2664 ▶sub matches_MT {
Subroutine matches_MT: called CC=26 SCAR=36.7
Pod undocumented
546 3 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
547 2664 my( $self, @args ) = @_;
548 2664 my($type, $action, $beg, $end) = $self->_rearrange( [qw(TYPE ACTION START END)], @args);
549 2664 my @actions = qw( identities conserved searchutils );
550
551 # prep $type
552 2664 ▶ $self->throw("Type not specified") if !defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 2664 2664
553 2664 ▶ $self->throw("Type '$type' unrecognized") unless grep(/^$type$/,qw(query hit subject));
Branch: 1 branch
BranchTrueFalseTotal
unless grep /^$type$/, ("query", "hit", "subject") 0 2664 2664
554 2664 ▶ $type = 'hit' if $type eq 'subject';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "subject" 0 2664 2664
555  
556 # prep $action
557 2664 ▶ $self->throw("Action not specified") if !defined $action;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $action 0 2664 2664
558 2664 ▶ $self->throw("Action '$action' unrecognized") unless grep(/^$action$/, @actions);
Branch: 1 branch
BranchTrueFalseTotal
unless grep /^$action$/, @actions 0 2664 2664
559  
560 2664 my ($len_id, $len_cons);
561 2664 my $c = Bio::Search::Tiling::MapTileUtils::_mapping_coeff($self, $type);
562 2664 ▶ if ((defined $beg && !defined $end) || (!defined $beg && defined $end)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $beg and not defined $end or not defined $beg and defined $end) { } 0 2664 2664
elsif (not +(defined $beg || defined $end) && $self->seq_str('match')) { } 1688 976 2664
Condition55%5/9
defined $beg and not defined $end or not defined $beg and defined $end
l!l&&r!l&&!r
002664
defined $beg and not defined $end
!ll&&!rl&&r
16889760
not defined $beg and defined $end
!ll&&!rl&&r
97616880
MC/DC0%0/4
defined $beg and not defined $end or not defined $beg and defined $end
defined $beg not defined $end not defined $beg defined $end
Truth table28%2/7
A and not(B) or not(C) and D
A= defined $begB= not defined $endC= not defined $begD= defined $end
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
563 0 $self->throw("Both start and end are required");
564 }
565 ▶ elsif ( (!defined($beg) && !defined($end)) || !$self->seq_str('match') ) {
Condition66%4/6
(defined $beg || defined $end) && $self->seq_str('match')
!ll&&!rl&&r
16880976
defined $beg or defined $end
l!l&&r!l&&!r
97601688
MC/DC33%1/3
(defined $beg || defined $end) && $self->seq_str('match')
defined $beg defined $end $self->seq_str('match')
Truth table40%2/5
A or B && C
A= defined $begB= defined $endC= $self->seq_str('match')
ABCresult
00X0
1X00
0100
1X11
0111
566 ## Get data for the whole alignment.
567 # the reported values x mapping
568 1688 ▶ $self->debug("Sequence data not present in report; returning data for entire HSP") unless $self->seq_str('match');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->seq_str("match") 156 1532 1688
569 1688 ($len_id, $len_cons) = map { $c*$_ } ($self->num_identical, $self->num_conserved);
570 1688 for ($action) {
571 1688 ▶ $_ eq 'identities' && do {
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "identities" and do { return $len_id } 450 1238 1688
572 450 return $len_id;
573 };
574 1238 ▶ $_ eq 'conserved' && do {
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "conserved" and do { return $len_cons } 450 788 1238
575 450 return $len_cons;
576 };
577 788 ▶ $_ eq 'searchutils' && do {
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "searchutils" and do { return $len_id, $len_cons } 788 0 788
578 788 return ($len_id, $len_cons);
579 };
580 0 do {
581 0 $self->throw("What are YOU doing here?");
582 };
583 }
584 }
585 else {
586 ## Get the substring representing the desired sub-section of aln.
587 976 my($start,$stop) = $self->range($type);
588 976 ▶ if ( $beg < $start or $stop < $end ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($beg < $start or $stop < $end) 0 976 976
Condition33%1/3
$beg < $start or $stop < $end
l!l&&r!l&&!r
00976
MC/DC0%0/2
$beg < $start or $stop < $end
$beg < $start $stop < $end
Truth table33%1/3
A or B
A= $beg < $startB= $stop < $end
ABresult
1X1
011
000
589 0 $self->throw("Start/stop out of range [$start, $stop]");
590 }
591  
592 # handle gaps
593 976 my $match_str = $self->seq_str('match');
594 976 ▶ if ($self->gaps) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->gaps) 764 212 976
595 # strip the homology string of gap positions relative
596 # to the target type
597 764 $match_str = $self->seq_str('match');
598 764 my $tgt = $self->seq_str($type);
599 764 my $encode = $match_str ^ $tgt;
600 764 my $zap = '-'^' ';
601 764 $encode =~ s/$zap//g;
602 764 $tgt =~ s/-//g;
603 764 $match_str = $tgt ^ $encode;
604 # match string is now the correct length for substr'ing below,
605 # given that start and end are gapless coordinates in the
606 # blast report
607 }
608  
609 976 my $seq = "";
610 976 $seq = substr( $match_str,
611 int( ($beg-$start)/Bio::Search::Tiling::MapTileUtils::_mapping_coeff($self, $type) ),
612 int( 1+($end-$beg)/Bio::Search::Tiling::MapTileUtils::_mapping_coeff($self, $type) )
613 );
614  
615 976 ▶ if(!CORE::length $seq) {
Branch: 1 branch
BranchTrueFalseTotal
unless (CORE::length $seq) 0 976 976
616 0 $self->throw("Undefined sub-sequence ($beg,$end). Valid range = $start - $stop");
617 }
618  
619 976 $seq =~ s/ //g; # remove space (no info).
620 976 $len_cons = (CORE::length $seq)*(Bio::Search::Tiling::MapTileUtils::_mapping_coeff($self,$type));
621 976 $seq =~ s/\+//g; # remove '+' characters (conservative substitutions)
622 976 $len_id = (CORE::length $seq)*(Bio::Search::Tiling::MapTileUtils::_mapping_coeff($self,$type));
623 976 for ($action) {
624 976 ▶ $_ eq 'identities' && do {
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "identities" and do { return $len_id } 0 976 976
625 0 return $len_id;
626 };
627 976 ▶ $_ eq 'conserved' && do {
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "conserved" and do { return $len_cons } 0 976 976
628 0 return $len_cons;
629 };
630 976 ▶ $_ eq 'searchutils' && do {
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "searchutils" and do { return $len_id, $len_cons } 976 0 976
631 976 return ($len_id, $len_cons);
632 };
633 0 do {
634 0 $self->throw("What are YOU doing here?");
635 };
636 }
637 }
638 }
639  
640 3 1;
641  
642 package Bio::LocatableSeq;
643 3 $Bio::LocatableSeq::VERSION = '1.7.8';
644  
645 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
646 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
647  
648 # mixin the Bio::FeatureHolderI implementation of
649 # Bio::Seq -- for get_tiled_aln
650  
651 =head2 get_SeqFeatures
652  
653 Title : get_SeqFeatures
654 Usage :
655 Function: Get the feature objects held by this feature holder.
656  
657 Features which are not top-level are subfeatures of one or
658 more of the returned feature objects, which means that you
659 must traverse the subfeature arrays of each top-level
660 feature object in order to traverse all features associated
661 with this sequence.
662  
663 Top-level features can be obtained by tag, specified in
664 the argument.
665  
666 Use get_all_SeqFeatures() if you want the feature tree
667 flattened into one single array.
668  
669 Example :
670 Returns : an array of Bio::SeqFeatureI implementing objects
671 Args : [optional] scalar string (feature tag)
672  
673  
674 =cut
675  
676 12 ▶sub get_SeqFeatures{
Subroutine get_SeqFeatures: called CC=4 SCAR=17.9
Pod undocumented
677 12 my $self = shift;
678 12 my $tag = shift;
679  
680 12 ▶ if( !defined $self->{'_as_feat'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_as_feat"}) 0 12 12
681 0 $self->{'_as_feat'} = [];
682 }
683 12 ▶ if ($tag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag) { } 0 12 12
684 0 ▶ return map { $_->primary_tag eq $tag ? $_ : () } @{$self->{'_as_feat'}};
Branch: 1 branch
BranchTrueFalseTotal
$_->primary_tag eq $tag ? : 0 0 0
685 }
686 else {
687 12 return @{$self->{'_as_feat'}};
688 }
689 }
690  
691 =head2 feature_count
692  
693 Title : feature_count
694 Usage : $seq->feature_count()
695 Function: Return the number of SeqFeatures attached to a sequence
696 Returns : integer representing the number of SeqFeatures
697 Args : None
698  
699  
700 =cut
701  
702 0 ▶sub feature_count {
Subroutine feature_count: not called CC=2 SCAR=17.9
Pod undocumented
703 0 my ($self) = @_;
704 0 ▶ if (defined($self->{'_as_feat'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'_as_feat'}) { } 0 0 0
705 0 return ($#{$self->{'_as_feat'}} + 1);
706 } else {
707 0 return 0;
708 }
709 }
710  
711 =head2 add_SeqFeature
712  
713 Title : add_SeqFeature
714 Usage : $seq->add_SeqFeature($feat);
715 $seq->add_SeqFeature(@feat);
716 Function: Adds the given feature object (or each of an array of feature
717 objects to the feature array of this
718 sequence. The object passed is required to implement the
719 Bio::SeqFeatureI interface.
720 Returns : 1 on success
721 Args : A Bio::SeqFeatureI implementing object, or an array of such objects.
722  
723  
724 =cut
725  
726 12 ▶sub add_SeqFeature {
Subroutine add_SeqFeature: called CC=4 SCAR=14.3
Pod undocumented
727 12 my ($self,@feat) = @_;
728 12 ▶ $self->{'_as_feat'} = [] unless $self->{'_as_feat'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_as_feat"} 12 0 12
729 12 foreach my $feat ( @feat ) {
730 24 ▶ if( !$feat->isa("Bio::SeqFeatureI") ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($feat->isa("Bio::SeqFeatureI")) 0 24 24
731 0 $self->throw("$feat is not a SeqFeatureI and that's what we expect...");
732 }
733 24 $feat->attach_seq($self);
734 24 push(@{$self->{'_as_feat'}},$feat);
735 }
736 12 return 1;
737 }
738  
739 =head2 remove_SeqFeatures
740  
741 Title : remove_SeqFeatures
742 Usage : $seq->remove_SeqFeatures();
743 Function: Flushes all attached SeqFeatureI objects.
744  
745 To remove individual feature objects, delete those from the returned
746 array and re-add the rest.
747 Example :
748 Returns : The array of Bio::SeqFeatureI objects removed from this seq.
749 Args : None
750  
751  
752 =cut
753  
754 0 ▶sub remove_SeqFeatures {
Subroutine remove_SeqFeatures: not called CC=2 SCAR=17.9
Pod undocumented
755 0 my $self = shift;
756  
757 0 ▶ return () unless $self->{'_as_feat'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_as_feat"} 0 0 0
758 0 my @feats = @{$self->{'_as_feat'}};
759 0 $self->{'_as_feat'} = [];
760 0 return @feats;
761 }
762  
763 3 1;
« Bio/Tools/Prints.pm ↑ Summary Bio/Tree/Node.pm »