The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

RandomJungle::Tree::Node - A simple representation of a node in a RandomJungle::Tree

VERSION

Version 0.02

SYNOPSIS

RandomJungle::Tree::Node is a simple representation of a node in a RandomJungle::Tree. This class provides access to data about a node. The constructor is not intended to be called outside of RandomJungle::Tree.

        use RandomJungle::Tree::Node;

        my $node = RandomJungle::Tree::Node->new( vector_index => $i, node_data => $href )
                or die $RandomJungle::Tree::Node::ERROR;

        my $bool = $node->is_terminal;
        my $predicted_pheno = $node->get_terminal_value || warn $node->err_str;

        my $variable_i = $node->get_variable_index || warn $node->err_str;

        my $vector_i = $node->get_vector_index;
        my $vector_i = $node->get_vector_index_of_parent || warn $node->err_str;

        # Returns the index of the next node based on a genotype value ( 0, 1, 2 )
        my $vector_i = $node->get_vector_index_for_genotype( $genotype )
                or warn $node->err_str;

        # Error handling
        $node->set_err( 'Something went boom' );
        my $msg = $node->err_str;
        my $trace = $node->err_trace;

METHODS

new()

Creates and returns a new RandomJungle::Tree::Node object:

        my $node = RandomJungle::Tree::Node->new( vector_index => $i, node_data => $href )
                or die $RandomJungle::Tree::Node::ERROR;

Both parameters are required: vector_index is the index of the node in the varID/values/branches vector (see XML file) node_data is an href from a RandomJungle::Tree object (from the rj_tree array within the object)

This method sets $ERROR and returns undef on failure.

Note: This method is not intended to be called outside of RandomJungle::Tree, as the interface and the structure of the node_data $href is not guaranteed to be stable.

is_terminal()

Returns 1 or 0, depending on whether or not the node is a terminal node, respectively.

        my $bool = $node->is_terminal;

get_variable_index()

Returns the index of the variable (from the RAW file) to be tested in this node. Note this is not the variable label.

        my $variable_i = $node->get_variable_index || warn $node->err_str;

Sets err_str and returns undef if the node is a terminal node.

get_terminal_value()

Returns the terminal value (predicted phenotype) of the node, if it is a terminal node.

        my $predicted_pheno = $node->get_terminal_value || warn $node->err_str;

Sets err_str and returns undef if the node is not a terminal node.

get_vector_index()

Returns the index of the node in the varID/values/branches vector (see XML file).

        my $vector_i = $node->get_vector_index;

get_vector_index_of_parent()

Returns the index of the parent node in the varID/values/branches vector (see XML file).

        my $vector_i = $node->get_vector_index_of_parent || warn $node->err_str;

Sets err_str and returns undef if the node is the root of the tree (index 0).

get_vector_index_for_genotype()

Takes as input a genotype value (valid values are 0, 1, 2) corresponding to the variable to be tested in this node (see get_variable_index) and returns the vector index of the next node in the tree, based on the genotype value.

        my $vector_i = $node->get_vector_index_for_genotype( $genotype )
                                        or warn $node->err_str;

Sets err_str and returns undef if the node is a terminal node or if the genotype is invalid.

set_err

Sets the error message (provided as a parameter) and creates a stack trace:

        $tree->set_err( 'Something went boom' );

err_str

Returns the last error message that was set:

        my $msg = $tree->err_str;

err_trace

Returns a backtrace for the last error that was encountered:

        my $trace = $tree->err_trace;

NOTES

I considered implementing this as a subclass of Tree::DAG_Node but decided there was too much overhead given the current requirements. Specifically, DAG_Node requires the associations between nodes to be built within the nodes themselves, which is not consistent with the current design of RandomJungle::Tree (it contains information about the structure of the tree and relationships between the nodes, and each node is independent).

A lot of methods could be added to facilitate classification and/or traversal, but that's not the point of this class, which is intended to simplify getting data about a node by wrapping the data structure of a node within RandomJungle::Tree.

SEE ALSO

RandomJungle::Jungle, RandomJungle::Tree, RandomJungle::Tree::Node, RandomJungle::XML, RandomJungle::OOB, RandomJungle::RAW, RandomJungle::DB, RandomJungle::Classification_DB

AUTHOR

Robert R. Freimuth

COPYRIGHT

Copyright (c) 2011 Mayo Foundation for Medical Education and Research. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.