Class Cluster

java.lang.Object
ffx.numerics.clustering.Cluster

public class Cluster extends Object
Represents a node in a hierarchical clustering tree (dendrogram). A Cluster may be a leaf (no children) or an internal node with two children. It tracks its name, parent, children, the list of leaf names contained beneath it, and an associated Distance used to store linkage distance and aggregate weight.
Since:
1.0
Author:
Lars Behnke, 2013, Michael J. Schnieders
  • Constructor Details

    • Cluster

      public Cluster(String name)
      Creates a new Cluster with the provided name.
      Parameters:
      name - the cluster name
  • Method Details

    • getDistance

      public Distance getDistance()
      Gets the Distance metadata for this cluster (linkage distance and weight).
      Returns:
      the Distance object
    • getWeightValue

      public Double getWeightValue()
      Convenience accessor for this cluster's aggregate weight.
      Returns:
      the weight value stored in the Distance
    • getDistanceValue

      public Double getDistanceValue()
      Convenience accessor for this cluster's linkage distance value.
      Returns:
      the linkage distance, or null if unset
    • setDistance

      public void setDistance(Distance distance)
      Sets the Distance metadata for this cluster.
      Parameters:
      distance - the Distance to set
    • getChildren

      public List<Cluster> getChildren()
      Returns the list of child clusters, creating it lazily if needed.
      Returns:
      mutable list of child clusters (possibly empty)
    • addLeafName

      public void addLeafName(String lname)
      Adds a single leaf name contained within this cluster's subtree.
      Parameters:
      lname - the leaf name to add
    • appendLeafNames

      public void appendLeafNames(List<String> lnames)
      Appends a list of leaf names to this cluster's leaf name list.
      Parameters:
      lnames - list of leaf names to append
    • getLeafNames

      public List<String> getLeafNames()
      Returns the list of leaf names beneath this cluster.
      Returns:
      list of leaf names
    • setChildren

      public void setChildren(List<Cluster> children)
      Sets the list of child clusters for this node.
      Parameters:
      children - the children to set
    • getParent

      public Cluster getParent()
      Gets the parent cluster of this node, or null if this is the root.
      Returns:
      the parent cluster, or null
    • setParent

      public void setParent(Cluster parent)
      Sets the parent cluster of this node.
      Parameters:
      parent - the parent cluster to set
    • getName

      public String getName()
      Gets the name of this cluster.
      Returns:
      the cluster name
    • setName

      public void setName(String name)
      Sets the name of this cluster.
      Parameters:
      name - the name to set
    • addChild

      public void addChild(Cluster cluster)
      Adds a child cluster to this node.
      Parameters:
      cluster - the child to add
    • contains

      public boolean contains(Cluster cluster)
      Tests whether this cluster has the specified child.
      Parameters:
      cluster - the child to look for
      Returns:
      true if present; false otherwise
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • isLeaf

      public boolean isLeaf()
      Returns true if this cluster is a leaf (has no children).
      Returns:
      true if leaf; false otherwise
    • countLeafs

      public int countLeafs()
      Counts the number of leaf descendants beneath this cluster.
      Returns:
      number of leaf nodes
    • countLeafs

      public int countLeafs(Cluster node, int count)
      Recursive helper to count leaves under the specified node.
      Parameters:
      node - the node to inspect
      count - running count of leaves
      Returns:
      updated count including leaves beneath node
    • toConsole

      public void toConsole(int indent)
      Prints this cluster and its subtree to the console with indentation.
      Parameters:
      indent - number of indentation levels for this node
    • toNewickString

      public String toNewickString(int indent)
      Serializes this cluster subtree into a simple Newick-like string. The first child is annotated with distance, the second with weight.
      Parameters:
      indent - indentation spaces to include (for readability)
      Returns:
      a Newick-like representation of this subtree
    • getTotalDistance

      public double getTotalDistance()
      Computes the cumulative distance down the leftmost branch of this cluster.
      Returns:
      total distance along the first-child path