X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FBinaryNode.java;h=624c2b9af0bd01e32df0ff8b8a94e00ae49a2f5f;hb=a0bd24f90375fc1d4be619bf65746a912dfcfc89;hp=6fb3be2f65372e1663498170a2387f17c59588ac;hpb=f008025f6aa0c2df0e1fbf556a89393e7052db72;p=jalview.git diff --git a/src/jalview/datamodel/BinaryNode.java b/src/jalview/datamodel/BinaryNode.java index 6fb3be2..624c2b9 100755 --- a/src/jalview/datamodel/BinaryNode.java +++ b/src/jalview/datamodel/BinaryNode.java @@ -1,90 +1,231 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.datamodel; -public class BinaryNode +import java.awt.Color; + +/** + * Represent a node in a binary tree + * + * @author $mclamp (probably!)$ + * @version $Revision$ + */ +public class BinaryNode { + T element; - Object element; String name; - BinaryNode left; - BinaryNode right; - BinaryNode parent; + + BinaryNode left; + + BinaryNode right; + + BinaryNode parent; + + /** Bootstrap value */ public int bootstrap; + /** DOCUMENT ME!! */ + public double dist; + + /** DOCUMENT ME!! */ + public int count; + + /** DOCUMENT ME!! */ + public double height; + + /** DOCUMENT ME!! */ + public float ycount; + + /** DOCUMENT ME!! */ + public Color color = Color.black; + + /** + * if true, node is created to simulate polytomy between parent and its 3 or + * more children + */ + public boolean dummy = false; + + /** + * Creates a new BinaryNode object. + */ public BinaryNode() { left = right = parent = null; bootstrap = 0; + dist = 0; } - public BinaryNode(Object element, BinaryNode parent, String name) + /** + * Creates a new BinaryNode object. + * + * @param element + * DOCUMENT ME! + * @param parent + * DOCUMENT ME! + * @param name + * DOCUMENT ME! + */ + public BinaryNode(T element, BinaryNode parent, String name, + double dist) { + this(); this.element = element; this.parent = parent; this.name = name; + this.dist = dist; + } - left = right = null; + public BinaryNode(T element, BinaryNode parent, String name, + double dist, int bootstrap) + { + this(element, parent, name, dist); + this.bootstrap = bootstrap; } - public Object element() + public BinaryNode(T val, BinaryNode parent, String name, double dist, + int bootstrap, boolean dummy) + { + this(val, parent, name, dist, bootstrap); + this.dummy = dummy; + } + + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public T element() { return element; } - public Object setElement(Object v) + /** + * DOCUMENT ME! + * + * @param v + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public T setElement(T v) { return element = v; } - public BinaryNode left() + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public BinaryNode left() { return left; } - public BinaryNode setLeft(BinaryNode n) + /** + * DOCUMENT ME! + * + * @param n + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public BinaryNode setLeft(BinaryNode n) { return left = n; } - public BinaryNode right() + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public BinaryNode right() { return right; } - public BinaryNode setRight(BinaryNode n) + /** + * DOCUMENT ME! + * + * @param n + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public BinaryNode setRight(BinaryNode n) { return right = n; } - public BinaryNode parent() + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public BinaryNode parent() { return parent; } - public BinaryNode setParent(BinaryNode n) + /** + * DOCUMENT ME! + * + * @param n + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public BinaryNode setParent(BinaryNode n) { return parent = n; } + /** + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ public boolean isLeaf() { return (left == null) && (right == null); } /** - * attaches FIRST and SECOND node arguments as the LEFT and RIGHT children of this node (removing any old references) - * a null parameter DOES NOT mean that the pointer to the corresponding child node is set to NULL - you should use + * attaches FIRST and SECOND node arguments as the LEFT and RIGHT children of + * this node (removing any old references) a null parameter DOES NOT mean that + * the pointer to the corresponding child node is set to NULL - you should use * setChild(null), or detach() for this. - * + * */ - public void SetChildren(BinaryNode leftchild, BinaryNode rightchild) + public void SetChildren(BinaryNode leftchild, BinaryNode rightchild) { if (leftchild != null) { this.setLeft(leftchild); leftchild.detach(); leftchild.setParent(this); - } + if (rightchild != null) { this.setRight(rightchild); @@ -95,11 +236,13 @@ public class BinaryNode /** * Detaches the node from the binary tree, along with all its child nodes. + * * @return BinaryNode The detached node. */ - public BinaryNode detach() + public BinaryNode detach() { - if (this.parent!=null) { + if (this.parent != null) + { if (this.parent.left == this) { this.parent.left = null; @@ -112,51 +255,129 @@ public class BinaryNode } } } + this.parent = null; + return this; } + /** - * Traverses up through the tree until a node with a free leftchild is discovered. + * Traverses up through the tree until a node with a free leftchild is + * discovered. + * * @return BinaryNode */ - public BinaryNode ascendLeft() { - BinaryNode c = this; - do { + public BinaryNode ascendLeft() + { + BinaryNode c = this; + + do + { c = c.parent(); - } while (c!=null && c.left()!=null && !c.left().isLeaf()); + } while ((c != null) && (c.left() != null) && !c.left().isLeaf()); + return c; } + /** - * Traverses up through the tree until a node with a free rightchild is discovered. - * Jalview builds trees by descent on the left, so this may be unused. + * Traverses up through the tree until a node with a free rightchild is + * discovered. Jalview builds trees by descent on the left, so this may be + * unused. + * * @return BinaryNode */ - public BinaryNode ascendRight() { - BinaryNode c = this; - do { + public BinaryNode ascendRight() + { + BinaryNode c = this; + + do + { c = c.parent(); - } while (c!=null && c.right()!=null && !c.right().isLeaf()); + } while ((c != null) && (c.right() != null) && !c.right().isLeaf()); + return c; } - + /** + * + * set the display name + * + * @param new + * name + */ public void setName(String name) { this.name = name; } + /** + * + * + * @return the display name for this node + */ public String getName() { return this.name; } + /** + * set integer bootstrap value + * + * @param boot + */ public void setBootstrap(int boot) { this.bootstrap = boot; } + /** + * get bootstrap + * + * @return integer value + */ public int getBootstrap() { return bootstrap; } + + /** + * @param dummy + * true if node is created for the representation of polytomous trees + */ + public boolean isDummy() + { + return dummy; + } + + /** + * DOCUMENT ME! + * + * @param newstate + * DOCUMENT ME! + * + * @return DOCUMENT ME! + */ + public boolean setDummy(boolean newstate) + { + boolean oldstate = dummy; + dummy = newstate; + + return oldstate; + } + + /** + * ascends the tree but doesn't stop until a non-dummy node is discovered. + * + */ + public BinaryNode AscendTree() + { + BinaryNode c = this; + + do + { + c = c.parent(); + } while ((c != null) && c.dummy); + + return c; + } }