Bio-EnsEMBL
view release on metacpan or search on metacpan
lib/Bio/EnsEMBL/Utils/Tree/Interval/Mutable/Node.pm view on Meta::CPAN
=head1 LICENSE
See the NOTICE file distributed with this work for additional information
regarding copyright ownership.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=cut
=head1 CONTACT
Please email comments or questions to the public Ensembl
developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
Questions may also be sent to the Ensembl help desk at
<http://www.ensembl.org/Help/Contact>.
=cut
=head1 NAME
Bio::EnsEMBL::Utils::Tree::Interval::Mutable::Node
=head1 DESCRIPTION
Represents a node in the mutable interval tree pure perl implementation.
=head1 METHODS
=cut
package Bio::EnsEMBL::Utils::Tree::Interval::Mutable::Node;
$Bio::EnsEMBL::Utils::Tree::Interval::Mutable::Node::VERSION = '114.0.0';
use strict;
use Scalar::Util qw(looks_like_number weaken);
use List::Util qw(max);
use Bio::EnsEMBL::Utils::Scalar qw(assert_ref);
use Bio::EnsEMBL::Utils::Exception qw(throw);
=head1 METHODS
=head2 new
Arg [1] : Bio::EnsEMBL::Utils::Tree::Interval::Mutable::PP
The tree to which the node belongs
Arg [2] : Bio::EnsEMBL::Utils::Interval
Description : Constructor. Creates a new mutable tree instance node
associated with the given interval
Returntype : Bio::EnsEMBL::Utils::Tree::Interval::Mutable::Node
Exceptions : none
Caller : general
=cut
sub new {
my $caller = shift;
my $class = ref($caller) || $caller;
my ($tree, $interval) = @_;
throw 'Node constructor takes (tree, interval) as arguments'
unless $tree and $interval;
my $self = bless({ tree => $tree,
intervals => [ $interval ], # the array of all records with the same key
key => $interval->start,
max => $interval->end,
parent => undef,
height => 0,
left => undef,
right => undef }, $class);
return $self;
}
=head2 tree
Arg [] : none
Example : my $tree = $node->root;
Description : Returns the tree to which the node belongs
Returntype : Bio::EnsEMBL::Utils::Tree::Interval::Mutable::PP
Exceptions : none
Caller : general
=cut
sub tree {
return shift->{tree};
}
=head2 key
Arg [] : none
Example : my $key = $node->key;
Description : Returns the key associated with the node
Returntype : scalar
Exceptions : none
Caller : general
=cut
sub key {
my $self = shift;
$self->{key} = shift if( @_ );
return $self->{key};
}
=head2 intervals
Arg [] : none
Example : my $intervals = $node->intervals;
Description : Returns the intervals associated with the node
Returntype : Arrayref of Bio::EnsEMBL::Utils::Interval
Exceptions : none
Caller : general
=cut
sub intervals {
return shift->{intervals};
}
=head add_interval
Arg [] : none
Description : Add an interval to the node's set of intervals
Returntype : none
Exceptions : none
Caller : general
=cut
sub add_interval {
push @{shift->{intervals}}, shift;
}
=head2 parent
Arg [] : none
Description : Return the parent of the node in the tree
Returntype : none
Exceptions : none
Caller : general
=cut
sub parent {
my $self = shift;
if (@_) {
$self->{parent} = shift;
weaken($self->{parent});
}
return $self->{parent};
}
=head2 height
Arg [] : none
Description : Return the height of the node
Returntype : scalar, positive or 0
Exceptions : none
Caller : general
=cut
sub height {
my $self = shift;
$self->{height} = shift if( @_ );
return $self->{height};
}
=head2 left
Arg [] : none
Description : Return the node's left child
Returntype : Bio::EnsEMBL::Utils::Tree::Interval::Mutable::Node
Exceptions : none
Caller : general
=cut
sub left {
my $self = shift;
$self->{left} = shift if( @_ );
return $self->{left};
}
=head2 right
Arg [] : none
Description : Return the node's right child
Returntype : Bio::EnsEMBL::Utils::Tree::Interval::Mutable::Node
Exceptions : none
Caller : general
=cut
sub right {
my $self = shift;
$self->{right} = shift if( @_ );
return $self->{right};
}
=head2 search
Arg [1] : Bio::EnsEMBL::Utils::Interval
The interval to search for overlaps in the tree
( run in 0.343 second using v1.01-cache-2.11-cpan-39bf76dae61 )