<commit_before>=head1 NAME

NestedSet - DESCRIPTION of Object

=head1 SYNOPSIS

=head1 DESCRIPTION

Abstract superclass to encapsulate the process of storing and manipulating a
nested-set representation tree.  Also implements a 'reference count' system 
based on the ObjectiveC retain/release design. 
Designed to be used as the Root class for all Compara 'proxy' classes 
(Member, GenomeDB, DnaFrag, NCBITaxon) to allow them to be made into sets and trees.

=head1 CONTACT

  Contact <NAME> on implementation detail: <EMAIL>
  Contact <NAME> on implementation/design detail: <EMAIL>
  Contact <NAME> on EnsEMBL in general: <EMAIL>

=head1 APPENDIX

The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _

=cut



package Bio::EnsEMBL::Compara::NestedSet;

use strict;
use warnings;

use Bio::EnsEMBL::Utils::Exception;
use Bio::EnsEMBL::Utils::Argument;

use Bio::EnsEMBL::Utils::Exception qw(deprecate throw);
use Bio::EnsEMBL::Utils::Scalar qw(:assert);

use Bio::TreeIO;
use Bio::EnsEMBL::Compara::Graph::Node;
our @ISA = qw(Bio::EnsEMBL::Compara::Graph::Node);

#################################################
# Factory methods
#################################################

=head2 cast

  Arg1          : class (string)
  Description   : Creates a copy of tree casting the nodes to a given class
  Example       : my $sp_tree = $tree->cast('Bio::EnsEMBL::Compara::SpeciesTreeNode');
  ReturnType    : An object of the specified class
  Exceptions    : none
  Caller        : general

=cut

## If this subroutine works we should merge it with copy
sub cast {
    my ($self, $class, $adaptor) = @_;

    eval "require $class";

    my $copy = $self->SUPER::copy;
    bless $copy, $class;
    $copy->adaptor($adaptor) if (defined $adaptor);

    $copy->node_id($self->node_id) if ($copy->can('node_id'));
    $copy->distance_to_parent($self->distance_to_parent);
    $copy->left_index($self->left_index);
    $copy->right_index($self->right_index);

    $copy->{_children_loaded} = $self->{_children_loaded};

    $self->_complete_cast_node($copy) if ($self->can('_complete_cast_node'));

    for my $child (@{$self->children}) {
        $copy->add_child($child->cast($class));
    }

    return $copy;
}

=head2 copy

  Overview   : creates copy of tree starting at this node going down<commit_msg>bugfix: _complete_cast_node has to be called on the copy<commit_after>=head1 NAME

NestedSet - DESCRIPTION of Object

=head1 SYNOPSIS

=head1 DESCRIPTION

Abstract superclass to encapsulate the process of storing and manipulating a
nested-set representation tree.  Also implements a 'reference count' system 
based on the ObjectiveC retain/release design. 
Designed to be used as the Root class for all Compara 'proxy' classes 
(Member, GenomeDB, DnaFrag, NCBITaxon) to allow them to be made into sets and trees.

=head1 CONTACT

  Contact <NAME> on implementation detail: <EMAIL>
  Contact <NAME> on implementation/design detail: <EMAIL>
  Contact <NAME> on EnsEMBL in general: <EMAIL>

=head1 APPENDIX

The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _

=cut



package Bio::EnsEMBL::Compara::NestedSet;

use strict;
use warnings;

use Bio::EnsEMBL::Utils::Exception;
use Bio::EnsEMBL::Utils::Argument;

use Bio::EnsEMBL::Utils::Exception qw(deprecate throw);
use Bio::EnsEMBL::Utils::Scalar qw(:assert);

use Bio::TreeIO;
use Bio::EnsEMBL::Compara::Graph::Node;
our @ISA = qw(Bio::EnsEMBL::Compara::Graph::Node);

#################################################
# Factory methods
#################################################

=head2 cast

  Arg1          : class (string)
  Description   : Creates a copy of tree casting the nodes to a given class
  Example       : my $sp_tree = $tree->cast('Bio::EnsEMBL::Compara::SpeciesTreeNode');
  ReturnType    : An object of the specified class
  Exceptions    : none
  Caller        : general

=cut

## If this subroutine works we should merge it with copy
sub cast {
    my ($self, $class, $adaptor) = @_;

    eval "require $class";

    my $copy = $self->SUPER::copy;
    bless $copy, $class;
    $copy->adaptor($adaptor) if (defined $adaptor);

    $copy->node_id($self->node_id) if ($copy->can('node_id'));
    $copy->distance_to_parent($self->distance_to_parent);
    $copy->left_index($self->left_index);
    $copy->right_index($self->right_index);

    $copy->{_children_loaded} = $self->{_children_loaded};

    $copy->_complete_cast_node($self) if ($copy->can('_complete_cast_node'));

    for my $child (@{$self->children}) {
        $copy->add_child($child->cast($class));
    }

    return $copy;
}

=head2 copy

  Overview   : creates copy of tree starting at this node going down
{'fraction_non_alphanumeric': 0.15643979057591623, 'fraction_numerical': 0.003350785340314136, 'mean_word_length': 4.572928821470245, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2353090', 'n_tokens_mistral': 1558, 'n_tokens_neox': 1467, 'n_words': 457}