JWS-112 Bumping version of T-Coffee to version 11.00.8cbe486.
[jabaws.git] / binaries / src / tcoffee / t_coffee_source / dp_lib / fsa_dp.h
1 /******************************COPYRIGHT NOTICE*******************************/
2 /*  (c) Centro de Regulacio Genomica                                                        */
3 /*  and                                                                                     */
4 /*  Cedric Notredame                                                                        */
5 /*  12 Aug 2014 - 22:07.                                                                    */
6 /*All rights reserved.                                                                      */
7 /*This file is part of T-COFFEE.                                                            */
8 /*                                                                                          */
9 /*    T-COFFEE is free software; you can redistribute it and/or modify                      */
10 /*    it under the terms of the GNU General Public License as published by                  */
11 /*    the Free Software Foundation; either version 2 of the License, or                     */
12 /*    (at your option) any later version.                                                   */
13 /*                                                                                          */
14 /*    T-COFFEE is distributed in the hope that it will be useful,                           */
15 /*    but WITHOUT ANY WARRANTY; without even the implied warranty of                        */
16 /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                         */
17 /*    GNU General Public License for more details.                                          */
18 /*                                                                                          */
19 /*    You should have received a copy of the GNU General Public License                     */
20 /*    along with Foobar; if not, write to the Free Software                                 */
21 /*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA             */
22 /*...............................................                                           */
23 /*  If you need some more information                                                       */
24 /*  cedric.notredame@europe.com                                                             */
25 /*...............................................                                           */
26 /******************************COPYRIGHT NOTICE*******************************/
27 #ifndef FSA_DP_H
28 #define FSA_DP_H
29
30 /*By convention, 0: START, 1: END*/
31
32 struct Hmm
33 {
34   
35   double freeT;           /*Free transition*/
36   double forbiden;        /*Forbiden transition*/
37   int start;              /*start, by convention: 0*/
38   int end;                /*end, by convention: 1*/
39
40   int nS;                 /*Number of states*/
41   int order;
42   struct HmmState  **S;   /*State List*/
43
44   /*Bounded HMM*/
45   double **T;             /*Transition matrix*/
46   int **fromM;            /*For any sate s, fromM[0]->number of states leading to s*/
47   int **toM;              /*For any sate s, toM[0]->number of s can go to*/
48                           /*End and Start are NOT included in toM and FromM*/
49   
50   
51 };
52 typedef struct Hmm Hmm;
53
54 struct HmmAln
55 {
56   Hmm *H;
57   int *state_list;
58 };
59 typedef struct HmmAln HmmAln;
60
61 typedef double (*Generic_em_func)(struct Hmm*, struct HmmState*, int);
62
63 struct HmmState
64 {
65 char name[100];
66 int state;
67 int DJ;
68 int DI;
69
70   /*Pair HMM*/
71 double em;
72 Col_cost_func em_func;
73
74   /*Linear HMM*/
75 double *em2;
76 Generic_em_func em_func2;
77 int nT;
78 struct StateTrans **T;
79 };
80 typedef struct HmmState HmmState;
81
82 struct StateTrans
83 {
84   char name[101];
85   double tr;
86 };
87 typedef struct StateTrans StateTrans;
88
89 struct MatState
90 {
91   int i;
92   int j;
93   int st;
94   int pst;
95   double sc;
96   struct MatState *n;
97   struct MatState *p;
98   struct MatState *m; /*memory*/
99   struct MatState *s; /*memory of the start point*/
100   /*Heap Mamagement: Never copy*/
101   struct MatState *Hn;/*Heap Next*/ 
102   struct MatState *Hp;/*Heap Previous*/ 
103   
104   struct MatState *Mn;/*Marked Heap section*/ 
105   struct MatState *Mp;/*Marked Heap Section*/ 
106   int free;
107 };
108 typedef struct MatState MatState;
109
110
111 /*********************************************************************************/
112 /*                                                                               */
113 /*                                                                               */
114 /*                     simple HMM: Viterbi                                       */
115 /*                                                                               */
116 /*                                                                               */
117 /*********************************************************************************/
118 int seq_viterbi_pair_wise (Alignment *A,int*ns, int **ls,Constraint_list *CL);
119
120 /*********************************************************************************/
121 /*                                                                               */
122 /*                                                                               */
123 /*                     HMM: Viterbi                                              */
124 /*                                                                               */
125 /*                                                                               */
126 /*********************************************************************************/
127
128 int viterbi_pair_wise_OLD (Alignment *A,int*ns, int **ls,Constraint_list *CL);
129 Alignment * viterbipath2aln (Alignment *A, int *ns,int **ls,int *tb, Hmm *H);
130 double*** viterbi_hmm (Alignment *A,int *ns, int **ls, Hmm *H, Constraint_list *CL);
131 int * viterbi2path (int l1,int l2, Hmm *H, double ***M);
132 /*********************************************************************************/
133 /*                                                                               */
134 /*                                                                               */
135 /*                      HMM modeling                                             */
136 /*                                                                               */
137 /*                                                                               */
138 /*********************************************************************************/
139 int viterbiL_pair_wise (Alignment *A,int*ns, int **ls,Constraint_list *CL);
140 MatState* RviterbiL_hmm (Alignment *A,int *ns, int **ls, Hmm *H, Constraint_list *CL,MatState *S, MatState *E);
141 MatState* viterbiL_hmm (Alignment *A,int *ns, int **ls, Hmm *H, Constraint_list *CL, MatState *S, MatState *E);
142
143 int viterbiD_pair_wise (Alignment *A,int*ns, int **ls,Constraint_list *CL);
144 double lu_RviterbiD_hmm (Alignment *A,int *ns, int **ls, Hmm *H, Constraint_list *CL,MatState *S, MatState *E, int **seg_list);
145 MatState* RviterbiD_hmm (Alignment *A,int *ns, int **ls, Hmm *H, Constraint_list *CL,MatState *S, MatState *E, int **seg_list);
146 MatState* viterbiD_hmm (Alignment *A,int *ns, int **ls, Hmm *H, Constraint_list *CL, MatState *S, MatState *E, int **seg_list);
147 int **seglist2table ( int **seglist,int l1, int l2);
148 int *seglist2line ( int **seglist, int line, int start, int end);
149 int * traceback (Alignment *A,int *ns, int **ls, Hmm *H, Constraint_list *CL,MatState *S, MatState *E, int **seg_list);
150
151 int viterbiDGL_pair_wise (Alignment *A,int*ns, int **ls,Constraint_list *CL);
152 double lu_RviterbiDGL_hmm (Alignment *A,int *ns, int **ls, Hmm *H, Constraint_list *CL,MatState *S, MatState *E, int **seg_list);
153 MatState* RviterbiDGL_hmm (Alignment *A,int *ns, int **ls, Hmm *H, Constraint_list *CL,MatState *S, MatState *E, int **seg_list);
154 MatState* viterbiDGL_hmm (Alignment *A,int *ns, int **ls, Hmm *H, Constraint_list *CL,MatState *S, MatState *E, int **seg_list);
155
156
157 /*********************************************************************************/
158 /*                                                                               */
159 /*                                                                               */
160 /*                      HMM modeling                                             */
161 /*                                                                               */
162 /*                                                                               */
163 /*********************************************************************************/
164 int MatStateAreIdentical (MatState*I, MatState*O);
165 int MaxDeltaMatState (MatState*I, MatState*O);
166 int MinDeltaMatState (MatState*I, MatState*O);
167
168 MatState * ManageMatState(int Mode, MatState *C);
169 MatState* CopyMatState ( MatState*I, MatState*O);
170
171 Hmm* read_hmm(char *file);
172 Hmm* declare_hmm(int n);
173 Hmm* free_Hmm(Hmm*H);
174 void DisplayHmm ( Hmm *H);
175
176 /*********************************************************************************/
177 /*                                                                               */
178 /*                                                                               */
179 /*                      HMM Models                                               */
180 /*                                                                               */
181 /*                                                                               */
182 /*********************************************************************************/
183 Hmm* define_two_mat_model(Constraint_list *CL);
184 Hmm* define_probcons_model(Constraint_list *CL);
185 Hmm* define_simple_model(Constraint_list *CL);
186
187 Hmm * bound_hmm ( Hmm *H);
188
189 #endif // FSA_DP_H