PhyloSort

phylosort
Class TreeNode

java.lang.Object
  extended by phylosort.TreeNode

public class TreeNode
extends java.lang.Object

A generic tree node that can be root, internal or leaf (operational taxonomic unit "OTU") node.

Version:
$Revision: 1.5 $
Author:
Ahmed Moustafa

Field Summary
static float DEFAULT_BRANCH_LENGTH
          Default branch length
static int DEFAULT_ROOT_ID
          Default root node id
static int DEFAULT_ROOT_LEVEL
          Default root node level
static int INVALID_NODE_ID
          Invalid node id (for example, node not found)
 
Constructor Summary
TreeNode()
          Default constructor
 
Method Summary
 void addChild(TreeNode child)
          Adds a child to the tree
 java.lang.String depthFirstSearch()
          Performs a depth-first search (DFS) starting at the current node
static TreeNode find(TreeNode tree, java.lang.String label)
          Finds a node with a specific label
 java.lang.Iterable<TreeNode> getChildren()
          Returns an iterator to the children
 int getChildrenCount()
          Returns the number of children
 int getId()
          Returns the node id
 java.lang.String getLabel()
          Returns the label of the node
 java.util.List<TreeNode> getLeaves()
          Returns all leaves under this node
 float getLength()
          Returns the length of the node branch
 int getLevel()
          Returns the node level
 int getMaximumId()
          Returns the maximum node id under this node
 TreeNode getNode(int id)
          Retrieve a node using its id
 TreeNode getParent()
          Returns the parent of the node
 Path getPathFromRoot()
          Returns an ordered list representing the path from the root to this node.
 TreeNode getRoot()
          Returns the root of the tree of a node
 java.lang.Iterable<TreeNode> getSortedChildren()
          Returns an iterorator to the sorted children
 java.lang.String getTaxon()
          Extracts a taxon string from the node label
 java.lang.String getTaxon(boolean labelOnNoMatch)
          Extracts a taxon string from the node label
 boolean isLeaf()
          Returns true if the nodes does not have any children
 boolean isRoot()
          Returns true if this the root node of the tree (i.e.
 java.lang.Iterable<TreeNode> iterator()
          Returns depth first search Iterable
 void preprocess()
          Processes the tree and sets the id and level for each in the tree
 int preprocess(int id, int level)
          Processes the tree and sets the id and level for each in the tree
 void removeChild(int child)
          Removes a child
 void removeChild(TreeNode child)
          Removes a child
 void setId(int id)
          Sets the node id
 void setLabel(java.lang.String label)
          Sets the label of the node
 void setLength(float length)
          Sets the length of the node branch
 void setLevel(int level)
          Sets the node level
 void setParent(TreeNode parent)
          Sets the parent of the node
 int size()
          Returns the number of terminal nodes in a tree
 java.lang.String toString()
          Returns a string representation of the tree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_ROOT_ID

public static final int DEFAULT_ROOT_ID
Default root node id

See Also:
Constant Field Values

DEFAULT_ROOT_LEVEL

public static final int DEFAULT_ROOT_LEVEL
Default root node level

See Also:
Constant Field Values

DEFAULT_BRANCH_LENGTH

public static final float DEFAULT_BRANCH_LENGTH
Default branch length

See Also:
Constant Field Values

INVALID_NODE_ID

public static final int INVALID_NODE_ID
Invalid node id (for example, node not found)

See Also:
Constant Field Values
Constructor Detail

TreeNode

public TreeNode()
Default constructor

Method Detail

addChild

public void addChild(TreeNode child)
Adds a child to the tree

Parameters:
child - A child to be added

getChildren

public java.lang.Iterable<TreeNode> getChildren()
Returns an iterator to the children

Returns:
an iterator to the children

getSortedChildren

public java.lang.Iterable<TreeNode> getSortedChildren()
Returns an iterorator to the sorted children

Returns:
an iterorator to the sorted children

getChildrenCount

public int getChildrenCount()
Returns the number of children

Returns:
the number of children

getLabel

public java.lang.String getLabel()
Returns the label of the node

Returns:
the label of the node

setLabel

public void setLabel(java.lang.String label)
Sets the label of the node

Parameters:
label - The label to set

getLength

public float getLength()
Returns the length of the node branch

Returns:
the length of the node branch

setLength

public void setLength(float length)
Sets the length of the node branch

Parameters:
length - The length to set

getId

public int getId()
Returns the node id

Returns:
int The node id

setId

public void setId(int id)
Sets the node id

Parameters:
id - The node id to set

getLevel

public int getLevel()
Returns the node level

Returns:
int The node level

setLevel

public void setLevel(int level)
Sets the node level

Parameters:
level - The node level to set

isLeaf

public boolean isLeaf()
Returns true if the nodes does not have any children

Returns:
true if the nodes does not have any children otherwise false

getParent

public TreeNode getParent()
Returns the parent of the node

Returns:
TreeNode The parent of the node

setParent

public void setParent(TreeNode parent)
Sets the parent of the node

Parameters:
parent - The parent to set

isRoot

public boolean isRoot()
Returns true if this the root node of the tree (i.e. it does not have a parent node)

Returns:
true if this the root node of the tree

depthFirstSearch

public java.lang.String depthFirstSearch()
Performs a depth-first search (DFS) starting at the current node

Returns:
String A string representation of the tree

toString

public java.lang.String toString()
Returns a string representation of the tree

Overrides:
toString in class java.lang.Object
Returns:
String A string representation of the tree

preprocess

public void preprocess()
Processes the tree and sets the id and level for each in the tree


preprocess

public int preprocess(int id,
                      int level)
Processes the tree and sets the id and level for each in the tree

Parameters:
id - The node id to set
level - The node level to set
Returns:
int The node id

getNode

public TreeNode getNode(int id)
Retrieve a node using its id

Parameters:
id - The node id
Returns:
TreeNode that has the specified id

getMaximumId

public int getMaximumId()
Returns the maximum node id under this node

Returns:
int The maximum node id under this node

getPathFromRoot

public Path getPathFromRoot()
Returns an ordered list representing the path from the root to this node. Each node in the path is represented by its id integer value.

Returns:
An ordered list representing the path from the root to this node

removeChild

public void removeChild(TreeNode child)
Removes a child

Parameters:
child - Child to be removed

removeChild

public void removeChild(int child)
Removes a child

Parameters:
child - Child to be removed

size

public int size()
Returns the number of terminal nodes in a tree

Returns:
the number of terminal nodes in a tree

getLeaves

public java.util.List<TreeNode> getLeaves()
Returns all leaves under this node

Returns:
all leaves under this node

getTaxon

public java.lang.String getTaxon()
Extracts a taxon string from the node label

Returns:
String taxon

getTaxon

public java.lang.String getTaxon(boolean labelOnNoMatch)
Extracts a taxon string from the node label

Parameters:
labelOnNoMatch - Flag to return the node label if no match
Returns:
String taxon

find

public static TreeNode find(TreeNode tree,
                            java.lang.String label)
Finds a node with a specific label

Parameters:
tree - TreeNode root of tree
label - String query label
Returns:
TreeNode with query label

getRoot

public TreeNode getRoot()
Returns the root of the tree of a node

Returns:
Root TreeNode

iterator

public java.lang.Iterable<TreeNode> iterator()
Returns depth first search Iterable

Returns:
Depth first search Iterable

PhyloSort

SourceForge.Net