#include #include #include #include #include "global.h" #include "tree.h" #include "evolve.h" #include "models.h" #include "gamma.h" #include "random.h" #include "covarion.h" int numTaxa, numBases, maxPartitions, numPartitions, fileFormat; double covarionRate, ONfreq; double CovRate[2]; int covarion; char *onoff="-+"; /* prototypes */ char SetHiddenState(); void RandomHiddenStates(char *seq, int inNumSites); void covarionSimulation(char *state, double *effectiveLength, double len); void MutateHiddenStates(char *seq, double *effectiveLength, int inFromSite, int inNumSites, double len); void EvolveHiddenStateNode(TNode *anc, TNode *des, int inFromSite, int inNumSites); void WriteHiddenStatesNode(FILE *fv, TTree *tree, int *nodeNo, TNode *des); void WriteAncestralEffLengthNode(FILE *fv, TTree *tree, int *nodeNo, TNode *des); /* functions */ void CreateHiddenStates(TTree *tree, int inNumSites) { /* Creates memory for the "hiddenStates" and the "effectiveLength0" pointers of all the nodes of the tree. */ TNode *P; P=tree->nodeList; while (P!=NULL) { if (P->hiddenStates != NULL) free(P->hiddenStates); P->hiddenStates=CAllocMem(inNumSites+1, "hiddenStates", "CreateHiddenStates", 0); if (P->effectiveLength0 != NULL) free(P->effectiveLength0 ); P->effectiveLength0=CAllocMem(sizeof(double)*(inNumSites+1),"hiddenLengths", "CreateHiddenStates", 0); P=P->next; } } char SetHiddenState() { /* creates a state on/off at random according to the probability ONfreq. */ char j; double r; j='\1'; /* ON */ r=rndu(); if (r > ONfreq) j='\0'; /* OFF */ #ifdef DEBUG print("Debugging: state created:",j); #endif return j; } void RandomHiddenStates(char *seq, int inNumSites) { /* creates a sequence of hidden states of length inNumSites, according to the probability ONfreq to be 'on'*/ int i; char *P; P=seq; for (i=0; i