MorphyLib
Phylogenetic data reconstruction library accommodating inapplicable data
morphydefs.h
1 //
2 // morphydefs.h
3 // MorPhy2
4 //
5 // Created by mbrazeau on 07/05/2017.
6 // Copyright © 2017 brazeaulab. All rights reserved.
7 //
8 
9 #ifndef morphydefs_h
10 #define morphydefs_h
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 #include <stdint.h>
17 #include <stdbool.h>
18 #ifdef MPLDBL
19 typedef double Mflt;
20 #elif MPLLDBL
21 typedef long double Mflt;
22 #else
23 typedef float Mflt;
24 #endif
25 
26 typedef unsigned int MPLstate;
27 
28 #define NA ((MPLstate)1)
29 #define MISSING ((MPLstate)~0)
30 #define ISAPPLIC (((MPLstate)~0)^NA)
31 #define MAXSTATES (CHAR_BIT * sizeof(MPLstate))
32 #define DEFAULTGAP '-'
33 #define DEFAULTMISSING '?'
34 #define DEFAULCHARTYPE FITCH_T
35 #define NACUTOFF 2 // The max number of NA tokens that can be ignored
36  // in a column
37 #define MPLCHARMAX INT_MAX
38 
39 typedef struct MPLndsets MPLndsets;
40 typedef struct partition_s MPLpartition;
41 // Evaluator function pointers
42 typedef int (*MPLdownfxn)
43  (MPLndsets* lset,
44  MPLndsets* rset,
45  MPLndsets* nset,
46  MPLpartition* part);
47 
48 typedef int (*MPLupfxn)
49  (MPLndsets* lset,
50  MPLndsets* rset,
51  MPLndsets* nset,
52  MPLndsets* ancset,
53  MPLpartition* part);
54 
55 typedef int (*MPLtipfxn)
56  (MPLndsets* tset,
57  MPLndsets* ancset,
58  MPLpartition* part);
59 
60 // Key data types
61 typedef enum {
62 
63  NONE_T = 0,
64  FITCH_T = 1,
65  WAGNER_T = 2,
66  DOLLO_T = 3,
67  IRREVERSIBLE_T = 4,
68  USERTYPE_T = 5,
69 
70  MAX_CTYPE,
71 
72 } MPLchtype;
73 
74 typedef enum {
75 
76  GAP_INAPPLIC,
77  GAP_MISSING,
78  GAP_NEWSTATE,
79 
80  GAP_MAX,
81 
82 } gap_t;
83 
84 typedef struct {
85  MPLstate asint;
86  char* asstr;
87 } MPLcell;
88 
89 
90 typedef struct charinfo_s MPLcharinfo;
91 typedef struct charinfo_s {
92 
93  int charindex;
94  int ninapplics;
95  bool included;
96  MPLchtype chtype;
97  union {
98  int intwt;
99  Mflt fltwt;
100  };
101  Mflt CIndex;
102  Mflt RCIndex;
103  Mflt HIndex;
104  Mflt RetIndex;
105 
106 } MPLcharinfo;
107 
108 
109 typedef struct partition_s MPLpartition;
110 typedef struct partition_s {
111 
112  MPLchtype chtype;
113  bool isNAtype;
114  int maxnchars;
115  int ncharsinpart;
116  int* charindices;
117  MPLtipfxn tipupdate;
118  MPLtipfxn tipfinalize;
119  MPLdownfxn inappdownfxn;
120  MPLupfxn inappupfxn;
121  MPLdownfxn prelimfxn;
122  MPLupfxn finalfxn;
123  MPLpartition* next;
124 
125 } MPLpartition;
126 
127 
128 
129 typedef struct MPLndsets {
130 
131  MPLstate* downpass1;
132  MPLstate* uppass1;
133  MPLstate* downpass2;
134  MPLstate* uppass2;
135  MPLstate* subtree_actives;
136  MPLstate* subtree_downpass1;
137  MPLstate* subtree_uppass1;
138  MPLstate* subtree_downpass2;
139  MPLstate* subtree_uppass2;
140 
141 } MPLndsets;
142 
143 typedef struct mpl_matrix_s {
144  int ncells;
145  MPLcell* cells;
146 } MPLmatrix;
147 
148 //typedef struct {
149 // int* tips;
150 // int* internals;
151 // MPLndsets** ancstates;
152 //} MPLnodesets;
153 
154 typedef struct symbols_s {
155  int numstates;
156  char* statesymbols;
157  char* symbolsinmatrix;
158  MPLstate* packed;
159  char gap;
160  char missing;
161 } MPLsymbols;
162 
163 
165 typedef struct Morphy_t {
166 
167  int numtaxa; // The number of terminal taxa
168  int numcharacters; // The number of characters (transformation series)
169  MPLcharinfo* charinfo; // Data type information about each character
170  int numparts; // The number of data type partitions
171  MPLpartition* partstack; // A place for unused partitions
172  MPLpartition** partitions; // The array of partitions
173  MPLsymbols symbols; // The symbols used in the dataset
174  gap_t gaphandl; // The method of gap treatment
175  union {
176  int asint;
177  Mflt asfloat;
178  } score; // The score (parsimony, likelihood etc.) of the evaluated data
179  MPLmatrix inmatrix; // Internal representation of the matrix
180  char* char_t_matrix; // The matrix as a NULL-terminated string
181  int numnodes; // The number of nodes
182  int* nodesequence; // The postorder sequence of nodes.
183  int nthreads; // For programs that wish to multithread
184  MPLndsets** statesets;
185 
186 } Morphy_t, *Morphyp;
187 
188 typedef void* Morphy;
189 
190 #ifdef __cplusplus
191 }
192 #endif
193 
194 #endif /* morphydefs_h */
Definition: morphydefs.h:91
Definition: morphydefs.h:143
Definition: morphydefs.h:129
Definition: morphydefs.h:84
Definition: morphydefs.h:154
Definition: morphydefs.h:110
Definition: morphydefs.h:165