| 1 | /* AxMl.h */ |
|---|
| 2 | |
|---|
| 3 | #define headerName "AxMl.h" |
|---|
| 4 | #define headerVersion "1.0.0" |
|---|
| 5 | #define headerDate "February, 2002" |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | #ifndef dnaml_h |
|---|
| 9 | |
|---|
| 10 | /* Compile time switches for various updates to program: |
|---|
| 11 | * 0 gives original version |
|---|
| 12 | * 1 gives new version |
|---|
| 13 | */ |
|---|
| 14 | |
|---|
| 15 | #define ReturnSmoothedView 1 /* Propagate changes back after smooth */ |
|---|
| 16 | #define BestInsertAverage 1 /* Build three taxon tree analytically */ |
|---|
| 17 | #define DeleteCheckpointFile 0 /* Remove checkpoint file when done */ |
|---|
| 18 | |
|---|
| 19 | #define EQUALITIES 16 |
|---|
| 20 | char map[EQUALITIES]; |
|---|
| 21 | char* map2; |
|---|
| 22 | #define Debug 0 |
|---|
| 23 | |
|---|
| 24 | /* Program constants and parameters */ |
|---|
| 25 | |
|---|
| 26 | #define maxlogf 1024 /* maximum number of user trees */ |
|---|
| 27 | #define maxcategories 35 /* maximum number of site types */ |
|---|
| 28 | |
|---|
| 29 | #define smoothings 32 /* maximum smoothing passes through tree */ |
|---|
| 30 | #define iterations 10 /* maximum iterations of makenewz per insert */ |
|---|
| 31 | #define newzpercycle 1 /* iterations of makenewz per tree traversal */ |
|---|
| 32 | #define nmlngth 10 /* number of characters in species name */ |
|---|
| 33 | #define deltaz 0.00001 /* test of net branch length change in update */ |
|---|
| 34 | #define zmin 1.0E-15 /* max branch prop. to -log(zmin) (= 34) */ |
|---|
| 35 | #define zmax (1.0 - 1.0E-6) /* min branch prop. to 1.0-zmax (= 1.0E-6) */ |
|---|
| 36 | #define defaultz 0.9 /* value of z assigned as starting point */ |
|---|
| 37 | #define unlikely -1.0E300 /* low likelihood for initialization */ |
|---|
| 38 | |
|---|
| 39 | /* These values are used to rescale the lilelihoods at a given site so that |
|---|
| 40 | * there is no floating point underflow. |
|---|
| 41 | */ |
|---|
| 42 | #define twotothe256 \ |
|---|
| 43 | 115792089237316195423570985008687907853269984665640564039457584007913129639936.0 |
|---|
| 44 | /* 2**256 (exactly) */ |
|---|
| 45 | #define minlikelihood (1.0/twotothe256) /* 2**(-256) */ |
|---|
| 46 | #define log_minlikelihood (-177.445678223345993274) /* log(1.0/twotothe256) */ |
|---|
| 47 | |
|---|
| 48 | /* The next two values are used for scaling the tree that is sketched in the |
|---|
| 49 | * output file. |
|---|
| 50 | */ |
|---|
| 51 | #define down 2 |
|---|
| 52 | #define over 60 |
|---|
| 53 | |
|---|
| 54 | #define checkpointname "checkpoint" |
|---|
| 55 | |
|---|
| 56 | #define badEval 1.0 |
|---|
| 57 | #define badZ 0.0 |
|---|
| 58 | #define badRear -1 |
|---|
| 59 | #define badSigma -1.0 |
|---|
| 60 | |
|---|
| 61 | #define TRUE 1 |
|---|
| 62 | #define FALSE 0 |
|---|
| 63 | |
|---|
| 64 | #define treeNone 0 |
|---|
| 65 | #define treeNewick 1 |
|---|
| 66 | #define treeProlog 2 |
|---|
| 67 | #define treePHYLIP 3 |
|---|
| 68 | #define treeMaxType 3 |
|---|
| 69 | #define treeDefType treePHYLIP |
|---|
| 70 | |
|---|
| 71 | #define ABS(x) (((x)<0) ? (-(x)) : (x)) |
|---|
| 72 | #define MIN(x,y) (((x)<(y)) ? (x) : (y)) |
|---|
| 73 | #define MAX(x,y) (((x)>(y)) ? (x) : (y)) |
|---|
| 74 | #define LOG(x) (((x)>0) ? log(x) : hang("log domain error")) |
|---|
| 75 | #define NINT(x) ((int) ((x)>0 ? ((x)+0.5) : ((x)-0.5))) |
|---|
| 76 | |
|---|
| 77 | #if ! Vectorize |
|---|
| 78 | typedef char yType; |
|---|
| 79 | #else |
|---|
| 80 | typedef int yType; |
|---|
| 81 | #endif |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | typedef int boolean; |
|---|
| 85 | typedef double xtype; |
|---|
| 86 | |
|---|
| 87 | typedef struct likelihood_vector { |
|---|
| 88 | xtype a, c, g, t; |
|---|
| 89 | long exp; |
|---|
| 90 | } likelivector; |
|---|
| 91 | |
|---|
| 92 | typedef struct xmantyp { |
|---|
| 93 | struct xmantyp *prev; |
|---|
| 94 | struct xmantyp *next; |
|---|
| 95 | struct noderec *owner; |
|---|
| 96 | likelivector *lv; |
|---|
| 97 | } xarray; |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | int equalities = 0; |
|---|
| 102 | |
|---|
| 103 | typedef struct fgh{ |
|---|
| 104 | double a, c, g, t; |
|---|
| 105 | long exp; |
|---|
| 106 | boolean set; |
|---|
| 107 | } |
|---|
| 108 | homType; |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | typedef struct noderec { |
|---|
| 112 | double z, z0; |
|---|
| 113 | struct noderec *next; |
|---|
| 114 | struct noderec *back; |
|---|
| 115 | int number; |
|---|
| 116 | xarray *x; |
|---|
| 117 | int xcoord, ycoord, ymin, ymax; |
|---|
| 118 | char name[nmlngth+1]; /* Space for null termination */ |
|---|
| 119 | yType *tip; /* Pointer to sequence data */ |
|---|
| 120 | |
|---|
| 121 | /* AxML modification start*/ |
|---|
| 122 | |
|---|
| 123 | char *equalityVector; /* subtree equality vector for this node*/ |
|---|
| 124 | homType mlv[EQUALITIES][maxcategories]; |
|---|
| 125 | /* AxML modification end*/ |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | } node, *nodeptr; |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | typedef struct { |
|---|
| 133 | double sumaq; |
|---|
| 134 | double sumgq; |
|---|
| 135 | double sumcq; |
|---|
| 136 | double sumtq; |
|---|
| 137 | int exp; |
|---|
| 138 | } poutsa; |
|---|
| 139 | |
|---|
| 140 | typedef struct { |
|---|
| 141 | double fx1a, fx1g, fx1c, fx1t, sumag, sumct, sumagct; |
|---|
| 142 | int exp; |
|---|
| 143 | } memP; |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | typedef struct { |
|---|
| 147 | double sumfx2rfx2y, fx2r, fx2y; |
|---|
| 148 | double a, c, g, t; |
|---|
| 149 | int exp; |
|---|
| 150 | } memQ; |
|---|
| 151 | |
|---|
| 152 | typedef struct { |
|---|
| 153 | int numsp; /* number of species (also tr->mxtips) */ |
|---|
| 154 | int sites; /* number of input sequence positions */ |
|---|
| 155 | yType **y; /* sequence data array */ |
|---|
| 156 | boolean freqread; /* user base frequencies have been read */ |
|---|
| 157 | /* To do: DNA specific values should get packaged into structure */ |
|---|
| 158 | double freqa, freqc, freqg, freqt, /* base frequencies */ |
|---|
| 159 | freqr, freqy, invfreqr, invfreqy, |
|---|
| 160 | freqar, freqcy, freqgr, freqty; |
|---|
| 161 | double ttratio, xi, xv, fracchange; /* transition/transversion */ |
|---|
| 162 | /* End of DNA specific values */ |
|---|
| 163 | int *wgt; /* weight per sequence pos */ |
|---|
| 164 | int *wgt2; /* weight per pos (booted) */ |
|---|
| 165 | int categs; /* number of rate categories */ |
|---|
| 166 | double catrat[maxcategories+1]; /* rates per categories */ |
|---|
| 167 | int *sitecat; /* category per sequence pos */ |
|---|
| 168 | } rawdata; |
|---|
| 169 | |
|---|
| 170 | typedef struct { |
|---|
| 171 | int *alias; /* site representing a pattern */ |
|---|
| 172 | int *aliaswgt; /* weight by pattern */ |
|---|
| 173 | int endsite; /* # of sequence patterns */ |
|---|
| 174 | int wgtsum; /* sum of weights of positions */ |
|---|
| 175 | int *patcat; /* category per pattern */ |
|---|
| 176 | double *patrat; /* rates per pattern */ |
|---|
| 177 | double *wr; /* weighted rate per pattern */ |
|---|
| 178 | double *wr2; /* weight*rate**2 per pattern */ |
|---|
| 179 | } cruncheddata; |
|---|
| 180 | |
|---|
| 181 | typedef struct { |
|---|
| 182 | double likelihood; |
|---|
| 183 | double *log_f; /* info for signif. of trees */ |
|---|
| 184 | node **nodep; |
|---|
| 185 | node *start; |
|---|
| 186 | node *outgrnode; |
|---|
| 187 | int mxtips; |
|---|
| 188 | int ntips; |
|---|
| 189 | int nextnode; |
|---|
| 190 | int opt_level; |
|---|
| 191 | int log_f_valid; /* log_f value sites */ |
|---|
| 192 | int global; /* branches to cross in full tree */ |
|---|
| 193 | int partswap; /* branches to cross in partial tree */ |
|---|
| 194 | int outgr; /* sequence number to use in rooting tree */ |
|---|
| 195 | boolean prelabeled; /* the possible tip names are known */ |
|---|
| 196 | boolean smoothed; |
|---|
| 197 | boolean rooted; |
|---|
| 198 | boolean userlen; /* use user-supplied branch lengths */ |
|---|
| 199 | rawdata *rdta; /* raw data structure */ |
|---|
| 200 | cruncheddata *cdta; /* crunched data structure */ |
|---|
| 201 | //stmatak modif |
|---|
| 202 | int eqDepth; /*indicates up to which tree depth het. eq. vectors shall be used */ |
|---|
| 203 | //stamatk modif |
|---|
| 204 | } tree; |
|---|
| 205 | |
|---|
| 206 | typedef struct conntyp { |
|---|
| 207 | double z; /* branch length */ |
|---|
| 208 | node *p, *q; /* parent and child sectors */ |
|---|
| 209 | void *valptr; /* pointer to value of subtree */ |
|---|
| 210 | int descend; /* pointer to first connect of child */ |
|---|
| 211 | int sibling; /* next connect from same parent */ |
|---|
| 212 | } connect, *connptr; |
|---|
| 213 | |
|---|
| 214 | typedef struct { |
|---|
| 215 | double likelihood; |
|---|
| 216 | double *log_f; /* info for signif. of trees */ |
|---|
| 217 | connect *links; /* pointer to first connect (start) */ |
|---|
| 218 | node *start; |
|---|
| 219 | int nextlink; /* index of next available connect */ |
|---|
| 220 | /* tr->start = tpl->links->p */ |
|---|
| 221 | int ntips; |
|---|
| 222 | int nextnode; |
|---|
| 223 | int opt_level; /* degree of branch swapping explored */ |
|---|
| 224 | int scrNum; /* position in sorted list of scores */ |
|---|
| 225 | int tplNum; /* position in sorted list of trees */ |
|---|
| 226 | int log_f_valid; /* log_f value sites */ |
|---|
| 227 | boolean prelabeled; /* the possible tip names are known */ |
|---|
| 228 | boolean smoothed; /* branch optimization converged? */ |
|---|
| 229 | } topol; |
|---|
| 230 | |
|---|
| 231 | typedef struct { |
|---|
| 232 | double best; /* highest score saved */ |
|---|
| 233 | double worst; /* lowest score saved */ |
|---|
| 234 | topol *start; /* starting tree for optimization */ |
|---|
| 235 | topol **byScore; |
|---|
| 236 | topol **byTopol; |
|---|
| 237 | int nkeep; /* maximum topologies to save */ |
|---|
| 238 | int nvalid; /* number of topologies saved */ |
|---|
| 239 | int ninit; /* number of topologies initialized */ |
|---|
| 240 | int numtrees; /* number of alternatives tested */ |
|---|
| 241 | boolean improved; |
|---|
| 242 | } bestlist; |
|---|
| 243 | |
|---|
| 244 | typedef struct { |
|---|
| 245 | long boot; /* bootstrap random number seed */ |
|---|
| 246 | int extra; /* extra output information switch */ |
|---|
| 247 | boolean empf; /* use empirical base frequencies */ |
|---|
| 248 | boolean interleaved; /* input data are in interleaved format */ |
|---|
| 249 | long jumble; /* jumble random number seed */ |
|---|
| 250 | int nkeep; /* number of best trees to keep */ |
|---|
| 251 | int numutrees; /* number of user trees to read */ |
|---|
| 252 | boolean prdata; /* echo data to output stream */ |
|---|
| 253 | boolean qadd; /* test addition without full smoothing */ |
|---|
| 254 | boolean restart; /* resume addition to partial tree */ |
|---|
| 255 | boolean root; /* use user-supplied outgroup */ |
|---|
| 256 | boolean trprint; /* print tree to output stream */ |
|---|
| 257 | int trout; /* write tree to "treefile" */ |
|---|
| 258 | boolean usertree; /* use user-supplied trees */ |
|---|
| 259 | boolean userwgt; /* use user-supplied position weight mask */ |
|---|
| 260 | } analdef; |
|---|
| 261 | |
|---|
| 262 | typedef struct { |
|---|
| 263 | double tipmax; |
|---|
| 264 | int tipy; |
|---|
| 265 | } drawdata; |
|---|
| 266 | |
|---|
| 267 | void exit(); |
|---|
| 268 | |
|---|
| 269 | #define Malloc(x) malloc((unsigned) (x)) /* BSD */ |
|---|
| 270 | /* #define Malloc(x) malloc((size_t) (x)) */ /* System V */ |
|---|
| 271 | |
|---|
| 272 | #define Free(x) (void) free((char *) (x)) /* BSD */ |
|---|
| 273 | /* #define Free(x) free((void *) (x)) */ /* System V */ |
|---|
| 274 | |
|---|
| 275 | const char *likelihood_key = "likelihood"; |
|---|
| 276 | const char *ntaxa_key = "ntaxa"; |
|---|
| 277 | const char *opt_level_key = "opt_level"; |
|---|
| 278 | const char *smoothed_key = "smoothed"; |
|---|
| 279 | |
|---|
| 280 | #define dnaml_h |
|---|
| 281 | #endif /* #if undef dnaml_h */ |
|---|