]> git.donarmstrong.com Git - ape.git/blob - src/me.h
0616592f78e57d3f490d278b218f90381d8ddf77
[ape.git] / src / me.h
1 /* me.h    2008-01-14 */
2
3 /* Copyright 2007-2008 Vincent Lefort, modified by Emmanuel Paradis */
4
5 /* This file is part of the R-package `ape'. */
6 /* See the file ../COPYING for licensing issues. */
7
8 #include <R.h>
9
10 #ifndef NONE
11 #define NONE 0
12 #endif
13 #ifndef UP
14 #define UP 1
15 #endif
16 #ifndef DOWN
17 #define DOWN 2
18 #endif
19 #ifndef LEFT
20 #define LEFT 3
21 #endif
22 #ifndef RIGHT
23 #define RIGHT 4
24 #endif
25 #ifndef SKEW
26 #define SKEW 5
27 #endif
28 #ifndef MAX_LABEL_LENGTH
29 #define MAX_LABEL_LENGTH 30
30 #endif
31 #ifndef NODE_LABEL_LENGTH
32 #define NODE_LABEL_LENGTH 30
33 #endif
34 #ifndef EDGE_LABEL_LENGTH
35 #define EDGE_LABEL_LENGTH 30
36 #endif
37 #ifndef MAX_DIGITS
38 #define MAX_DIGITS 20
39 #endif
40 /* #ifndef INPUT_SIZE */
41 /* #define INPUT_SIZE 100 */
42 /* #endif */
43 #ifndef MAX_INPUT_SIZE
44 #define MAX_INPUT_SIZE 100000
45 #endif
46 #ifndef EPSILON
47 #define EPSILON 1.E-06
48 #endif
49 #ifndef ReadOpenParenthesis
50 #define ReadOpenParenthesis 0
51 #endif
52 #ifndef ReadSubTree
53 #define ReadSubTree 1
54 #endif
55 #ifndef ReadLabel
56 #define ReadLabel 2
57 #endif
58 #ifndef ReadWeight
59 #define ReadWeight 3
60 #endif
61 #ifndef AddEdge
62 #define AddEdge 4
63 #endif
64
65 #define XINDEX(i, j) n*(i - 1) - i*(i - 1)/2 + j - i - 1
66
67 typedef struct word
68 {
69   char name[MAX_LABEL_LENGTH];
70   struct word *suiv;
71 } WORD;
72
73 typedef struct pointers
74 {
75   WORD *head;
76   WORD *tail;
77 } POINTERS;
78
79 typedef struct node {
80   char label[NODE_LABEL_LENGTH];
81   struct edge *parentEdge;
82   struct edge *leftEdge;
83   struct edge *middleEdge;
84   struct edge *rightEdge;
85   int index;
86   int index2;
87 } node;
88
89 typedef struct edge {
90   char label[EDGE_LABEL_LENGTH];
91   struct node *tail; /*for edge (u,v), u is the tail, v is the head*/
92   struct node *head;
93   int bottomsize; /*number of nodes below edge */
94   int topsize;    /*number of nodes above edge */
95   double distance;
96   double totalweight;
97 } edge;
98
99 typedef struct tree {
100   char name[MAX_LABEL_LENGTH];
101   struct node *root;
102   int size;
103   double weight;
104 } tree;
105
106 typedef struct set
107 {
108   struct node *firstNode;
109   struct set *secondNode;
110 } set;
111
112 void me_b(double *X, int *N, char **labels, int *nni, int *spr, int *tbr, int *edge1, int *edge2, double *el, char **tl);
113 void me_o(double *X, int *N, char **labels, int *nni, int *edge1, int *edge2, double *el, char **tl);
114 //int whiteSpace(char c);
115 double **initDoubleMatrix(int d);
116 double **loadMatrix (double *X, char **labels, int n, set *S);
117 set *addToSet(node *v, set *X);
118 node *makeNewNode(char *label, int i);
119 node *makeNode(char *label, edge *parentEdge, int index);
120 node *copyNode(node *v);
121 edge *siblingEdge(edge *e);
122 edge *makeEdge(char *label, node *tail, node *head, double weight);
123 tree *newTree();
124 void updateSizes(edge *e, int direction);
125 tree *detrifurcate(tree *T);
126 void compareSets(tree *T, set *S);
127 void partitionSizes(tree *T);
128 edge *depthFirstTraverse(tree *T, edge *e);
129 edge *findBottomLeft(edge *e);
130 edge *moveRight(edge *e);
131 edge *topFirstTraverse(tree *T, edge *e);
132 edge *moveUpRight(edge *e);
133 void freeMatrix(double **D, int size);
134 void freeSet(set *S);
135 void freeTree(tree *T);
136 void freeSubTree(edge *e);
137 int whiteSpace(char c);
138 int leaf(node *v);
139 node *decodeNewickSubtree(char *treeString, tree *T, int *uCount);
140 tree *readNewickString (char *str, int numLeaves);
141 void subtree2phylo(node *parent, int *edge1, int *edge2, double *el, char **tl);
142 void tree2phylo(tree *T, int *edge1, int *edge2, double *el, char **tl, int n);