3 See the NOTICE file distributed with
this work
for additional information
4 regarding copyright ownership.
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
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.
23 Please email comments or questions to the
public Ensembl
24 developers list at <http:
26 Questions may also be sent to the Ensembl help desk at
37 # start with an empty tree
40 # add a few intervals (i.e. Bio::EnsEMBL::Utils::Interval)
46 my $result = $tree->search(85, 100);
47 if (scalar @{$result}) {
48 print
"Found overlapping interval: [", $result->[0]->start,
', ', $result->[0]->end,
"\n";
53 Class representing a dynamic, i.e.
mutable, interval tree implemented as an augmented AVL balanced binary tree.
55 This module is a wrapper around two possible implementations: one
using the Perl extension (XS) mechanisms, and
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.
65 package Bio::EnsEMBL::Utils::Tree::Interval::Mutable;
72 # the modules providing the underlying implementation,
73 # either XS or pure perl fallback
74 my $XS =
'Bio::EnsEMBL::XS::Utils::Tree::Interval::Mutable';
75 my $PP =
'Bio::EnsEMBL::Utils::Tree::Interval::Mutable::PP';
77 # if XS is used, version at least 1.3.1 is required (provides the interval tree library)
78 my $VERSION_XS =
'1.3.1';
80 my
@public_methods = qw/ insert search remove size /;
82 # import either XS or PP methods into namespace
83 unless ($Bio::EnsEMBL::Utils::Tree::Interval::Mutable::IMPL) {
84 # first check if XS is available and try to load it,
85 # otherwise fall back to PP implementation
86 _load_xs() or _load_pp() or throw "Couldn't load implementation: $
@";
93 Example : my $tree = Bio::EnsEMBL::Utils::Tree::Mutable();
94 Description : Constructor. Creates a new mutable tree instance
95 Returntype : Bio::EnsEMBL::Utils::Tree::Interval::Mutable
103 my $class = ref($caller) || $caller;
105 # for ($XS|$PP)::new(0);
106 return eval qq| $Bio::EnsEMBL::Utils::Tree::Interval::Mutable::IMPL\::new( \$caller ) | unless $caller; ## no critic
108 if (my $self = $Bio::EnsEMBL::Utils::Tree::Interval::Mutable::IMPL->new(@_)) {
109 $self->{_IMPL} = $Bio::EnsEMBL::Utils::Tree::Interval::Mutable::IMPL;
110 bless($self, $class);
118 _load($XS, $VERSION_XS);
126 my ($module, $version) = @_;
129 eval qq| use $module $version |; ## no critic
130 info(sprintf("Cannot load %s interval tree implementation", $module eq $XS?'XS':'PP'), 2000)
137 no strict qw(refs);
## no critic
139 for my $method (@public_methods) {
140 *{
"Bio::EnsEMBL::Utils::Tree::Interval::Mutable::$method"} = \&{
"$module\::$method"};