1 /* plot_phylo.c (2006-10-13) */
3 /* Copyright 2004-2006 Emmanuel Paradis
5 /* This file is part of the R-package `ape'. */
6 /* See the file ../COPYING for licensing issues. */
10 void node_depth_edgelength(int *ntip, int *nnode, int *edge1, int *edge2,
11 int *nedge, double *edge_length, double *xx)
15 /* We do a preorder tree traversal starting from the bottom */
16 /* of `edge'; we assume `xx' has 0 for the root and the tree */
17 /* is in pruningwise order. */
18 for (i = *nedge - 1; i >= 0; i--)
19 xx[edge2[i] - 1] = xx[edge1[i] - 1] + edge_length[i];
22 void node_depth(int *ntip, int *nnode, int *edge1, int *edge2,
23 int *nedge, double *xx)
27 /* First set the coordinates for all tips */
28 for (i = 0; i < *ntip; i++) xx[i] = 1;
30 /* Then compute recursively for the nodes; we assume `xx' has */
31 /* been initialized with 0's which is true if it has been */
32 /* created in R (the tree must be in pruningwise order) */
33 for (i = 0; i < *nedge; i++)
34 xx[edge1[i] - 1] = xx[edge1[i] - 1] + xx[edge2[i] - 1];
37 void node_height(int *ntip, int *nnode, int *edge1, int *edge2,
38 int *nedge, double *yy)
43 /* The coordinates of the tips have been already computed */
48 for (i = 0; i < *nedge; i++) {
49 S += yy[edge2[i] - 1];
51 if (edge1[i + 1] != edge1[i]) {
52 yy[edge1[i] - 1] = S/n;
59 void node_height_clado(int *ntip, int *nnode, int *edge1, int *edge2,
60 int *nedge, double *xx, double *yy)
65 node_depth(ntip, nnode, edge1, edge2, nedge, xx);
67 /* The coordinates of the tips have been already computed */
72 for (i = 0; i < *nedge; i++) {
73 S += yy[edge2[i] - 1] * xx[edge2[i] - 1];
74 n += xx[edge2[i] - 1];
75 if (edge1[i + 1] != edge1[i]) {
76 yy[edge1[i] - 1] = S/n;