source: trunk/GDE/PHYLIP/phylip.h

Last change on this file was 19480, checked in by westram, 15 months ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 19.7 KB
Line 
1#ifndef _PHYLIP_H_
2#define _PHYLIP_H_
3
4/* version 3.6a3. (c) Copyright 1993-2002 by the University of Washington.
5   Written by Joseph Felsenstein, Akiko Fuseki, Sean Lamont, Andrew Keeffe,
6   Mike Palczewski, Doug Buxton and Dan Fineman.
7   Permission is granted to copy and use this program provided no fee is
8   charged for it and provided that this copyright notice is not removed. */
9
10#define VERSION "3.6a3"
11
12/* machine-specific stuff:
13   based on a number of factors in the library stdlib.h, we will try
14   to determine what kind of machine/compiler this program is being
15   built on.  However, it doesn't always succeed.  However, if you have
16   ANSI conforming C, it will probably work.
17
18   We will try to figure out machine type
19   based on defines in stdio, and compiler-defined things as well.: */
20
21#include <stdio.h>
22#include <stdlib.h>
23#ifdef WIN32
24#include <windows.h>
25
26void phyClearScreen(void);
27void phySaveConsoleAttributes(void);
28void phySetConsoleAttributes(void);
29void phyRestoreConsoleAttributes(void);
30void phyFillScreenColor(void);
31
32#endif
33#ifndef WIN32
34#include <unistd.h>   /* Contains the close(FILE *f) declaration */
35#endif
36
37#ifdef  GNUDOS
38#define DJGPP
39#define DOS
40#endif
41
42#ifdef THINK_C
43#define MAC
44#endif
45#ifdef __MWERKS__
46#ifndef WIN32
47#define MAC
48#endif
49#endif
50
51#ifdef __CMS_OPEN
52#define CMS
53#define EBCDIC true
54#define INFILE "infile data"
55#define OUTFILE "outfile data"
56#define FONTFILE "fontfile data"
57#define PLOTFILE "plotfile data"
58#define INTREE "intree data"
59#define INTREE2 "intree data 2"
60#define OUTTREE "outtree data"
61#define CATFILE "categories data"
62#define WEIGHTFILE "weights data"
63#define ANCFILE "ancestors data"
64#define MIXFILE "mixture data"
65#define FACTFILE "factors data"
66#else
67#define EBCDIC false
68#define INFILE "infile"
69#define OUTFILE "outfile"
70#define FONTFILE "fontfile" /* on unix this might be /usr/local/lib/fontfile */
71#define PLOTFILE "plotfile"
72#define INTREE "intree"
73#define INTREE2 "intree2"
74#define OUTTREE "outtree"
75#define CATFILE "categories"
76#define WEIGHTFILE "weights"
77#define ANCFILE "ancestors"
78#define MIXFILE "mixture"
79#define FACTFILE "factors"
80#endif
81
82#ifdef L_ctermid            /* try and detect for sysV or V7. */
83#define SYSTEM_FIVE
84#endif
85
86#ifdef sequent
87#define SYSTEM_FIVE
88#endif
89
90#ifndef SYSTEM_FIVE
91#include <stdlib.h>
92# if defined(_STDLIB_H_) || defined(_H_STDLIB) || defined(H_SCCSID) || defined(unix)
93# define UNIX
94# define MACHINE_TYPE "BSD Unix C"
95# endif
96#endif
97
98
99#ifdef __STDIO_LOADED
100#define VMS
101#define MACHINE_TYPE "VAX/VMS C"
102#endif
103
104#ifdef __WATCOMC__
105#define QUICKC
106#define WATCOM
107#define DOS
108#include "graph.h"
109#endif
110/* watcom-c has graphics library calls that are almost identical to    *
111 * quick-c, so the "QUICKC" symbol name stays.                         */
112
113
114#ifdef _QC
115#define MACHINE_TYPE "MS-DOS / Quick C"
116#define QUICKC
117#include "graph.h"
118#define DOS
119#endif
120
121#ifdef _DOS_MODE
122#define MACHINE_TYPE "MS-DOS /Microsoft C "
123#define DOS           /* DOS is always defined if on a DOS machine */
124#define MSC           /* MSC is defined for microsoft C              */
125#endif
126
127#ifdef __MSDOS__      /* TURBO c compiler, ONLY (no other DOS C compilers) */
128#define DOS
129#define TURBOC
130#include <stdlib.h>
131#include <graphics.h>
132#endif
133
134#ifdef DJGPP          /* DJ Delorie's original gnu  C/C++ port */
135#include <graphics.h>
136#endif
137
138#ifndef MACHINE_TYPE
139#define MACHINE_TYPE "ANSI C"
140#endif
141
142#ifdef DOS
143#define MALLOCRETURN void
144#else
145#define MALLOCRETURN void
146#endif
147#ifdef VMS
148#define signed /* signed doesn't exist in VMS */
149#endif
150
151/* default screen types */
152/*  if on a DOS but not a Windows system can use IBM PC screen controls */
153#ifdef DOS
154#ifndef WIN32
155#define IBMCRT true
156#define ANSICRT false
157#endif
158#endif
159/*  if on a Mac cannot use screen controls */
160#ifdef MAC
161#define IBMCRT false
162#define ANSICRT false
163#endif
164/*  if on a Windows system cannot use screen controls */
165#ifdef WIN32
166#define IBMCRT false
167#define ANSICRT false
168#endif
169/* otherwise, let's assume we are on a Linux or Unix system
170   with no ANSI terminal controls */
171#ifndef MAC
172#ifndef DOS
173#ifndef WIN32
174#define IBMCRT false
175#define ANSICRT false
176#endif
177#endif
178#endif
179
180#ifdef DJGPP
181#undef MALLOCRETURN
182#define MALLOCRETURN void
183#endif
184
185
186/* includes: */
187#ifdef UNIX
188#include <strings.h>
189#else
190#include <string.h>
191#endif
192
193#include <math.h>
194#include <ctype.h>
195
196#ifdef MAC
197/* debug beerli */
198#ifdef DRAW
199#include "interface.h"
200#else
201#include "macface.h"
202#endif
203#define getch gettch
204#endif
205
206/* directory delimiters */
207#ifdef MAC
208#define DELIMITER ':'
209#else
210#ifdef WIN32
211#define DELIMITER '\\'
212#else
213#define DELIMITER '/'
214#endif
215#endif
216
217
218#define FClose(file) if (file) fclose(file) ; file=NULL
219#define Malloc(x) mymalloc((long)x)
220
221typedef void *Anyptr;
222#define Signed     signed
223#define Const     const
224#define Volatile  volatile
225#define Char        char      /* Characters (not bytes) */
226#define Static     static     /* Private global funcs and vars */
227#define Local      static     /* Nested functions */
228
229typedef unsigned char boolean;
230
231#define true    1
232#define false   0
233#define SETBITS 31
234
235MALLOCRETURN    *mymalloc(long);
236
237#define FNMLNGTH        200  /* length of array to store a file name */
238#define MAXNCH          20
239#define nmlngth         10   /* number of characters in species name    */
240#define maxcategs       9    /* maximum number of site types */
241#define maxcategs2     11    /* maximum number of site types + 2 */
242#define point           "."
243#define pointe          '.'
244#define down            2
245
246#define smoothings      4    /* number of passes through smoothing algorithm */
247#define iterations      4    /* number of iterates for each branch           */
248#define epsilon         0.0001  /* small number used in makenewv */
249#define EPSILON         0.00001  /* small number used in hermite root-finding */
250#define initialv        0.1  /* starting branch length unless otherwise */
251#define over            60   /* maximum width all branches of tree on screen */
252#define SQRTPI 1.7724538509055160273
253#define SQRT2  1.4142135623730950488
254
255typedef long *steptr;
256typedef long longer[6];
257typedef char naym[MAXNCH];
258typedef long *bitptr;
259typedef double raterootarray[maxcategs2][maxcategs2];
260
261typedef struct bestelm {
262  long *btree;
263  boolean gloreange;
264  boolean locreange;
265  boolean collapse;
266} bestelm;
267
268extern FILE *infile, *outfile, *intree, *intree2, *outtree,
269    *weightfile, *catfile, *ancfile, *mixfile, *factfile;
270extern long spp, words, bits;
271extern boolean ibmpc, ansi, tranvsp;
272extern naym *nayme;                     /* names of species */
273
274
275#define ebcdic          EBCDIC
276
277typedef Char plotstring[MAXNCH];
278
279/* Approx. 1GB, used to test for memory request errors */
280#define TOO_MUCH_MEMORY 1000000000
281
282
283/* The below pre-processor commands define the type used to store
284   group arrays.  We can't use #elif for metrowerks, so we use
285   cascaded if statements */
286#include <limits.h>
287
288/* K&R says that there should be a plus in front of the number, but no
289   machine we've seen actually uses one; we'll include it just in
290   case. */
291#define MAX_32BITS        2147483647
292#define MAX_32BITS_PLUS  +2147483647
293
294/* If ints are 4 bytes, use them */
295#if INT_MAX == MAX_32BITS
296typedef int  group_type;
297
298#else 
299     #if INT_MAX == MAX_32BITS_PLUS
300     typedef int  group_type;
301
302     #else
303          /* Else, if longs are 4 bytes, use them */
304          #if LONG_MAX == MAX_32BITS
305          typedef long group_type;
306
307          #else
308               #if LONG_MAX == MAX_32BITS_PLUS
309                typedef long group_type;
310
311               /* Default to longs */
312               #else
313                    typedef long group_type;
314               #endif
315
316          #endif
317     #endif
318#endif
319
320/* for restml */
321
322#define maxcutter       8    /* maximum number of bases in a site in restml */
323
324/* for many programs */
325
326#define maxuser         1000  /* maximum number of user-defined trees    */
327
328typedef Char **sequence;
329
330typedef enum {
331  A, C, G, T, O
332} bases;
333
334typedef enum {
335  alanine, arginine, asparagine, aspartic, cysteine, 
336  glutamine, glutamic, glycine, histidine, isoleucine,
337  leucine, lysine, methionine, phenylalanine, proline,
338  serine, threonine, tryptophan, tyrosine, valine
339} acids;
340
341/* for Pars */
342
343typedef enum {
344  ZERO = 0, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN
345} discbases;
346
347/* for Protpars */
348
349typedef enum {
350  ala, arg, asn, asp, cys, gln, glu, gly, his, ileu, leu, lys, met, phe, pro,
351  ser1, ser2, thr, trp, tyr, val, del, stop, asx, glx, ser, unk, quest
352} aas;
353
354typedef double sitelike[(long)T - (long)A + 1];   /* used in dnaml, dnadist */
355typedef double psitelike[(long)valine - (long)alanine + 1];
356                             /* used in proml                                    */       
357     
358typedef long *baseptr;       /* baseptr used in dnapars, dnacomp & dnapenny */
359typedef long *baseptr2;      /* baseptr used in dnamove                     */
360typedef unsigned char *discbaseptr;         /* discbaseptr used in pars     */
361typedef sitelike *ratelike;                    /* used in dnaml ...            */
362typedef psitelike *pratelike;                    /* used in proml                    */
363typedef ratelike *phenotype;    /* phenotype used in dnaml, dnamlk, dnadist */
364typedef pratelike *pphenotype;  /* phenotype used in proml                    */ 
365typedef double sitelike2[maxcutter + 1];
366typedef sitelike2 *phenotype2;              /* phenotype2 used in restml    */
367typedef double *phenotype3;                 /* for continuous char programs */
368
369typedef double *vector;                     /* used in distance programs    */
370
371typedef long nucarray[(long)O - (long)A + 1];
372typedef long discnucarray[(long)SEVEN - (long)ZERO + 1];
373
374typedef enum { nocollap, tocollap, undefined } collapstates;
375
376typedef enum { bottom, nonbottom, hslength, tip, iter, length,
377                 hsnolength, treewt, unittrwt } initops;
378
379
380typedef double **transmatrix;
381typedef transmatrix *transptr;                /* transptr used in restml */
382
383typedef long sitearray[3];
384typedef sitearray *seqptr;                    /* seqptr used in protpars */
385
386typedef struct node {
387  struct node *next, *back;
388  plotstring nayme;
389  long naymlength, tipsabove, index;
390  double times_in_tree;            /* Previously known as cons_index */
391  double xcoord, ycoord;
392  long long_xcoord, long_ycoord;         /* for use in cons.               */
393  double oldlen, length, r, theta, oldtheta, width, depth,
394         tipdist, lefttheta, righttheta;
395  group_type *nodeset;                   /* used by accumulate      -plc   */
396  long ymin, ymax;                       /* used by printree        -plc   */
397  boolean haslength;               /* haslength used in dnamlk             */
398  boolean iter;                    /* iter used in dnaml, fitch & restml   */
399  boolean initialized;             /* initialized used in dnamlk & restml  */
400  long branchnum;                  /* branchnum used in restml             */
401  phenotype x;                     /* x used in dnaml, dnamlk, dnadist     */
402  phenotype2 x2;                   /* x2 used in restml                    */
403  phenotype3 view;                 /* contml etc                           */
404  pphenotype protx;                /* protx used in proml */ 
405  aas *seq;                  /* the sequence used in protpars              */
406  seqptr siteset;            /* temporary storage for aa's used in protpars*/
407  double v, deltav, ssq;       /* ssq used only in contrast                */
408  double bigv;                 /* bigv used in contml                      */
409  double tyme, oldtyme;        /* used in dnamlk                           */
410  double t;                    /* time in kitsch                           */
411  boolean sametime;            /* bookkeeps scrunched nodes in kitsch      */
412  double weight;               /* weight of node used by scrunch in kitsch */
413  boolean processed;           /* used by evaluate in kitsch               */
414  boolean deleted;        /* true if node is deleted (retree)              */
415  boolean hasname;        /* true if tip has a name (retree)               */
416  double beyond;          /* distance beyond this node to most distant tip */
417                            /* (retree) */
418  boolean deadend;          /* true if no undeleted nodes beyond this node */
419                            /* (retree) */
420  boolean onebranch;        /* true if there is one undeleted node beyond  */
421                            /* this node (retree)                          */
422  struct node *onebranchnode;
423                            /* if there is, a pointer to that node (retree)*/
424  double onebranchlength;   /* if there is, the distance from here to there*/
425                                /* (retree)                                */
426  boolean onebranchhaslength;   /* true if there is a valid combined length*/
427                                 /* from here to there (retree)            */
428  collapstates collapse;         /* used in dnapars & dnacomp              */
429  boolean tip;
430  boolean bottom;                /* used in dnapars & dnacomp, disc char   */
431  boolean visited;               /* used in dnapars & dnacomp  disc char   */
432  baseptr base;                  /* the sequence in dnapars/comp/penny     */
433  discbaseptr discbase;          /* the sequence in pars                   */
434  baseptr2 base2;                /* the sequence in dnamove                */
435  baseptr oldbase;               /* record previous sequence               */
436  discbaseptr olddiscbase;       /* record previous sequence               */
437  long numdesc;                  /* number of immediate descendants        */
438  nucarray *numnuc;              /* bookkeeps number of nucleotides        */
439  discnucarray *discnumnuc;      /* bookkeeps number of nucleotides        */
440  steptr numsteps;               /* bookkeeps steps                        */
441  steptr oldnumsteps;            /* record previous steps                  */
442  double sumsteps;               /* bookkeeps sum of steps                 */
443  nucarray cumlengths;           /* bookkeeps cummulative minimum lengths  */
444  discnucarray disccumlengths;   /* bookkeeps cummulative minimum lengths  */
445  nucarray numreconst;           /* bookkeeps number of  reconstructions   */
446  discnucarray discnumreconst;   /* bookkeeps number of  reconstructions   */
447  vector d, w;                   /* for distance matrix programs           */
448  double dist;                   /* dist used in fitch                     */
449  bitptr stateone, statezero;    /* discrete char programs                 */
450  long maxpos;                   /* maxpos used in Clique                  */
451  Char state;                    /* state used in Dnamove, Dolmove & Move  */
452} node;
453
454typedef node **pointarray;
455
456typedef struct tree {
457  pointarray nodep;
458  double likelihood;
459  transptr trans, transprod;       /* trans and transprod used in restml */
460  node *start;                    /* start used in dnaml & restml */
461  node *root;                     /* root used in dnamlk */
462} tree;
463
464typedef void (*initptr)(node **, node **, node *, long, long,
465                         long *, long *, initops, pointarray,
466                         pointarray, Char *, Char *, FILE *);
467
468#ifndef OLDC
469/* function prototypes */
470void   scan_eoln(FILE *);
471boolean    eoff(FILE *);
472boolean    eoln(FILE *);
473int    filexists(char *);
474const char*  get_command_name (const char *);
475void   getstryng(char *);
476void   openfile(FILE **,const char *,const char *,const char *,const char *,
477                char *);
478void   cleerhome(void);
479void   loopcount(long *, long);
480double randum(longer);
481void   randumize(longer, long *);
482double normrand(longer);
483long   readlong(const char *);
484
485void   uppercase(Char *);
486void   initseed(long *, long *, longer);
487void   initjumble(long *, long *, longer, long *);
488void   initoutgroup(long *, long);
489void   initthreshold(double *);
490void   initcatn(long *);
491void   initcategs(long, double *);
492void   initprobcat(long, double *, double *);
493double logfac (long);
494double halfroot(double (*func)(long , double), long, double, double);
495double hermite(long, double);
496void initlaguerrecat(long, double, double *, double *);
497void   root_hermite(long, double *);
498void   hermite_weight(long, double *, double *);
499void   inithermitcat(long, double, double *, double *);
500void   lgr(long, double, raterootarray);
501double glaguerre(long, double, double);
502void   initgammacat(long, double, double *, double *);
503void   inithowmany(long *, long);
504void   inithowoften(long *);
505
506void   initlambda(double *);
507void   initfreqs(double *, double *, double *, double *);
508void   initratio(double *);
509void   initpower(double *);
510void   initdatasets(long *);
511void   justweights(long *);
512void   initterminal(boolean *, boolean *);
513void   initnumlines(long *);
514void   initbestrees(bestelm *, long, boolean);
515void   newline(FILE *, long, long, long);
516
517void   inputnumbers(long *, long *, long *, long);
518void   inputnumbersold(long *, long *, long *, long);
519void   inputnumbers2(long *, long *, long n);
520void   inputnumbers3(long *, long *);
521void   samenumsp(long *, long);
522void   samenumsp2(long);
523void   readoptions(long *, const char *);
524void   matchoptions(Char *, const char *);
525void   inputweights(long, steptr, boolean *);
526void   inputweightsold(long, steptr, boolean *);
527void   inputweights2(long, long, long *, steptr, boolean *, const char *);
528void   printweights(FILE *, long, long, steptr, const char *);
529
530void   inputcategs(long, long, steptr, long, const char *);
531void   printcategs(FILE *, long, steptr, const char *);
532void   inputfactors(long, Char *, boolean *);
533void   inputfactorsnew(long, Char *, boolean *);
534void   printfactors(FILE *, long, Char *, const char *);
535void   headings(long, const char *, const char *);
536void   initname(long);
537void   findtree(boolean *,long *,long,long *,bestelm *);
538void   addtree(long,long *,boolean,long *,bestelm *);
539long   findunrearranged(bestelm *, long, boolean);
540boolean torearrange(bestelm *, long);
541
542void   reducebestrees(bestelm *, long *);
543void   shellsort(double *, long *, long);
544void   getch(Char *, long *, FILE *);
545void   getch2(Char *, long *);
546void   findch(Char, Char *, long);
547void   findch2(Char, long *, long *, Char *);
548void   findch3(Char, Char *, long, long);
549void   processlength(double *,double *,Char *,boolean *,FILE *,long *);
550void   writename(long, long, long *);
551void   memerror(void);
552
553void   odd_malloc(long);
554
555void   gnu(node **, node **);
556void   chuck(node **, node *);
557void   zeronumnuc(node *, long);
558void   zerodiscnumnuc(node *, long);
559void   allocnontip(node *, long *, long);
560void   allocdiscnontip(node *, long *, unsigned char *, long );
561void   allocnode(node **, long *, long);
562void   allocdiscnode(node **, long *, unsigned char *, long );
563void   gnutreenode(node **, node **, long, long, long *);
564void   gnudisctreenode(node **, node **, long , long, long *,
565                unsigned char *);
566
567void   chucktreenode(node **, node *);
568void   setupnode(node *, long);
569long   count_sibs (node *);
570void   inittrav (node *);
571void   commentskipper(FILE ***, long *);
572long   countcomma(FILE **, long *);
573long   countsemic(FILE **);
574void   hookup(node *, node *);
575void   link_trees(long, long , long, pointarray);
576void   allocate_nodep(pointarray *, FILE **, long  *);
577 
578void   malloc_pheno(node *, long, long);
579void   malloc_ppheno(node *, long, long);
580long   take_name_from_tree (Char *, Char *, FILE *);
581void   match_names_to_data (Char *, pointarray, node **, long);
582void   addelement(node **, node *, Char *, long *, FILE *, pointarray,
583                boolean *, boolean *, pointarray, long *, long *, boolean *,
584                node **, initptr);
585void   treeread (FILE *, node **, pointarray, boolean *, boolean *,
586                pointarray, long *, boolean *, node **, initptr);
587void   addelement2(node *, Char *, long *, FILE *, pointarray, boolean,
588                double *, boolean *, long *, long *, long, boolean *);
589void   treeread2 (FILE *, node **, pointarray, boolean, double *,
590                boolean *, boolean *, long *);
591void   exxit (int);
592void countup(long *loopcount, long maxcount);
593char gettc(FILE* file);
594void init(int argc, char** argv);
595#endif /* OLDC */
596#endif /* _PHYLIP_H_ */
Note: See TracBrowser for help on using the repository browser.