package medusa.georgios.ClusteringAlgorithms;
// The neighbour-joining algorithm. Make a rooted tree by arbitrarily
// adding a root node with edges to the last two leaves
public class NJ {
int N; // The initial number of leaves
int K; // The number of clusters created so far
NJCluster[] cluster; // The nodes (clusters) of the resulting tree
float[] r; // The average distance to other leaves
public StringBuffer NHX = new StringBuffer("");
public NJ(float[][] ds) {
N = ds.length;
cluster = new NJCluster[2*N-1];
for (int i=0; i= dimdjk
|| dijdkm == dimdjk && dijdkm >= dikdjm
|| dikdjm == dimdjk && dikdjm >= dijdkm)) {
System.out.println("(i, j, k, m) = ("+i+","+j+","+k+","+m+")");
return false;
}
}
return true;
}
public boolean is_internal(NJCluster cluster)
{
if( cluster.left == null && cluster.right == null)
return false;
else
return true;
}
public String NewickFormat(NJCluster cluster) {
if(this.is_internal(cluster)){
NHX.append("(");
this.NewickFormat(cluster.left);}
if(this.is_internal(cluster)){NHX.append(",");}
else
{NHX.append(Clustering_NJ_UPGMA.labels.get(cluster.lab-1));}
if(this.is_internal(cluster)){
this.NewickFormat(cluster.right);
NHX.append(")");
}
return NHX.toString()+";";
}
}
Ads help maintain this website.