Package ffx.numerics.clustering
Class Cluster
java.lang.Object
ffx.numerics.clustering.Cluster
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a child cluster to this node.void
addLeafName
(String lname) Adds a single leaf name contained within this cluster's subtree.void
appendLeafNames
(List<String> lnames) Appends a list of leaf names to this cluster's leaf name list.boolean
Tests whether this cluster has the specified child.int
Counts the number of leaf descendants beneath this cluster.int
countLeafs
(Cluster node, int count) Recursive helper to count leaves under the specified node.boolean
Returns the list of child clusters, creating it lazily if needed.Gets the Distance metadata for this cluster (linkage distance and weight).Convenience accessor for this cluster's linkage distance value.Returns the list of leaf names beneath this cluster.getName()
Gets the name of this cluster.Gets the parent cluster of this node, or null if this is the root.double
Computes the cumulative distance down the leftmost branch of this cluster.Convenience accessor for this cluster's aggregate weight.int
hashCode()
boolean
isLeaf()
Returns true if this cluster is a leaf (has no children).void
setChildren
(List<Cluster> children) Sets the list of child clusters for this node.void
setDistance
(Distance distance) Sets the Distance metadata for this cluster.void
Sets the name of this cluster.void
Sets the parent cluster of this node.void
toConsole
(int indent) Prints this cluster and its subtree to the console with indentation.toNewickString
(int indent) Serializes this cluster subtree into a simple Newick-like string.toString()
-
Constructor Details
-
Cluster
Creates a new Cluster with the provided name.- Parameters:
name
- the cluster name
-
-
Method Details
-
getDistance
Gets the Distance metadata for this cluster (linkage distance and weight).- Returns:
- the Distance object
-
getWeightValue
Convenience accessor for this cluster's aggregate weight.- Returns:
- the weight value stored in the Distance
-
getDistanceValue
Convenience accessor for this cluster's linkage distance value.- Returns:
- the linkage distance, or null if unset
-
setDistance
Sets the Distance metadata for this cluster.- Parameters:
distance
- the Distance to set
-
getChildren
Returns the list of child clusters, creating it lazily if needed.- Returns:
- mutable list of child clusters (possibly empty)
-
addLeafName
Adds a single leaf name contained within this cluster's subtree.- Parameters:
lname
- the leaf name to add
-
appendLeafNames
Appends a list of leaf names to this cluster's leaf name list.- Parameters:
lnames
- list of leaf names to append
-
getLeafNames
Returns the list of leaf names beneath this cluster.- Returns:
- list of leaf names
-
setChildren
Sets the list of child clusters for this node.- Parameters:
children
- the children to set
-
getParent
Gets the parent cluster of this node, or null if this is the root.- Returns:
- the parent cluster, or null
-
setParent
Sets the parent cluster of this node.- Parameters:
parent
- the parent cluster to set
-
getName
Gets the name of this cluster.- Returns:
- the cluster name
-
setName
Sets the name of this cluster.- Parameters:
name
- the name to set
-
addChild
Adds a child cluster to this node.- Parameters:
cluster
- the child to add
-
contains
Tests whether this cluster has the specified child.- Parameters:
cluster
- the child to look for- Returns:
- true if present; false otherwise
-
toString
-
equals
-
hashCode
public int hashCode() -
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
Recursive helper to count leaves under the specified node.- Parameters:
node
- the node to inspectcount
- 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
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
-