Class RootedFromUnrooted

  • All Implemented Interfaces:
    Graph, RootedTree, Tree, Attributable

    public class RootedFromUnrooted
    extends java.lang.Object
    implements RootedTree
    Root an unrooted tree. This class works as a wrapper over any tree to root it. There are two constructors, one which roots the tree at any internal node, the other roots the tree between any two internal nodes. Be aware that rooting between nodes where one of them has less than 3 adjacencies may be problematic when converting back from the Newick format.
    Version:
    $Id: RootedFromUnrooted.java 936 2008-08-06 14:12:07Z rambaut $
    Author:
    Joseph Heled
    • Constructor Detail

      • RootedFromUnrooted

        public RootedFromUnrooted​(Tree source,
                                  Node root,
                                  boolean intentUnrooted)
        Root tree at some internal node.
        Parameters:
        source - tree to root
        root - internal node to root at
        intentUnrooted -
      • RootedFromUnrooted

        public RootedFromUnrooted​(Tree source,
                                  Node left,
                                  Node right,
                                  double fromLeft)
        Root source by creating a new internal node whose children are (the adjacent) left and right.
        Parameters:
        source -
        left -
        right -
        fromLeft - branch from new root to left node.
    • Method Detail

      • getChildren

        public java.util.List<Node> getChildren​(Node node)
        Specified by:
        getChildren in interface RootedTree
        Parameters:
        node - the node whose children are being requested.
        Returns:
        the list of nodes that are the children of the given node. The set may be empty for a terminal node (a tip).
      • hasHeights

        public boolean hasHeights()
        Specified by:
        hasHeights in interface RootedTree
        Returns:
        Whether this tree has node heights available
      • getHeight

        public double getHeight​(Node node)
        Specified by:
        getHeight in interface RootedTree
        Parameters:
        node - the node whose height is being requested.
        Returns:
        the height of the given node. The height will be less than the parent's height and greater than it children's heights.
      • hasLengths

        public boolean hasLengths()
        Specified by:
        hasLengths in interface RootedTree
        Returns:
        Whether this tree has branch lengths available
      • getLength

        public double getLength​(Node node)
        Specified by:
        getLength in interface RootedTree
        Parameters:
        node - the node whose branch length (to its parent) is being requested.
        Returns:
        the length of the branch to the parent node (0.0 if the node is the root).
      • getParent

        public Node getParent​(Node node)
        Specified by:
        getParent in interface RootedTree
        Parameters:
        node - the node whose parent is requested
        Returns:
        the parent node of the given node, or null if the node is the root node.
      • getRootNode

        public Node getRootNode()
        Description copied from interface: RootedTree
        The root of the tree has the largest node height of all nodes in the tree.
        Specified by:
        getRootNode in interface RootedTree
        Returns:
        the root of the tree.
      • conceptuallyUnrooted

        public boolean conceptuallyUnrooted()
        Description copied from interface: RootedTree
        Due to current implementation limitations, trees store "branch" information in nodes. So, internally rooted trees are genetrated when un-rooted would be more natural. This should be removed. If this is a rooted tree then it is rooted. This can really only confuse things. Trees are unrooted, RootedTrees are rooted. This is not an implementation limitation. It may be that a RootedTree has an arbitrary root but it is still rooted. With a rooted tree, it is convenient to store branch information at the node (i.e., for the branch above the node) because there is no "branch" object. Andrew. This function will probably become deprecated once the "development" tree viewer becomes in sync with the main tree viewer branch and some method of handling this concept has been introduced. Until then, this method remains.
        Specified by:
        conceptuallyUnrooted in interface RootedTree
        Returns:
        true if tree(s) are to be viewed as unrooted
      • getExternalNodes

        public java.util.Set<Node> getExternalNodes()
        Specified by:
        getExternalNodes in interface Tree
        Returns:
        a set of all nodes that have degree 1. These nodes are often refered to as 'tips'.
      • getInternalNodes

        public java.util.Set<Node> getInternalNodes()
        Specified by:
        getInternalNodes in interface Tree
        Returns:
        a set of all nodes that have degree 2 or more. These nodes are often refered to as internal nodes.
      • getTaxa

        public java.util.Set<Taxon> getTaxa()
        Specified by:
        getTaxa in interface Tree
        Returns:
        the set of taxa associated with the external nodes of this tree. The size of this set should be the same as the size of the external nodes set.
      • getTaxon

        public Taxon getTaxon​(Node node)
        Specified by:
        getTaxon in interface Tree
        Parameters:
        node - the node whose associated taxon is being requested.
        Returns:
        the taxon object associated with the given node, or null if the node is an internal node.
      • isExternal

        public boolean isExternal​(Node node)
        Specified by:
        isExternal in interface Tree
        Parameters:
        node - the node
        Returns:
        true if the node is of degree 1.
      • getNode

        public Node getNode​(Taxon taxon)
        Specified by:
        getNode in interface Tree
        Parameters:
        taxon - the taxon
        Returns:
        the external node associated with the given taxon, or null if the taxon is not a member of the taxa set associated with this tree.
      • getEdges

        public java.util.List<Edge> getEdges​(Node node)
        Returns a list of edges connected to this node
        Specified by:
        getEdges in interface Graph
        Parameters:
        node -
        Returns:
        the set of nodes that are attached by edges to the given node.
      • getNodes

        public Node[] getNodes​(Edge edge)
        Description copied from interface: Graph
        Returns an array of 2 nodes which are the nodes at either end of the edge.
        Specified by:
        getNodes in interface Graph
        Returns:
        an array of 2 edges
      • getAdjacencies

        public java.util.List<Node> getAdjacencies​(Node node)
        Description copied from interface: Graph
        Returns a list of nodes connected to this node by an edge
        Specified by:
        getAdjacencies in interface Graph
        Returns:
        the set of nodes that are attached by edges to the given node.
      • getEdgeLength

        public double getEdgeLength​(Node node1,
                                    Node node2)
                             throws Graph.NoEdgeException
        Description copied from interface: Graph
        Returns the length of the edge that connects these two nodes
        Specified by:
        getEdgeLength in interface Graph
        Returns:
        the edge length.
        Throws:
        Graph.NoEdgeException - if the nodes are not directly connected by an edge.
      • getNodes

        public java.util.Set<Node> getNodes()
        Specified by:
        getNodes in interface Graph
        Returns:
        the set of all nodes in this graph.
      • getEdges

        public java.util.Set<Edge> getEdges()
        Specified by:
        getEdges in interface Graph
        Returns:
        the set of all edges in this graph.
      • getExternalEdges

        public java.util.Set<Edge> getExternalEdges()
        The set of external edges.
        Specified by:
        getExternalEdges in interface Tree
        Returns:
        the set of external edges.
      • getInternalEdges

        public java.util.Set<Edge> getInternalEdges()
        The set of internal edges.
        Specified by:
        getInternalEdges in interface Tree
        Returns:
        the set of internal edges.
      • getNodes

        public java.util.Set<Node> getNodes​(int degree)
        Specified by:
        getNodes in interface Graph
        Parameters:
        degree - the number of edges connected to a node
        Returns:
        a set containing all nodes in this graph of the given degree.
      • isRoot

        public boolean isRoot​(Node node)
        Specified by:
        isRoot in interface RootedTree
        Parameters:
        node - the node
        Returns:
        true if the node is the root of this tree.
      • setAttribute

        public void setAttribute​(java.lang.String name,
                                 java.lang.Object value)
        Description copied from interface: Attributable
        Sets an named attribute for this object.
        Specified by:
        setAttribute in interface Attributable
        Parameters:
        name - the name of the attribute.
        value - the new value of the attribute.
      • getAttribute

        public java.lang.Object getAttribute​(java.lang.String name)
        Specified by:
        getAttribute in interface Attributable
        Parameters:
        name - the name of the attribute of interest, or null if the attribute doesn't exist.
        Returns:
        an object representing the named attributed for this object.
      • removeAttribute

        public void removeAttribute​(java.lang.String name)
        Specified by:
        removeAttribute in interface Attributable
        Parameters:
        name - name of attribute to remove
      • getAttributeNames

        public java.util.Set<java.lang.String> getAttributeNames()
        Specified by:
        getAttributeNames in interface Attributable
        Returns:
        an array of the attributeNames that this object has.
      • getAttributeMap

        public java.util.Map<java.lang.String,​java.lang.Object> getAttributeMap()
        Description copied from interface: Attributable
        Gets the entire attribute map.
        Specified by:
        getAttributeMap in interface Attributable
        Returns:
        an unmodifiable map