EnsEMBL/Utils/Tree/Interval/Mutable.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 13 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 78 CC 5 SCAR 19.5
CC
5
Cov
0%
new
12.0
_load
12.0
_load_xs
2.0
CRAP 7.0
1 =head1 LICENSE
2  
3 See the NOTICE file distributed with this work for additional information
4 regarding copyright ownership.
5  
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9  
10 http://www.apache.org/licenses/LICENSE-2.0
11  
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17  
18 =cut
19  
20  
21 =head1 CONTACT
22  
23 Please email comments or questions to the public Ensembl
24 developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
25  
26 Questions may also be sent to the Ensembl help desk at
27 <http://www.ensembl.org/Help/Contact>.
28  
29 =cut
30  
31 =head1 NAME
32  
33 Bio::EnsEMBL::Utils::Tree::Interval::Mutable
34  
35 =head1 SYNOPSIS
36  
37 # start with an empty tree
38 my $tree = Bio::EnsEMBL::Utils::Tree::Interval::Mutable->new();
39  
40 # add a few intervals (i.e. Bio::EnsEMBL::Utils::Interval)
41 $tree->insert($i1);
42 $tree->insert($i2);
43 $tree->insert($i3);
44  
45 # query the tree
46 my $result = $tree->search(85, 100);
47 if (scalar @{$result}) {
48 print "Found overlapping interval: [", $result->[0]->start, ', ', $result->[0]->end, "\n";
49 }
50  
51 =head1 DESCRIPTION
52  
53 Class representing a dynamic, i.e. mutable, interval tree implemented as an augmented AVL balanced binary tree.
54  
55 This module is a wrapper around two possible implementations: one using the Perl extension (XS) mechanisms, and
56 a pure Perl (PP) one.
57  
58 The module is capable of detecting whether the XS module is available and it loads it in that
59 case; it falls back to the PP implementation otherwise.
60
61 =head1 METHODS
62  
63 =cut
64  
65 package Bio::EnsEMBL::Utils::Tree::Interval::Mutable;
66 $Bio::EnsEMBL::Utils::Tree::Interval::Mutable::VERSION = '114.0.0_50'; # TRIAL
67 $Bio::EnsEMBL::Utils::Tree::Interval::Mutable::VERSION = '114.0.050';
68 use strict;
69  
70 use Bio::EnsEMBL::Utils::Scalar qw(assert_ref);
71 use Bio::EnsEMBL::Utils::Exception qw(throw warning info);
72  
73 # the modules providing the underlying implementation,
74 # either XS or pure perl fallback
75 my $XS = 'Bio::EnsEMBL::XS::Utils::Tree::Interval::Mutable';
76 my $PP = 'Bio::EnsEMBL::Utils::Tree::Interval::Mutable::PP';
77  
78 # if XS is used, version at least 1.3.1 is required (provides the interval tree library)
79 my $VERSION_XS = '1.3.1';
80  
81 my @public_methods = qw/ insert search remove size /;
82  
83 # import either XS or PP methods into namespace
84 unless ($Bio::EnsEMBL::Utils::Tree::Interval::Mutable::IMPL) {
85 # first check if XS is available and try to load it,
86 # otherwise fall back to PP implementation
87 _load_xs() or _load_pp() or throw "Couldn't load implementation: $@";
88 }
89  
90  
91 =head2 new
92  
93 Arg [] : none
94 Example : my $tree = Bio::EnsEMBL::Utils::Tree::Mutable();
95 Description : Constructor. Creates a new mutable tree instance
96 Returntype : Bio::EnsEMBL::Utils::Tree::Interval::Mutable
97 Exceptions : none
98 Caller : general
99  
100 =cut
101  
102 sub new {
103 my $caller = shift;
104 my $class = ref($caller) || $caller;
105  
106 # for ($XS|$PP)::new(0);
107 return eval qq| $Bio::EnsEMBL::Utils::Tree::Interval::Mutable::IMPL\::new( \$caller ) | unless $caller; ## no critic
108  
109 if (my $self = $Bio::EnsEMBL::Utils::Tree::Interval::Mutable::IMPL->new(@_)) {
110 $self->{_IMPL} = $Bio::EnsEMBL::Utils::Tree::Interval::Mutable::IMPL;
111 bless($self, $class);
112 return $self
113 }
114  
115 return;
116 }
117  
118 sub _load_xs {
119 _load($XS, $VERSION_XS);
120 }
121  
122 sub _load_pp {
123 _load($PP);
124 }
125  
126 sub _load {
127 my ($module, $version) = @_;
128 $version ||= '';
129  
130 eval qq| use $module $version |; ## no critic
131 info(sprintf("Cannot load %s interval tree implementation", $module eq $XS?'XS':'PP'), 2000)
132 and return if $@;
133  
134 push @Bio::EnsEMBL::Utils::Tree::Interval::Mutable::ISA, $module;
135 $Bio::EnsEMBL::Utils::Tree::Interval::Mutable::IMPL = $module;
136  
137 local $^W;
138 no strict qw(refs); ## no critic
139  
140 for my $method (@public_methods) {
141 *{"Bio::EnsEMBL::Utils::Tree::Interval::Mutable::$method"} = \&{"$module\::$method"};
142 }
143
144 return 1;
145 }
146  
147 1;
148