phylogeny
Class UpdownDistance

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Frame
                          |
                          +--phylogeny.UpdownDistance
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class UpdownDistance
extends java.awt.Frame

UpdownDistance is a class designed to compute the Updown distance in two phylogenetic trees. Currently, the system can be utilized by execution from the command line. All that is required to use the system once it is running is for the input of two Newick formatted trees (the query and data strings).

Version:
1.0
Author:
Steven Regula

Nested Class Summary
static class UpdownDistance.Node
          This class allows for a dynamically allocated tree structure.
 
Field Summary
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Window
 
Fields inherited from class java.awt.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
UpdownDistance()
           
 
Method Summary
static UpdownDistance.Node build(java.lang.String s, UpdownDistance.Node parent, int from, int to)
          Method for supporting Newick Trees with that include an edge length parameter.
static UpdownDistance.Node buildReduced (UpdownDistance.Node n, UpdownDistance.Node lowestMarkedNode)
          This method performs additional error checking to verify correctness of input string.
static UpdownDistance.Node buildSimple(java.lang.String s, UpdownDistance.Node parent, int from, int to)
          Recursive method for creating a tree structure through the use of the node class.
static boolean checkNewick(java.lang.String treeNewick)
          This method performs Newick String Validation
static java.lang.String createSVGTree (UpdownDistance.Node n, boolean checkMark)
          This method is used for creating xml SVG visual diagrams of trees.
static int[][] distanceMatrix (UpdownDistance.Node n, java.lang.String nodeNameList, int type, boolean checkMark)
          Create a double array representing the distance matrix of all nodes in an array.
static java.lang.String edgeSVG (UpdownDistance.Node n, int level, double xLoc, double xLocParent, int nodeSpreadX, boolean checkMark)
          This method is used by createSVG for drawing edges and nodes for the graphically represented tree.
static void fileWriter(java.lang.String source, java.lang.String fname)
          This method opens a file and writes a string to it.
static int findLocation(java.lang.String[] nameArray, java.lang.String nameINode)
          This is a utility method for determining which location a node name is at in an array.
static java.lang.String formatTitle(java.lang.String title, int maxWidth)
          Utility method for formatting node names when listing Up Distance matrices
static java.lang.String getInputTree(java.lang.String typeEntry)
          This method handles the input of Newick formatted trees.
static java.lang.String[] intersectionPD (UpdownDistance.Node PRoot, UpdownDistance.Node DRoot)
          Computes the intersecting nodes of two trees.
static void listMatrix(java.lang.String labelMatrix, int[][] varMatrix)
          Output method for drawing a computed distance matrix double array.
static int lookup (UpdownDistance.Node n, java.lang.String nameNode, int level, boolean checkMark)
          Recursive method to traverse a tree and determine how many relative levels deep a given node is.
static UpdownDistance.Node lowestCommonAncestor (UpdownDistance.Node parent, java.lang.String nameNodeN1, java.lang.String nameNodeN2, int level)
          This method is responsible for performing the work required to find the lowest common ancestor for two particular node names.
static void main(java.lang.String[] args)
          Currently the main method drives the input/output functions
static java.lang.String nodeNames (UpdownDistance.Node n, boolean checkMark)
          Generates node names when a root node is passed, operates through recursion.
static UpdownDistance.Node parse(java.lang.String s)
          Kick-off method for supporting Newick Trees with that include an edge length parameter.
static java.lang.String readFile(java.lang.String fileName)
          This method uses command line argument data to open and read in a Newick Formatted Tree.
static boolean ruleCheck (UpdownDistance.Node PRoot, java.lang.String[] PNameArray, UpdownDistance.Node DRoot, java.lang.String[] DNameArray)
          This method ensures that Updown Distance should be calculated based on specific rules
static int treeReductionStep1 (UpdownDistance.Node parentTreeP, UpdownDistance.Node parentTreeD)
          The first step for tree reduction is to mark all nodes that happen to have some lower node also present in I (the intersection).
static int treeReductionStep15 (UpdownDistance.Node parentTreeP, UpdownDistance.Node parentTreeD)
          This method is one version of the second step for tree reduction.
static int treeReductionStep2 (UpdownDistance.Node parentTreeD)
          This additional tree reduction step can be called upon to remove a marking if any particular marked node has less than 2 marked children
static int UpdownDistanceP(int[][] P, java.lang.String PNames)
          Leverage input values to compute the Up Down distance between two trees.
static int UpdownDistancePD(int[][] P, java.lang.String PNames, int[][] D, java.lang.String DNames)
          Leverage input values to compute the Up Down distance between two trees.
static boolean validateTree(java.lang.String inputTree)
          This method performs additional error checking to verify correctness of input string.
static boolean validateTree2 (UpdownDistance.Node n, boolean rootNode)
          This method validates phylogenetic tree integrity by ensuring that each unlabeled node has at least two (2) children.
 
Methods inherited from class java.awt.Frame
addNotify, finalize, getAccessibleContext, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, paramString, remove, removeNotify, setCursor, setExtendedState, setIconImage, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, postEvent, processEvent, processWindowEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Constructor Detail

UpdownDistance

public UpdownDistance()
Method Detail

parse

public static UpdownDistance.Node parse(java.lang.String s)
Kick-off method for supporting Newick Trees with that include an edge length parameter. Reserved for future use.

Parameters:
s - the Newick tree string to be parsed
Returns:
a top level node for a successfully parsed tree

build

public static UpdownDistance.Node build(java.lang.String s,
                                        UpdownDistance.Node parent,
                                        int from,
                                        int to)
Method for supporting Newick Trees with that include an edge length parameter. Reserved for future use.

Parameters:
s - the Newick tree string to be parsed
parent - the current node parent
from - current location in Newick string during parsing
to - end location in Newick String during parsing
Returns:
a node who is parent to all nodes below

buildSimple

public static UpdownDistance.Node buildSimple(java.lang.String s,
                                              UpdownDistance.Node parent,
                                              int from,
                                              int to)
Recursive method for creating a tree structure through the use of the node class. Method received a string and "drills down" the inner nodes.

Parameters:
s - the Newick tree string to be parsed
parent - the current node parent
from - current location in Newick string during parsing
to - end location in Newick String during parsing
Returns:
a node who is parent to all nodes below

lookup

public static int lookup(UpdownDistance.Node n,
                         java.lang.String nameNode,
                         int level,
                         boolean checkMark)
Recursive method to traverse a tree and determine how many relative levels deep a given node is.

Parameters:
n - Starting node
nameNode - The name of the node we are searching for
level - The current depth
checkMark - If we should increment level for "reduced" nodes
Returns:
Level (-1) if not found

treeReductionStep1

public static int treeReductionStep1
(UpdownDistance.Node parentTreeP,
                                     UpdownDistance.Node parentTreeD)
The first step for tree reduction is to mark all nodes that happen to have some lower node also present in I (the intersection). The method accomplishes this through the use of recursion.

Parameters:
parentTreeP - The query tree root node
parentTreeD - The data tree root node
Returns:
A lower node in I was found (or -1 if not found)

treeReductionStep15

public static int treeReductionStep15
(UpdownDistance.Node parentTreeP,
                                      UpdownDistance.Node parentTreeD)
This method is one version of the second step for tree reduction. This version relies on the principle that the lca of all combinations of nodes in the intersection should be marked.

Parameters:
parentTreeP - The query tree root node
parentTreeD - The data tree root node
Returns:
1 if successful

treeReductionStep2

public static int treeReductionStep2
(UpdownDistance.Node parentTreeD)
This additional tree reduction step can be called upon to remove a marking if any particular marked node has less than 2 marked children

Parameters:
parentTreeD - The data tree root node
Returns:
1 if successful, -1 if not (so method is not called)

lowestCommonAncestor

public static UpdownDistance.Node lowestCommonAncestor
(UpdownDistance.Node parent,
                                                       java.lang.String nameNodeN1,
                                                       java.lang.String nameNodeN2,
                                                       int level)
This method is responsible for performing the work required to find the lowest common ancestor for two particular node names.

Parameters:
parent - The parent node to begin searching under
nameNodeN1 - The first node name in question
nameNodeN2 - The second node name in question
level - The current level
Returns:
Current level (-1 if not found)

distanceMatrix

public static int[][] distanceMatrix
(UpdownDistance.Node n,
                                     java.lang.String nodeNameList,
                                     int type,
                                     boolean checkMark)
Create a double array representing the distance matrix of all nodes in an array. Note that if the boolean flag "checkMark" is set - we should ignore unmarked nodes. The reason for this is to enforce the tree reduction policy when searching for nodes.

Parameters:
n - The parent node to begin searching under
nodeNameList - A list of nodes in the tree with root node n
type - Search flag designating horiz or vertical search
checkMark - Tree to determine if tree reduction is being enforced
Returns:
The matrix of Up distances for all nodes in a tree

listMatrix

public static void listMatrix(java.lang.String labelMatrix,
                              int[][] varMatrix)
Output method for drawing a computed distance matrix double array.

Parameters:
labelMatrix - The labels (node names) for a tree
varMatrix - The double array to be output

formatTitle

public static java.lang.String formatTitle(java.lang.String title,
                                           int maxWidth)
Utility method for formatting node names when listing Up Distance matrices

Parameters:
title - The character string to be printed
maxWidth - The desired width for spacing
Returns:
The padded character string

nodeNames

public static java.lang.String nodeNames
(UpdownDistance.Node n,
                                         boolean checkMark)
Generates node names when a root node is passed, operates through recursion.

Parameters:
n - Node for which to retrieve lower node names
checkMark - Flag to designate whether tree reduction should be enforced.
Returns:
The lower node names

intersectionPD

public static java.lang.String[] intersectionPD
(UpdownDistance.Node PRoot,
                                                UpdownDistance.Node DRoot)
Computes the intersecting nodes of two trees.

Parameters:
PRoot - The root of the Query tree
DRoot - The root of the Data tree
Returns:
The array of strings representing the intersection nodes

UpdownDistancePD

public static int UpdownDistancePD(int[][] P,
                                   java.lang.String PNames,
                                   int[][] D,
                                   java.lang.String DNames)
Leverage input values to compute the Up Down distance between two trees.

Parameters:
P - The Up Down distance matrix of P
PNames - The node names for query tree P
D - The Up Down distance matrix of D
DNames - The node names for data tree D
Returns:
The Up Down Distance

UpdownDistanceP

public static int UpdownDistanceP(int[][] P,
                                  java.lang.String PNames)
Leverage input values to compute the Up Down distance between two trees.

Parameters:
P - The Up Down distance matrix of P
PNames - The node names for query tree P
Returns:
The Up Down Distance

findLocation

public static int findLocation(java.lang.String[] nameArray,
                               java.lang.String nameINode)
This is a utility method for determining which location a node name is at in an array.

Parameters:
nameArray - The array of node names
nameINode - The node name in question
Returns:
The location in the name array string

createSVGTree

public static java.lang.String createSVGTree
(UpdownDistance.Node n,
                                             boolean checkMark)
This method is used for creating xml SVG visual diagrams of trees. This function is especially handy when creating documentation/calculation examples.

Parameters:
n - A root node of a tree
checkMark - Boolean flag to determine if a reduced data tree is being drawn
Returns:
The xml string

edgeSVG

public static java.lang.String edgeSVG
(UpdownDistance.Node n,
                                       int level,
                                       double xLoc,
                                       double xLocParent,
                                       int nodeSpreadX,
                                       boolean checkMark)
This method is used by createSVG for drawing edges and nodes for the graphically represented tree.

Parameters:
n - The parent node.
level - The depth or current level in the tree hierarchy (used for calculating y coordinates)
xLoc - The current horizontal location
xLocParent - The horizontal location of the parent node
nodeSpreadX - The desired seperation width of nodes on the level
checkMark - Boolean flag to determine if reduction should be enforced
Returns:
The edge segment in an xml string

fileWriter

public static void fileWriter(java.lang.String source,
                              java.lang.String fname)
This method opens a file and writes a string to it.

Parameters:
source - The text to be printed to the file
fname - The desired filename

getInputTree

public static java.lang.String getInputTree(java.lang.String typeEntry)
This method handles the input of Newick formatted trees. Some initial error checking is also enforced here to guide the user with respect to input string format.

Parameters:
typeEntry - Parameter for determining if the tree entered is query or data
Returns:
Returns the input string

validateTree

public static boolean validateTree(java.lang.String inputTree)
This method performs additional error checking to verify correctness of input string. Currently this validation operates by counting parenthesis.

Parameters:
inputTree - The input string to verify
Returns:
Boolean flag to represent success or failure or verification

buildReduced

public static UpdownDistance.Node buildReduced
(UpdownDistance.Node n,
                                               UpdownDistance.Node lowestMarkedNode)
This method performs additional error checking to verify correctness of input string. Currently this validation operates by counting parenthesis.

Returns:
Boolean flag to represent success or failure or verification

validateTree2

public static boolean validateTree2
(UpdownDistance.Node n,
                                    boolean rootNode)
This method validates phylogenetic tree integrity by ensuring that each unlabeled node has at least two (2) children.

Parameters:
n - The input tree to verify (root node)
Returns:
Boolean flag to represent success or failure or verification

checkNewick

public static boolean checkNewick(java.lang.String treeNewick)
This method performs Newick String Validation

Returns:
Boolean flag to represent success or failure or verification

ruleCheck

public static boolean ruleCheck
(UpdownDistance.Node PRoot,
                                java.lang.String[] PNameArray,
                                UpdownDistance.Node DRoot,
                                java.lang.String[] DNameArray)
This method ensures that Updown Distance should be calculated based on specific rules

Parameters:
PRoot - The Query tree to verify (root node)
DRoot - The Data tree to verify (root node)
Returns:
Boolean flag to represent success or failure or verification

readFile

public static java.lang.String readFile(java.lang.String fileName)
This method uses command line argument data to open and read in a Newick Formatted Tree. This is used to overcome the platform dependent maximum interactive input string problem.

Parameters:
fileName - The name of the file to open and read
Returns:
Newick Formatted Tree

main

public static void main(java.lang.String[] args)
Currently the main method drives the input/output functions

Parameters:
args - Any command line arguments