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

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 82 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';
45 use strict;
46  
47 use Scalar::Util qw(looks_like_number);
48 use Bio::EnsEMBL::Utils::Exception qw(throw);
49  
50 =head2 new
51  
52 Arg [1] : scalar, $x_center
53 The mid point of the intervals represented by the node
54 Arg [2] : Arrayref of Bio::EnsEMBL::Utils::Interval instances
55 Represents the set of intervals overlapping $x_center
56 Arg [3] : Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node
57 The left subtree
58 Arg [4] : Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node
59 The right subtree
60 Description : Constructor. Creates a new centered immutable interval tree node instance
61 Returntype : Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node
62 Exceptions : if $x_center is not a number or the remaining args are not of the
63 correct type
64 Caller : general
65  
66 =cut
67  
68 sub new {
69 my $caller = shift;
70 my $class = ref($caller) || $caller;
71  
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;
75  
76 throw 'x_center must be a number' unless looks_like_number($x_center);
77  
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');
83  
84 if(defined($left)) {
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';
87 }
88 }
89  
90 if(defined($right)) {
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';
93 }
94 }
95  
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} ],
99 'lchild' => $left,
100 'rchild' => $right }, $class);
101 return $self;
102 }
103  
104 =head2 x_center
105  
106 Arg [] : none
107 Description : Return the center point of the intervals represented by the node
108 Returntype : scalar
109 Exceptions : none
110 Caller : general
111  
112 =cut
113  
114 sub x_center {
115 return shift->{x_center};
116 }
117  
118 =head2 s_center_beg
119  
120 Arg [] : none
121 Description : Returns the set of intervals containing the center point sorted by their start point
122 Returntype : Arrayref of Bio::EnsEMBL::Utils::Interval
123 Exceptions : none
124 Caller : general
125  
126 =cut
127  
128 sub s_center_beg {
129 return shift->{s_center_beg};
130 }
131  
132 =head2 s_center_end
133  
134 Arg [] : none
135 Description : Returns the set of intervals containing the center point sorted by their end point
136 Returntype : Arrayref of Bio::EnsEMBL::Utils::Interval
137 Exceptions : none
138 Caller : general
139  
140 =cut
141  
142 sub s_center_end {
143 return shift->{s_center_end};
144 }
145  
146 =head2 left
147  
148 Arg [] : none
149 Description : Returns the node's left child
150 Returntype : Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node
151 Exceptions : none
152 Caller : general
153  
154 =cut
155  
156 sub left {
157 return shift->{lchild};
158 }
159  
160 =head2 right
161  
162 Arg [] : none
163 Description : Returns the node's right child
164 Returntype : Bio::EnsEMBL::Utils::Tree::Interval::Immutable::Node
165 Exceptions : none
166 Caller : general
167  
168 =cut
169  
170 sub right {
171 return shift->{rchild};
172 }
173  
174 1;
175