softparsmap
Class Node

java.lang.Object
  extended bysoftparsmap.Node
All Implemented Interfaces:
java.lang.Comparable
Direct Known Subclasses:
GeneNode, SpeciesNode

public abstract class Node
extends java.lang.Object
implements java.lang.Comparable

Define common behavior for gene and species nodes and trees. When writing 'this subtree' below it refers to the tree where this node is the root.


Constructor Summary
Node(int label)
          Constructs a gene node with given label.
 
Method Summary
 Node addChild(Node child)
          Adds a child under this parent and sets the child's parent as this node.
 int compareTo(java.lang.Object o)
          Returns this label number minus the given nodes label number.
 boolean equals(java.lang.Object o)
          Two nodes are equal iff they have the same label.
 Node findLCA(java.util.Set leaves)
          Find the last common ancestor in this subtree for the given set of leaves.
 java.util.Set getChildren()
          Returns the child set containing the children.
 int getLabel()
          Returns the label.
 java.util.Set getLeaves()
          Return the leaves of this subtree.
 java.util.Map getMap()
          Returns a map that can be used to save any additional information associated with this node.
 java.util.Set getNodes()
          Return all internal nodes and leaves in this subtree.
 Node getParent()
          Returns the parent of this node.
 Node getRoot()
          Returns the root of this tree.
 java.util.List getSplits()
          Returns the splits that exist in this tree.
 boolean hasChildren()
          Returns true if this node has children, else false.
 int hashCode()
          Returns the label value.
 boolean isBinaryTree()
          Return true if the subtree where this node is the root is binary, else false.
 boolean isConsistentWith(Node tree)
          Returns true if this tree is consistent with the given tree.
 boolean isRoot()
          Returns true if this node is the root of the tree.
static int nextUnique()
          Returns the next unique integer.
 int numChildren()
          Returns the number of children this node has.
 Node pruneOneChildNodes()
          Remove all internal nodes with only one child.
 boolean removeChild(Node child)
          Remove the child from this parent and set the child's parent to null.
 void setMap(java.util.Map map)
           
static void setNextUnique(int newNextUnique)
           
 java.lang.String toString()
          Returns the label number.
 java.lang.String toStringAll()
          Return toStringTree() and toStringTable().
 java.lang.String toStringTable()
          Returns a table of all the attribute information that is found in this subtree.
 java.lang.String toStringTree()
          Returns a easy to read tree of this subtree.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Node

public Node(int label)
Constructs a gene node with given label.

Parameters:
label - the label for this node. Two labels in the same tree can not be the same.
Method Detail

getSplits

public java.util.List getSplits()
Returns the splits that exist in this tree. This method can only be used on the root.

Returns:
the splits that exist in this tree.
See Also:
Split

getMap

public java.util.Map getMap()
Returns a map that can be used to save any additional information associated with this node.

Returns:
a node specific map.

setMap

public void setMap(java.util.Map map)

isConsistentWith

public boolean isConsistentWith(Node tree)
Returns true if this tree is consistent with the given tree. A tree T1 is consistent with a tree T2 iff all splits in T1 is consistent with every split in T2.

Returns:
true if this tree is consistent with the given tree.
See Also:
Split

findLCA

public Node findLCA(java.util.Set leaves)
Find the last common ancestor in this subtree for the given set of leaves.

Parameters:
leaves - is a subset of all leaves in this tree
Returns:
the last common ancestor

isBinaryTree

public boolean isBinaryTree()
Return true if the subtree where this node is the root is binary, else false.

Returns:
true if the subtree is binary, else false.

getNodes

public java.util.Set getNodes()
Return all internal nodes and leaves in this subtree.

Returns:
a set containing all internal nodes and leaves of this subtree.

getLeaves

public java.util.Set getLeaves()
Return the leaves of this subtree.

Returns:
the leaves of this subtree.

pruneOneChildNodes

public Node pruneOneChildNodes()
Remove all internal nodes with only one child. This is done on this subtree and the lowest node is retained.

Returns:
the new root for the changed subtree.

getRoot

public Node getRoot()
Returns the root of this tree.

Returns:
the root of this tree

equals

public boolean equals(java.lang.Object o)
Two nodes are equal iff they have the same label.

Returns:
true if their labels are the same, else false.

hashCode

public int hashCode()
Returns the label value. Consistent with equals(java.lang.Object).

Returns:
the label value.

compareTo

public int compareTo(java.lang.Object o)
Returns this label number minus the given nodes label number.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - is the given node
Returns:
this label number minus the given nodes label number
See Also:
Comparable

removeChild

public boolean removeChild(Node child)
Remove the child from this parent and set the child's parent to null.

Parameters:
child - is the child of this parent that will be removed.
Returns:
true if the child was removed, else false.

addChild

public Node addChild(Node child)
Adds a child under this parent and sets the child's parent as this node.

Parameters:
child - is the new child.
Returns:
this node for chaining.
Throws:
FatalException - if there already exists a child with the the same label.

getParent

public Node getParent()
Returns the parent of this node.

Returns:
the parent of this node.

isRoot

public boolean isRoot()
Returns true if this node is the root of the tree.

Returns:
true if this node is the root.

getLabel

public int getLabel()
Returns the label.

Returns:
this nodes label

toString

public java.lang.String toString()
Returns the label number.

Returns:
the label number

toStringAll

public java.lang.String toStringAll()
Return toStringTree() and toStringTable().

Returns:
toStringTree() and toStringTable()

toStringTree

public java.lang.String toStringTree()
Returns a easy to read tree of this subtree.

Returns:
a easy to read tree of this subtree

toStringTable

public java.lang.String toStringTable()
Returns a table of all the attribute information that is found in this subtree.

Returns:
A table containing all information that exists in this subtree. If attributes are missing it is because they are null.

hasChildren

public boolean hasChildren()
Returns true if this node has children, else false.

Returns:
true if thisnode has children, else false.

numChildren

public int numChildren()
Returns the number of children this node has.

Returns:
the number of children this node has.

getChildren

public java.util.Set getChildren()
Returns the child set containing the children. If there are no children, an empty set will be created and returned.

Returns:
the set of children under this node. If there are no children an empty set will be created and returned.

nextUnique

public static int nextUnique()
Returns the next unique integer. Iterate through all existing integers from 1 to 2^31 and then start over at 1 again. This stream of unique integers are used to label new nodes.

Returns:
the next unique integer

setNextUnique

public static void setNextUnique(int newNextUnique)