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