CAFE
Computational Analysis of gene Family Evolution
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cafe_commands.cpp File Reference
#include "../config.h"
#include <stdio.h>
#include <time.h>
#include <map>
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <stdexcept>
#include <stack>
#include "lambda.h"
#include "lambdamu.h"
#include "cafe_commands.h"
#include "reports.h"
#include "pvalue.h"
#include "conditional_distribution.h"
#include "simerror.h"
#include "error_model.h"
#include "log_buffer.h"
#include "Globals.h"
#include "viterbi.h"
#include "gene_family.h"
#include "cross_validator.h"
#include <dirent.h>
#include <sys/stat.h>
#include <utils_string.h>
#include "cafe_shell.h"
#include "cafe.h"

Data Structures

struct  family_args
 
struct  errormodel_args
 

Functions

void cafe_log (pCafeParam param, const char *msg,...)
 Logs the message and parameters in a standard way. More...
 
void __cafe_tree_string_gainloss (pString pstr, pPhylogenyNode ptnode)
 
void __cafe_tree_string_sum_gainloss (pString pstr, pPhylogenyNode ptnode)
 
int __cafe_cmd_extinct_count_zero (pTree pcafe)
 
void __hg_print_sim_extinct (pHistogram **phist_sim_n, pHistogram *phist_sim, int r, pHistogram phist_tmp, double *cnt, int num_trials)
 
pErrorStruct cafe_shell_create_error_matrix_from_estimate (pErrorMeasure errormeasure)
 
void cafe_shell_set_branchlength (pCafeParam param, int max_family_size)
 
void set_range_from_family (family_size_range *range, pCafeFamily family)
 
double __cafe_best_lambda_search (double *plambda, void *args)
 
double __cafe_cluster_lambda_search (double *parameters, void *args)
 
map< string, cafe_command2get_dispatcher ()
 Holds the list of commands that are available in Cafe. More...
 
void get_doubles_array (vector< double > &loc, pArgument parg)
 
int cafe_cmd_echo (Globals &globals, std::vector< std::string > tokens)
 Echoes test to the log file. More...
 
int cafe_cmd_date (Globals &globals, std::vector< std::string > tokens)
 Date: Writes the current date and time to log file More...
 
int cafe_cmd_exit (Globals &globals, std::vector< std::string > tokens)
 Exit: Close files, release memory and exit application More...
 
void set_log_file (Globals &globals, string log_file)
 
int cafe_cmd_log (Globals &globals, std::vector< std::string > tokens)
 Log: Sets file to which data is logged More...
 
void write_version (ostream &ost)
 
int cafe_cmd_version (Globals &globals, std::vector< std::string > tokens)
 Version: Prints CAFE version and date of build More...
 
int cafe_cmd_source (Globals &globals, std::vector< std::string > tokens)
 Source: Executes a series of commands from a CAFE command file More...
 
void list_commands (std::ostream &ost)
 
int cafe_cmd_list (Globals &, std::vector< std::string > tokens)
 List: List all commands available in CAFE More...
 
void clear_node_viterbis (pTree ptree, pTreeNode ptnode, va_list ap1)
 
void clear_tree_viterbis (pCafeTree ptree)
 
int write_family_gainloss (ostream &ofst, std::string family_id, pCafeTree tree1, pCafeTree tree2)
 
void prereqs (pCafeParam param, int flags)
 
vector< Argumentbuild_argument_list (vector< string > tokens)
 
int cafe_shell_dispatch_command (Globals &globals, char *cmd)
 
int cafe_shell_dispatch_commandf (Globals &globals, const char *format,...)
 
int get_num_trials (vector< string > args)
 
void cafe_shell_prompt (const char *prompt, const char *format,...)
 
int set_family_size_interactive (pCafeTree pcafe)
 
void verify_directory (string dirname)
 
int * get_root_dist (pCafeTree pcafe, pCafeFamily pfamily, int k_value, family_size_range *range)
 
vector< int > get_clusters (int parameterized_k_value, int num_families, double *k_weights)
 
void write_node_headers (ostream &s1, ostream &s2, pCafeTree pcafe)
 
void write_leaves (ostream &ofst, pCafeTree pcafe, int *k, int i, int id, bool evens)
 
int cafe_cmd_generate_random_family (Globals &globals, std::vector< std::string > tokens)
 generate_random_family: Generates random families More...
 
struct load_args get_load_arguments (vector< Argument > pargs)
 
void copy_args_to_param (Globals &globals, struct load_args &args)
 
bool endsWith (std::string const &fullString, std::string const &ending)
 
int cafe_cmd_load (Globals &globals, std::vector< std::string > tokens)
 Load: Loads families from a family file with a defined format More...
 
struct family_args get_family_arguments (vector< Argument > pargs)
 
int cafe_cmd_report (Globals &globals, std::vector< std::string > tokens)
 Report: Generates reports in various formats of the calculations completed More...
 
template<typename T >
void write_vector (ostream &ost, vector< T > items, string delimiter)
 
void write_family (ostream &ost, pCafeFamily family)
 
int cafe_cmd_tree (Globals &globals, std::vector< std::string > tokens)
 : The tree to perform calculations on. Must be in Newick format. More...
 
struct viterbi_args get_viterbi_arguments (vector< Argument > pargs)
 
int to_integer (std::string str)
 
int cafe_shell_parse_familysize (pTree pcafe, std::vector< std::string > tokens)
 
void run_viterbi_sim (pCafeTree pcafe, pCafeFamily pfamily, roots &roots)
 
int init_histograms (int rfsize, roots &roots, int nsamples)
 
ostream & operator<< (ostream &os, const Histogram &hist)
 
struct pvalue_args get_pvalue_arguments (vector< Argument > pargs)
 
int cafe_cmd_pvalue (Globals &globals, std::vector< std::string > tokens)
 PValue: Calculates pvalues More...
 
lhtest_args get_lhtest_arguments (vector< Argument > pargs)
 
std::vector< std::string > enumerate_directory (std::string dir, std::string ext)
 
int cafe_cmd_lhtest (Globals &globals, std::vector< std::string > tokens)
 
int cafe_cmd_simerror (Globals &globals, std::vector< std::string > tokens)
 
errormodel_args get_errormodel_arguments (vector< Argument > pargs)
 
int cafe_cmd_errormodel (Globals &globals, std::vector< std::string > tokens)
 errormodel: allows the user to specify an error distribution. More...
 
esterror_args get_esterror_arguments (vector< Argument > pargs)
 
void validate (esterror_args args)
 
int cafe_cmd_esterror (Globals &globals, std::vector< std::string > tokens)
 
int cafe_cmd_noerrormodel (Globals &globals, std::vector< std::string > tokens)
 
void tree_set_branch_lengths (pCafeTree pcafe, std::vector< int > lengths)
 
int s_to_i (std::string s)
 
std::string get_input_file (std::vector< std::string > tokens)
 
int cafe_cmd_rootdist (Globals &globals, std::vector< std::string > tokens)
 Specify root family size distribution for simulation. More...
 
void log_param_values (std::ostream &ost, Globals &globals)
 
int cafe_cmd_seed (Globals &globals, std::vector< std::string > tokens)
 Set the random seed for reproducible results. More...
 
void __tree_build_node_list (pTree ptree, pTreeNode ptnode, va_list ap1)
 
void __tree_build_prefix_node_list (pTree ptree, pTreeNode ptnode, va_list ap1)
 
void __tree_build_postfix_node_list (pTree ptree, pTreeNode ptnode, va_list ap1)
 
void tree_traveral_infix (pTree ptree, tree_func_node func,...)
 
void tree_build_node_list (pTree ptree)
 
pTree __cafe_tree_new (tree_func_node_new new_tree_node_func, int size)
 
void cafe_tree_parse_node (pTree ptree, pTreeNode ptnode)
 
pCafeTree cafe_tree_new (const char *sztree, family_size_range *range, double lambda, double mu)
 

Variables

pTree tmp_lambda_tree
 
pBirthDeathCacheArray probability_cache
 

Function Documentation

double __cafe_best_lambda_search ( double *  plambda,
void *  args 
)
double __cafe_cluster_lambda_search ( double *  parameters,
void *  args 
)
int __cafe_cmd_extinct_count_zero ( pTree  pcafe)
pTree __cafe_tree_new ( tree_func_node_new  new_tree_node_func,
int  size 
)
void __cafe_tree_string_gainloss ( pString  pstr,
pPhylogenyNode  ptnode 
)
void __cafe_tree_string_sum_gainloss ( pString  pstr,
pPhylogenyNode  ptnode 
)
void __hg_print_sim_extinct ( pHistogram **  phist_sim_n,
pHistogram phist_sim,
int  r,
pHistogram  phist_tmp,
double *  cnt,
int  num_trials 
)
void __tree_build_node_list ( pTree  ptree,
pTreeNode  ptnode,
va_list  ap1 
)
void __tree_build_postfix_node_list ( pTree  ptree,
pTreeNode  ptnode,
va_list  ap1 
)
void __tree_build_prefix_node_list ( pTree  ptree,
pTreeNode  ptnode,
va_list  ap1 
)
vector<Argument> build_argument_list ( vector< string >  tokens)
int cafe_cmd_esterror ( Globals globals,
std::vector< std::string >  tokens 
)
int cafe_cmd_lhtest ( Globals globals,
std::vector< std::string >  tokens 
)
int cafe_cmd_noerrormodel ( Globals globals,
std::vector< std::string >  tokens 
)
int cafe_cmd_simerror ( Globals globals,
std::vector< std::string >  tokens 
)
void cafe_log ( pCafeParam  param,
const char *  msg,
  ... 
)

Logs the message and parameters in a standard way.

If the user has assigned a file for logging, message is written to the file and also to stdout. The stdout write will be suppressed if the param "quiet" flag is set.

pErrorStruct cafe_shell_create_error_matrix_from_estimate ( pErrorMeasure  errormeasure)
int cafe_shell_dispatch_command ( Globals globals,
char *  cmd 
)
int cafe_shell_dispatch_commandf ( Globals globals,
const char *  format,
  ... 
)
int cafe_shell_parse_familysize ( pTree  pcafe,
std::vector< std::string >  tokens 
)
void cafe_shell_prompt ( const char *  prompt,
const char *  format,
  ... 
)
void cafe_shell_set_branchlength ( pCafeParam  param,
int  max_family_size 
)
pCafeTree cafe_tree_new ( const char *  sztree,
family_size_range range,
double  lambda,
double  mu 
)
void cafe_tree_parse_node ( pTree  ptree,
pTreeNode  ptnode 
)
void clear_node_viterbis ( pTree  ptree,
pTreeNode  ptnode,
va_list  ap1 
)
void clear_tree_viterbis ( pCafeTree  ptree)
void copy_args_to_param ( Globals globals,
struct load_args args 
)
bool endsWith ( std::string const &  fullString,
std::string const &  ending 
)
std::vector<std::string> enumerate_directory ( std::string  dir,
std::string  ext 
)
vector<int> get_clusters ( int  parameterized_k_value,
int  num_families,
double *  k_weights 
)
map<string, cafe_command2> get_dispatcher ( )

Holds the list of commands that are available in Cafe.

Each element consists of a command and the function that is called to handle that command. Functions include cafe_cmd_lambda, #cafe_cmd_family, cafe_cmd_tree, etc.

void get_doubles_array ( vector< double > &  loc,
pArgument  parg 
)
errormodel_args get_errormodel_arguments ( vector< Argument pargs)
esterror_args get_esterror_arguments ( vector< Argument pargs)
struct family_args get_family_arguments ( vector< Argument pargs)
std::string get_input_file ( std::vector< std::string >  tokens)
lhtest_args get_lhtest_arguments ( vector< Argument pargs)
struct load_args get_load_arguments ( vector< Argument pargs)
int get_num_trials ( vector< string >  args)
struct pvalue_args get_pvalue_arguments ( vector< Argument pargs)
int* get_root_dist ( pCafeTree  pcafe,
pCafeFamily  pfamily,
int  k_value,
family_size_range range 
)
struct viterbi_args get_viterbi_arguments ( vector< Argument pargs)
int init_histograms ( int  rfsize,
roots roots,
int  nsamples 
)
void list_commands ( std::ostream &  ost)
void log_param_values ( std::ostream &  ost,
Globals globals 
)
ostream& operator<< ( ostream &  os,
const Histogram hist 
)
void prereqs ( pCafeParam  param,
int  flags 
)
void run_viterbi_sim ( pCafeTree  pcafe,
pCafeFamily  pfamily,
roots roots 
)
int s_to_i ( std::string  s)
int set_family_size_interactive ( pCafeTree  pcafe)
void set_log_file ( Globals globals,
string  log_file 
)
void set_range_from_family ( family_size_range range,
pCafeFamily  family 
)
int to_integer ( std::string  str)
void tree_build_node_list ( pTree  ptree)
void tree_set_branch_lengths ( pCafeTree  pcafe,
std::vector< int >  lengths 
)
void tree_traveral_infix ( pTree  ptree,
tree_func_node  func,
  ... 
)
void validate ( esterror_args  args)
void verify_directory ( string  dirname)
void write_family ( ostream &  ost,
pCafeFamily  family 
)
int write_family_gainloss ( ostream &  ofst,
std::string  family_id,
pCafeTree  tree1,
pCafeTree  tree2 
)
void write_leaves ( ostream &  ofst,
pCafeTree  pcafe,
int *  k,
int  i,
int  id,
bool  evens 
)
void write_node_headers ( ostream &  s1,
ostream &  s2,
pCafeTree  pcafe 
)
template<typename T >
void write_vector ( ostream &  ost,
vector< T >  items,
string  delimiter 
)
void write_version ( ostream &  ost)

Variable Documentation

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.

pTree tmp_lambda_tree