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 Instances of
this class represent nodes in a centered immutable interval tree.
43 package Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node;
47 use Scalar::Util qw(looks_like_number);
52 Arg [1] : scalar, $x_center
53 The mid point of the intervals represented by the node
55 Represents the set of intervals overlapping $x_center
60 Description : Constructor. Creates a
new centered immutable interval tree node instance
62 Exceptions :
if $x_center is not a number or the remaining args are not of the
70 my $class = ref($caller) || $caller;
72 my ($x_center, $s_center, $left, $right) = @_;
73 throw 'Node takes arguments (x_center, s_center, left_child, right_child)'
74 unless $x_center and $s_center; # and $left and $right;
76 throw 'x_center must be a number' unless looks_like_number($x_center);
78 # Bio::EnsEMBL::Utils::Scalar::assert_ref is high-overhead, and was
79 # the source of a significant performance penalty in pipelines where
80 # millions of new nodes are being instantiated. Replaced with simpler
81 # low-overhead type validation.
82 throw 's_center must be an array' unless (ref($s_center) eq
'ARRAY');
85 unless (ref($left) eq
'Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node') {
86 throw 'left must be a Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node';
91 unless (ref($right) eq
'Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node') {
92 throw 'right must be a Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node';
96 my $self = bless({
'x_center' => $x_center,
97 's_center_beg' => [
map { $_->[1] } sort { $a->[0] <=> $b->[0] }
map { [ $_->start, $_ ] } @{$s_center} ],
98 's_center_end' => [
map { $_->[1] } sort { $b->[0] <=> $a->[0] }
map { [ $_->end, $_ ] } @{$s_center} ],
100 'rchild' => $right }, $class);
107 Description : Return the center point of the intervals represented by the node
115 return shift->{x_center};
121 Description : Returns the set of intervals containing the center point sorted by their start point
129 return shift->{s_center_beg};
135 Description : Returns the set of intervals containing the center point sorted by their end point
143 return shift->{s_center_end};
149 Description : Returns the node
's left child
150 Returntype : Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node
157 return shift->{lchild};
163 Description : Returns the node's right child
171 return shift->{rchild};