コード例 #1
0
ファイル: SPR.c プロジェクト: Ward9250/ape
void SPR(tree *T, double **D, double **A, int *count)
{
  int i,j,k;
  node *v;
  /*FILE *treefile;*/
  edge *e,*f;
  /* char filename[MAX_LABEL_LENGTH];*/
  double ***swapWeights;
  double swapValue = 0.0;
  swapWeights = (double ***)malloc(2*sizeof(double **));
  makeBMEAveragesTable(T,D,A);
  assignBMEWeights(T,A);
  weighTree(T);
  /*if (verbose)
    printf("Before SPRs: tree length is %lf.\n",T->weight);*/
  for(i=0;i<2;i++)
    swapWeights[i] = initDoubleMatrix(T->size);
  do
    {
      swapValue=0.0;
      zero3DMatrix(swapWeights,2,T->size,T->size);
      i = j = k = 0;
      for(e=depthFirstTraverse(T,NULL);NULL!=e;e=depthFirstTraverse(T,e))
	assignSPRWeights(e->head,A,swapWeights);
      findTableMin(&i,&j,&k,T->size,swapWeights,&swapValue);
      swapValue = swapWeights[i][j][k];
      if (swapValue < -EPSILON)
	{
//	  if (verbose)
//	    printf("New tree weight should be %lf.\n",T->weight + 0.25*swapValue);
	  v = indexedNode(T,j);
	  f = indexedEdge(T,k);
//	  if (verbose)
//	    printf("Swapping tree below %s to split edge %s with head %s and tail %s\n",
//			   v->parentEdge->label,f->label,f->head->label,f->tail->label);
	  SPRTopShift(T,v,f,2-i);
	  makeBMEAveragesTable(T,D,A);
	  assignBMEWeights(T,A);
	  weighTree(T);
	  (*count)++;
	  /*sprintf(filename,"tree%d.new",*count);*/
//	  if (verbose)
//	    printf("After %d SPRs, tree weight is %lf.\n\n",*count,T->weight);
	  /*treefile = fopen(filename,"w");
	  NewickPrintTree(T,treefile);
	  fclose(treefile);*/
	  }
    } while (swapValue < -EPSILON);
  for(i=0;i<2;i++)
    freeMatrix(swapWeights[i],T->size);
  free(swapWeights);
  /*if (verbose)
    readOffTree(T);*/
}
コード例 #2
0
ファイル: SPR.c プロジェクト: pranjalv123/ASTRID
void SPR (tree *T, double **D, double **A, int *count, FILE *statfile)
{
	int i, j, k;
	node *v;
	edge *e, *f;
	double ***swapWeights;
	double treeWeightBefore;
	double swapValue = 0.0;
	boolean firstSPR = TRUE;

	swapWeights = (double ***) mCalloc (2, sizeof(double **));
	makeBMEAveragesTable (T, D, A);
	assignBMEWeights (T, A);
	weighTree (T);
	treeWeightBefore = T->weight;

	for (i=0; i<2; i++)
		swapWeights[i] = initDoubleMatrix (T->size);

	do
	{
		swapValue = 0.0;
		zero3DMatrix (swapWeights, 2, T->size, T->size);
		i = j = k = 0;

		for (e = depthFirstTraverse (T, NULL); NULL != e; e = depthFirstTraverse (T, e))
			assignSPRWeights (e->head, A, swapWeights);

		findTableMin (&i, &j, &k, T->size, swapWeights, &swapValue);
		swapValue = swapWeights[i][j][k];
		if (swapValue < -FLT_EPSILON)
		{
			if (firstSPR)
			{
				firstSPR = FALSE;
				if (!isBoostrap)
				{

					if (verbose > 2)
						Debug ( (char*)"Before SPR: tree length is %f.", treeWeightBefore);
					else if (verbose > 1)
						Message ( (char*)". Before SPR: tree length is %f.", treeWeightBefore);
				}
			}

			if (verbose > 2 && !isBoostrap)
				Debug ( (char*)"New tree length should be %f.", T->weight + 0.25 * swapValue);

			v = indexedNode (T, j);
			f = indexedEdge (T, k);

			if (verbose > 2 && !isBoostrap)
			{
				if ((NULL == f->head->label) || (strlen (f->head->label) == 0))
				{
					if ((NULL == f->tail->label) || (strlen (f->tail->label) == 0))
						Debug ( (char*)"Swapping tree below '%s' to split edge '%s' with internal head and tail.",
							v->parentEdge->label, f->label);

					else
						Debug ( (char*)"Swapping tree below '%s' to split edge '%s' with internal head and tail '%s'.",
							v->parentEdge->label, f->label, f->tail->label);
				}
				else
				{
					if ((NULL == f->tail->label) || (strlen (f->tail->label) == 0))
						Debug ( (char*)"Swapping tree below '%s' to split edge '%s' with head '%s' and internal tail.",
							v->parentEdge->label, f->label, f->head->label, f->tail->label);

					else
						Debug ( (char*)"Swapping tree below '%s' to split edge '%s' with head '%s' and tail '%s'.",
							v->parentEdge->label, f->label, f->head->label, f->tail->label);
				}
			}

			SPRTopShift (v, f, 2-i);
			makeBMEAveragesTable (T, D, A);
			assignBMEWeights (T, A);
			weighTree (T);
			(*count)++;

			if (!isBoostrap)
			{

				if (verbose > 2)
					Debug ( (char*)"SPR %5d: new tree length is %f.", *count, T->weight);
				else if (verbose > 1)
					Message ( (char*)". SPR %5d: new tree length is %f.", *count, T->weight);
			}

		}
	} while (swapValue < -FLT_EPSILON);

	for (i=0; i<2; i++)
		freeMatrix (swapWeights[i], T->size);

	free (swapWeights);

	return;
}