EnsEMBL/Utils/Tree/Interval/Immutable/Node.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 79 CC 8 SCAR 36.1
CC
8
Cov
0%
new
72.0
x_center
2.0
s_center_beg
2.0
CRAP 37.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::Immutable::Node
34  
35 =head1 DESCRIPTION
36  
37 Instances of this class represent nodes in a centered immutable interval tree.
38  
39 =head1 METHODS
40  
41 =cut
42  
43 package Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node;
44 $Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node::VERSION = '114.0.0_50'; # TRIAL
45 $Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node::VERSION = '114.0.050';
46 use strict;
47  
48 use Scalar::Util qw(looks_like_number);
49 use Bio::EnsEMBL::Utils::Exception qw(throw);
50  
51 =head2 new
52  
53 Arg [1] : scalar, $x_center
54 The mid point of the intervals represented by the node
55 Arg [2] : Arrayref of Bio::EnsEMBL::Utils::Interval instances
56 Represents the set of intervals overlapping $x_center
57 Arg [3] : Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node
58 The left subtree
59 Arg [4] : Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node
60 The right subtree
61 Description : Constructor. Creates a new centered immutable interval tree node instance
62 Returntype : Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node
63 Exceptions : if $x_center is not a number or the remaining args are not of the
64 correct type
65 Caller : general
66  
67 =cut
68  
69 sub new {
70 my $caller = shift;
71 my $class = ref($caller) || $caller;
72  
73 my ($x_center, $s_center, $left, $right) = @_;
74 throw 'Node takes arguments (x_center, s_center, left_child, right_child)'
75 unless $x_center and $s_center; # and $left and $right;
76  
77 throw 'x_center must be a number' unless looks_like_number($x_center);
78  
79 # Bio::EnsEMBL::Utils::Scalar::assert_ref is high-overhead, and was
80 # the source of a significant performance penalty in pipelines where
81 # millions of new nodes are being instantiated. Replaced with simpler
82 # low-overhead type validation.
83 throw 's_center must be an array' unless (ref($s_center) eq 'ARRAY');
84  
85 if(defined($left)) {
86 unless (ref($left) eq 'Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node') {
87 throw 'left must be a Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node';
88 }
89 }
90  
91 if(defined($right)) {
92 unless (ref($right) eq 'Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node') {
93 throw 'right must be a Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node';
94 }
95 }
96  
97 my $self = bless({ 'x_center' => $x_center,
98 's_center_beg' => [ map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [ $_->start, $_ ] } @{$s_center} ],
99 's_center_end' => [ map { $_->[1] } sort { $b->[0] <=> $a->[0] } map { [ $_->end, $_ ] } @{$s_center} ],
100 'lchild' => $left,
101 'rchild' => $right }, $class);
102 return $self;
103 }
104  
105 =head2 x_center
106  
107 Arg [] : none
108 Description : Return the center point of the intervals represented by the node
109 Returntype : scalar
110 Exceptions : none
111 Caller : general
112  
113 =cut
114  
115 sub x_center {
116 return shift->{x_center};
117 }
118  
119 =head2 s_center_beg
120  
121 Arg [] : none
122 Description : Returns the set of intervals containing the center point sorted by their start point
123 Returntype : Arrayref of Bio::EnsEMBL::Utils::Interval
124 Exceptions : none
125 Caller : general
126  
127 =cut
128  
129 sub s_center_beg {
130 return shift->{s_center_beg};
131 }
132  
133 =head2 s_center_end
134  
135 Arg [] : none
136 Description : Returns the set of intervals containing the center point sorted by their end point
137 Returntype : Arrayref of Bio::EnsEMBL::Utils::Interval
138 Exceptions : none
139 Caller : general
140  
141 =cut
142  
143 sub s_center_end {
144 return shift->{s_center_end};
145 }
146  
147 =head2 left
148  
149 Arg [] : none
150 Description : Returns the node's left child
151 Returntype : Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node
152 Exceptions : none
153 Caller : general
154  
155 =cut
156  
157 sub left {
158 return shift->{lchild};
159 }
160  
161 =head2 right
162  
163 Arg [] : none
164 Description : Returns the node's right child
165 Returntype : Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node
166 Exceptions : none
167 Caller : general
168  
169 =cut
170  
171 sub right {
172 return shift->{rchild};
173 }
174  
175 1;
176