X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FBinaryNode.java;h=624c2b9af0bd01e32df0ff8b8a94e00ae49a2f5f;hb=HEAD;hp=47cd108e0807ba3d7f41ded64e2503cd84271c4b;hpb=b2f9a8d7bce642ff4011bc6d49e02bb0569fbb11;p=jalview.git diff --git a/src/jalview/datamodel/BinaryNode.java b/src/jalview/datamodel/BinaryNode.java index 47cd108..624c2b9 100755 --- a/src/jalview/datamodel/BinaryNode.java +++ b/src/jalview/datamodel/BinaryNode.java @@ -1,44 +1,69 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1) - * Copyright (C) 2014 The Jalview Authors + * 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. + * 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 . + * 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; +import java.awt.Color; + /** - * DOCUMENT ME! + * Represent a node in a binary tree * - * @author $author$ + * @author $mclamp (probably!)$ * @version $Revision$ */ -public class BinaryNode +public class BinaryNode { - Object element; + T element; String name; - BinaryNode left; + BinaryNode left; - BinaryNode right; + BinaryNode right; - BinaryNode parent; + BinaryNode parent; - /** DOCUMENT ME!! */ + /** 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. */ @@ -46,6 +71,7 @@ public class BinaryNode { left = right = parent = null; bootstrap = 0; + dist = 0; } /** @@ -58,13 +84,28 @@ public class BinaryNode * @param name * DOCUMENT ME! */ - public BinaryNode(Object element, BinaryNode parent, String name) + public BinaryNode(T element, BinaryNode parent, String name, + double dist) { + this(); this.element = element; this.parent = parent; this.name = name; + this.dist = dist; + } + + public BinaryNode(T element, BinaryNode parent, String name, + double dist, int bootstrap) + { + this(element, parent, name, dist); + this.bootstrap = bootstrap; + } - left = right = null; + public BinaryNode(T val, BinaryNode parent, String name, double dist, + int bootstrap, boolean dummy) + { + this(val, parent, name, dist, bootstrap); + this.dummy = dummy; } /** @@ -72,7 +113,7 @@ public class BinaryNode * * @return DOCUMENT ME! */ - public Object element() + public T element() { return element; } @@ -85,7 +126,7 @@ public class BinaryNode * * @return DOCUMENT ME! */ - public Object setElement(Object v) + public T setElement(T v) { return element = v; } @@ -95,7 +136,7 @@ public class BinaryNode * * @return DOCUMENT ME! */ - public BinaryNode left() + public BinaryNode left() { return left; } @@ -108,7 +149,7 @@ public class BinaryNode * * @return DOCUMENT ME! */ - public BinaryNode setLeft(BinaryNode n) + public BinaryNode setLeft(BinaryNode n) { return left = n; } @@ -118,7 +159,7 @@ public class BinaryNode * * @return DOCUMENT ME! */ - public BinaryNode right() + public BinaryNode right() { return right; } @@ -131,7 +172,7 @@ public class BinaryNode * * @return DOCUMENT ME! */ - public BinaryNode setRight(BinaryNode n) + public BinaryNode setRight(BinaryNode n) { return right = n; } @@ -141,7 +182,7 @@ public class BinaryNode * * @return DOCUMENT ME! */ - public BinaryNode parent() + public BinaryNode parent() { return parent; } @@ -154,7 +195,7 @@ public class BinaryNode * * @return DOCUMENT ME! */ - public BinaryNode setParent(BinaryNode n) + public BinaryNode setParent(BinaryNode n) { return parent = n; } @@ -176,7 +217,7 @@ public class BinaryNode * setChild(null), or detach() for this. * */ - public void SetChildren(BinaryNode leftchild, BinaryNode rightchild) + public void SetChildren(BinaryNode leftchild, BinaryNode rightchild) { if (leftchild != null) { @@ -198,7 +239,7 @@ public class BinaryNode * * @return BinaryNode The detached node. */ - public BinaryNode detach() + public BinaryNode detach() { if (this.parent != null) { @@ -226,9 +267,9 @@ public class BinaryNode * * @return BinaryNode */ - public BinaryNode ascendLeft() + public BinaryNode ascendLeft() { - BinaryNode c = this; + BinaryNode c = this; do { @@ -245,9 +286,9 @@ public class BinaryNode * * @return BinaryNode */ - public BinaryNode ascendRight() + public BinaryNode ascendRight() { - BinaryNode c = this; + BinaryNode c = this; do { @@ -261,7 +302,8 @@ public class BinaryNode * * set the display name * - * @param new name + * @param new + * name */ public void setName(String name) { @@ -297,4 +339,45 @@ public class BinaryNode { 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; + } }