jebl.evolution.trees
Class NeighborJoiningTreeBuilder

java.lang.Object
  extended by jebl.evolution.trees.ClusteringTreeBuilder<Tree>
      extended by jebl.evolution.trees.NeighborJoiningTreeBuilder
All Implemented Interfaces:
TreeBuilder<Tree>

public class NeighborJoiningTreeBuilder
extends ClusteringTreeBuilder<Tree>

Constructs an unrooted tree by neighbor-joining using pairwise distances. Adapted from BEAST code.

Author:
Andrew Rambaut, Alexei Drummond, Joseph Heled

Field Summary
 
Fields inherited from class jebl.evolution.trees.ClusteringTreeBuilder
alias, besti, bestj, clusters, distance, distanceMatrix, minimumTaxa, newCluster, numClusters, tipCount
 
Constructor Summary
NeighborJoiningTreeBuilder(DistanceMatrix distanceMatrix)
          construct NJ tree
 
Method Summary
protected  Node createExternalNode(Taxon taxon)
           
protected  Node createInternalNode(Node[] nodes, double[] distances)
          Creates a new internal node that will have the specified nodes as its children
protected  void findNextPair()
          Find next two clusters to join.
protected  void finish()
           
protected  Tree getTree()
           
protected  double[] joinClusters()
          Inform derived class that clusters besti,bestj are being joinded into a new cluster.
protected  double updatedDistance(int k)
          compute updated distance between the new cluster (besti,bestj) to any other cluster k.
 
Methods inherited from class jebl.evolution.trees.ClusteringTreeBuilder
addProgressListener, build, fireSetProgress, getBuilder, getDist, init, newCluster, removeProgressListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NeighborJoiningTreeBuilder

public NeighborJoiningTreeBuilder(DistanceMatrix distanceMatrix)
construct NJ tree

Parameters:
distanceMatrix - distance matrix
Method Detail

findNextPair

protected void findNextPair()
Description copied from class: ClusteringTreeBuilder
Find next two clusters to join. set shared best{i,j}.

Overrides:
findNextPair in class ClusteringTreeBuilder<Tree>

getTree

protected Tree getTree()
Specified by:
getTree in class ClusteringTreeBuilder<Tree>

createExternalNode

protected Node createExternalNode(Taxon taxon)
Specified by:
createExternalNode in class ClusteringTreeBuilder<Tree>

createInternalNode

protected Node createInternalNode(Node[] nodes,
                                  double[] distances)
Creates a new internal node that will have the specified nodes as its children

Specified by:
createInternalNode in class ClusteringTreeBuilder<Tree>
Parameters:
nodes - Nodes whose parent is about to be created
distances - Distances of those nodes to the parent. distances.length == nodes.length must hold.
Returns:
the new node

finish

protected void finish()
Overrides:
finish in class ClusteringTreeBuilder<Tree>

joinClusters

protected double[] joinClusters()
Description copied from class: ClusteringTreeBuilder
Inform derived class that clusters besti,bestj are being joinded into a new cluster. New cluster will be (the smaller) besti while clusters greater than bestj are shifted one space back.

Specified by:
joinClusters in class ClusteringTreeBuilder<Tree>
Returns:
branch distances to new internal node [besti - dist , bestj dist]

updatedDistance

protected double updatedDistance(int k)
Description copied from class: ClusteringTreeBuilder
compute updated distance between the new cluster (besti,bestj) to any other cluster k. (i,j,k) are cluster indices in [0..numClusters-1]

Specified by:
updatedDistance in class ClusteringTreeBuilder<Tree>