Exemplo n.º 1
0
boolean treeEvaluate (tree *tr, double smoothFactor)       /* Evaluate a user tree */
{
  boolean result;
 
  if(tr->useBrLenScaler)
    assert(0);
 
  result = smoothTree(tr, (int)((double)smoothings * smoothFactor));
  
  assert(result); 

  evaluateGeneric(tr, tr->start);         

  return TRUE;
}
Exemplo n.º 2
0
int main(int argc, char * argv[])
{

  tree        * tr;

  if (argc != 2)
   {
     fprintf (stderr, "syntax: %s [binary-alignment-file]\n", argv[0]);
     return (1);
   }
  tr = (tree *)malloc(sizeof(tree));

  /* read the binary input, setup tree, initialize model with alignment */
  read_msa(tr,argv[1]);
  tr->randomNumberSeed = 665;
  makeRandomTree(tr);
  printf("Number of taxa: %d\n", tr->mxtips);
  printf("Number of partitions: %d\n", tr->NumberOfModels);


  /* compute the LH of the full tree */
  printf ("Virtual root: %d\n", tr->start->number);
  evaluateGeneric(tr, tr->start, TRUE);
  printf("Likelihood: %f\n", tr->likelihood);

  /* 8 rounds of branch length optimization */
  smoothTree(tr, 1);
  evaluateGeneric(tr, tr->start, TRUE);
  printf("Likelihood after branch length optimization: %.20f\n", tr->likelihood);



  /* Now we show how to find a particular LH vector for a node */
  int i;
  int node_number = tr->mxtips + 1;
  nodeptr p = tr->nodep[node_number];
  printf("Pointing to  node %d\n", p->number);

  /* Fix as VR */
  newviewGeneric(tr, p, FALSE);
  newviewGeneric(tr, p->back, FALSE);
  evaluateGeneric(tr, p, FALSE);
  printf("Likelihood : %.f\n", tr->likelihood);

  printf("Make a copy of LH vector for node  %d\n", p->number);
  likelihood_vector *vector = copy_likelihood_vectors(tr, p);
  for(i=0; i<vector->num_partitions; i++)
     printf("Partition %d requires %d bytes\n", i, (int)vector->partition_sizes[i]);

  /* Check we have the same vector in both tree and copied one */
  assert(same_vector(tr, p, vector));

  /* Now force the p to get a new value (generally branch lengths are NOT updated like this) */
  /* This is just an example to show usage (for fast NNI eval), manually updating vectors is not recommended! */
  printf("bl : %.40f\n", p->next->z[0]);
  p->next->z[0] = p->next->back->z[0] = zmin;
  printf("bl : %.40f\n", p->next->z[0]);
  newviewGeneric(tr, p, FALSE);
  assert(!same_vector(tr, p, vector));
  evaluateGeneric(tr, p, FALSE);
  printf("Likelihood : %f\n", tr->likelihood);

  restore_vector(tr, p, vector);
  assert(same_vector(tr, p, vector));
  evaluateGeneric(tr, p, FALSE);
  printf("Likelihood after manually restoring the vector : %f\n", tr->likelihood);

  free_likelihood_vector(vector);

  /* Pick an inner branch */
  printf("numBranches %d \n", tr->numBranches);
  //tr->numBranches = 1;
  p = tr->nodep[tr->mxtips + 1];
  int partition_id = 0; /* single partition */
  double bl = get_branch_length(tr, p, partition_id);
  printf("z value: %f , bl value %f\n", p->z[partition_id], bl);
  /* set the bl to 2.5 */
  double new_bl = 2.5;
  set_branch_length(tr, p, partition_id, new_bl);
  printf("Changed BL to %f\n", new_bl);
  printf("new z value: %f , new bl value %f\n", p->z[partition_id], get_branch_length(tr, p, partition_id));
  /* set back to original */
  printf("Changed to previous BL\n");
  set_branch_length(tr, p, partition_id, bl);
  printf("new z value: %f , new bl value %f\n", p->z[partition_id], get_branch_length(tr, p, partition_id));

  return (0);
}