/* Last changed Time-stamp: <95/07/12 19:52:41 ivo> */ /* Cluster Analysis using Ward's Method Ward J Amer Stat Ass, 58 (1963), p236 c Peter Stadler and Ivo Hofacker */ #include #include #include #include "utils.h" #define PUBLIC #define PRIVATE static #define INFINITY 1000000 typedef struct{ int set1; int set2; float distance; float distance2; } Union; typedef struct { int type; int weight; int father; int sons; int leftmostleaf; } Postorder_list; PUBLIC Union *wards_cluster(float **clmat); PUBLIC Union *neighbour_joining(float **clmat); PUBLIC void printf_phylogeny(Union *tree, char *type); /*--------------------------------------------------------------------*/ PUBLIC Union *wards_cluster(float **clmat) { float **d; int *indic; int *size; float *help; Union *tree; float min,deno,xa,xb,x; int i,j,step,s=0,t=0,n; n= (int)(clmat[0][0]); size = (int *) space((n+1)*sizeof(int)); d = (float **) space((n+1)*sizeof(float *)); for(i=0;i<=n;i++) d[i] = (float *) space((n+1)*sizeof(float)); indic = (int *) space((n+1)*sizeof(int)); help = (float *) space((n+1)*sizeof(float)); tree = (Union *) space((n+1)*sizeof(Union)); tree[0].set1 = n; tree[0].set2 = 0; tree[0].distance = 0.0; tree[0].distance2 = 0.0; for (i=1;i<=n;i++) size[i]=1; for (i=1; i<=n; i++){ for(j=1; j<=n; j++){ d[i][j] = clmat[i][j]; } } /* look for the indices [s,t] with minimum d[s][t]*/ for(step=1;step %d %s ( Phylogeny using ",n, type); switch(type[0]){ case 'W' : printf("Ward's Method )\n"); printf("> Nodes Variance\n"); for(i=1; i Nodes Branch Length in Tree\n"); for(i=1; i