Functions that deal (mostly) with conditional likelihood (re)computation. More...
Functions  
union  __attribute__ ((aligned(PLL_BYTE_ALIGNMENT))) 
void  pllNewviewIterative (pllInstance *tr, partitionList *pr, int startIndex) 
Compute the conditional likelihood for each entry (node) of the traversal descriptor. More...  
void  computeTraversal (pllInstance *tr, nodeptr p, boolean partialTraversal, int numBranches) 
Compute the traversal descriptor of the subtree rooted at p. More...  
void  pllNewviewGeneric (pllInstance *tr, partitionList *pr, nodeptr p, boolean masked) 
Computes the conditional likelihood vectors of all nodes in the subtree rooted at p. More...  
void  newviewAncestralIterative (pllInstance *tr, partitionList *pr) 
A very simple iterative function, we only access the conditional likelihood vector at node p. More...  
void  pllNewviewGenericAncestral (pllInstance *tr, partitionList *pr, nodeptr p) 
Computes the conditional likelihood vectors of all nodes in the subtree rooted at p and the marginal ancestral probabilities at node p. More...  
void  printAncestralState (nodeptr p, boolean printStates, boolean printProbs, pllInstance *tr, partitionList *pr) 
Prints the ancestral state information for a node p to the terminal. More...  
boolean  isGap (unsigned int *x, int pos) 
Check whether the position pos in bitvector x is a gap. More...  
boolean  noGap (unsigned int *x, int pos) 
Check whether the position pos in bitvector x is NOT a gap. More...  
Static functions  
static void  computeTraversalInfo (nodeptr p, traversalInfo *ti, int *counter, int maxTips, int numBranches, boolean partialTraversal, recompVectors *rvec, boolean useRecom) 
Compute a partial or full traversal descriptor for a subtree of the topology. More...  
static void  makeP (double z1, double z2, double *rptr, double *EI, double *EIGN, int numberOfCategories, double *left, double *right, boolean saveMem, int maxCat, const int states) 
Computes two P matrices for two edges. More...  
static void  newviewGTRGAMMAPROT_LG4 (int tipCase, double *x1, double *x2, double *x3, double *extEV[4], double *tipVector[4], int *ex3, unsigned char *tipX1, unsigned char *tipX2, int n, double *left, double *right, int *wgt, int *scalerIncrement, const boolean useFastScaling) 
Computation of conditional likelihood arrray for the GTR GAMMA and for the LG4 model (Optimized SSE3 version for AA data) More...  
static void  newviewGTRGAMMA_GAPPED_SAVE (int tipCase, double *x1_start, double *x2_start, double *x3_start, double *EV, double *tipVector, int *ex3, unsigned char *tipX1, unsigned char *tipX2, const int n, double *left, double *right, int *wgt, int *scalerIncrement, const boolean fastScaling, unsigned int *x1_gap, unsigned int *x2_gap, unsigned int *x3_gap, double *x1_gapColumn, double *x2_gapColumn, double *x3_gapColumn) 
Computation of conditional likelihood arrray for GTR GAMMA with memory saving (Optimized SSE3 version for DNA data) More...  
static void  newviewGTRGAMMA (int tipCase, double *x1_start, double *x2_start, double *x3_start, double *EV, double *tipVector, int *ex3, unsigned char *tipX1, unsigned char *tipX2, const int n, double *left, double *right, int *wgt, int *scalerIncrement, const boolean fastScaling) 
Computation of conditional likelihood arrray for GTR GAMMA (Optimized SSE3 version for DNA data) More...  
static void  newviewGTRCAT (int tipCase, double *EV, int *cptr, double *x1_start, double *x2_start, double *x3_start, double *tipVector, int *ex3, unsigned char *tipX1, unsigned char *tipX2, int n, double *left, double *right, int *wgt, int *scalerIncrement, const boolean fastScaling) 
Computation of conditional likelihood arrray for GTR CAT (Optimized SSE3 version for DNA data) More...  
static void  newviewGTRCAT_SAVE (int tipCase, double *EV, int *cptr, double *x1_start, double *x2_start, double *x3_start, double *tipVector, int *ex3, unsigned char *tipX1, unsigned char *tipX2, int n, double *left, double *right, int *wgt, int *scalerIncrement, const boolean fastScaling, unsigned int *x1_gap, unsigned int *x2_gap, unsigned int *x3_gap, double *x1_gapColumn, double *x2_gapColumn, double *x3_gapColumn, const int maxCats) 
Computation of conditional likelihood arrray for GTR CAT with memory saving (Optimized SSE3 version for DNA data) More...  
static void  newviewGTRGAMMAPROT_GAPPED_SAVE (int tipCase, double *x1, double *x2, double *x3, double *extEV, double *tipVector, int *ex3, unsigned char *tipX1, unsigned char *tipX2, int n, double *left, double *right, int *wgt, int *scalerIncrement, const boolean fastScaling, unsigned int *x1_gap, unsigned int *x2_gap, unsigned int *x3_gap, double *x1_gapColumn, double *x2_gapColumn, double *x3_gapColumn) 
Computation of conditional likelihood arrray for GTR GAMMA with memory saving (Optimized SSE3 version for AA data) More...  
static void  newviewGTRGAMMAPROT (int tipCase, double *x1, double *x2, double *x3, double *extEV, double *tipVector, int *ex3, unsigned char *tipX1, unsigned char *tipX2, int n, double *left, double *right, int *wgt, int *scalerIncrement, const boolean fastScaling) 
Computation of conditional likelihood arrray for GTR GAMMA (Optimized SSE3 version for AA data) More...  
static void  newviewGTRCATPROT (int tipCase, double *extEV, int *cptr, double *x1, double *x2, double *x3, double *tipVector, int *ex3, unsigned char *tipX1, unsigned char *tipX2, int n, double *left, double *right, int *wgt, int *scalerIncrement, const boolean fastScaling) 
Computation of conditional likelihood arrray for GTR CAT (Optimized SSE3 version for AA data) More...  
static void  newviewGTRCATPROT_SAVE (int tipCase, double *extEV, int *cptr, double *x1, double *x2, double *x3, double *tipVector, int *ex3, unsigned char *tipX1, unsigned char *tipX2, int n, double *left, double *right, int *wgt, int *scalerIncrement, const boolean fastScaling, unsigned int *x1_gap, unsigned int *x2_gap, unsigned int *x3_gap, double *x1_gapColumn, double *x2_gapColumn, double *x3_gapColumn, const int maxCats) 
Computation of conditional likelihood arrray for GTR CAT with memory saving (Optimized SSE3 version for AA data) More...  
static void  makeP_FlexLG4 (double z1, double z2, double *rptr, double *EI[4], double *EIGN[4], int numberOfCategories, double *left, double *right, const int numStates) 
Compute two P matrices for two edges for the LG4 model. More...  
static void  newviewCAT_FLEX (int tipCase, double *extEV, int *cptr, double *x1, double *x2, double *x3, double *tipVector, int *ex3, unsigned char *tipX1, unsigned char *tipX2, int n, double *left, double *right, int *wgt, int *scalerIncrement, const boolean fastScaling, const int states) 
Computation of conditional likelihood arrays for CAT. More...  
static void  newviewGAMMA_FLEX (int tipCase, double *x1, double *x2, double *x3, double *extEV, double *tipVector, int *ex3, unsigned char *tipX1, unsigned char *tipX2, int n, double *left, double *right, int *wgt, int *scalerIncrement, const boolean fastScaling, const int states, const int maxStateValue) 
Computation of conditional likelihood arrays for GAMMA. More...  
static void  ancestralCat (double *x3, double *ancestralBuffer, double *diagptable, const int n, const int numStates, int *cptr) 
Compute the marginal ancestral probability vector for CAT/PSR model. More...  
static void  ancestralGamma (double *x3, double *ancestralBuffer, double *diagptable, const int n, const int numStates, const int gammaStates) 
Compute the marginal ancestral probability vector for GAMMA model. More...  
static void  calc_diagp_Ancestral (double *rptr, double *EI, double *EIGN, int numberOfCategories, double *left, const int numStates) 
Compute a dedicated zero branch length P matrix. More...  
static char  getStateCharacter (int dataType, int state) 
Get the character representation of an enumerated DNA or AA state. More...  
Variables  
absMask = {{0x7fffffffffffffffULL , 0x7fffffffffffffffULL }}  
const char  dnaStateNames [4] 
Array that contains letters for the four DNA basepairs, i.e. 0 = A, 1 = C, 2 = G, 3 = T.  
const char  protStateNames [20] 
Array that contains letters for the 20 AA basepairs.  
const unsigned int  mask32 [32] 
Array that contains the first 32 powers of 2, i.e. 2^0 upto 2^31. More...  
Functions that deal (mostly) with conditional likelihood (re)computation.

static 
Compute the marginal ancestral probability vector for CAT/PSR model.
Computes the marginal ancestral probability vector for CAT/PSR model, given the conditional likelihood vector x3 of some node, and a zero branch length P matrix diagptable.
x3  Conditional likelihood of the node for which we are computing the ancestral vector 
ancestralBuffer  Buffer where to store the marginal ancestral probability vector 
diagptable  A zero branch length P matrix 
n  Number of sites in the partition to process (in the case of MPI/PTHREADS, the number of sites in the partition assigned to the current thread/process) 
numStates  Number of states 
cptr  Array where the rate for each site in the compressed partition alignment is stored 

static 
Compute the marginal ancestral probability vector for GAMMA model.
Computes the marginal ancestral probability vector for the GAMMA model, given the conditional likelihood vector x3 of some node, and a zero branch length P matrix diagptable.
x3  Conditional likelihood of the node for which we are computing the ancestral vector 
ancestralBuffer  Buffer where to store the marginal ancestral probability vector 
diagptable  A zero branch length P matrix 
n  Number of sites in the partition to process (in the case of MPI/PTHREADS, the number of sites in the partition assigned to the current thread/process) 
numStates  Number of states 
gammaStates  Number of GAMMA categories times number of states 

static 
Compute a dedicated zero branch length P matrix.
Computes a P matrix by assuming a branch length of zero. This is used for the marginal ancestral probabilities recomputation.
rptr  Array of values for rate categories 
EI  Inverse eigenvector of Q matrix 
EIGN  Eigenvalues of Q matrix 
numberOfCategories  Number of rate categories 
left  Where to store the resulting P matrix 
numStates  Number of states 
void computeTraversal  (  pllInstance *  tr, 
nodeptr  p,  
boolean  partialTraversal,  
int  numBranches  
) 
Compute the traversal descriptor of the subtree rooted at p.
Computes the traversal descriptor of the subtree with root p. By traversal descriptory we essentially mean a preorder traversal of the unrooted topology by rooting it at a node p. If partialTraversal is set to PLL_TRUE then subtrees which are oriented correctly (i.e. if root node r of a subtree has r>x == 1) are not included in the traversal descriptor.
tr  PLL instance 
p  Node assumed to be the root 
partialTraversal  If set to PLL_TRUE, then a partial traversal descriptor is computed. 
numBranches  Number of branches (either perpartition branch or joint branch estimate) 

static 
Compute a partial or full traversal descriptor for a subtree of the topology.
Unless the partialTraversal is set to PLL_TRUE, compute a partial traversal descriptor down to the point/node in the tree where the conditional likelihood vector representing a subtree is already oriented in the correct direction. The elements of the traversal descriptor are stored in ti and a counter keeps track of the number of elements.
p  Root of the subtree for which we want to compute the traversal descriptor. The two descendents are p>next>back and p>next>next>back 
ti  i Traversal descriptor element structure 
counter  Number of elements in the traversal descriptor. Updated when an element is added 
maxTips  Number of tips in the tree structure 
numBranches  Number of branches 
partialTraversal  If PLL_TRUE, a partial traversal descriptor is computed, otherwise a full 
rvec  Parameter concerning ancestral state recomputation. Please document 
useRecom  If PLL_TRUE, then ancestral state recomputation is enabled. 

static 
Get the character representation of an enumerated DNA or AA state.
Returns the character representation of the enumarates DNA or AA state, from the constant arrays dnaStateNames (for DNA) or protStateNames (for proteins).
dataType  Type of data, i.e. PLL_DNA_DATA or PLL_AA_DATA 
state  The number which we want to decode to a letter 

inline 
Check whether the position pos in bitvector x is a gap.
x  A bitvector represented by unsigned integers 
pos  Position to check in x if it is set (i.e. it is a gap) 

static 
Computes two P matrices for two edges.
Generic function for computing the P matrices of two nodes based on their edges. This is used to (later) compute the the conditional likelihood at a node p which has two descendants q and , which in turn have the edges z1 and z2 that connect them with p. Given those edges, we compute two P matrices P(z1) and P(z2) which are stored in the arrays left and right.
The following value is computed here:
to fill up the P matrix.
z1  Branch length leading to left descendant node (let's call it q) 
z2  Branch length leading to right descendant node (let's call it r) 
rptr  Array of values for rate categories 
EI  Inverse eigenvectors of Qmatrix 
EIGN  Eigenvalues of Qmatrix 
numberOfCategories  How many rate heterogeneity categories we have, depending on GAMMA and CAT 
left  Where to store the left P matrix (for node q) 
right  Where to store the right P matrix (for node r) 
saveMem  If set to PLL_TRUE, memory saving technique is enabled 
maxCat  Maximum number of rate categories 
states  Number of states for the particular data (4 for DNA or 20 for AA) 

static 
Compute two P matrices for two edges for the LG4 model.
Computing the P matrices of two nodes based on their edges for the LG4 model. This is used to (later) compute the the conditional likelihood at a node p which has two descendants q and , which in turn have the edges z1 and z2 that connect them with p. Given those edges, we compute two P matrices P(z1) and P(z2) which are stored in the arrays left and right.
z1  Branch length leading to left descendant node (let's call it q) 
z2  Branch length leading to right descendant node (let's call it r) 
rptr  Array of values for rate categories 
EI  Inverse eigenvectors of 4 Qmatrices 
EIGN  Eigenvalues of 4 Qmatrix 
numberOfCategories  How many rate heterogeneity categories we have, depending on GAMMA and CAT 
left  Where to store the left P matrix (for node q) 
right  Where to store the right P matrix (for node r) 
numStates  Number of states for the particular data (4 for DNA or 20 for AA) 
void newviewAncestralIterative  (  pllInstance *  tr, 
partitionList *  pr  
) 
A very simple iterative function, we only access the conditional likelihood vector at node p.

static 
Computation of conditional likelihood arrays for CAT.
This is a generic, slow but readable function implementation for computing the conditional likelihood arrays at p, given child nodes q and r using the CAT mode of rate heterogeneity. Depending whether q, resp. , are tips or internal nodes (indicated by tipCase) the conditional likelihoods are computed based on x1 if q is an inner node or tipX1 if it is a tip, resp. x2 if r is an inner node or tipX2 if it is a tip. Output array ex3 stores the number of times the likelihood of each site for each internal node has been scaled. The conditional likelihood vectors for any possible basepair (which is useful when q or r are tips) has been already precomputed from the eigenvalues of the Q matrix in the array tipVector. In case the conditional likelihood for a particular site is very small in terms of a floating point number, then it is multiplied by a very large number (scaling), and then number of times it has been scaled (per node) is stored in the array ex3, if fastScaling is set to PLL_FALSE. Otherwise, the total number of scalings for all sites and all nodes is stored in a single variable scalerIncrement.
tipCase  Can be either PLL_TIP_TIP, or PLL_TIP_INNER or PLL_INNER_INNER, and describes the descendants of the node for which we currently compute the condition likelihood vector, i.e. whether they are both tips (leaves), or one is tip and the other an inner node, or both are inner nodes. 
extEV  Eigenvectors of Q matrix 
cptr  Array where the rate for each site in the compressed partition alignment is stored 
x1  Conditional likelihood vectors of the first child node, in case it is an internal node 
x2  Conditional likelihood vectors of the second child node, in case it is an internal node 
x3  Pointer to where the computed conditional likelihood vector of node p will be stored 
tipVector  Vector contining sums of left eigenvectors for likelihood computation at tips. 
ex3  Pointer to an array of whose elements correspond to the number of times the likelihood of a particular site of a particular internal nodeis scaled. Those elements are incremented at every scaling operation and only if fastScaling flag is set to PLL_FALSE. This array will be used later when evaluating the likelihood of the whole tree. 
tipX1  Pointer to the alignment data (sequence) of first child node, in case it is a tip 
tipX2  Pointer to the alignment data (sequence) of second child node, in case it is a tip 
n  Number of sites for which we are doing the evaluation. For the singlethread version this is the number of sites in the current partition, for multithreads this is the number of sites assigned to the running thread from the current partition. 
left  Pointer to the P matrix of the left child 
right  Pointer to the P matrix of the right child 
wgt  Array of weights for each site 
scalerIncrement  Where to store the number of scalings carried out in case fastScaling is set to PLL_TRUE. 
fastScaling  If set to PLL_TRUE, only the total number of scalings for all sites of the partition will be stored in scalerIncrement, otherwise persite scalings are stored in the array ex3. 
states  Number of states for the particular data (4 for DNA or 20 for AA) 

static 
Computation of conditional likelihood arrays for GAMMA.
This is a generic, slow but readable function implementation for computing the conditional likelihood arrays at p, given child nodes q and r using the GAMMA model of rate heterogeneity. Depending whether q, resp. , are tips or internal nodes (indicated by tipCase) the conditional likelihoods are computed based on x1 if q is an inner node or tipX1 if it is a tip, resp. x2 if r is an inner node or tipX2 if it is a tip. Output array ex3 stores the number of times the likelihood of each site for each internal node has been scaled. The conditional likelihood vectors for any possible basepair (which is useful when q or r are tips) has been already precomputed from the eigenvalues of the Q matrix in the array tipVector. In case the conditional likelihood for a particular site is very small in terms of a floating point number, then it is multiplied by a very large number (scaling), and then number of times it has been scaled (per node) is stored in the array ex3, if fastScaling is set to PLL_FALSE. Otherwise, the total number of scalings for all sites and all nodes is stored in a single variable scalerIncrement.
tipCase  Can be either PLL_TIP_TIP, or PLL_TIP_INNER or PLL_INNER_INNER, and describes the descendants of the node for which we currently compute the condition likelihood vector, i.e. whether they are both tips (leaves), or one is tip and the other an inner node, or both are inner nodes. 
x1  Conditional likelihood vectors of the first child node, in case it is an internal node 
x2  Conditional likelihood vectors of the second child node, in case it is an internal node 
x3  Pointer to where the computed conditional likelihood vector of node p will be stored 
extEV  Eigenvectors of Q matrix 
tipVector  Vector contining sums of left eigenvectors for likelihood computation at tips. 
ex3  Pointer to an array of whose elements correspond to the number of times the likelihood of a particular site of a particular internal nodeis scaled. Those elements are incremented at every scaling operation and only if fastScaling flag is set to PLL_FALSE. This array will be used later when evaluating the likelihood of the whole tree. 
tipX1  Pointer to the alignment data (sequence) of first child node, in case it is a tip 
tipX2  Pointer to the alignment data (sequence) of second child node, in case it is a tip 
n  Number of sites to be processed 
left  Pointer to the P matrix of the left child 
right  Pointer to the P matrix of the right child 
wgt  Array of weights for each site 
scalerIncrement  Where to store the number of scalings carried out in case fastScaling is set to PLL_TRUE. 
fastScaling  If set to PLL_TRUE, only the total number of scalings for all sites of the partition will be stored in scalerIncrement, otherwise persite scalings are stored in the array ex3. 
states  Number of states for the particular data (4 for DNA or 20 for AA) 
maxStateValue  Number of all possible basepairs including degenerate characters, i.e. 16 for DNA and 23 for AA 

inline 
Check whether the position pos in bitvector x is NOT a gap.
x  A bitvector represented by unsigned integers 
pos  Position to check in x if it is NOT set (i.e. it is NOT a gap) 
void pllNewviewGeneric  (  pllInstance *  tr, 
partitionList *  pr,  
nodeptr  p,  
boolean  masked  
) 
Computes the conditional likelihood vectors of all nodes in the subtree rooted at p.
Compute the conditional likelihood vectors of all nodes in the subtree rooted at node p. The conditional likelihood vector at node p is recomputed regardless of whether the orientation (i.e. p>x) is correct or not, and, recursuvely, the likelihoods at each node in the subtree as needed and if necessary. In case masked is set to PLL_TRUE, the computation will not take place at partitions for which the conditional likelihood has converged (for example as a reult of previous branch length optimization).
tr  PLL instance 
pr  List of partitions 
p  Root of the subtree for which we want to recompute the conditional likelihood vectors 
masked  If set to PLL_TRUE, then likelihood vectors of partitions that are converged are not recomputed. 
void pllNewviewGenericAncestral  (  pllInstance *  tr, 
partitionList *  pr,  
nodeptr  p  
) 
Computes the conditional likelihood vectors of all nodes in the subtree rooted at p and the marginal ancestral probabilities at node p.
Compute the conditional likelihood vectors of all nodes in the subtree rooted at node p. The conditional likelihood vector at node p is recomputed regardless of whether the orientation (i.e. p>x) is correct or not, and, recursively, the likelihoods at each node in the subtree as needed and if necessary. In addition, the marginal ancestral probability vector for node p is also computed.
tr  PLL instance 
pr  List of partitions 
p  Node for which we want to compute the ancestral vector 
void pllNewviewIterative  (  pllInstance *  tr, 
partitionList *  pr,  
int  startIndex  
) 
Compute the conditional likelihood for each entry (node) of the traversal descriptor.
Computes the conditional likelihood vectors for each entry (node) in the already computed traversal descriptor, starting from the startIndex entry.
tr  PLL instance 
pr  List of partitions 
startIndex  From which node to start computing the conditional likelihood vectors in the traversal descriptor 
void printAncestralState  (  nodeptr  p, 
boolean  printStates,  
boolean  printProbs,  
pllInstance *  tr,  
partitionList *  pr  
) 
Prints the ancestral state information for a node p to the terminal.
Prints the ancestral state information for a node p to the terminal. The ancestral state sequence, resp. marginal ancestral state probabilities, is printed depending on whether printStates, resp. printProbs, is set to PLL_TRUE.
p  The node for which to print the ancestral state sequence 
printStates  If set to PLL_TRUE then the ancestral state sequence is printed 
printProbs  If set to PLL_TRUE then the marginal ancestral state probabilities are printed 
tr  PLL instance 
pr  List of partitions 
const unsigned int mask32[32] 
Array that contains the first 32 powers of 2, i.e. 2^0 upto 2^31.
Array that contains the first 32 powers of 2, i.e. 2^0 upto 2^31.