CAFE
Computational Analysis of gene Family Evolution
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cafe_tree.c File Reference
#include "cafe.h"
#include <stdlib.h>
#include <math.h>
#include <mathfunc.h>
#include <chooseln_cache.h>
#include "time.h"

Functions

void __phylogeny_free_node (pTree ptree, pTreeNode ptnode, va_list ap1)
 
pTreeNode cafe_tree_new_empty_node (pTree ptree)
 
void cafe_tree_set_parameters (pCafeTree pcafe, family_size_range *range, double lambda)
 
void __cafe_tree_free_node (pTree ptree, pTreeNode ptnode, va_list ap1)
 
void cafe_tree_free (pCafeTree pcafe)
 
void cafe_tree_string_name (pString pstr, pPhylogenyNode ptnode)
 
void cafe_tree_string_familysize_lambda (pString pstr, pPhylogenyNode ptnode)
 
void cafe_tree_string_familysize (pString pstr, pPhylogenyNode ptnode)
 
void cafe_tree_string_lambda (pString pstr, pPhylogenyNode ptnode)
 
void cafe_tree_string_id (pString pstr, pPhylogenyNode pnode)
 
pString cafe_tree_string_with_familysize_lambda (pCafeTree pcafe)
 
pString cafe_tree_string_with_lambda (pCafeTree pcafe)
 
pString cafe_tree_string_with_familysize (pCafeTree pcafe)
 
pString cafe_tree_string_with_id (pCafeTree pcafe)
 
pString cafe_tree_string (pCafeTree pcafe)
 
void cafe_tree_string_print (pCafeTree pcafe)
 
double cafe_tree_mp_remark (pString pstr, pTree ptree, pMetapostConfig pmc, va_list ap1)
 
void initialize_leaf_likelihoods_for_viterbi (double **matrix, int num_rows, int range, int familysize, int num_cols, pErrorStruct errormodel)
 Initialize matrix values according to the error model or to defaults if familysize < 0, sets the first (range) values of each row to 1, ignoring the others otherwise if errormodel is NULL, initializes all values of each row to 0 except for the one indexed by familysize, which is 1 otherwise, sets each row of matrix to the row of errormatrix indexed by familysize I doubt this function is doing what was intended. More...
 
void initialize_leaf_likelihoods (pTree ptree, pTreeNode ptnode)
 Set likelihood to 1 for actual value, 0 otherwise, or copy values from an existing errormodel Copies likelihood values from an errormodel if one exists, otherwise sets all likelihoods to 0 except for familysize, which is set to 1. More...
 
void compute_viterbis (pCafeNode node, int k, double *factors, int rootfamilysize_start, int rootfamilysize_end, int familysize_start, int familysize_end)
 
void compute_child_factor (pCafeTree pcafe, pCafeNode child, family_size_range *range, double *factors)
 
void compute_internal_node_likelihood (pTree ptree, pTreeNode ptnode)
 
void free_probabilities (struct probabilities *probs)
 
void compute_node_likelihoods (pTree ptree, pTreeNode ptnode, va_list ap1)
 
void compute_node_likelihoods_recursive (pTree ptree, pTreeNode ptnode)
 
void compute_tree_likelihoods (pCafeTree pcafe)
 
double * get_likelihoods (const pCafeTree pcafe)
 
void node_set_birthdeath_matrix (pCafeNode pcnode, pBirthDeathCacheArray cache, int num_lambdas)
 Initialize node with probability values that it may need. If multiple lambdas are set, k_bd is set to an arraylist of matrices with probability values In this case, values are set up to the value of num_lambdas otherwise the value birthdeath_matrix is used probability values are drawn from the cache argument, which should hold a variety of possible values. More...
 
void add_key (pArrayList arr, double branchlength, double lambda, double mu)
 
void get_keys_from_node (pCafeNode pcnode, pArrayList arr, int num_lambdas)
 
void do_node_set_birthdeath (pTree ptree, pTreeNode ptnode, va_list ap1)
 
void gather_keys (pTree ptree, pTreeNode ptnode, va_list ap1)
 
void cafe_tree_set_birthdeath (pCafeTree pcafe, int max_family_size)
 
void cafe_tree_node_copy (pTreeNode psrc, pTreeNode pdest)
 
void __cafe_tree_copy_new_fill (pCafeTree psrc, pCafeTree pdest)
 
pCafeTree cafe_tree_copy (pCafeTree psrc)
 
pCafeTree cafe_tree_split (pCafeTree pcafe, int idx)
 
void __cafe_tree_node_random_familysize (pTree ptree, pTreeNode pnode, va_list ap1)
 
int cafe_tree_random_familysize (pCafeTree pcafe, int rootFamilysize, int maxFamilySize)
 
void initialize_leaf_likelihood_clustered (pTree ptree, pTreeNode ptnode)
 
void compute_internal_node_likelihood_clustered (pTree ptree, pTreeNode ptnode)
 
void compute_node_clustered_likelihood (pTree ptree, pTreeNode ptnode, va_list ap1)
 
void __cafe_tree_node_compute_clustered_likelihood_using_cache (pTree ptree, pTreeNode ptnode, va_list ap1)
 
void cafe_tree_node_free_clustered_likelihoods (pCafeParam param)
 
double ** cafe_tree_clustered_likelihood (pCafeTree pcafe, struct chooseln_cache *ln_cache)
 

Variables

pBirthDeathCacheArray probability_cache
 
struct chooseln_cache cache
 A cache of values of chooseln. More...
 

Function Documentation

void __cafe_tree_copy_new_fill ( pCafeTree  psrc,
pCafeTree  pdest 
)
void __cafe_tree_free_node ( pTree  ptree,
pTreeNode  ptnode,
va_list  ap1 
)
void __cafe_tree_node_compute_clustered_likelihood_using_cache ( pTree  ptree,
pTreeNode  ptnode,
va_list  ap1 
)
void __cafe_tree_node_random_familysize ( pTree  ptree,
pTreeNode  pnode,
va_list  ap1 
)
void __phylogeny_free_node ( pTree  ptree,
pTreeNode  ptnode,
va_list  ap1 
)
void add_key ( pArrayList  arr,
double  branchlength,
double  lambda,
double  mu 
)
double** cafe_tree_clustered_likelihood ( pCafeTree  pcafe,
struct chooseln_cache ln_cache 
)
pCafeTree cafe_tree_copy ( pCafeTree  psrc)
void cafe_tree_free ( pCafeTree  pcafe)
double cafe_tree_mp_remark ( pString  pstr,
pTree  ptree,
pMetapostConfig  pmc,
va_list  ap1 
)
pTreeNode cafe_tree_new_empty_node ( pTree  ptree)
void cafe_tree_node_copy ( pTreeNode  psrc,
pTreeNode  pdest 
)
void cafe_tree_node_free_clustered_likelihoods ( pCafeParam  param)
int cafe_tree_random_familysize ( pCafeTree  pcafe,
int  rootFamilysize,
int  maxFamilySize 
)

Sets the family size of each node to random value between 0 and the tree's pbdc_array maxFamilySize.

void cafe_tree_set_birthdeath ( pCafeTree  pcafe,
int  max_family_size 
)

Set each node's birthdeath matrix based on its values of branchlength, lambdas, and mus

void cafe_tree_set_parameters ( pCafeTree  pcafe,
family_size_range range,
double  lambda 
)
pCafeTree cafe_tree_split ( pCafeTree  pcafe,
int  idx 
)
pString cafe_tree_string ( pCafeTree  pcafe)
void cafe_tree_string_familysize ( pString  pstr,
pPhylogenyNode  ptnode 
)
void cafe_tree_string_familysize_lambda ( pString  pstr,
pPhylogenyNode  ptnode 
)
void cafe_tree_string_id ( pString  pstr,
pPhylogenyNode  pnode 
)
void cafe_tree_string_lambda ( pString  pstr,
pPhylogenyNode  ptnode 
)
void cafe_tree_string_name ( pString  pstr,
pPhylogenyNode  ptnode 
)
void cafe_tree_string_print ( pCafeTree  pcafe)
pString cafe_tree_string_with_familysize ( pCafeTree  pcafe)
pString cafe_tree_string_with_familysize_lambda ( pCafeTree  pcafe)
pString cafe_tree_string_with_id ( pCafeTree  pcafe)
pString cafe_tree_string_with_lambda ( pCafeTree  pcafe)
void compute_child_factor ( pCafeTree  pcafe,
pCafeNode  child,
family_size_range range,
double *  factors 
)
void compute_internal_node_likelihood ( pTree  ptree,
pTreeNode  ptnode 
)
void compute_internal_node_likelihood_clustered ( pTree  ptree,
pTreeNode  ptnode 
)
void compute_node_clustered_likelihood ( pTree  ptree,
pTreeNode  ptnode,
va_list  ap1 
)
void compute_node_likelihoods ( pTree  ptree,
pTreeNode  ptnode,
va_list  ap1 
)
void compute_node_likelihoods_recursive ( pTree  ptree,
pTreeNode  ptnode 
)
void compute_tree_likelihoods ( pCafeTree  pcafe)
void compute_viterbis ( pCafeNode  node,
int  k,
double *  factors,
int  rootfamilysize_start,
int  rootfamilysize_end,
int  familysize_start,
int  familysize_end 
)
void do_node_set_birthdeath ( pTree  ptree,
pTreeNode  ptnode,
va_list  ap1 
)
void free_probabilities ( struct probabilities probs)
void gather_keys ( pTree  ptree,
pTreeNode  ptnode,
va_list  ap1 
)
void get_keys_from_node ( pCafeNode  pcnode,
pArrayList  arr,
int  num_lambdas 
)
double* get_likelihoods ( const pCafeTree  pcafe)
void initialize_leaf_likelihood_clustered ( pTree  ptree,
pTreeNode  ptnode 
)
void initialize_leaf_likelihoods ( pTree  ptree,
pTreeNode  ptnode 
)

Set likelihood to 1 for actual value, 0 otherwise, or copy values from an existing errormodel Copies likelihood values from an errormodel if one exists, otherwise sets all likelihoods to 0 except for familysize, which is set to 1.

void initialize_leaf_likelihoods_for_viterbi ( double **  matrix,
int  num_rows,
int  range,
int  familysize,
int  num_cols,
pErrorStruct  errormodel 
)

Initialize matrix values according to the error model or to defaults if familysize < 0, sets the first (range) values of each row to 1, ignoring the others otherwise if errormodel is NULL, initializes all values of each row to 0 except for the one indexed by familysize, which is 1 otherwise, sets each row of matrix to the row of errormatrix indexed by familysize I doubt this function is doing what was intended.

void node_set_birthdeath_matrix ( pCafeNode  pcnode,
pBirthDeathCacheArray  cache,
int  num_lambdas 
)

Initialize node with probability values that it may need. If multiple lambdas are set, k_bd is set to an arraylist of matrices with probability values In this case, values are set up to the value of num_lambdas otherwise the value birthdeath_matrix is used probability values are drawn from the cache argument, which should hold a variety of possible values.

Variable Documentation

struct chooseln_cache cache

A cache of values of chooseln.

Chooseln evaluates the natural logarithm of Gamma(n+1)/(Gamma(k+1)*Gamma(n-k+1)) The cache holds values for integer values of n and k. It does not appear to be threadsafe.

P(X(t) = c | X(0) = s) = {j=0}^{(s,c)} {s}{j}{s+c-j-1}{s-1} ^{s+c-2j}(1-2)^j

pBirthDeathCacheArray probability_cache

The variable cafe_param is a global singleton that holds general program state. cafe_param holds pcafe, a CafeTree, and pfamily, a CafeFamily . These are set by the user via the commands "tree" and "load" respectively. When the user calls the command "lambda" calculations are performed on the pcafe and pfamily variables.