1 /*
2 
3 PHYML :  a program that  computes maximum likelihood  phylogenies from
4 DNA or AA homologous sequences
5 
6 Copyright (C) Stephane Guindon. Oct 2003 onward
7 
8 All parts of  the source except where indicated  are distributed under
9 the GNU public licence.  See http://www.opensource.org for details.
10 
11 */
12 
13 #include <config.h>
14 
15 #ifndef LK_H
16 #define LK_H
17 
18 #include "utilities.h"
19 #include "optimiz.h"
20 #include "models.h"
21 #include "free.h"
22 #include "times.h"
23 #include "mixt.h"
24 #include "avx.h"
25 #include "sse.h"
26 
27 void Update_All_Partial_Lk(t_tree *tree);
28 void Init_Tips_At_One_Site_Nucleotides_Float(char state, int pos, phydbl *p_lk);
29 void Init_Tips_At_One_Site_AA_Float(char aa, int pos, phydbl *p_lk);
30 void Get_All_Partial_Lk(t_tree *tree,t_edge *b_fcus,t_node *a,t_node *d);
31 void Get_All_Partial_Lk_Scale(t_tree *tree,t_edge *b_fcus,t_node *a,t_node *d);
32 void Post_Order_Lk(t_node *pere, t_node *fils, t_tree *tree);
33 void Pre_Order_Lk(t_node *pere, t_node *fils, t_tree *tree);
34 phydbl Lk(t_edge *b, t_tree *tree);
35 void Site_Lk(t_tree *tree);
36 phydbl Return_Abs_Lk(t_tree *tree);
37 matrix *ML_Dist(calign *data, t_mod *mod);
38 phydbl Lk_Given_Two_Seq(calign *data, int numseq1, int numseq2, phydbl dist, t_mod *mod, phydbl *loglk);
39 void Unconstraint_Lk(t_tree *tree);
40 void Update_Partial_Lk(t_tree *tree,t_edge *b_fcus,t_node *n);
41 void Update_Partial_Lk_Generic(t_tree *tree,t_edge *b_fcus,t_node *n);
42 /* void Default_Update_Partial_Lk(t_tree *tree,t_edge *b_fcus,t_node *n); */
43 void Init_Partial_Lk_Tips_Double(t_tree *tree);
44 void Init_Partial_Lk_Tips_Int(t_tree *tree);
45 void Init_Partial_Lk_At_One_Node(t_node *a, t_tree *tree);
46 void Update_PMat_At_Given_Edge(t_edge *b_fcus, t_tree *tree);
47 void Sort_Sites_Based_On_Lk(t_tree *tree);
48 void Get_Partial_Lk_Scale(t_tree *tree, t_edge *b_fcus, t_node *a, t_node *d);
49 void Get_Partial_Lk(t_tree *tree, t_edge *b_fcus, t_node *a, t_node *d);
50 void Init_Tips_At_One_Site_Nucleotides_Int(char state, int pos, short int *p_pars);
51 void Init_Tips_At_One_Site_AA_Int(char aa, int pos, short int *p_pars);
52 void Update_Partial_Lk_Along_A_Path(t_node **path, int path_length, t_tree *tree);
53 phydbl Lk_Dist(phydbl *F, phydbl dist, t_mod *mod);
54 phydbl Update_Lk_At_Given_Edge(t_edge *b_fcus, t_tree *tree);
55 void Update_Partial_Lk_Greedy(t_tree *tree, t_edge *b_fcus, t_node *n);
56 void Get_All_Partial_Lk_Scale_Greedy(t_tree *tree, t_edge *b_fcus, t_node *a, t_node *d);
57 phydbl Lk_Triplet(t_node *a, t_node *d, t_tree *tree);
58 phydbl *Post_Prob_Rates_At_Given_Edge(t_edge *b, phydbl *post_prob, t_tree *tree);
59 phydbl Lk_With_MAP_Branch_Rates(t_tree *tree);
60 void Init_Tips_At_One_Site_Generic_Int(char *state, int ns, int state_len, int pos, short int *p_pars);
61 void Init_Tips_At_One_Site_Generic_Float(char *state, int ns, int state_len, int pos, phydbl *p_lk);
62 void Backup_Partial_Lk(t_node *d, t_edge *b, t_tree *tree);
63 void Restore_Partial_Lk(t_node *d, t_edge *b, t_tree *tree);
64 void Backup_Partial_Scale(t_node *d, t_edge *b, t_tree *tree);
65 void Restore_Partial_Scale(t_node *d, t_edge *b, t_tree *tree);
66 void Init_Partial_Lk_Loc(t_tree *tree);
67 phydbl Lk_Normal_Approx(t_tree *tree);
68 phydbl Wrap_Lk(t_edge *b, t_tree *tree, supert_tree *stree);
69 phydbl Wrap_Lk_At_Given_Edge(t_edge *b, t_tree *tree, supert_tree *stree);
70 phydbl Wrap_Part_Lk_At_Given_Edge(t_edge *b, t_tree *tree, supert_tree *stree);
71 phydbl Wrap_Part_Lk(t_edge *b, t_tree *tree, supert_tree *stree);
72 phydbl Wrap_Geo_Lk(t_edge *b, t_tree *tree, supert_tree *stree);
73 phydbl Wrap_Diff_Lk_Norm_At_Given_Edge(t_edge *b, t_tree *tree, supert_tree *stree);
74 phydbl Wrap_Lk_Rates(t_edge *b, t_tree *tree, supert_tree *stree);
75 phydbl Wrap_Lk_Linreg(t_edge *b, t_tree *tree, supert_tree *stree);
76 phydbl Wrap_Lk_Times(t_edge *b, t_tree *tree, supert_tree *stree);
77 phydbl Lk_LastFirst(t_tree *tree);
78 int Check_Lk_At_Given_Edge(int verbose, t_tree *tree);
79 void Stepwise_Add_Lk(t_tree *tree);
80 void Update_Eigen_Lr(t_edge *b, t_tree *tree);
81 phydbl dLk(phydbl *l, t_edge *b, t_tree *tree);
82 phydbl Lk_Core(int state, int ambiguity_check,phydbl *p_lk_left, phydbl *p_lk_rght,phydbl *Pij_rr,phydbl *tPij_rr,t_edge *b,t_tree *tree);
83 /* void Lk_dLk_Core_Eigen_Lr(phydbl *expl, phydbl *dot_prod, t_edge *b, phydbl *lk, phydbl *dlk, t_tree *tree); */
84 phydbl Lk_Core_Eigen_Lr(phydbl *expl, phydbl *dot_prod, t_edge *b, t_tree *tree);
85 phydbl Invariant_Lk(int fact_sum_scale, int site, int *num_prec_issue, t_tree *tree);
86 void Composite_Lk(t_tree *tree);
87 int Sample_Ancestral_Seq_Core(t_node *a, t_node *d, t_edge *b, int r_cat, int site, t_tree *tree);
88 void Default_Update_Partial_Lk(t_tree *tree, t_edge *b, t_node *d);
89 void Lk_dLk_Core_Eigen_Lr(phydbl *expl, phydbl *dot_prod, t_edge *b, phydbl *lk, phydbl *dlk, t_tree *tree);
90 void Lk_dLk_Core_One_Class_Eigen_Lr(phydbl *dot_prod, phydbl *expl, unsigned int ns, phydbl *lk, phydbl *dlk);
91 phydbl Lk_Core_One_Class_Eigen_Lr(phydbl *dot_prod, phydbl *expl, int ns);
92 void Core_Default_Update_Partial_Lk(const t_node *n_v1, const t_node *n_v2,
93                                     phydbl *plk0, const phydbl *plk1, const phydbl *plk2,
94                                     const phydbl *Pij1, const phydbl *Pij2,
95                                     int *sum_scale0, const int *sum_scale1, const int *sum_scale2,
96                                     const int ns, const int ncatg, const int npatterns, const int apply_scaling,
97                                     const phydbl *wght);
98 
99 
100 
101 
102 
103 
104 /* phydbl Lk_Core_One_Class_Eigen_Lr(phydbl *dot_prod, phydbl *expl, int ns); */
105 /* void Lk_dLk_Core_One_Class_Eigen_Lr(phydbl *dot_prod, phydbl *expl, unsigned int ns, phydbl *lk, phydbl *dlk); */
106 phydbl Lk_Core_One_Class_No_Eigen_Lr(phydbl *p_lk_left, phydbl *p_lk_rght, phydbl *Pij,phydbl *pi, int ns, int ambiguity_check, int state);
107 
108 void Pull_Scaling_Factors(int site,t_edge *b,t_tree *tree);
109 void Set_All_Partial_Lk(t_node **n_v1, t_node **n_v2,phydbl **p_lk, int **sum_scale, int **p_lk_loc,phydbl **Pij1, phydbl **tPij1, phydbl **p_lk_v1, int **sum_scale_v1,phydbl **Pij2, phydbl **tPij2, phydbl **p_lk_v2, int **sum_scale_v2,t_node *d, t_edge *b, t_tree *tree
110 #ifdef BEAGLE
111                                 , int *dest_p_idx, int *child1_p_idx, int* child2_p_idx, int* Pij1_idx, int* Pij2_idx
112 #endif
113                                 );
114 void Set_Partial_Lk_One_Side(phydbl **Pij, phydbl **tPij, phydbl **p_lk,  int **sum_scale, t_node *d, t_edge *b, t_tree *tree
115 #ifdef BEAGLE
116                                      , int* child_p_idx, int* Pij_idx
117 #endif
118                                      );
119 void Rate_Correction(int exponent, phydbl *site_lk_cat);
120 void Switch_Partial_Lk_Pre(t_node *a, t_node *d, t_edge *b, short int yesno, t_tree *tree);
121 void Switch_Partial_Lk_Post(t_node *a, t_node *d, t_edge *b, short int yesno, t_tree *tree);
122 
123 void Partial_Lk_Inin(const phydbl *Pij1, const phydbl *plk1, const phydbl *Pij2, const phydbl *plk2, const int ns, phydbl *plk0);
124 void Partial_Lk_Exex(const phydbl *Pij1, const int state1, const phydbl *Pij2, const int state2, const int ns, phydbl *plk0);
125 void Partial_Lk_Exin(const phydbl *Pij1, const int state1, const phydbl *Pij2, const phydbl *plk2, const int ns, phydbl *plk0);
126 
127 
128 #endif
129 
130 
131 
132 
133 
134 
135