org.forester.phylogeny
Class PhylogenyNode

java.lang.Object
  extended by org.forester.phylogeny.PhylogenyNode
All Implemented Interfaces:
Comparable<PhylogenyNode>, PhylogenyNodeI

public class PhylogenyNode
extends Object
implements PhylogenyNodeI, Comparable<PhylogenyNode>


Field Summary
static double DISTANCE_DEFAULT
          Value of -99.0 is used as default value.
 
Constructor Summary
PhylogenyNode()
          Default constructor for PhylogenyNode.
PhylogenyNode(String nhx)
           
PhylogenyNode(String nhx, NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction)
           
PhylogenyNode(String nhx, NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction, boolean replace_underscores)
          Constructor for PhylogenyNode.
 
Method Summary
 void addAsChild(PhylogenyNodeI node)
          Adds PhylogenyNode n to the list of child nodes and sets the _parent of n to this.
 int compareTo(PhylogenyNode o)
           
 PhylogenyNode copyNodeData()
          Returns a new PhylogenyNode which has its data copied from this PhylogenyNode.
 boolean equals(Object o)
           
 List<PhylogenyNode> getAllExternalDescendants()
          Returns a List containing references to all external children of this PhylogenyNode.
 List<String> getAllExternalDescendantsNames()
          Returns a List containing references to all names of the external children of this PhylogenyNode.
 BranchData getBranchData()
           
 PhylogenyNode getChildNode(int i)
          This return child node n of this node.
 PhylogenyNode getChildNode1()
          Convenience method.
 PhylogenyNode getChildNode2()
          Convenience method.
 int getChildNodeIndex()
          This gets the child node index of this node.
 int getChildNodeIndex(PhylogenyNode parent)
          This gets the child node index of this node, given that parent is its parent
 List<PhylogenyNode> getDescendants()
           
 double getDistanceToParent()
          Returns the length of the branch leading to the _parent of this PhylogenyNode (double).
 PhylogenyNode getFirstChildNode()
          Convenience method.
 byte getIndicator()
          Returns the _indicator value of this PhylogenyNode.
 PhylogenyNode getLastChildNode()
          Convenience method.
 PhylogenyNode getLink()
          Returns a refernce to the linked PhylogenyNode of this PhylogenyNode.
 PhylogenyNode getNextExternalNode()
          Returns a refernce to the next external PhylogenyNode of this PhylogenyNode.
static int getNodeCount()
          Returns the total number of all Nodes created so far.
 NodeData getNodeData()
           
 int getNodeId()
          Returns the ID (int) of this PhylogenyNode.
 String getNodeName()
          Returns the name of this node.
 int getNumberOfDescendants()
           
 int getNumberOfExternalNodes()
          Returns the total number of external Nodes originating from this PhylogenyNode (int).
 int getNumberOfParents()
           
 PhylogenyNode getParent()
          Returns a refernce to the parent PhylogenyNode of this PhylogenyNode.
 boolean getPathToParent()
           
 PhylogenyNode getPreviousExternalNode()
          Returns a refernce to the next external PhylogenyNode of this PhylogenyNode.
 float getXcoord()
          Used for drawing of Trees.
 float getXSecondary()
           
 float getYcoord()
          Used for drawing of Trees.
 float getYSecondary()
           
 int hashCode()
           
 void initializeData()
          Deletes data of this PhylogenyNode.
 boolean isCollapse()
          Returns whether this PhylogenyNode should be drawn as collapsed.
 boolean isDuplication()
          Returns true if this PhylogenyNode represents a _duplication event, false otherwise.
 boolean isExternal()
          Checks whether this PhylogenyNode is external (tip).
 boolean isFirstChildNode()
          DOCUMENT ME!
 boolean isFirstExternalNode()
          DOCUMENT ME!
 boolean isHasAssignedEvent()
          Returns whether a _duplication or speciation event has been assigned for this PhylogenyNode.
 boolean isInternal()
          Checks whether this PhylogenyNode is internal (tip).
 boolean isLastChildNode()
          Returns true if this node is the last child node of its _parent.
 boolean isLastExternalNode()
          DOCUMENT ME!
 boolean isRoot()
          Checks whether this PhylogenyNode is a root.
 boolean isSpeciation()
           
 PhylogenyNodeIterator iterateChildNodesForward()
           
 void preorderPrint()
          Prints to the console the subtree originating from this PhylogenyNode in preorder.
 void removeChildNode(int i)
           
 void removeChildNode(PhylogenyNode remove_me)
           
 void setBranchData(BranchData branch_data)
           
 void setChild1(PhylogenyNode n)
          Sets the first child PhylogenyNode of this PhylogenyNode to n.
 void setChild2(PhylogenyNode n)
          Sets the second child PhylogenyNode of this PhylogenyNode to n.
 void setChildNode(int i, PhylogenyNode node)
          Inserts PhylogenyNode n at the specified position i into the list of child nodes.
 void setCollapse(boolean b)
          Sets whether this PhylogenyNode should be drawn as collapsed.
 void setDistanceToParent(double d)
          Sets the length of the branch leading to the _parent of this PhylogenyNode to double d.
 void setIndicator(byte i)
          Sets the _indicator value of this PhylogenyNode to i.
 void setLink(PhylogenyNode n)
          Sets the linked PhylogenyNode of this PhylogenyNode to n.
 void setName(String node_name)
          Sets the name of this node.
static void setNodeCount(int i)
          Sets the total number of all Nodes created so far to i (int).
protected  void setNodeId(int i)
          Sets the ID of this PhylogenyNode to i (int).
 void setParent(PhylogenyNode n)
          Sets the _parent PhylogenyNode of this PhylogenyNode to n.
 void setPathToParent(boolean value)
           
 void setSumExtNodes(int i)
          Sets the total number of external Nodes originating from this PhylogenyNode to i (int).
 void setXcoord(float x)
          Used for drawing of Trees.
 void setXSecondary(float x_secondary)
           
 void setYcoord(float y)
          Used for drawing of Trees.
 void setYSecondary(float y_secondary)
           
 String toNewHampshire(boolean simple_nh, boolean write_distance_to_parent)
           
 String toNewHampshireX()
          Converts this PhylogenyNode to a New Hampshire X (NHX) String representation.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DISTANCE_DEFAULT

public static final double DISTANCE_DEFAULT
Value of -99.0 is used as default value.

See Also:
Constant Field Values
Constructor Detail

PhylogenyNode

public PhylogenyNode()
Default constructor for PhylogenyNode.


PhylogenyNode

public PhylogenyNode(String nhx)
              throws NHXFormatException
Throws:
NHXFormatException

PhylogenyNode

public PhylogenyNode(String nhx,
                     NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction)
              throws NHXFormatException
Throws:
NHXFormatException

PhylogenyNode

public PhylogenyNode(String nhx,
                     NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction,
                     boolean replace_underscores)
              throws NHXFormatException
Constructor for PhylogenyNode.

Parameters:
s - String representing one PhylogenyNode in New Hampshire (NH) or New Hampshire X (NHX) format.
Throws:
NHXFormatException
PhylogenyParserException
Method Detail

setPathToParent

public void setPathToParent(boolean value)

getPathToParent

public boolean getPathToParent()

addAsChild

public final void addAsChild(PhylogenyNodeI node)
Adds PhylogenyNode n to the list of child nodes and sets the _parent of n to this.

Specified by:
addAsChild in interface PhylogenyNodeI
Parameters:
n - the PhylogenyNode to add

compareTo

public final int compareTo(PhylogenyNode o)
Specified by:
compareTo in interface Comparable<PhylogenyNode>

copyNodeData

public final PhylogenyNode copyNodeData()
Returns a new PhylogenyNode which has its data copied from this PhylogenyNode. Links to the other Nodes in the same Phylogeny are NOT copied (e.g. _link to _parent). Field "_link" IS copied.

See Also:
getLink()

equals

public final boolean equals(Object o)
Overrides:
equals in class Object

getAllExternalDescendants

public final List<PhylogenyNode> getAllExternalDescendants()
Returns a List containing references to all external children of this PhylogenyNode.

Returns:
List of references to external Nodes

getAllExternalDescendantsNames

public final List<String> getAllExternalDescendantsNames()
Returns a List containing references to all names of the external children of this PhylogenyNode.

Returns:
List of references to names of external Nodes

getBranchData

public final BranchData getBranchData()

getChildNode

public final PhylogenyNode getChildNode(int i)
This return child node n of this node.

Specified by:
getChildNode in interface PhylogenyNodeI
Parameters:
n - the index of the child to get
Returns:
the child node with index n
Throws:
IllegalArgumentException - if n is out of bounds

getChildNode1

public final PhylogenyNode getChildNode1()
Convenience method. Returns the first child PhylogenyNode of this PhylogenyNode.


getChildNode2

public final PhylogenyNode getChildNode2()
Convenience method. Returns the second child PhylogenyNode of this PhylogenyNode.

[last modified May 18, 2005 by CMZ]


getChildNodeIndex

public final int getChildNodeIndex()
This gets the child node index of this node.

Returns:
the child node index of this node
Throws:
UnsupportedOperationException - if this node is a root node

getChildNodeIndex

public final int getChildNodeIndex(PhylogenyNode parent)
This gets the child node index of this node, given that parent is its parent

[last modified Aug 14, 2006 by CMZ]

Returns:
the child node index of this node
Throws:
UnsupportedOperationException - if this node is a root node

getDescendants

public final List<PhylogenyNode> getDescendants()

getDistanceToParent

public final double getDistanceToParent()
Returns the length of the branch leading to the _parent of this PhylogenyNode (double).

Specified by:
getDistanceToParent in interface PhylogenyNodeI

getFirstChildNode

public final PhylogenyNode getFirstChildNode()
Convenience method. Returns the first child node of this node.

[last modified May 18, 2005 by CMZ]

Returns:
the first child node of this node

getIndicator

public final byte getIndicator()
Returns the _indicator value of this PhylogenyNode.


getLastChildNode

public final PhylogenyNode getLastChildNode()
Convenience method. Returns the last child node of this node.

[last modified May 18, 2005 by CMZ]

Returns:
the last child node of this node

getLink

public final PhylogenyNode getLink()
Returns a refernce to the linked PhylogenyNode of this PhylogenyNode. Currently, this method is only used for the speciation-_duplication assignment algorithms.


getNextExternalNode

public final PhylogenyNode getNextExternalNode()
Returns a refernce to the next external PhylogenyNode of this PhylogenyNode. TODO should be in Phylogeny. Returns null if no next external node is available.


getNodeData

public final NodeData getNodeData()

getNodeId

public final int getNodeId()
Returns the ID (int) of this PhylogenyNode.

Specified by:
getNodeId in interface PhylogenyNodeI

getNodeName

public final String getNodeName()
Returns the name of this node.

Specified by:
getNodeName in interface PhylogenyNodeI

getNumberOfDescendants

public final int getNumberOfDescendants()

getNumberOfExternalNodes

public final int getNumberOfExternalNodes()
Returns the total number of external Nodes originating from this PhylogenyNode (int).


getNumberOfParents

public final int getNumberOfParents()

getParent

public final PhylogenyNode getParent()
Returns a refernce to the parent PhylogenyNode of this PhylogenyNode.


getPreviousExternalNode

public final PhylogenyNode getPreviousExternalNode()
Returns a refernce to the next external PhylogenyNode of this PhylogenyNode. TODO should be in Phylogeny. Returns null if no next external node is available.


getXcoord

public final float getXcoord()
Used for drawing of Trees.


getXSecondary

public final float getXSecondary()

getYcoord

public final float getYcoord()
Used for drawing of Trees.


getYSecondary

public final float getYSecondary()

hashCode

public final int hashCode()
Overrides:
hashCode in class Object

initializeData

public final void initializeData()
Deletes data of this PhylogenyNode. Links to the other Nodes in the Phylogeny, the ID and the sum of external nodes are NOT deleted. Field "_link" (_link to Nodes in other Phylogeny) IS deleted.

See Also:
(Last modified: 12/20/03)

isCollapse

public final boolean isCollapse()
Returns whether this PhylogenyNode should be drawn as collapsed.


isDuplication

public final boolean isDuplication()
Returns true if this PhylogenyNode represents a _duplication event, false otherwise.


isExternal

public final boolean isExternal()
Checks whether this PhylogenyNode is external (tip).

Returns:
true if this PhylogenyNode is external, false otherwise

isFirstChildNode

public final boolean isFirstChildNode()
DOCUMENT ME!

Returns:
DOCUMENT ME!

isFirstExternalNode

public final boolean isFirstExternalNode()
DOCUMENT ME!

Returns:
DOCUMENT ME!

isHasAssignedEvent

public final boolean isHasAssignedEvent()
Returns whether a _duplication or speciation event has been assigned for this PhylogenyNode.


isInternal

public final boolean isInternal()
Checks whether this PhylogenyNode is internal (tip).

Returns:
true if this PhylogenyNode is external, false otherwise

isLastChildNode

public final boolean isLastChildNode()
Returns true if this node is the last child node of its _parent.

[last modified June 01, 2005 by CMZ]

Returns:
true if this node is the last child node of its _parent, false otherwise

isLastExternalNode

public final boolean isLastExternalNode()
DOCUMENT ME!

Returns:
DOCUMENT ME!

isRoot

public final boolean isRoot()
Checks whether this PhylogenyNode is a root.

Returns:
true if this PhylogenyNode is the root, false otherwise

isSpeciation

public final boolean isSpeciation()

iterateChildNodesForward

public final PhylogenyNodeIterator iterateChildNodesForward()

preorderPrint

public void preorderPrint()
Prints to the console the subtree originating from this PhylogenyNode in preorder.


removeChildNode

public final void removeChildNode(int i)

removeChildNode

public final void removeChildNode(PhylogenyNode remove_me)

setBranchData

public final void setBranchData(BranchData branch_data)

setChild1

public final void setChild1(PhylogenyNode n)
Sets the first child PhylogenyNode of this PhylogenyNode to n.


setChild2

public final void setChild2(PhylogenyNode n)
Sets the second child PhylogenyNode of this PhylogenyNode to n.


setChildNode

public final void setChildNode(int i,
                               PhylogenyNode node)
Inserts PhylogenyNode n at the specified position i into the list of child nodes. This does not allow null slots in the list of child nodes: If i is larger than the number of child nodes, n is just added to the list, not place at index i.

Parameters:
i - the index of position where to add the child
n - the PhylogenyNode to add

setCollapse

public final void setCollapse(boolean b)
Sets whether this PhylogenyNode should be drawn as collapsed.


setDistanceToParent

public final void setDistanceToParent(double d)
Sets the length of the branch leading to the _parent of this PhylogenyNode to double d.

Specified by:
setDistanceToParent in interface PhylogenyNodeI

setIndicator

public final void setIndicator(byte i)
Sets the _indicator value of this PhylogenyNode to i.


setLink

public final void setLink(PhylogenyNode n)
Sets the linked PhylogenyNode of this PhylogenyNode to n. Currently, this method is only used for the speciation-_duplication assignment algorithms.


setName

public final void setName(String node_name)
Sets the name of this node.

Specified by:
setName in interface PhylogenyNodeI

setNodeId

protected final void setNodeId(int i)
Sets the ID of this PhylogenyNode to i (int). In most cases, this number should not be set to values lower than getNodeCount().


setParent

public final void setParent(PhylogenyNode n)
Sets the _parent PhylogenyNode of this PhylogenyNode to n.

Specified by:
setParent in interface PhylogenyNodeI

setSumExtNodes

public final void setSumExtNodes(int i)
Sets the total number of external Nodes originating from this PhylogenyNode to i (int).


setXcoord

public final void setXcoord(float x)
Used for drawing of Trees.


setXSecondary

public final void setXSecondary(float x_secondary)

setYcoord

public final void setYcoord(float y)
Used for drawing of Trees.


setYSecondary

public final void setYSecondary(float y_secondary)

toNewHampshire

public final String toNewHampshire(boolean simple_nh,
                                   boolean write_distance_to_parent)

toNewHampshireX

public final String toNewHampshireX()
Converts this PhylogenyNode to a New Hampshire X (NHX) String representation.


toString

public final String toString()
Overrides:
toString in class Object

getNodeCount

public static final int getNodeCount()
Returns the total number of all Nodes created so far.

Returns:
total number of Nodes (int)

setNodeCount

public static final void setNodeCount(int i)
Sets the total number of all Nodes created so far to i (int).