1 /* plot_phylo.c (2012-10-01) */
3 /* Copyright 2004-2012 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 */
47 for (i = 0; i < *nedge; i++) {
48 S += yy[edge2[i] - 1];
50 if (edge1[i + 1] != edge1[i]) {
51 yy[edge1[i] - 1] = S/n;
58 void node_height_clado(int *ntip, int *nnode, int *edge1, int *edge2,
59 int *nedge, double *xx, double *yy)
64 node_depth(ntip, nnode, edge1, edge2, nedge, xx);
66 /* The coordinates of the tips have been already computed */
70 for (i = 0; i < *nedge; i++) {
71 S += yy[edge2[i] - 1] * xx[edge2[i] - 1];
72 n += xx[edge2[i] - 1];
73 if (edge1[i + 1] != edge1[i]) {
74 yy[edge1[i] - 1] = S/n;